@rjsf/validator-ajv8 6.5.2 → 6.6.0
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 +2 -2
- package/dist/compileSchemaValidators.cjs.map +2 -2
- package/dist/compileSchemaValidators.esm.js +2 -2
- package/dist/compileSchemaValidators.esm.js.map +2 -2
- package/dist/index.cjs +180 -178
- package/dist/index.cjs.map +4 -4
- package/dist/validator-ajv8.esm.js +176 -174
- package/dist/validator-ajv8.esm.js.map +4 -4
- package/dist/validator-ajv8.umd.js +155 -153
- package/lib/compileSchemaValidators.d.ts +1 -1
- package/lib/compileSchemaValidators.js.map +1 -1
- package/lib/compileSchemaValidatorsCode.js +1 -1
- package/lib/compileSchemaValidatorsCode.js.map +1 -1
- package/lib/createAjvInstance.js +1 -1
- package/lib/createAjvInstance.js.map +1 -1
- package/lib/createPrecompiledValidator.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/precompiledValidator.d.ts +1 -1
- package/lib/precompiledValidator.js +1 -1
- package/lib/precompiledValidator.js.map +1 -1
- package/lib/processRawValidationErrors.d.ts +1 -1
- package/lib/processRawValidationErrors.js +1 -1
- package/lib/processRawValidationErrors.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/validator.d.ts +2 -2
- package/lib/validator.js.map +1 -1
- package/package.json +11 -11
- package/src/compileSchemaValidators.ts +2 -2
- package/src/compileSchemaValidatorsCode.ts +1 -1
- package/src/createAjvInstance.ts +1 -1
- package/src/createPrecompiledValidator.ts +1 -1
- package/src/index.ts +1 -1
- package/src/precompiledValidator.ts +3 -3
- package/src/processRawValidationErrors.ts +2 -2
- package/src/tsconfig.json +2 -2
- package/src/validator.ts +2 -2
|
@@ -37,14 +37,14 @@ module.exports = __toCommonJS(compileSchemaValidators_exports);
|
|
|
37
37
|
var import_fs = __toESM(require("fs"), 1);
|
|
38
38
|
|
|
39
39
|
// src/compileSchemaValidatorsCode.ts
|
|
40
|
-
var import_standalone = __toESM(require("ajv/dist/standalone"), 1);
|
|
41
40
|
var import_utils2 = require("@rjsf/utils");
|
|
41
|
+
var import_standalone = __toESM(require("ajv/dist/standalone"), 1);
|
|
42
42
|
|
|
43
43
|
// src/createAjvInstance.ts
|
|
44
|
+
var import_utils = require("@rjsf/utils");
|
|
44
45
|
var import_ajv = __toESM(require("ajv"), 1);
|
|
45
46
|
var import_ajv_formats = __toESM(require("ajv-formats"), 1);
|
|
46
47
|
var import_isObject = __toESM(require("lodash/isObject"), 1);
|
|
47
|
-
var import_utils = require("@rjsf/utils");
|
|
48
48
|
var AJV_CONFIG = {
|
|
49
49
|
allErrors: true,
|
|
50
50
|
multipleOfPrecision: 8,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/compileSchemaValidators.ts", "../src/compileSchemaValidatorsCode.ts", "../src/createAjvInstance.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';\nimport fs from 'fs';\n\nimport { compileSchemaValidatorsCode } from './compileSchemaValidatorsCode';\nimport { CustomValidatorOptionsType } from './types';\n\nexport { compileSchemaValidatorsCode };\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\n const moduleCode = compileSchemaValidatorsCode(schema, options);\n console.log(`writing ${output}`);\n fs.writeFileSync(output, moduleCode);\n}\n", "import { RJSFSchema, StrictRJSFSchema, schemaParser } from '@rjsf/utils';\nimport standaloneCode from 'ajv/dist/standalone';\n\nimport createAjvInstance from './createAjvInstance';\nimport { CustomValidatorOptionsType } from './types';\n\n/** The function used to compile a schema into javascript code 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 [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 function compileSchemaValidatorsCode<S extends StrictRJSFSchema = RJSFSchema>(\n schema: S,\n options: CustomValidatorOptionsType = {},\n) {\n const schemaMaps = schemaParser(schema);\n const schemas = Object.values(schemaMaps);\n\n const {\n additionalMetaSchemas,\n customFormats,\n ajvOptionsOverrides = {},\n ajvFormatOptions,\n AjvClass,\n extenderFn,\n } = 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(\n additionalMetaSchemas,\n customFormats,\n compileOptions,\n ajvFormatOptions,\n AjvClass,\n extenderFn,\n );\n\n return standaloneCode(ajv);\n}\n", "import { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITIONAL_PROPERTIES_FLAG } from '@rjsf/utils';\nimport Ajv, { Options } from 'ajv';\nimport addFormats, { FormatsPluginOptions } from 'ajv-formats';\nimport isObject from 'lodash/isObject';\n\nimport { CustomValidatorOptionsType } from './types';\n\nexport const AJV_CONFIG: Options = {\n allErrors: true,\n multipleOfPrecision: 8,\n strict: false,\n verbose: true,\n discriminator: false, // TODO enable this in V6\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 * @param [extenderFn] - A function to call to extend AJV, such as `ajvErrors()`\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 extenderFn?: CustomValidatorOptionsType['extenderFn'],\n) {\n let 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_ADDITIONAL_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 if (extenderFn) {\n ajv = extenderFn(ajv);\n }\n\n return ajv;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gBAAe;;;ACDf,IAAAA,gBAA2D;AAC3D,wBAA2B;;;ACD3B,mBAA0E;AAC1E,iBAA6B;AAC7B,yBAAiD;AACjD,sBAAqB;AAId,IAAM,aAAsB;AAAA,EACjC,WAAW;AAAA,EACX,qBAAqB;AAAA,EACrB,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,eAAe;AAAA;AACjB;AACO,IAAM,qBACX;AACK,IAAM,wBAAwB;AAkBtB,SAAR,kBACL,uBACA,eACA,sBAAyE,CAAC,GAC1E,kBACA,WAAuB,WAAAC,SACvB,YACA;AACA,MAAI,MAAM,IAAI,SAAS,EAAE,GAAG,YAAY,GAAG,oBAAoB,CAAC;AAChE,MAAI,kBAAkB;AACpB,2BAAAC,SAAW,KAAK,gBAAgB;AAAA,EAClC,WAAW,qBAAqB,OAAO;AACrC,2BAAAA,SAAW,GAAG;AAAA,EAChB;AAGA,MAAI,UAAU,YAAY,qBAAqB;AAC/C,MAAI,UAAU,SAAS,kBAAkB;AAGzC,MAAI,WAAW,qCAAwB;AACvC,MAAI,WAAW,4CAA+B;AAG9C,MAAI,MAAM,QAAQ,qBAAqB,GAAG;AACxC,QAAI,cAAc,qBAAqB;AAAA,EACzC;AAGA,UAAI,gBAAAC,SAAS,aAAa,GAAG;AAC3B,WAAO,KAAK,aAAa,EAAE,QAAQ,CAAC,eAAe;AACjD,UAAI,UAAU,YAAY,cAAc,UAAU,CAAC;AAAA,IACrD,CAAC;AAAA,EACH;AACA,MAAI,YAAY;AACd,UAAM,WAAW,GAAG;AAAA,EACtB;AAEA,SAAO;AACT;;;ADzDO,SAAS,4BACd,QACA,UAAsC,CAAC,GACvC;AACA,QAAM,iBAAa,4BAAa,MAAM;AACtC,QAAM,UAAU,OAAO,OAAO,UAAU;AAExC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,sBAAsB,CAAC;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,iBAAiB;AAAA,IACrB,GAAG;AAAA,IACH,MAAM,EAAE,OAAO,MAAM,GAAG,oBAAoB,MAAM,QAAQ,KAAK;AAAA,IAC/D;AAAA,EACF;AACA,QAAM,MAAM;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,aAAO,kBAAAC,SAAe,GAAG;AAC3B;;;AD5Be,SAAR,wBACL,QACA,QACA,UAAsC,CAAC,GACvC;AACA,UAAQ,IAAI,oBAAoB;AAEhC,QAAM,aAAa,4BAA4B,QAAQ,OAAO;AAC9D,UAAQ,IAAI,WAAW,MAAM,EAAE;AAC/B,YAAAC,QAAG,cAAc,QAAQ,UAAU;AACrC;",
|
|
6
6
|
"names": ["import_utils", "Ajv", "addFormats", "isObject", "standaloneCode", "fs"]
|
|
7
7
|
}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
|
|
4
4
|
// src/compileSchemaValidatorsCode.ts
|
|
5
|
-
import standaloneCode from "ajv/dist/standalone";
|
|
6
5
|
import { schemaParser } from "@rjsf/utils";
|
|
6
|
+
import standaloneCode from "ajv/dist/standalone";
|
|
7
7
|
|
|
8
8
|
// src/createAjvInstance.ts
|
|
9
|
+
import { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITIONAL_PROPERTIES_FLAG } from "@rjsf/utils";
|
|
9
10
|
import Ajv from "ajv";
|
|
10
11
|
import addFormats from "ajv-formats";
|
|
11
12
|
import isObject from "lodash/isObject";
|
|
12
|
-
import { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITIONAL_PROPERTIES_FLAG } from "@rjsf/utils";
|
|
13
13
|
var AJV_CONFIG = {
|
|
14
14
|
allErrors: true,
|
|
15
15
|
multipleOfPrecision: 8,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/compileSchemaValidators.ts", "../src/compileSchemaValidatorsCode.ts", "../src/createAjvInstance.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import { RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';\nimport fs from 'fs';\n\nimport { compileSchemaValidatorsCode } from './compileSchemaValidatorsCode';\nimport { CustomValidatorOptionsType } from './types';\n\nexport { compileSchemaValidatorsCode };\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\n const moduleCode = compileSchemaValidatorsCode(schema, options);\n console.log(`writing ${output}`);\n fs.writeFileSync(output, moduleCode);\n}\n", "import { RJSFSchema, StrictRJSFSchema, schemaParser } from '@rjsf/utils';\nimport standaloneCode from 'ajv/dist/standalone';\n\nimport createAjvInstance from './createAjvInstance';\nimport { CustomValidatorOptionsType } from './types';\n\n/** The function used to compile a schema into javascript code 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 [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 function compileSchemaValidatorsCode<S extends StrictRJSFSchema = RJSFSchema>(\n schema: S,\n options: CustomValidatorOptionsType = {},\n) {\n const schemaMaps = schemaParser(schema);\n const schemas = Object.values(schemaMaps);\n\n const {\n additionalMetaSchemas,\n customFormats,\n ajvOptionsOverrides = {},\n ajvFormatOptions,\n AjvClass,\n extenderFn,\n } = 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(\n additionalMetaSchemas,\n customFormats,\n compileOptions,\n ajvFormatOptions,\n AjvClass,\n extenderFn,\n );\n\n return standaloneCode(ajv);\n}\n", "import { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITIONAL_PROPERTIES_FLAG } from '@rjsf/utils';\nimport Ajv, { Options } from 'ajv';\nimport addFormats, { FormatsPluginOptions } from 'ajv-formats';\nimport isObject from 'lodash/isObject';\n\nimport { CustomValidatorOptionsType } from './types';\n\nexport const AJV_CONFIG: Options = {\n allErrors: true,\n multipleOfPrecision: 8,\n strict: false,\n verbose: true,\n discriminator: false, // TODO enable this in V6\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 * @param [extenderFn] - A function to call to extend AJV, such as `ajvErrors()`\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 extenderFn?: CustomValidatorOptionsType['extenderFn'],\n) {\n let 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_ADDITIONAL_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 if (extenderFn) {\n ajv = extenderFn(ajv);\n }\n\n return ajv;\n}\n"],
|
|
5
|
+
"mappings": ";AACA,OAAO,QAAQ;;;ACDf,SAAuC,oBAAoB;AAC3D,OAAO,oBAAoB;;;ACD3B,SAAS,0BAA0B,uCAAuC;AAC1E,OAAO,SAAsB;AAC7B,OAAO,gBAA0C;AACjD,OAAO,cAAc;AAId,IAAM,aAAsB;AAAA,EACjC,WAAW;AAAA,EACX,qBAAqB;AAAA,EACrB,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,eAAe;AAAA;AACjB;AACO,IAAM,qBACX;AACK,IAAM,wBAAwB;AAkBtB,SAAR,kBACL,uBACA,eACA,sBAAyE,CAAC,GAC1E,kBACA,WAAuB,KACvB,YACA;AACA,MAAI,MAAM,IAAI,SAAS,EAAE,GAAG,YAAY,GAAG,oBAAoB,CAAC;AAChE,MAAI,kBAAkB;AACpB,eAAW,KAAK,gBAAgB;AAAA,EAClC,WAAW,qBAAqB,OAAO;AACrC,eAAW,GAAG;AAAA,EAChB;AAGA,MAAI,UAAU,YAAY,qBAAqB;AAC/C,MAAI,UAAU,SAAS,kBAAkB;AAGzC,MAAI,WAAW,wBAAwB;AACvC,MAAI,WAAW,+BAA+B;AAG9C,MAAI,MAAM,QAAQ,qBAAqB,GAAG;AACxC,QAAI,cAAc,qBAAqB;AAAA,EACzC;AAGA,MAAI,SAAS,aAAa,GAAG;AAC3B,WAAO,KAAK,aAAa,EAAE,QAAQ,CAAC,eAAe;AACjD,UAAI,UAAU,YAAY,cAAc,UAAU,CAAC;AAAA,IACrD,CAAC;AAAA,EACH;AACA,MAAI,YAAY;AACd,UAAM,WAAW,GAAG;AAAA,EACtB;AAEA,SAAO;AACT;;;ADzDO,SAAS,4BACd,QACA,UAAsC,CAAC,GACvC;AACA,QAAM,aAAa,aAAa,MAAM;AACtC,QAAM,UAAU,OAAO,OAAO,UAAU;AAExC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,sBAAsB,CAAC;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,iBAAiB;AAAA,IACrB,GAAG;AAAA,IACH,MAAM,EAAE,OAAO,MAAM,GAAG,oBAAoB,MAAM,QAAQ,KAAK;AAAA,IAC/D;AAAA,EACF;AACA,QAAM,MAAM;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO,eAAe,GAAG;AAC3B;;;AD5Be,SAAR,wBACL,QACA,QACA,UAAsC,CAAC,GACvC;AACA,UAAQ,IAAI,oBAAoB;AAEhC,QAAM,aAAa,4BAA4B,QAAQ,OAAO;AAC9D,UAAQ,IAAI,WAAW,MAAM,EAAE;AAC/B,KAAG,cAAc,QAAQ,UAAU;AACrC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -36,60 +36,21 @@ __export(index_exports, {
|
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
38
|
|
|
39
|
-
// src/
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
// src/createAjvInstance.ts
|
|
43
|
-
var import_ajv = __toESM(require("ajv"), 1);
|
|
44
|
-
var import_ajv_formats = __toESM(require("ajv-formats"), 1);
|
|
45
|
-
var import_isObject = __toESM(require("lodash/isObject"), 1);
|
|
46
|
-
var import_utils = require("@rjsf/utils");
|
|
47
|
-
var AJV_CONFIG = {
|
|
48
|
-
allErrors: true,
|
|
49
|
-
multipleOfPrecision: 8,
|
|
50
|
-
strict: false,
|
|
51
|
-
verbose: true,
|
|
52
|
-
discriminator: false
|
|
53
|
-
// TODO enable this in V6
|
|
54
|
-
};
|
|
55
|
-
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*\)))$/;
|
|
56
|
-
var DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
|
|
57
|
-
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides = {}, ajvFormatOptions, AjvClass = import_ajv.default, extenderFn) {
|
|
58
|
-
let ajv = new AjvClass({ ...AJV_CONFIG, ...ajvOptionsOverrides });
|
|
59
|
-
if (ajvFormatOptions) {
|
|
60
|
-
(0, import_ajv_formats.default)(ajv, ajvFormatOptions);
|
|
61
|
-
} else if (ajvFormatOptions !== false) {
|
|
62
|
-
(0, import_ajv_formats.default)(ajv);
|
|
63
|
-
}
|
|
64
|
-
ajv.addFormat("data-url", DATA_URL_FORMAT_REGEX);
|
|
65
|
-
ajv.addFormat("color", COLOR_FORMAT_REGEX);
|
|
66
|
-
ajv.addKeyword(import_utils.ADDITIONAL_PROPERTY_FLAG);
|
|
67
|
-
ajv.addKeyword(import_utils.RJSF_ADDITIONAL_PROPERTIES_FLAG);
|
|
68
|
-
if (Array.isArray(additionalMetaSchemas)) {
|
|
69
|
-
ajv.addMetaSchema(additionalMetaSchemas);
|
|
70
|
-
}
|
|
71
|
-
if ((0, import_isObject.default)(customFormats)) {
|
|
72
|
-
Object.keys(customFormats).forEach((formatName) => {
|
|
73
|
-
ajv.addFormat(formatName, customFormats[formatName]);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
if (extenderFn) {
|
|
77
|
-
ajv = extenderFn(ajv);
|
|
78
|
-
}
|
|
79
|
-
return ajv;
|
|
80
|
-
}
|
|
39
|
+
// src/precompiledValidator.ts
|
|
40
|
+
var import_utils2 = require("@rjsf/utils");
|
|
41
|
+
var import_get2 = __toESM(require("lodash/get"), 1);
|
|
81
42
|
|
|
82
43
|
// src/processRawValidationErrors.ts
|
|
44
|
+
var import_utils = require("@rjsf/utils");
|
|
83
45
|
var import_get = __toESM(require("lodash/get"), 1);
|
|
84
|
-
var import_utils2 = require("@rjsf/utils");
|
|
85
46
|
function filterDuplicateErrors(errorList, suppressDuplicateFiltering = "none") {
|
|
86
47
|
if (suppressDuplicateFiltering === "all") {
|
|
87
48
|
return errorList;
|
|
88
49
|
}
|
|
89
50
|
return errorList.reduce((acc, err) => {
|
|
90
51
|
const { message, schemaPath } = err;
|
|
91
|
-
const anyOfIndex = suppressDuplicateFiltering !== "anyOf" ? schemaPath?.indexOf(`/${
|
|
92
|
-
const oneOfIndex = suppressDuplicateFiltering !== "oneOf" ? schemaPath?.indexOf(`/${
|
|
52
|
+
const anyOfIndex = suppressDuplicateFiltering !== "anyOf" ? schemaPath?.indexOf(`/${import_utils.ANY_OF_KEY}/`) : void 0;
|
|
53
|
+
const oneOfIndex = suppressDuplicateFiltering !== "oneOf" ? schemaPath?.indexOf(`/${import_utils.ONE_OF_KEY}/`) : void 0;
|
|
93
54
|
let schemaPrefix;
|
|
94
55
|
if (anyOfIndex && anyOfIndex >= 0) {
|
|
95
56
|
schemaPrefix = schemaPath?.substring(0, anyOfIndex);
|
|
@@ -118,16 +79,16 @@ function transformRJSFValidationErrors(errors = [], uiSchema, suppressDuplicateF
|
|
|
118
79
|
if (rawPropertyNames.length > 0) {
|
|
119
80
|
rawPropertyNames.forEach((currentProperty) => {
|
|
120
81
|
const path = property ? `${property}.${currentProperty}` : currentProperty;
|
|
121
|
-
let uiSchemaTitle = (0,
|
|
82
|
+
let uiSchemaTitle = (0, import_utils.getUiOptions)((0, import_get.default)(uiSchema, `${path.replace(/^\./, "")}`)).title;
|
|
122
83
|
if (uiSchemaTitle === void 0) {
|
|
123
84
|
const uiSchemaPath = schemaPath.replace(/\/properties\//g, "/").split("/").slice(1, -1).concat([currentProperty]);
|
|
124
|
-
uiSchemaTitle = (0,
|
|
85
|
+
uiSchemaTitle = (0, import_utils.getUiOptions)((0, import_get.default)(uiSchema, uiSchemaPath)).title;
|
|
125
86
|
}
|
|
126
87
|
if (uiSchemaTitle) {
|
|
127
88
|
message = message.replace(`'${currentProperty}'`, `'${uiSchemaTitle}'`);
|
|
128
89
|
uiTitle = uiSchemaTitle;
|
|
129
90
|
} else {
|
|
130
|
-
const parentSchemaTitle = (0, import_get.default)(parentSchema, [
|
|
91
|
+
const parentSchemaTitle = (0, import_get.default)(parentSchema, [import_utils.PROPERTIES_KEY, currentProperty, "title"]);
|
|
131
92
|
if (parentSchemaTitle) {
|
|
132
93
|
message = message.replace(`'${currentProperty}'`, `'${parentSchemaTitle}'`);
|
|
133
94
|
uiTitle = parentSchemaTitle;
|
|
@@ -136,7 +97,7 @@ function transformRJSFValidationErrors(errors = [], uiSchema, suppressDuplicateF
|
|
|
136
97
|
});
|
|
137
98
|
stack = message;
|
|
138
99
|
} else {
|
|
139
|
-
const uiSchemaTitle = (0,
|
|
100
|
+
const uiSchemaTitle = (0, import_utils.getUiOptions)((0, import_get.default)(uiSchema, `${property.replace(/^\./, "")}`)).title;
|
|
140
101
|
if (uiSchemaTitle) {
|
|
141
102
|
stack = `'${uiSchemaTitle}' ${message}`.trim();
|
|
142
103
|
uiTitle = uiSchemaTitle;
|
|
@@ -173,7 +134,7 @@ function processRawValidationErrors(validator, rawErrors, formData, schema, cust
|
|
|
173
134
|
if (typeof transformErrors === "function") {
|
|
174
135
|
errors = transformErrors(errors, uiSchema);
|
|
175
136
|
}
|
|
176
|
-
let errorSchema = (0,
|
|
137
|
+
let errorSchema = (0, import_utils.toErrorSchema)(errors);
|
|
177
138
|
if (invalidSchemaError) {
|
|
178
139
|
errorSchema = {
|
|
179
140
|
...errorSchema,
|
|
@@ -185,10 +146,169 @@ function processRawValidationErrors(validator, rawErrors, formData, schema, cust
|
|
|
185
146
|
if (typeof customValidate !== "function") {
|
|
186
147
|
return { errors, errorSchema };
|
|
187
148
|
}
|
|
188
|
-
const newFormData = (0,
|
|
189
|
-
const errorHandler = customValidate(newFormData, (0,
|
|
190
|
-
const userErrorSchema = (0,
|
|
191
|
-
return (0,
|
|
149
|
+
const newFormData = (0, import_utils.getDefaultFormState)(validator, schema, formData, schema, true);
|
|
150
|
+
const errorHandler = customValidate(newFormData, (0, import_utils.createErrorHandler)(newFormData), uiSchema, errorSchema);
|
|
151
|
+
const userErrorSchema = (0, import_utils.unwrapErrorHandler)(errorHandler);
|
|
152
|
+
return (0, import_utils.validationDataMerge)({ errors, errorSchema }, userErrorSchema);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/precompiledValidator.ts
|
|
156
|
+
var AJV8PrecompiledValidator = class {
|
|
157
|
+
/** Constructs an `AJV8PrecompiledValidator` instance using the `validateFns` and `rootSchema`
|
|
158
|
+
*
|
|
159
|
+
* @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function
|
|
160
|
+
* @param rootSchema - The root schema that was used with the `compileSchema()` function
|
|
161
|
+
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s
|
|
162
|
+
* @param [suppressDuplicateFiltering] - Controls which duplicate filtering is suppressed; see `filterDuplicateErrors`
|
|
163
|
+
* @throws - Error when the base schema of the precompiled validator does not have a matching validator function
|
|
164
|
+
*/
|
|
165
|
+
constructor(validateFns, rootSchema, localizer, suppressDuplicateFiltering) {
|
|
166
|
+
this.rootSchema = rootSchema;
|
|
167
|
+
this.validateFns = validateFns;
|
|
168
|
+
this.localizer = localizer;
|
|
169
|
+
this.suppressDuplicateFiltering = suppressDuplicateFiltering;
|
|
170
|
+
this.mainValidator = this.getValidator(rootSchema);
|
|
171
|
+
}
|
|
172
|
+
/** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator
|
|
173
|
+
* functions.
|
|
174
|
+
*
|
|
175
|
+
* @param schema - The schema for which a precompiled validator function is desired
|
|
176
|
+
* @returns - The precompiled validator function associated with this schema
|
|
177
|
+
*/
|
|
178
|
+
getValidator(schema) {
|
|
179
|
+
const key = (0, import_get2.default)(schema, import_utils2.ID_KEY) || (0, import_utils2.hashForSchema)(schema);
|
|
180
|
+
const validator = this.validateFns[key];
|
|
181
|
+
if (!validator) {
|
|
182
|
+
throw new Error(`No precompiled validator function was found for the given schema for "${key}"`);
|
|
183
|
+
}
|
|
184
|
+
return validator;
|
|
185
|
+
}
|
|
186
|
+
/** Ensures that the validator is using the same schema as the root schema used to construct the precompiled
|
|
187
|
+
* validator. It first compares the given `schema` against the root schema and if they aren't the same, then it
|
|
188
|
+
* checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in
|
|
189
|
+
* instead of the raw root schema.
|
|
190
|
+
*
|
|
191
|
+
* @param schema - The schema against which to validate the form data
|
|
192
|
+
* @param [formData] - The form data to validate if any
|
|
193
|
+
*/
|
|
194
|
+
ensureSameRootSchema(schema, formData) {
|
|
195
|
+
if (!(0, import_utils2.deepEquals)(schema, this.rootSchema)) {
|
|
196
|
+
const resolvedRootSchema = (0, import_utils2.retrieveSchema)(this, this.rootSchema, this.rootSchema, formData);
|
|
197
|
+
if (!(0, import_utils2.deepEquals)(schema, resolvedRootSchema)) {
|
|
198
|
+
throw new Error(
|
|
199
|
+
"The schema associated with the precompiled validator differs from the rootSchema provided for validation"
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
206
|
+
* by the playground. Returns the `errors` from the validation
|
|
207
|
+
*
|
|
208
|
+
* @param schema - The schema against which to validate the form data
|
|
209
|
+
* @param [formData] - The form data to validate, if any
|
|
210
|
+
* @throws - Error when the schema provided does not match the base schema of the precompiled validator
|
|
211
|
+
*/
|
|
212
|
+
rawValidation(schema, formData) {
|
|
213
|
+
this.ensureSameRootSchema(schema, formData);
|
|
214
|
+
this.mainValidator(formData);
|
|
215
|
+
if (typeof this.localizer === "function") {
|
|
216
|
+
this.localizer(this.mainValidator.errors);
|
|
217
|
+
}
|
|
218
|
+
const errors = this.mainValidator.errors || void 0;
|
|
219
|
+
this.mainValidator.errors = null;
|
|
220
|
+
return { errors };
|
|
221
|
+
}
|
|
222
|
+
/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
|
|
223
|
+
* the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
|
|
224
|
+
* supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and
|
|
225
|
+
* transform them in what ever way it chooses.
|
|
226
|
+
*
|
|
227
|
+
* @param formData - The form data to validate
|
|
228
|
+
* @param schema - The schema against which to validate the form data
|
|
229
|
+
* @param [customValidate] - An optional function that is used to perform custom validation
|
|
230
|
+
* @param [transformErrors] - An optional function that is used to transform errors after AJV validation
|
|
231
|
+
* @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
|
|
232
|
+
*/
|
|
233
|
+
validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
|
|
234
|
+
const rawErrors = this.rawValidation(schema, formData);
|
|
235
|
+
return processRawValidationErrors(
|
|
236
|
+
this,
|
|
237
|
+
rawErrors,
|
|
238
|
+
formData,
|
|
239
|
+
schema,
|
|
240
|
+
customValidate,
|
|
241
|
+
transformErrors,
|
|
242
|
+
uiSchema,
|
|
243
|
+
this.suppressDuplicateFiltering
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
/** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is
|
|
247
|
+
* invalid, then this function will return false.
|
|
248
|
+
*
|
|
249
|
+
* @param schema - The schema against which to validate the form data
|
|
250
|
+
* @param formData - The form data to validate
|
|
251
|
+
* @param rootSchema - The root schema used to provide $ref resolutions
|
|
252
|
+
* @returns - true if the formData validates against the schema, false otherwise
|
|
253
|
+
* @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there
|
|
254
|
+
* isn't a precompiled validator function associated with the schema
|
|
255
|
+
*/
|
|
256
|
+
isValid(schema, formData, rootSchema) {
|
|
257
|
+
this.ensureSameRootSchema(rootSchema, formData);
|
|
258
|
+
if ((0, import_get2.default)(schema, import_utils2.ID_KEY) === import_utils2.JUNK_OPTION_ID) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
const validator = this.getValidator(schema);
|
|
262
|
+
return validator(formData);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// src/createPrecompiledValidator.ts
|
|
267
|
+
function createPrecompiledValidator(validateFns, rootSchema, localizer, suppressDuplicateFiltering) {
|
|
268
|
+
return new AJV8PrecompiledValidator(validateFns, rootSchema, localizer, suppressDuplicateFiltering);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// src/validator.ts
|
|
272
|
+
var import_utils4 = require("@rjsf/utils");
|
|
273
|
+
|
|
274
|
+
// src/createAjvInstance.ts
|
|
275
|
+
var import_utils3 = require("@rjsf/utils");
|
|
276
|
+
var import_ajv = __toESM(require("ajv"), 1);
|
|
277
|
+
var import_ajv_formats = __toESM(require("ajv-formats"), 1);
|
|
278
|
+
var import_isObject = __toESM(require("lodash/isObject"), 1);
|
|
279
|
+
var AJV_CONFIG = {
|
|
280
|
+
allErrors: true,
|
|
281
|
+
multipleOfPrecision: 8,
|
|
282
|
+
strict: false,
|
|
283
|
+
verbose: true,
|
|
284
|
+
discriminator: false
|
|
285
|
+
// TODO enable this in V6
|
|
286
|
+
};
|
|
287
|
+
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*\)))$/;
|
|
288
|
+
var DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
|
|
289
|
+
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides = {}, ajvFormatOptions, AjvClass = import_ajv.default, extenderFn) {
|
|
290
|
+
let ajv = new AjvClass({ ...AJV_CONFIG, ...ajvOptionsOverrides });
|
|
291
|
+
if (ajvFormatOptions) {
|
|
292
|
+
(0, import_ajv_formats.default)(ajv, ajvFormatOptions);
|
|
293
|
+
} else if (ajvFormatOptions !== false) {
|
|
294
|
+
(0, import_ajv_formats.default)(ajv);
|
|
295
|
+
}
|
|
296
|
+
ajv.addFormat("data-url", DATA_URL_FORMAT_REGEX);
|
|
297
|
+
ajv.addFormat("color", COLOR_FORMAT_REGEX);
|
|
298
|
+
ajv.addKeyword(import_utils3.ADDITIONAL_PROPERTY_FLAG);
|
|
299
|
+
ajv.addKeyword(import_utils3.RJSF_ADDITIONAL_PROPERTIES_FLAG);
|
|
300
|
+
if (Array.isArray(additionalMetaSchemas)) {
|
|
301
|
+
ajv.addMetaSchema(additionalMetaSchemas);
|
|
302
|
+
}
|
|
303
|
+
if ((0, import_isObject.default)(customFormats)) {
|
|
304
|
+
Object.keys(customFormats).forEach((formatName) => {
|
|
305
|
+
ajv.addFormat(formatName, customFormats[formatName]);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
if (extenderFn) {
|
|
309
|
+
ajv = extenderFn(ajv);
|
|
310
|
+
}
|
|
311
|
+
return ajv;
|
|
192
312
|
}
|
|
193
313
|
|
|
194
314
|
// src/validator.ts
|
|
@@ -241,8 +361,8 @@ var AJV8Validator = class {
|
|
|
241
361
|
let compilationError = void 0;
|
|
242
362
|
let compiledValidator;
|
|
243
363
|
try {
|
|
244
|
-
if (schema[
|
|
245
|
-
compiledValidator = this.ajv.getSchema(schema[
|
|
364
|
+
if (schema[import_utils4.ID_KEY]) {
|
|
365
|
+
compiledValidator = this.ajv.getSchema(schema[import_utils4.ID_KEY]);
|
|
246
366
|
}
|
|
247
367
|
if (compiledValidator === void 0) {
|
|
248
368
|
compiledValidator = this.ajv.compile(schema);
|
|
@@ -318,10 +438,10 @@ var AJV8Validator = class {
|
|
|
318
438
|
if (this.lastSeenRootSchema === rootSchema && this.hasRegisteredRootSchema) {
|
|
319
439
|
return;
|
|
320
440
|
}
|
|
321
|
-
const rootSchemaId = rootSchema[
|
|
441
|
+
const rootSchemaId = rootSchema[import_utils4.ID_KEY] ?? import_utils4.ROOT_SCHEMA_PREFIX;
|
|
322
442
|
if (this.ajv.getSchema(rootSchemaId) === void 0) {
|
|
323
443
|
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
324
|
-
} else if (!(0,
|
|
444
|
+
} else if (!(0, import_utils4.deepEquals)(rootSchema, this.ajv.getSchema(rootSchemaId)?.schema)) {
|
|
325
445
|
this.ajv.removeSchema(rootSchemaId);
|
|
326
446
|
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
327
447
|
}
|
|
@@ -339,8 +459,8 @@ var AJV8Validator = class {
|
|
|
339
459
|
isValid(schema, formData, rootSchema) {
|
|
340
460
|
try {
|
|
341
461
|
this.handleSchemaUpdate(rootSchema);
|
|
342
|
-
const schemaWithIdRefPrefix = (0,
|
|
343
|
-
const schemaId = schemaWithIdRefPrefix[
|
|
462
|
+
const schemaWithIdRefPrefix = (0, import_utils4.withIdRefPrefix)(schema);
|
|
463
|
+
const schemaId = schemaWithIdRefPrefix[import_utils4.ID_KEY] ?? (0, import_utils4.hashForSchema)(schemaWithIdRefPrefix);
|
|
344
464
|
let compiledValidator;
|
|
345
465
|
compiledValidator = this.ajv.getSchema(schemaId);
|
|
346
466
|
if (compiledValidator === void 0) {
|
|
@@ -360,124 +480,6 @@ function customizeValidator(options = {}, localizer) {
|
|
|
360
480
|
return new AJV8Validator(options, localizer);
|
|
361
481
|
}
|
|
362
482
|
|
|
363
|
-
// src/precompiledValidator.ts
|
|
364
|
-
var import_get2 = __toESM(require("lodash/get"), 1);
|
|
365
|
-
var import_utils4 = require("@rjsf/utils");
|
|
366
|
-
var AJV8PrecompiledValidator = class {
|
|
367
|
-
/** Constructs an `AJV8PrecompiledValidator` instance using the `validateFns` and `rootSchema`
|
|
368
|
-
*
|
|
369
|
-
* @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function
|
|
370
|
-
* @param rootSchema - The root schema that was used with the `compileSchema()` function
|
|
371
|
-
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s
|
|
372
|
-
* @param [suppressDuplicateFiltering] - Controls which duplicate filtering is suppressed; see `filterDuplicateErrors`
|
|
373
|
-
* @throws - Error when the base schema of the precompiled validator does not have a matching validator function
|
|
374
|
-
*/
|
|
375
|
-
constructor(validateFns, rootSchema, localizer, suppressDuplicateFiltering) {
|
|
376
|
-
this.rootSchema = rootSchema;
|
|
377
|
-
this.validateFns = validateFns;
|
|
378
|
-
this.localizer = localizer;
|
|
379
|
-
this.suppressDuplicateFiltering = suppressDuplicateFiltering;
|
|
380
|
-
this.mainValidator = this.getValidator(rootSchema);
|
|
381
|
-
}
|
|
382
|
-
/** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator
|
|
383
|
-
* functions.
|
|
384
|
-
*
|
|
385
|
-
* @param schema - The schema for which a precompiled validator function is desired
|
|
386
|
-
* @returns - The precompiled validator function associated with this schema
|
|
387
|
-
*/
|
|
388
|
-
getValidator(schema) {
|
|
389
|
-
const key = (0, import_get2.default)(schema, import_utils4.ID_KEY) || (0, import_utils4.hashForSchema)(schema);
|
|
390
|
-
const validator = this.validateFns[key];
|
|
391
|
-
if (!validator) {
|
|
392
|
-
throw new Error(`No precompiled validator function was found for the given schema for "${key}"`);
|
|
393
|
-
}
|
|
394
|
-
return validator;
|
|
395
|
-
}
|
|
396
|
-
/** Ensures that the validator is using the same schema as the root schema used to construct the precompiled
|
|
397
|
-
* validator. It first compares the given `schema` against the root schema and if they aren't the same, then it
|
|
398
|
-
* checks against the resolved root schema, on the chance that a resolved version of the root schema was passed in
|
|
399
|
-
* instead of the raw root schema.
|
|
400
|
-
*
|
|
401
|
-
* @param schema - The schema against which to validate the form data
|
|
402
|
-
* @param [formData] - The form data to validate if any
|
|
403
|
-
*/
|
|
404
|
-
ensureSameRootSchema(schema, formData) {
|
|
405
|
-
if (!(0, import_utils4.deepEquals)(schema, this.rootSchema)) {
|
|
406
|
-
const resolvedRootSchema = (0, import_utils4.retrieveSchema)(this, this.rootSchema, this.rootSchema, formData);
|
|
407
|
-
if (!(0, import_utils4.deepEquals)(schema, resolvedRootSchema)) {
|
|
408
|
-
throw new Error(
|
|
409
|
-
"The schema associated with the precompiled validator differs from the rootSchema provided for validation"
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return true;
|
|
414
|
-
}
|
|
415
|
-
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
416
|
-
* by the playground. Returns the `errors` from the validation
|
|
417
|
-
*
|
|
418
|
-
* @param schema - The schema against which to validate the form data
|
|
419
|
-
* @param [formData] - The form data to validate, if any
|
|
420
|
-
* @throws - Error when the schema provided does not match the base schema of the precompiled validator
|
|
421
|
-
*/
|
|
422
|
-
rawValidation(schema, formData) {
|
|
423
|
-
this.ensureSameRootSchema(schema, formData);
|
|
424
|
-
this.mainValidator(formData);
|
|
425
|
-
if (typeof this.localizer === "function") {
|
|
426
|
-
this.localizer(this.mainValidator.errors);
|
|
427
|
-
}
|
|
428
|
-
const errors = this.mainValidator.errors || void 0;
|
|
429
|
-
this.mainValidator.errors = null;
|
|
430
|
-
return { errors };
|
|
431
|
-
}
|
|
432
|
-
/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
|
|
433
|
-
* the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
|
|
434
|
-
* supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and
|
|
435
|
-
* transform them in what ever way it chooses.
|
|
436
|
-
*
|
|
437
|
-
* @param formData - The form data to validate
|
|
438
|
-
* @param schema - The schema against which to validate the form data
|
|
439
|
-
* @param [customValidate] - An optional function that is used to perform custom validation
|
|
440
|
-
* @param [transformErrors] - An optional function that is used to transform errors after AJV validation
|
|
441
|
-
* @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
|
|
442
|
-
*/
|
|
443
|
-
validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
|
|
444
|
-
const rawErrors = this.rawValidation(schema, formData);
|
|
445
|
-
return processRawValidationErrors(
|
|
446
|
-
this,
|
|
447
|
-
rawErrors,
|
|
448
|
-
formData,
|
|
449
|
-
schema,
|
|
450
|
-
customValidate,
|
|
451
|
-
transformErrors,
|
|
452
|
-
uiSchema,
|
|
453
|
-
this.suppressDuplicateFiltering
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
/** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is
|
|
457
|
-
* invalid, then this function will return false.
|
|
458
|
-
*
|
|
459
|
-
* @param schema - The schema against which to validate the form data
|
|
460
|
-
* @param formData - The form data to validate
|
|
461
|
-
* @param rootSchema - The root schema used to provide $ref resolutions
|
|
462
|
-
* @returns - true if the formData validates against the schema, false otherwise
|
|
463
|
-
* @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there
|
|
464
|
-
* isn't a precompiled validator function associated with the schema
|
|
465
|
-
*/
|
|
466
|
-
isValid(schema, formData, rootSchema) {
|
|
467
|
-
this.ensureSameRootSchema(rootSchema, formData);
|
|
468
|
-
if ((0, import_get2.default)(schema, import_utils4.ID_KEY) === import_utils4.JUNK_OPTION_ID) {
|
|
469
|
-
return false;
|
|
470
|
-
}
|
|
471
|
-
const validator = this.getValidator(schema);
|
|
472
|
-
return validator(formData);
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
// src/createPrecompiledValidator.ts
|
|
477
|
-
function createPrecompiledValidator(validateFns, rootSchema, localizer, suppressDuplicateFiltering) {
|
|
478
|
-
return new AJV8PrecompiledValidator(validateFns, rootSchema, localizer, suppressDuplicateFiltering);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
483
|
// src/index.ts
|
|
482
484
|
var index_default = customizeValidator();
|
|
483
485
|
//# sourceMappingURL=index.cjs.map
|