@rjsf/validator-ajv8 5.7.0 → 5.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compileSchemaValidators.cjs.development.js +59 -0
- package/dist/compileSchemaValidators.cjs.development.js.map +1 -0
- package/dist/compileSchemaValidators.cjs.production.min.js +2 -0
- package/dist/compileSchemaValidators.cjs.production.min.js.map +1 -0
- package/dist/compileSchemaValidators.js +8 -0
- package/dist/createAjvInstance-0cd8cfba.js +2 -0
- package/dist/createAjvInstance-0cd8cfba.js.map +1 -0
- package/dist/{validator-ajv8.cjs.development.js → index.cjs.development.js} +8 -137
- package/dist/index.cjs.development.js.map +1 -0
- package/dist/index.cjs.production.min.js +2 -0
- package/dist/index.cjs.production.min.js.map +1 -0
- package/dist/index.d.ts +1 -14
- package/dist/index.js +2 -2
- package/dist/validator-ajv8.esm.js +2 -44
- package/dist/validator-ajv8.esm.js.map +1 -1
- package/dist/validator-ajv8.umd.development.js +4 -47
- package/dist/validator-ajv8.umd.development.js.map +1 -1
- package/dist/validator-ajv8.umd.production.min.js +1 -1
- package/dist/validator-ajv8.umd.production.min.js.map +1 -1
- package/package.json +6 -5
- package/dist/validator-ajv8.cjs.development.js.map +0 -1
- package/dist/validator-ajv8.cjs.production.min.js +0 -2
- package/dist/validator-ajv8.cjs.production.min.js.map +0 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var createAjvInstance = require('./createAjvInstance-0cd8cfba.js');
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var standaloneCode = require('ajv/dist/standalone');
|
|
8
|
+
var utils = require('@rjsf/utils');
|
|
9
|
+
require('ajv');
|
|
10
|
+
require('ajv-formats');
|
|
11
|
+
require('lodash/isObject');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
16
|
+
var standaloneCode__default = /*#__PURE__*/_interopDefaultLegacy(standaloneCode);
|
|
17
|
+
|
|
18
|
+
/** The function used to compile a schema into an output file in the form that allows it to be used as a precompiled
|
|
19
|
+
* validator. The main reasons for using a precompiled validator is reducing code size, improving validation speed and,
|
|
20
|
+
* most importantly, avoiding dynamic code compilation when prohibited by a browser's Content Security Policy. For more
|
|
21
|
+
* information about AJV code compilation see: https://ajv.js.org/standalone.html
|
|
22
|
+
*
|
|
23
|
+
* @param schema - The schema to be compiled into a set of precompiled validators functions
|
|
24
|
+
* @param output - The name of the file into which the precompiled validator functions will be generated
|
|
25
|
+
* @param [options={}] - The set of `CustomValidatorOptionsType` information used to alter the AJV validator used for
|
|
26
|
+
* compiling the schema. They are the same options that are passed to the `customizeValidator()` function in
|
|
27
|
+
* order to modify the behavior of the regular AJV-based validator.
|
|
28
|
+
*/
|
|
29
|
+
function compileSchemaValidators(schema, output, options) {
|
|
30
|
+
if (options === void 0) {
|
|
31
|
+
options = {};
|
|
32
|
+
}
|
|
33
|
+
console.log('parsing the schema');
|
|
34
|
+
var schemaMaps = utils.schemaParser(schema);
|
|
35
|
+
var schemas = Object.values(schemaMaps);
|
|
36
|
+
var _options = options,
|
|
37
|
+
additionalMetaSchemas = _options.additionalMetaSchemas,
|
|
38
|
+
customFormats = _options.customFormats,
|
|
39
|
+
_options$ajvOptionsOv = _options.ajvOptionsOverrides,
|
|
40
|
+
ajvOptionsOverrides = _options$ajvOptionsOv === void 0 ? {} : _options$ajvOptionsOv,
|
|
41
|
+
ajvFormatOptions = _options.ajvFormatOptions,
|
|
42
|
+
AjvClass = _options.AjvClass;
|
|
43
|
+
// Allow users to turn off the `lines: true` feature in their own overrides, but NOT the `source: true`
|
|
44
|
+
var compileOptions = createAjvInstance._extends({}, ajvOptionsOverrides, {
|
|
45
|
+
code: createAjvInstance._extends({
|
|
46
|
+
lines: true
|
|
47
|
+
}, ajvOptionsOverrides.code, {
|
|
48
|
+
source: true
|
|
49
|
+
}),
|
|
50
|
+
schemas: schemas
|
|
51
|
+
});
|
|
52
|
+
var ajv = createAjvInstance.createAjvInstance(additionalMetaSchemas, customFormats, compileOptions, ajvFormatOptions, AjvClass);
|
|
53
|
+
var moduleCode = standaloneCode__default["default"](ajv);
|
|
54
|
+
console.log("writing " + output);
|
|
55
|
+
fs__default["default"].writeFileSync(output, moduleCode);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports["default"] = compileSchemaValidators;
|
|
59
|
+
//# sourceMappingURL=compileSchemaValidators.cjs.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileSchemaValidators.cjs.development.js","sources":["../src/compileSchemaValidators.ts"],"sourcesContent":["import fs from 'fs';\nimport standaloneCode from 'ajv/dist/standalone';\nimport { RJSFSchema, StrictRJSFSchema, schemaParser } from '@rjsf/utils';\n\nimport createAjvInstance from './createAjvInstance';\nimport { CustomValidatorOptionsType } from './types';\n\n/** The function used to compile a schema into an output file in the form that allows it to be used as a precompiled\n * validator. The main reasons for using a precompiled validator is reducing code size, improving validation speed and,\n * most importantly, avoiding dynamic code compilation when prohibited by a browser's Content Security Policy. For more\n * information about AJV code compilation see: https://ajv.js.org/standalone.html\n *\n * @param schema - The schema to be compiled into a set of precompiled validators functions\n * @param output - The name of the file into which the precompiled validator functions will be generated\n * @param [options={}] - The set of `CustomValidatorOptionsType` information used to alter the AJV validator used for\n * compiling the schema. They are the same options that are passed to the `customizeValidator()` function in\n * order to modify the behavior of the regular AJV-based validator.\n */\nexport default function compileSchemaValidators<S extends StrictRJSFSchema = RJSFSchema>(\n schema: S,\n output: string,\n options: CustomValidatorOptionsType = {}\n) {\n console.log('parsing the schema');\n const schemaMaps = schemaParser(schema);\n const schemas = Object.values(schemaMaps);\n\n const { additionalMetaSchemas, customFormats, ajvOptionsOverrides = {}, ajvFormatOptions, AjvClass } = options;\n // Allow users to turn off the `lines: true` feature in their own overrides, but NOT the `source: true`\n const compileOptions = {\n ...ajvOptionsOverrides,\n code: { lines: true, ...ajvOptionsOverrides.code, source: true },\n schemas,\n };\n const ajv = createAjvInstance(additionalMetaSchemas, customFormats, compileOptions, ajvFormatOptions, AjvClass);\n\n const moduleCode = standaloneCode(ajv);\n console.log(`writing ${output}`);\n fs.writeFileSync(output, moduleCode);\n}\n"],"names":["compileSchemaValidators","schema","output","options","console","log","schemaMaps","schemaParser","schemas","Object","values","_options","additionalMetaSchemas","customFormats","_options$ajvOptionsOv","ajvOptionsOverrides","ajvFormatOptions","AjvClass","compileOptions","_extends","code","lines","source","ajv","createAjvInstance","moduleCode","standaloneCode","fs","writeFileSync"],"mappings":";;;;;;;;;;;;;;;;;AAOA;;;;;;;;;;AAUG;AACW,SAAUA,uBAAuBA,CAC7CC,MAAS,EACTC,MAAc,EACdC,OAAA,EAAwC;AAAA,EAAA,IAAxCA,OAAA,KAAA,KAAA,CAAA,EAAA;IAAAA,OAAA,GAAsC,EAAE,CAAA;AAAA,GAAA;AAExCC,EAAAA,OAAO,CAACC,GAAG,CAAC,oBAAoB,CAAC,CAAA;AACjC,EAAA,IAAMC,UAAU,GAAGC,kBAAY,CAACN,MAAM,CAAC,CAAA;AACvC,EAAA,IAAMO,OAAO,GAAGC,MAAM,CAACC,MAAM,CAACJ,UAAU,CAAC,CAAA;EAEzC,IAAAK,QAAA,GAAuGR,OAAO;IAAtGS,qBAAqB,GAAAD,QAAA,CAArBC,qBAAqB;IAAEC,aAAa,GAAAF,QAAA,CAAbE,aAAa;IAAAC,qBAAA,GAAAH,QAAA,CAAEI,mBAAmB;AAAnBA,IAAAA,mBAAmB,GAAAD,qBAAA,KAAA,KAAA,CAAA,GAAG,EAAE,GAAAA,qBAAA;IAAEE,gBAAgB,GAAAL,QAAA,CAAhBK,gBAAgB;IAAEC,QAAQ,GAAAN,QAAA,CAARM,QAAQ,CAAA;AAClG;AACA,EAAA,IAAMC,cAAc,GAAAC,0BAAA,CAAA,EAAA,EACfJ,mBAAmB,EAAA;AACtBK,IAAAA,IAAI,EAAAD,0BAAA,CAAA;AAAIE,MAAAA,KAAK,EAAE,IAAA;KAASN,EAAAA,mBAAmB,CAACK,IAAI,EAAA;AAAEE,MAAAA,MAAM,EAAE,IAAA;KAAM,CAAA;AAChEd,IAAAA,OAAO,EAAPA,OAAAA;GACD,CAAA,CAAA;AACD,EAAA,IAAMe,GAAG,GAAGC,mCAAiB,CAACZ,qBAAqB,EAAEC,aAAa,EAAEK,cAAc,EAAEF,gBAAgB,EAAEC,QAAQ,CAAC,CAAA;AAE/G,EAAA,IAAMQ,UAAU,GAAGC,kCAAc,CAACH,GAAG,CAAC,CAAA;AACtCnB,EAAAA,OAAO,CAACC,GAAG,CAAYH,UAAAA,GAAAA,MAAQ,CAAC,CAAA;AAChCyB,EAAAA,sBAAE,CAACC,aAAa,CAAC1B,MAAM,EAAEuB,UAAU,CAAC,CAAA;AACtC;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./createAjvInstance-0cd8cfba.js"),r=require("fs"),t=require("ajv/dist/standalone"),s=require("@rjsf/utils");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("ajv"),require("ajv-formats"),require("lodash/isObject");var i=a(r),o=a(t);exports.default=function(r,t,a){void 0===a&&(a={}),console.log("parsing the schema");var c=s.schemaParser(r),n=Object.values(c),u=a.additionalMetaSchemas,d=a.customFormats,l=a.ajvOptionsOverrides,v=void 0===l?{}:l,j=a.ajvFormatOptions,f=a.AjvClass,m=e._extends({},v,{code:e._extends({lines:!0},v.code,{source:!0}),schemas:n}),p=e.createAjvInstance(u,d,m,j,f),q=o.default(p);console.log("writing "+t),i.default.writeFileSync(t,q)};
|
|
2
|
+
//# sourceMappingURL=compileSchemaValidators.cjs.production.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileSchemaValidators.cjs.production.min.js","sources":["../src/compileSchemaValidators.ts"],"sourcesContent":["import fs from 'fs';\nimport standaloneCode from 'ajv/dist/standalone';\nimport { RJSFSchema, StrictRJSFSchema, schemaParser } from '@rjsf/utils';\n\nimport createAjvInstance from './createAjvInstance';\nimport { CustomValidatorOptionsType } from './types';\n\n/** The function used to compile a schema into an output file in the form that allows it to be used as a precompiled\n * validator. The main reasons for using a precompiled validator is reducing code size, improving validation speed and,\n * most importantly, avoiding dynamic code compilation when prohibited by a browser's Content Security Policy. For more\n * information about AJV code compilation see: https://ajv.js.org/standalone.html\n *\n * @param schema - The schema to be compiled into a set of precompiled validators functions\n * @param output - The name of the file into which the precompiled validator functions will be generated\n * @param [options={}] - The set of `CustomValidatorOptionsType` information used to alter the AJV validator used for\n * compiling the schema. They are the same options that are passed to the `customizeValidator()` function in\n * order to modify the behavior of the regular AJV-based validator.\n */\nexport default function compileSchemaValidators<S extends StrictRJSFSchema = RJSFSchema>(\n schema: S,\n output: string,\n options: CustomValidatorOptionsType = {}\n) {\n console.log('parsing the schema');\n const schemaMaps = schemaParser(schema);\n const schemas = Object.values(schemaMaps);\n\n const { additionalMetaSchemas, customFormats, ajvOptionsOverrides = {}, ajvFormatOptions, AjvClass } = options;\n // Allow users to turn off the `lines: true` feature in their own overrides, but NOT the `source: true`\n const compileOptions = {\n ...ajvOptionsOverrides,\n code: { lines: true, ...ajvOptionsOverrides.code, source: true },\n schemas,\n };\n const ajv = createAjvInstance(additionalMetaSchemas, customFormats, compileOptions, ajvFormatOptions, AjvClass);\n\n const moduleCode = standaloneCode(ajv);\n console.log(`writing ${output}`);\n fs.writeFileSync(output, moduleCode);\n}\n"],"names":["schema","output","options","console","log","schemaMaps","schemaParser","schemas","Object","values","additionalMetaSchemas","customFormats","_options$ajvOptionsOv","ajvOptionsOverrides","ajvFormatOptions","AjvClass","compileOptions","_extends","code","lines","source","ajv","createAjvInstance","moduleCode","standaloneCode","fs","writeFileSync"],"mappings":"0WAkBc,SACZA,EACAC,EACAC,QAAA,IAAAA,IAAAA,EAAsC,CAAA,GAEtCC,QAAQC,IAAI,sBACZ,IAAMC,EAAaC,eAAaN,GAC1BO,EAAUC,OAAOC,OAAOJ,GAEtBK,EAA+FR,EAA/FQ,sBAAuBC,EAAwET,EAAxES,cAAaC,EAA2DV,EAAzDW,oBAAAA,OAAmB,IAAAD,EAAG,CAAE,EAAAA,EAAEE,EAA+BZ,EAA/BY,iBAAkBC,EAAab,EAAba,SAEpFC,EAAcC,EAAAA,SAAA,CAAA,EACfJ,EAAmB,CACtBK,KAAID,EAAAA,SAAA,CAAIE,OAAO,GAASN,EAAoBK,KAAI,CAAEE,QAAQ,IAC1Db,QAAAA,IAEIc,EAAMC,EAAAA,kBAAkBZ,EAAuBC,EAAeK,EAAgBF,EAAkBC,GAEhGQ,EAAaC,UAAeH,GAClClB,QAAQC,IAAeH,WAAAA,GACvBwB,EAAAA,QAAGC,cAAczB,EAAQsB,EAC3B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("ajv"),r=require("ajv-formats"),a=require("lodash/isObject"),t=require("@rjsf/utils");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=o(e),n=o(r),d=o(a);function i(){return i=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var a=arguments[r];for(var t in a)Object.prototype.hasOwnProperty.call(a,t)&&(e[t]=a[t])}return e},i.apply(this,arguments)}var u={allErrors:!0,multipleOfPrecision:8,strict:!1,verbose:!0},l=/^(#?([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,(.*)$/;exports._extends=i,exports._objectWithoutPropertiesLoose=function(e,r){if(null==e)return{};var a,t,o={},s=Object.keys(e);for(t=0;t<s.length;t++)r.indexOf(a=s[t])>=0||(o[a]=e[a]);return o},exports.createAjvInstance=function(e,r,a,o,f){void 0===a&&(a={}),void 0===f&&(f=s.default);var b=new f(i({},u,a));return o?n.default(b,o):!1!==o&&n.default(b),b.addFormat("data-url",c),b.addFormat("color",l),b.addKeyword(t.ADDITIONAL_PROPERTY_FLAG),b.addKeyword(t.RJSF_ADDITONAL_PROPERTIES_FLAG),Array.isArray(e)&&b.addMetaSchema(e),d.default(r)&&Object.keys(r).forEach((function(e){b.addFormat(e,r[e])})),b};
|
|
2
|
+
//# sourceMappingURL=createAjvInstance-0cd8cfba.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAjvInstance-0cd8cfba.js","sources":["../src/createAjvInstance.ts"],"sourcesContent":["import Ajv, { Options } from 'ajv';\nimport addFormats, { FormatsPluginOptions } from 'ajv-formats';\nimport isObject from 'lodash/isObject';\n\nimport { CustomValidatorOptionsType } from './types';\nimport { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITONAL_PROPERTIES_FLAG } from '@rjsf/utils';\n\nexport const AJV_CONFIG: Options = {\n allErrors: true,\n multipleOfPrecision: 8,\n strict: false,\n verbose: true,\n} as const;\nexport const COLOR_FORMAT_REGEX =\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*\\)))$/;\nexport const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;\n\n/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.\n * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the\n * list. If `customFormats` are provided then those additional formats are added to the list of supported formats. If\n * `ajvOptionsOverrides` are provided then they are spread on top of the default `AJV_CONFIG` options when constructing\n * the `Ajv` instance. With Ajv v8, the JSON Schema formats are not provided by default, but can be plugged in. By\n * default, all formats from the `ajv-formats` library are added. To disable this capability, set the `ajvFormatOptions`\n * parameter to `false`. Additionally, you can configure the `ajv-formats` by providing a custom set of\n * [format options](https://github.com/ajv-validator/ajv-formats) to the `ajvFormatOptions` parameter.\n *\n * @param [additionalMetaSchemas] - The list of additional meta schemas that the validator can access\n * @param [customFormats] - The set of additional custom formats that the validator will support\n * @param [ajvOptionsOverrides={}] - The set of validator config override options\n * @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it\n * @param [AjvClass] - The `Ajv` class to use when creating the validator instance\n */\nexport default function createAjvInstance(\n additionalMetaSchemas?: CustomValidatorOptionsType['additionalMetaSchemas'],\n customFormats?: CustomValidatorOptionsType['customFormats'],\n ajvOptionsOverrides: CustomValidatorOptionsType['ajvOptionsOverrides'] = {},\n ajvFormatOptions?: FormatsPluginOptions | false,\n AjvClass: typeof Ajv = Ajv\n) {\n const ajv = new AjvClass({ ...AJV_CONFIG, ...ajvOptionsOverrides });\n if (ajvFormatOptions) {\n addFormats(ajv, ajvFormatOptions);\n } else if (ajvFormatOptions !== false) {\n addFormats(ajv);\n }\n\n // add custom formats\n ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);\n ajv.addFormat('color', COLOR_FORMAT_REGEX);\n\n // Add RJSF-specific additional properties keywords so Ajv doesn't report errors if strict is enabled.\n ajv.addKeyword(ADDITIONAL_PROPERTY_FLAG);\n ajv.addKeyword(RJSF_ADDITONAL_PROPERTIES_FLAG);\n\n // add more schemas to validate against\n if (Array.isArray(additionalMetaSchemas)) {\n ajv.addMetaSchema(additionalMetaSchemas);\n }\n\n // add more custom formats to validate against\n if (isObject(customFormats)) {\n Object.keys(customFormats).forEach((formatName) => {\n ajv.addFormat(formatName, customFormats[formatName]);\n });\n }\n\n return ajv;\n}\n"],"names":["AJV_CONFIG","allErrors","multipleOfPrecision","strict","verbose","COLOR_FORMAT_REGEX","DATA_URL_FORMAT_REGEX","additionalMetaSchemas","customFormats","ajvOptionsOverrides","ajvFormatOptions","AjvClass","Ajv","ajv","_extends","addFormats","addFormat","addKeyword","ADDITIONAL_PROPERTY_FLAG","RJSF_ADDITONAL_PROPERTIES_FLAG","Array","isArray","addMetaSchema","isObject","Object","keys","forEach","formatName"],"mappings":"sbAOO,IAAMA,EAAsB,CACjCC,WAAW,EACXC,oBAAqB,EACrBC,QAAQ,EACRC,SAAS,GAEEC,EACX,6YACWC,EAAwB,kRAiBb,SACtBC,EACAC,EACAC,EACAC,EACAC,YAFAF,IAAAA,EAAyE,CAAA,YAEzEE,IAAAA,EAAuBC,EAAAA,SAEvB,IAAMC,EAAM,IAAIF,EAAQG,EAAA,CAAA,EAAMd,EAAeS,IA2B7C,OA1BIC,EACFK,UAAWF,EAAKH,IACc,IAArBA,GACTK,EAAU,QAACF,GAIbA,EAAIG,UAAU,WAAYV,GAC1BO,EAAIG,UAAU,QAASX,GAGvBQ,EAAII,WAAWC,EAAAA,0BACfL,EAAII,WAAWE,EAAAA,gCAGXC,MAAMC,QAAQd,IAChBM,EAAIS,cAAcf,GAIhBgB,EAAAA,QAASf,IACXgB,OAAOC,KAAKjB,GAAekB,SAAQ,SAACC,GAClCd,EAAIG,UAAUW,EAAYnB,EAAcmB,GAC1C,IAGKd,CACT"}
|
|
@@ -3,106 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var utils = require('@rjsf/utils');
|
|
6
|
-
var
|
|
7
|
-
var addFormats = require('ajv-formats');
|
|
8
|
-
var isObject = require('lodash/isObject');
|
|
6
|
+
var createAjvInstance = require('./createAjvInstance-0cd8cfba.js');
|
|
9
7
|
var get = require('lodash/get');
|
|
10
|
-
var fs = require('fs');
|
|
11
|
-
var standaloneCode = require('ajv/dist/standalone');
|
|
12
8
|
var isEqual = require('lodash/isEqual');
|
|
9
|
+
require('ajv');
|
|
10
|
+
require('ajv-formats');
|
|
11
|
+
require('lodash/isObject');
|
|
13
12
|
|
|
14
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
14
|
|
|
16
|
-
var Ajv__default = /*#__PURE__*/_interopDefaultLegacy(Ajv);
|
|
17
|
-
var addFormats__default = /*#__PURE__*/_interopDefaultLegacy(addFormats);
|
|
18
|
-
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
|
19
15
|
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
|
|
20
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
21
|
-
var standaloneCode__default = /*#__PURE__*/_interopDefaultLegacy(standaloneCode);
|
|
22
16
|
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
23
17
|
|
|
24
|
-
function _extends() {
|
|
25
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
26
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
27
|
-
var source = arguments[i];
|
|
28
|
-
for (var key in source) {
|
|
29
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
30
|
-
target[key] = source[key];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
|
-
return _extends.apply(this, arguments);
|
|
37
|
-
}
|
|
38
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
39
|
-
if (source == null) return {};
|
|
40
|
-
var target = {};
|
|
41
|
-
var sourceKeys = Object.keys(source);
|
|
42
|
-
var key, i;
|
|
43
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
44
|
-
key = sourceKeys[i];
|
|
45
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
46
|
-
target[key] = source[key];
|
|
47
|
-
}
|
|
48
|
-
return target;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var AJV_CONFIG = {
|
|
52
|
-
allErrors: true,
|
|
53
|
-
multipleOfPrecision: 8,
|
|
54
|
-
strict: false,
|
|
55
|
-
verbose: true
|
|
56
|
-
};
|
|
57
|
-
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*\)))$/;
|
|
58
|
-
var DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
|
|
59
|
-
/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.
|
|
60
|
-
* If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the
|
|
61
|
-
* list. If `customFormats` are provided then those additional formats are added to the list of supported formats. If
|
|
62
|
-
* `ajvOptionsOverrides` are provided then they are spread on top of the default `AJV_CONFIG` options when constructing
|
|
63
|
-
* the `Ajv` instance. With Ajv v8, the JSON Schema formats are not provided by default, but can be plugged in. By
|
|
64
|
-
* default, all formats from the `ajv-formats` library are added. To disable this capability, set the `ajvFormatOptions`
|
|
65
|
-
* parameter to `false`. Additionally, you can configure the `ajv-formats` by providing a custom set of
|
|
66
|
-
* [format options](https://github.com/ajv-validator/ajv-formats) to the `ajvFormatOptions` parameter.
|
|
67
|
-
*
|
|
68
|
-
* @param [additionalMetaSchemas] - The list of additional meta schemas that the validator can access
|
|
69
|
-
* @param [customFormats] - The set of additional custom formats that the validator will support
|
|
70
|
-
* @param [ajvOptionsOverrides={}] - The set of validator config override options
|
|
71
|
-
* @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it
|
|
72
|
-
* @param [AjvClass] - The `Ajv` class to use when creating the validator instance
|
|
73
|
-
*/
|
|
74
|
-
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass) {
|
|
75
|
-
if (ajvOptionsOverrides === void 0) {
|
|
76
|
-
ajvOptionsOverrides = {};
|
|
77
|
-
}
|
|
78
|
-
if (AjvClass === void 0) {
|
|
79
|
-
AjvClass = Ajv__default["default"];
|
|
80
|
-
}
|
|
81
|
-
var ajv = new AjvClass(_extends({}, AJV_CONFIG, ajvOptionsOverrides));
|
|
82
|
-
if (ajvFormatOptions) {
|
|
83
|
-
addFormats__default["default"](ajv, ajvFormatOptions);
|
|
84
|
-
} else if (ajvFormatOptions !== false) {
|
|
85
|
-
addFormats__default["default"](ajv);
|
|
86
|
-
}
|
|
87
|
-
// add custom formats
|
|
88
|
-
ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);
|
|
89
|
-
ajv.addFormat('color', COLOR_FORMAT_REGEX);
|
|
90
|
-
// Add RJSF-specific additional properties keywords so Ajv doesn't report errors if strict is enabled.
|
|
91
|
-
ajv.addKeyword(utils.ADDITIONAL_PROPERTY_FLAG);
|
|
92
|
-
ajv.addKeyword(utils.RJSF_ADDITONAL_PROPERTIES_FLAG);
|
|
93
|
-
// add more schemas to validate against
|
|
94
|
-
if (Array.isArray(additionalMetaSchemas)) {
|
|
95
|
-
ajv.addMetaSchema(additionalMetaSchemas);
|
|
96
|
-
}
|
|
97
|
-
// add more custom formats to validate against
|
|
98
|
-
if (isObject__default["default"](customFormats)) {
|
|
99
|
-
Object.keys(customFormats).forEach(function (formatName) {
|
|
100
|
-
ajv.addFormat(formatName, customFormats[formatName]);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
return ajv;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
18
|
var _excluded = ["instancePath", "keyword", "params", "schemaPath", "parentSchema"];
|
|
107
19
|
/** Transforming the error output from ajv to format used by @rjsf/utils.
|
|
108
20
|
* At some point, components should be updated to support ajv.
|
|
@@ -120,7 +32,7 @@ function transformRJSFValidationErrors(errors, uiSchema) {
|
|
|
120
32
|
params = e.params,
|
|
121
33
|
schemaPath = e.schemaPath,
|
|
122
34
|
parentSchema = e.parentSchema,
|
|
123
|
-
rest = _objectWithoutPropertiesLoose(e, _excluded);
|
|
35
|
+
rest = createAjvInstance._objectWithoutPropertiesLoose(e, _excluded);
|
|
124
36
|
var _rest$message = rest.message,
|
|
125
37
|
message = _rest$message === void 0 ? '' : _rest$message;
|
|
126
38
|
var property = instancePath.replace(/\//g, '.');
|
|
@@ -186,7 +98,7 @@ function processRawValidationErrors(validator, rawErrors, formData, schema, cust
|
|
|
186
98
|
}
|
|
187
99
|
var errorSchema = utils.toErrorSchema(errors);
|
|
188
100
|
if (invalidSchemaError) {
|
|
189
|
-
errorSchema = _extends({}, errorSchema, {
|
|
101
|
+
errorSchema = createAjvInstance._extends({}, errorSchema, {
|
|
190
102
|
$schema: {
|
|
191
103
|
__errors: [invalidSchemaError.message]
|
|
192
104
|
}
|
|
@@ -232,7 +144,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
232
144
|
ajvOptionsOverrides = options.ajvOptionsOverrides,
|
|
233
145
|
ajvFormatOptions = options.ajvFormatOptions,
|
|
234
146
|
AjvClass = options.AjvClass;
|
|
235
|
-
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);
|
|
147
|
+
this.ajv = createAjvInstance.createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);
|
|
236
148
|
this.localizer = localizer;
|
|
237
149
|
}
|
|
238
150
|
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
@@ -354,46 +266,6 @@ function customizeValidator(options, localizer) {
|
|
|
354
266
|
return new AJV8Validator(options, localizer);
|
|
355
267
|
}
|
|
356
268
|
|
|
357
|
-
/** The function used to compile a schema into an output file in the form that allows it to be used as a precompiled
|
|
358
|
-
* validator. The main reasons for using a precompiled validator is reducing code size, improving validation speed and,
|
|
359
|
-
* most importantly, avoiding dynamic code compilation when prohibited by a browser's Content Security Policy. For more
|
|
360
|
-
* information about AJV code compilation see: https://ajv.js.org/standalone.html
|
|
361
|
-
*
|
|
362
|
-
* @param schema - The schema to be compiled into a set of precompiled validators functions
|
|
363
|
-
* @param output - The name of the file into which the precompiled validator functions will be generated
|
|
364
|
-
* @param [options={}] - The set of `CustomValidatorOptionsType` information used to alter the AJV validator used for
|
|
365
|
-
* compiling the schema. They are the same options that are passed to the `customizeValidator()` function in
|
|
366
|
-
* order to modify the behavior of the regular AJV-based validator.
|
|
367
|
-
*/
|
|
368
|
-
function compileSchemaValidators(schema, output, options) {
|
|
369
|
-
if (options === void 0) {
|
|
370
|
-
options = {};
|
|
371
|
-
}
|
|
372
|
-
console.log('parsing the schema');
|
|
373
|
-
var schemaMaps = utils.schemaParser(schema);
|
|
374
|
-
var schemas = Object.values(schemaMaps);
|
|
375
|
-
var _options = options,
|
|
376
|
-
additionalMetaSchemas = _options.additionalMetaSchemas,
|
|
377
|
-
customFormats = _options.customFormats,
|
|
378
|
-
_options$ajvOptionsOv = _options.ajvOptionsOverrides,
|
|
379
|
-
ajvOptionsOverrides = _options$ajvOptionsOv === void 0 ? {} : _options$ajvOptionsOv,
|
|
380
|
-
ajvFormatOptions = _options.ajvFormatOptions,
|
|
381
|
-
AjvClass = _options.AjvClass;
|
|
382
|
-
// Allow users to turn off the `lines: true` feature in their own overrides, but NOT the `source: true`
|
|
383
|
-
var compileOptions = _extends({}, ajvOptionsOverrides, {
|
|
384
|
-
code: _extends({
|
|
385
|
-
lines: true
|
|
386
|
-
}, ajvOptionsOverrides.code, {
|
|
387
|
-
source: true
|
|
388
|
-
}),
|
|
389
|
-
schemas: schemas
|
|
390
|
-
});
|
|
391
|
-
var ajv = createAjvInstance(additionalMetaSchemas, customFormats, compileOptions, ajvFormatOptions, AjvClass);
|
|
392
|
-
var moduleCode = standaloneCode__default["default"](ajv);
|
|
393
|
-
console.log("writing " + output);
|
|
394
|
-
fs__default["default"].writeFileSync(output, moduleCode);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
269
|
/** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the
|
|
398
270
|
* `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.
|
|
399
271
|
*/
|
|
@@ -533,8 +405,7 @@ function createPrecompiledValidator(validateFns, rootSchema, localizer) {
|
|
|
533
405
|
|
|
534
406
|
var index = /*#__PURE__*/customizeValidator();
|
|
535
407
|
|
|
536
|
-
exports.compileSchemaValidators = compileSchemaValidators;
|
|
537
408
|
exports.createPrecompiledValidator = createPrecompiledValidator;
|
|
538
409
|
exports.customizeValidator = customizeValidator;
|
|
539
410
|
exports["default"] = index;
|
|
540
|
-
//# sourceMappingURL=
|
|
411
|
+
//# sourceMappingURL=index.cjs.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.development.js","sources":["../src/processRawValidationErrors.ts","../src/validator.ts","../src/customizeValidator.ts","../src/precompiledValidator.ts","../src/createPrecompiledValidator.ts","../src/index.ts"],"sourcesContent":["import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport {\n createErrorHandler,\n CustomValidator,\n ErrorTransformer,\n FormContextType,\n getDefaultFormState,\n getUiOptions,\n PROPERTIES_KEY,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n toErrorSchema,\n UiSchema,\n unwrapErrorHandler,\n validationDataMerge,\n ValidatorType,\n} from '@rjsf/utils';\n\nexport type RawValidationErrorsType<Result = any> = { errors?: Result[]; validationError?: Error };\n\n/** Transforming the error output from ajv to format used by @rjsf/utils.\n * At some point, components should be updated to support ajv.\n *\n * @param errors - The list of AJV errors to convert to `RJSFValidationErrors`\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport function transformRJSFValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(errors: ErrorObject[] = [], uiSchema?: UiSchema<T, S, F>): RJSFValidationError[] {\n return errors.map((e: ErrorObject) => {\n const { instancePath, keyword, params, schemaPath, parentSchema, ...rest } = e;\n let { message = '' } = rest;\n let property = instancePath.replace(/\\//g, '.');\n let stack = `${property} ${message}`.trim();\n\n if ('missingProperty' in params) {\n property = property ? `${property}.${params.missingProperty}` : params.missingProperty;\n const currentProperty: string = params.missingProperty;\n const uiSchemaTitle = getUiOptions(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n message = message.replace(currentProperty, uiSchemaTitle);\n } else {\n const parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']);\n\n if (parentSchemaTitle) {\n message = message.replace(currentProperty, parentSchemaTitle);\n }\n }\n\n stack = message;\n } else {\n const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n stack = `'${uiSchemaTitle}' ${message}`.trim();\n } else {\n const parentSchemaTitle = parentSchema?.title;\n\n if (parentSchemaTitle) {\n stack = `'${parentSchemaTitle}' ${message}`.trim();\n }\n }\n }\n\n // put data in expected format\n return {\n name: keyword,\n property,\n message,\n params, // specific to ajv\n stack,\n schemaPath,\n };\n });\n}\n\n/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param validator - The `ValidatorType` implementation used for the `getDefaultFormState()` call\n * @param rawErrors - The list of raw `ErrorObject`s to process\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport default function processRawValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(\n validator: ValidatorType<T, S, F>,\n rawErrors: RawValidationErrorsType<ErrorObject>,\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n) {\n const { validationError: invalidSchemaError } = rawErrors;\n let errors = transformRJSFValidationErrors<T, S, F>(rawErrors.errors, uiSchema);\n\n if (invalidSchemaError) {\n errors = [...errors, { stack: invalidSchemaError!.message }];\n }\n if (typeof transformErrors === 'function') {\n errors = transformErrors(errors, uiSchema);\n }\n\n let errorSchema = toErrorSchema<T>(errors);\n\n if (invalidSchemaError) {\n errorSchema = {\n ...errorSchema,\n $schema: {\n __errors: [invalidSchemaError!.message],\n },\n };\n }\n\n if (typeof customValidate !== 'function') {\n return { errors, errorSchema };\n }\n\n // Include form data with undefined values, which is required for custom validation.\n const newFormData = getDefaultFormState<T, S, F>(validator, schema, formData, schema, true) as T;\n\n const errorHandler = customValidate(newFormData, createErrorHandler<T>(newFormData), uiSchema);\n const userErrorSchema = unwrapErrorHandler<T>(errorHandler);\n return validationDataMerge<T>({ errors, errorSchema }, userErrorSchema);\n}\n","import Ajv, { ErrorObject, ValidateFunction } from 'ajv';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n ID_KEY,\n RJSFSchema,\n ROOT_SCHEMA_PREFIX,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n withIdRefPrefix,\n} from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport createAjvInstance from './createAjvInstance';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.\n */\nexport default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>\n implements ValidatorType<T, S, F>\n{\n /** The AJV instance to use for all validations\n *\n * @private\n */\n private ajv: Ajv;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8Validator` instance using the `options`\n *\n * @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n */\n constructor(options: CustomValidatorOptionsType, localizer?: Localizer) {\n const { additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass } = options;\n this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);\n this.localizer = localizer;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema[ID_KEY]) {\n compiledValidator = this.ajv.getSchema(schema[ID_KEY]);\n }\n try {\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schema);\n }\n compiledValidator(formData);\n } catch (err) {\n compilationError = err as Error;\n }\n\n let errors;\n if (compiledValidator) {\n if (typeof this.localizer === 'function') {\n this.localizer(compiledValidator.errors);\n }\n errors = compiledValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n compiledValidator.errors = null;\n }\n\n return {\n errors: errors as unknown as Result[],\n validationError: compilationError,\n };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or\n * false otherwise. If the schema is invalid, then this function will return\n * false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n const rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX;\n try {\n // add the rootSchema ROOT_SCHEMA_PREFIX as id.\n // then rewrite the schema ref's to point to the rootSchema\n // this accounts for the case where schema have references to models\n // that lives in the rootSchema but not in the schema in question.\n if (this.ajv.getSchema(rootSchemaId) === undefined) {\n this.ajv.addSchema(rootSchema, rootSchemaId);\n }\n const schemaWithIdRefPrefix = withIdRefPrefix<S>(schema) as S;\n let compiledValidator: ValidateFunction | undefined;\n if (schemaWithIdRefPrefix[ID_KEY]) {\n compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix[ID_KEY]);\n }\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schemaWithIdRefPrefix);\n }\n const result = compiledValidator(formData);\n return result as boolean;\n } catch (e) {\n console.warn('Error encountered compiling schema:', e);\n return false;\n } finally {\n // TODO: A function should be called if the root schema changes so we don't have to remove and recompile the schema every run.\n // make sure we remove the rootSchema from the global ajv instance\n this.ajv.removeSchema(rootSchemaId);\n }\n }\n}\n","import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport AJV8Validator from './validator';\n\n/** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if\n * provided. If a `localizer` is provided, it is used to translate the messages generated by the underlying AJV\n * validation.\n *\n * @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The custom validator implementation resulting from the set of parameters provided\n */\nexport default function customizeValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(options: CustomValidatorOptionsType = {}, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8Validator<T, S, F>(options, localizer);\n}\n","import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport isEqual from 'lodash/isEqual';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n hashForSchema,\n ID_KEY,\n RJSFSchema,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n} from '@rjsf/utils';\n\nimport { CompiledValidateFunction, Localizer, ValidatorFunctions } from './types';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the\n * `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.\n */\nexport default class AJV8PrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n> implements ValidatorType<T, S, F>\n{\n /** The root schema object used to construct this validator\n *\n * @private\n */\n readonly rootSchema: S;\n\n /** The `ValidatorFunctions` map used to construct this validator\n *\n * @private\n */\n readonly validateFns: ValidatorFunctions<T>;\n\n /** The main validator function associated with the base schema in the `precompiledValidator`\n *\n * @private\n */\n readonly mainValidator: CompiledValidateFunction<T>;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8PrecompiledValidator` instance using the `validateFns` and `rootSchema`\n *\n * @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function\n * @param rootSchema - The root schema that was used with the `compileSchema()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @throws - Error when the base schema of the precompiled validator does not have a matching validator function\n */\n constructor(validateFns: ValidatorFunctions<T>, rootSchema: S, localizer?: Localizer) {\n this.rootSchema = rootSchema;\n this.validateFns = validateFns;\n this.localizer = localizer;\n this.mainValidator = this.getValidator(rootSchema);\n }\n\n /** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator\n * functions.\n *\n * @param schema - The schema for which a precompiled validator function is desired\n * @returns - The precompiled validator function associated with this schema\n */\n getValidator(schema: S) {\n const key = get(schema, ID_KEY) || hashForSchema(schema);\n const validator = this.validateFns[key];\n if (!validator) {\n throw new Error(`No precompiled validator function was found for the given schema for \"${key}\"`);\n }\n return validator;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n if (!isEqual(schema, this.rootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled schema differs from the schema provided for validation'\n );\n }\n this.mainValidator(formData);\n\n if (typeof this.localizer === 'function') {\n this.localizer(this.mainValidator.errors);\n }\n const errors = this.mainValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n this.mainValidator.errors = null;\n\n return { errors: errors as unknown as Result[] };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is\n * invalid, then this function will return false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n * @returns - true if the formData validates against the schema, false otherwise\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there\n * isn't a precompiled validator function associated with the schema\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n if (!isEqual(rootSchema, this.rootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled validator differs from the rootSchema provided for validation'\n );\n }\n const validator = this.getValidator(schema);\n return validator(formData);\n }\n}\n","import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { Localizer, ValidatorFunctions } from './types';\nimport AJV8PrecompiledValidator from './precompiledValidator';\n\n/** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`\n * is provided, it is used to translate the messages generated by the underlying AJV validation.\n *\n * NOTE: The `validateFns` parameter is an object obtained by importing from a precompiled validation file created via\n * the `compileSchemaValidators()` function.\n *\n * @param validateFns - The map of the validation functions that are created by the `compileSchemaValidators()` function\n * @param rootSchema - The root schema that was used with the `compileSchemaValidators()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The precompiled validator implementation resulting from the set of parameters provided\n */\nexport default function createPrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(validateFns: ValidatorFunctions<T>, rootSchema: S, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8PrecompiledValidator<T, S, F>(validateFns, rootSchema, localizer);\n}\n","import customizeValidator from './customizeValidator';\nimport createPrecompiledValidator from './createPrecompiledValidator';\n\nexport { customizeValidator, createPrecompiledValidator };\nexport * from './types';\n\nexport default customizeValidator();\n"],"names":["transformRJSFValidationErrors","errors","uiSchema","map","e","instancePath","keyword","params","schemaPath","parentSchema","rest","_objectWithoutPropertiesLoose","_excluded","_rest$message","message","property","replace","stack","trim","missingProperty","currentProperty","uiSchemaTitle","getUiOptions","get","title","parentSchemaTitle","PROPERTIES_KEY","name","processRawValidationErrors","validator","rawErrors","formData","schema","customValidate","transformErrors","invalidSchemaError","validationError","concat","errorSchema","toErrorSchema","_extends","$schema","__errors","newFormData","getDefaultFormState","errorHandler","createErrorHandler","userErrorSchema","unwrapErrorHandler","validationDataMerge","AJV8Validator","options","localizer","ajv","additionalMetaSchemas","customFormats","ajvOptionsOverrides","ajvFormatOptions","AjvClass","createAjvInstance","_proto","prototype","toErrorList","fieldPath","rawValidation","compilationError","undefined","compiledValidator","ID_KEY","getSchema","compile","err","validateFormData","isValid","rootSchema","_rootSchema$ID_KEY","rootSchemaId","ROOT_SCHEMA_PREFIX","addSchema","schemaWithIdRefPrefix","withIdRefPrefix","result","console","warn","removeSchema","customizeValidator","AJV8PrecompiledValidator","validateFns","mainValidator","getValidator","key","hashForSchema","Error","isEqual","createPrecompiledValidator"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA;;;;;AAKG;SACaA,6BAA6BA,CAI3CC,MAAwB,EAAIC,QAA4B,EAAA;AAAA,EAAA,IAAxDD,MAAwB,KAAA,KAAA,CAAA,EAAA;AAAxBA,IAAAA,MAAwB,GAAA,EAAE,CAAA;AAAA,GAAA;AAC1B,EAAA,OAAOA,MAAM,CAACE,GAAG,CAAC,UAACC,CAAc,EAAI;AACnC,IAAA,IAAQC,YAAY,GAAyDD,CAAC,CAAtEC,YAAY;MAAEC,OAAO,GAAgDF,CAAC,CAAxDE,OAAO;MAAEC,MAAM,GAAwCH,CAAC,CAA/CG,MAAM;MAAEC,UAAU,GAA4BJ,CAAC,CAAvCI,UAAU;MAAEC,YAAY,GAAcL,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ChC,QAA4B,EAAA;IAE5B,IAAM4B,SAAS,GAAG,IAAI,CAACkC,aAAa,CAAchC,MAAM,EAAED,QAAQ,CAAC,CAAA;AACnE,IAAA,OAAOH,0BAA0B,CAAC,IAAI,EAAEE,SAAS,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,cAAc,EAAEC,eAAe,EAAEhC,QAAQ,CAAC,CAAA;AACjH,GAAA;AAEA;;;;;;;;;AASG,MATH;EAAA0D,MAAA,CAUAa,OAAO,GAAP,SAAAA,OAAAA,CAAQzC,MAAS,EAAED,QAAuB,EAAE2C,UAAa,EAAA;IACvD,IAAI,CAACmB,2BAAO,CAACnB,UAAU,EAAE,IAAI,CAACA,UAAU,CAAC,EAAE;AACzC,MAAA,MAAM,IAAIkB,KAAK,CACb,0GAA0G,CAC3G,CAAA;AACF,KAAA;AACD,IAAA,IAAM/D,SAAS,GAAG,IAAI,CAAC4D,YAAY,CAACzD,MAAM,CAAC,CAAA;IAC3C,OAAOH,SAAS,CAACE,QAAQ,CAAC,CAAA;GAC3B,CAAA;AAAA,EAAA,OAAAuD,wBAAA,CAAA;AAAA,CAAA,EAAA;;AC3JH;;;;;;;;;;AAUG;AACqB,SAAAQ,0BAA0BA,CAIhDP,WAAkC,EAAEb,UAAa,EAAEtB,SAAqB,EAAA;EACxE,OAAO,IAAIkC,wBAAwB,CAAUC,WAAW,EAAEb,UAAU,EAAEtB,SAAS,CAAC,CAAA;AAClF;;AChBA,YAAeiC,aAAAA,kBAAkB,EAAE;;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("@rjsf/utils"),t=require("./createAjvInstance-0cd8cfba.js"),e=require("lodash/get"),a=require("lodash/isEqual");function i(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}require("ajv"),require("ajv-formats"),require("lodash/isObject");var o=i(e),s=i(a),n=["instancePath","keyword","params","schemaPath","parentSchema"];function c(e,a,i,s,c,l,h){var d=a.validationError,u=function(e,a){return void 0===e&&(e=[]),e.map((function(e){var i=e.instancePath,s=e.keyword,c=e.params,l=e.schemaPath,h=e.parentSchema,d=t._objectWithoutPropertiesLoose(e,n).message,u=void 0===d?"":d,v=i.replace(/\//g,"."),m=(v+" "+u).trim();if("missingProperty"in c){var f=c.missingProperty,p=r.getUiOptions(o.default(a,""+(v=v?v+"."+c.missingProperty:c.missingProperty).replace(/^\./,""))).title;if(p)u=u.replace(f,p);else{var E=o.default(h,[r.PROPERTIES_KEY,f,"title"]);E&&(u=u.replace(f,E))}m=u}else{var g=r.getUiOptions(o.default(a,""+v.replace(/^\./,""))).title;if(g)m=("'"+g+"' "+u).trim();else{var j=null==h?void 0:h.title;j&&(m=("'"+j+"' "+u).trim())}}return{name:s,property:v,message:u,params:c,stack:m,schemaPath:l}}))}(a.errors,h);d&&(u=[].concat(u,[{stack:d.message}])),"function"==typeof l&&(u=l(u,h));var v=r.toErrorSchema(u);if(d&&(v=t._extends({},v,{$schema:{__errors:[d.message]}})),"function"!=typeof c)return{errors:u,errorSchema:v};var m=r.getDefaultFormState(e,s,i,s,!0),f=c(m,r.createErrorHandler(m),h),p=r.unwrapErrorHandler(f);return r.validationDataMerge({errors:u,errorSchema:v},p)}var l=function(){function e(r,e){this.ajv=void 0,this.localizer=void 0,this.ajv=t.createAjvInstance(r.additionalMetaSchemas,r.customFormats,r.ajvOptionsOverrides,r.ajvFormatOptions,r.AjvClass),this.localizer=e}var a=e.prototype;return a.toErrorList=function(t,e){return void 0===e&&(e=[]),r.toErrorList(t,e)},a.rawValidation=function(t,e){var a,i,o=void 0;t[r.ID_KEY]&&(a=this.ajv.getSchema(t[r.ID_KEY]));try{void 0===a&&(a=this.ajv.compile(t)),a(e)}catch(r){o=r}return a&&("function"==typeof this.localizer&&this.localizer(a.errors),i=a.errors||void 0,a.errors=null),{errors:i,validationError:o}},a.validateFormData=function(r,t,e,a,i){return c(this,this.rawValidation(t,r),r,t,e,a,i)},a.isValid=function(t,e,a){var i,o=null!=(i=a[r.ID_KEY])?i:r.ROOT_SCHEMA_PREFIX;try{void 0===this.ajv.getSchema(o)&&this.ajv.addSchema(a,o);var s,n=r.withIdRefPrefix(t);return n[r.ID_KEY]&&(s=this.ajv.getSchema(n[r.ID_KEY])),void 0===s&&(s=this.ajv.compile(n)),s(e)}catch(r){return console.warn("Error encountered compiling schema:",r),!1}finally{this.ajv.removeSchema(o)}},e}();function h(r,t){return void 0===r&&(r={}),new l(r,t)}var d=function(){function t(r,t,e){this.rootSchema=void 0,this.validateFns=void 0,this.mainValidator=void 0,this.localizer=void 0,this.rootSchema=t,this.validateFns=r,this.localizer=e,this.mainValidator=this.getValidator(t)}var e=t.prototype;return e.getValidator=function(t){var e=o.default(t,r.ID_KEY)||r.hashForSchema(t),a=this.validateFns[e];if(!a)throw new Error('No precompiled validator function was found for the given schema for "'+e+'"');return a},e.toErrorList=function(t,e){return void 0===e&&(e=[]),r.toErrorList(t,e)},e.rawValidation=function(r,t){if(!s.default(r,this.rootSchema))throw new Error("The schema associated with the precompiled schema differs from the schema provided for validation");this.mainValidator(t),"function"==typeof this.localizer&&this.localizer(this.mainValidator.errors);var e=this.mainValidator.errors||void 0;return this.mainValidator.errors=null,{errors:e}},e.validateFormData=function(r,t,e,a,i){return c(this,this.rawValidation(t,r),r,t,e,a,i)},e.isValid=function(r,t,e){if(!s.default(e,this.rootSchema))throw new Error("The schema associated with the precompiled validator differs from the rootSchema provided for validation");return this.getValidator(r)(t)},t}(),u=h();exports.createPrecompiledValidator=function(r,t,e){return new d(r,t,e)},exports.customizeValidator=h,exports.default=u;
|
|
2
|
+
//# sourceMappingURL=index.cjs.production.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.production.min.js","sources":["../src/processRawValidationErrors.ts","../src/validator.ts","../src/customizeValidator.ts","../src/precompiledValidator.ts","../src/index.ts","../src/createPrecompiledValidator.ts"],"sourcesContent":["import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport {\n createErrorHandler,\n CustomValidator,\n ErrorTransformer,\n FormContextType,\n getDefaultFormState,\n getUiOptions,\n PROPERTIES_KEY,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n toErrorSchema,\n UiSchema,\n unwrapErrorHandler,\n validationDataMerge,\n ValidatorType,\n} from '@rjsf/utils';\n\nexport type RawValidationErrorsType<Result = any> = { errors?: Result[]; validationError?: Error };\n\n/** Transforming the error output from ajv to format used by @rjsf/utils.\n * At some point, components should be updated to support ajv.\n *\n * @param errors - The list of AJV errors to convert to `RJSFValidationErrors`\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport function transformRJSFValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(errors: ErrorObject[] = [], uiSchema?: UiSchema<T, S, F>): RJSFValidationError[] {\n return errors.map((e: ErrorObject) => {\n const { instancePath, keyword, params, schemaPath, parentSchema, ...rest } = e;\n let { message = '' } = rest;\n let property = instancePath.replace(/\\//g, '.');\n let stack = `${property} ${message}`.trim();\n\n if ('missingProperty' in params) {\n property = property ? `${property}.${params.missingProperty}` : params.missingProperty;\n const currentProperty: string = params.missingProperty;\n const uiSchemaTitle = getUiOptions(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n message = message.replace(currentProperty, uiSchemaTitle);\n } else {\n const parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']);\n\n if (parentSchemaTitle) {\n message = message.replace(currentProperty, parentSchemaTitle);\n }\n }\n\n stack = message;\n } else {\n const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n stack = `'${uiSchemaTitle}' ${message}`.trim();\n } else {\n const parentSchemaTitle = parentSchema?.title;\n\n if (parentSchemaTitle) {\n stack = `'${parentSchemaTitle}' ${message}`.trim();\n }\n }\n }\n\n // put data in expected format\n return {\n name: keyword,\n property,\n message,\n params, // specific to ajv\n stack,\n schemaPath,\n };\n });\n}\n\n/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param validator - The `ValidatorType` implementation used for the `getDefaultFormState()` call\n * @param rawErrors - The list of raw `ErrorObject`s to process\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport default function processRawValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(\n validator: ValidatorType<T, S, F>,\n rawErrors: RawValidationErrorsType<ErrorObject>,\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n) {\n const { validationError: invalidSchemaError } = rawErrors;\n let errors = transformRJSFValidationErrors<T, S, F>(rawErrors.errors, uiSchema);\n\n if (invalidSchemaError) {\n errors = [...errors, { stack: invalidSchemaError!.message }];\n }\n if (typeof transformErrors === 'function') {\n errors = transformErrors(errors, uiSchema);\n }\n\n let errorSchema = toErrorSchema<T>(errors);\n\n if (invalidSchemaError) {\n errorSchema = {\n ...errorSchema,\n $schema: {\n __errors: [invalidSchemaError!.message],\n },\n };\n }\n\n if (typeof customValidate !== 'function') {\n return { errors, errorSchema };\n }\n\n // Include form data with undefined values, which is required for custom validation.\n const newFormData = getDefaultFormState<T, S, F>(validator, schema, formData, schema, true) as T;\n\n const errorHandler = customValidate(newFormData, createErrorHandler<T>(newFormData), uiSchema);\n const userErrorSchema = unwrapErrorHandler<T>(errorHandler);\n return validationDataMerge<T>({ errors, errorSchema }, userErrorSchema);\n}\n","import Ajv, { ErrorObject, ValidateFunction } from 'ajv';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n ID_KEY,\n RJSFSchema,\n ROOT_SCHEMA_PREFIX,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n withIdRefPrefix,\n} from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport createAjvInstance from './createAjvInstance';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.\n */\nexport default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>\n implements ValidatorType<T, S, F>\n{\n /** The AJV instance to use for all validations\n *\n * @private\n */\n private ajv: Ajv;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8Validator` instance using the `options`\n *\n * @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n */\n constructor(options: CustomValidatorOptionsType, localizer?: Localizer) {\n const { additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass } = options;\n this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);\n this.localizer = localizer;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema[ID_KEY]) {\n compiledValidator = this.ajv.getSchema(schema[ID_KEY]);\n }\n try {\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schema);\n }\n compiledValidator(formData);\n } catch (err) {\n compilationError = err as Error;\n }\n\n let errors;\n if (compiledValidator) {\n if (typeof this.localizer === 'function') {\n this.localizer(compiledValidator.errors);\n }\n errors = compiledValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n compiledValidator.errors = null;\n }\n\n return {\n errors: errors as unknown as Result[],\n validationError: compilationError,\n };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or\n * false otherwise. If the schema is invalid, then this function will return\n * false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n const rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX;\n try {\n // add the rootSchema ROOT_SCHEMA_PREFIX as id.\n // then rewrite the schema ref's to point to the rootSchema\n // this accounts for the case where schema have references to models\n // that lives in the rootSchema but not in the schema in question.\n if (this.ajv.getSchema(rootSchemaId) === undefined) {\n this.ajv.addSchema(rootSchema, rootSchemaId);\n }\n const schemaWithIdRefPrefix = withIdRefPrefix<S>(schema) as S;\n let compiledValidator: ValidateFunction | undefined;\n if (schemaWithIdRefPrefix[ID_KEY]) {\n compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix[ID_KEY]);\n }\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schemaWithIdRefPrefix);\n }\n const result = compiledValidator(formData);\n return result as boolean;\n } catch (e) {\n console.warn('Error encountered compiling schema:', e);\n return false;\n } finally {\n // TODO: A function should be called if the root schema changes so we don't have to remove and recompile the schema every run.\n // make sure we remove the rootSchema from the global ajv instance\n this.ajv.removeSchema(rootSchemaId);\n }\n }\n}\n","import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport AJV8Validator from './validator';\n\n/** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if\n * provided. If a `localizer` is provided, it is used to translate the messages generated by the underlying AJV\n * validation.\n *\n * @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The custom validator implementation resulting from the set of parameters provided\n */\nexport default function customizeValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(options: CustomValidatorOptionsType = {}, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8Validator<T, S, F>(options, localizer);\n}\n","import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport isEqual from 'lodash/isEqual';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n hashForSchema,\n ID_KEY,\n RJSFSchema,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n} from '@rjsf/utils';\n\nimport { CompiledValidateFunction, Localizer, ValidatorFunctions } from './types';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the\n * `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.\n */\nexport default class AJV8PrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n> implements ValidatorType<T, S, F>\n{\n /** The root schema object used to construct this validator\n *\n * @private\n */\n readonly rootSchema: S;\n\n /** The `ValidatorFunctions` map used to construct this validator\n *\n * @private\n */\n readonly validateFns: ValidatorFunctions<T>;\n\n /** The main validator function associated with the base schema in the `precompiledValidator`\n *\n * @private\n */\n readonly mainValidator: CompiledValidateFunction<T>;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8PrecompiledValidator` instance using the `validateFns` and `rootSchema`\n *\n * @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function\n * @param rootSchema - The root schema that was used with the `compileSchema()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @throws - Error when the base schema of the precompiled validator does not have a matching validator function\n */\n constructor(validateFns: ValidatorFunctions<T>, rootSchema: S, localizer?: Localizer) {\n this.rootSchema = rootSchema;\n this.validateFns = validateFns;\n this.localizer = localizer;\n this.mainValidator = this.getValidator(rootSchema);\n }\n\n /** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator\n * functions.\n *\n * @param schema - The schema for which a precompiled validator function is desired\n * @returns - The precompiled validator function associated with this schema\n */\n getValidator(schema: S) {\n const key = get(schema, ID_KEY) || hashForSchema(schema);\n const validator = this.validateFns[key];\n if (!validator) {\n throw new Error(`No precompiled validator function was found for the given schema for \"${key}\"`);\n }\n return validator;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n if (!isEqual(schema, this.rootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled schema differs from the schema provided for validation'\n );\n }\n this.mainValidator(formData);\n\n if (typeof this.localizer === 'function') {\n this.localizer(this.mainValidator.errors);\n }\n const errors = this.mainValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n this.mainValidator.errors = null;\n\n return { errors: errors as unknown as Result[] };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is\n * invalid, then this function will return false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n * @returns - true if the formData validates against the schema, false otherwise\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there\n * isn't a precompiled validator function associated with the schema\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n if (!isEqual(rootSchema, this.rootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled validator differs from the rootSchema provided for validation'\n );\n }\n const validator = this.getValidator(schema);\n return validator(formData);\n }\n}\n","import customizeValidator from './customizeValidator';\nimport createPrecompiledValidator from './createPrecompiledValidator';\n\nexport { customizeValidator, createPrecompiledValidator };\nexport * from './types';\n\nexport default customizeValidator();\n","import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { Localizer, ValidatorFunctions } from './types';\nimport AJV8PrecompiledValidator from './precompiledValidator';\n\n/** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`\n * is provided, it is used to translate the messages generated by the underlying AJV validation.\n *\n * NOTE: The `validateFns` parameter is an object obtained by importing from a precompiled validation file created via\n * the `compileSchemaValidators()` function.\n *\n * @param validateFns - The map of the validation functions that are created by the `compileSchemaValidators()` function\n * @param rootSchema - The root schema that was used with the `compileSchemaValidators()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The precompiled validator implementation resulting from the set of parameters provided\n */\nexport default function createPrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(validateFns: ValidatorFunctions<T>, rootSchema: S, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8PrecompiledValidator<T, S, F>(validateFns, rootSchema, localizer);\n}\n"],"names":["processRawValidationErrors","validator","rawErrors","formData","schema","customValidate","transformErrors","uiSchema","invalidSchemaError","validationError","errors","map","e","instancePath","keyword","params","schemaPath","parentSchema","_rest$message","_objectWithoutPropertiesLoose","_excluded","message","property","replace","stack","trim","currentProperty","missingProperty","uiSchemaTitle","getUiOptions","get","title","parentSchemaTitle","PROPERTIES_KEY","name","transformRJSFValidationErrors","concat","errorSchema","toErrorSchema","_extends","$schema","__errors","newFormData","getDefaultFormState","errorHandler","createErrorHandler","userErrorSchema","unwrapErrorHandler","validationDataMerge","AJV8Validator","options","localizer","this","ajv","createAjvInstance","additionalMetaSchemas","customFormats","ajvOptionsOverrides","ajvFormatOptions","AjvClass","_proto","prototype","toErrorList","fieldPath","rawValidation","compiledValidator","compilationError","undefined","ID_KEY","getSchema","compile","err","validateFormData","isValid","rootSchema","_rootSchema$ID_KEY","rootSchemaId","ROOT_SCHEMA_PREFIX","addSchema","schemaWithIdRefPrefix","withIdRefPrefix","console","warn","removeSchema","customizeValidator","AJV8PrecompiledValidator","validateFns","mainValidator","getValidator","key","hashForSchema","Error","isEqual"],"mappings":"+ZA8Fc,SAAUA,EAKtBC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,IAAyBC,EAAuBN,EAAxCO,gBACJC,WA5EJA,EAA4BH,GAC5B,YADwB,IAAxBG,IAAAA,EAAwB,IACjBA,EAAOC,KAAI,SAACC,GACjB,IAAQC,EAAqED,EAArEC,aAAcC,EAAuDF,EAAvDE,QAASC,EAA8CH,EAA9CG,OAAQC,EAAsCJ,EAAtCI,WAAYC,EAA0BL,EAA1BK,aACnDC,EADwEC,EAAAA,8BAAKP,EAACQ,GACxEC,QAAAA,OAAU,IAAHH,EAAG,GAAEA,EACdI,EAAWT,EAAaU,QAAQ,MAAO,KACvCC,GAAWF,MAAYD,GAAUI,OAErC,GAAI,oBAAqBV,EAAQ,CAE/B,IAAMW,EAA0BX,EAAOY,gBACjCC,EAAgBC,EAAAA,aAAaC,EAAG,QAACvB,EAAae,IAFpDA,EAAWA,EAAcA,EAAQ,IAAIP,EAAOY,gBAAoBZ,EAAOY,iBAEV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,EAEAkD,EAWAY,iBAAA,SACErE,EACAC,EACAC,EACAC,EACAC,GAGA,OAAOP,EAA2BoD,KADhBA,KAAKY,cAA2B5D,EAAQD,GACPA,EAAUC,EAAQC,EAAgBC,EAAiBC,EACxG,EAEAqD,EAUAa,QAAA,SAAQrE,EAAWD,EAAyBuE,GAC1C,IAAKkB,EAAAA,QAAQlB,EAAYtB,KAAKsB,YAC5B,MAAM,IAAIiB,MACR,4GAIJ,OADkBvC,KAAKoC,aAAapF,EAC7BH,CAAUE,IAClBkF,CAAA,CAxI0C,GClB9BD,EAAAA,uCCUS,SAItBE,EAAoCZ,EAAevB,GACnD,OAAO,IAAIkC,EAAkCC,EAAaZ,EAAYvB,EACxE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -48,19 +48,6 @@ type ValidatorFunctions<T = any> = {
|
|
|
48
48
|
*/
|
|
49
49
|
declare function customizeValidator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(options?: CustomValidatorOptionsType, localizer?: Localizer): ValidatorType<T, S, F>;
|
|
50
50
|
|
|
51
|
-
/** The function used to compile a schema into an output file in the form that allows it to be used as a precompiled
|
|
52
|
-
* validator. The main reasons for using a precompiled validator is reducing code size, improving validation speed and,
|
|
53
|
-
* most importantly, avoiding dynamic code compilation when prohibited by a browser's Content Security Policy. For more
|
|
54
|
-
* information about AJV code compilation see: https://ajv.js.org/standalone.html
|
|
55
|
-
*
|
|
56
|
-
* @param schema - The schema to be compiled into a set of precompiled validators functions
|
|
57
|
-
* @param output - The name of the file into which the precompiled validator functions will be generated
|
|
58
|
-
* @param [options={}] - The set of `CustomValidatorOptionsType` information used to alter the AJV validator used for
|
|
59
|
-
* compiling the schema. They are the same options that are passed to the `customizeValidator()` function in
|
|
60
|
-
* order to modify the behavior of the regular AJV-based validator.
|
|
61
|
-
*/
|
|
62
|
-
declare function compileSchemaValidators<S extends StrictRJSFSchema = RJSFSchema>(schema: S, output: string, options?: CustomValidatorOptionsType): void;
|
|
63
|
-
|
|
64
51
|
/** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`
|
|
65
52
|
* is provided, it is used to translate the messages generated by the underlying AJV validation.
|
|
66
53
|
*
|
|
@@ -76,4 +63,4 @@ declare function createPrecompiledValidator<T = any, S extends StrictRJSFSchema
|
|
|
76
63
|
|
|
77
64
|
declare const _default: _rjsf_utils.ValidatorType<any, _rjsf_utils.RJSFSchema, any>;
|
|
78
65
|
|
|
79
|
-
export { CompiledValidateFunction, CustomValidatorOptionsType, Localizer, ValidatorFunctions,
|
|
66
|
+
export { CompiledValidateFunction, CustomValidatorOptionsType, Localizer, ValidatorFunctions, createPrecompiledValidator, customizeValidator, _default as default };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
'use strict'
|
|
3
3
|
|
|
4
4
|
if (process.env.NODE_ENV === 'production') {
|
|
5
|
-
module.exports = require('./
|
|
5
|
+
module.exports = require('./index.cjs.production.min.js')
|
|
6
6
|
} else {
|
|
7
|
-
module.exports = require('./
|
|
7
|
+
module.exports = require('./index.cjs.development.js')
|
|
8
8
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITONAL_PROPERTIES_FLAG, toErrorSchema, getDefaultFormState, createErrorHandler, unwrapErrorHandler, validationDataMerge, getUiOptions, PROPERTIES_KEY, toErrorList, ID_KEY, withIdRefPrefix, ROOT_SCHEMA_PREFIX,
|
|
1
|
+
import { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITONAL_PROPERTIES_FLAG, toErrorSchema, getDefaultFormState, createErrorHandler, unwrapErrorHandler, validationDataMerge, getUiOptions, PROPERTIES_KEY, toErrorList, ID_KEY, withIdRefPrefix, ROOT_SCHEMA_PREFIX, hashForSchema } from '@rjsf/utils';
|
|
2
2
|
import Ajv from 'ajv';
|
|
3
3
|
import addFormats from 'ajv-formats';
|
|
4
4
|
import isObject from 'lodash-es/isObject';
|
|
5
5
|
import get from 'lodash-es/get';
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
import standaloneCode from 'ajv/dist/standalone';
|
|
8
6
|
import isEqual from 'lodash-es/isEqual';
|
|
9
7
|
|
|
10
8
|
function _extends() {
|
|
@@ -340,46 +338,6 @@ function customizeValidator(options, localizer) {
|
|
|
340
338
|
return new AJV8Validator(options, localizer);
|
|
341
339
|
}
|
|
342
340
|
|
|
343
|
-
/** The function used to compile a schema into an output file in the form that allows it to be used as a precompiled
|
|
344
|
-
* validator. The main reasons for using a precompiled validator is reducing code size, improving validation speed and,
|
|
345
|
-
* most importantly, avoiding dynamic code compilation when prohibited by a browser's Content Security Policy. For more
|
|
346
|
-
* information about AJV code compilation see: https://ajv.js.org/standalone.html
|
|
347
|
-
*
|
|
348
|
-
* @param schema - The schema to be compiled into a set of precompiled validators functions
|
|
349
|
-
* @param output - The name of the file into which the precompiled validator functions will be generated
|
|
350
|
-
* @param [options={}] - The set of `CustomValidatorOptionsType` information used to alter the AJV validator used for
|
|
351
|
-
* compiling the schema. They are the same options that are passed to the `customizeValidator()` function in
|
|
352
|
-
* order to modify the behavior of the regular AJV-based validator.
|
|
353
|
-
*/
|
|
354
|
-
function compileSchemaValidators(schema, output, options) {
|
|
355
|
-
if (options === void 0) {
|
|
356
|
-
options = {};
|
|
357
|
-
}
|
|
358
|
-
console.log('parsing the schema');
|
|
359
|
-
var schemaMaps = schemaParser(schema);
|
|
360
|
-
var schemas = Object.values(schemaMaps);
|
|
361
|
-
var _options = options,
|
|
362
|
-
additionalMetaSchemas = _options.additionalMetaSchemas,
|
|
363
|
-
customFormats = _options.customFormats,
|
|
364
|
-
_options$ajvOptionsOv = _options.ajvOptionsOverrides,
|
|
365
|
-
ajvOptionsOverrides = _options$ajvOptionsOv === void 0 ? {} : _options$ajvOptionsOv,
|
|
366
|
-
ajvFormatOptions = _options.ajvFormatOptions,
|
|
367
|
-
AjvClass = _options.AjvClass;
|
|
368
|
-
// Allow users to turn off the `lines: true` feature in their own overrides, but NOT the `source: true`
|
|
369
|
-
var compileOptions = _extends({}, ajvOptionsOverrides, {
|
|
370
|
-
code: _extends({
|
|
371
|
-
lines: true
|
|
372
|
-
}, ajvOptionsOverrides.code, {
|
|
373
|
-
source: true
|
|
374
|
-
}),
|
|
375
|
-
schemas: schemas
|
|
376
|
-
});
|
|
377
|
-
var ajv = createAjvInstance(additionalMetaSchemas, customFormats, compileOptions, ajvFormatOptions, AjvClass);
|
|
378
|
-
var moduleCode = standaloneCode(ajv);
|
|
379
|
-
console.log("writing " + output);
|
|
380
|
-
fs.writeFileSync(output, moduleCode);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
341
|
/** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the
|
|
384
342
|
* `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.
|
|
385
343
|
*/
|
|
@@ -519,5 +477,5 @@ function createPrecompiledValidator(validateFns, rootSchema, localizer) {
|
|
|
519
477
|
|
|
520
478
|
var index = /*#__PURE__*/customizeValidator();
|
|
521
479
|
|
|
522
|
-
export {
|
|
480
|
+
export { createPrecompiledValidator, customizeValidator, index as default };
|
|
523
481
|
//# sourceMappingURL=validator-ajv8.esm.js.map
|