@rjsf/validator-ajv8 6.5.0 → 6.5.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/index.cjs +14 -0
- package/dist/index.cjs.map +2 -2
- package/dist/validator-ajv8.esm.js +14 -0
- package/dist/validator-ajv8.esm.js.map +2 -2
- package/dist/validator-ajv8.umd.js +14 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/validator.d.ts +12 -0
- package/lib/validator.js +14 -0
- package/lib/validator.js.map +1 -1
- package/package.json +3 -3
- package/src/validator.ts +21 -0
package/lib/validator.d.ts
CHANGED
|
@@ -20,6 +20,16 @@ export default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
20
20
|
* @private
|
|
21
21
|
*/
|
|
22
22
|
readonly suppressDuplicateFiltering?: SuppressDuplicateFilteringType;
|
|
23
|
+
/** Most recent `rootSchema` reference processed by `handleSchemaUpdate`.
|
|
24
|
+
*
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
private lastSeenRootSchema?;
|
|
28
|
+
/** True once a `rootSchema` has been registered with Ajv in this lifecycle.
|
|
29
|
+
*
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
private hasRegisteredRootSchema;
|
|
23
33
|
/** Constructs an `AJV8Validator` instance using the `options`
|
|
24
34
|
*
|
|
25
35
|
* @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance
|
|
@@ -50,6 +60,8 @@ export default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
50
60
|
validateFormData(formData: T | undefined, schema: S, customValidate?: CustomValidator<T, S, F>, transformErrors?: ErrorTransformer<T, S, F>, uiSchema?: UiSchema<T, S, F>): ValidationData<T>;
|
|
51
61
|
/**
|
|
52
62
|
* This function checks if a schema needs to be added and if the root schemas don't match it removes the old root schema from the ajv instance and adds the new one.
|
|
63
|
+
* When called repeatedly with the same `rootSchema` reference the deep-equality check is skipped.
|
|
64
|
+
*
|
|
53
65
|
* @param rootSchema - The root schema used to provide $ref resolutions
|
|
54
66
|
*/
|
|
55
67
|
handleSchemaUpdate(rootSchema: S): void;
|
package/lib/validator.js
CHANGED
|
@@ -10,6 +10,11 @@ export default class AJV8Validator {
|
|
|
10
10
|
* @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s
|
|
11
11
|
*/
|
|
12
12
|
constructor(options, localizer) {
|
|
13
|
+
/** True once a `rootSchema` has been registered with Ajv in this lifecycle.
|
|
14
|
+
*
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
this.hasRegisteredRootSchema = false;
|
|
13
18
|
const { additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass, extenderFn, suppressDuplicateFiltering, } = options;
|
|
14
19
|
this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass, extenderFn);
|
|
15
20
|
this.localizer = localizer;
|
|
@@ -19,6 +24,8 @@ export default class AJV8Validator {
|
|
|
19
24
|
*/
|
|
20
25
|
reset() {
|
|
21
26
|
this.ajv.removeSchema();
|
|
27
|
+
this.lastSeenRootSchema = undefined;
|
|
28
|
+
this.hasRegisteredRootSchema = false;
|
|
22
29
|
}
|
|
23
30
|
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
24
31
|
* by the playground. Returns the `errors` from the validation
|
|
@@ -110,10 +117,15 @@ export default class AJV8Validator {
|
|
|
110
117
|
}
|
|
111
118
|
/**
|
|
112
119
|
* This function checks if a schema needs to be added and if the root schemas don't match it removes the old root schema from the ajv instance and adds the new one.
|
|
120
|
+
* When called repeatedly with the same `rootSchema` reference the deep-equality check is skipped.
|
|
121
|
+
*
|
|
113
122
|
* @param rootSchema - The root schema used to provide $ref resolutions
|
|
114
123
|
*/
|
|
115
124
|
handleSchemaUpdate(rootSchema) {
|
|
116
125
|
var _a, _b;
|
|
126
|
+
if (this.lastSeenRootSchema === rootSchema && this.hasRegisteredRootSchema) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
117
129
|
const rootSchemaId = (_a = rootSchema[ID_KEY]) !== null && _a !== void 0 ? _a : ROOT_SCHEMA_PREFIX;
|
|
118
130
|
// add the rootSchema ROOT_SCHEMA_PREFIX as id.
|
|
119
131
|
// if schema validator instance doesn't exist, add it.
|
|
@@ -125,6 +137,8 @@ export default class AJV8Validator {
|
|
|
125
137
|
this.ajv.removeSchema(rootSchemaId);
|
|
126
138
|
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
127
139
|
}
|
|
140
|
+
this.lastSeenRootSchema = rootSchema;
|
|
141
|
+
this.hasRegisteredRootSchema = true;
|
|
128
142
|
}
|
|
129
143
|
/** Validates data against a schema, returning true if the data is valid, or
|
|
130
144
|
* false otherwise. If the schema is invalid, then this function will return
|
package/lib/validator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,UAAU,EAGV,MAAM,EAEN,kBAAkB,EAKlB,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAC;AAGrB,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,0BAAuD,MAAM,8BAA8B,CAAC;AAEnG;GACG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,UAAU,EAGV,MAAM,EAEN,kBAAkB,EAKlB,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAC;AAGrB,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,0BAAuD,MAAM,8BAA8B,CAAC;AAEnG;GACG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAmChC;;;;OAIG;IACH,YAAY,OAAmC,EAAE,SAAqB;QAXtE;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AAC,GAAG,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;YAC5C,CAAC;YACD,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;YAC3C,OAAO,MAAiB,CAAC;QAC3B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,qCAAqC,EAAE,CAAC,CAAC,CAAC;YACvD,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/validator-ajv8",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -83,10 +83,10 @@
|
|
|
83
83
|
"lodash-es": "^4.18.1"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
|
-
"@rjsf/utils": "^6.
|
|
86
|
+
"@rjsf/utils": "^6.5.x"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
|
-
"@rjsf/utils": "6.5.
|
|
89
|
+
"@rjsf/utils": "6.5.2",
|
|
90
90
|
"@types/json-schema": "^7.0.15",
|
|
91
91
|
"ajv-i18n": "^4.2.0",
|
|
92
92
|
"eslint": "^8.57.1"
|
package/src/validator.ts
CHANGED
|
@@ -44,6 +44,18 @@ export default class AJV8Validator<
|
|
|
44
44
|
*/
|
|
45
45
|
readonly suppressDuplicateFiltering?: SuppressDuplicateFilteringType;
|
|
46
46
|
|
|
47
|
+
/** Most recent `rootSchema` reference processed by `handleSchemaUpdate`.
|
|
48
|
+
*
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
private lastSeenRootSchema?: S;
|
|
52
|
+
|
|
53
|
+
/** True once a `rootSchema` has been registered with Ajv in this lifecycle.
|
|
54
|
+
*
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
private hasRegisteredRootSchema = false;
|
|
58
|
+
|
|
47
59
|
/** Constructs an `AJV8Validator` instance using the `options`
|
|
48
60
|
*
|
|
49
61
|
* @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance
|
|
@@ -75,6 +87,8 @@ export default class AJV8Validator<
|
|
|
75
87
|
*/
|
|
76
88
|
reset() {
|
|
77
89
|
this.ajv.removeSchema();
|
|
90
|
+
this.lastSeenRootSchema = undefined;
|
|
91
|
+
this.hasRegisteredRootSchema = false;
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
/** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
|
|
@@ -181,9 +195,14 @@ export default class AJV8Validator<
|
|
|
181
195
|
|
|
182
196
|
/**
|
|
183
197
|
* This function checks if a schema needs to be added and if the root schemas don't match it removes the old root schema from the ajv instance and adds the new one.
|
|
198
|
+
* When called repeatedly with the same `rootSchema` reference the deep-equality check is skipped.
|
|
199
|
+
*
|
|
184
200
|
* @param rootSchema - The root schema used to provide $ref resolutions
|
|
185
201
|
*/
|
|
186
202
|
handleSchemaUpdate(rootSchema: S): void {
|
|
203
|
+
if (this.lastSeenRootSchema === rootSchema && this.hasRegisteredRootSchema) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
187
206
|
const rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX;
|
|
188
207
|
// add the rootSchema ROOT_SCHEMA_PREFIX as id.
|
|
189
208
|
// if schema validator instance doesn't exist, add it.
|
|
@@ -194,6 +213,8 @@ export default class AJV8Validator<
|
|
|
194
213
|
this.ajv.removeSchema(rootSchemaId);
|
|
195
214
|
this.ajv.addSchema(rootSchema, rootSchemaId);
|
|
196
215
|
}
|
|
216
|
+
this.lastSeenRootSchema = rootSchema;
|
|
217
|
+
this.hasRegisteredRootSchema = true;
|
|
197
218
|
}
|
|
198
219
|
|
|
199
220
|
/** Validates data against a schema, returning true if the data is valid, or
|