@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.
- package/LICENSE.md +201 -0
- package/README.md +247 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +8 -0
- package/dist/validator-ajv8.cjs.development.js +458 -0
- package/dist/validator-ajv8.cjs.development.js.map +1 -0
- package/dist/validator-ajv8.cjs.production.min.js +2 -0
- package/dist/validator-ajv8.cjs.production.min.js.map +1 -0
- package/dist/validator-ajv8.esm.js +446 -0
- package/dist/validator-ajv8.esm.js.map +1 -0
- package/dist/validator-ajv8.umd.development.js +458 -0
- package/dist/validator-ajv8.umd.development.js.map +1 -0
- package/dist/validator-ajv8.umd.production.min.js +2 -0
- package/dist/validator-ajv8.umd.production.min.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import toPath from 'lodash-es/toPath';
|
|
2
|
+
import { ERRORS_KEY, isObject as isObject$1, getDefaultFormState, mergeValidationData, REF_KEY } from '@rjsf/utils';
|
|
3
|
+
import Ajv from 'ajv';
|
|
4
|
+
import addFormats from 'ajv-formats';
|
|
5
|
+
import isObject from 'lodash-es/isObject';
|
|
6
|
+
|
|
7
|
+
const AJV_CONFIG = {
|
|
8
|
+
allErrors: true,
|
|
9
|
+
multipleOfPrecision: 8
|
|
10
|
+
};
|
|
11
|
+
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*\)))$/;
|
|
12
|
+
const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
|
|
13
|
+
/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.
|
|
14
|
+
* If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the
|
|
15
|
+
* list. If `customFormats` are provided then those additional formats are added to the list of supported formats. If
|
|
16
|
+
* `ajvOptionsOverrides` are provided then they are spread on top of the default `AJV_CONFIG` options when constructing
|
|
17
|
+
* the `Ajv` instance. With Ajv v8, the JSON Schema formats are not provided by default, but can be plugged in. By
|
|
18
|
+
* default, all formats from the `ajv-formats` library are added. To disable this capability, set the `ajvFormatOptions`
|
|
19
|
+
* parameter to `false`. Additionally, you can configure the `ajv-formats` by providing a custom set of
|
|
20
|
+
* [format options](https://github.com/ajv-validator/ajv-formats) to the `ajvFormatOptions` parameter.
|
|
21
|
+
*
|
|
22
|
+
* @param [additionalMetaSchemas] - The list of additional meta schemas that the validator can access
|
|
23
|
+
* @param [customFormats] - The set of additional custom formats that the validator will support
|
|
24
|
+
* @param [ajvOptionsOverrides={}] - The set of validator config override options
|
|
25
|
+
* @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions) {
|
|
29
|
+
if (ajvOptionsOverrides === void 0) {
|
|
30
|
+
ajvOptionsOverrides = {};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ajv = new Ajv({ ...AJV_CONFIG,
|
|
34
|
+
...ajvOptionsOverrides
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (typeof ajvFormatOptions !== "boolean") {
|
|
38
|
+
addFormats(ajv, ajvFormatOptions);
|
|
39
|
+
} // add custom formats
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
ajv.addFormat("data-url", DATA_URL_FORMAT_REGEX);
|
|
43
|
+
ajv.addFormat("color", COLOR_FORMAT_REGEX); // add more schemas to validate against
|
|
44
|
+
|
|
45
|
+
if (Array.isArray(additionalMetaSchemas)) {
|
|
46
|
+
ajv.addMetaSchema(additionalMetaSchemas);
|
|
47
|
+
} // add more custom formats to validate against
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if (isObject(customFormats)) {
|
|
51
|
+
Object.keys(customFormats).forEach(formatName => {
|
|
52
|
+
ajv.addFormat(formatName, customFormats[formatName]);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return ajv;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
|
|
60
|
+
/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
class AJV8Validator {
|
|
64
|
+
/** The AJV instance to use for all validations
|
|
65
|
+
*
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/** Constructs an `AJV8Validator` instance using the `options`
|
|
70
|
+
*
|
|
71
|
+
* @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance
|
|
72
|
+
*/
|
|
73
|
+
constructor(options) {
|
|
74
|
+
this.ajv = void 0;
|
|
75
|
+
const {
|
|
76
|
+
additionalMetaSchemas,
|
|
77
|
+
customFormats,
|
|
78
|
+
ajvOptionsOverrides,
|
|
79
|
+
ajvFormatOptions
|
|
80
|
+
} = options;
|
|
81
|
+
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions);
|
|
82
|
+
}
|
|
83
|
+
/** Transforms a ajv validation errors list:
|
|
84
|
+
* [
|
|
85
|
+
* {property: '.level1.level2[2].level3', message: 'err a'},
|
|
86
|
+
* {property: '.level1.level2[2].level3', message: 'err b'},
|
|
87
|
+
* {property: '.level1.level2[4].level3', message: 'err b'},
|
|
88
|
+
* ]
|
|
89
|
+
* Into an error tree:
|
|
90
|
+
* {
|
|
91
|
+
* level1: {
|
|
92
|
+
* level2: {
|
|
93
|
+
* 2: {level3: {errors: ['err a', 'err b']}},
|
|
94
|
+
* 4: {level3: {errors: ['err b']}},
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* };
|
|
98
|
+
*
|
|
99
|
+
* @param errors - The list of RJSFValidationError objects
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
toErrorSchema(errors) {
|
|
105
|
+
if (!errors.length) {
|
|
106
|
+
return {};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return errors.reduce((errorSchema, error) => {
|
|
110
|
+
const {
|
|
111
|
+
property,
|
|
112
|
+
message
|
|
113
|
+
} = error;
|
|
114
|
+
const path = toPath(property);
|
|
115
|
+
let parent = errorSchema; // If the property is at the root (.level1) then toPath creates
|
|
116
|
+
// an empty array element at the first index. Remove it.
|
|
117
|
+
|
|
118
|
+
if (path.length > 0 && path[0] === "") {
|
|
119
|
+
path.splice(0, 1);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
for (const segment of path.slice(0)) {
|
|
123
|
+
if (!(segment in parent)) {
|
|
124
|
+
parent[segment] = {};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
parent = parent[segment];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (Array.isArray(parent.__errors)) {
|
|
131
|
+
// We store the list of errors for this node in a property named __errors
|
|
132
|
+
// to avoid name collision with a possible sub schema field named
|
|
133
|
+
// 'errors' (see `validate.createErrorHandler`).
|
|
134
|
+
parent.__errors = parent.__errors.concat(message);
|
|
135
|
+
} else {
|
|
136
|
+
if (message) {
|
|
137
|
+
parent.__errors = [message];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return errorSchema;
|
|
142
|
+
}, {});
|
|
143
|
+
}
|
|
144
|
+
/** Converts an `errorSchema` into a list of `RJSFValidationErrors`
|
|
145
|
+
*
|
|
146
|
+
* @param errorSchema - The `ErrorSchema` instance to convert
|
|
147
|
+
* @param [fieldPath=[]] - The current field path, defaults to [] if not specified
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
toErrorList(errorSchema, fieldPath) {
|
|
152
|
+
if (fieldPath === void 0) {
|
|
153
|
+
fieldPath = [];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!errorSchema) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
let errorList = [];
|
|
161
|
+
|
|
162
|
+
if (ERRORS_KEY in errorSchema) {
|
|
163
|
+
errorList = errorList.concat(errorSchema.__errors.map(message => {
|
|
164
|
+
const property = "." + fieldPath.join(".");
|
|
165
|
+
return {
|
|
166
|
+
property,
|
|
167
|
+
message,
|
|
168
|
+
stack: property + " " + message
|
|
169
|
+
};
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return Object.keys(errorSchema).reduce((acc, key) => {
|
|
174
|
+
if (key !== ERRORS_KEY) {
|
|
175
|
+
acc = acc.concat(this.toErrorList(errorSchema[key], [...fieldPath, key]));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return acc;
|
|
179
|
+
}, errorList);
|
|
180
|
+
}
|
|
181
|
+
/** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it
|
|
182
|
+
*
|
|
183
|
+
* @param formData - The form data around which the error handler is created
|
|
184
|
+
* @private
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
createErrorHandler(formData) {
|
|
189
|
+
const handler = {
|
|
190
|
+
// We store the list of errors for this node in a property named __errors
|
|
191
|
+
// to avoid name collision with a possible sub schema field named
|
|
192
|
+
// 'errors' (see `utils.toErrorSchema`).
|
|
193
|
+
__errors: [],
|
|
194
|
+
|
|
195
|
+
addError(message) {
|
|
196
|
+
this.__errors.push(message);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
if (isObject$1(formData)) {
|
|
202
|
+
const formObject = formData;
|
|
203
|
+
return Object.keys(formObject).reduce((acc, key) => {
|
|
204
|
+
return { ...acc,
|
|
205
|
+
[key]: this.createErrorHandler(formObject[key])
|
|
206
|
+
};
|
|
207
|
+
}, handler);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (Array.isArray(formData)) {
|
|
211
|
+
return formData.reduce((acc, value, key) => {
|
|
212
|
+
return { ...acc,
|
|
213
|
+
[key]: this.createErrorHandler(value)
|
|
214
|
+
};
|
|
215
|
+
}, handler);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return handler;
|
|
219
|
+
}
|
|
220
|
+
/** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError` functions from it
|
|
221
|
+
*
|
|
222
|
+
* @param errorHandler - The `FormValidation` error handling structure
|
|
223
|
+
* @private
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
unwrapErrorHandler(errorHandler) {
|
|
228
|
+
return Object.keys(errorHandler).reduce((acc, key) => {
|
|
229
|
+
if (key === "addError") {
|
|
230
|
+
return acc;
|
|
231
|
+
} else if (key === ERRORS_KEY) {
|
|
232
|
+
return { ...acc,
|
|
233
|
+
[key]: errorHandler[key]
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return { ...acc,
|
|
238
|
+
[key]: this.unwrapErrorHandler(errorHandler[key])
|
|
239
|
+
};
|
|
240
|
+
}, {});
|
|
241
|
+
}
|
|
242
|
+
/** Transforming the error output from ajv to format used by @rjsf/utils.
|
|
243
|
+
* At some point, components should be updated to support ajv.
|
|
244
|
+
*
|
|
245
|
+
* @param errors - The list of AJV errors to convert to `RJSFValidationErrors`
|
|
246
|
+
* @private
|
|
247
|
+
*/
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
transformRJSFValidationErrors(errors) {
|
|
251
|
+
if (errors === void 0) {
|
|
252
|
+
errors = [];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (errors === null) {
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return errors.map(e => {
|
|
260
|
+
const {
|
|
261
|
+
instancePath,
|
|
262
|
+
keyword,
|
|
263
|
+
message,
|
|
264
|
+
params,
|
|
265
|
+
schemaPath
|
|
266
|
+
} = e;
|
|
267
|
+
const property = instancePath.replace(/\//g, "."); // put data in expected format
|
|
268
|
+
|
|
269
|
+
return {
|
|
270
|
+
name: keyword,
|
|
271
|
+
property,
|
|
272
|
+
message,
|
|
273
|
+
params,
|
|
274
|
+
stack: (property + " " + message).trim(),
|
|
275
|
+
schemaPath
|
|
276
|
+
};
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
|
|
280
|
+
* the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
|
|
281
|
+
* supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and
|
|
282
|
+
* transform them in what ever way it chooses.
|
|
283
|
+
*
|
|
284
|
+
* @param formData - The form data to validate
|
|
285
|
+
* @param schema - The schema against which to validate the form data
|
|
286
|
+
* @param [customValidate] - An optional function that is used to perform custom validation
|
|
287
|
+
* @param [transformErrors] - An optional function that is used to transform errors after AJV validation
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
validateFormData(formData, schema, customValidate, transformErrors) {
|
|
292
|
+
// Include form data with undefined values, which is required for validation.
|
|
293
|
+
const rootSchema = schema;
|
|
294
|
+
const newFormData = getDefaultFormState(this, schema, formData, rootSchema, true);
|
|
295
|
+
let validationError = null;
|
|
296
|
+
|
|
297
|
+
try {
|
|
298
|
+
this.ajv.validate(schema, newFormData);
|
|
299
|
+
} catch (err) {
|
|
300
|
+
validationError = err;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let errors = this.transformRJSFValidationErrors(this.ajv.errors); // Clear errors to prevent persistent errors, see #1104
|
|
304
|
+
|
|
305
|
+
this.ajv.errors = null;
|
|
306
|
+
const noProperMetaSchema = validationError && validationError.message && typeof validationError.message === "string" && validationError.message.includes("no schema with key or ref ");
|
|
307
|
+
|
|
308
|
+
if (noProperMetaSchema) {
|
|
309
|
+
errors = [...errors, {
|
|
310
|
+
stack: validationError.message
|
|
311
|
+
}];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (typeof transformErrors === "function") {
|
|
315
|
+
errors = transformErrors(errors);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
let errorSchema = this.toErrorSchema(errors);
|
|
319
|
+
|
|
320
|
+
if (noProperMetaSchema) {
|
|
321
|
+
errorSchema = { ...errorSchema,
|
|
322
|
+
...{
|
|
323
|
+
$schema: {
|
|
324
|
+
__errors: [validationError.message]
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (typeof customValidate !== "function") {
|
|
331
|
+
return {
|
|
332
|
+
errors,
|
|
333
|
+
errorSchema
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const errorHandler = customValidate(newFormData, this.createErrorHandler(newFormData));
|
|
338
|
+
const userErrorSchema = this.unwrapErrorHandler(errorHandler);
|
|
339
|
+
return mergeValidationData(this, {
|
|
340
|
+
errors,
|
|
341
|
+
errorSchema
|
|
342
|
+
}, userErrorSchema);
|
|
343
|
+
}
|
|
344
|
+
/** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling
|
|
345
|
+
* `withIdRefPrefix` for any other elements.
|
|
346
|
+
*
|
|
347
|
+
* @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
348
|
+
* @private
|
|
349
|
+
*/
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
withIdRefPrefixObject(node) {
|
|
353
|
+
for (const key in node) {
|
|
354
|
+
const realObj = node;
|
|
355
|
+
const value = realObj[key];
|
|
356
|
+
|
|
357
|
+
if (key === REF_KEY && typeof value === "string" && value.startsWith("#")) {
|
|
358
|
+
realObj[key] = ROOT_SCHEMA_PREFIX + value;
|
|
359
|
+
} else {
|
|
360
|
+
realObj[key] = this.withIdRefPrefix(value);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return node;
|
|
365
|
+
}
|
|
366
|
+
/** Takes a `node` object list and transforms any contained `$ref` node variables with a prefix, recursively calling
|
|
367
|
+
* `withIdRefPrefix` for any other elements.
|
|
368
|
+
*
|
|
369
|
+
* @param nodeThe - list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
370
|
+
* @private
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
withIdRefPrefixArray(node) {
|
|
375
|
+
for (let i = 0; i < node.length; i++) {
|
|
376
|
+
node[i] = this.withIdRefPrefix(node[i]);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return node;
|
|
380
|
+
}
|
|
381
|
+
/** Validates data against a schema, returning true if the data is valid, or
|
|
382
|
+
* false otherwise. If the schema is invalid, then this function will return
|
|
383
|
+
* false.
|
|
384
|
+
*
|
|
385
|
+
* @param schema - The schema against which to validate the form data * @param schema
|
|
386
|
+
* @param formData- - The form data to validate
|
|
387
|
+
* @param rootSchema - The root schema used to provide $ref resolutions
|
|
388
|
+
*/
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
isValid(schema, formData, rootSchema) {
|
|
392
|
+
try {
|
|
393
|
+
// add the rootSchema ROOT_SCHEMA_PREFIX as id.
|
|
394
|
+
// then rewrite the schema ref's to point to the rootSchema
|
|
395
|
+
// this accounts for the case where schema have references to models
|
|
396
|
+
// that lives in the rootSchema but not in the schema in question.
|
|
397
|
+
const result = this.ajv.addSchema(rootSchema, ROOT_SCHEMA_PREFIX).validate(this.withIdRefPrefix(schema), formData);
|
|
398
|
+
return result;
|
|
399
|
+
} catch (e) {
|
|
400
|
+
return false;
|
|
401
|
+
} finally {
|
|
402
|
+
// make sure we remove the rootSchema from the global ajv instance
|
|
403
|
+
this.ajv.removeSchema(ROOT_SCHEMA_PREFIX);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/** Recursively prefixes all $ref's in a schema with `ROOT_SCHEMA_PREFIX`
|
|
407
|
+
* This is used in isValid to make references to the rootSchema
|
|
408
|
+
*
|
|
409
|
+
* @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
|
|
410
|
+
* @protected
|
|
411
|
+
*/
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
withIdRefPrefix(schemaNode) {
|
|
415
|
+
if (schemaNode.constructor === Object) {
|
|
416
|
+
return this.withIdRefPrefixObject({ ...schemaNode
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (Array.isArray(schemaNode)) {
|
|
421
|
+
return this.withIdRefPrefixArray([...schemaNode]);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return schemaNode;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if
|
|
430
|
+
* provided.
|
|
431
|
+
*
|
|
432
|
+
* @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance
|
|
433
|
+
*/
|
|
434
|
+
|
|
435
|
+
function customizeValidator(options) {
|
|
436
|
+
if (options === void 0) {
|
|
437
|
+
options = {};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return new AJV8Validator(options);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
var index = /*#__PURE__*/customizeValidator();
|
|
444
|
+
|
|
445
|
+
export { customizeValidator, index as default };
|
|
446
|
+
//# sourceMappingURL=validator-ajv8.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator-ajv8.esm.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,GAAJ,CAAQ,EAAE,GAAGX,UAAL;IAAiB,GAAGQ,mBAAAA;AAApB,GAAR,CAAZ,CAAA;;AACA,EAAA,IAAI,OAAOC,gBAAP,KAA4B,SAAhC,EAA2C;AACzCG,IAAAA,UAAU,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,CAAJ,EAA0C;IACxCI,GAAG,CAACM,aAAJ,CAAkBV,qBAAlB,CAAA,CAAA;AACD,GAd8C;;;AAiB/C,EAAA,IAAIW,Q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