@rjsf/validator-ajv8 5.2.0 → 5.2.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/LICENSE.md +183 -183
- package/README.md +26 -26
- package/dist/validator-ajv8.cjs.development.js +22 -22
- package/dist/validator-ajv8.cjs.development.js.map +1 -1
- package/dist/validator-ajv8.cjs.production.min.js.map +1 -1
- package/dist/validator-ajv8.esm.js +22 -22
- package/dist/validator-ajv8.esm.js.map +1 -1
- package/dist/validator-ajv8.umd.development.js +22 -22
- package/dist/validator-ajv8.umd.development.js.map +1 -1
- package/dist/validator-ajv8.umd.production.min.js.map +1 -1
- package/package.json +3 -3
|
@@ -83,8 +83,8 @@ function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverr
|
|
|
83
83
|
addFormats__default["default"](ajv);
|
|
84
84
|
}
|
|
85
85
|
// add custom formats
|
|
86
|
-
ajv.addFormat(
|
|
87
|
-
ajv.addFormat(
|
|
86
|
+
ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);
|
|
87
|
+
ajv.addFormat('color', COLOR_FORMAT_REGEX);
|
|
88
88
|
// Add RJSF-specific additional properties keywords so Ajv doesn't report errors if strict is enabled.
|
|
89
89
|
ajv.addKeyword(utils.ADDITIONAL_PROPERTY_FLAG);
|
|
90
90
|
ajv.addKeyword(utils.RJSF_ADDITONAL_PROPERTIES_FLAG);
|
|
@@ -102,7 +102,7 @@ function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverr
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
var _excluded = ["instancePath", "keyword", "params", "schemaPath", "parentSchema"];
|
|
105
|
-
var ROOT_SCHEMA_PREFIX =
|
|
105
|
+
var ROOT_SCHEMA_PREFIX = '__rjsf_rootSchema';
|
|
106
106
|
/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.
|
|
107
107
|
*/
|
|
108
108
|
var AJV8Validator = /*#__PURE__*/function () {
|
|
@@ -161,7 +161,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
161
161
|
var path = toPath__default["default"](property);
|
|
162
162
|
// If the property is at the root (.level1) then toPath creates
|
|
163
163
|
// an empty array element at the first index. Remove it.
|
|
164
|
-
if (path.length > 0 && path[0] ===
|
|
164
|
+
if (path.length > 0 && path[0] === '') {
|
|
165
165
|
path.splice(0, 1);
|
|
166
166
|
}
|
|
167
167
|
if (message) {
|
|
@@ -187,7 +187,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
187
187
|
var errorList = [];
|
|
188
188
|
if (utils.ERRORS_KEY in errorSchema) {
|
|
189
189
|
errorList = errorList.concat(errorSchema[utils.ERRORS_KEY].map(function (message) {
|
|
190
|
-
var property = "." + fieldPath.join(
|
|
190
|
+
var property = "." + fieldPath.join('.');
|
|
191
191
|
return {
|
|
192
192
|
property: property,
|
|
193
193
|
message: message,
|
|
@@ -242,7 +242,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
242
242
|
var _this3 = this;
|
|
243
243
|
return Object.keys(errorHandler).reduce(function (acc, key) {
|
|
244
244
|
var _extends5;
|
|
245
|
-
if (key ===
|
|
245
|
+
if (key === 'addError') {
|
|
246
246
|
return acc;
|
|
247
247
|
} else if (key === utils.ERRORS_KEY) {
|
|
248
248
|
var _extends4;
|
|
@@ -269,24 +269,24 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
269
269
|
parentSchema = e.parentSchema,
|
|
270
270
|
rest = _objectWithoutPropertiesLoose(e, _excluded);
|
|
271
271
|
var _rest$message = rest.message,
|
|
272
|
-
message = _rest$message === void 0 ?
|
|
273
|
-
var property = instancePath.replace(/\//g,
|
|
272
|
+
message = _rest$message === void 0 ? '' : _rest$message;
|
|
273
|
+
var property = instancePath.replace(/\//g, '.');
|
|
274
274
|
var stack = (property + " " + message).trim();
|
|
275
|
-
if (
|
|
275
|
+
if ('missingProperty' in params) {
|
|
276
276
|
property = property ? property + "." + params.missingProperty : params.missingProperty;
|
|
277
277
|
var currentProperty = params.missingProperty;
|
|
278
|
-
var uiSchemaTitle = utils.getUiOptions(get__default["default"](uiSchema, "" + property.replace(/^\./,
|
|
278
|
+
var uiSchemaTitle = utils.getUiOptions(get__default["default"](uiSchema, "" + property.replace(/^\./, ''))).title;
|
|
279
279
|
if (uiSchemaTitle) {
|
|
280
280
|
message = message.replace(currentProperty, uiSchemaTitle);
|
|
281
281
|
} else {
|
|
282
|
-
var parentSchemaTitle = get__default["default"](parentSchema, [utils.PROPERTIES_KEY, currentProperty,
|
|
282
|
+
var parentSchemaTitle = get__default["default"](parentSchema, [utils.PROPERTIES_KEY, currentProperty, 'title']);
|
|
283
283
|
if (parentSchemaTitle) {
|
|
284
284
|
message = message.replace(currentProperty, parentSchemaTitle);
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
stack = message;
|
|
288
288
|
} else {
|
|
289
|
-
var _uiSchemaTitle = utils.getUiOptions(get__default["default"](uiSchema, "" + property.replace(/^\./,
|
|
289
|
+
var _uiSchemaTitle = utils.getUiOptions(get__default["default"](uiSchema, "" + property.replace(/^\./, ''))).title;
|
|
290
290
|
if (_uiSchemaTitle) {
|
|
291
291
|
stack = ("'" + _uiSchemaTitle + "' " + message).trim();
|
|
292
292
|
} else {
|
|
@@ -316,8 +316,8 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
316
316
|
_proto.rawValidation = function rawValidation(schema, formData) {
|
|
317
317
|
var compilationError = undefined;
|
|
318
318
|
var compiledValidator;
|
|
319
|
-
if (schema[
|
|
320
|
-
compiledValidator = this.ajv.getSchema(schema[
|
|
319
|
+
if (schema['$id']) {
|
|
320
|
+
compiledValidator = this.ajv.getSchema(schema['$id']);
|
|
321
321
|
}
|
|
322
322
|
try {
|
|
323
323
|
if (compiledValidator === undefined) {
|
|
@@ -329,7 +329,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
329
329
|
}
|
|
330
330
|
var errors;
|
|
331
331
|
if (compiledValidator) {
|
|
332
|
-
if (typeof this.localizer ===
|
|
332
|
+
if (typeof this.localizer === 'function') {
|
|
333
333
|
this.localizer(compiledValidator.errors);
|
|
334
334
|
}
|
|
335
335
|
errors = compiledValidator.errors || undefined;
|
|
@@ -361,7 +361,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
361
361
|
stack: invalidSchemaError.message
|
|
362
362
|
}]);
|
|
363
363
|
}
|
|
364
|
-
if (typeof transformErrors ===
|
|
364
|
+
if (typeof transformErrors === 'function') {
|
|
365
365
|
errors = transformErrors(errors, uiSchema);
|
|
366
366
|
}
|
|
367
367
|
var errorSchema = this.toErrorSchema(errors);
|
|
@@ -372,7 +372,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
372
372
|
}
|
|
373
373
|
});
|
|
374
374
|
}
|
|
375
|
-
if (typeof customValidate !==
|
|
375
|
+
if (typeof customValidate !== 'function') {
|
|
376
376
|
return {
|
|
377
377
|
errors: errors,
|
|
378
378
|
errorSchema: errorSchema
|
|
@@ -397,7 +397,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
397
397
|
for (var key in node) {
|
|
398
398
|
var realObj = node;
|
|
399
399
|
var value = realObj[key];
|
|
400
|
-
if (key === utils.REF_KEY && typeof value ===
|
|
400
|
+
if (key === utils.REF_KEY && typeof value === 'string' && value.startsWith('#')) {
|
|
401
401
|
realObj[key] = ROOT_SCHEMA_PREFIX + value;
|
|
402
402
|
} else {
|
|
403
403
|
realObj[key] = this.withIdRefPrefix(value);
|
|
@@ -427,7 +427,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
427
427
|
*/;
|
|
428
428
|
_proto.isValid = function isValid(schema, formData, rootSchema) {
|
|
429
429
|
var _rootSchema$$id;
|
|
430
|
-
var rootSchemaId = (_rootSchema$$id = rootSchema[
|
|
430
|
+
var rootSchemaId = (_rootSchema$$id = rootSchema['$id']) != null ? _rootSchema$$id : ROOT_SCHEMA_PREFIX;
|
|
431
431
|
try {
|
|
432
432
|
// add the rootSchema ROOT_SCHEMA_PREFIX as id.
|
|
433
433
|
// then rewrite the schema ref's to point to the rootSchema
|
|
@@ -438,8 +438,8 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
438
438
|
}
|
|
439
439
|
var schemaWithIdRefPrefix = this.withIdRefPrefix(schema);
|
|
440
440
|
var compiledValidator;
|
|
441
|
-
if (schemaWithIdRefPrefix[
|
|
442
|
-
compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix[
|
|
441
|
+
if (schemaWithIdRefPrefix['$id']) {
|
|
442
|
+
compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix['$id']);
|
|
443
443
|
}
|
|
444
444
|
if (compiledValidator === undefined) {
|
|
445
445
|
compiledValidator = this.ajv.compile(schemaWithIdRefPrefix);
|
|
@@ -447,7 +447,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
447
447
|
var result = compiledValidator(formData);
|
|
448
448
|
return result;
|
|
449
449
|
} catch (e) {
|
|
450
|
-
console.warn(
|
|
450
|
+
console.warn('Error encountered compiling schema:', e);
|
|
451
451
|
return false;
|
|
452
452
|
} finally {
|
|
453
453
|
// TODO: A function should be called if the root schema changes so we don't have to remove and recompile the schema every run.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator-ajv8.cjs.development.js","sources":["../src/createAjvInstance.ts","../src/validator.ts","../src/customizeValidator.ts","../src/index.ts"],"sourcesContent":["import Ajv, { Options } from \"ajv\";\nimport addFormats, { FormatsPluginOptions } from \"ajv-formats\";\nimport isObject from \"lodash/isObject\";\n\nimport { CustomValidatorOptionsType } from \"./types\";\nimport {\n ADDITIONAL_PROPERTY_FLAG,\n RJSF_ADDITONAL_PROPERTIES_FLAG,\n} 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 =\n /^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","import Ajv, { ErrorObject, ValidateFunction } from \"ajv\";\nimport toPath from \"lodash/toPath\";\nimport isObject from \"lodash/isObject\";\nimport clone from \"lodash/clone\";\nimport {\n CustomValidator,\n ERRORS_KEY,\n ErrorSchema,\n ErrorSchemaBuilder,\n ErrorTransformer,\n FieldValidation,\n FormContextType,\n FormValidation,\n GenericObjectType,\n getDefaultFormState,\n mergeValidationData,\n REF_KEY,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n UiSchema,\n ValidationData,\n ValidatorType,\n PROPERTIES_KEY,\n getUiOptions,\n} from \"@rjsf/utils\";\nimport get from \"lodash/get\";\n\nimport { CustomValidatorOptionsType, Localizer } from \"./types\";\nimport createAjvInstance from \"./createAjvInstance\";\n\nconst ROOT_SCHEMA_PREFIX = \"__rjsf_rootSchema\";\n\n/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.\n */\nexport default class AJV8Validator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n 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 {\n additionalMetaSchemas,\n customFormats,\n ajvOptionsOverrides,\n ajvFormatOptions,\n AjvClass,\n } = options;\n this.ajv = createAjvInstance(\n additionalMetaSchemas,\n customFormats,\n ajvOptionsOverrides,\n ajvFormatOptions,\n AjvClass\n );\n this.localizer = localizer;\n }\n\n /** Transforms a ajv validation errors list:\n * [\n * {property: '.level1.level2[2].level3', message: 'err a'},\n * {property: '.level1.level2[2].level3', message: 'err b'},\n * {property: '.level1.level2[4].level3', message: 'err b'},\n * ]\n * Into an error tree:\n * {\n * level1: {\n * level2: {\n * 2: {level3: {errors: ['err a', 'err b']}},\n * 4: {level3: {errors: ['err b']}},\n * }\n * }\n * };\n *\n * @param errors - The list of RJSFValidationError objects\n * @private\n */\n private toErrorSchema(errors: RJSFValidationError[]): ErrorSchema<T> {\n const builder = new ErrorSchemaBuilder<T>();\n if (errors.length) {\n errors.forEach((error) => {\n const { property, message } = error;\n const path = toPath(property);\n\n // If the property is at the root (.level1) then toPath creates\n // an empty array element at the first index. Remove it.\n if (path.length > 0 && path[0] === \"\") {\n path.splice(0, 1);\n }\n if (message) {\n builder.addErrors(message, path);\n }\n });\n }\n return builder.ErrorSchema;\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 */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n if (!errorSchema) {\n return [];\n }\n let errorList: RJSFValidationError[] = [];\n if (ERRORS_KEY in errorSchema) {\n errorList = errorList.concat(\n errorSchema[ERRORS_KEY]!.map((message: string) => {\n const property = `.${fieldPath.join(\".\")}`;\n return {\n property,\n message,\n stack: `${property} ${message}`,\n };\n })\n );\n }\n return Object.keys(errorSchema).reduce((acc, key) => {\n if (key !== ERRORS_KEY) {\n acc = acc.concat(\n this.toErrorList((errorSchema as GenericObjectType)[key], [\n ...fieldPath,\n key,\n ])\n );\n }\n return acc;\n }, errorList);\n }\n\n /** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it\n *\n * @param formData - The form data around which the error handler is created\n * @private\n */\n private createErrorHandler(formData: T): FormValidation<T> {\n const handler: FieldValidation = {\n // We store the list of errors for this node in a property named __errors\n // to avoid name collision with a possible sub schema field named\n // 'errors' (see `utils.toErrorSchema`).\n __errors: [],\n addError(message: string) {\n this.__errors!.push(message);\n },\n };\n if (Array.isArray(formData)) {\n return formData.reduce((acc, value, key) => {\n return { ...acc, [key]: this.createErrorHandler(value) };\n }, handler);\n }\n if (isObject(formData)) {\n const formObject: GenericObjectType = formData as GenericObjectType;\n return Object.keys(formObject).reduce((acc, key) => {\n return { ...acc, [key]: this.createErrorHandler(formObject[key]) };\n }, handler as FormValidation<T>);\n }\n return handler as FormValidation<T>;\n }\n\n /** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError` functions from it\n *\n * @param errorHandler - The `FormValidation` error handling structure\n * @private\n */\n private unwrapErrorHandler(errorHandler: FormValidation<T>): ErrorSchema<T> {\n return Object.keys(errorHandler).reduce((acc, key) => {\n if (key === \"addError\") {\n return acc;\n } else if (key === ERRORS_KEY) {\n return { ...acc, [key]: (errorHandler as GenericObjectType)[key] };\n }\n return {\n ...acc,\n [key]: this.unwrapErrorHandler(\n (errorHandler as GenericObjectType)[key]\n ),\n };\n }, {} as ErrorSchema<T>);\n }\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 * @protected\n */\n protected transformRJSFValidationErrors(\n errors: ErrorObject[] = [],\n uiSchema?: UiSchema<T, S, F>\n ): RJSFValidationError[] {\n return errors.map((e: ErrorObject) => {\n const {\n instancePath,\n keyword,\n params,\n schemaPath,\n parentSchema,\n ...rest\n } = 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\n ? `${property}.${params.missingProperty}`\n : params.missingProperty;\n const currentProperty: string = params.missingProperty;\n const uiSchemaTitle = getUiOptions(\n get(uiSchema, `${property.replace(/^\\./, \"\")}`)\n ).title;\n\n if (uiSchemaTitle) {\n message = message.replace(currentProperty, uiSchemaTitle);\n } else {\n const parentSchemaTitle = get(parentSchema, [\n PROPERTIES_KEY,\n currentProperty,\n \"title\",\n ]);\n\n if (parentSchemaTitle) {\n message = message.replace(currentProperty, parentSchemaTitle);\n }\n }\n\n stack = message;\n } else {\n const uiSchemaTitle = getUiOptions(\n get(uiSchema, `${property.replace(/^\\./, \"\")}`)\n ).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 /** 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>(\n schema: RJSFSchema,\n formData?: T\n ): { errors?: Result[]; validationError?: Error } {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema[\"$id\"]) {\n compiledValidator = this.ajv.getSchema(schema[\"$id\"]);\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 const { validationError: invalidSchemaError } = rawErrors;\n let errors = this.transformRJSFValidationErrors(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 = this.toErrorSchema(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>(\n this,\n schema,\n formData,\n schema,\n true\n ) as T;\n\n const errorHandler = customValidate(\n newFormData,\n this.createErrorHandler(newFormData),\n uiSchema\n );\n const userErrorSchema = this.unwrapErrorHandler(errorHandler);\n return mergeValidationData<T, S, F>(\n this,\n { errors, errorSchema },\n userErrorSchema\n );\n }\n\n /** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling\n * `withIdRefPrefix` for any other elements.\n *\n * @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @private\n */\n private withIdRefPrefixObject(node: S) {\n for (const key in node) {\n const realObj: GenericObjectType = node;\n const value = realObj[key];\n if (\n key === REF_KEY &&\n typeof value === \"string\" &&\n value.startsWith(\"#\")\n ) {\n realObj[key] = ROOT_SCHEMA_PREFIX + value;\n } else {\n realObj[key] = this.withIdRefPrefix(value);\n }\n }\n return node;\n }\n\n /** Takes a `node` object list and transforms any contained `$ref` node variables with a prefix, recursively calling\n * `withIdRefPrefix` for any other elements.\n *\n * @param node - The list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @private\n */\n private withIdRefPrefixArray(node: S[]): S[] {\n for (let i = 0; i < node.length; i++) {\n node[i] = this.withIdRefPrefix(node[i]) as S;\n }\n return node;\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\"] ?? 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 = this.withIdRefPrefix(schema) as S;\n let compiledValidator: ValidateFunction | undefined;\n if (schemaWithIdRefPrefix[\"$id\"]) {\n compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix[\"$id\"]);\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 /** Recursively prefixes all $ref's in a schema with `ROOT_SCHEMA_PREFIX`\n * This is used in isValid to make references to the rootSchema\n *\n * @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @protected\n */\n protected withIdRefPrefix(schemaNode: S | S[]): S | S[] {\n if (Array.isArray(schemaNode)) {\n return this.withIdRefPrefixArray([...schemaNode]);\n }\n if (isObject(schemaNode)) {\n return this.withIdRefPrefixObject(clone<S>(schemaNode));\n }\n return schemaNode;\n }\n}\n","import {\n FormContextType,\n RJSFSchema,\n StrictRJSFSchema,\n ValidatorType,\n} 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.\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 */\nexport default function customizeValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(\n options: CustomValidatorOptionsType = {},\n localizer?: Localizer\n): ValidatorType<T, S, F> {\n return new AJV8Validator<T, S, F>(options, localizer);\n}\n","import customizeValidator from \"./customizeValidator\";\n\nexport { customizeValidator };\nexport * from \"./types\";\n\nexport default customizeValidator();\n"],"names":["AJV_CONFIG","allErrors","multipleOfPrecision","strict","verbose","COLOR_FORMAT_REGEX","DATA_URL_FORMAT_REGEX","createAjvInstance","additionalMetaSchemas","customFormats","ajvOptionsOverrides","ajvFormatOptions","AjvClass","Ajv","ajv","addFormats","addFormat","addKeyword","ADDITIONAL_PROPERTY_FLAG","RJSF_ADDITONAL_PROPERTIES_FLAG","Array","isArray","addMetaSchema","isObject","Object","keys","forEach","formatName","ROOT_SCHEMA_PREFIX","AJV8Validator","options","localizer","toErrorSchema","errors","builder","ErrorSchemaBuilder","length","error","property","message","path","toPath","splice","addErrors","ErrorSchema","toErrorList","errorSchema","fieldPath","errorList","ERRORS_KEY","concat","map","join","stack","reduce","acc","key","createErrorHandler","formData","handler","__errors","addError","push","value","formObject","unwrapErrorHandler","errorHandler","transformRJSFValidationErrors","uiSchema","e","instancePath","keyword","params","schemaPath","parentSchema","rest","replace","trim","missingProperty","currentProperty","uiSchemaTitle","getUiOptions","get","title","parentSchemaTitle","PROPERTIES_KEY","name","rawValidation","schema","compilationError","undefined","compiledValidator","getSchema","compile","err","validationError","validateFormData","customValidate","transformErrors","rawErrors","invalidSchemaError","$schema","newFormData","getDefaultFormState","userErrorSchema","mergeValidationData","withIdRefPrefixObject","node","realObj","REF_KEY","startsWith","withIdRefPrefix","withIdRefPrefixArray","i","isValid","rootSchema","rootSchemaId","addSchema","schemaWithIdRefPrefix","result","console","warn","removeSchema","schemaNode","clone","customizeValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,IAAMA,UAAU,GAAY;AACjCC,EAAAA,SAAS,EAAE,IAAI;AACfC,EAAAA,mBAAmB,EAAE,CAAC;AACtBC,EAAAA,MAAM,EAAE,KAAK;AACbC,EAAAA,OAAO,EAAE,IAAA;CACD,CAAA;AACH,IAAMC,kBAAkB,GAC7B,4YAA4Y,CAAA;AACvY,IAAMC,qBAAqB,GAChC,2DAA2D,CAAA;AAE7D;;;;;;;;;;;;;;AAcG;AACqB,SAAAC,iBAAiB,CACvCC,qBAA2E,EAC3EC,aAA2D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Ae,GAAf,SAAgBY,eAAAA,CAAAA,UAAmB,EAAA;AAC3C,IAAA,IAAIvG,KAAK,CAACC,OAAO,CAACsG,UAAU,CAAC,EAAE;AAC7B,MAAA,OAAO,IAAI,CAACX,oBAAoB,CAAA,EAAA,CAAA,MAAA,CAAKW,UAAU,CAAE,CAAA,CAAA;AAClD,KAAA;AACD,IAAA,IAAIpG,4BAAQ,CAACoG,UAAU,CAAC,EAAE;MACxB,OAAO,IAAI,CAACjB,qBAAqB,CAACkB,yBAAK,CAAID,UAAU,CAAC,CAAC,CAAA;AACxD,KAAA;AACD,IAAA,OAAOA,UAAU,CAAA;GAClB,CAAA;AAAA,EAAA,OAAA,aAAA,CAAA;AAAA,CAAA,EAAA;;AC5cH;;;;;AAKG;AACqB,SAAAE,kBAAkB,CAKxC/F,OAAsC,EACtCC,SAAqB,EAAA;AAAA,EAAA,IADrBD,OAAsC,KAAA,KAAA,CAAA,EAAA;IAAtCA,OAAsC,GAAA,EAAE,CAAA;AAAA,GAAA;AAGxC,EAAA,OAAO,IAAID,aAAa,CAAUC,OAAO,EAAEC,SAAS,CAAC,CAAA;AACvD;;ACpBA,YAAA,aAAe8F,kBAAkB,EAAE;;;;;"}
|
|
1
|
+
{"version":3,"file":"validator-ajv8.cjs.development.js","sources":["../src/createAjvInstance.ts","../src/validator.ts","../src/customizeValidator.ts","../src/index.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","import Ajv, { ErrorObject, ValidateFunction } from 'ajv';\nimport toPath from 'lodash/toPath';\nimport isObject from 'lodash/isObject';\nimport clone from 'lodash/clone';\nimport {\n CustomValidator,\n ERRORS_KEY,\n ErrorSchema,\n ErrorSchemaBuilder,\n ErrorTransformer,\n FieldValidation,\n FormContextType,\n FormValidation,\n GenericObjectType,\n getDefaultFormState,\n mergeValidationData,\n REF_KEY,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n UiSchema,\n ValidationData,\n ValidatorType,\n PROPERTIES_KEY,\n getUiOptions,\n} from '@rjsf/utils';\nimport get from 'lodash/get';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport createAjvInstance from './createAjvInstance';\n\nconst ROOT_SCHEMA_PREFIX = '__rjsf_rootSchema';\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 /** Transforms a ajv validation errors list:\n * [\n * {property: '.level1.level2[2].level3', message: 'err a'},\n * {property: '.level1.level2[2].level3', message: 'err b'},\n * {property: '.level1.level2[4].level3', message: 'err b'},\n * ]\n * Into an error tree:\n * {\n * level1: {\n * level2: {\n * 2: {level3: {errors: ['err a', 'err b']}},\n * 4: {level3: {errors: ['err b']}},\n * }\n * }\n * };\n *\n * @param errors - The list of RJSFValidationError objects\n * @private\n */\n private toErrorSchema(errors: RJSFValidationError[]): ErrorSchema<T> {\n const builder = new ErrorSchemaBuilder<T>();\n if (errors.length) {\n errors.forEach((error) => {\n const { property, message } = error;\n const path = toPath(property);\n\n // If the property is at the root (.level1) then toPath creates\n // an empty array element at the first index. Remove it.\n if (path.length > 0 && path[0] === '') {\n path.splice(0, 1);\n }\n if (message) {\n builder.addErrors(message, path);\n }\n });\n }\n return builder.ErrorSchema;\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 */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n if (!errorSchema) {\n return [];\n }\n let errorList: RJSFValidationError[] = [];\n if (ERRORS_KEY in errorSchema) {\n errorList = errorList.concat(\n errorSchema[ERRORS_KEY]!.map((message: string) => {\n const property = `.${fieldPath.join('.')}`;\n return {\n property,\n message,\n stack: `${property} ${message}`,\n };\n })\n );\n }\n return Object.keys(errorSchema).reduce((acc, key) => {\n if (key !== ERRORS_KEY) {\n acc = acc.concat(this.toErrorList((errorSchema as GenericObjectType)[key], [...fieldPath, key]));\n }\n return acc;\n }, errorList);\n }\n\n /** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it\n *\n * @param formData - The form data around which the error handler is created\n * @private\n */\n private createErrorHandler(formData: T): FormValidation<T> {\n const handler: FieldValidation = {\n // We store the list of errors for this node in a property named __errors\n // to avoid name collision with a possible sub schema field named\n // 'errors' (see `utils.toErrorSchema`).\n __errors: [],\n addError(message: string) {\n this.__errors!.push(message);\n },\n };\n if (Array.isArray(formData)) {\n return formData.reduce((acc, value, key) => {\n return { ...acc, [key]: this.createErrorHandler(value) };\n }, handler);\n }\n if (isObject(formData)) {\n const formObject: GenericObjectType = formData as GenericObjectType;\n return Object.keys(formObject).reduce((acc, key) => {\n return { ...acc, [key]: this.createErrorHandler(formObject[key]) };\n }, handler as FormValidation<T>);\n }\n return handler as FormValidation<T>;\n }\n\n /** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError` functions from it\n *\n * @param errorHandler - The `FormValidation` error handling structure\n * @private\n */\n private unwrapErrorHandler(errorHandler: FormValidation<T>): ErrorSchema<T> {\n return Object.keys(errorHandler).reduce((acc, key) => {\n if (key === 'addError') {\n return acc;\n } else if (key === ERRORS_KEY) {\n return { ...acc, [key]: (errorHandler as GenericObjectType)[key] };\n }\n return {\n ...acc,\n [key]: this.unwrapErrorHandler((errorHandler as GenericObjectType)[key]),\n };\n }, {} as ErrorSchema<T>);\n }\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 * @protected\n */\n protected transformRJSFValidationErrors(\n errors: ErrorObject[] = [],\n uiSchema?: UiSchema<T, S, F>\n ): 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(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 /** 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: RJSFSchema, formData?: T): { errors?: Result[]; validationError?: Error } {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema['$id']) {\n compiledValidator = this.ajv.getSchema(schema['$id']);\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 const { validationError: invalidSchemaError } = rawErrors;\n let errors = this.transformRJSFValidationErrors(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 = this.toErrorSchema(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>(this, schema, formData, schema, true) as T;\n\n const errorHandler = customValidate(newFormData, this.createErrorHandler(newFormData), uiSchema);\n const userErrorSchema = this.unwrapErrorHandler(errorHandler);\n return mergeValidationData<T, S, F>(this, { errors, errorSchema }, userErrorSchema);\n }\n\n /** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling\n * `withIdRefPrefix` for any other elements.\n *\n * @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @private\n */\n private withIdRefPrefixObject(node: S) {\n for (const key in node) {\n const realObj: GenericObjectType = node;\n const value = realObj[key];\n if (key === REF_KEY && typeof value === 'string' && value.startsWith('#')) {\n realObj[key] = ROOT_SCHEMA_PREFIX + value;\n } else {\n realObj[key] = this.withIdRefPrefix(value);\n }\n }\n return node;\n }\n\n /** Takes a `node` object list and transforms any contained `$ref` node variables with a prefix, recursively calling\n * `withIdRefPrefix` for any other elements.\n *\n * @param node - The list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @private\n */\n private withIdRefPrefixArray(node: S[]): S[] {\n for (let i = 0; i < node.length; i++) {\n node[i] = this.withIdRefPrefix(node[i]) as S;\n }\n return node;\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'] ?? 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 = this.withIdRefPrefix(schema) as S;\n let compiledValidator: ValidateFunction | undefined;\n if (schemaWithIdRefPrefix['$id']) {\n compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix['$id']);\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 /** Recursively prefixes all $ref's in a schema with `ROOT_SCHEMA_PREFIX`\n * This is used in isValid to make references to the rootSchema\n *\n * @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @protected\n */\n protected withIdRefPrefix(schemaNode: S | S[]): S | S[] {\n if (Array.isArray(schemaNode)) {\n return this.withIdRefPrefixArray([...schemaNode]);\n }\n if (isObject(schemaNode)) {\n return this.withIdRefPrefixObject(clone<S>(schemaNode));\n }\n return schemaNode;\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.\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 */\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 customizeValidator from './customizeValidator';\n\nexport { customizeValidator };\nexport * from './types';\n\nexport default customizeValidator();\n"],"names":["AJV_CONFIG","allErrors","multipleOfPrecision","strict","verbose","COLOR_FORMAT_REGEX","DATA_URL_FORMAT_REGEX","createAjvInstance","additionalMetaSchemas","customFormats","ajvOptionsOverrides","ajvFormatOptions","AjvClass","Ajv","ajv","addFormats","addFormat","addKeyword","ADDITIONAL_PROPERTY_FLAG","RJSF_ADDITONAL_PROPERTIES_FLAG","Array","isArray","addMetaSchema","isObject","Object","keys","forEach","formatName","ROOT_SCHEMA_PREFIX","AJV8Validator","options","localizer","toErrorSchema","errors","builder","ErrorSchemaBuilder","length","error","property","message","path","toPath","splice","addErrors","ErrorSchema","toErrorList","errorSchema","fieldPath","errorList","ERRORS_KEY","concat","map","join","stack","reduce","acc","key","createErrorHandler","formData","handler","__errors","addError","push","value","formObject","unwrapErrorHandler","errorHandler","transformRJSFValidationErrors","uiSchema","e","instancePath","keyword","params","schemaPath","parentSchema","rest","replace","trim","missingProperty","currentProperty","uiSchemaTitle","getUiOptions","get","title","parentSchemaTitle","PROPERTIES_KEY","name","rawValidation","schema","compilationError","undefined","compiledValidator","getSchema","compile","err","validationError","validateFormData","customValidate","transformErrors","rawErrors","invalidSchemaError","$schema","newFormData","getDefaultFormState","userErrorSchema","mergeValidationData","withIdRefPrefixObject","node","realObj","REF_KEY","startsWith","withIdRefPrefix","withIdRefPrefixArray","i","isValid","rootSchema","rootSchemaId","addSchema","schemaWithIdRefPrefix","result","console","warn","removeSchema","schemaNode","clone","customizeValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOO,IAAMA,UAAU,GAAY;AACjCC,EAAAA,SAAS,EAAE,IAAI;AACfC,EAAAA,mBAAmB,EAAE,CAAC;AACtBC,EAAAA,MAAM,EAAE,KAAK;AACbC,EAAAA,OAAO,EAAE,IAAA;CACD,CAAA;AACH,IAAMC,kBAAkB,GAC7B,4YAA4Y,CAAA;AACvY,IAAMC,qBAAqB,GAAG,2DAA2D,CAAA;AAEhG;;;;;;;;;;;;;;AAcG;AACqB,SAAAC,iBAAiB,CACvCC,qBAA2E,EAC3EC,aAA2D,EAC3DC,qBACAC,gBAA+C,EAC/CC,UAA0B;AAAA,EAAA,IAF1BF;IAAAA,sBAAyE,EAAE,CAAA;AAAA,GAAA;AAAA,EAAA,IAE3EE;AAAAA,IAAAA,WAAuBC,uBAAG,CAAA;AAAA,GAAA;EAE1B,IAAMC,GAAG,GAAG,IAAIF,QAAQ,cAAMZ,UAAU,EAAKU,mBAAmB,CAAG,CAAA,CAAA;AACnE,EAAA,IAAIC,gBAAgB,EAAE;AACpBI,IAAAA,8BAAU,CAACD,GAAG,EAAEH,gBAAgB,CA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AAI,CAACjB,qBAAqB,CAACkB,yBAAK,CAAID,UAAU,CAAC,CAAC,CAAA;AACxD,KAAA;AACD,IAAA,OAAOA,UAAU,CAAA;GAClB,CAAA;AAAA,EAAA,OAAA,aAAA,CAAA;AAAA,CAAA,EAAA;;ACrZH;;;;;AAKG;AACqB,SAAAE,kBAAkB,CAIxC/F,OAAsC,EAAIC,SAAqB,EAAA;AAAA,EAAA,IAA/DD,OAAsC,KAAA,KAAA,CAAA,EAAA;IAAtCA,OAAsC,GAAA,EAAE,CAAA;AAAA,GAAA;AACxC,EAAA,OAAO,IAAID,aAAa,CAAUC,OAAO,EAAEC,SAAS,CAAC,CAAA;AACvD;;ACZA,YAAA,aAAe8F,kBAAkB,EAAE;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator-ajv8.cjs.production.min.js","sources":["../src/createAjvInstance.ts","../src/validator.ts","../src/customizeValidator.ts","../src/index.ts"],"sourcesContent":["import Ajv, { Options } from \"ajv\";\nimport addFormats, { FormatsPluginOptions } from \"ajv-formats\";\nimport isObject from \"lodash/isObject\";\n\nimport { CustomValidatorOptionsType } from \"./types\";\nimport {\n ADDITIONAL_PROPERTY_FLAG,\n RJSF_ADDITONAL_PROPERTIES_FLAG,\n} 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 =\n /^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","import Ajv, { ErrorObject, ValidateFunction } from \"ajv\";\nimport toPath from \"lodash/toPath\";\nimport isObject from \"lodash/isObject\";\nimport clone from \"lodash/clone\";\nimport {\n CustomValidator,\n ERRORS_KEY,\n ErrorSchema,\n ErrorSchemaBuilder,\n ErrorTransformer,\n FieldValidation,\n FormContextType,\n FormValidation,\n GenericObjectType,\n getDefaultFormState,\n mergeValidationData,\n REF_KEY,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n UiSchema,\n ValidationData,\n ValidatorType,\n PROPERTIES_KEY,\n getUiOptions,\n} from \"@rjsf/utils\";\nimport get from \"lodash/get\";\n\nimport { CustomValidatorOptionsType, Localizer } from \"./types\";\nimport createAjvInstance from \"./createAjvInstance\";\n\nconst ROOT_SCHEMA_PREFIX = \"__rjsf_rootSchema\";\n\n/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.\n */\nexport default class AJV8Validator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n 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 {\n additionalMetaSchemas,\n customFormats,\n ajvOptionsOverrides,\n ajvFormatOptions,\n AjvClass,\n } = options;\n this.ajv = createAjvInstance(\n additionalMetaSchemas,\n customFormats,\n ajvOptionsOverrides,\n ajvFormatOptions,\n AjvClass\n );\n this.localizer = localizer;\n }\n\n /** Transforms a ajv validation errors list:\n * [\n * {property: '.level1.level2[2].level3', message: 'err a'},\n * {property: '.level1.level2[2].level3', message: 'err b'},\n * {property: '.level1.level2[4].level3', message: 'err b'},\n * ]\n * Into an error tree:\n * {\n * level1: {\n * level2: {\n * 2: {level3: {errors: ['err a', 'err b']}},\n * 4: {level3: {errors: ['err b']}},\n * }\n * }\n * };\n *\n * @param errors - The list of RJSFValidationError objects\n * @private\n */\n private toErrorSchema(errors: RJSFValidationError[]): ErrorSchema<T> {\n const builder = new ErrorSchemaBuilder<T>();\n if (errors.length) {\n errors.forEach((error) => {\n const { property, message } = error;\n const path = toPath(property);\n\n // If the property is at the root (.level1) then toPath creates\n // an empty array element at the first index. Remove it.\n if (path.length > 0 && path[0] === \"\") {\n path.splice(0, 1);\n }\n if (message) {\n builder.addErrors(message, path);\n }\n });\n }\n return builder.ErrorSchema;\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 */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n if (!errorSchema) {\n return [];\n }\n let errorList: RJSFValidationError[] = [];\n if (ERRORS_KEY in errorSchema) {\n errorList = errorList.concat(\n errorSchema[ERRORS_KEY]!.map((message: string) => {\n const property = `.${fieldPath.join(\".\")}`;\n return {\n property,\n message,\n stack: `${property} ${message}`,\n };\n })\n );\n }\n return Object.keys(errorSchema).reduce((acc, key) => {\n if (key !== ERRORS_KEY) {\n acc = acc.concat(\n this.toErrorList((errorSchema as GenericObjectType)[key], [\n ...fieldPath,\n key,\n ])\n );\n }\n return acc;\n }, errorList);\n }\n\n /** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it\n *\n * @param formData - The form data around which the error handler is created\n * @private\n */\n private createErrorHandler(formData: T): FormValidation<T> {\n const handler: FieldValidation = {\n // We store the list of errors for this node in a property named __errors\n // to avoid name collision with a possible sub schema field named\n // 'errors' (see `utils.toErrorSchema`).\n __errors: [],\n addError(message: string) {\n this.__errors!.push(message);\n },\n };\n if (Array.isArray(formData)) {\n return formData.reduce((acc, value, key) => {\n return { ...acc, [key]: this.createErrorHandler(value) };\n }, handler);\n }\n if (isObject(formData)) {\n const formObject: GenericObjectType = formData as GenericObjectType;\n return Object.keys(formObject).reduce((acc, key) => {\n return { ...acc, [key]: this.createErrorHandler(formObject[key]) };\n }, handler as FormValidation<T>);\n }\n return handler as FormValidation<T>;\n }\n\n /** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError` functions from it\n *\n * @param errorHandler - The `FormValidation` error handling structure\n * @private\n */\n private unwrapErrorHandler(errorHandler: FormValidation<T>): ErrorSchema<T> {\n return Object.keys(errorHandler).reduce((acc, key) => {\n if (key === \"addError\") {\n return acc;\n } else if (key === ERRORS_KEY) {\n return { ...acc, [key]: (errorHandler as GenericObjectType)[key] };\n }\n return {\n ...acc,\n [key]: this.unwrapErrorHandler(\n (errorHandler as GenericObjectType)[key]\n ),\n };\n }, {} as ErrorSchema<T>);\n }\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 * @protected\n */\n protected transformRJSFValidationErrors(\n errors: ErrorObject[] = [],\n uiSchema?: UiSchema<T, S, F>\n ): RJSFValidationError[] {\n return errors.map((e: ErrorObject) => {\n const {\n instancePath,\n keyword,\n params,\n schemaPath,\n parentSchema,\n ...rest\n } = 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\n ? `${property}.${params.missingProperty}`\n : params.missingProperty;\n const currentProperty: string = params.missingProperty;\n const uiSchemaTitle = getUiOptions(\n get(uiSchema, `${property.replace(/^\\./, \"\")}`)\n ).title;\n\n if (uiSchemaTitle) {\n message = message.replace(currentProperty, uiSchemaTitle);\n } else {\n const parentSchemaTitle = get(parentSchema, [\n PROPERTIES_KEY,\n currentProperty,\n \"title\",\n ]);\n\n if (parentSchemaTitle) {\n message = message.replace(currentProperty, parentSchemaTitle);\n }\n }\n\n stack = message;\n } else {\n const uiSchemaTitle = getUiOptions(\n get(uiSchema, `${property.replace(/^\\./, \"\")}`)\n ).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 /** 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>(\n schema: RJSFSchema,\n formData?: T\n ): { errors?: Result[]; validationError?: Error } {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema[\"$id\"]) {\n compiledValidator = this.ajv.getSchema(schema[\"$id\"]);\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 const { validationError: invalidSchemaError } = rawErrors;\n let errors = this.transformRJSFValidationErrors(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 = this.toErrorSchema(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>(\n this,\n schema,\n formData,\n schema,\n true\n ) as T;\n\n const errorHandler = customValidate(\n newFormData,\n this.createErrorHandler(newFormData),\n uiSchema\n );\n const userErrorSchema = this.unwrapErrorHandler(errorHandler);\n return mergeValidationData<T, S, F>(\n this,\n { errors, errorSchema },\n userErrorSchema\n );\n }\n\n /** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling\n * `withIdRefPrefix` for any other elements.\n *\n * @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @private\n */\n private withIdRefPrefixObject(node: S) {\n for (const key in node) {\n const realObj: GenericObjectType = node;\n const value = realObj[key];\n if (\n key === REF_KEY &&\n typeof value === \"string\" &&\n value.startsWith(\"#\")\n ) {\n realObj[key] = ROOT_SCHEMA_PREFIX + value;\n } else {\n realObj[key] = this.withIdRefPrefix(value);\n }\n }\n return node;\n }\n\n /** Takes a `node` object list and transforms any contained `$ref` node variables with a prefix, recursively calling\n * `withIdRefPrefix` for any other elements.\n *\n * @param node - The list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @private\n */\n private withIdRefPrefixArray(node: S[]): S[] {\n for (let i = 0; i < node.length; i++) {\n node[i] = this.withIdRefPrefix(node[i]) as S;\n }\n return node;\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\"] ?? 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 = this.withIdRefPrefix(schema) as S;\n let compiledValidator: ValidateFunction | undefined;\n if (schemaWithIdRefPrefix[\"$id\"]) {\n compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix[\"$id\"]);\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 /** Recursively prefixes all $ref's in a schema with `ROOT_SCHEMA_PREFIX`\n * This is used in isValid to make references to the rootSchema\n *\n * @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @protected\n */\n protected withIdRefPrefix(schemaNode: S | S[]): S | S[] {\n if (Array.isArray(schemaNode)) {\n return this.withIdRefPrefixArray([...schemaNode]);\n }\n if (isObject(schemaNode)) {\n return this.withIdRefPrefixObject(clone<S>(schemaNode));\n }\n return schemaNode;\n }\n}\n","import {\n FormContextType,\n RJSFSchema,\n StrictRJSFSchema,\n ValidatorType,\n} 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.\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 */\nexport default function customizeValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(\n options: CustomValidatorOptionsType = {},\n localizer?: Localizer\n): ValidatorType<T, S, F> {\n return new AJV8Validator<T, S, F>(options, localizer);\n}\n","import customizeValidator from \"./customizeValidator\";\n\nexport { customizeValidator };\nexport * from \"./types\";\n\nexport default customizeValidator();\n"],"names":["AJV_CONFIG","allErrors","multipleOfPrecision","strict","verbose","COLOR_FORMAT_REGEX","DATA_URL_FORMAT_REGEX","AJV8Validator","options","localizer","this","ajv","additionalMetaSchemas","customFormats","ajvOptionsOverrides","ajvFormatOptions","AjvClass","Ajv","addFormats","addFormat","addKeyword","ADDITIONAL_PROPERTY_FLAG","RJSF_ADDITONAL_PROPERTIES_FLAG","Array","isArray","addMetaSchema","isObject","Object","keys","forEach","formatName","createAjvInstance","_proto","prototype","toErrorSchema","errors","builder","ErrorSchemaBuilder","length","error","message","path","toPath","property","splice","addErrors","ErrorSchema","toErrorList","errorSchema","fieldPath","_this","errorList","ERRORS_KEY","concat","map","join","stack","reduce","acc","key","createErrorHandler","formData","_this2","handler","__errors","addError","push","value","_extends2","formObject","_extends3","_extends","unwrapErrorHandler","errorHandler","_this3","_extends5","_extends4","transformRJSFValidationErrors","uiSchema","e","instancePath","keyword","params","schemaPath","parentSchema","rest","_excluded","_rest$message","replace","trim","currentProperty","missingProperty","uiSchemaTitle","getUiOptions","get","title","parentSchemaTitle","PROPERTIES_KEY","name","rawValidation","schema","compiledValidator","compilationError","undefined","getSchema","compile","err","validationError","validateFormData","customValidate","transformErrors","rawErrors","invalidSchemaError","$schema","newFormData","getDefaultFormState","userErrorSchema","mergeValidationData","withIdRefPrefixObject","node","REF_KEY","startsWith","withIdRefPrefix","withIdRefPrefixArray","i","isValid","rootSchema","_rootSchema$$id","rootSchemaId","addSchema","schemaWithIdRefPrefix","console","warn","removeSchema","schemaNode","clone","customizeValidator","index"],"mappings":"+kBAUO,IAAMA,EAAsB,CACjCC,WAAW,EACXC,oBAAqB,EACrBC,QAAQ,EACRC,SAAS,GAEEC,EACX,6YACWC,EACX,8HCgBmBC,EAAa,WAuBhC,SAAYC,EAAAA,EAAqCC,GAAqBC,KAb9DC,SAAG,EAAAD,KAMFD,eAAS,EAehBC,KAAKC,ID9Be,SACtBC,EACAC,EACAC,EACAC,EACAC,YAFAF,IAAAA,EAAyE,CAAA,YAEzEE,IAAAA,EAAuBC,EAAAA,SAEvB,IAAMN,EAAM,IAAIK,OAAchB,EAAec,IA2B7C,OA1BIC,EACFG,UAAWP,EAAKI,IACc,IAArBA,GACTG,EAAU,QAACP,GAIbA,EAAIQ,UAAU,WAAYb,GAC1BK,EAAIQ,UAAU,QAASd,GAGvBM,EAAIS,WAAWC,EAAAA,0BACfV,EAAIS,WAAWE,EAAAA,gCAGXC,MAAMC,QAAQZ,IAChBD,EAAIc,cAAcb,GAIhBc,EAAAA,QAASb,IACXc,OAAOC,KAAKf,GAAegB,SAAQ,SA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,UAAU0B,EAA2B,WAE1C3B,IAAtBF,IACFA,EAAoB3F,KAAKC,IAAI8F,QAAQyB,IAExB7B,EAAkBxC,EASlC,CAPC,MAAOkB,GAEP,OADAoD,QAAQC,KAAK,sCAAuCrD,IAC7C,CACR,CAAS,QAGRrE,KAAKC,IAAI0H,aAAaL,EACvB,CACH,EAEAhG,EAMU0F,gBAAA,SAAgBY,GACxB,OAAI/G,MAAMC,QAAQ8G,GACT5H,KAAKiH,qBAAoB,GAAAtE,OAAKiF,IAEnC5G,EAAAA,QAAS4G,GACJ5H,KAAK4G,sBAAsBiB,UAASD,IAEtCA,GACR/H,CAAA,CAnb+B,GCnBV,SAAAiI,EAKtBhI,EACAC,GAEA,YAHsC,IAAtCD,IAAAA,EAAsC,CAAA,GAG/B,IAAID,EAAuBC,EAASC,EAC7C,CCpBA,IAAAgI,EAAeD"}
|
|
1
|
+
{"version":3,"file":"validator-ajv8.cjs.production.min.js","sources":["../src/createAjvInstance.ts","../src/validator.ts","../src/customizeValidator.ts","../src/index.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","import Ajv, { ErrorObject, ValidateFunction } from 'ajv';\nimport toPath from 'lodash/toPath';\nimport isObject from 'lodash/isObject';\nimport clone from 'lodash/clone';\nimport {\n CustomValidator,\n ERRORS_KEY,\n ErrorSchema,\n ErrorSchemaBuilder,\n ErrorTransformer,\n FieldValidation,\n FormContextType,\n FormValidation,\n GenericObjectType,\n getDefaultFormState,\n mergeValidationData,\n REF_KEY,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n UiSchema,\n ValidationData,\n ValidatorType,\n PROPERTIES_KEY,\n getUiOptions,\n} from '@rjsf/utils';\nimport get from 'lodash/get';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport createAjvInstance from './createAjvInstance';\n\nconst ROOT_SCHEMA_PREFIX = '__rjsf_rootSchema';\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 /** Transforms a ajv validation errors list:\n * [\n * {property: '.level1.level2[2].level3', message: 'err a'},\n * {property: '.level1.level2[2].level3', message: 'err b'},\n * {property: '.level1.level2[4].level3', message: 'err b'},\n * ]\n * Into an error tree:\n * {\n * level1: {\n * level2: {\n * 2: {level3: {errors: ['err a', 'err b']}},\n * 4: {level3: {errors: ['err b']}},\n * }\n * }\n * };\n *\n * @param errors - The list of RJSFValidationError objects\n * @private\n */\n private toErrorSchema(errors: RJSFValidationError[]): ErrorSchema<T> {\n const builder = new ErrorSchemaBuilder<T>();\n if (errors.length) {\n errors.forEach((error) => {\n const { property, message } = error;\n const path = toPath(property);\n\n // If the property is at the root (.level1) then toPath creates\n // an empty array element at the first index. Remove it.\n if (path.length > 0 && path[0] === '') {\n path.splice(0, 1);\n }\n if (message) {\n builder.addErrors(message, path);\n }\n });\n }\n return builder.ErrorSchema;\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 */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n if (!errorSchema) {\n return [];\n }\n let errorList: RJSFValidationError[] = [];\n if (ERRORS_KEY in errorSchema) {\n errorList = errorList.concat(\n errorSchema[ERRORS_KEY]!.map((message: string) => {\n const property = `.${fieldPath.join('.')}`;\n return {\n property,\n message,\n stack: `${property} ${message}`,\n };\n })\n );\n }\n return Object.keys(errorSchema).reduce((acc, key) => {\n if (key !== ERRORS_KEY) {\n acc = acc.concat(this.toErrorList((errorSchema as GenericObjectType)[key], [...fieldPath, key]));\n }\n return acc;\n }, errorList);\n }\n\n /** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it\n *\n * @param formData - The form data around which the error handler is created\n * @private\n */\n private createErrorHandler(formData: T): FormValidation<T> {\n const handler: FieldValidation = {\n // We store the list of errors for this node in a property named __errors\n // to avoid name collision with a possible sub schema field named\n // 'errors' (see `utils.toErrorSchema`).\n __errors: [],\n addError(message: string) {\n this.__errors!.push(message);\n },\n };\n if (Array.isArray(formData)) {\n return formData.reduce((acc, value, key) => {\n return { ...acc, [key]: this.createErrorHandler(value) };\n }, handler);\n }\n if (isObject(formData)) {\n const formObject: GenericObjectType = formData as GenericObjectType;\n return Object.keys(formObject).reduce((acc, key) => {\n return { ...acc, [key]: this.createErrorHandler(formObject[key]) };\n }, handler as FormValidation<T>);\n }\n return handler as FormValidation<T>;\n }\n\n /** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError` functions from it\n *\n * @param errorHandler - The `FormValidation` error handling structure\n * @private\n */\n private unwrapErrorHandler(errorHandler: FormValidation<T>): ErrorSchema<T> {\n return Object.keys(errorHandler).reduce((acc, key) => {\n if (key === 'addError') {\n return acc;\n } else if (key === ERRORS_KEY) {\n return { ...acc, [key]: (errorHandler as GenericObjectType)[key] };\n }\n return {\n ...acc,\n [key]: this.unwrapErrorHandler((errorHandler as GenericObjectType)[key]),\n };\n }, {} as ErrorSchema<T>);\n }\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 * @protected\n */\n protected transformRJSFValidationErrors(\n errors: ErrorObject[] = [],\n uiSchema?: UiSchema<T, S, F>\n ): 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(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 /** 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: RJSFSchema, formData?: T): { errors?: Result[]; validationError?: Error } {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema['$id']) {\n compiledValidator = this.ajv.getSchema(schema['$id']);\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 const { validationError: invalidSchemaError } = rawErrors;\n let errors = this.transformRJSFValidationErrors(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 = this.toErrorSchema(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>(this, schema, formData, schema, true) as T;\n\n const errorHandler = customValidate(newFormData, this.createErrorHandler(newFormData), uiSchema);\n const userErrorSchema = this.unwrapErrorHandler(errorHandler);\n return mergeValidationData<T, S, F>(this, { errors, errorSchema }, userErrorSchema);\n }\n\n /** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling\n * `withIdRefPrefix` for any other elements.\n *\n * @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @private\n */\n private withIdRefPrefixObject(node: S) {\n for (const key in node) {\n const realObj: GenericObjectType = node;\n const value = realObj[key];\n if (key === REF_KEY && typeof value === 'string' && value.startsWith('#')) {\n realObj[key] = ROOT_SCHEMA_PREFIX + value;\n } else {\n realObj[key] = this.withIdRefPrefix(value);\n }\n }\n return node;\n }\n\n /** Takes a `node` object list and transforms any contained `$ref` node variables with a prefix, recursively calling\n * `withIdRefPrefix` for any other elements.\n *\n * @param node - The list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @private\n */\n private withIdRefPrefixArray(node: S[]): S[] {\n for (let i = 0; i < node.length; i++) {\n node[i] = this.withIdRefPrefix(node[i]) as S;\n }\n return node;\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'] ?? 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 = this.withIdRefPrefix(schema) as S;\n let compiledValidator: ValidateFunction | undefined;\n if (schemaWithIdRefPrefix['$id']) {\n compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix['$id']);\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 /** Recursively prefixes all $ref's in a schema with `ROOT_SCHEMA_PREFIX`\n * This is used in isValid to make references to the rootSchema\n *\n * @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it\n * @protected\n */\n protected withIdRefPrefix(schemaNode: S | S[]): S | S[] {\n if (Array.isArray(schemaNode)) {\n return this.withIdRefPrefixArray([...schemaNode]);\n }\n if (isObject(schemaNode)) {\n return this.withIdRefPrefixObject(clone<S>(schemaNode));\n }\n return schemaNode;\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.\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 */\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 customizeValidator from './customizeValidator';\n\nexport { customizeValidator };\nexport * from './types';\n\nexport default customizeValidator();\n"],"names":["AJV_CONFIG","allErrors","multipleOfPrecision","strict","verbose","COLOR_FORMAT_REGEX","DATA_URL_FORMAT_REGEX","AJV8Validator","options","localizer","this","ajv","additionalMetaSchemas","customFormats","ajvOptionsOverrides","ajvFormatOptions","AjvClass","Ajv","addFormats","addFormat","addKeyword","ADDITIONAL_PROPERTY_FLAG","RJSF_ADDITONAL_PROPERTIES_FLAG","Array","isArray","addMetaSchema","isObject","Object","keys","forEach","formatName","createAjvInstance","_proto","prototype","toErrorSchema","errors","builder","ErrorSchemaBuilder","length","error","message","path","toPath","property","splice","addErrors","ErrorSchema","toErrorList","errorSchema","fieldPath","_this","errorList","ERRORS_KEY","concat","map","join","stack","reduce","acc","key","createErrorHandler","formData","_this2","handler","__errors","addError","push","value","_extends2","formObject","_extends3","_extends","unwrapErrorHandler","errorHandler","_this3","_extends5","_extends4","transformRJSFValidationErrors","uiSchema","e","instancePath","keyword","params","schemaPath","parentSchema","rest","_excluded","_rest$message","replace","trim","currentProperty","missingProperty","uiSchemaTitle","getUiOptions","get","title","parentSchemaTitle","PROPERTIES_KEY","name","rawValidation","schema","compiledValidator","compilationError","undefined","getSchema","compile","err","validationError","validateFormData","customValidate","transformErrors","rawErrors","invalidSchemaError","$schema","newFormData","getDefaultFormState","userErrorSchema","mergeValidationData","withIdRefPrefixObject","node","REF_KEY","startsWith","withIdRefPrefix","withIdRefPrefixArray","i","isValid","rootSchema","_rootSchema$$id","rootSchemaId","addSchema","schemaWithIdRefPrefix","console","warn","removeSchema","schemaNode","clone","customizeValidator","index"],"mappings":"+kBAOO,IAAMA,EAAsB,CACjCC,WAAW,EACXC,oBAAqB,EACrBC,QAAQ,EACRC,SAAS,GAEEC,EACX,6YACWC,EAAwB,8HCoBhBC,EAAa,WAoBhC,SAAYC,EAAAA,EAAqCC,GAAqBC,KAb9DC,SAAG,EAAAD,KAMFD,eAAS,EAShBC,KAAKC,IDzBe,SACtBC,EACAC,EACAC,EACAC,EACAC,YAFAF,IAAAA,EAAyE,CAAA,YAEzEE,IAAAA,EAAuBC,EAAAA,SAEvB,IAAMN,EAAM,IAAIK,OAAchB,EAAec,IA2B7C,OA1BIC,EACFG,UAAWP,EAAKI,IACc,IAArBA,GACTG,EAAU,QAACP,GAIbA,EAAIQ,UAAU,WAAYb,GAC1BK,EAAIQ,UAAU,QAASd,GAGvBM,EAAIS,WAAWC,EAAAA,0BACfV,EAAIS,WAAWE,EAAAA,gCAGXC,MAAMC,QAAQZ,IAChBD,EAAIc,cAAcb,GAIhBc,EAAAA,QAASb,IACXc,OAAOC,KAAKf,GAAegB,SAAQ,SAACC,GAClCnB,EAAIQ,UAAUW,EAAYjB,EAAciB,GAC1C,IAGKnB,CACT,CCVeoB,CADuFvB,EAA1FI,sBAA0FJ,EAAnEK,cAAmEL,EAApDM,oBAAoDN,EAA/BO,iBAA+BP,EAAbQ,UAErFN,KAAKD,UAAYA,CACnB,CAEA,IAAAuB,EAAAzB,EAAA0B,UA6VC,OA7VDD,EAmBQE,cAAA,S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C,IAAI0H,aAAaL,EACvB,CACH,EAEAhG,EAMU0F,gBAAA,SAAgBY,GACxB,OAAI/G,MAAMC,QAAQ8G,GACT5H,KAAKiH,qBAAoB,GAAAtE,OAAKiF,IAEnC5G,EAAAA,QAAS4G,GACJ5H,KAAK4G,sBAAsBiB,UAASD,IAEtCA,GACR/H,CAAA,CAvX+B,GCxBV,SAAAiI,EAItBhI,EAA0CC,GAC1C,YADsC,IAAtCD,IAAAA,EAAsC,CAAA,GAC/B,IAAID,EAAuBC,EAASC,EAC7C,CCZA,IAAAgI,EAAeD"}
|
|
@@ -70,8 +70,8 @@ function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverr
|
|
|
70
70
|
addFormats(ajv);
|
|
71
71
|
}
|
|
72
72
|
// add custom formats
|
|
73
|
-
ajv.addFormat(
|
|
74
|
-
ajv.addFormat(
|
|
73
|
+
ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);
|
|
74
|
+
ajv.addFormat('color', COLOR_FORMAT_REGEX);
|
|
75
75
|
// Add RJSF-specific additional properties keywords so Ajv doesn't report errors if strict is enabled.
|
|
76
76
|
ajv.addKeyword(ADDITIONAL_PROPERTY_FLAG);
|
|
77
77
|
ajv.addKeyword(RJSF_ADDITONAL_PROPERTIES_FLAG);
|
|
@@ -89,7 +89,7 @@ function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverr
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
var _excluded = ["instancePath", "keyword", "params", "schemaPath", "parentSchema"];
|
|
92
|
-
var ROOT_SCHEMA_PREFIX =
|
|
92
|
+
var ROOT_SCHEMA_PREFIX = '__rjsf_rootSchema';
|
|
93
93
|
/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.
|
|
94
94
|
*/
|
|
95
95
|
var AJV8Validator = /*#__PURE__*/function () {
|
|
@@ -148,7 +148,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
148
148
|
var path = toPath(property);
|
|
149
149
|
// If the property is at the root (.level1) then toPath creates
|
|
150
150
|
// an empty array element at the first index. Remove it.
|
|
151
|
-
if (path.length > 0 && path[0] ===
|
|
151
|
+
if (path.length > 0 && path[0] === '') {
|
|
152
152
|
path.splice(0, 1);
|
|
153
153
|
}
|
|
154
154
|
if (message) {
|
|
@@ -174,7 +174,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
174
174
|
var errorList = [];
|
|
175
175
|
if (ERRORS_KEY in errorSchema) {
|
|
176
176
|
errorList = errorList.concat(errorSchema[ERRORS_KEY].map(function (message) {
|
|
177
|
-
var property = "." + fieldPath.join(
|
|
177
|
+
var property = "." + fieldPath.join('.');
|
|
178
178
|
return {
|
|
179
179
|
property: property,
|
|
180
180
|
message: message,
|
|
@@ -229,7 +229,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
229
229
|
var _this3 = this;
|
|
230
230
|
return Object.keys(errorHandler).reduce(function (acc, key) {
|
|
231
231
|
var _extends5;
|
|
232
|
-
if (key ===
|
|
232
|
+
if (key === 'addError') {
|
|
233
233
|
return acc;
|
|
234
234
|
} else if (key === ERRORS_KEY) {
|
|
235
235
|
var _extends4;
|
|
@@ -256,24 +256,24 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
256
256
|
parentSchema = e.parentSchema,
|
|
257
257
|
rest = _objectWithoutPropertiesLoose(e, _excluded);
|
|
258
258
|
var _rest$message = rest.message,
|
|
259
|
-
message = _rest$message === void 0 ?
|
|
260
|
-
var property = instancePath.replace(/\//g,
|
|
259
|
+
message = _rest$message === void 0 ? '' : _rest$message;
|
|
260
|
+
var property = instancePath.replace(/\//g, '.');
|
|
261
261
|
var stack = (property + " " + message).trim();
|
|
262
|
-
if (
|
|
262
|
+
if ('missingProperty' in params) {
|
|
263
263
|
property = property ? property + "." + params.missingProperty : params.missingProperty;
|
|
264
264
|
var currentProperty = params.missingProperty;
|
|
265
|
-
var uiSchemaTitle = getUiOptions(get(uiSchema, "" + property.replace(/^\./,
|
|
265
|
+
var uiSchemaTitle = getUiOptions(get(uiSchema, "" + property.replace(/^\./, ''))).title;
|
|
266
266
|
if (uiSchemaTitle) {
|
|
267
267
|
message = message.replace(currentProperty, uiSchemaTitle);
|
|
268
268
|
} else {
|
|
269
|
-
var parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty,
|
|
269
|
+
var parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']);
|
|
270
270
|
if (parentSchemaTitle) {
|
|
271
271
|
message = message.replace(currentProperty, parentSchemaTitle);
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
274
|
stack = message;
|
|
275
275
|
} else {
|
|
276
|
-
var _uiSchemaTitle = getUiOptions(get(uiSchema, "" + property.replace(/^\./,
|
|
276
|
+
var _uiSchemaTitle = getUiOptions(get(uiSchema, "" + property.replace(/^\./, ''))).title;
|
|
277
277
|
if (_uiSchemaTitle) {
|
|
278
278
|
stack = ("'" + _uiSchemaTitle + "' " + message).trim();
|
|
279
279
|
} else {
|
|
@@ -303,8 +303,8 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
303
303
|
_proto.rawValidation = function rawValidation(schema, formData) {
|
|
304
304
|
var compilationError = undefined;
|
|
305
305
|
var compiledValidator;
|
|
306
|
-
if (schema[
|
|
307
|
-
compiledValidator = this.ajv.getSchema(schema[
|
|
306
|
+
if (schema['$id']) {
|
|
307
|
+
compiledValidator = this.ajv.getSchema(schema['$id']);
|
|
308
308
|
}
|
|
309
309
|
try {
|
|
310
310
|
if (compiledValidator === undefined) {
|
|
@@ -316,7 +316,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
316
316
|
}
|
|
317
317
|
var errors;
|
|
318
318
|
if (compiledValidator) {
|
|
319
|
-
if (typeof this.localizer ===
|
|
319
|
+
if (typeof this.localizer === 'function') {
|
|
320
320
|
this.localizer(compiledValidator.errors);
|
|
321
321
|
}
|
|
322
322
|
errors = compiledValidator.errors || undefined;
|
|
@@ -348,7 +348,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
348
348
|
stack: invalidSchemaError.message
|
|
349
349
|
}]);
|
|
350
350
|
}
|
|
351
|
-
if (typeof transformErrors ===
|
|
351
|
+
if (typeof transformErrors === 'function') {
|
|
352
352
|
errors = transformErrors(errors, uiSchema);
|
|
353
353
|
}
|
|
354
354
|
var errorSchema = this.toErrorSchema(errors);
|
|
@@ -359,7 +359,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
359
359
|
}
|
|
360
360
|
});
|
|
361
361
|
}
|
|
362
|
-
if (typeof customValidate !==
|
|
362
|
+
if (typeof customValidate !== 'function') {
|
|
363
363
|
return {
|
|
364
364
|
errors: errors,
|
|
365
365
|
errorSchema: errorSchema
|
|
@@ -384,7 +384,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
384
384
|
for (var key in node) {
|
|
385
385
|
var realObj = node;
|
|
386
386
|
var value = realObj[key];
|
|
387
|
-
if (key === REF_KEY && typeof value ===
|
|
387
|
+
if (key === REF_KEY && typeof value === 'string' && value.startsWith('#')) {
|
|
388
388
|
realObj[key] = ROOT_SCHEMA_PREFIX + value;
|
|
389
389
|
} else {
|
|
390
390
|
realObj[key] = this.withIdRefPrefix(value);
|
|
@@ -414,7 +414,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
414
414
|
*/;
|
|
415
415
|
_proto.isValid = function isValid(schema, formData, rootSchema) {
|
|
416
416
|
var _rootSchema$$id;
|
|
417
|
-
var rootSchemaId = (_rootSchema$$id = rootSchema[
|
|
417
|
+
var rootSchemaId = (_rootSchema$$id = rootSchema['$id']) != null ? _rootSchema$$id : ROOT_SCHEMA_PREFIX;
|
|
418
418
|
try {
|
|
419
419
|
// add the rootSchema ROOT_SCHEMA_PREFIX as id.
|
|
420
420
|
// then rewrite the schema ref's to point to the rootSchema
|
|
@@ -425,8 +425,8 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
425
425
|
}
|
|
426
426
|
var schemaWithIdRefPrefix = this.withIdRefPrefix(schema);
|
|
427
427
|
var compiledValidator;
|
|
428
|
-
if (schemaWithIdRefPrefix[
|
|
429
|
-
compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix[
|
|
428
|
+
if (schemaWithIdRefPrefix['$id']) {
|
|
429
|
+
compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix['$id']);
|
|
430
430
|
}
|
|
431
431
|
if (compiledValidator === undefined) {
|
|
432
432
|
compiledValidator = this.ajv.compile(schemaWithIdRefPrefix);
|
|
@@ -434,7 +434,7 @@ var AJV8Validator = /*#__PURE__*/function () {
|
|
|
434
434
|
var result = compiledValidator(formData);
|
|
435
435
|
return result;
|
|
436
436
|
} catch (e) {
|
|
437
|
-
console.warn(
|
|
437
|
+
console.warn('Error encountered compiling schema:', e);
|
|
438
438
|
return false;
|
|
439
439
|
} finally {
|
|
440
440
|
// TODO: A function should be called if the root schema changes so we don't have to remove and recompile the schema every run.
|