@rjsf/validator-ata 6.6.1 → 6.6.2
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.map +2 -2
- package/dist/compileSchemaValidators.esm.js.map +2 -2
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +2 -2
- package/dist/validator-ata.esm.js +8 -20
- package/dist/validator-ata.esm.js.map +2 -2
- package/dist/validator-ata.umd.js +6 -6
- package/lib/compileSchemaValidators.d.ts +2 -2
- package/lib/compileSchemaValidators.js +2 -0
- package/lib/compileSchemaValidators.js.map +1 -1
- package/lib/compileSchemaValidatorsCode.d.ts +2 -2
- package/lib/compileSchemaValidatorsCode.js +1 -1
- package/lib/compileSchemaValidatorsCode.js.map +1 -1
- package/lib/createAtaInstance.js.map +1 -1
- package/lib/createPrecompiledValidator.d.ts +2 -2
- package/lib/customizeValidator.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/precompiledValidator.d.ts +3 -3
- package/lib/precompiledValidator.js +1 -1
- package/lib/precompiledValidator.js.map +1 -1
- package/lib/processRawValidationErrors.d.ts +3 -3
- package/lib/processRawValidationErrors.js +2 -2
- package/lib/processRawValidationErrors.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +3 -7
- package/lib/validator.d.ts +2 -2
- package/lib/validator.js +5 -5
- package/lib/validator.js.map +1 -1
- package/package.json +2 -2
- package/src/compileSchemaValidators.ts +4 -2
- package/src/compileSchemaValidatorsCode.ts +4 -3
- package/src/createAtaInstance.ts +1 -1
- package/src/createPrecompiledValidator.ts +2 -2
- package/src/customizeValidator.ts +1 -1
- package/src/index.ts +1 -1
- package/src/precompiledValidator.ts +5 -8
- package/src/processRawValidationErrors.ts +18 -16
- package/src/types.ts +3 -5
- package/src/validator.ts +9 -13
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ANY_OF_KEY,
|
|
3
|
-
createErrorHandler,
|
|
1
|
+
import type {
|
|
4
2
|
CustomValidator,
|
|
5
3
|
ErrorTransformer,
|
|
6
4
|
FormContextType,
|
|
5
|
+
RJSFSchema,
|
|
6
|
+
RJSFValidationError,
|
|
7
|
+
StrictRJSFSchema,
|
|
8
|
+
UiSchema,
|
|
9
|
+
ValidatorType,
|
|
10
|
+
} from '@rjsf/utils';
|
|
11
|
+
import {
|
|
12
|
+
ANY_OF_KEY,
|
|
13
|
+
createErrorHandler,
|
|
7
14
|
getDefaultFormState,
|
|
8
15
|
getUiOptions,
|
|
9
16
|
ONE_OF_KEY,
|
|
10
17
|
PROPERTIES_KEY,
|
|
11
|
-
RJSFSchema,
|
|
12
|
-
RJSFValidationError,
|
|
13
|
-
StrictRJSFSchema,
|
|
14
18
|
toErrorSchema,
|
|
15
|
-
UiSchema,
|
|
16
19
|
unwrapErrorHandler,
|
|
17
20
|
validationDataMerge,
|
|
18
|
-
ValidatorType,
|
|
19
21
|
} from '@rjsf/utils';
|
|
20
22
|
import type { ValidationError } from 'ata-validator';
|
|
21
23
|
import get from 'lodash/get';
|
|
22
24
|
|
|
23
25
|
import type { SuppressDuplicateFilteringType } from './types';
|
|
24
26
|
|
|
25
|
-
export
|
|
27
|
+
export interface RawValidationErrorsType<Result = any> {
|
|
26
28
|
errors?: Result[];
|
|
27
29
|
validationError?: Error;
|
|
28
|
-
}
|
|
30
|
+
}
|
|
29
31
|
|
|
30
32
|
/** Filters duplicate errors from `anyOf`/`oneOf` schema paths according to
|
|
31
33
|
* the `suppressDuplicateFiltering` flag. Mirrors the `@rjsf/validator-ajv8`
|
|
@@ -40,7 +42,7 @@ export function filterDuplicateErrors(
|
|
|
40
42
|
if (suppressDuplicateFiltering === 'all') {
|
|
41
43
|
return errorList;
|
|
42
44
|
}
|
|
43
|
-
return errorList.reduce((acc: RJSFValidationError[], err: RJSFValidationError) => {
|
|
45
|
+
return errorList.reduce<RJSFValidationError[]>((acc: RJSFValidationError[], err: RJSFValidationError) => {
|
|
44
46
|
const { message, schemaPath } = err;
|
|
45
47
|
const anyOfIndex = suppressDuplicateFiltering !== 'anyOf' ? schemaPath?.indexOf(`/${ANY_OF_KEY}/`) : undefined;
|
|
46
48
|
const oneOfIndex = suppressDuplicateFiltering !== 'oneOf' ? schemaPath?.indexOf(`/${ONE_OF_KEY}/`) : undefined;
|
|
@@ -57,7 +59,7 @@ export function filterDuplicateErrors(
|
|
|
57
59
|
acc.push(err);
|
|
58
60
|
}
|
|
59
61
|
return acc;
|
|
60
|
-
}, []
|
|
62
|
+
}, []);
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
/** Transforms ata-validator errors into the RJSF-internal `RJSFValidationError`
|
|
@@ -91,7 +93,7 @@ export function transformRJSFValidationErrors<
|
|
|
91
93
|
if (rawPropertyNames.length > 0) {
|
|
92
94
|
rawPropertyNames.forEach((currentProperty) => {
|
|
93
95
|
const path = property ? `${property}.${currentProperty}` : currentProperty;
|
|
94
|
-
let uiSchemaTitle = getUiOptions(get(uiSchema,
|
|
96
|
+
let uiSchemaTitle = getUiOptions(get(uiSchema, path.replace(/^\./, ''))).title;
|
|
95
97
|
if (uiSchemaTitle === undefined) {
|
|
96
98
|
const uiSchemaPath = schemaPath
|
|
97
99
|
.replace(/\/properties\//g, '/')
|
|
@@ -114,7 +116,7 @@ export function transformRJSFValidationErrors<
|
|
|
114
116
|
|
|
115
117
|
stack = message;
|
|
116
118
|
} else {
|
|
117
|
-
const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema,
|
|
119
|
+
const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema, property.replace(/^\./, ''))).title;
|
|
118
120
|
|
|
119
121
|
if (uiSchemaTitle) {
|
|
120
122
|
stack = `'${uiSchemaTitle}' ${message}`.trim();
|
|
@@ -168,7 +170,7 @@ export default function processRawValidationErrors<
|
|
|
168
170
|
let errors = transformRJSFValidationErrors<T, S, F>(rawErrors.errors, uiSchema, suppressDuplicateFiltering);
|
|
169
171
|
|
|
170
172
|
if (invalidSchemaError) {
|
|
171
|
-
errors = [...errors, { stack: invalidSchemaError
|
|
173
|
+
errors = [...errors, { stack: invalidSchemaError.message }];
|
|
172
174
|
}
|
|
173
175
|
if (typeof transformErrors === 'function') {
|
|
174
176
|
errors = transformErrors(errors, uiSchema);
|
|
@@ -180,7 +182,7 @@ export default function processRawValidationErrors<
|
|
|
180
182
|
errorSchema = {
|
|
181
183
|
...errorSchema,
|
|
182
184
|
$schema: {
|
|
183
|
-
__errors: [invalidSchemaError
|
|
185
|
+
__errors: [invalidSchemaError.message],
|
|
184
186
|
},
|
|
185
187
|
};
|
|
186
188
|
}
|
package/src/types.ts
CHANGED
|
@@ -32,15 +32,13 @@ export interface CustomValidatorOptionsType {
|
|
|
32
32
|
* Mirrors `ajv.addMetaSchema` / `ajv.addSchema` semantics; ata resolves
|
|
33
33
|
* `$ref` against the registered set.
|
|
34
34
|
*/
|
|
35
|
-
additionalMetaSchemas?:
|
|
35
|
+
additionalMetaSchemas?: readonly object[];
|
|
36
36
|
|
|
37
37
|
/** Custom format checkers. Keys are format names referenced from `format`
|
|
38
38
|
* in the schema. Values are validation functions, RegExps, or pre-anchored
|
|
39
39
|
* regex source strings (compiled into a function for ata).
|
|
40
40
|
*/
|
|
41
|
-
customFormats?:
|
|
42
|
-
[k: string]: string | RegExp | AtaFormatChecker;
|
|
43
|
-
};
|
|
41
|
+
customFormats?: Record<string, string | RegExp | AtaFormatChecker>;
|
|
44
42
|
|
|
45
43
|
/** Overrides spread on top of the default `ata-validator` options. Use this
|
|
46
44
|
* to flip `coerceTypes`, `removeAdditional`, `verbose`, or `abortEarly`.
|
|
@@ -68,4 +66,4 @@ export interface CompiledValidateFunction {
|
|
|
68
66
|
(data: unknown): boolean;
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
export type ValidatorFunctions =
|
|
69
|
+
export type ValidatorFunctions = Record<string, CompiledValidateFunction>;
|
package/src/validator.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CustomValidator,
|
|
3
|
-
deepEquals,
|
|
4
3
|
ErrorTransformer,
|
|
5
4
|
FormContextType,
|
|
6
|
-
hashForSchema,
|
|
7
|
-
ID_KEY,
|
|
8
5
|
RJSFSchema,
|
|
9
|
-
ROOT_SCHEMA_PREFIX,
|
|
10
6
|
StrictRJSFSchema,
|
|
11
7
|
UiSchema,
|
|
12
8
|
ValidationData,
|
|
13
9
|
ValidatorType,
|
|
14
|
-
withIdRefPrefix,
|
|
15
10
|
} from '@rjsf/utils';
|
|
11
|
+
import { deepEquals, hashForSchema, ID_KEY, ROOT_SCHEMA_PREFIX, withIdRefPrefix } from '@rjsf/utils';
|
|
16
12
|
import type { ValidationError, Validator } from 'ata-validator';
|
|
17
13
|
import cloneDeep from 'lodash/cloneDeep';
|
|
18
14
|
|
|
@@ -96,7 +92,7 @@ export default class ATAValidator<
|
|
|
96
92
|
* a mutated probe changes subsequent answers, so the wrapper has to
|
|
97
93
|
* preserve referential purity that AJV provides by default.
|
|
98
94
|
*/
|
|
99
|
-
private cloneForValidation<D>(data: D): D {
|
|
95
|
+
private static cloneForValidation<D>(data: D): D {
|
|
100
96
|
if (data === null || typeof data !== 'object') {
|
|
101
97
|
return data;
|
|
102
98
|
}
|
|
@@ -141,9 +137,9 @@ export default class ATAValidator<
|
|
|
141
137
|
let errors: ValidationError[] | undefined;
|
|
142
138
|
|
|
143
139
|
try {
|
|
144
|
-
const id =
|
|
140
|
+
const id = schema[ID_KEY] ?? hashForSchema(schema);
|
|
145
141
|
const validator = this.getOrBuild(id, schema);
|
|
146
|
-
const result = validator.validate(
|
|
142
|
+
const result = validator.validate(ATAValidator.cloneForValidation(formData));
|
|
147
143
|
errors = result.valid ? undefined : result.errors;
|
|
148
144
|
|
|
149
145
|
if (errors && typeof this.localizer === 'function') {
|
|
@@ -195,7 +191,7 @@ export default class ATAValidator<
|
|
|
195
191
|
if (this.lastSeenRootSchema === rootSchema && this.hasRegisteredRootSchema) {
|
|
196
192
|
return;
|
|
197
193
|
}
|
|
198
|
-
const rootSchemaId =
|
|
194
|
+
const rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX;
|
|
199
195
|
// Inject $id into a copy of the rootSchema so ata's schema registry can
|
|
200
196
|
// resolve `<rootSchemaId>#/...` refs produced by `withIdRefPrefix`.
|
|
201
197
|
// The original user-supplied schema is left untouched.
|
|
@@ -219,11 +215,11 @@ export default class ATAValidator<
|
|
|
219
215
|
try {
|
|
220
216
|
this.handleSchemaUpdate(rootSchema);
|
|
221
217
|
const schemaWithIdRefPrefix = withIdRefPrefix<S>(schema) as S;
|
|
222
|
-
const id =
|
|
218
|
+
const id = schemaWithIdRefPrefix[ID_KEY] ?? hashForSchema(schemaWithIdRefPrefix);
|
|
223
219
|
const validator = this.getOrBuild(id, schemaWithIdRefPrefix);
|
|
224
|
-
return validator.validate(
|
|
220
|
+
return validator.validate(ATAValidator.cloneForValidation(formData)).valid;
|
|
225
221
|
} catch (e) {
|
|
226
|
-
//
|
|
222
|
+
// oxlint-disable-next-line no-console
|
|
227
223
|
console.warn('Error encountered compiling schema:', e);
|
|
228
224
|
return false;
|
|
229
225
|
}
|