Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rjsf/validator-ajv6

Package Overview
Dependencies
Maintainers
2
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rjsf/validator-ajv6 - npm Package Compare versions

Comparing version 5.10.0 to 5.11.1

157

dist/validator-ajv6.cjs.development.js

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

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 = {
const AJV_CONFIG = {
errorDataPath: 'property',

@@ -37,4 +22,4 @@ allErrors: true,

};
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,(.*)$/;
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,(.*)$/;
/** Creates an Ajv version 6 implementation object with standard support for the 'color` and `data-url` custom formats.

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

*/
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides) {
if (ajvOptionsOverrides === void 0) {
ajvOptionsOverrides = {};
}
var ajv = new Ajv__default["default"](_extends({}, AJV_CONFIG, ajvOptionsOverrides));
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides = {}) {
const ajv = new Ajv__default["default"]({
...AJV_CONFIG,
...ajvOptionsOverrides
});
// add custom formats

@@ -66,3 +51,3 @@ ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);

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

@@ -78,3 +63,3 @@ });

*/
var AJV6Validator = /*#__PURE__*/function () {
class AJV6Validator {
/** Constructs an `AJV6Validator` instance using the `options`

@@ -84,3 +69,3 @@ *

*/
function AJV6Validator(options) {
constructor(options) {
/** The AJV instance to use for all validations

@@ -91,5 +76,7 @@ *

this.ajv = void 0;
var additionalMetaSchemas = options.additionalMetaSchemas,
customFormats = options.customFormats,
ajvOptionsOverrides = options.ajvOptionsOverrides;
const {
additionalMetaSchemas,
customFormats,
ajvOptionsOverrides
} = options;
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides);

@@ -104,7 +91,3 @@ }

*/
var _proto = AJV6Validator.prototype;
_proto.toErrorList = function toErrorList(errorSchema, fieldPath) {
if (fieldPath === void 0) {
fieldPath = [];
}
toErrorList(errorSchema, fieldPath = []) {
return utils.toErrorList(errorSchema, fieldPath);

@@ -117,22 +100,21 @@ }

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

@@ -146,5 +128,5 @@ });

* @param formData - The form data to validate
*/;
_proto.rawValidation = function rawValidation(schema, formData) {
var validationError = undefined;
*/
rawValidation(schema, formData) {
let validationError = undefined;
try {

@@ -155,3 +137,3 @@ this.ajv.validate(schema, formData);

}
var errors = this.ajv.errors || undefined;
const errors = this.ajv.errors || undefined;
// Clear errors to prevent persistent errors, see #1104

@@ -161,3 +143,3 @@ this.ajv.errors = null;

errors: errors,
validationError: validationError
validationError
};

@@ -175,13 +157,15 @@ }

* @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
*/;
_proto.validateFormData = function validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
var rootSchema = schema;
var rawErrors = this.rawValidation(schema, formData);
var validationError = rawErrors.validationError;
var errors = this.transformRJSFValidationErrors(rawErrors.errors);
var noProperMetaSchema = validationError && validationError.message && validationError.message.includes('no schema with key or ref ');
*/
validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
const rootSchema = schema;
const rawErrors = this.rawValidation(schema, formData);
const {
validationError
} = rawErrors;
let errors = this.transformRJSFValidationErrors(rawErrors.errors);
const noProperMetaSchema = validationError && validationError.message && validationError.message.includes('no schema with key or ref ');
if (noProperMetaSchema) {
errors = [].concat(errors, [{
errors = [...errors, {
stack: validationError.message
}]);
}];
}

@@ -191,23 +175,26 @@ if (typeof transformErrors === 'function') {

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

@@ -222,4 +209,4 @@ }

* @param rootSchema - The root schema used to provide $ref resolutions
*/;
_proto.isValid = function isValid(schema, formData, rootSchema) {
*/
isValid(schema, formData, rootSchema) {
try {

@@ -230,3 +217,3 @@ // add the rootSchema ROOT_SCHEMA_PREFIX as id.

// that lives in the rootSchema but not in the schema in question.
var result = this.ajv.addSchema(rootSchema, utils.ROOT_SCHEMA_PREFIX).validate(utils.withIdRefPrefix(schema), formData);
const result = this.ajv.addSchema(rootSchema, utils.ROOT_SCHEMA_PREFIX).validate(utils.withIdRefPrefix(schema), formData);
return result;

@@ -239,5 +226,4 @@ } catch (e) {

}
};
return AJV6Validator;
}();
}
}

@@ -250,6 +236,3 @@ /** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if

*/
function customizeValidator(options) {
if (options === void 0) {
options = {};
}
function customizeValidator(options = {}) {
return new AJV6Validator(options);

@@ -256,0 +239,0 @@ }

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("@rjsf/utils"),a=require("ajv"),e=require("lodash/isObject");function t(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var o=t(a),i=t(e);function s(){return s=Object.assign?Object.assign.bind():function(r){for(var a=1;a<arguments.length;a++){var e=arguments[a];for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t])}return r},s.apply(this,arguments)}var n={errorDataPath:"property",allErrors:!0,multipleOfPrecision:8,schemaId:"auto",unknownFormats:"ignore"},d=/^(#?([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*\)))$/,u=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/,c=function(){function a(r){this.ajv=void 0,this.ajv=function(r,a,e){void 0===e&&(e={});var t=new o.default(s({},n,e));return t.addFormat("data-url",u),t.addFormat("color",d),Array.isArray(r)&&t.addMetaSchema(r),i.default(a)&&Object.keys(a).forEach((function(r){t.addFormat(r,a[r])})),t}(r.additionalMetaSchemas,r.customFormats,r.ajvOptionsOverrides)}var e=a.prototype;return e.toErrorList=function(a,e){return void 0===e&&(e=[]),r.toErrorList(a,e)},e.transformRJSFValidationErrors=function(r){return void 0===r&&(r=[]),r.map((function(r){var a=r.message,e=r.schemaPath,t=""+r.dataPath;return{name:r.keyword,property:t,message:a,params:r.params,stack:(t+" "+a).trim(),schemaPath:e}}))},e.rawValidation=function(r,a){var e=void 0;try{this.ajv.validate(r,a)}catch(r){e=r}var t=this.ajv.errors||void 0;return this.ajv.errors=null,{errors:t,validationError:e}},e.validateFormData=function(a,e,t,o,i){var n=e,d=this.rawValidation(e,a),u=d.validationError,c=this.transformRJSFValidationErrors(d.errors),l=u&&u.message&&u.message.includes("no schema with key or ref ");l&&(c=[].concat(c,[{stack:u.message}])),"function"==typeof o&&(c=o(c,i));var v=r.toErrorSchema(c);if(l&&(v=s({},v,{$schema:{__errors:[u.message]}})),"function"!=typeof t)return{errors:c,errorSchema:v};var f=r.getDefaultFormState(this,e,a,n,!0),m=t(f,r.createErrorHandler(f),i),h=r.unwrapErrorHandler(m);return r.validationDataMerge({errors:c,errorSchema:v},h)},e.isValid=function(a,e,t){try{return this.ajv.addSchema(t,r.ROOT_SCHEMA_PREFIX).validate(r.withIdRefPrefix(a),e)}catch(r){return!1}finally{this.ajv.removeSchema(r.ROOT_SCHEMA_PREFIX)}},a}();function l(r){return void 0===r&&(r={}),new c(r)}var v=l();exports.customizeValidator=l,exports.default=v;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("@rjsf/utils"),a=require("ajv"),e=require("lodash/isObject");function t(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var s=t(a),o=t(e);const i={errorDataPath:"property",allErrors:!0,multipleOfPrecision:8,schemaId:"auto",unknownFormats:"ignore"},n=/^(#?([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*\)))$/,d=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;class l{constructor(r){this.ajv=void 0;const{additionalMetaSchemas:a,customFormats:e,ajvOptionsOverrides:t}=r;this.ajv=function(r,a,e={}){const t=new s.default({...i,...e});return t.addFormat("data-url",d),t.addFormat("color",n),Array.isArray(r)&&t.addMetaSchema(r),o.default(a)&&Object.keys(a).forEach((r=>{t.addFormat(r,a[r])})),t}(a,e,t)}toErrorList(a,e=[]){return r.toErrorList(a,e)}transformRJSFValidationErrors(r=[]){return r.map((r=>{const{dataPath:a,keyword:e,message:t,params:s,schemaPath:o}=r,i=`${a}`;return{name:e,property:i,message:t,params:s,stack:`${i} ${t}`.trim(),schemaPath:o}}))}rawValidation(r,a){let e;try{this.ajv.validate(r,a)}catch(r){e=r}const t=this.ajv.errors||void 0;return this.ajv.errors=null,{errors:t,validationError:e}}validateFormData(a,e,t,s,o){const i=e,n=this.rawValidation(e,a),{validationError:d}=n;let l=this.transformRJSFValidationErrors(n.errors);const c=d&&d.message&&d.message.includes("no schema with key or ref ");c&&(l=[...l,{stack:d.message}]),"function"==typeof s&&(l=s(l,o));let u=r.toErrorSchema(l);if(c&&(u={...u,$schema:{__errors:[d.message]}}),"function"!=typeof t)return{errors:l,errorSchema:u};const m=r.getDefaultFormState(this,e,a,i,!0),h=t(m,r.createErrorHandler(m),o),f=r.unwrapErrorHandler(h);return r.validationDataMerge({errors:l,errorSchema:u},f)}isValid(a,e,t){try{return this.ajv.addSchema(t,r.ROOT_SCHEMA_PREFIX).validate(r.withIdRefPrefix(a),e)}catch(r){return!1}finally{this.ajv.removeSchema(r.ROOT_SCHEMA_PREFIX)}}}function c(r={}){return new l(r)}var u=c();exports.customizeValidator=c,exports.default=u;
//# sourceMappingURL=validator-ajv6.cjs.production.min.js.map

@@ -5,18 +5,3 @@ import { toErrorList, toErrorSchema, getDefaultFormState, createErrorHandler, unwrapErrorHandler, validationDataMerge, ROOT_SCHEMA_PREFIX, withIdRefPrefix } from '@rjsf/utils';

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 = {
const AJV_CONFIG = {
errorDataPath: 'property',

@@ -28,4 +13,4 @@ allErrors: true,

};
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,(.*)$/;
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,(.*)$/;
/** Creates an Ajv version 6 implementation object with standard support for the 'color` and `data-url` custom formats.

@@ -42,7 +27,7 @@ * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the

*/
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides) {
if (ajvOptionsOverrides === void 0) {
ajvOptionsOverrides = {};
}
var ajv = new Ajv(_extends({}, AJV_CONFIG, ajvOptionsOverrides));
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides = {}) {
const ajv = new Ajv({
...AJV_CONFIG,
...ajvOptionsOverrides
});
// add custom formats

@@ -57,3 +42,3 @@ ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);

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

@@ -69,3 +54,3 @@ });

*/
var AJV6Validator = /*#__PURE__*/function () {
class AJV6Validator {
/** Constructs an `AJV6Validator` instance using the `options`

@@ -75,3 +60,3 @@ *

*/
function AJV6Validator(options) {
constructor(options) {
/** The AJV instance to use for all validations

@@ -82,5 +67,7 @@ *

this.ajv = void 0;
var additionalMetaSchemas = options.additionalMetaSchemas,
customFormats = options.customFormats,
ajvOptionsOverrides = options.ajvOptionsOverrides;
const {
additionalMetaSchemas,
customFormats,
ajvOptionsOverrides
} = options;
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides);

@@ -95,7 +82,3 @@ }

*/
var _proto = AJV6Validator.prototype;
_proto.toErrorList = function toErrorList$1(errorSchema, fieldPath) {
if (fieldPath === void 0) {
fieldPath = [];
}
toErrorList(errorSchema, fieldPath = []) {
return toErrorList(errorSchema, fieldPath);

@@ -108,22 +91,21 @@ }

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

@@ -137,5 +119,5 @@ });

* @param formData - The form data to validate
*/;
_proto.rawValidation = function rawValidation(schema, formData) {
var validationError = undefined;
*/
rawValidation(schema, formData) {
let validationError = undefined;
try {

@@ -146,3 +128,3 @@ this.ajv.validate(schema, formData);

}
var errors = this.ajv.errors || undefined;
const errors = this.ajv.errors || undefined;
// Clear errors to prevent persistent errors, see #1104

@@ -152,3 +134,3 @@ this.ajv.errors = null;

errors: errors,
validationError: validationError
validationError
};

@@ -166,13 +148,15 @@ }

* @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
*/;
_proto.validateFormData = function validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
var rootSchema = schema;
var rawErrors = this.rawValidation(schema, formData);
var validationError = rawErrors.validationError;
var errors = this.transformRJSFValidationErrors(rawErrors.errors);
var noProperMetaSchema = validationError && validationError.message && validationError.message.includes('no schema with key or ref ');
*/
validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
const rootSchema = schema;
const rawErrors = this.rawValidation(schema, formData);
const {
validationError
} = rawErrors;
let errors = this.transformRJSFValidationErrors(rawErrors.errors);
const noProperMetaSchema = validationError && validationError.message && validationError.message.includes('no schema with key or ref ');
if (noProperMetaSchema) {
errors = [].concat(errors, [{
errors = [...errors, {
stack: validationError.message
}]);
}];
}

@@ -182,23 +166,26 @@ if (typeof transformErrors === 'function') {

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

@@ -213,4 +200,4 @@ }

* @param rootSchema - The root schema used to provide $ref resolutions
*/;
_proto.isValid = function isValid(schema, formData, rootSchema) {
*/
isValid(schema, formData, rootSchema) {
try {

@@ -221,3 +208,3 @@ // add the rootSchema ROOT_SCHEMA_PREFIX as id.

// that lives in the rootSchema but not in the schema in question.
var result = this.ajv.addSchema(rootSchema, ROOT_SCHEMA_PREFIX).validate(withIdRefPrefix(schema), formData);
const result = this.ajv.addSchema(rootSchema, ROOT_SCHEMA_PREFIX).validate(withIdRefPrefix(schema), formData);
return result;

@@ -230,5 +217,4 @@ } catch (e) {

}
};
return AJV6Validator;
}();
}
}

@@ -241,6 +227,3 @@ /** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if

*/
function customizeValidator(options) {
if (options === void 0) {
options = {};
}
function customizeValidator(options = {}) {
return new AJV6Validator(options);

@@ -247,0 +230,0 @@ }

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

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 = {
const AJV_CONFIG = {
errorDataPath: 'property',

@@ -35,4 +20,4 @@ allErrors: true,

};
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,(.*)$/;
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,(.*)$/;
/** Creates an Ajv version 6 implementation object with standard support for the 'color` and `data-url` custom formats.

@@ -49,7 +34,7 @@ * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the

*/
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides) {
if (ajvOptionsOverrides === void 0) {
ajvOptionsOverrides = {};
}
var ajv = new Ajv__default["default"](_extends({}, AJV_CONFIG, ajvOptionsOverrides));
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides = {}) {
const ajv = new Ajv__default["default"]({
...AJV_CONFIG,
...ajvOptionsOverrides
});
// add custom formats

@@ -64,3 +49,3 @@ ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);

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

@@ -76,3 +61,3 @@ });

*/
var AJV6Validator = /*#__PURE__*/function () {
class AJV6Validator {
/** Constructs an `AJV6Validator` instance using the `options`

@@ -82,3 +67,3 @@ *

*/
function AJV6Validator(options) {
constructor(options) {
/** The AJV instance to use for all validations

@@ -89,5 +74,7 @@ *

this.ajv = void 0;
var additionalMetaSchemas = options.additionalMetaSchemas,
customFormats = options.customFormats,
ajvOptionsOverrides = options.ajvOptionsOverrides;
const {
additionalMetaSchemas,
customFormats,
ajvOptionsOverrides
} = options;
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides);

@@ -102,7 +89,3 @@ }

*/
var _proto = AJV6Validator.prototype;
_proto.toErrorList = function toErrorList(errorSchema, fieldPath) {
if (fieldPath === void 0) {
fieldPath = [];
}
toErrorList(errorSchema, fieldPath = []) {
return utils.toErrorList(errorSchema, fieldPath);

@@ -115,22 +98,21 @@ }

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

@@ -144,5 +126,5 @@ });

* @param formData - The form data to validate
*/;
_proto.rawValidation = function rawValidation(schema, formData) {
var validationError = undefined;
*/
rawValidation(schema, formData) {
let validationError = undefined;
try {

@@ -153,3 +135,3 @@ this.ajv.validate(schema, formData);

}
var errors = this.ajv.errors || undefined;
const errors = this.ajv.errors || undefined;
// Clear errors to prevent persistent errors, see #1104

@@ -159,3 +141,3 @@ this.ajv.errors = null;

errors: errors,
validationError: validationError
validationError
};

@@ -173,13 +155,15 @@ }

* @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
*/;
_proto.validateFormData = function validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
var rootSchema = schema;
var rawErrors = this.rawValidation(schema, formData);
var validationError = rawErrors.validationError;
var errors = this.transformRJSFValidationErrors(rawErrors.errors);
var noProperMetaSchema = validationError && validationError.message && validationError.message.includes('no schema with key or ref ');
*/
validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
const rootSchema = schema;
const rawErrors = this.rawValidation(schema, formData);
const {
validationError
} = rawErrors;
let errors = this.transformRJSFValidationErrors(rawErrors.errors);
const noProperMetaSchema = validationError && validationError.message && validationError.message.includes('no schema with key or ref ');
if (noProperMetaSchema) {
errors = [].concat(errors, [{
errors = [...errors, {
stack: validationError.message
}]);
}];
}

@@ -189,23 +173,26 @@ if (typeof transformErrors === 'function') {

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

@@ -220,4 +207,4 @@ }

* @param rootSchema - The root schema used to provide $ref resolutions
*/;
_proto.isValid = function isValid(schema, formData, rootSchema) {
*/
isValid(schema, formData, rootSchema) {
try {

@@ -228,3 +215,3 @@ // add the rootSchema ROOT_SCHEMA_PREFIX as id.

// that lives in the rootSchema but not in the schema in question.
var result = this.ajv.addSchema(rootSchema, utils.ROOT_SCHEMA_PREFIX).validate(utils.withIdRefPrefix(schema), formData);
const result = this.ajv.addSchema(rootSchema, utils.ROOT_SCHEMA_PREFIX).validate(utils.withIdRefPrefix(schema), formData);
return result;

@@ -237,5 +224,4 @@ } catch (e) {

}
};
return AJV6Validator;
}();
}
}

@@ -248,6 +234,3 @@ /** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if

*/
function customizeValidator(options) {
if (options === void 0) {
options = {};
}
function customizeValidator(options = {}) {
return new AJV6Validator(options);

@@ -254,0 +237,0 @@ }

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

!function(r,a){"object"==typeof exports&&"undefined"!=typeof module?a(exports,require("@rjsf/utils"),require("ajv"),require("lodash-es/isObject")):"function"==typeof define&&define.amd?define(["exports","@rjsf/utils","ajv","lodash-es/isObject"],a):a((r="undefined"!=typeof globalThis?globalThis:r||self)["@rjsf/validator-ajv6"]={},r.utils,r.Ajv,r.isObject)}(this,(function(r,a,e,t){"use strict";function o(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var i=o(e),s=o(t);function n(){return n=Object.assign?Object.assign.bind():function(r){for(var a=1;a<arguments.length;a++){var e=arguments[a];for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t])}return r},n.apply(this,arguments)}var d={errorDataPath:"property",allErrors:!0,multipleOfPrecision:8,schemaId:"auto",unknownFormats:"ignore"},u=/^(#?([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*\)))$/,c=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/,l=function(){function r(r){this.ajv=void 0,this.ajv=function(r,a,e){void 0===e&&(e={});var t=new i.default(n({},d,e));return t.addFormat("data-url",c),t.addFormat("color",u),Array.isArray(r)&&t.addMetaSchema(r),s.default(a)&&Object.keys(a).forEach((function(r){t.addFormat(r,a[r])})),t}(r.additionalMetaSchemas,r.customFormats,r.ajvOptionsOverrides)}var e=r.prototype;return e.toErrorList=function(r,e){return void 0===e&&(e=[]),a.toErrorList(r,e)},e.transformRJSFValidationErrors=function(r){return void 0===r&&(r=[]),r.map((function(r){var a=r.message,e=r.schemaPath,t=""+r.dataPath;return{name:r.keyword,property:t,message:a,params:r.params,stack:(t+" "+a).trim(),schemaPath:e}}))},e.rawValidation=function(r,a){var e=void 0;try{this.ajv.validate(r,a)}catch(r){e=r}var t=this.ajv.errors||void 0;return this.ajv.errors=null,{errors:t,validationError:e}},e.validateFormData=function(r,e,t,o,i){var s=e,d=this.rawValidation(e,r),u=d.validationError,c=this.transformRJSFValidationErrors(d.errors),l=u&&u.message&&u.message.includes("no schema with key or ref ");l&&(c=[].concat(c,[{stack:u.message}])),"function"==typeof o&&(c=o(c,i));var f=a.toErrorSchema(c);if(l&&(f=n({},f,{$schema:{__errors:[u.message]}})),"function"!=typeof t)return{errors:c,errorSchema:f};var v=a.getDefaultFormState(this,e,r,s,!0),h=t(v,a.createErrorHandler(v),i),m=a.unwrapErrorHandler(h);return a.validationDataMerge({errors:c,errorSchema:f},m)},e.isValid=function(r,e,t){try{return this.ajv.addSchema(t,a.ROOT_SCHEMA_PREFIX).validate(a.withIdRefPrefix(r),e)}catch(r){return!1}finally{this.ajv.removeSchema(a.ROOT_SCHEMA_PREFIX)}},r}();function f(r){return void 0===r&&(r={}),new l(r)}var v=f();r.customizeValidator=f,r.default=v,Object.defineProperty(r,"__esModule",{value:!0})}));
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@rjsf/utils"),require("ajv"),require("lodash-es/isObject")):"function"==typeof define&&define.amd?define(["exports","@rjsf/utils","ajv","lodash-es/isObject"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self)["@rjsf/validator-ajv6"]={},r.utils,r.Ajv,r.isObject)}(this,(function(r,e,a,t){"use strict";function s(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var o=s(a),i=s(t);const n={errorDataPath:"property",allErrors:!0,multipleOfPrecision:8,schemaId:"auto",unknownFormats:"ignore"},d=/^(#?([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*\)))$/,l=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;class c{constructor(r){this.ajv=void 0;const{additionalMetaSchemas:e,customFormats:a,ajvOptionsOverrides:t}=r;this.ajv=function(r,e,a={}){const t=new o.default({...n,...a});return t.addFormat("data-url",l),t.addFormat("color",d),Array.isArray(r)&&t.addMetaSchema(r),i.default(e)&&Object.keys(e).forEach((r=>{t.addFormat(r,e[r])})),t}(e,a,t)}toErrorList(r,a=[]){return e.toErrorList(r,a)}transformRJSFValidationErrors(r=[]){return r.map((r=>{const{dataPath:e,keyword:a,message:t,params:s,schemaPath:o}=r,i=`${e}`;return{name:a,property:i,message:t,params:s,stack:`${i} ${t}`.trim(),schemaPath:o}}))}rawValidation(r,e){let a;try{this.ajv.validate(r,e)}catch(r){a=r}const t=this.ajv.errors||void 0;return this.ajv.errors=null,{errors:t,validationError:a}}validateFormData(r,a,t,s,o){const i=a,n=this.rawValidation(a,r),{validationError:d}=n;let l=this.transformRJSFValidationErrors(n.errors);const c=d&&d.message&&d.message.includes("no schema with key or ref ");c&&(l=[...l,{stack:d.message}]),"function"==typeof s&&(l=s(l,o));let u=e.toErrorSchema(l);if(c&&(u={...u,$schema:{__errors:[d.message]}}),"function"!=typeof t)return{errors:l,errorSchema:u};const f=e.getDefaultFormState(this,a,r,i,!0),m=t(f,e.createErrorHandler(f),o),h=e.unwrapErrorHandler(m);return e.validationDataMerge({errors:l,errorSchema:u},h)}isValid(r,a,t){try{return this.ajv.addSchema(t,e.ROOT_SCHEMA_PREFIX).validate(e.withIdRefPrefix(r),a)}catch(r){return!1}finally{this.ajv.removeSchema(e.ROOT_SCHEMA_PREFIX)}}}function u(r={}){return new c(r)}var f=u();r.customizeValidator=u,r.default=f,Object.defineProperty(r,"__esModule",{value:!0})}));
//# sourceMappingURL=validator-ajv6.umd.production.min.js.map
{
"name": "@rjsf/validator-ajv6",
"version": "5.10.0",
"version": "5.11.1",
"main": "dist/index.js",

@@ -21,4 +21,3 @@ "module": "dist/validator-ajv6.esm.js",

"precommit": "lint-staged",
"test": "dts test",
"bump-packages": "npm update --save --lockfile-version 2"
"test": "jest"
},

@@ -43,12 +42,14 @@ "lint-staged": {

"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/plugin-transform-modules-commonjs": "^7.22.5",
"@babel/plugin-transform-react-jsx": "^7.22.5",
"@babel/preset-env": "^7.22.9",
"@babel/preset-react": "^7.22.5",
"@rjsf/utils": "^5.10.0",
"@babel/preset-typescript": "^7.22.5",
"@rjsf/utils": "^5.11.1",
"@types/jest-expect-message": "^1.1.0",
"@types/json-schema": "^7.0.12",
"@types/lodash": "^4.14.195",
"babel-jest": "^29.6.1",
"dts-cli": "^1.6.3",
"eslint": "^8.44.0",
"jest": "^29.6.1",
"jest-environment-jsdom": "^29.6.1",
"jest-expect-message": "^1.1.3",

@@ -78,3 +79,3 @@ "rimraf": "^5.0.1"

"license": "Apache-2.0",
"gitHead": "d05138f4dc678e0f6f85e13780dd3e17074791c8"
"gitHead": "0a7771f489753b9743d15aa9ae69dbf0ce821541"
}

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc