@rjsf/validator-ajv8
Advanced tools
Comparing version 5.0.0-beta.5 to 5.0.0-beta.6
import * as _rjsf_utils from '@rjsf/utils'; | ||
import { ValidatorType } from '@rjsf/utils'; | ||
import { Options } from 'ajv'; | ||
import { Options, ErrorObject } from 'ajv'; | ||
import { FormatsPluginOptions } from 'ajv-formats'; | ||
@@ -20,2 +20,5 @@ | ||
} | ||
/** The type describing a function that takes a list of Ajv `ErrorObject`s and localizes them | ||
*/ | ||
declare type Localizer = (errors?: null | ErrorObject[]) => void; | ||
@@ -26,7 +29,8 @@ /** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if | ||
* @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance | ||
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s | ||
*/ | ||
declare function customizeValidator<T = any>(options?: CustomValidatorOptionsType): ValidatorType<T>; | ||
declare function customizeValidator<T = any>(options?: CustomValidatorOptionsType, localizer?: Localizer): ValidatorType<T>; | ||
declare const _default: _rjsf_utils.ValidatorType<any>; | ||
export { CustomValidatorOptionsType, customizeValidator, _default as default }; | ||
export { CustomValidatorOptionsType, Localizer, customizeValidator, _default as default }; |
@@ -80,8 +80,15 @@ 'use strict'; | ||
/** The Localizer function to use for localizing Ajv errors | ||
* | ||
* @private | ||
*/ | ||
/** Constructs an `AJV8Validator` instance using the `options` | ||
* | ||
* @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance | ||
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s | ||
*/ | ||
constructor(options) { | ||
constructor(options, localizer) { | ||
this.ajv = void 0; | ||
this.localizer = void 0; | ||
const { | ||
@@ -94,2 +101,3 @@ additionalMetaSchemas, | ||
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions); | ||
this.localizer = localizer; | ||
} | ||
@@ -316,2 +324,6 @@ /** Transforms a ajv validation errors list: | ||
if (typeof this.localizer === "function") { | ||
this.localizer(this.ajv.errors); | ||
} | ||
let errors = this.transformRJSFValidationErrors(this.ajv.errors); // Clear errors to prevent persistent errors, see #1104 | ||
@@ -447,5 +459,6 @@ | ||
* @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance | ||
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s | ||
*/ | ||
function customizeValidator(options) { | ||
function customizeValidator(options, localizer) { | ||
if (options === void 0) { | ||
@@ -455,3 +468,3 @@ options = {}; | ||
return new AJV8Validator(options); | ||
return new AJV8Validator(options, localizer); | ||
} | ||
@@ -458,0 +471,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("lodash/toPath"),e=require("@rjsf/utils"),t=require("ajv"),a=require("ajv-formats"),s=require("lodash/isObject");function o(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var i=o(r),n=o(t),c=o(a),d=o(s);const l={allErrors:!0,multipleOfPrecision:8},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*\)))$/,h=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;class f{constructor(r){this.ajv=void 0;const{additionalMetaSchemas:e,customFormats:t,ajvOptionsOverrides:a,ajvFormatOptions:s}=r;this.ajv=function(r,e,t,a){void 0===t&&(t={});const s=new n.default({...l,...t});return"boolean"!=typeof a&&c.default(s,a),s.addFormat("data-url",h),s.addFormat("color",u),Array.isArray(r)&&s.addMetaSchema(r),d.default(e)&&Object.keys(e).forEach((r=>{s.addFormat(r,e[r])})),s}(e,t,a,s)}toErrorSchema(r){return r.length?r.reduce(((r,e)=>{const{property:t,message:a}=e,s=i.default(t);let o=r;s.length>0&&""===s[0]&&s.splice(0,1);for(const r of s.slice(0))r in o||(o[r]={}),o=o[r];return Array.isArray(o.__errors)?o.__errors=o.__errors.concat(a):a&&(o.__errors=[a]),r}),{}):{}}toErrorList(r,t){if(void 0===t&&(t=[]),!r)return[];let a=[];return e.ERRORS_KEY in r&&(a=a.concat(r.__errors.map((r=>{const e="."+t.join(".");return{property:e,message:r,stack:e+" "+r}})))),Object.keys(r).reduce(((a,s)=>(s!==e.ERRORS_KEY&&(a=a.concat(this.toErrorList(r[s],[...t,s]))),a)),a)}createErrorHandler(r){const t={__errors:[],addError(r){this.__errors.push(r)}};if(e.isObject(r)){const e=r;return Object.keys(e).reduce(((r,t)=>({...r,[t]:this.createErrorHandler(e[t])})),t)}return Array.isArray(r)?r.reduce(((r,e,t)=>({...r,[t]:this.createErrorHandler(e)})),t):t}unwrapErrorHandler(r){return Object.keys(r).reduce(((t,a)=>"addError"===a?t:a===e.ERRORS_KEY?{...t,[a]:r[a]}:{...t,[a]:this.unwrapErrorHandler(r[a])}),{})}transformRJSFValidationErrors(r){return void 0===r&&(r=[]),null===r?[]:r.map((r=>{const{instancePath:e,keyword:t,message:a,params:s,schemaPath:o}=r,i=e.replace(/\//g,".");return{name:t,property:i,message:a,params:s,stack:(i+" "+a).trim(),schemaPath:o}}))}validateFormData(r,t,a,s){const o=e.getDefaultFormState(this,t,r,t,!0);let i=null;try{this.ajv.validate(t,o)}catch(r){i=r}let n=this.transformRJSFValidationErrors(this.ajv.errors);this.ajv.errors=null;const c=i&&i.message&&"string"==typeof i.message&&i.message.includes("no schema with key or ref ");c&&(n=[...n,{stack:i.message}]),"function"==typeof s&&(n=s(n));let d=this.toErrorSchema(n);if(c&&(d={...d,$schema:{__errors:[i.message]}}),"function"!=typeof a)return{errors:n,errorSchema:d};const l=a(o,this.createErrorHandler(o)),u=this.unwrapErrorHandler(l);return e.mergeValidationData(this,{errors:n,errorSchema:d},u)}withIdRefPrefixObject(r){for(const t in r){const a=r[t];r[t]=t===e.REF_KEY&&"string"==typeof a&&a.startsWith("#")?"__rjsf_rootSchema"+a:this.withIdRefPrefix(a)}return r}withIdRefPrefixArray(r){for(let e=0;e<r.length;e++)r[e]=this.withIdRefPrefix(r[e]);return r}isValid(r,e,t){try{return this.ajv.addSchema(t,"__rjsf_rootSchema").validate(this.withIdRefPrefix(r),e)}catch(r){return!1}finally{this.ajv.removeSchema("__rjsf_rootSchema")}}withIdRefPrefix(r){return r.constructor===Object?this.withIdRefPrefixObject({...r}):Array.isArray(r)?this.withIdRefPrefixArray([...r]):r}}function m(r){return void 0===r&&(r={}),new f(r)}var y=m();exports.customizeValidator=m,exports.default=y; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("lodash/toPath"),e=require("@rjsf/utils"),t=require("ajv"),a=require("ajv-formats"),s=require("lodash/isObject");function o(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var i=o(r),n=o(t),c=o(a),l=o(s);const d={allErrors:!0,multipleOfPrecision:8},h=/^(#?([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,(.*)$/;class f{constructor(r,e){this.ajv=void 0,this.localizer=void 0;const{additionalMetaSchemas:t,customFormats:a,ajvOptionsOverrides:s,ajvFormatOptions:o}=r;this.ajv=function(r,e,t,a){void 0===t&&(t={});const s=new n.default({...d,...t});return"boolean"!=typeof a&&c.default(s,a),s.addFormat("data-url",u),s.addFormat("color",h),Array.isArray(r)&&s.addMetaSchema(r),l.default(e)&&Object.keys(e).forEach((r=>{s.addFormat(r,e[r])})),s}(t,a,s,o),this.localizer=e}toErrorSchema(r){return r.length?r.reduce(((r,e)=>{const{property:t,message:a}=e,s=i.default(t);let o=r;s.length>0&&""===s[0]&&s.splice(0,1);for(const r of s.slice(0))r in o||(o[r]={}),o=o[r];return Array.isArray(o.__errors)?o.__errors=o.__errors.concat(a):a&&(o.__errors=[a]),r}),{}):{}}toErrorList(r,t){if(void 0===t&&(t=[]),!r)return[];let a=[];return e.ERRORS_KEY in r&&(a=a.concat(r.__errors.map((r=>{const e="."+t.join(".");return{property:e,message:r,stack:e+" "+r}})))),Object.keys(r).reduce(((a,s)=>(s!==e.ERRORS_KEY&&(a=a.concat(this.toErrorList(r[s],[...t,s]))),a)),a)}createErrorHandler(r){const t={__errors:[],addError(r){this.__errors.push(r)}};if(e.isObject(r)){const e=r;return Object.keys(e).reduce(((r,t)=>({...r,[t]:this.createErrorHandler(e[t])})),t)}return Array.isArray(r)?r.reduce(((r,e,t)=>({...r,[t]:this.createErrorHandler(e)})),t):t}unwrapErrorHandler(r){return Object.keys(r).reduce(((t,a)=>"addError"===a?t:a===e.ERRORS_KEY?{...t,[a]:r[a]}:{...t,[a]:this.unwrapErrorHandler(r[a])}),{})}transformRJSFValidationErrors(r){return void 0===r&&(r=[]),null===r?[]:r.map((r=>{const{instancePath:e,keyword:t,message:a,params:s,schemaPath:o}=r,i=e.replace(/\//g,".");return{name:t,property:i,message:a,params:s,stack:(i+" "+a).trim(),schemaPath:o}}))}validateFormData(r,t,a,s){const o=e.getDefaultFormState(this,t,r,t,!0);let i=null;try{this.ajv.validate(t,o)}catch(r){i=r}"function"==typeof this.localizer&&this.localizer(this.ajv.errors);let n=this.transformRJSFValidationErrors(this.ajv.errors);this.ajv.errors=null;const c=i&&i.message&&"string"==typeof i.message&&i.message.includes("no schema with key or ref ");c&&(n=[...n,{stack:i.message}]),"function"==typeof s&&(n=s(n));let l=this.toErrorSchema(n);if(c&&(l={...l,$schema:{__errors:[i.message]}}),"function"!=typeof a)return{errors:n,errorSchema:l};const d=a(o,this.createErrorHandler(o)),h=this.unwrapErrorHandler(d);return e.mergeValidationData(this,{errors:n,errorSchema:l},h)}withIdRefPrefixObject(r){for(const t in r){const a=r[t];r[t]=t===e.REF_KEY&&"string"==typeof a&&a.startsWith("#")?"__rjsf_rootSchema"+a:this.withIdRefPrefix(a)}return r}withIdRefPrefixArray(r){for(let e=0;e<r.length;e++)r[e]=this.withIdRefPrefix(r[e]);return r}isValid(r,e,t){try{return this.ajv.addSchema(t,"__rjsf_rootSchema").validate(this.withIdRefPrefix(r),e)}catch(r){return!1}finally{this.ajv.removeSchema("__rjsf_rootSchema")}}withIdRefPrefix(r){return r.constructor===Object?this.withIdRefPrefixObject({...r}):Array.isArray(r)?this.withIdRefPrefixArray([...r]):r}}function m(r,e){return void 0===r&&(r={}),new f(r,e)}var y=m();exports.customizeValidator=m,exports.default=y; | ||
//# sourceMappingURL=validator-ajv8.cjs.production.min.js.map |
@@ -69,8 +69,15 @@ import toPath from 'lodash-es/toPath'; | ||
/** The Localizer function to use for localizing Ajv errors | ||
* | ||
* @private | ||
*/ | ||
/** Constructs an `AJV8Validator` instance using the `options` | ||
* | ||
* @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance | ||
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s | ||
*/ | ||
constructor(options) { | ||
constructor(options, localizer) { | ||
this.ajv = void 0; | ||
this.localizer = void 0; | ||
const { | ||
@@ -83,2 +90,3 @@ additionalMetaSchemas, | ||
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions); | ||
this.localizer = localizer; | ||
} | ||
@@ -305,2 +313,6 @@ /** Transforms a ajv validation errors list: | ||
if (typeof this.localizer === "function") { | ||
this.localizer(this.ajv.errors); | ||
} | ||
let errors = this.transformRJSFValidationErrors(this.ajv.errors); // Clear errors to prevent persistent errors, see #1104 | ||
@@ -436,5 +448,6 @@ | ||
* @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance | ||
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s | ||
*/ | ||
function customizeValidator(options) { | ||
function customizeValidator(options, localizer) { | ||
if (options === void 0) { | ||
@@ -444,3 +457,3 @@ options = {}; | ||
return new AJV8Validator(options); | ||
return new AJV8Validator(options, localizer); | ||
} | ||
@@ -447,0 +460,0 @@ |
@@ -76,8 +76,15 @@ (function (global, factory) { | ||
/** The Localizer function to use for localizing Ajv errors | ||
* | ||
* @private | ||
*/ | ||
/** Constructs an `AJV8Validator` instance using the `options` | ||
* | ||
* @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance | ||
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s | ||
*/ | ||
constructor(options) { | ||
constructor(options, localizer) { | ||
this.ajv = void 0; | ||
this.localizer = void 0; | ||
const { | ||
@@ -90,2 +97,3 @@ additionalMetaSchemas, | ||
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions); | ||
this.localizer = localizer; | ||
} | ||
@@ -312,2 +320,6 @@ /** Transforms a ajv validation errors list: | ||
if (typeof this.localizer === "function") { | ||
this.localizer(this.ajv.errors); | ||
} | ||
let errors = this.transformRJSFValidationErrors(this.ajv.errors); // Clear errors to prevent persistent errors, see #1104 | ||
@@ -443,5 +455,6 @@ | ||
* @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance | ||
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s | ||
*/ | ||
function customizeValidator(options) { | ||
function customizeValidator(options, localizer) { | ||
if (options === void 0) { | ||
@@ -451,3 +464,3 @@ options = {}; | ||
return new AJV8Validator(options); | ||
return new AJV8Validator(options, localizer); | ||
} | ||
@@ -454,0 +467,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("lodash-es/toPath"),require("@rjsf/utils"),require("ajv"),require("ajv-formats"),require("lodash-es/isObject")):"function"==typeof define&&define.amd?define(["exports","lodash-es/toPath","@rjsf/utils","ajv","ajv-formats","lodash-es/isObject"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self)["@rjsf/validator-ajv8"]={},r.toPath,r.utils,r.Ajv,r.addFormats,r.isObject)}(this,(function(r,e,t,a,s,o){"use strict";function i(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var n=i(e),c=i(a),d=i(s),l=i(o);const u={allErrors:!0,multipleOfPrecision:8},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*\)))$/,h=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/,m="__rjsf_rootSchema";class y{constructor(r){this.ajv=void 0;const{additionalMetaSchemas:e,customFormats:t,ajvOptionsOverrides:a,ajvFormatOptions:s}=r;this.ajv=function(r,e,t,a){void 0===t&&(t={});const s=new c.default({...u,...t});return"boolean"!=typeof a&&d.default(s,a),s.addFormat("data-url",h),s.addFormat("color",f),Array.isArray(r)&&s.addMetaSchema(r),l.default(e)&&Object.keys(e).forEach((r=>{s.addFormat(r,e[r])})),s}(e,t,a,s)}toErrorSchema(r){return r.length?r.reduce(((r,e)=>{const{property:t,message:a}=e,s=n.default(t);let o=r;s.length>0&&""===s[0]&&s.splice(0,1);for(const r of s.slice(0))r in o||(o[r]={}),o=o[r];return Array.isArray(o.__errors)?o.__errors=o.__errors.concat(a):a&&(o.__errors=[a]),r}),{}):{}}toErrorList(r,e){if(void 0===e&&(e=[]),!r)return[];let a=[];return t.ERRORS_KEY in r&&(a=a.concat(r.__errors.map((r=>{const t="."+e.join(".");return{property:t,message:r,stack:t+" "+r}})))),Object.keys(r).reduce(((a,s)=>(s!==t.ERRORS_KEY&&(a=a.concat(this.toErrorList(r[s],[...e,s]))),a)),a)}createErrorHandler(r){const e={__errors:[],addError(r){this.__errors.push(r)}};if(t.isObject(r)){const t=r;return Object.keys(t).reduce(((r,e)=>({...r,[e]:this.createErrorHandler(t[e])})),e)}return Array.isArray(r)?r.reduce(((r,e,t)=>({...r,[t]:this.createErrorHandler(e)})),e):e}unwrapErrorHandler(r){return Object.keys(r).reduce(((e,a)=>"addError"===a?e:a===t.ERRORS_KEY?{...e,[a]:r[a]}:{...e,[a]:this.unwrapErrorHandler(r[a])}),{})}transformRJSFValidationErrors(r){return void 0===r&&(r=[]),null===r?[]:r.map((r=>{const{instancePath:e,keyword:t,message:a,params:s,schemaPath:o}=r,i=e.replace(/\//g,".");return{name:t,property:i,message:a,params:s,stack:(i+" "+a).trim(),schemaPath:o}}))}validateFormData(r,e,a,s){const o=t.getDefaultFormState(this,e,r,e,!0);let i=null;try{this.ajv.validate(e,o)}catch(r){i=r}let n=this.transformRJSFValidationErrors(this.ajv.errors);this.ajv.errors=null;const c=i&&i.message&&"string"==typeof i.message&&i.message.includes("no schema with key or ref ");c&&(n=[...n,{stack:i.message}]),"function"==typeof s&&(n=s(n));let d=this.toErrorSchema(n);if(c&&(d={...d,$schema:{__errors:[i.message]}}),"function"!=typeof a)return{errors:n,errorSchema:d};const l=a(o,this.createErrorHandler(o)),u=this.unwrapErrorHandler(l);return t.mergeValidationData(this,{errors:n,errorSchema:d},u)}withIdRefPrefixObject(r){for(const e in r){const a=r[e];r[e]=e===t.REF_KEY&&"string"==typeof a&&a.startsWith("#")?m+a:this.withIdRefPrefix(a)}return r}withIdRefPrefixArray(r){for(let e=0;e<r.length;e++)r[e]=this.withIdRefPrefix(r[e]);return r}isValid(r,e,t){try{return this.ajv.addSchema(t,m).validate(this.withIdRefPrefix(r),e)}catch(r){return!1}finally{this.ajv.removeSchema(m)}}withIdRefPrefix(r){return r.constructor===Object?this.withIdRefPrefixObject({...r}):Array.isArray(r)?this.withIdRefPrefixArray([...r]):r}}function p(r){return void 0===r&&(r={}),new y(r)}var j=p();r.customizeValidator=p,r.default=j,Object.defineProperty(r,"__esModule",{value:!0})})); | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("lodash-es/toPath"),require("@rjsf/utils"),require("ajv"),require("ajv-formats"),require("lodash-es/isObject")):"function"==typeof define&&define.amd?define(["exports","lodash-es/toPath","@rjsf/utils","ajv","ajv-formats","lodash-es/isObject"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self)["@rjsf/validator-ajv8"]={},r.toPath,r.utils,r.Ajv,r.addFormats,r.isObject)}(this,(function(r,e,t,a,s,o){"use strict";function i(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var n=i(e),c=i(a),d=i(s),l=i(o);const u={allErrors:!0,multipleOfPrecision:8},h=/^(#?([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*\)))$/,f=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/,m="__rjsf_rootSchema";class y{constructor(r,e){this.ajv=void 0,this.localizer=void 0;const{additionalMetaSchemas:t,customFormats:a,ajvOptionsOverrides:s,ajvFormatOptions:o}=r;this.ajv=function(r,e,t,a){void 0===t&&(t={});const s=new c.default({...u,...t});return"boolean"!=typeof a&&d.default(s,a),s.addFormat("data-url",f),s.addFormat("color",h),Array.isArray(r)&&s.addMetaSchema(r),l.default(e)&&Object.keys(e).forEach((r=>{s.addFormat(r,e[r])})),s}(t,a,s,o),this.localizer=e}toErrorSchema(r){return r.length?r.reduce(((r,e)=>{const{property:t,message:a}=e,s=n.default(t);let o=r;s.length>0&&""===s[0]&&s.splice(0,1);for(const r of s.slice(0))r in o||(o[r]={}),o=o[r];return Array.isArray(o.__errors)?o.__errors=o.__errors.concat(a):a&&(o.__errors=[a]),r}),{}):{}}toErrorList(r,e){if(void 0===e&&(e=[]),!r)return[];let a=[];return t.ERRORS_KEY in r&&(a=a.concat(r.__errors.map((r=>{const t="."+e.join(".");return{property:t,message:r,stack:t+" "+r}})))),Object.keys(r).reduce(((a,s)=>(s!==t.ERRORS_KEY&&(a=a.concat(this.toErrorList(r[s],[...e,s]))),a)),a)}createErrorHandler(r){const e={__errors:[],addError(r){this.__errors.push(r)}};if(t.isObject(r)){const t=r;return Object.keys(t).reduce(((r,e)=>({...r,[e]:this.createErrorHandler(t[e])})),e)}return Array.isArray(r)?r.reduce(((r,e,t)=>({...r,[t]:this.createErrorHandler(e)})),e):e}unwrapErrorHandler(r){return Object.keys(r).reduce(((e,a)=>"addError"===a?e:a===t.ERRORS_KEY?{...e,[a]:r[a]}:{...e,[a]:this.unwrapErrorHandler(r[a])}),{})}transformRJSFValidationErrors(r){return void 0===r&&(r=[]),null===r?[]:r.map((r=>{const{instancePath:e,keyword:t,message:a,params:s,schemaPath:o}=r,i=e.replace(/\//g,".");return{name:t,property:i,message:a,params:s,stack:(i+" "+a).trim(),schemaPath:o}}))}validateFormData(r,e,a,s){const o=t.getDefaultFormState(this,e,r,e,!0);let i=null;try{this.ajv.validate(e,o)}catch(r){i=r}"function"==typeof this.localizer&&this.localizer(this.ajv.errors);let n=this.transformRJSFValidationErrors(this.ajv.errors);this.ajv.errors=null;const c=i&&i.message&&"string"==typeof i.message&&i.message.includes("no schema with key or ref ");c&&(n=[...n,{stack:i.message}]),"function"==typeof s&&(n=s(n));let d=this.toErrorSchema(n);if(c&&(d={...d,$schema:{__errors:[i.message]}}),"function"!=typeof a)return{errors:n,errorSchema:d};const l=a(o,this.createErrorHandler(o)),u=this.unwrapErrorHandler(l);return t.mergeValidationData(this,{errors:n,errorSchema:d},u)}withIdRefPrefixObject(r){for(const e in r){const a=r[e];r[e]=e===t.REF_KEY&&"string"==typeof a&&a.startsWith("#")?m+a:this.withIdRefPrefix(a)}return r}withIdRefPrefixArray(r){for(let e=0;e<r.length;e++)r[e]=this.withIdRefPrefix(r[e]);return r}isValid(r,e,t){try{return this.ajv.addSchema(t,m).validate(this.withIdRefPrefix(r),e)}catch(r){return!1}finally{this.ajv.removeSchema(m)}}withIdRefPrefix(r){return r.constructor===Object?this.withIdRefPrefixObject({...r}):Array.isArray(r)?this.withIdRefPrefixArray([...r]):r}}function p(r,e){return void 0===r&&(r={}),new y(r,e)}var j=p();r.customizeValidator=p,r.default=j,Object.defineProperty(r,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=validator-ajv8.umd.production.min.js.map |
{ | ||
"name": "@rjsf/validator-ajv8", | ||
"version": "5.0.0-beta.5", | ||
"version": "5.0.0-beta.6", | ||
"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.5", | ||
"@rjsf/utils": "^5.0.0-beta.6", | ||
"@types/jest-expect-message": "^1.0.3", | ||
@@ -76,3 +76,3 @@ "@types/json-schema": "^7.0.9", | ||
"license": "Apache-2.0", | ||
"gitHead": "e4c61ea6867d6089dced3227d5aa8ac40516376d" | ||
"gitHead": "dfc8bbca60113fc5a78302b2ed79e3ea9b16241b" | ||
} |
@@ -11,3 +11,3 @@ [![Build Status][build-shield]][build-url] | ||
<a href="https://github.com/rjsf-team/react-jsonschema-form"> | ||
<img src="https://raw.githubusercontent.com/rjsf-team/react-jsonschema-form/59a8206e148474bea854bbb006f624143fbcbac8/packages/validator-ajv6/logo.png" alt="Logo" width="120" height="120"> | ||
<img src="https://raw.githubusercontent.com/rjsf-team/react-jsonschema-form/7ebc86621d8df8c21f0c39bcca6d476f6f7a2051/packages/validator-ajv8/logo.png" alt="Logo" width="120" height="120"> | ||
</a> | ||
@@ -244,6 +244,5 @@ | ||
[license-url]: https://choosealicense.com/licenses/apache-2.0/ | ||
[npm-shield]: https://img.shields.io/npm/v/@rjsf/material-ui/latest.svg?style=flat-square | ||
[npm-url]: https://www.npmjs.com/package/@rjsf/material-ui | ||
[npm-dl-shield]: https://img.shields.io/npm/dm/@rjsf/material-ui.svg?style=flat-square | ||
[npm-dl-url]: https://www.npmjs.com/package/@rjsf/material-ui | ||
[product-screenshot]: https://raw.githubusercontent.com/rjsf-team/react-jsonschema-form/e2e1181d1020f18cad0c80c661ddae28edb9794e/packages/material-ui/screenshot5.png | ||
[npm-shield]: https://img.shields.io/npm/v/@rjsf/validator-ajv8/latest.svg?style=flat-square | ||
[npm-url]: https://www.npmjs.com/package/@rjsf/validator-ajv8 | ||
[npm-dl-shield]: https://img.shields.io/npm/dm/@rjsf/validator-ajv8.svg?style=flat-square | ||
[npm-dl-url]: https://www.npmjs.com/package/@rjsf/validator-ajv8 |
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
205170
1241
247