@rjsf/validator-ajv8 5.0.0-beta.5

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.
@@ -0,0 +1,458 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var toPath = require('lodash/toPath');
6
+ var utils = require('@rjsf/utils');
7
+ var Ajv = require('ajv');
8
+ var addFormats = require('ajv-formats');
9
+ var isObject = require('lodash/isObject');
10
+
11
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
+
13
+ var toPath__default = /*#__PURE__*/_interopDefaultLegacy(toPath);
14
+ var Ajv__default = /*#__PURE__*/_interopDefaultLegacy(Ajv);
15
+ var addFormats__default = /*#__PURE__*/_interopDefaultLegacy(addFormats);
16
+ var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
17
+
18
+ const AJV_CONFIG = {
19
+ allErrors: true,
20
+ multipleOfPrecision: 8
21
+ };
22
+ const COLOR_FORMAT_REGEX = /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/;
23
+ const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
24
+ /** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.
25
+ * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the
26
+ * list. If `customFormats` are provided then those additional formats are added to the list of supported formats. If
27
+ * `ajvOptionsOverrides` are provided then they are spread on top of the default `AJV_CONFIG` options when constructing
28
+ * the `Ajv` instance. With Ajv v8, the JSON Schema formats are not provided by default, but can be plugged in. By
29
+ * default, all formats from the `ajv-formats` library are added. To disable this capability, set the `ajvFormatOptions`
30
+ * parameter to `false`. Additionally, you can configure the `ajv-formats` by providing a custom set of
31
+ * [format options](https://github.com/ajv-validator/ajv-formats) to the `ajvFormatOptions` parameter.
32
+ *
33
+ * @param [additionalMetaSchemas] - The list of additional meta schemas that the validator can access
34
+ * @param [customFormats] - The set of additional custom formats that the validator will support
35
+ * @param [ajvOptionsOverrides={}] - The set of validator config override options
36
+ * @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it
37
+ */
38
+
39
+ function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions) {
40
+ if (ajvOptionsOverrides === void 0) {
41
+ ajvOptionsOverrides = {};
42
+ }
43
+
44
+ const ajv = new Ajv__default["default"]({ ...AJV_CONFIG,
45
+ ...ajvOptionsOverrides
46
+ });
47
+
48
+ if (typeof ajvFormatOptions !== "boolean") {
49
+ addFormats__default["default"](ajv, ajvFormatOptions);
50
+ } // add custom formats
51
+
52
+
53
+ ajv.addFormat("data-url", DATA_URL_FORMAT_REGEX);
54
+ ajv.addFormat("color", COLOR_FORMAT_REGEX); // add more schemas to validate against
55
+
56
+ if (Array.isArray(additionalMetaSchemas)) {
57
+ ajv.addMetaSchema(additionalMetaSchemas);
58
+ } // add more custom formats to validate against
59
+
60
+
61
+ if (isObject__default["default"](customFormats)) {
62
+ Object.keys(customFormats).forEach(formatName => {
63
+ ajv.addFormat(formatName, customFormats[formatName]);
64
+ });
65
+ }
66
+
67
+ return ajv;
68
+ }
69
+
70
+ const ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
71
+ /** `ValidatorType` implementation that uses the AJV 8 validation mechanism.
72
+ */
73
+
74
+ class AJV8Validator {
75
+ /** The AJV instance to use for all validations
76
+ *
77
+ * @private
78
+ */
79
+
80
+ /** Constructs an `AJV8Validator` instance using the `options`
81
+ *
82
+ * @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance
83
+ */
84
+ constructor(options) {
85
+ this.ajv = void 0;
86
+ const {
87
+ additionalMetaSchemas,
88
+ customFormats,
89
+ ajvOptionsOverrides,
90
+ ajvFormatOptions
91
+ } = options;
92
+ this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions);
93
+ }
94
+ /** Transforms a ajv validation errors list:
95
+ * [
96
+ * {property: '.level1.level2[2].level3', message: 'err a'},
97
+ * {property: '.level1.level2[2].level3', message: 'err b'},
98
+ * {property: '.level1.level2[4].level3', message: 'err b'},
99
+ * ]
100
+ * Into an error tree:
101
+ * {
102
+ * level1: {
103
+ * level2: {
104
+ * 2: {level3: {errors: ['err a', 'err b']}},
105
+ * 4: {level3: {errors: ['err b']}},
106
+ * }
107
+ * }
108
+ * };
109
+ *
110
+ * @param errors - The list of RJSFValidationError objects
111
+ * @private
112
+ */
113
+
114
+
115
+ toErrorSchema(errors) {
116
+ if (!errors.length) {
117
+ return {};
118
+ }
119
+
120
+ return errors.reduce((errorSchema, error) => {
121
+ const {
122
+ property,
123
+ message
124
+ } = error;
125
+ const path = toPath__default["default"](property);
126
+ let parent = errorSchema; // If the property is at the root (.level1) then toPath creates
127
+ // an empty array element at the first index. Remove it.
128
+
129
+ if (path.length > 0 && path[0] === "") {
130
+ path.splice(0, 1);
131
+ }
132
+
133
+ for (const segment of path.slice(0)) {
134
+ if (!(segment in parent)) {
135
+ parent[segment] = {};
136
+ }
137
+
138
+ parent = parent[segment];
139
+ }
140
+
141
+ if (Array.isArray(parent.__errors)) {
142
+ // We store the list of errors for this node in a property named __errors
143
+ // to avoid name collision with a possible sub schema field named
144
+ // 'errors' (see `validate.createErrorHandler`).
145
+ parent.__errors = parent.__errors.concat(message);
146
+ } else {
147
+ if (message) {
148
+ parent.__errors = [message];
149
+ }
150
+ }
151
+
152
+ return errorSchema;
153
+ }, {});
154
+ }
155
+ /** Converts an `errorSchema` into a list of `RJSFValidationErrors`
156
+ *
157
+ * @param errorSchema - The `ErrorSchema` instance to convert
158
+ * @param [fieldPath=[]] - The current field path, defaults to [] if not specified
159
+ */
160
+
161
+
162
+ toErrorList(errorSchema, fieldPath) {
163
+ if (fieldPath === void 0) {
164
+ fieldPath = [];
165
+ }
166
+
167
+ if (!errorSchema) {
168
+ return [];
169
+ }
170
+
171
+ let errorList = [];
172
+
173
+ if (utils.ERRORS_KEY in errorSchema) {
174
+ errorList = errorList.concat(errorSchema.__errors.map(message => {
175
+ const property = "." + fieldPath.join(".");
176
+ return {
177
+ property,
178
+ message,
179
+ stack: property + " " + message
180
+ };
181
+ }));
182
+ }
183
+
184
+ return Object.keys(errorSchema).reduce((acc, key) => {
185
+ if (key !== utils.ERRORS_KEY) {
186
+ acc = acc.concat(this.toErrorList(errorSchema[key], [...fieldPath, key]));
187
+ }
188
+
189
+ return acc;
190
+ }, errorList);
191
+ }
192
+ /** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it
193
+ *
194
+ * @param formData - The form data around which the error handler is created
195
+ * @private
196
+ */
197
+
198
+
199
+ createErrorHandler(formData) {
200
+ const handler = {
201
+ // We store the list of errors for this node in a property named __errors
202
+ // to avoid name collision with a possible sub schema field named
203
+ // 'errors' (see `utils.toErrorSchema`).
204
+ __errors: [],
205
+
206
+ addError(message) {
207
+ this.__errors.push(message);
208
+ }
209
+
210
+ };
211
+
212
+ if (utils.isObject(formData)) {
213
+ const formObject = formData;
214
+ return Object.keys(formObject).reduce((acc, key) => {
215
+ return { ...acc,
216
+ [key]: this.createErrorHandler(formObject[key])
217
+ };
218
+ }, handler);
219
+ }
220
+
221
+ if (Array.isArray(formData)) {
222
+ return formData.reduce((acc, value, key) => {
223
+ return { ...acc,
224
+ [key]: this.createErrorHandler(value)
225
+ };
226
+ }, handler);
227
+ }
228
+
229
+ return handler;
230
+ }
231
+ /** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError` functions from it
232
+ *
233
+ * @param errorHandler - The `FormValidation` error handling structure
234
+ * @private
235
+ */
236
+
237
+
238
+ unwrapErrorHandler(errorHandler) {
239
+ return Object.keys(errorHandler).reduce((acc, key) => {
240
+ if (key === "addError") {
241
+ return acc;
242
+ } else if (key === utils.ERRORS_KEY) {
243
+ return { ...acc,
244
+ [key]: errorHandler[key]
245
+ };
246
+ }
247
+
248
+ return { ...acc,
249
+ [key]: this.unwrapErrorHandler(errorHandler[key])
250
+ };
251
+ }, {});
252
+ }
253
+ /** Transforming the error output from ajv to format used by @rjsf/utils.
254
+ * At some point, components should be updated to support ajv.
255
+ *
256
+ * @param errors - The list of AJV errors to convert to `RJSFValidationErrors`
257
+ * @private
258
+ */
259
+
260
+
261
+ transformRJSFValidationErrors(errors) {
262
+ if (errors === void 0) {
263
+ errors = [];
264
+ }
265
+
266
+ if (errors === null) {
267
+ return [];
268
+ }
269
+
270
+ return errors.map(e => {
271
+ const {
272
+ instancePath,
273
+ keyword,
274
+ message,
275
+ params,
276
+ schemaPath
277
+ } = e;
278
+ const property = instancePath.replace(/\//g, "."); // put data in expected format
279
+
280
+ return {
281
+ name: keyword,
282
+ property,
283
+ message,
284
+ params,
285
+ stack: (property + " " + message).trim(),
286
+ schemaPath
287
+ };
288
+ });
289
+ }
290
+ /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
291
+ * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
292
+ * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and
293
+ * transform them in what ever way it chooses.
294
+ *
295
+ * @param formData - The form data to validate
296
+ * @param schema - The schema against which to validate the form data
297
+ * @param [customValidate] - An optional function that is used to perform custom validation
298
+ * @param [transformErrors] - An optional function that is used to transform errors after AJV validation
299
+ */
300
+
301
+
302
+ validateFormData(formData, schema, customValidate, transformErrors) {
303
+ // Include form data with undefined values, which is required for validation.
304
+ const rootSchema = schema;
305
+ const newFormData = utils.getDefaultFormState(this, schema, formData, rootSchema, true);
306
+ let validationError = null;
307
+
308
+ try {
309
+ this.ajv.validate(schema, newFormData);
310
+ } catch (err) {
311
+ validationError = err;
312
+ }
313
+
314
+ let errors = this.transformRJSFValidationErrors(this.ajv.errors); // Clear errors to prevent persistent errors, see #1104
315
+
316
+ this.ajv.errors = null;
317
+ const noProperMetaSchema = validationError && validationError.message && typeof validationError.message === "string" && validationError.message.includes("no schema with key or ref ");
318
+
319
+ if (noProperMetaSchema) {
320
+ errors = [...errors, {
321
+ stack: validationError.message
322
+ }];
323
+ }
324
+
325
+ if (typeof transformErrors === "function") {
326
+ errors = transformErrors(errors);
327
+ }
328
+
329
+ let errorSchema = this.toErrorSchema(errors);
330
+
331
+ if (noProperMetaSchema) {
332
+ errorSchema = { ...errorSchema,
333
+ ...{
334
+ $schema: {
335
+ __errors: [validationError.message]
336
+ }
337
+ }
338
+ };
339
+ }
340
+
341
+ if (typeof customValidate !== "function") {
342
+ return {
343
+ errors,
344
+ errorSchema
345
+ };
346
+ }
347
+
348
+ const errorHandler = customValidate(newFormData, this.createErrorHandler(newFormData));
349
+ const userErrorSchema = this.unwrapErrorHandler(errorHandler);
350
+ return utils.mergeValidationData(this, {
351
+ errors,
352
+ errorSchema
353
+ }, userErrorSchema);
354
+ }
355
+ /** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling
356
+ * `withIdRefPrefix` for any other elements.
357
+ *
358
+ * @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
359
+ * @private
360
+ */
361
+
362
+
363
+ withIdRefPrefixObject(node) {
364
+ for (const key in node) {
365
+ const realObj = node;
366
+ const value = realObj[key];
367
+
368
+ if (key === utils.REF_KEY && typeof value === "string" && value.startsWith("#")) {
369
+ realObj[key] = ROOT_SCHEMA_PREFIX + value;
370
+ } else {
371
+ realObj[key] = this.withIdRefPrefix(value);
372
+ }
373
+ }
374
+
375
+ return node;
376
+ }
377
+ /** Takes a `node` object list and transforms any contained `$ref` node variables with a prefix, recursively calling
378
+ * `withIdRefPrefix` for any other elements.
379
+ *
380
+ * @param nodeThe - list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
381
+ * @private
382
+ */
383
+
384
+
385
+ withIdRefPrefixArray(node) {
386
+ for (let i = 0; i < node.length; i++) {
387
+ node[i] = this.withIdRefPrefix(node[i]);
388
+ }
389
+
390
+ return node;
391
+ }
392
+ /** Validates data against a schema, returning true if the data is valid, or
393
+ * false otherwise. If the schema is invalid, then this function will return
394
+ * false.
395
+ *
396
+ * @param schema - The schema against which to validate the form data * @param schema
397
+ * @param formData- - The form data to validate
398
+ * @param rootSchema - The root schema used to provide $ref resolutions
399
+ */
400
+
401
+
402
+ isValid(schema, formData, rootSchema) {
403
+ try {
404
+ // add the rootSchema ROOT_SCHEMA_PREFIX as id.
405
+ // then rewrite the schema ref's to point to the rootSchema
406
+ // this accounts for the case where schema have references to models
407
+ // that lives in the rootSchema but not in the schema in question.
408
+ const result = this.ajv.addSchema(rootSchema, ROOT_SCHEMA_PREFIX).validate(this.withIdRefPrefix(schema), formData);
409
+ return result;
410
+ } catch (e) {
411
+ return false;
412
+ } finally {
413
+ // make sure we remove the rootSchema from the global ajv instance
414
+ this.ajv.removeSchema(ROOT_SCHEMA_PREFIX);
415
+ }
416
+ }
417
+ /** Recursively prefixes all $ref's in a schema with `ROOT_SCHEMA_PREFIX`
418
+ * This is used in isValid to make references to the rootSchema
419
+ *
420
+ * @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
421
+ * @protected
422
+ */
423
+
424
+
425
+ withIdRefPrefix(schemaNode) {
426
+ if (schemaNode.constructor === Object) {
427
+ return this.withIdRefPrefixObject({ ...schemaNode
428
+ });
429
+ }
430
+
431
+ if (Array.isArray(schemaNode)) {
432
+ return this.withIdRefPrefixArray([...schemaNode]);
433
+ }
434
+
435
+ return schemaNode;
436
+ }
437
+
438
+ }
439
+
440
+ /** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if
441
+ * provided.
442
+ *
443
+ * @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance
444
+ */
445
+
446
+ function customizeValidator(options) {
447
+ if (options === void 0) {
448
+ options = {};
449
+ }
450
+
451
+ return new AJV8Validator(options);
452
+ }
453
+
454
+ var index = /*#__PURE__*/customizeValidator();
455
+
456
+ exports.customizeValidator = customizeValidator;
457
+ exports["default"] = index;
458
+ //# sourceMappingURL=validator-ajv8.cjs.development.js.map
@@ -0,0 +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\";\n\nexport const AJV_CONFIG: Options = {\n allErrors: true,\n multipleOfPrecision: 8,\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 */\nexport default function createAjvInstance(\n additionalMetaSchemas?: CustomValidatorOptionsType[\"additionalMetaSchemas\"],\n customFormats?: CustomValidatorOptionsType[\"customFormats\"],\n ajvOptionsOverrides: CustomValidatorOptionsType[\"ajvOptionsOverrides\"] = {},\n ajvFormatOptions?: FormatsPluginOptions | false\n) {\n const ajv = new Ajv({ ...AJV_CONFIG, ...ajvOptionsOverrides });\n if (typeof ajvFormatOptions !== \"boolean\") {\n addFormats(ajv, ajvFormatOptions);\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 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 } from \"ajv\";\nimport toPath from \"lodash/toPath\";\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FieldValidation,\n FormValidation,\n GenericObjectType,\n RJSFSchema,\n RJSFValidationError,\n ValidationData,\n ValidatorType,\n getDefaultFormState,\n isObject,\n mergeValidationData,\n ERRORS_KEY,\n REF_KEY,\n} from \"@rjsf/utils\";\n\nimport { CustomValidatorOptionsType } 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> implements ValidatorType<T> {\n /** The AJV instance to use for all validations\n *\n * @private\n */\n private ajv: Ajv;\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 */\n constructor(options: CustomValidatorOptionsType) {\n const {\n additionalMetaSchemas,\n customFormats,\n ajvOptionsOverrides,\n ajvFormatOptions,\n } = options;\n this.ajv = createAjvInstance(\n additionalMetaSchemas,\n customFormats,\n ajvOptionsOverrides,\n ajvFormatOptions\n );\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 if (!errors.length) {\n return {} as ErrorSchema<T>;\n }\n return errors.reduce(\n (errorSchema: ErrorSchema<T>, error): ErrorSchema<T> => {\n const { property, message } = error;\n const path = toPath(property);\n let parent: GenericObjectType = errorSchema;\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\n for (const segment of path.slice(0)) {\n if (!(segment in parent)) {\n parent[segment] = {};\n }\n parent = parent[segment];\n }\n\n if (Array.isArray(parent.__errors)) {\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 `validate.createErrorHandler`).\n parent.__errors = parent.__errors.concat(message!);\n } else {\n if (message) {\n parent.__errors = [message];\n }\n }\n return errorSchema;\n },\n {} as ErrorSchema<T>\n );\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!.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 (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 if (Array.isArray(formData)) {\n return formData.reduce((acc, value, key) => {\n return { ...acc, [key]: this.createErrorHandler(value) };\n }, handler);\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 * @private\n */\n private transformRJSFValidationErrors(\n errors: Ajv[\"errors\"] = []\n ): RJSFValidationError[] {\n if (errors === null) {\n return [];\n }\n\n return errors.map((e: ErrorObject) => {\n const { instancePath, keyword, message, params, schemaPath } = e;\n const property = instancePath.replace(/\\//g, \".\");\n\n // put data in expected format\n return {\n name: keyword,\n property,\n message,\n params, // specific to ajv\n stack: `${property} ${message}`.trim(),\n schemaPath,\n };\n });\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param 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 */\n validateFormData(\n formData: T,\n schema: RJSFSchema,\n customValidate?: CustomValidator<T>,\n transformErrors?: ErrorTransformer\n ): ValidationData<T> {\n // Include form data with undefined values, which is required for validation.\n const rootSchema = schema;\n const newFormData = getDefaultFormState<T>(\n this,\n schema,\n formData,\n rootSchema,\n true\n ) as T;\n\n let validationError: Error | null = null;\n try {\n this.ajv.validate(schema, newFormData);\n } catch (err) {\n validationError = err as Error;\n }\n\n let errors = this.transformRJSFValidationErrors(this.ajv.errors);\n // Clear errors to prevent persistent errors, see #1104\n\n this.ajv.errors = null;\n\n const noProperMetaSchema =\n validationError &&\n validationError.message &&\n typeof validationError.message === \"string\" &&\n validationError.message.includes(\"no schema with key or ref \");\n\n if (noProperMetaSchema) {\n errors = [...errors, { stack: validationError!.message }];\n }\n if (typeof transformErrors === \"function\") {\n errors = transformErrors(errors);\n }\n\n let errorSchema = this.toErrorSchema(errors);\n\n if (noProperMetaSchema) {\n errorSchema = {\n ...errorSchema,\n ...{\n $schema: {\n __errors: [validationError!.message],\n },\n },\n };\n }\n\n if (typeof customValidate !== \"function\") {\n return { errors, errorSchema };\n }\n\n const errorHandler = customValidate(\n newFormData,\n this.createErrorHandler(newFormData)\n );\n const userErrorSchema = this.unwrapErrorHandler(errorHandler);\n return mergeValidationData<T>(\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: object) {\n for (const key in node) {\n const realObj: { [k: string]: any } = 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 nodeThe - 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: object[]): RJSFSchema {\n for (let i = 0; i < node.length; i++) {\n node[i] = this.withIdRefPrefix(node[i]);\n }\n return node as RJSFSchema;\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 * @param schema\n * @param formData- - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n */\n isValid(schema: RJSFSchema, formData: T, rootSchema: RJSFSchema) {\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 const result = this.ajv\n .addSchema(rootSchema, ROOT_SCHEMA_PREFIX)\n .validate(this.withIdRefPrefix(schema), formData);\n return result as boolean;\n } catch (e) {\n return false;\n } finally {\n // make sure we remove the rootSchema from the global ajv instance\n this.ajv.removeSchema(ROOT_SCHEMA_PREFIX);\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: RJSFSchema): RJSFSchema {\n if (schemaNode.constructor === Object) {\n return this.withIdRefPrefixObject({ ...schemaNode });\n }\n if (Array.isArray(schemaNode)) {\n return this.withIdRefPrefixArray([...schemaNode]);\n }\n return schemaNode;\n }\n}\n","import { ValidatorType } from \"@rjsf/utils\";\n\nimport { CustomValidatorOptionsType } 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 */\nexport default function customizeValidator<T = any>(\n options: CustomValidatorOptionsType = {}\n): ValidatorType<T> {\n return new AJV8Validator<T>(options);\n}\n","import customizeValidator from \"./customizeValidator\";\n\nexport { customizeValidator };\nexport * from \"./types\";\n\nexport default customizeValidator();\n"],"names":["AJV_CONFIG","allErrors","multipleOfPrecision","COLOR_FORMAT_REGEX","DATA_URL_FORMAT_REGEX","createAjvInstance","additionalMetaSchemas","customFormats","ajvOptionsOverrides","ajvFormatOptions","ajv","Ajv","addFormats","addFormat","Array","isArray","addMetaSchema","isObject","Object","keys","forEach","formatName","ROOT_SCHEMA_PREFIX","AJV8Validator","constructor","options","toErrorSchema","errors","length","reduce","errorSchema","error","property","message","path","toPath","parent","splice","segment","slice","__errors","concat","toErrorList","fieldPath","errorList","ERRORS_KEY","map","join","stack","acc","key","createErrorHandler","formData","handler","addError","push","formObject","value","unwrapErrorHandler","errorHandler","transformRJSFValidationErrors","e","instancePath","keyword","params","schemaPath","replace","name","trim","validateFormData","schema","customValidate","transformErrors","rootSchema","newFormData","getDefaultFormState","validationError","validate","err","noProperMetaSchema","includes","$schema","userErrorSchema","mergeValidationData","withIdRefPrefixObject","node","realObj","REF_KEY","startsWith","withIdRefPrefix","withIdRefPrefixArray","i","isValid","result","addSchema","removeSchema","schemaNode","customizeValidator"],"mappings":";;;;;;;;;;;;;;;;;AAMO,MAAMA,UAAU,GAAY;AACjCC,EAAAA,SAAS,EAAE,IADsB;AAEjCC,EAAAA,mBAAmB,EAAE,CAAA;AAFY,CAA5B,CAAA;AAIA,MAAMC,kBAAkB,GAC7B,4YADK,CAAA;AAEA,MAAMC,qBAAqB,GAChC,2DADK,CAAA;AAGP;;;;;;;;;;;;;AAaG;;AACqB,SAAAC,iBAAA,CACtBC,qBADsB,EAEtBC,aAFsB,EAGtBC,mBAHsB,EAItBC,gBAJsB,EAIyB;AAAA,EAAA,IAD/CD,mBAC+C,KAAA,KAAA,CAAA,EAAA;AAD/CA,IAAAA,mBAC+C,GAD0B,EAC1B,CAAA;AAAA,GAAA;;AAE/C,EAAA,MAAME,GAAG,GAAG,IAAIC,uBAAJ,CAAQ,EAAE,GAAGX,UAAL;IAAiB,GAAGQ,mBAAAA;AAApB,GAAR,CAAZ,CAAA;;AACA,EAAA,IAAI,OAAOC,gBAAP,KAA4B,SAAhC,EAA2C;AACzCG,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0});var r=require("lodash/toPath"),e=require("@rjsf/utils"),t=require("ajv"),a=require("ajv-formats"),s=require("lodash/isObject");function o(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var i=o(r),n=o(t),c=o(a),d=o(s);const l={allErrors:!0,multipleOfPrecision:8},u=/^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/,h=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;class f{constructor(r){this.ajv=void 0;const{additionalMetaSchemas:e,customFormats:t,ajvOptionsOverrides:a,ajvFormatOptions:s}=r;this.ajv=function(r,e,t,a){void 0===t&&(t={});const s=new n.default({...l,...t});return"boolean"!=typeof a&&c.default(s,a),s.addFormat("data-url",h),s.addFormat("color",u),Array.isArray(r)&&s.addMetaSchema(r),d.default(e)&&Object.keys(e).forEach((r=>{s.addFormat(r,e[r])})),s}(e,t,a,s)}toErrorSchema(r){return r.length?r.reduce(((r,e)=>{const{property:t,message:a}=e,s=i.default(t);let o=r;s.length>0&&""===s[0]&&s.splice(0,1);for(const r of s.slice(0))r in o||(o[r]={}),o=o[r];return Array.isArray(o.__errors)?o.__errors=o.__errors.concat(a):a&&(o.__errors=[a]),r}),{}):{}}toErrorList(r,t){if(void 0===t&&(t=[]),!r)return[];let a=[];return e.ERRORS_KEY in r&&(a=a.concat(r.__errors.map((r=>{const e="."+t.join(".");return{property:e,message:r,stack:e+" "+r}})))),Object.keys(r).reduce(((a,s)=>(s!==e.ERRORS_KEY&&(a=a.concat(this.toErrorList(r[s],[...t,s]))),a)),a)}createErrorHandler(r){const t={__errors:[],addError(r){this.__errors.push(r)}};if(e.isObject(r)){const e=r;return Object.keys(e).reduce(((r,t)=>({...r,[t]:this.createErrorHandler(e[t])})),t)}return Array.isArray(r)?r.reduce(((r,e,t)=>({...r,[t]:this.createErrorHandler(e)})),t):t}unwrapErrorHandler(r){return Object.keys(r).reduce(((t,a)=>"addError"===a?t:a===e.ERRORS_KEY?{...t,[a]:r[a]}:{...t,[a]:this.unwrapErrorHandler(r[a])}),{})}transformRJSFValidationErrors(r){return void 0===r&&(r=[]),null===r?[]:r.map((r=>{const{instancePath:e,keyword:t,message:a,params:s,schemaPath:o}=r,i=e.replace(/\//g,".");return{name:t,property:i,message:a,params:s,stack:(i+" "+a).trim(),schemaPath:o}}))}validateFormData(r,t,a,s){const o=e.getDefaultFormState(this,t,r,t,!0);let i=null;try{this.ajv.validate(t,o)}catch(r){i=r}let n=this.transformRJSFValidationErrors(this.ajv.errors);this.ajv.errors=null;const c=i&&i.message&&"string"==typeof i.message&&i.message.includes("no schema with key or ref ");c&&(n=[...n,{stack:i.message}]),"function"==typeof s&&(n=s(n));let d=this.toErrorSchema(n);if(c&&(d={...d,$schema:{__errors:[i.message]}}),"function"!=typeof a)return{errors:n,errorSchema:d};const l=a(o,this.createErrorHandler(o)),u=this.unwrapErrorHandler(l);return e.mergeValidationData(this,{errors:n,errorSchema:d},u)}withIdRefPrefixObject(r){for(const t in r){const a=r[t];r[t]=t===e.REF_KEY&&"string"==typeof a&&a.startsWith("#")?"__rjsf_rootSchema"+a:this.withIdRefPrefix(a)}return r}withIdRefPrefixArray(r){for(let e=0;e<r.length;e++)r[e]=this.withIdRefPrefix(r[e]);return r}isValid(r,e,t){try{return this.ajv.addSchema(t,"__rjsf_rootSchema").validate(this.withIdRefPrefix(r),e)}catch(r){return!1}finally{this.ajv.removeSchema("__rjsf_rootSchema")}}withIdRefPrefix(r){return r.constructor===Object?this.withIdRefPrefixObject({...r}):Array.isArray(r)?this.withIdRefPrefixArray([...r]):r}}function m(r){return void 0===r&&(r={}),new f(r)}var y=m();exports.customizeValidator=m,exports.default=y;
2
+ //# sourceMappingURL=validator-ajv8.cjs.production.min.js.map
@@ -0,0 +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\";\n\nexport const AJV_CONFIG: Options = {\n allErrors: true,\n multipleOfPrecision: 8,\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 */\nexport default function createAjvInstance(\n additionalMetaSchemas?: CustomValidatorOptionsType[\"additionalMetaSchemas\"],\n customFormats?: CustomValidatorOptionsType[\"customFormats\"],\n ajvOptionsOverrides: CustomValidatorOptionsType[\"ajvOptionsOverrides\"] = {},\n ajvFormatOptions?: FormatsPluginOptions | false\n) {\n const ajv = new Ajv({ ...AJV_CONFIG, ...ajvOptionsOverrides });\n if (typeof ajvFormatOptions !== \"boolean\") {\n addFormats(ajv, ajvFormatOptions);\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 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 } from \"ajv\";\nimport toPath from \"lodash/toPath\";\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FieldValidation,\n FormValidation,\n GenericObjectType,\n RJSFSchema,\n RJSFValidationError,\n ValidationData,\n ValidatorType,\n getDefaultFormState,\n isObject,\n mergeValidationData,\n ERRORS_KEY,\n REF_KEY,\n} from \"@rjsf/utils\";\n\nimport { CustomValidatorOptionsType } 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> implements ValidatorType<T> {\n /** The AJV instance to use for all validations\n *\n * @private\n */\n private ajv: Ajv;\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 */\n constructor(options: CustomValidatorOptionsType) {\n const {\n additionalMetaSchemas,\n customFormats,\n ajvOptionsOverrides,\n ajvFormatOptions,\n } = options;\n this.ajv = createAjvInstance(\n additionalMetaSchemas,\n customFormats,\n ajvOptionsOverrides,\n ajvFormatOptions\n );\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 if (!errors.length) {\n return {} as ErrorSchema<T>;\n }\n return errors.reduce(\n (errorSchema: ErrorSchema<T>, error): ErrorSchema<T> => {\n const { property, message } = error;\n const path = toPath(property);\n let parent: GenericObjectType = errorSchema;\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\n for (const segment of path.slice(0)) {\n if (!(segment in parent)) {\n parent[segment] = {};\n }\n parent = parent[segment];\n }\n\n if (Array.isArray(parent.__errors)) {\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 `validate.createErrorHandler`).\n parent.__errors = parent.__errors.concat(message!);\n } else {\n if (message) {\n parent.__errors = [message];\n }\n }\n return errorSchema;\n },\n {} as ErrorSchema<T>\n );\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!.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 (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 if (Array.isArray(formData)) {\n return formData.reduce((acc, value, key) => {\n return { ...acc, [key]: this.createErrorHandler(value) };\n }, handler);\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 * @private\n */\n private transformRJSFValidationErrors(\n errors: Ajv[\"errors\"] = []\n ): RJSFValidationError[] {\n if (errors === null) {\n return [];\n }\n\n return errors.map((e: ErrorObject) => {\n const { instancePath, keyword, message, params, schemaPath } = e;\n const property = instancePath.replace(/\\//g, \".\");\n\n // put data in expected format\n return {\n name: keyword,\n property,\n message,\n params, // specific to ajv\n stack: `${property} ${message}`.trim(),\n schemaPath,\n };\n });\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param 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 */\n validateFormData(\n formData: T,\n schema: RJSFSchema,\n customValidate?: CustomValidator<T>,\n transformErrors?: ErrorTransformer\n ): ValidationData<T> {\n // Include form data with undefined values, which is required for validation.\n const rootSchema = schema;\n const newFormData = getDefaultFormState<T>(\n this,\n schema,\n formData,\n rootSchema,\n true\n ) as T;\n\n let validationError: Error | null = null;\n try {\n this.ajv.validate(schema, newFormData);\n } catch (err) {\n validationError = err as Error;\n }\n\n let errors = this.transformRJSFValidationErrors(this.ajv.errors);\n // Clear errors to prevent persistent errors, see #1104\n\n this.ajv.errors = null;\n\n const noProperMetaSchema =\n validationError &&\n validationError.message &&\n typeof validationError.message === \"string\" &&\n validationError.message.includes(\"no schema with key or ref \");\n\n if (noProperMetaSchema) {\n errors = [...errors, { stack: validationError!.message }];\n }\n if (typeof transformErrors === \"function\") {\n errors = transformErrors(errors);\n }\n\n let errorSchema = this.toErrorSchema(errors);\n\n if (noProperMetaSchema) {\n errorSchema = {\n ...errorSchema,\n ...{\n $schema: {\n __errors: [validationError!.message],\n },\n },\n };\n }\n\n if (typeof customValidate !== \"function\") {\n return { errors, errorSchema };\n }\n\n const errorHandler = customValidate(\n newFormData,\n this.createErrorHandler(newFormData)\n );\n const userErrorSchema = this.unwrapErrorHandler(errorHandler);\n return mergeValidationData<T>(\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: object) {\n for (const key in node) {\n const realObj: { [k: string]: any } = 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 nodeThe - 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: object[]): RJSFSchema {\n for (let i = 0; i < node.length; i++) {\n node[i] = this.withIdRefPrefix(node[i]);\n }\n return node as RJSFSchema;\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 * @param schema\n * @param formData- - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n */\n isValid(schema: RJSFSchema, formData: T, rootSchema: RJSFSchema) {\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 const result = this.ajv\n .addSchema(rootSchema, ROOT_SCHEMA_PREFIX)\n .validate(this.withIdRefPrefix(schema), formData);\n return result as boolean;\n } catch (e) {\n return false;\n } finally {\n // make sure we remove the rootSchema from the global ajv instance\n this.ajv.removeSchema(ROOT_SCHEMA_PREFIX);\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: RJSFSchema): RJSFSchema {\n if (schemaNode.constructor === Object) {\n return this.withIdRefPrefixObject({ ...schemaNode });\n }\n if (Array.isArray(schemaNode)) {\n return this.withIdRefPrefixArray([...schemaNode]);\n }\n return schemaNode;\n }\n}\n","import { ValidatorType } from \"@rjsf/utils\";\n\nimport { CustomValidatorOptionsType } 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 */\nexport default function customizeValidator<T = any>(\n options: CustomValidatorOptionsType = {}\n): ValidatorType<T> {\n return new AJV8Validator<T>(options);\n}\n","import customizeValidator from \"./customizeValidator\";\n\nexport { customizeValidator };\nexport * from \"./types\";\n\nexport default customizeValidator();\n"],"names":["AJV_CONFIG","allErrors","multipleOfPrecision","COLOR_FORMAT_REGEX","DATA_URL_FORMAT_REGEX","AJV8Validator","constructor","options","this","ajv","additionalMetaSchemas","customFormats","ajvOptionsOverrides","ajvFormatOptions","Ajv","addFormats","addFormat","Array","isArray","addMetaSchema","isObject","Object","keys","forEach","formatName","createAjvInstance","toErrorSchema","errors","length","reduce","errorSchema","error","property","message","path","toPath","parent","splice","segment","slice","__errors","concat","toErrorList","fieldPath","errorList","ERRORS_KEY","map","join","stack","acc","key","createErrorHandler","formData","handler","addError","push","formObject","value","unwrapErrorHandler","errorHandler","transformRJSFValidationErrors","e","instancePath","keyword","params","schemaPath","replace","name","trim","validateFormData","schema","customValidate","transformErrors","newFormData","getDefaultFormState","validationError","validate","err","noProperMetaSchema","includes","$schema","userErrorSchema","mergeValidationData","withIdRefPrefixObject","node","REF_KEY","startsWith","withIdRefPrefix","withIdRefPrefixArray","i","isValid","rootSchema","addSchema","removeSchema","schemaNode","customizeValidator","index"],"mappings":"2SAMO,MAAMA,EAAsB,CACjCC,WAAW,EACXC,oBAAqB,GAEVC,EACX,6YACWC,EACX,4DCcY,MAAOC,EAWnBC,YAAYC,GAAmCC,KANvCC,SAMuC,EAC7C,MAAMC,sBACJA,EADIC,cAEJA,EAFIC,oBAGJA,EAHIC,iBAIJA,GACEN,EACJC,KAAKC,IDhBe,SACtBC,EACAC,EACAC,EACAC,QAA+C,IAD/CD,IAAAA,EAAyE,CAAA,GAGzE,MAAMH,EAAM,IAAIK,UAAI,IAAKd,KAAeY,IAqBxC,MApBgC,kBAArBC,GACTE,UAAWN,EAAKI,GAIlBJ,EAAIO,UAAU,WAAYZ,GAC1BK,EAAIO,UAAU,QAASb,GAGnBc,MAAMC,QAAQR,IAChBD,EAAIU,cAAcT,GAIhBU,EAAAA,QAAST,IACXU,OAAOC,KAAKX,GAAeY,SAASC,IAClCf,EAAIO,UAAUQ,EAAYb,EAAca,GAAxC,IAIGf,CACR,CCZcgB,CACTf,EACAC,EACAC,EACAC,EAEH,CAqBOa,cAAcC,GACpB,OAAKA,EAAOC,OAGLD,EAAOE,QACZ,CAACC,EAA6BC,KAC5B,MAAMC,SAAEA,EAAFC,QAAYA,GAAYF,EACxBG,EAAOC,UAAOH,GACpB,IAAII,EAA4BN,EAI5BI,EAAKN,OAAS,GAAiB,KAAZM,EAAK,IAC1BA,EAAKG,OAAO,EAAG,GAGjB,IA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