@rjsf/validator-ajv8 5.10.0 → 5.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compileSchemaValidators.cjs.development.js +22 -24
- package/dist/compileSchemaValidators.cjs.development.js.map +1 -1
- package/dist/compileSchemaValidators.cjs.production.min.js +1 -1
- package/dist/compileSchemaValidators.cjs.production.min.js.map +1 -1
- package/dist/createAjvInstance-33d73c95.js +2 -0
- package/dist/{createAjvInstance-0cd8cfba.js.map → createAjvInstance-33d73c95.js.map} +1 -1
- package/dist/index.cjs.development.js +95 -106
- package/dist/index.cjs.development.js.map +1 -1
- package/dist/index.cjs.production.min.js +1 -1
- package/dist/index.cjs.production.min.js.map +1 -1
- package/dist/validator-ajv8.esm.js +103 -144
- package/dist/validator-ajv8.esm.js.map +1 -1
- package/dist/validator-ajv8.umd.development.js +103 -144
- 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 +8 -7
- package/dist/createAjvInstance-0cd8cfba.js +0 -2
|
@@ -12,41 +12,14 @@
|
|
|
12
12
|
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
|
|
13
13
|
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
17
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
18
|
-
var source = arguments[i];
|
|
19
|
-
for (var key in source) {
|
|
20
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
21
|
-
target[key] = source[key];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return target;
|
|
26
|
-
};
|
|
27
|
-
return _extends.apply(this, arguments);
|
|
28
|
-
}
|
|
29
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
30
|
-
if (source == null) return {};
|
|
31
|
-
var target = {};
|
|
32
|
-
var sourceKeys = Object.keys(source);
|
|
33
|
-
var key, i;
|
|
34
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
35
|
-
key = sourceKeys[i];
|
|
36
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
37
|
-
target[key] = source[key];
|
|
38
|
-
}
|
|
39
|
-
return target;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var AJV_CONFIG = {
|
|
15
|
+
const AJV_CONFIG = {
|
|
43
16
|
allErrors: true,
|
|
44
17
|
multipleOfPrecision: 8,
|
|
45
18
|
strict: false,
|
|
46
19
|
verbose: true
|
|
47
20
|
};
|
|
48
|
-
|
|
49
|
-
|
|
21
|
+
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*\)))$/;
|
|
22
|
+
const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
|
|
50
23
|
/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.
|
|
51
24
|
* If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the
|
|
52
25
|
* list. If `customFormats` are provided then those additional formats are added to the list of supported formats. If
|
|
@@ -62,14 +35,11 @@
|
|
|
62
35
|
* @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it
|
|
63
36
|
* @param [AjvClass] - The `Ajv` class to use when creating the validator instance
|
|
64
37
|
*/
|
|
65
|
-
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
AjvClass = Ajv__default["default"];
|
|
71
|
-
}
|
|
72
|
-
var ajv = new AjvClass(_extends({}, AJV_CONFIG, ajvOptionsOverrides));
|
|
38
|
+
function createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides = {}, ajvFormatOptions, AjvClass = Ajv__default["default"]) {
|
|
39
|
+
const ajv = new AjvClass({
|
|
40
|
+
...AJV_CONFIG,
|
|
41
|
+
...ajvOptionsOverrides
|
|
42
|
+
});
|
|
73
43
|
if (ajvFormatOptions) {
|
|
74
44
|
addFormats__default["default"](ajv, ajvFormatOptions);
|
|
75
45
|
} else if (ajvFormatOptions !== false) {
|
|
@@ -87,67 +57,66 @@
|
|
|
87
57
|
}
|
|
88
58
|
// add more custom formats to validate against
|
|
89
59
|
if (isObject__default["default"](customFormats)) {
|
|
90
|
-
Object.keys(customFormats).forEach(
|
|
60
|
+
Object.keys(customFormats).forEach(formatName => {
|
|
91
61
|
ajv.addFormat(formatName, customFormats[formatName]);
|
|
92
62
|
});
|
|
93
63
|
}
|
|
94
64
|
return ajv;
|
|
95
65
|
}
|
|
96
66
|
|
|
97
|
-
var _excluded = ["instancePath", "keyword", "params", "schemaPath", "parentSchema"];
|
|
98
67
|
/** Transforming the error output from ajv to format used by @rjsf/utils.
|
|
99
68
|
* At some point, components should be updated to support ajv.
|
|
100
69
|
*
|
|
101
70
|
* @param errors - The list of AJV errors to convert to `RJSFValidationErrors`
|
|
102
71
|
* @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
|
|
103
72
|
*/
|
|
104
|
-
function transformRJSFValidationErrors(errors, uiSchema) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
73
|
+
function transformRJSFValidationErrors(errors = [], uiSchema) {
|
|
74
|
+
return errors.map(e => {
|
|
75
|
+
const {
|
|
76
|
+
instancePath,
|
|
77
|
+
keyword,
|
|
78
|
+
params,
|
|
79
|
+
schemaPath,
|
|
80
|
+
parentSchema,
|
|
81
|
+
...rest
|
|
82
|
+
} = e;
|
|
83
|
+
let {
|
|
84
|
+
message = ''
|
|
85
|
+
} = rest;
|
|
86
|
+
let property = instancePath.replace(/\//g, '.');
|
|
87
|
+
let stack = `${property} ${message}`.trim();
|
|
119
88
|
if ('missingProperty' in params) {
|
|
120
|
-
property = property ? property
|
|
121
|
-
|
|
122
|
-
|
|
89
|
+
property = property ? `${property}.${params.missingProperty}` : params.missingProperty;
|
|
90
|
+
const currentProperty = params.missingProperty;
|
|
91
|
+
const uiSchemaTitle = utils.getUiOptions(get__default["default"](uiSchema, `${property.replace(/^\./, '')}`)).title;
|
|
123
92
|
if (uiSchemaTitle) {
|
|
124
93
|
message = message.replace(currentProperty, uiSchemaTitle);
|
|
125
94
|
} else {
|
|
126
|
-
|
|
95
|
+
const parentSchemaTitle = get__default["default"](parentSchema, [utils.PROPERTIES_KEY, currentProperty, 'title']);
|
|
127
96
|
if (parentSchemaTitle) {
|
|
128
97
|
message = message.replace(currentProperty, parentSchemaTitle);
|
|
129
98
|
}
|
|
130
99
|
}
|
|
131
100
|
stack = message;
|
|
132
101
|
} else {
|
|
133
|
-
|
|
134
|
-
if (
|
|
135
|
-
stack =
|
|
102
|
+
const uiSchemaTitle = utils.getUiOptions(get__default["default"](uiSchema, `${property.replace(/^\./, '')}`)).title;
|
|
103
|
+
if (uiSchemaTitle) {
|
|
104
|
+
stack = `'${uiSchemaTitle}' ${message}`.trim();
|
|
136
105
|
} else {
|
|
137
|
-
|
|
138
|
-
if (
|
|
139
|
-
stack =
|
|
106
|
+
const parentSchemaTitle = parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.title;
|
|
107
|
+
if (parentSchemaTitle) {
|
|
108
|
+
stack = `'${parentSchemaTitle}' ${message}`.trim();
|
|
140
109
|
}
|
|
141
110
|
}
|
|
142
111
|
}
|
|
143
112
|
// put data in expected format
|
|
144
113
|
return {
|
|
145
114
|
name: keyword,
|
|
146
|
-
property
|
|
147
|
-
message
|
|
148
|
-
params
|
|
149
|
-
stack
|
|
150
|
-
schemaPath
|
|
115
|
+
property,
|
|
116
|
+
message,
|
|
117
|
+
params,
|
|
118
|
+
stack,
|
|
119
|
+
schemaPath
|
|
151
120
|
};
|
|
152
121
|
});
|
|
153
122
|
}
|
|
@@ -165,49 +134,52 @@
|
|
|
165
134
|
* @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
|
|
166
135
|
*/
|
|
167
136
|
function processRawValidationErrors(validator, rawErrors, formData, schema, customValidate, transformErrors, uiSchema) {
|
|
168
|
-
|
|
169
|
-
|
|
137
|
+
const {
|
|
138
|
+
validationError: invalidSchemaError
|
|
139
|
+
} = rawErrors;
|
|
140
|
+
let errors = transformRJSFValidationErrors(rawErrors.errors, uiSchema);
|
|
170
141
|
if (invalidSchemaError) {
|
|
171
|
-
errors = [
|
|
142
|
+
errors = [...errors, {
|
|
172
143
|
stack: invalidSchemaError.message
|
|
173
|
-
}]
|
|
144
|
+
}];
|
|
174
145
|
}
|
|
175
146
|
if (typeof transformErrors === 'function') {
|
|
176
147
|
errors = transformErrors(errors, uiSchema);
|
|
177
148
|
}
|
|
178
|
-
|
|
149
|
+
let errorSchema = utils.toErrorSchema(errors);
|
|
179
150
|
if (invalidSchemaError) {
|
|
180
|
-
errorSchema =
|
|
151
|
+
errorSchema = {
|
|
152
|
+
...errorSchema,
|
|
181
153
|
$schema: {
|
|
182
154
|
__errors: [invalidSchemaError.message]
|
|
183
155
|
}
|
|
184
|
-
}
|
|
156
|
+
};
|
|
185
157
|
}
|
|
186
158
|
if (typeof customValidate !== 'function') {
|
|
187
159
|
return {
|
|
188
|
-
errors
|
|
189
|
-
errorSchema
|
|
160
|
+
errors,
|
|
161
|
+
errorSchema
|
|
190
162
|
};
|
|
191
163
|
}
|
|
192
164
|
// Include form data with undefined values, which is required for custom validation.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
165
|
+
const newFormData = utils.getDefaultFormState(validator, schema, formData, schema, true);
|
|
166
|
+
const errorHandler = customValidate(newFormData, utils.createErrorHandler(newFormData), uiSchema);
|
|
167
|
+
const userErrorSchema = utils.unwrapErrorHandler(errorHandler);
|
|
196
168
|
return utils.validationDataMerge({
|
|
197
|
-
errors
|
|
198
|
-
errorSchema
|
|
169
|
+
errors,
|
|
170
|
+
errorSchema
|
|
199
171
|
}, userErrorSchema);
|
|
200
172
|
}
|
|
201
173
|
|
|
202
174
|
/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.
|
|
203
175
|
*/
|
|
204
|
-
|
|
176
|
+
class AJV8Validator {
|
|
205
177
|
/** Constructs an `AJV8Validator` instance using the `options`
|
|
206
178
|
*
|
|
207
179
|
* @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance
|
|
208
180
|
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s
|
|
209
181
|
*/
|
|
210
|
-
|
|
182
|
+
constructor(options, localizer) {
|
|
211
183
|
/** The AJV instance to use for all validations
|
|
212
184
|
*
|
|
213
185
|
* @private
|
|
@@ -218,11 +190,13 @@
|
|
|
218
190
|
* @private
|
|
219
191
|
*/
|
|
220
192
|
this.localizer = void 0;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
193
|
+
const {
|
|
194
|
+
additionalMetaSchemas,
|
|
195
|
+
customFormats,
|
|
196
|
+
ajvOptionsOverrides,
|
|
197
|
+
ajvFormatOptions,
|
|
198
|
+
AjvClass
|
|
199
|
+
} = options;
|
|
226
200
|
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);
|
|
227
201
|
this.localizer = localizer;
|
|
228
202
|
}
|
|
@@ -233,11 +207,7 @@
|
|
|
233
207
|
* @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in
|
|
234
208
|
* the next major release.
|
|
235
209
|
*/
|
|
236
|
-
|
|
237
|
-
_proto.toErrorList = function toErrorList(errorSchema, fieldPath) {
|
|
238
|
-
if (fieldPath === void 0) {
|
|
239
|
-
fieldPath = [];
|
|
240
|
-
}
|
|
210
|
+
toErrorList(errorSchema, fieldPath = []) {
|
|
241
211
|
return utils.toErrorList(errorSchema, fieldPath);
|
|
242
212
|
}
|
|
243
213
|
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
@@ -245,10 +215,10 @@
|
|
|
245
215
|
*
|
|
246
216
|
* @param schema - The schema against which to validate the form data * @param schema
|
|
247
217
|
* @param formData - The form data to validate
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
218
|
+
*/
|
|
219
|
+
rawValidation(schema, formData) {
|
|
220
|
+
let compilationError = undefined;
|
|
221
|
+
let compiledValidator;
|
|
252
222
|
if (schema[utils.ID_KEY]) {
|
|
253
223
|
compiledValidator = this.ajv.getSchema(schema[utils.ID_KEY]);
|
|
254
224
|
}
|
|
@@ -260,7 +230,7 @@
|
|
|
260
230
|
} catch (err) {
|
|
261
231
|
compilationError = err;
|
|
262
232
|
}
|
|
263
|
-
|
|
233
|
+
let errors;
|
|
264
234
|
if (compiledValidator) {
|
|
265
235
|
if (typeof this.localizer === 'function') {
|
|
266
236
|
this.localizer(compiledValidator.errors);
|
|
@@ -284,9 +254,9 @@
|
|
|
284
254
|
* @param [customValidate] - An optional function that is used to perform custom validation
|
|
285
255
|
* @param [transformErrors] - An optional function that is used to transform errors after AJV validation
|
|
286
256
|
* @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
257
|
+
*/
|
|
258
|
+
validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
|
|
259
|
+
const rawErrors = this.rawValidation(schema, formData);
|
|
290
260
|
return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);
|
|
291
261
|
}
|
|
292
262
|
/** Validates data against a schema, returning true if the data is valid, or
|
|
@@ -296,12 +266,10 @@
|
|
|
296
266
|
* @param schema - The schema against which to validate the form data
|
|
297
267
|
* @param formData - The form data to validate
|
|
298
268
|
* @param rootSchema - The root schema used to provide $ref resolutions
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
var rootSchemaId = (_rootSchema$ID_KEY = rootSchema[utils.ID_KEY]) != null ? _rootSchema$ID_KEY : utils.ROOT_SCHEMA_PREFIX;
|
|
269
|
+
*/
|
|
270
|
+
isValid(schema, formData, rootSchema) {
|
|
271
|
+
const rootSchemaId = rootSchema[utils.ID_KEY] ?? utils.ROOT_SCHEMA_PREFIX;
|
|
303
272
|
try {
|
|
304
|
-
var _schemaWithIdRefPrefi;
|
|
305
273
|
// add the rootSchema ROOT_SCHEMA_PREFIX as id.
|
|
306
274
|
// then rewrite the schema ref's to point to the rootSchema
|
|
307
275
|
// this accounts for the case where schema have references to models
|
|
@@ -309,9 +277,9 @@
|
|
|
309
277
|
if (this.ajv.getSchema(rootSchemaId) === undefined) {
|
|
310
278
|
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
311
279
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
280
|
+
const schemaWithIdRefPrefix = utils.withIdRefPrefix(schema);
|
|
281
|
+
const schemaId = schemaWithIdRefPrefix[utils.ID_KEY] ?? utils.hashForSchema(schemaWithIdRefPrefix);
|
|
282
|
+
let compiledValidator;
|
|
315
283
|
compiledValidator = this.ajv.getSchema(schemaId);
|
|
316
284
|
if (compiledValidator === undefined) {
|
|
317
285
|
// Add schema by an explicit ID so it can be fetched later
|
|
@@ -319,7 +287,7 @@
|
|
|
319
287
|
// https://ajv.js.org/guide/managing-schemas.html#pre-adding-all-schemas-vs-adding-on-demand
|
|
320
288
|
compiledValidator = this.ajv.addSchema(schemaWithIdRefPrefix, schemaId).getSchema(schemaId) || this.ajv.compile(schemaWithIdRefPrefix);
|
|
321
289
|
}
|
|
322
|
-
|
|
290
|
+
const result = compiledValidator(formData);
|
|
323
291
|
return result;
|
|
324
292
|
} catch (e) {
|
|
325
293
|
console.warn('Error encountered compiling schema:', e);
|
|
@@ -329,9 +297,8 @@
|
|
|
329
297
|
// make sure we remove the rootSchema from the global ajv instance
|
|
330
298
|
this.ajv.removeSchema(rootSchemaId);
|
|
331
299
|
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
}();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
335
302
|
|
|
336
303
|
/** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if
|
|
337
304
|
* provided. If a `localizer` is provided, it is used to translate the messages generated by the underlying AJV
|
|
@@ -341,17 +308,14 @@
|
|
|
341
308
|
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s
|
|
342
309
|
* @returns - The custom validator implementation resulting from the set of parameters provided
|
|
343
310
|
*/
|
|
344
|
-
function customizeValidator(options, localizer) {
|
|
345
|
-
if (options === void 0) {
|
|
346
|
-
options = {};
|
|
347
|
-
}
|
|
311
|
+
function customizeValidator(options = {}, localizer) {
|
|
348
312
|
return new AJV8Validator(options, localizer);
|
|
349
313
|
}
|
|
350
314
|
|
|
351
315
|
/** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the
|
|
352
316
|
* `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.
|
|
353
317
|
*/
|
|
354
|
-
|
|
318
|
+
class AJV8PrecompiledValidator {
|
|
355
319
|
/** Constructs an `AJV8PrecompiledValidator` instance using the `validateFns` and `rootSchema`
|
|
356
320
|
*
|
|
357
321
|
* @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function
|
|
@@ -359,7 +323,7 @@
|
|
|
359
323
|
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s
|
|
360
324
|
* @throws - Error when the base schema of the precompiled validator does not have a matching validator function
|
|
361
325
|
*/
|
|
362
|
-
|
|
326
|
+
constructor(validateFns, rootSchema, localizer) {
|
|
363
327
|
/** The root schema object used to construct this validator
|
|
364
328
|
*
|
|
365
329
|
* @private
|
|
@@ -397,12 +361,11 @@
|
|
|
397
361
|
* @param schema - The schema for which a precompiled validator function is desired
|
|
398
362
|
* @returns - The precompiled validator function associated with this schema
|
|
399
363
|
*/
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
var validator = this.validateFns[key];
|
|
364
|
+
getValidator(schema) {
|
|
365
|
+
const key = get__default["default"](schema, utils.ID_KEY) || utils.hashForSchema(schema);
|
|
366
|
+
const validator = this.validateFns[key];
|
|
404
367
|
if (!validator) {
|
|
405
|
-
throw new Error(
|
|
368
|
+
throw new Error(`No precompiled validator function was found for the given schema for "${key}"`);
|
|
406
369
|
}
|
|
407
370
|
return validator;
|
|
408
371
|
}
|
|
@@ -412,11 +375,8 @@
|
|
|
412
375
|
* @param [fieldPath=[]] - The current field path, defaults to [] if not specified
|
|
413
376
|
* @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in
|
|
414
377
|
* the next major release.
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
if (fieldPath === void 0) {
|
|
418
|
-
fieldPath = [];
|
|
419
|
-
}
|
|
378
|
+
*/
|
|
379
|
+
toErrorList(errorSchema, fieldPath = []) {
|
|
420
380
|
return utils.toErrorList(errorSchema, fieldPath);
|
|
421
381
|
}
|
|
422
382
|
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
@@ -425,8 +385,8 @@
|
|
|
425
385
|
* @param schema - The schema against which to validate the form data * @param schema
|
|
426
386
|
* @param formData - The form data to validate
|
|
427
387
|
* @throws - Error when the schema provided does not match the base schema of the precompiled validator
|
|
428
|
-
|
|
429
|
-
|
|
388
|
+
*/
|
|
389
|
+
rawValidation(schema, formData) {
|
|
430
390
|
if (!isEqual__default["default"](schema, this.resolvedRootSchema)) {
|
|
431
391
|
throw new Error('The schema associated with the precompiled schema differs from the schema provided for validation');
|
|
432
392
|
}
|
|
@@ -434,7 +394,7 @@
|
|
|
434
394
|
if (typeof this.localizer === 'function') {
|
|
435
395
|
this.localizer(this.mainValidator.errors);
|
|
436
396
|
}
|
|
437
|
-
|
|
397
|
+
const errors = this.mainValidator.errors || undefined;
|
|
438
398
|
// Clear errors to prevent persistent errors, see #1104
|
|
439
399
|
this.mainValidator.errors = null;
|
|
440
400
|
return {
|
|
@@ -451,9 +411,9 @@
|
|
|
451
411
|
* @param [customValidate] - An optional function that is used to perform custom validation
|
|
452
412
|
* @param [transformErrors] - An optional function that is used to transform errors after AJV validation
|
|
453
413
|
* @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
414
|
+
*/
|
|
415
|
+
validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
|
|
416
|
+
const rawErrors = this.rawValidation(schema, formData);
|
|
457
417
|
return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);
|
|
458
418
|
}
|
|
459
419
|
/** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is
|
|
@@ -465,19 +425,18 @@
|
|
|
465
425
|
* @returns - true if the formData validates against the schema, false otherwise
|
|
466
426
|
* @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there
|
|
467
427
|
* isn't a precompiled validator function associated with the schema
|
|
468
|
-
|
|
469
|
-
|
|
428
|
+
*/
|
|
429
|
+
isValid(schema, formData, rootSchema) {
|
|
470
430
|
if (!isEqual__default["default"](rootSchema, this.rootSchema)) {
|
|
471
431
|
throw new Error('The schema associated with the precompiled validator differs from the rootSchema provided for validation');
|
|
472
432
|
}
|
|
473
433
|
if (get__default["default"](schema, utils.ID_KEY) === utils.JUNK_OPTION_ID) {
|
|
474
434
|
return false;
|
|
475
435
|
}
|
|
476
|
-
|
|
436
|
+
const validator = this.getValidator(schema);
|
|
477
437
|
return validator(formData);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
}();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
481
440
|
|
|
482
441
|
/** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`
|
|
483
442
|
* is provided, it is used to translate the messages generated by the underlying AJV validation.
|