Socket
Socket
Sign inDemoInstall

@rjsf/validator-ajv8

Package Overview
Dependencies
4
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.0-beta.14 to 5.0.0-beta.15

282

dist/validator-ajv8.cjs.development.js

@@ -20,3 +20,18 @@ 'use strict';

const AJV_CONFIG = {
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
var AJV_CONFIG = {
allErrors: true,

@@ -26,4 +41,4 @@ multipleOfPrecision: 8,

};
const COLOR_FORMAT_REGEX = /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/;
const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
var COLOR_FORMAT_REGEX = /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/;
var DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.

@@ -51,6 +66,3 @@ * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the

}
const ajv = new AjvClass({
...AJV_CONFIG,
...ajvOptionsOverrides
});
var ajv = new AjvClass(_extends({}, AJV_CONFIG, ajvOptionsOverrides));
if (ajvFormatOptions) {

@@ -73,3 +85,3 @@ addFormats__default["default"](ajv, ajvFormatOptions);

if (isObject__default["default"](customFormats)) {
Object.keys(customFormats).forEach(formatName => {
Object.keys(customFormats).forEach(function (formatName) {
ajv.addFormat(formatName, customFormats[formatName]);

@@ -81,6 +93,6 @@ });

const ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
var ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.
*/
class AJV8Validator {
var AJV8Validator = /*#__PURE__*/function () {
/** The AJV instance to use for all validations

@@ -101,12 +113,10 @@ *

*/
constructor(options, localizer) {
function AJV8Validator(options, localizer) {
this.ajv = void 0;
this.localizer = void 0;
const {
additionalMetaSchemas,
customFormats,
ajvOptionsOverrides,
ajvFormatOptions,
AjvClass
} = options;
var additionalMetaSchemas = options.additionalMetaSchemas,
customFormats = options.customFormats,
ajvOptionsOverrides = options.ajvOptionsOverrides,
ajvFormatOptions = options.ajvFormatOptions,
AjvClass = options.AjvClass;
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);

@@ -134,36 +144,21 @@ this.localizer = localizer;

*/
toErrorSchema(errors) {
if (!errors.length) {
return {};
}
return errors.reduce((errorSchema, error) => {
const {
property,
message
} = error;
const path = toPath__default["default"](property);
let parent = errorSchema;
// If the property is at the root (.level1) then toPath creates
// an empty array element at the first index. Remove it.
if (path.length > 0 && path[0] === "") {
path.splice(0, 1);
}
for (const segment of path.slice(0)) {
if (!(segment in parent)) {
parent[segment] = {};
var _proto = AJV8Validator.prototype;
_proto.toErrorSchema = function toErrorSchema(errors) {
var builder = new utils.ErrorSchemaBuilder();
if (errors.length) {
errors.forEach(function (error) {
var property = error.property,
message = error.message;
var path = toPath__default["default"](property);
// If the property is at the root (.level1) then toPath creates
// an empty array element at the first index. Remove it.
if (path.length > 0 && path[0] === "") {
path.splice(0, 1);
}
parent = parent[segment];
}
if (Array.isArray(parent.__errors)) {
// We store the list of errors for this node in a property named __errors
// to avoid name collision with a possible sub schema field named
// 'errors' (see `validate.createErrorHandler`).
parent.__errors = parent.__errors.concat(message);
} else {
if (message) {
parent.__errors = [message];
builder.addErrors(message, path);
}
}
return errorSchema;
}, {});
});
}
return builder.ErrorSchema;
}

@@ -174,4 +169,5 @@ /** Converts an `errorSchema` into a list of `RJSFValidationErrors`

* @param [fieldPath=[]] - The current field path, defaults to [] if not specified
*/
toErrorList(errorSchema, fieldPath) {
*/;
_proto.toErrorList = function toErrorList(errorSchema, fieldPath) {
var _this = this;
if (fieldPath === void 0) {

@@ -183,16 +179,16 @@ fieldPath = [];

}
let errorList = [];
var errorList = [];
if (utils.ERRORS_KEY in errorSchema) {
errorList = errorList.concat(errorSchema.__errors.map(message => {
const property = `.${fieldPath.join(".")}`;
errorList = errorList.concat(errorSchema[utils.ERRORS_KEY].map(function (message) {
var property = "." + fieldPath.join(".");
return {
property,
message,
stack: `${property} ${message}`
property: property,
message: message,
stack: property + " " + message
};
}));
}
return Object.keys(errorSchema).reduce((acc, key) => {
return Object.keys(errorSchema).reduce(function (acc, key) {
if (key !== utils.ERRORS_KEY) {
acc = acc.concat(this.toErrorList(errorSchema[key], [...fieldPath, key]));
acc = acc.concat(_this.toErrorList(errorSchema[key], [].concat(fieldPath, [key])));
}

@@ -206,5 +202,6 @@ return acc;

* @private
*/
createErrorHandler(formData) {
const handler = {
*/;
_proto.createErrorHandler = function createErrorHandler(formData) {
var _this2 = this;
var handler = {
// We store the list of errors for this node in a property named __errors

@@ -214,3 +211,3 @@ // to avoid name collision with a possible sub schema field named

__errors: [],
addError(message) {
addError: function addError(message) {
this.__errors.push(message);

@@ -220,16 +217,12 @@ }

if (Array.isArray(formData)) {
return formData.reduce((acc, value, key) => {
return {
...acc,
[key]: this.createErrorHandler(value)
};
return formData.reduce(function (acc, value, key) {
var _extends2;
return _extends({}, acc, (_extends2 = {}, _extends2[key] = _this2.createErrorHandler(value), _extends2));
}, handler);
}
if (isObject__default["default"](formData)) {
const formObject = formData;
return Object.keys(formObject).reduce((acc, key) => {
return {
...acc,
[key]: this.createErrorHandler(formObject[key])
};
var formObject = formData;
return Object.keys(formObject).reduce(function (acc, key) {
var _extends3;
return _extends({}, acc, (_extends3 = {}, _extends3[key] = _this2.createErrorHandler(formObject[key]), _extends3));
}, handler);

@@ -243,17 +236,14 @@ }

* @private
*/
unwrapErrorHandler(errorHandler) {
return Object.keys(errorHandler).reduce((acc, key) => {
*/;
_proto.unwrapErrorHandler = function unwrapErrorHandler(errorHandler) {
var _this3 = this;
return Object.keys(errorHandler).reduce(function (acc, key) {
var _extends5;
if (key === "addError") {
return acc;
} else if (key === utils.ERRORS_KEY) {
return {
...acc,
[key]: errorHandler[key]
};
var _extends4;
return _extends({}, acc, (_extends4 = {}, _extends4[key] = errorHandler[key], _extends4));
}
return {
...acc,
[key]: this.unwrapErrorHandler(errorHandler[key])
};
return _extends({}, acc, (_extends5 = {}, _extends5[key] = _this3.unwrapErrorHandler(errorHandler[key]), _extends5));
}, {});

@@ -266,24 +256,27 @@ }

* @private
*/
transformRJSFValidationErrors(errors) {
*/;
_proto.transformRJSFValidationErrors = function transformRJSFValidationErrors(errors) {
if (errors === void 0) {
errors = [];
}
return errors.map(e => {
const {
instancePath,
keyword,
message,
params,
schemaPath
} = e;
const property = instancePath.replace(/\//g, ".");
return errors.map(function (e) {
var instancePath = e.instancePath,
keyword = e.keyword,
message = e.message,
params = e.params,
schemaPath = e.schemaPath;
var property = instancePath.replace(/\//g, ".");
var stack = (property + " " + message).trim();
if ("missingProperty" in params) {
property = property ? property + "." + params.missingProperty : params.missingProperty;
stack = message;
}
// put data in expected format
return {
name: keyword,
property,
message,
params,
stack: `${property} ${message}`.trim(),
schemaPath
property: property,
message: message,
params: params,
stack: stack,
schemaPath: schemaPath
};

@@ -297,6 +290,6 @@ });

* @param formData - The form data to validate
*/
rawValidation(schema, formData) {
let compilationError = undefined;
let compiledValidator;
*/;
_proto.rawValidation = function rawValidation(schema, formData) {
var compilationError = undefined;
var compiledValidator;
if (schema["$id"]) {

@@ -313,3 +306,3 @@ compiledValidator = this.ajv.getSchema(schema["$id"]);

}
let errors;
var errors;
if (compiledValidator) {

@@ -337,13 +330,11 @@ if (typeof this.localizer === "function") {

* @param [transformErrors] - An optional function that is used to transform errors after AJV validation
*/
validateFormData(formData, schema, customValidate, transformErrors) {
const rawErrors = this.rawValidation(schema, formData);
const {
validationError: invalidSchemaError
} = rawErrors;
let errors = this.transformRJSFValidationErrors(rawErrors.errors);
*/;
_proto.validateFormData = function validateFormData(formData, schema, customValidate, transformErrors) {
var rawErrors = this.rawValidation(schema, formData);
var invalidSchemaError = rawErrors.validationError;
var errors = this.transformRJSFValidationErrors(rawErrors.errors);
if (invalidSchemaError) {
errors = [...errors, {
errors = [].concat(errors, [{
stack: invalidSchemaError.message
}];
}]);
}

@@ -353,24 +344,23 @@ if (typeof transformErrors === "function") {

}
let errorSchema = this.toErrorSchema(errors);
var errorSchema = this.toErrorSchema(errors);
if (invalidSchemaError) {
errorSchema = {
...errorSchema,
errorSchema = _extends({}, errorSchema, {
$schema: {
__errors: [invalidSchemaError.message]
}
};
});
}
if (typeof customValidate !== "function") {
return {
errors,
errorSchema
errors: errors,
errorSchema: errorSchema
};
}
// Include form data with undefined values, which is required for custom validation.
const newFormData = utils.getDefaultFormState(this, schema, formData, schema, true);
const errorHandler = customValidate(newFormData, this.createErrorHandler(newFormData));
const userErrorSchema = this.unwrapErrorHandler(errorHandler);
var newFormData = utils.getDefaultFormState(this, schema, formData, schema, true);
var errorHandler = customValidate(newFormData, this.createErrorHandler(newFormData));
var userErrorSchema = this.unwrapErrorHandler(errorHandler);
return utils.mergeValidationData(this, {
errors,
errorSchema
errors: errors,
errorSchema: errorSchema
}, userErrorSchema);

@@ -383,7 +373,7 @@ }

* @private
*/
withIdRefPrefixObject(node) {
for (const key in node) {
const realObj = node;
const value = realObj[key];
*/;
_proto.withIdRefPrefixObject = function withIdRefPrefixObject(node) {
for (var key in node) {
var realObj = node;
var value = realObj[key];
if (key === utils.REF_KEY && typeof value === "string" && value.startsWith("#")) {

@@ -402,5 +392,5 @@ realObj[key] = ROOT_SCHEMA_PREFIX + value;

* @private
*/
withIdRefPrefixArray(node) {
for (let i = 0; i < node.length; i++) {
*/;
_proto.withIdRefPrefixArray = function withIdRefPrefixArray(node) {
for (var i = 0; i < node.length; i++) {
node[i] = this.withIdRefPrefix(node[i]);

@@ -417,5 +407,6 @@ }

* @param rootSchema - The root schema used to provide $ref resolutions
*/
isValid(schema, formData, rootSchema) {
const rootSchemaId = rootSchema["$id"] ?? ROOT_SCHEMA_PREFIX;
*/;
_proto.isValid = function isValid(schema, formData, rootSchema) {
var _rootSchema$$id;
var rootSchemaId = (_rootSchema$$id = rootSchema["$id"]) != null ? _rootSchema$$id : ROOT_SCHEMA_PREFIX;
try {

@@ -429,4 +420,4 @@ // add the rootSchema ROOT_SCHEMA_PREFIX as id.

}
const schemaWithIdRefPrefix = this.withIdRefPrefix(schema);
let compiledValidator;
var schemaWithIdRefPrefix = this.withIdRefPrefix(schema);
var compiledValidator;
if (schemaWithIdRefPrefix["$id"]) {

@@ -438,3 +429,3 @@ compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix["$id"]);

}
const result = compiledValidator(formData);
var result = compiledValidator(formData);
return result;

@@ -455,6 +446,6 @@ } catch (e) {

* @protected
*/
withIdRefPrefix(schemaNode) {
*/;
_proto.withIdRefPrefix = function withIdRefPrefix(schemaNode) {
if (Array.isArray(schemaNode)) {
return this.withIdRefPrefixArray([...schemaNode]);
return this.withIdRefPrefixArray([].concat(schemaNode));
}

@@ -465,4 +456,5 @@ if (isObject__default["default"](schemaNode)) {

return schemaNode;
}
}
};
return AJV8Validator;
}();

@@ -469,0 +461,0 @@ /** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("lodash/toPath"),e=require("lodash/isObject"),t=require("lodash/clone"),a=require("@rjsf/utils"),o=require("ajv8"),s=require("ajv-formats");function i(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var n=i(r),d=i(e),c=i(t),l=i(o),h=i(s);const u={allErrors:!0,multipleOfPrecision:8,strict:!1},f=/^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/,m=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;class v{constructor(r,e){this.ajv=void 0,this.localizer=void 0;const{additionalMetaSchemas:t,customFormats:o,ajvOptionsOverrides:s,ajvFormatOptions:i,AjvClass:n}=r;this.ajv=function(r,e,t,o,s){void 0===t&&(t={}),void 0===s&&(s=l.default);const i=new s({...u,...t});return o?h.default(i,o):!1!==o&&h.default(i),i.addFormat("data-url",m),i.addFormat("color",f),i.addKeyword(a.ADDITIONAL_PROPERTY_FLAG),i.addKeyword(a.RJSF_ADDITONAL_PROPERTIES_FLAG),Array.isArray(r)&&i.addMetaSchema(r),d.default(e)&&Object.keys(e).forEach((r=>{i.addFormat(r,e[r])})),i}(t,o,s,i,n),this.localizer=e}toErrorSchema(r){return r.length?r.reduce(((r,e)=>{const{property:t,message:a}=e,o=n.default(t);let s=r;o.length>0&&""===o[0]&&o.splice(0,1);for(const r of o.slice(0))r in s||(s[r]={}),s=s[r];return Array.isArray(s.__errors)?s.__errors=s.__errors.concat(a):a&&(s.__errors=[a]),r}),{}):{}}toErrorList(r,e){if(void 0===e&&(e=[]),!r)return[];let t=[];return a.ERRORS_KEY in r&&(t=t.concat(r.__errors.map((r=>{const t=`.${e.join(".")}`;return{property:t,message:r,stack:`${t} ${r}`}})))),Object.keys(r).reduce(((t,o)=>(o!==a.ERRORS_KEY&&(t=t.concat(this.toErrorList(r[o],[...e,o]))),t)),t)}createErrorHandler(r){const e={__errors:[],addError(r){this.__errors.push(r)}};if(Array.isArray(r))return r.reduce(((r,e,t)=>({...r,[t]:this.createErrorHandler(e)})),e);if(d.default(r)){const t=r;return Object.keys(t).reduce(((r,e)=>({...r,[e]:this.createErrorHandler(t[e])})),e)}return e}unwrapErrorHandler(r){return Object.keys(r).reduce(((e,t)=>"addError"===t?e:t===a.ERRORS_KEY?{...e,[t]:r[t]}:{...e,[t]:this.unwrapErrorHandler(r[t])}),{})}transformRJSFValidationErrors(r){return void 0===r&&(r=[]),r.map((r=>{const{instancePath:e,keyword:t,message:a,params:o,schemaPath:s}=r,i=e.replace(/\//g,".");return{name:t,property:i,message:a,params:o,stack:`${i} ${a}`.trim(),schemaPath:s}}))}rawValidation(r,e){let t,a,o;r.$id&&(a=this.ajv.getSchema(r.$id));try{void 0===a&&(a=this.ajv.compile(r)),a(e)}catch(r){t=r}return a&&("function"==typeof this.localizer&&this.localizer(a.errors),o=a.errors||void 0,a.errors=null),{errors:o,validationError:t}}validateFormData(r,e,t,o){const s=this.rawValidation(e,r),{validationError:i}=s;let n=this.transformRJSFValidationErrors(s.errors);i&&(n=[...n,{stack:i.message}]),"function"==typeof o&&(n=o(n));let d=this.toErrorSchema(n);if(i&&(d={...d,$schema:{__errors:[i.message]}}),"function"!=typeof t)return{errors:n,errorSchema:d};const c=a.getDefaultFormState(this,e,r,e,!0),l=t(c,this.createErrorHandler(c)),h=this.unwrapErrorHandler(l);return a.mergeValidationData(this,{errors:n,errorSchema:d},h)}withIdRefPrefixObject(r){for(const e in r){const t=r[e];r[e]=e===a.REF_KEY&&"string"==typeof t&&t.startsWith("#")?"__rjsf_rootSchema"+t:this.withIdRefPrefix(t)}return r}withIdRefPrefixArray(r){for(let e=0;e<r.length;e++)r[e]=this.withIdRefPrefix(r[e]);return r}isValid(r,e,t){const a=t.$id??"__rjsf_rootSchema";try{void 0===this.ajv.getSchema(a)&&this.ajv.addSchema(t,a);const o=this.withIdRefPrefix(r);let s;return o.$id&&(s=this.ajv.getSchema(o.$id)),void 0===s&&(s=this.ajv.compile(o)),s(e)}catch(r){return console.warn("Error encountered compiling schema:",r),!1}finally{this.ajv.removeSchema(a)}}withIdRefPrefix(r){return Array.isArray(r)?this.withIdRefPrefixArray([...r]):d.default(r)?this.withIdRefPrefixObject(c.default(r)):r}}function p(r,e){return void 0===r&&(r={}),new v(r,e)}var _=p();exports.customizeValidator=p,exports.default=_;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("lodash/toPath"),e=require("lodash/isObject"),t=require("lodash/clone"),a=require("@rjsf/utils"),i=require("ajv8"),o=require("ajv-formats");function n(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var s=n(r),c=n(e),d=n(t),u=n(i),f=n(o);function l(){return l=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=t[a])}return r},l.apply(this,arguments)}var h={allErrors:!0,multipleOfPrecision:8,strict:!1},v=/^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/,m=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/,p=function(){function r(r,e){this.ajv=void 0,this.localizer=void 0,this.ajv=function(r,e,t,i,o){void 0===t&&(t={}),void 0===o&&(o=u.default);var n=new o(l({},h,t));return i?f.default(n,i):!1!==i&&f.default(n),n.addFormat("data-url",m),n.addFormat("color",v),n.addKeyword(a.ADDITIONAL_PROPERTY_FLAG),n.addKeyword(a.RJSF_ADDITONAL_PROPERTIES_FLAG),Array.isArray(r)&&n.addMetaSchema(r),c.default(e)&&Object.keys(e).forEach((function(r){n.addFormat(r,e[r])})),n}(r.additionalMetaSchemas,r.customFormats,r.ajvOptionsOverrides,r.ajvFormatOptions,r.AjvClass),this.localizer=e}var e=r.prototype;return e.toErrorSchema=function(r){var e=new a.ErrorSchemaBuilder;return r.length&&r.forEach((function(r){var t=r.message,a=s.default(r.property);a.length>0&&""===a[0]&&a.splice(0,1),t&&e.addErrors(t,a)})),e.ErrorSchema},e.toErrorList=function(r,e){var t=this;if(void 0===e&&(e=[]),!r)return[];var i=[];return a.ERRORS_KEY in r&&(i=i.concat(r[a.ERRORS_KEY].map((function(r){var t="."+e.join(".");return{property:t,message:r,stack:t+" "+r}})))),Object.keys(r).reduce((function(i,o){return o!==a.ERRORS_KEY&&(i=i.concat(t.toErrorList(r[o],[].concat(e,[o])))),i}),i)},e.createErrorHandler=function(r){var e=this,t={__errors:[],addError:function(r){this.__errors.push(r)}};if(Array.isArray(r))return r.reduce((function(r,t,a){var i;return l({},r,((i={})[a]=e.createErrorHandler(t),i))}),t);if(c.default(r)){var a=r;return Object.keys(a).reduce((function(r,t){var i;return l({},r,((i={})[t]=e.createErrorHandler(a[t]),i))}),t)}return t},e.unwrapErrorHandler=function(r){var e=this;return Object.keys(r).reduce((function(t,i){var o,n;return"addError"===i?t:l({},t,i===a.ERRORS_KEY?((n={})[i]=r[i],n):((o={})[i]=e.unwrapErrorHandler(r[i]),o))}),{})},e.transformRJSFValidationErrors=function(r){return void 0===r&&(r=[]),r.map((function(r){var e=r.keyword,t=r.message,a=r.params,i=r.schemaPath,o=r.instancePath.replace(/\//g,"."),n=(o+" "+t).trim();return"missingProperty"in a&&(o=o?o+"."+a.missingProperty:a.missingProperty,n=t),{name:e,property:o,message:t,params:a,stack:n,schemaPath:i}}))},e.rawValidation=function(r,e){var t,a,i=void 0;r.$id&&(t=this.ajv.getSchema(r.$id));try{void 0===t&&(t=this.ajv.compile(r)),t(e)}catch(r){i=r}return t&&("function"==typeof this.localizer&&this.localizer(t.errors),a=t.errors||void 0,t.errors=null),{errors:a,validationError:i}},e.validateFormData=function(r,e,t,i){var o=this.rawValidation(e,r),n=o.validationError,s=this.transformRJSFValidationErrors(o.errors);n&&(s=[].concat(s,[{stack:n.message}])),"function"==typeof i&&(s=i(s));var c=this.toErrorSchema(s);if(n&&(c=l({},c,{$schema:{__errors:[n.message]}})),"function"!=typeof t)return{errors:s,errorSchema:c};var d=a.getDefaultFormState(this,e,r,e,!0),u=t(d,this.createErrorHandler(d)),f=this.unwrapErrorHandler(u);return a.mergeValidationData(this,{errors:s,errorSchema:c},f)},e.withIdRefPrefixObject=function(r){for(var e in r){var t=r[e];r[e]=e===a.REF_KEY&&"string"==typeof t&&t.startsWith("#")?"__rjsf_rootSchema"+t:this.withIdRefPrefix(t)}return r},e.withIdRefPrefixArray=function(r){for(var e=0;e<r.length;e++)r[e]=this.withIdRefPrefix(r[e]);return r},e.isValid=function(r,e,t){var a,i=null!=(a=t.$id)?a:"__rjsf_rootSchema";try{void 0===this.ajv.getSchema(i)&&this.ajv.addSchema(t,i);var o,n=this.withIdRefPrefix(r);return n.$id&&(o=this.ajv.getSchema(n.$id)),void 0===o&&(o=this.ajv.compile(n)),o(e)}catch(r){return console.warn("Error encountered compiling schema:",r),!1}finally{this.ajv.removeSchema(i)}},e.withIdRefPrefix=function(r){return Array.isArray(r)?this.withIdRefPrefixArray([].concat(r)):c.default(r)?this.withIdRefPrefixObject(d.default(r)):r},r}();function y(r,e){return void 0===r&&(r={}),new p(r,e)}var E=y();exports.customizeValidator=y,exports.default=E;
//# sourceMappingURL=validator-ajv8.cjs.production.min.js.map
import toPath from 'lodash-es/toPath';
import isObject from 'lodash-es/isObject';
import clone from 'lodash-es/clone';
import { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITONAL_PROPERTIES_FLAG, ERRORS_KEY, getDefaultFormState, mergeValidationData, REF_KEY } from '@rjsf/utils';
import { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITONAL_PROPERTIES_FLAG, ErrorSchemaBuilder, ERRORS_KEY, getDefaultFormState, mergeValidationData, REF_KEY } from '@rjsf/utils';
import Ajv from 'ajv8';
import addFormats from 'ajv-formats';
const AJV_CONFIG = {
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
var AJV_CONFIG = {
allErrors: true,

@@ -13,4 +28,4 @@ multipleOfPrecision: 8,

};
const COLOR_FORMAT_REGEX = /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/;
const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
var COLOR_FORMAT_REGEX = /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/;
var DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.

@@ -38,6 +53,3 @@ * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the

}
const ajv = new AjvClass({
...AJV_CONFIG,
...ajvOptionsOverrides
});
var ajv = new AjvClass(_extends({}, AJV_CONFIG, ajvOptionsOverrides));
if (ajvFormatOptions) {

@@ -60,3 +72,3 @@ addFormats(ajv, ajvFormatOptions);

if (isObject(customFormats)) {
Object.keys(customFormats).forEach(formatName => {
Object.keys(customFormats).forEach(function (formatName) {
ajv.addFormat(formatName, customFormats[formatName]);

@@ -68,6 +80,6 @@ });

const ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
var ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.
*/
class AJV8Validator {
var AJV8Validator = /*#__PURE__*/function () {
/** The AJV instance to use for all validations

@@ -88,12 +100,10 @@ *

*/
constructor(options, localizer) {
function AJV8Validator(options, localizer) {
this.ajv = void 0;
this.localizer = void 0;
const {
additionalMetaSchemas,
customFormats,
ajvOptionsOverrides,
ajvFormatOptions,
AjvClass
} = options;
var additionalMetaSchemas = options.additionalMetaSchemas,
customFormats = options.customFormats,
ajvOptionsOverrides = options.ajvOptionsOverrides,
ajvFormatOptions = options.ajvFormatOptions,
AjvClass = options.AjvClass;
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);

@@ -121,36 +131,21 @@ this.localizer = localizer;

*/
toErrorSchema(errors) {
if (!errors.length) {
return {};
}
return errors.reduce((errorSchema, error) => {
const {
property,
message
} = error;
const path = toPath(property);
let parent = errorSchema;
// If the property is at the root (.level1) then toPath creates
// an empty array element at the first index. Remove it.
if (path.length > 0 && path[0] === "") {
path.splice(0, 1);
}
for (const segment of path.slice(0)) {
if (!(segment in parent)) {
parent[segment] = {};
var _proto = AJV8Validator.prototype;
_proto.toErrorSchema = function toErrorSchema(errors) {
var builder = new ErrorSchemaBuilder();
if (errors.length) {
errors.forEach(function (error) {
var property = error.property,
message = error.message;
var path = toPath(property);
// If the property is at the root (.level1) then toPath creates
// an empty array element at the first index. Remove it.
if (path.length > 0 && path[0] === "") {
path.splice(0, 1);
}
parent = parent[segment];
}
if (Array.isArray(parent.__errors)) {
// We store the list of errors for this node in a property named __errors
// to avoid name collision with a possible sub schema field named
// 'errors' (see `validate.createErrorHandler`).
parent.__errors = parent.__errors.concat(message);
} else {
if (message) {
parent.__errors = [message];
builder.addErrors(message, path);
}
}
return errorSchema;
}, {});
});
}
return builder.ErrorSchema;
}

@@ -161,4 +156,5 @@ /** Converts an `errorSchema` into a list of `RJSFValidationErrors`

* @param [fieldPath=[]] - The current field path, defaults to [] if not specified
*/
toErrorList(errorSchema, fieldPath) {
*/;
_proto.toErrorList = function toErrorList(errorSchema, fieldPath) {
var _this = this;
if (fieldPath === void 0) {

@@ -170,16 +166,16 @@ fieldPath = [];

}
let errorList = [];
var errorList = [];
if (ERRORS_KEY in errorSchema) {
errorList = errorList.concat(errorSchema.__errors.map(message => {
const property = `.${fieldPath.join(".")}`;
errorList = errorList.concat(errorSchema[ERRORS_KEY].map(function (message) {
var property = "." + fieldPath.join(".");
return {
property,
message,
stack: `${property} ${message}`
property: property,
message: message,
stack: property + " " + message
};
}));
}
return Object.keys(errorSchema).reduce((acc, key) => {
return Object.keys(errorSchema).reduce(function (acc, key) {
if (key !== ERRORS_KEY) {
acc = acc.concat(this.toErrorList(errorSchema[key], [...fieldPath, key]));
acc = acc.concat(_this.toErrorList(errorSchema[key], [].concat(fieldPath, [key])));
}

@@ -193,5 +189,6 @@ return acc;

* @private
*/
createErrorHandler(formData) {
const handler = {
*/;
_proto.createErrorHandler = function createErrorHandler(formData) {
var _this2 = this;
var handler = {
// We store the list of errors for this node in a property named __errors

@@ -201,3 +198,3 @@ // to avoid name collision with a possible sub schema field named

__errors: [],
addError(message) {
addError: function addError(message) {
this.__errors.push(message);

@@ -207,16 +204,12 @@ }

if (Array.isArray(formData)) {
return formData.reduce((acc, value, key) => {
return {
...acc,
[key]: this.createErrorHandler(value)
};
return formData.reduce(function (acc, value, key) {
var _extends2;
return _extends({}, acc, (_extends2 = {}, _extends2[key] = _this2.createErrorHandler(value), _extends2));
}, handler);
}
if (isObject(formData)) {
const formObject = formData;
return Object.keys(formObject).reduce((acc, key) => {
return {
...acc,
[key]: this.createErrorHandler(formObject[key])
};
var formObject = formData;
return Object.keys(formObject).reduce(function (acc, key) {
var _extends3;
return _extends({}, acc, (_extends3 = {}, _extends3[key] = _this2.createErrorHandler(formObject[key]), _extends3));
}, handler);

@@ -230,17 +223,14 @@ }

* @private
*/
unwrapErrorHandler(errorHandler) {
return Object.keys(errorHandler).reduce((acc, key) => {
*/;
_proto.unwrapErrorHandler = function unwrapErrorHandler(errorHandler) {
var _this3 = this;
return Object.keys(errorHandler).reduce(function (acc, key) {
var _extends5;
if (key === "addError") {
return acc;
} else if (key === ERRORS_KEY) {
return {
...acc,
[key]: errorHandler[key]
};
var _extends4;
return _extends({}, acc, (_extends4 = {}, _extends4[key] = errorHandler[key], _extends4));
}
return {
...acc,
[key]: this.unwrapErrorHandler(errorHandler[key])
};
return _extends({}, acc, (_extends5 = {}, _extends5[key] = _this3.unwrapErrorHandler(errorHandler[key]), _extends5));
}, {});

@@ -253,24 +243,27 @@ }

* @private
*/
transformRJSFValidationErrors(errors) {
*/;
_proto.transformRJSFValidationErrors = function transformRJSFValidationErrors(errors) {
if (errors === void 0) {
errors = [];
}
return errors.map(e => {
const {
instancePath,
keyword,
message,
params,
schemaPath
} = e;
const property = instancePath.replace(/\//g, ".");
return errors.map(function (e) {
var instancePath = e.instancePath,
keyword = e.keyword,
message = e.message,
params = e.params,
schemaPath = e.schemaPath;
var property = instancePath.replace(/\//g, ".");
var stack = (property + " " + message).trim();
if ("missingProperty" in params) {
property = property ? property + "." + params.missingProperty : params.missingProperty;
stack = message;
}
// put data in expected format
return {
name: keyword,
property,
message,
params,
stack: `${property} ${message}`.trim(),
schemaPath
property: property,
message: message,
params: params,
stack: stack,
schemaPath: schemaPath
};

@@ -284,6 +277,6 @@ });

* @param formData - The form data to validate
*/
rawValidation(schema, formData) {
let compilationError = undefined;
let compiledValidator;
*/;
_proto.rawValidation = function rawValidation(schema, formData) {
var compilationError = undefined;
var compiledValidator;
if (schema["$id"]) {

@@ -300,3 +293,3 @@ compiledValidator = this.ajv.getSchema(schema["$id"]);

}
let errors;
var errors;
if (compiledValidator) {

@@ -324,13 +317,11 @@ if (typeof this.localizer === "function") {

* @param [transformErrors] - An optional function that is used to transform errors after AJV validation
*/
validateFormData(formData, schema, customValidate, transformErrors) {
const rawErrors = this.rawValidation(schema, formData);
const {
validationError: invalidSchemaError
} = rawErrors;
let errors = this.transformRJSFValidationErrors(rawErrors.errors);
*/;
_proto.validateFormData = function validateFormData(formData, schema, customValidate, transformErrors) {
var rawErrors = this.rawValidation(schema, formData);
var invalidSchemaError = rawErrors.validationError;
var errors = this.transformRJSFValidationErrors(rawErrors.errors);
if (invalidSchemaError) {
errors = [...errors, {
errors = [].concat(errors, [{
stack: invalidSchemaError.message
}];
}]);
}

@@ -340,24 +331,23 @@ if (typeof transformErrors === "function") {

}
let errorSchema = this.toErrorSchema(errors);
var errorSchema = this.toErrorSchema(errors);
if (invalidSchemaError) {
errorSchema = {
...errorSchema,
errorSchema = _extends({}, errorSchema, {
$schema: {
__errors: [invalidSchemaError.message]
}
};
});
}
if (typeof customValidate !== "function") {
return {
errors,
errorSchema
errors: errors,
errorSchema: errorSchema
};
}
// Include form data with undefined values, which is required for custom validation.
const newFormData = getDefaultFormState(this, schema, formData, schema, true);
const errorHandler = customValidate(newFormData, this.createErrorHandler(newFormData));
const userErrorSchema = this.unwrapErrorHandler(errorHandler);
var newFormData = getDefaultFormState(this, schema, formData, schema, true);
var errorHandler = customValidate(newFormData, this.createErrorHandler(newFormData));
var userErrorSchema = this.unwrapErrorHandler(errorHandler);
return mergeValidationData(this, {
errors,
errorSchema
errors: errors,
errorSchema: errorSchema
}, userErrorSchema);

@@ -370,7 +360,7 @@ }

* @private
*/
withIdRefPrefixObject(node) {
for (const key in node) {
const realObj = node;
const value = realObj[key];
*/;
_proto.withIdRefPrefixObject = function withIdRefPrefixObject(node) {
for (var key in node) {
var realObj = node;
var value = realObj[key];
if (key === REF_KEY && typeof value === "string" && value.startsWith("#")) {

@@ -389,5 +379,5 @@ realObj[key] = ROOT_SCHEMA_PREFIX + value;

* @private
*/
withIdRefPrefixArray(node) {
for (let i = 0; i < node.length; i++) {
*/;
_proto.withIdRefPrefixArray = function withIdRefPrefixArray(node) {
for (var i = 0; i < node.length; i++) {
node[i] = this.withIdRefPrefix(node[i]);

@@ -404,5 +394,6 @@ }

* @param rootSchema - The root schema used to provide $ref resolutions
*/
isValid(schema, formData, rootSchema) {
const rootSchemaId = rootSchema["$id"] ?? ROOT_SCHEMA_PREFIX;
*/;
_proto.isValid = function isValid(schema, formData, rootSchema) {
var _rootSchema$$id;
var rootSchemaId = (_rootSchema$$id = rootSchema["$id"]) != null ? _rootSchema$$id : ROOT_SCHEMA_PREFIX;
try {

@@ -416,4 +407,4 @@ // add the rootSchema ROOT_SCHEMA_PREFIX as id.

}
const schemaWithIdRefPrefix = this.withIdRefPrefix(schema);
let compiledValidator;
var schemaWithIdRefPrefix = this.withIdRefPrefix(schema);
var compiledValidator;
if (schemaWithIdRefPrefix["$id"]) {

@@ -425,3 +416,3 @@ compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix["$id"]);

}
const result = compiledValidator(formData);
var result = compiledValidator(formData);
return result;

@@ -442,6 +433,6 @@ } catch (e) {

* @protected
*/
withIdRefPrefix(schemaNode) {
*/;
_proto.withIdRefPrefix = function withIdRefPrefix(schemaNode) {
if (Array.isArray(schemaNode)) {
return this.withIdRefPrefixArray([...schemaNode]);
return this.withIdRefPrefixArray([].concat(schemaNode));
}

@@ -452,4 +443,5 @@ if (isObject(schemaNode)) {

return schemaNode;
}
}
};
return AJV8Validator;
}();

@@ -456,0 +448,0 @@ /** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if

@@ -15,3 +15,18 @@ (function (global, factory) {

const AJV_CONFIG = {
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
var AJV_CONFIG = {
allErrors: true,

@@ -21,4 +36,4 @@ multipleOfPrecision: 8,

};
const COLOR_FORMAT_REGEX = /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/;
const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
var COLOR_FORMAT_REGEX = /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/;
var DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.

@@ -46,6 +61,3 @@ * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the

}
const ajv = new AjvClass({
...AJV_CONFIG,
...ajvOptionsOverrides
});
var ajv = new AjvClass(_extends({}, AJV_CONFIG, ajvOptionsOverrides));
if (ajvFormatOptions) {

@@ -68,3 +80,3 @@ addFormats__default["default"](ajv, ajvFormatOptions);

if (isObject__default["default"](customFormats)) {
Object.keys(customFormats).forEach(formatName => {
Object.keys(customFormats).forEach(function (formatName) {
ajv.addFormat(formatName, customFormats[formatName]);

@@ -76,6 +88,6 @@ });

const ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
var ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.
*/
class AJV8Validator {
var AJV8Validator = /*#__PURE__*/function () {
/** The AJV instance to use for all validations

@@ -96,12 +108,10 @@ *

*/
constructor(options, localizer) {
function AJV8Validator(options, localizer) {
this.ajv = void 0;
this.localizer = void 0;
const {
additionalMetaSchemas,
customFormats,
ajvOptionsOverrides,
ajvFormatOptions,
AjvClass
} = options;
var additionalMetaSchemas = options.additionalMetaSchemas,
customFormats = options.customFormats,
ajvOptionsOverrides = options.ajvOptionsOverrides,
ajvFormatOptions = options.ajvFormatOptions,
AjvClass = options.AjvClass;
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);

@@ -129,36 +139,21 @@ this.localizer = localizer;

*/
toErrorSchema(errors) {
if (!errors.length) {
return {};
}
return errors.reduce((errorSchema, error) => {
const {
property,
message
} = error;
const path = toPath__default["default"](property);
let parent = errorSchema;
// If the property is at the root (.level1) then toPath creates
// an empty array element at the first index. Remove it.
if (path.length > 0 && path[0] === "") {
path.splice(0, 1);
}
for (const segment of path.slice(0)) {
if (!(segment in parent)) {
parent[segment] = {};
var _proto = AJV8Validator.prototype;
_proto.toErrorSchema = function toErrorSchema(errors) {
var builder = new utils.ErrorSchemaBuilder();
if (errors.length) {
errors.forEach(function (error) {
var property = error.property,
message = error.message;
var path = toPath__default["default"](property);
// If the property is at the root (.level1) then toPath creates
// an empty array element at the first index. Remove it.
if (path.length > 0 && path[0] === "") {
path.splice(0, 1);
}
parent = parent[segment];
}
if (Array.isArray(parent.__errors)) {
// We store the list of errors for this node in a property named __errors
// to avoid name collision with a possible sub schema field named
// 'errors' (see `validate.createErrorHandler`).
parent.__errors = parent.__errors.concat(message);
} else {
if (message) {
parent.__errors = [message];
builder.addErrors(message, path);
}
}
return errorSchema;
}, {});
});
}
return builder.ErrorSchema;
}

@@ -169,4 +164,5 @@ /** Converts an `errorSchema` into a list of `RJSFValidationErrors`

* @param [fieldPath=[]] - The current field path, defaults to [] if not specified
*/
toErrorList(errorSchema, fieldPath) {
*/;
_proto.toErrorList = function toErrorList(errorSchema, fieldPath) {
var _this = this;
if (fieldPath === void 0) {

@@ -178,16 +174,16 @@ fieldPath = [];

}
let errorList = [];
var errorList = [];
if (utils.ERRORS_KEY in errorSchema) {
errorList = errorList.concat(errorSchema.__errors.map(message => {
const property = `.${fieldPath.join(".")}`;
errorList = errorList.concat(errorSchema[utils.ERRORS_KEY].map(function (message) {
var property = "." + fieldPath.join(".");
return {
property,
message,
stack: `${property} ${message}`
property: property,
message: message,
stack: property + " " + message
};
}));
}
return Object.keys(errorSchema).reduce((acc, key) => {
return Object.keys(errorSchema).reduce(function (acc, key) {
if (key !== utils.ERRORS_KEY) {
acc = acc.concat(this.toErrorList(errorSchema[key], [...fieldPath, key]));
acc = acc.concat(_this.toErrorList(errorSchema[key], [].concat(fieldPath, [key])));
}

@@ -201,5 +197,6 @@ return acc;

* @private
*/
createErrorHandler(formData) {
const handler = {
*/;
_proto.createErrorHandler = function createErrorHandler(formData) {
var _this2 = this;
var handler = {
// We store the list of errors for this node in a property named __errors

@@ -209,3 +206,3 @@ // to avoid name collision with a possible sub schema field named

__errors: [],
addError(message) {
addError: function addError(message) {
this.__errors.push(message);

@@ -215,16 +212,12 @@ }

if (Array.isArray(formData)) {
return formData.reduce((acc, value, key) => {
return {
...acc,
[key]: this.createErrorHandler(value)
};
return formData.reduce(function (acc, value, key) {
var _extends2;
return _extends({}, acc, (_extends2 = {}, _extends2[key] = _this2.createErrorHandler(value), _extends2));
}, handler);
}
if (isObject__default["default"](formData)) {
const formObject = formData;
return Object.keys(formObject).reduce((acc, key) => {
return {
...acc,
[key]: this.createErrorHandler(formObject[key])
};
var formObject = formData;
return Object.keys(formObject).reduce(function (acc, key) {
var _extends3;
return _extends({}, acc, (_extends3 = {}, _extends3[key] = _this2.createErrorHandler(formObject[key]), _extends3));
}, handler);

@@ -238,17 +231,14 @@ }

* @private
*/
unwrapErrorHandler(errorHandler) {
return Object.keys(errorHandler).reduce((acc, key) => {
*/;
_proto.unwrapErrorHandler = function unwrapErrorHandler(errorHandler) {
var _this3 = this;
return Object.keys(errorHandler).reduce(function (acc, key) {
var _extends5;
if (key === "addError") {
return acc;
} else if (key === utils.ERRORS_KEY) {
return {
...acc,
[key]: errorHandler[key]
};
var _extends4;
return _extends({}, acc, (_extends4 = {}, _extends4[key] = errorHandler[key], _extends4));
}
return {
...acc,
[key]: this.unwrapErrorHandler(errorHandler[key])
};
return _extends({}, acc, (_extends5 = {}, _extends5[key] = _this3.unwrapErrorHandler(errorHandler[key]), _extends5));
}, {});

@@ -261,24 +251,27 @@ }

* @private
*/
transformRJSFValidationErrors(errors) {
*/;
_proto.transformRJSFValidationErrors = function transformRJSFValidationErrors(errors) {
if (errors === void 0) {
errors = [];
}
return errors.map(e => {
const {
instancePath,
keyword,
message,
params,
schemaPath
} = e;
const property = instancePath.replace(/\//g, ".");
return errors.map(function (e) {
var instancePath = e.instancePath,
keyword = e.keyword,
message = e.message,
params = e.params,
schemaPath = e.schemaPath;
var property = instancePath.replace(/\//g, ".");
var stack = (property + " " + message).trim();
if ("missingProperty" in params) {
property = property ? property + "." + params.missingProperty : params.missingProperty;
stack = message;
}
// put data in expected format
return {
name: keyword,
property,
message,
params,
stack: `${property} ${message}`.trim(),
schemaPath
property: property,
message: message,
params: params,
stack: stack,
schemaPath: schemaPath
};

@@ -292,6 +285,6 @@ });

* @param formData - The form data to validate
*/
rawValidation(schema, formData) {
let compilationError = undefined;
let compiledValidator;
*/;
_proto.rawValidation = function rawValidation(schema, formData) {
var compilationError = undefined;
var compiledValidator;
if (schema["$id"]) {

@@ -308,3 +301,3 @@ compiledValidator = this.ajv.getSchema(schema["$id"]);

}
let errors;
var errors;
if (compiledValidator) {

@@ -332,13 +325,11 @@ if (typeof this.localizer === "function") {

* @param [transformErrors] - An optional function that is used to transform errors after AJV validation
*/
validateFormData(formData, schema, customValidate, transformErrors) {
const rawErrors = this.rawValidation(schema, formData);
const {
validationError: invalidSchemaError
} = rawErrors;
let errors = this.transformRJSFValidationErrors(rawErrors.errors);
*/;
_proto.validateFormData = function validateFormData(formData, schema, customValidate, transformErrors) {
var rawErrors = this.rawValidation(schema, formData);
var invalidSchemaError = rawErrors.validationError;
var errors = this.transformRJSFValidationErrors(rawErrors.errors);
if (invalidSchemaError) {
errors = [...errors, {
errors = [].concat(errors, [{
stack: invalidSchemaError.message
}];
}]);
}

@@ -348,24 +339,23 @@ if (typeof transformErrors === "function") {

}
let errorSchema = this.toErrorSchema(errors);
var errorSchema = this.toErrorSchema(errors);
if (invalidSchemaError) {
errorSchema = {
...errorSchema,
errorSchema = _extends({}, errorSchema, {
$schema: {
__errors: [invalidSchemaError.message]
}
};
});
}
if (typeof customValidate !== "function") {
return {
errors,
errorSchema
errors: errors,
errorSchema: errorSchema
};
}
// Include form data with undefined values, which is required for custom validation.
const newFormData = utils.getDefaultFormState(this, schema, formData, schema, true);
const errorHandler = customValidate(newFormData, this.createErrorHandler(newFormData));
const userErrorSchema = this.unwrapErrorHandler(errorHandler);
var newFormData = utils.getDefaultFormState(this, schema, formData, schema, true);
var errorHandler = customValidate(newFormData, this.createErrorHandler(newFormData));
var userErrorSchema = this.unwrapErrorHandler(errorHandler);
return utils.mergeValidationData(this, {
errors,
errorSchema
errors: errors,
errorSchema: errorSchema
}, userErrorSchema);

@@ -378,7 +368,7 @@ }

* @private
*/
withIdRefPrefixObject(node) {
for (const key in node) {
const realObj = node;
const value = realObj[key];
*/;
_proto.withIdRefPrefixObject = function withIdRefPrefixObject(node) {
for (var key in node) {
var realObj = node;
var value = realObj[key];
if (key === utils.REF_KEY && typeof value === "string" && value.startsWith("#")) {

@@ -397,5 +387,5 @@ realObj[key] = ROOT_SCHEMA_PREFIX + value;

* @private
*/
withIdRefPrefixArray(node) {
for (let i = 0; i < node.length; i++) {
*/;
_proto.withIdRefPrefixArray = function withIdRefPrefixArray(node) {
for (var i = 0; i < node.length; i++) {
node[i] = this.withIdRefPrefix(node[i]);

@@ -412,5 +402,6 @@ }

* @param rootSchema - The root schema used to provide $ref resolutions
*/
isValid(schema, formData, rootSchema) {
const rootSchemaId = rootSchema["$id"] ?? ROOT_SCHEMA_PREFIX;
*/;
_proto.isValid = function isValid(schema, formData, rootSchema) {
var _rootSchema$$id;
var rootSchemaId = (_rootSchema$$id = rootSchema["$id"]) != null ? _rootSchema$$id : ROOT_SCHEMA_PREFIX;
try {

@@ -424,4 +415,4 @@ // add the rootSchema ROOT_SCHEMA_PREFIX as id.

}
const schemaWithIdRefPrefix = this.withIdRefPrefix(schema);
let compiledValidator;
var schemaWithIdRefPrefix = this.withIdRefPrefix(schema);
var compiledValidator;
if (schemaWithIdRefPrefix["$id"]) {

@@ -433,3 +424,3 @@ compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix["$id"]);

}
const result = compiledValidator(formData);
var result = compiledValidator(formData);
return result;

@@ -450,6 +441,6 @@ } catch (e) {

* @protected
*/
withIdRefPrefix(schemaNode) {
*/;
_proto.withIdRefPrefix = function withIdRefPrefix(schemaNode) {
if (Array.isArray(schemaNode)) {
return this.withIdRefPrefixArray([...schemaNode]);
return this.withIdRefPrefixArray([].concat(schemaNode));
}

@@ -460,4 +451,5 @@ if (isObject__default["default"](schemaNode)) {

return schemaNode;
}
}
};
return AJV8Validator;
}();

@@ -464,0 +456,0 @@ /** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if

@@ -1,2 +0,2 @@

!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("lodash-es/toPath"),require("lodash-es/isObject"),require("lodash-es/clone"),require("@rjsf/utils"),require("ajv8"),require("ajv-formats")):"function"==typeof define&&define.amd?define(["exports","lodash-es/toPath","lodash-es/isObject","lodash-es/clone","@rjsf/utils","ajv8","ajv-formats"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self)["@rjsf/validator-ajv8"]={},r.toPath,r.isObject,r.clone,r.utils,r.Ajv,r.addFormats)}(this,(function(r,e,t,a,o,s,i){"use strict";function n(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var d=n(e),c=n(t),l=n(a),h=n(s),u=n(i);const f={allErrors:!0,multipleOfPrecision:8,strict:!1},m=/^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/,v=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/,p="__rjsf_rootSchema";class y{constructor(r,e){this.ajv=void 0,this.localizer=void 0;const{additionalMetaSchemas:t,customFormats:a,ajvOptionsOverrides:s,ajvFormatOptions:i,AjvClass:n}=r;this.ajv=function(r,e,t,a,s){void 0===t&&(t={}),void 0===s&&(s=h.default);const i=new s({...f,...t});return a?u.default(i,a):!1!==a&&u.default(i),i.addFormat("data-url",v),i.addFormat("color",m),i.addKeyword(o.ADDITIONAL_PROPERTY_FLAG),i.addKeyword(o.RJSF_ADDITONAL_PROPERTIES_FLAG),Array.isArray(r)&&i.addMetaSchema(r),c.default(e)&&Object.keys(e).forEach((r=>{i.addFormat(r,e[r])})),i}(t,a,s,i,n),this.localizer=e}toErrorSchema(r){return r.length?r.reduce(((r,e)=>{const{property:t,message:a}=e,o=d.default(t);let s=r;o.length>0&&""===o[0]&&o.splice(0,1);for(const r of o.slice(0))r in s||(s[r]={}),s=s[r];return Array.isArray(s.__errors)?s.__errors=s.__errors.concat(a):a&&(s.__errors=[a]),r}),{}):{}}toErrorList(r,e){if(void 0===e&&(e=[]),!r)return[];let t=[];return o.ERRORS_KEY in r&&(t=t.concat(r.__errors.map((r=>{const t=`.${e.join(".")}`;return{property:t,message:r,stack:`${t} ${r}`}})))),Object.keys(r).reduce(((t,a)=>(a!==o.ERRORS_KEY&&(t=t.concat(this.toErrorList(r[a],[...e,a]))),t)),t)}createErrorHandler(r){const e={__errors:[],addError(r){this.__errors.push(r)}};if(Array.isArray(r))return r.reduce(((r,e,t)=>({...r,[t]:this.createErrorHandler(e)})),e);if(c.default(r)){const t=r;return Object.keys(t).reduce(((r,e)=>({...r,[e]:this.createErrorHandler(t[e])})),e)}return e}unwrapErrorHandler(r){return Object.keys(r).reduce(((e,t)=>"addError"===t?e:t===o.ERRORS_KEY?{...e,[t]:r[t]}:{...e,[t]:this.unwrapErrorHandler(r[t])}),{})}transformRJSFValidationErrors(r){return void 0===r&&(r=[]),r.map((r=>{const{instancePath:e,keyword:t,message:a,params:o,schemaPath:s}=r,i=e.replace(/\//g,".");return{name:t,property:i,message:a,params:o,stack:`${i} ${a}`.trim(),schemaPath:s}}))}rawValidation(r,e){let t,a,o;r.$id&&(a=this.ajv.getSchema(r.$id));try{void 0===a&&(a=this.ajv.compile(r)),a(e)}catch(r){t=r}return a&&("function"==typeof this.localizer&&this.localizer(a.errors),o=a.errors||void 0,a.errors=null),{errors:o,validationError:t}}validateFormData(r,e,t,a){const s=this.rawValidation(e,r),{validationError:i}=s;let n=this.transformRJSFValidationErrors(s.errors);i&&(n=[...n,{stack:i.message}]),"function"==typeof a&&(n=a(n));let d=this.toErrorSchema(n);if(i&&(d={...d,$schema:{__errors:[i.message]}}),"function"!=typeof t)return{errors:n,errorSchema:d};const c=o.getDefaultFormState(this,e,r,e,!0),l=t(c,this.createErrorHandler(c)),h=this.unwrapErrorHandler(l);return o.mergeValidationData(this,{errors:n,errorSchema:d},h)}withIdRefPrefixObject(r){for(const e in r){const t=r[e];r[e]=e===o.REF_KEY&&"string"==typeof t&&t.startsWith("#")?p+t:this.withIdRefPrefix(t)}return r}withIdRefPrefixArray(r){for(let e=0;e<r.length;e++)r[e]=this.withIdRefPrefix(r[e]);return r}isValid(r,e,t){const a=t.$id??p;try{void 0===this.ajv.getSchema(a)&&this.ajv.addSchema(t,a);const o=this.withIdRefPrefix(r);let s;return o.$id&&(s=this.ajv.getSchema(o.$id)),void 0===s&&(s=this.ajv.compile(o)),s(e)}catch(r){return console.warn("Error encountered compiling schema:",r),!1}finally{this.ajv.removeSchema(a)}}withIdRefPrefix(r){return Array.isArray(r)?this.withIdRefPrefixArray([...r]):c.default(r)?this.withIdRefPrefixObject(l.default(r)):r}}function j(r,e){return void 0===r&&(r={}),new y(r,e)}var E=j();r.customizeValidator=j,r.default=E,Object.defineProperty(r,"__esModule",{value:!0})}));
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("lodash-es/toPath"),require("lodash-es/isObject"),require("lodash-es/clone"),require("@rjsf/utils"),require("ajv8"),require("ajv-formats")):"function"==typeof define&&define.amd?define(["exports","lodash-es/toPath","lodash-es/isObject","lodash-es/clone","@rjsf/utils","ajv8","ajv-formats"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self)["@rjsf/validator-ajv8"]={},r.toPath,r.isObject,r.clone,r.utils,r.Ajv,r.addFormats)}(this,(function(r,e,t,a,i,o,n){"use strict";function s(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var c=s(e),d=s(t),u=s(a),f=s(o),l=s(n);function h(){return h=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=t[a])}return r},h.apply(this,arguments)}var v={allErrors:!0,multipleOfPrecision:8,strict:!1},m=/^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/,p=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/,y="__rjsf_rootSchema",j=function(){function r(r,e){this.ajv=void 0,this.localizer=void 0,this.ajv=function(r,e,t,a,o){void 0===t&&(t={}),void 0===o&&(o=f.default);var n=new o(h({},v,t));return a?l.default(n,a):!1!==a&&l.default(n),n.addFormat("data-url",p),n.addFormat("color",m),n.addKeyword(i.ADDITIONAL_PROPERTY_FLAG),n.addKeyword(i.RJSF_ADDITONAL_PROPERTIES_FLAG),Array.isArray(r)&&n.addMetaSchema(r),d.default(e)&&Object.keys(e).forEach((function(r){n.addFormat(r,e[r])})),n}(r.additionalMetaSchemas,r.customFormats,r.ajvOptionsOverrides,r.ajvFormatOptions,r.AjvClass),this.localizer=e}var e=r.prototype;return e.toErrorSchema=function(r){var e=new i.ErrorSchemaBuilder;return r.length&&r.forEach((function(r){var t=r.message,a=c.default(r.property);a.length>0&&""===a[0]&&a.splice(0,1),t&&e.addErrors(t,a)})),e.ErrorSchema},e.toErrorList=function(r,e){var t=this;if(void 0===e&&(e=[]),!r)return[];var a=[];return i.ERRORS_KEY in r&&(a=a.concat(r[i.ERRORS_KEY].map((function(r){var t="."+e.join(".");return{property:t,message:r,stack:t+" "+r}})))),Object.keys(r).reduce((function(a,o){return o!==i.ERRORS_KEY&&(a=a.concat(t.toErrorList(r[o],[].concat(e,[o])))),a}),a)},e.createErrorHandler=function(r){var e=this,t={__errors:[],addError:function(r){this.__errors.push(r)}};if(Array.isArray(r))return r.reduce((function(r,t,a){var i;return h({},r,((i={})[a]=e.createErrorHandler(t),i))}),t);if(d.default(r)){var a=r;return Object.keys(a).reduce((function(r,t){var i;return h({},r,((i={})[t]=e.createErrorHandler(a[t]),i))}),t)}return t},e.unwrapErrorHandler=function(r){var e=this;return Object.keys(r).reduce((function(t,a){var o,n;return"addError"===a?t:h({},t,a===i.ERRORS_KEY?((n={})[a]=r[a],n):((o={})[a]=e.unwrapErrorHandler(r[a]),o))}),{})},e.transformRJSFValidationErrors=function(r){return void 0===r&&(r=[]),r.map((function(r){var e=r.keyword,t=r.message,a=r.params,i=r.schemaPath,o=r.instancePath.replace(/\//g,"."),n=(o+" "+t).trim();return"missingProperty"in a&&(o=o?o+"."+a.missingProperty:a.missingProperty,n=t),{name:e,property:o,message:t,params:a,stack:n,schemaPath:i}}))},e.rawValidation=function(r,e){var t,a,i=void 0;r.$id&&(t=this.ajv.getSchema(r.$id));try{void 0===t&&(t=this.ajv.compile(r)),t(e)}catch(r){i=r}return t&&("function"==typeof this.localizer&&this.localizer(t.errors),a=t.errors||void 0,t.errors=null),{errors:a,validationError:i}},e.validateFormData=function(r,e,t,a){var o=this.rawValidation(e,r),n=o.validationError,s=this.transformRJSFValidationErrors(o.errors);n&&(s=[].concat(s,[{stack:n.message}])),"function"==typeof a&&(s=a(s));var c=this.toErrorSchema(s);if(n&&(c=h({},c,{$schema:{__errors:[n.message]}})),"function"!=typeof t)return{errors:s,errorSchema:c};var d=i.getDefaultFormState(this,e,r,e,!0),u=t(d,this.createErrorHandler(d)),f=this.unwrapErrorHandler(u);return i.mergeValidationData(this,{errors:s,errorSchema:c},f)},e.withIdRefPrefixObject=function(r){for(var e in r){var t=r[e];r[e]=e===i.REF_KEY&&"string"==typeof t&&t.startsWith("#")?y+t:this.withIdRefPrefix(t)}return r},e.withIdRefPrefixArray=function(r){for(var e=0;e<r.length;e++)r[e]=this.withIdRefPrefix(r[e]);return r},e.isValid=function(r,e,t){var a,i=null!=(a=t.$id)?a:y;try{void 0===this.ajv.getSchema(i)&&this.ajv.addSchema(t,i);var o,n=this.withIdRefPrefix(r);return n.$id&&(o=this.ajv.getSchema(n.$id)),void 0===o&&(o=this.ajv.compile(n)),o(e)}catch(r){return console.warn("Error encountered compiling schema:",r),!1}finally{this.ajv.removeSchema(i)}},e.withIdRefPrefix=function(r){return Array.isArray(r)?this.withIdRefPrefixArray([].concat(r)):d.default(r)?this.withIdRefPrefixObject(u.default(r)):r},r}();function E(r,e){return void 0===r&&(r={}),new j(r,e)}var b=E();r.customizeValidator=E,r.default=b,Object.defineProperty(r,"__esModule",{value:!0})}));
//# sourceMappingURL=validator-ajv8.umd.production.min.js.map
{
"name": "@rjsf/validator-ajv8",
"version": "5.0.0-beta.14",
"version": "5.0.0-beta.15",
"main": "dist/index.js",

@@ -45,3 +45,3 @@ "module": "dist/validator-ajv8.esm.js",

"@babel/preset-react": "^7.18.6",
"@rjsf/utils": "^5.0.0-beta.14",
"@rjsf/utils": "^5.0.0-beta.15",
"@types/jest-expect-message": "^1.1.0",

@@ -76,3 +76,3 @@ "@types/json-schema": "^7.0.9",

"license": "Apache-2.0",
"gitHead": "a0f9a938e4551a42d5c94f8673b13b937279cdc5"
"gitHead": "965c0e41f1ab1261bbc1f9a1e9f64fc526426087"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc