@rjsf/validator-ajv8 5.0.0-beta.11 → 5.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +6 -4
- package/dist/validator-ajv8.cjs.development.js +77 -114
- package/dist/validator-ajv8.cjs.development.js.map +1 -1
- package/dist/validator-ajv8.cjs.production.min.js +1 -1
- package/dist/validator-ajv8.cjs.production.min.js.map +1 -1
- package/dist/validator-ajv8.esm.js +76 -114
- package/dist/validator-ajv8.esm.js.map +1 -1
- package/dist/validator-ajv8.umd.development.js +79 -117
- package/dist/validator-ajv8.umd.development.js.map +1 -1
- package/dist/validator-ajv8.umd.production.min.js +1 -1
- package/dist/validator-ajv8.umd.production.min.js.map +1 -1
- package/package.json +11 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _rjsf_utils from '@rjsf/utils';
|
|
2
|
-
import { ValidatorType } from '@rjsf/utils';
|
|
3
|
-
import { Options, ErrorObject } from 'ajv';
|
|
2
|
+
import { StrictRJSFSchema, RJSFSchema, ValidatorType } from '@rjsf/utils';
|
|
3
|
+
import Ajv, { Options, ErrorObject } from 'ajv';
|
|
4
4
|
import { FormatsPluginOptions } from 'ajv-formats';
|
|
5
5
|
|
|
6
6
|
/** The type describing how to customize the AJV6 validator
|
|
@@ -16,6 +16,8 @@ interface CustomValidatorOptionsType {
|
|
|
16
16
|
ajvOptionsOverrides?: Options;
|
|
17
17
|
/** The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it */
|
|
18
18
|
ajvFormatOptions?: FormatsPluginOptions | false;
|
|
19
|
+
/** The AJV class to construct */
|
|
20
|
+
AjvClass?: typeof Ajv;
|
|
19
21
|
}
|
|
20
22
|
/** The type describing a function that takes a list of Ajv `ErrorObject`s and localizes them
|
|
21
23
|
*/
|
|
@@ -27,8 +29,8 @@ declare type Localizer = (errors?: null | ErrorObject[]) => void;
|
|
|
27
29
|
* @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance
|
|
28
30
|
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s
|
|
29
31
|
*/
|
|
30
|
-
declare function customizeValidator<T = any>(options?: CustomValidatorOptionsType, localizer?: Localizer): ValidatorType<T>;
|
|
32
|
+
declare function customizeValidator<T = any, S extends StrictRJSFSchema = RJSFSchema>(options?: CustomValidatorOptionsType, localizer?: Localizer): ValidatorType<T, S>;
|
|
31
33
|
|
|
32
|
-
declare const _default: _rjsf_utils.ValidatorType<any>;
|
|
34
|
+
declare const _default: _rjsf_utils.ValidatorType<any, _rjsf_utils.RJSFSchema>;
|
|
33
35
|
|
|
34
36
|
export { CustomValidatorOptionsType, Localizer, customizeValidator, _default as default };
|
|
@@ -3,17 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var toPath = require('lodash/toPath');
|
|
6
|
+
var isObject = require('lodash/isObject');
|
|
7
|
+
var clone = require('lodash/clone');
|
|
6
8
|
var utils = require('@rjsf/utils');
|
|
7
9
|
var Ajv = require('ajv');
|
|
8
10
|
var addFormats = require('ajv-formats');
|
|
9
|
-
var isObject = require('lodash/isObject');
|
|
10
11
|
|
|
11
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
13
|
|
|
13
14
|
var toPath__default = /*#__PURE__*/_interopDefaultLegacy(toPath);
|
|
15
|
+
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
|
16
|
+
var clone__default = /*#__PURE__*/_interopDefaultLegacy(clone);
|
|
14
17
|
var Ajv__default = /*#__PURE__*/_interopDefaultLegacy(Ajv);
|
|
15
18
|
var addFormats__default = /*#__PURE__*/_interopDefaultLegacy(addFormats);
|
|
16
|
-
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
|
|
17
19
|
|
|
18
20
|
const AJV_CONFIG = {
|
|
19
21
|
allErrors: true,
|
|
@@ -35,42 +37,39 @@ const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base
|
|
|
35
37
|
* @param [ajvOptionsOverrides={}] - The set of validator config override options
|
|
36
38
|
* @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it
|
|
37
39
|
*/
|
|
38
|
-
|
|
39
|
-
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions) {
|
|
40
|
+
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass) {
|
|
40
41
|
if (ajvOptionsOverrides === void 0) {
|
|
41
42
|
ajvOptionsOverrides = {};
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
if (AjvClass === void 0) {
|
|
45
|
+
AjvClass = Ajv__default["default"];
|
|
46
|
+
}
|
|
47
|
+
const ajv = new AjvClass({
|
|
48
|
+
...AJV_CONFIG,
|
|
45
49
|
...ajvOptionsOverrides
|
|
46
50
|
});
|
|
47
|
-
|
|
48
51
|
if (typeof ajvFormatOptions !== "boolean") {
|
|
49
52
|
addFormats__default["default"](ajv, ajvFormatOptions);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
}
|
|
54
|
+
// add custom formats
|
|
53
55
|
ajv.addFormat("data-url", DATA_URL_FORMAT_REGEX);
|
|
54
|
-
ajv.addFormat("color", COLOR_FORMAT_REGEX);
|
|
55
|
-
|
|
56
|
+
ajv.addFormat("color", COLOR_FORMAT_REGEX);
|
|
57
|
+
// add more schemas to validate against
|
|
56
58
|
if (Array.isArray(additionalMetaSchemas)) {
|
|
57
59
|
ajv.addMetaSchema(additionalMetaSchemas);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
}
|
|
61
|
+
// add more custom formats to validate against
|
|
61
62
|
if (isObject__default["default"](customFormats)) {
|
|
62
63
|
Object.keys(customFormats).forEach(formatName => {
|
|
63
64
|
ajv.addFormat(formatName, customFormats[formatName]);
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
|
-
|
|
67
67
|
return ajv;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
const ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
|
|
71
71
|
/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.
|
|
72
72
|
*/
|
|
73
|
-
|
|
74
73
|
class AJV8Validator {
|
|
75
74
|
/** The AJV instance to use for all validations
|
|
76
75
|
*
|
|
@@ -94,9 +93,10 @@ class AJV8Validator {
|
|
|
94
93
|
additionalMetaSchemas,
|
|
95
94
|
customFormats,
|
|
96
95
|
ajvOptionsOverrides,
|
|
97
|
-
ajvFormatOptions
|
|
96
|
+
ajvFormatOptions,
|
|
97
|
+
AjvClass
|
|
98
98
|
} = options;
|
|
99
|
-
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions);
|
|
99
|
+
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);
|
|
100
100
|
this.localizer = localizer;
|
|
101
101
|
}
|
|
102
102
|
/** Transforms a ajv validation errors list:
|
|
@@ -118,34 +118,28 @@ class AJV8Validator {
|
|
|
118
118
|
* @param errors - The list of RJSFValidationError objects
|
|
119
119
|
* @private
|
|
120
120
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
121
|
toErrorSchema(errors) {
|
|
124
122
|
if (!errors.length) {
|
|
125
123
|
return {};
|
|
126
124
|
}
|
|
127
|
-
|
|
128
125
|
return errors.reduce((errorSchema, error) => {
|
|
129
126
|
const {
|
|
130
127
|
property,
|
|
131
128
|
message
|
|
132
129
|
} = error;
|
|
133
130
|
const path = toPath__default["default"](property);
|
|
134
|
-
let parent = errorSchema;
|
|
131
|
+
let parent = errorSchema;
|
|
132
|
+
// If the property is at the root (.level1) then toPath creates
|
|
135
133
|
// an empty array element at the first index. Remove it.
|
|
136
|
-
|
|
137
134
|
if (path.length > 0 && path[0] === "") {
|
|
138
135
|
path.splice(0, 1);
|
|
139
136
|
}
|
|
140
|
-
|
|
141
137
|
for (const segment of path.slice(0)) {
|
|
142
138
|
if (!(segment in parent)) {
|
|
143
139
|
parent[segment] = {};
|
|
144
140
|
}
|
|
145
|
-
|
|
146
141
|
parent = parent[segment];
|
|
147
142
|
}
|
|
148
|
-
|
|
149
143
|
if (Array.isArray(parent.__errors)) {
|
|
150
144
|
// We store the list of errors for this node in a property named __errors
|
|
151
145
|
// to avoid name collision with a possible sub schema field named
|
|
@@ -156,7 +150,6 @@ class AJV8Validator {
|
|
|
156
150
|
parent.__errors = [message];
|
|
157
151
|
}
|
|
158
152
|
}
|
|
159
|
-
|
|
160
153
|
return errorSchema;
|
|
161
154
|
}, {});
|
|
162
155
|
}
|
|
@@ -165,35 +158,28 @@ class AJV8Validator {
|
|
|
165
158
|
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
166
159
|
* @param [fieldPath=[]] - The current field path, defaults to [] if not specified
|
|
167
160
|
*/
|
|
168
|
-
|
|
169
|
-
|
|
170
161
|
toErrorList(errorSchema, fieldPath) {
|
|
171
162
|
if (fieldPath === void 0) {
|
|
172
163
|
fieldPath = [];
|
|
173
164
|
}
|
|
174
|
-
|
|
175
165
|
if (!errorSchema) {
|
|
176
166
|
return [];
|
|
177
167
|
}
|
|
178
|
-
|
|
179
168
|
let errorList = [];
|
|
180
|
-
|
|
181
169
|
if (utils.ERRORS_KEY in errorSchema) {
|
|
182
170
|
errorList = errorList.concat(errorSchema.__errors.map(message => {
|
|
183
|
-
const property =
|
|
171
|
+
const property = `.${fieldPath.join(".")}`;
|
|
184
172
|
return {
|
|
185
173
|
property,
|
|
186
174
|
message,
|
|
187
|
-
stack: property
|
|
175
|
+
stack: `${property} ${message}`
|
|
188
176
|
};
|
|
189
177
|
}));
|
|
190
178
|
}
|
|
191
|
-
|
|
192
179
|
return Object.keys(errorSchema).reduce((acc, key) => {
|
|
193
180
|
if (key !== utils.ERRORS_KEY) {
|
|
194
181
|
acc = acc.concat(this.toErrorList(errorSchema[key], [...fieldPath, key]));
|
|
195
182
|
}
|
|
196
|
-
|
|
197
183
|
return acc;
|
|
198
184
|
}, errorList);
|
|
199
185
|
}
|
|
@@ -202,38 +188,33 @@ class AJV8Validator {
|
|
|
202
188
|
* @param formData - The form data around which the error handler is created
|
|
203
189
|
* @private
|
|
204
190
|
*/
|
|
205
|
-
|
|
206
|
-
|
|
207
191
|
createErrorHandler(formData) {
|
|
208
192
|
const handler = {
|
|
209
193
|
// We store the list of errors for this node in a property named __errors
|
|
210
194
|
// to avoid name collision with a possible sub schema field named
|
|
211
195
|
// 'errors' (see `utils.toErrorSchema`).
|
|
212
196
|
__errors: [],
|
|
213
|
-
|
|
214
197
|
addError(message) {
|
|
215
198
|
this.__errors.push(message);
|
|
216
199
|
}
|
|
217
|
-
|
|
218
200
|
};
|
|
219
|
-
|
|
220
|
-
if (utils.isObject(formData)) {
|
|
221
|
-
const formObject = formData;
|
|
222
|
-
return Object.keys(formObject).reduce((acc, key) => {
|
|
223
|
-
return { ...acc,
|
|
224
|
-
[key]: this.createErrorHandler(formObject[key])
|
|
225
|
-
};
|
|
226
|
-
}, handler);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
201
|
if (Array.isArray(formData)) {
|
|
230
202
|
return formData.reduce((acc, value, key) => {
|
|
231
|
-
return {
|
|
203
|
+
return {
|
|
204
|
+
...acc,
|
|
232
205
|
[key]: this.createErrorHandler(value)
|
|
233
206
|
};
|
|
234
207
|
}, handler);
|
|
235
208
|
}
|
|
236
|
-
|
|
209
|
+
if (isObject__default["default"](formData)) {
|
|
210
|
+
const formObject = formData;
|
|
211
|
+
return Object.keys(formObject).reduce((acc, key) => {
|
|
212
|
+
return {
|
|
213
|
+
...acc,
|
|
214
|
+
[key]: this.createErrorHandler(formObject[key])
|
|
215
|
+
};
|
|
216
|
+
}, handler);
|
|
217
|
+
}
|
|
237
218
|
return handler;
|
|
238
219
|
}
|
|
239
220
|
/** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError` functions from it
|
|
@@ -241,19 +222,18 @@ class AJV8Validator {
|
|
|
241
222
|
* @param errorHandler - The `FormValidation` error handling structure
|
|
242
223
|
* @private
|
|
243
224
|
*/
|
|
244
|
-
|
|
245
|
-
|
|
246
225
|
unwrapErrorHandler(errorHandler) {
|
|
247
226
|
return Object.keys(errorHandler).reduce((acc, key) => {
|
|
248
227
|
if (key === "addError") {
|
|
249
228
|
return acc;
|
|
250
229
|
} else if (key === utils.ERRORS_KEY) {
|
|
251
|
-
return {
|
|
230
|
+
return {
|
|
231
|
+
...acc,
|
|
252
232
|
[key]: errorHandler[key]
|
|
253
233
|
};
|
|
254
234
|
}
|
|
255
|
-
|
|
256
|
-
|
|
235
|
+
return {
|
|
236
|
+
...acc,
|
|
257
237
|
[key]: this.unwrapErrorHandler(errorHandler[key])
|
|
258
238
|
};
|
|
259
239
|
}, {});
|
|
@@ -264,17 +244,10 @@ class AJV8Validator {
|
|
|
264
244
|
* @param errors - The list of AJV errors to convert to `RJSFValidationErrors`
|
|
265
245
|
* @private
|
|
266
246
|
*/
|
|
267
|
-
|
|
268
|
-
|
|
269
247
|
transformRJSFValidationErrors(errors) {
|
|
270
248
|
if (errors === void 0) {
|
|
271
249
|
errors = [];
|
|
272
250
|
}
|
|
273
|
-
|
|
274
|
-
if (errors === null) {
|
|
275
|
-
return [];
|
|
276
|
-
}
|
|
277
|
-
|
|
278
251
|
return errors.map(e => {
|
|
279
252
|
const {
|
|
280
253
|
instancePath,
|
|
@@ -283,18 +256,42 @@ class AJV8Validator {
|
|
|
283
256
|
params,
|
|
284
257
|
schemaPath
|
|
285
258
|
} = e;
|
|
286
|
-
const property = instancePath.replace(/\//g, ".");
|
|
287
|
-
|
|
259
|
+
const property = instancePath.replace(/\//g, ".");
|
|
260
|
+
// put data in expected format
|
|
288
261
|
return {
|
|
289
262
|
name: keyword,
|
|
290
263
|
property,
|
|
291
264
|
message,
|
|
292
265
|
params,
|
|
293
|
-
stack:
|
|
266
|
+
stack: `${property} ${message}`.trim(),
|
|
294
267
|
schemaPath
|
|
295
268
|
};
|
|
296
269
|
});
|
|
297
270
|
}
|
|
271
|
+
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
272
|
+
* by the playground. Returns the `errors` from the validation
|
|
273
|
+
*
|
|
274
|
+
* @param schema - The schema against which to validate the form data * @param schema
|
|
275
|
+
* @param formData - The form data to validate
|
|
276
|
+
*/
|
|
277
|
+
rawValidation(schema, formData) {
|
|
278
|
+
let validationError = undefined;
|
|
279
|
+
try {
|
|
280
|
+
this.ajv.validate(schema, formData);
|
|
281
|
+
} catch (err) {
|
|
282
|
+
validationError = err;
|
|
283
|
+
}
|
|
284
|
+
if (typeof this.localizer === "function") {
|
|
285
|
+
this.localizer(this.ajv.errors);
|
|
286
|
+
}
|
|
287
|
+
const errors = this.ajv.errors || undefined;
|
|
288
|
+
// Clear errors to prevent persistent errors, see #1104
|
|
289
|
+
this.ajv.errors = null;
|
|
290
|
+
return {
|
|
291
|
+
errors: errors,
|
|
292
|
+
validationError
|
|
293
|
+
};
|
|
294
|
+
}
|
|
298
295
|
/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
|
|
299
296
|
* the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
|
|
300
297
|
* supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and
|
|
@@ -305,43 +302,28 @@ class AJV8Validator {
|
|
|
305
302
|
* @param [customValidate] - An optional function that is used to perform custom validation
|
|
306
303
|
* @param [transformErrors] - An optional function that is used to transform errors after AJV validation
|
|
307
304
|
*/
|
|
308
|
-
|
|
309
|
-
|
|
310
305
|
validateFormData(formData, schema, customValidate, transformErrors) {
|
|
311
306
|
// Include form data with undefined values, which is required for validation.
|
|
312
307
|
const rootSchema = schema;
|
|
313
308
|
const newFormData = utils.getDefaultFormState(this, schema, formData, rootSchema, true);
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (typeof this.localizer === "function") {
|
|
323
|
-
this.localizer(this.ajv.errors);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
let errors = this.transformRJSFValidationErrors(this.ajv.errors); // Clear errors to prevent persistent errors, see #1104
|
|
327
|
-
|
|
328
|
-
this.ajv.errors = null;
|
|
329
|
-
const noProperMetaSchema = validationError && validationError.message && typeof validationError.message === "string" && validationError.message.includes("no schema with key or ref ");
|
|
330
|
-
|
|
309
|
+
const rawErrors = this.rawValidation(schema, newFormData);
|
|
310
|
+
const {
|
|
311
|
+
validationError
|
|
312
|
+
} = rawErrors;
|
|
313
|
+
let errors = this.transformRJSFValidationErrors(rawErrors.errors);
|
|
314
|
+
const noProperMetaSchema = validationError && validationError.message && validationError.message.includes("no schema with key or ref ");
|
|
331
315
|
if (noProperMetaSchema) {
|
|
332
316
|
errors = [...errors, {
|
|
333
317
|
stack: validationError.message
|
|
334
318
|
}];
|
|
335
319
|
}
|
|
336
|
-
|
|
337
320
|
if (typeof transformErrors === "function") {
|
|
338
321
|
errors = transformErrors(errors);
|
|
339
322
|
}
|
|
340
|
-
|
|
341
323
|
let errorSchema = this.toErrorSchema(errors);
|
|
342
|
-
|
|
343
324
|
if (noProperMetaSchema) {
|
|
344
|
-
errorSchema = {
|
|
325
|
+
errorSchema = {
|
|
326
|
+
...errorSchema,
|
|
345
327
|
...{
|
|
346
328
|
$schema: {
|
|
347
329
|
__errors: [validationError.message]
|
|
@@ -349,14 +331,12 @@ class AJV8Validator {
|
|
|
349
331
|
}
|
|
350
332
|
};
|
|
351
333
|
}
|
|
352
|
-
|
|
353
334
|
if (typeof customValidate !== "function") {
|
|
354
335
|
return {
|
|
355
336
|
errors,
|
|
356
337
|
errorSchema
|
|
357
338
|
};
|
|
358
339
|
}
|
|
359
|
-
|
|
360
340
|
const errorHandler = customValidate(newFormData, this.createErrorHandler(newFormData));
|
|
361
341
|
const userErrorSchema = this.unwrapErrorHandler(errorHandler);
|
|
362
342
|
return utils.mergeValidationData(this, {
|
|
@@ -370,35 +350,28 @@ class AJV8Validator {
|
|
|
370
350
|
* @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
371
351
|
* @private
|
|
372
352
|
*/
|
|
373
|
-
|
|
374
|
-
|
|
375
353
|
withIdRefPrefixObject(node) {
|
|
376
354
|
for (const key in node) {
|
|
377
355
|
const realObj = node;
|
|
378
356
|
const value = realObj[key];
|
|
379
|
-
|
|
380
357
|
if (key === utils.REF_KEY && typeof value === "string" && value.startsWith("#")) {
|
|
381
358
|
realObj[key] = ROOT_SCHEMA_PREFIX + value;
|
|
382
359
|
} else {
|
|
383
360
|
realObj[key] = this.withIdRefPrefix(value);
|
|
384
361
|
}
|
|
385
362
|
}
|
|
386
|
-
|
|
387
363
|
return node;
|
|
388
364
|
}
|
|
389
365
|
/** Takes a `node` object list and transforms any contained `$ref` node variables with a prefix, recursively calling
|
|
390
366
|
* `withIdRefPrefix` for any other elements.
|
|
391
367
|
*
|
|
392
|
-
* @param
|
|
368
|
+
* @param node - The list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
393
369
|
* @private
|
|
394
370
|
*/
|
|
395
|
-
|
|
396
|
-
|
|
397
371
|
withIdRefPrefixArray(node) {
|
|
398
372
|
for (let i = 0; i < node.length; i++) {
|
|
399
373
|
node[i] = this.withIdRefPrefix(node[i]);
|
|
400
374
|
}
|
|
401
|
-
|
|
402
375
|
return node;
|
|
403
376
|
}
|
|
404
377
|
/** Validates data against a schema, returning true if the data is valid, or
|
|
@@ -409,8 +382,6 @@ class AJV8Validator {
|
|
|
409
382
|
* @param formData- - The form data to validate
|
|
410
383
|
* @param rootSchema - The root schema used to provide $ref resolutions
|
|
411
384
|
*/
|
|
412
|
-
|
|
413
|
-
|
|
414
385
|
isValid(schema, formData, rootSchema) {
|
|
415
386
|
try {
|
|
416
387
|
// add the rootSchema ROOT_SCHEMA_PREFIX as id.
|
|
@@ -432,21 +403,15 @@ class AJV8Validator {
|
|
|
432
403
|
* @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
433
404
|
* @protected
|
|
434
405
|
*/
|
|
435
|
-
|
|
436
|
-
|
|
437
406
|
withIdRefPrefix(schemaNode) {
|
|
438
|
-
if (schemaNode.constructor === Object) {
|
|
439
|
-
return this.withIdRefPrefixObject({ ...schemaNode
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
|
|
443
407
|
if (Array.isArray(schemaNode)) {
|
|
444
408
|
return this.withIdRefPrefixArray([...schemaNode]);
|
|
445
409
|
}
|
|
446
|
-
|
|
410
|
+
if (isObject__default["default"](schemaNode)) {
|
|
411
|
+
return this.withIdRefPrefixObject(clone__default["default"](schemaNode));
|
|
412
|
+
}
|
|
447
413
|
return schemaNode;
|
|
448
414
|
}
|
|
449
|
-
|
|
450
415
|
}
|
|
451
416
|
|
|
452
417
|
/** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if
|
|
@@ -455,12 +420,10 @@ class AJV8Validator {
|
|
|
455
420
|
* @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance
|
|
456
421
|
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s
|
|
457
422
|
*/
|
|
458
|
-
|
|
459
423
|
function customizeValidator(options, localizer) {
|
|
460
424
|
if (options === void 0) {
|
|
461
425
|
options = {};
|
|
462
426
|
}
|
|
463
|
-
|
|
464
427
|
return new AJV8Validator(options, localizer);
|
|
465
428
|
}
|
|
466
429
|
|
|
@@ -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\";\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, 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> implements ValidatorType<T> {\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 } = options;\n this.ajv = createAjvInstance(\n additionalMetaSchemas,\n customFormats,\n ajvOptionsOverrides,\n ajvFormatOptions\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 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 if (typeof this.localizer === \"function\") {\n this.localizer(this.ajv.errors);\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, 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<T = any>(\n options: CustomValidatorOptionsType = {},\n localizer?: Localizer\n): ValidatorType<T> {\n return new AJV8Validator<T>(options, localizer);\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","localizer","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,IAAAA,8BAAU,CAACF,GAAD,EAAMD,gBAAN,CAAV,CAAA;AACD,GAL8C;;;AAQ/CC,EAAAA,GAAG,CAACG,SAAJ,CAAc,UAAd,EAA0BT,qBAA1B,CAAA,CAAA;AACAM,EAAAA,GAAG,CAACG,SAAJ,CAAc,OAAd,EAAuBV,kBAAvB,EAT+C;;AAY/C,EAAA,IAAIW,KAAK,CAACC,OAAN,CAAcT,qBAAd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AAjC;;;;;"}
|
|
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 AjvClass: typeof Ajv = Ajv\n) {\n const ajv = new AjvClass({ ...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 isObject from \"lodash/isObject\";\nimport clone from \"lodash/clone\";\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FieldValidation,\n FormValidation,\n GenericObjectType,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n ValidationData,\n ValidatorType,\n getDefaultFormState,\n mergeValidationData,\n ERRORS_KEY,\n REF_KEY,\n} from \"@rjsf/utils\";\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> implements ValidatorType<T>\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 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 (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 * @private\n */\n private transformRJSFValidationErrors(\n errors: ErrorObject[] = []\n ): RJSFValidationError[] {\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 /** 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 validationError: Error | undefined = undefined;\n try {\n this.ajv.validate(schema, formData);\n } catch (err) {\n validationError = err as Error;\n }\n\n if (typeof this.localizer === \"function\") {\n this.localizer(this.ajv.errors);\n }\n const errors = this.ajv.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n this.ajv.errors = null;\n\n return { errors: errors as unknown as Result[], validationError };\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 | undefined,\n schema: S,\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 const rawErrors = this.rawValidation<ErrorObject>(schema, newFormData);\n const { validationError } = rawErrors;\n let errors = this.transformRJSFValidationErrors(rawErrors.errors);\n\n const noProperMetaSchema =\n validationError &&\n validationError.message &&\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: 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 * @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: S, formData: T, rootSchema: S) {\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: 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 { 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>(\n options: CustomValidatorOptionsType = {},\n localizer?: Localizer\n): ValidatorType<T, S> {\n return new AJV8Validator<T, S>(options, localizer);\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","AjvClass","Ajv","ajv","addFormats","addFormat","Array","isArray","addMetaSchema","isObject","Object","keys","forEach","formatName","ROOT_SCHEMA_PREFIX","AJV8Validator","constructor","options","localizer","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","value","formObject","unwrapErrorHandler","errorHandler","transformRJSFValidationErrors","e","instancePath","keyword","params","schemaPath","replace","name","trim","rawValidation","schema","validationError","undefined","validate","err","validateFormData","customValidate","transformErrors","rootSchema","newFormData","getDefaultFormState","rawErrors","noProperMetaSchema","includes","$schema","userErrorSchema","mergeValidationData","withIdRefPrefixObject","node","realObj","REF_KEY","startsWith","withIdRefPrefix","withIdRefPrefixArray","i","isValid","result","addSchema","removeSchema","schemaNode","clone","customizeValidator"],"mappings":";;;;;;;;;;;;;;;;;;;AAMO,MAAMA,UAAU,GAAY;AACjCC,EAAAA,SAAS,EAAE,IAAI;AACfC,EAAAA,mBAAmB,EAAE,CAAA;CACb,CAAA;AACH,MAAMC,kBAAkB,GAC7B,4YAA4Y,CAAA;AACvY,MAAMC,qBAAqB,GAChC,2DAA2D,CAAA;AAE7D;;;;;;;;;;;;;AAaG;AACqB,SAAAC,iBAAiB,CACvCC,qBAA2E,EAC3EC,aAA2D,EAC3DC,qBACAC,gBAA+C,E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E,eAAe,CAACO,UAAmB,EAAA;AAC3C,IAAA,IAAItF,KAAK,CAACC,OAAO,CAACqF,UAAU,CAAC,EAAE;MAC7B,OAAO,IAAI,CAACN,oBAAoB,CAAC,CAAC,GAAGM,UAAU,CAAC,CAAC,CAAA;AAClD,KAAA;AACD,IAAA,IAAInF,4BAAQ,CAACmF,UAAU,CAAC,EAAE;MACxB,OAAO,IAAI,CAACZ,qBAAqB,CAACa,yBAAK,CAAID,UAAU,CAAC,CAAC,CAAA;AACxD,KAAA;AACD,IAAA,OAAOA,UAAU,CAAA;AACnB,GAAA;AACD;;ACxZD;;;;;AAKG;AACqB,SAAAE,kBAAkB,CAIxC7E,OAAsC,EACtCC,SAAqB,EAAA;AAAA,EAAA,IADrBD,OAAsC,KAAA,KAAA,CAAA,EAAA;IAAtCA,OAAsC,GAAA,EAAE,CAAA;AAAA,GAAA;AAGxC,EAAA,OAAO,IAAIF,aAAa,CAAOE,OAAO,EAAEC,SAAS,CAAC,CAAA;AACpD;;ACdA,YAAA,aAAe4E,kBAAkB,EAAE;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("lodash/toPath"),e=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("lodash/toPath"),e=require("lodash/isObject"),t=require("lodash/clone"),a=require("@rjsf/utils"),s=require("ajv"),o=require("ajv-formats");function i(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var n=i(r),c=i(e),d=i(t),l=i(s),h=i(o);const u={allErrors:!0,multipleOfPrecision:8},f=/^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/,m=/^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;class v{constructor(r,e){this.ajv=void 0,this.localizer=void 0;const{additionalMetaSchemas:t,customFormats:a,ajvOptionsOverrides:s,ajvFormatOptions:o,AjvClass:i}=r;this.ajv=function(r,e,t,a,s){void 0===t&&(t={}),void 0===s&&(s=l.default);const o=new s({...u,...t});return"boolean"!=typeof a&&h.default(o,a),o.addFormat("data-url",m),o.addFormat("color",f),Array.isArray(r)&&o.addMetaSchema(r),c.default(e)&&Object.keys(e).forEach((r=>{o.addFormat(r,e[r])})),o}(t,a,s,o,i),this.localizer=e}toErrorSchema(r){return r.length?r.reduce(((r,e)=>{const{property:t,message:a}=e,s=n.default(t);let o=r;s.length>0&&""===s[0]&&s.splice(0,1);for(const r of s.slice(0))r in o||(o[r]={}),o=o[r];return Array.isArray(o.__errors)?o.__errors=o.__errors.concat(a):a&&(o.__errors=[a]),r}),{}):{}}toErrorList(r,e){if(void 0===e&&(e=[]),!r)return[];let t=[];return a.ERRORS_KEY in r&&(t=t.concat(r.__errors.map((r=>{const t=`.${e.join(".")}`;return{property:t,message:r,stack:`${t} ${r}`}})))),Object.keys(r).reduce(((t,s)=>(s!==a.ERRORS_KEY&&(t=t.concat(this.toErrorList(r[s],[...e,s]))),t)),t)}createErrorHandler(r){const e={__errors:[],addError(r){this.__errors.push(r)}};if(Array.isArray(r))return r.reduce(((r,e,t)=>({...r,[t]:this.createErrorHandler(e)})),e);if(c.default(r)){const t=r;return Object.keys(t).reduce(((r,e)=>({...r,[e]:this.createErrorHandler(t[e])})),e)}return e}unwrapErrorHandler(r){return Object.keys(r).reduce(((e,t)=>"addError"===t?e:t===a.ERRORS_KEY?{...e,[t]:r[t]}:{...e,[t]:this.unwrapErrorHandler(r[t])}),{})}transformRJSFValidationErrors(r){return void 0===r&&(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}}))}rawValidation(r,e){let t;try{this.ajv.validate(r,e)}catch(r){t=r}"function"==typeof this.localizer&&this.localizer(this.ajv.errors);const a=this.ajv.errors||void 0;return this.ajv.errors=null,{errors:a,validationError:t}}validateFormData(r,e,t,s){const o=a.getDefaultFormState(this,e,r,e,!0),i=this.rawValidation(e,o),{validationError:n}=i;let c=this.transformRJSFValidationErrors(i.errors);const d=n&&n.message&&n.message.includes("no schema with key or ref ");d&&(c=[...c,{stack:n.message}]),"function"==typeof s&&(c=s(c));let l=this.toErrorSchema(c);if(d&&(l={...l,$schema:{__errors:[n.message]}}),"function"!=typeof t)return{errors:c,errorSchema:l};const h=t(o,this.createErrorHandler(o)),u=this.unwrapErrorHandler(h);return a.mergeValidationData(this,{errors:c,errorSchema:l},u)}withIdRefPrefixObject(r){for(const e in r){const t=r[e];r[e]=e===a.REF_KEY&&"string"==typeof t&&t.startsWith("#")?"__rjsf_rootSchema"+t:this.withIdRefPrefix(t)}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 Array.isArray(r)?this.withIdRefPrefixArray([...r]):c.default(r)?this.withIdRefPrefixObject(d.default(r)):r}}function y(r,e){return void 0===r&&(r={}),new v(r,e)}var p=y();exports.customizeValidator=y,exports.default=p;
|
|
2
2
|
//# sourceMappingURL=validator-ajv8.cjs.production.min.js.map
|