@rjsf/utils 5.21.0 → 5.21.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.js +44 -33
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +44 -33
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +37 -38
- package/lib/ErrorSchemaBuilder.d.ts +3 -3
- package/lib/ErrorSchemaBuilder.js +2 -1
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/createSchemaUtils.js +1 -1
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/deepEquals.d.ts +1 -1
- package/lib/deepEquals.js +10 -34
- package/lib/deepEquals.js.map +1 -1
- package/lib/enumOptionsDeselectValue.js +3 -3
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.js +3 -3
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/parser/ParserValidator.js +3 -3
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/schemaParser.js +4 -4
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/schema/retrieveSchema.js +21 -7
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/toIdSchema.js +2 -2
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.js +3 -3
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/src/ErrorSchemaBuilder.ts +6 -5
- package/src/createSchemaUtils.ts +1 -1
- package/src/deepEquals.ts +10 -37
- package/src/enumOptionsDeselectValue.ts +4 -3
- package/src/enumOptionsIsSelected.ts +4 -3
- package/src/parser/ParserValidator.ts +3 -3
- package/src/parser/schemaParser.ts +4 -4
- package/src/schema/retrieveSchema.ts +20 -8
- package/src/schema/toIdSchema.ts +2 -2
- package/src/schema/toPathSchema.ts +3 -3
package/src/deepEquals.ts
CHANGED
|
@@ -1,37 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import isEqualWith from 'lodash/isEqualWith';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param a - The first element to check typeof
|
|
6
|
-
* @param b - The second element to check typeof
|
|
7
|
-
* @returns - if typeof a and b are equal to function return true, otherwise false
|
|
8
|
-
*/
|
|
9
|
-
function isFunctions(a: any, b: any) {
|
|
10
|
-
return typeof a === 'function' && typeof b === 'function';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Implements a deep equals using the `fast-equal.createCustomEqual` function, that provides a customized comparator that
|
|
14
|
-
* assumes all functions in objects are equivalent.
|
|
15
|
-
*
|
|
16
|
-
* @param a - The first element to compare
|
|
17
|
-
* @param b - The second element to compare
|
|
18
|
-
* @returns - True if the `a` and `b` are deeply equal, false otherwise
|
|
19
|
-
*/
|
|
20
|
-
const customDeepEqual = createCustomEqual({
|
|
21
|
-
createInternalComparator: (comparator: (a: any, b: any, state: State<any>) => boolean) => {
|
|
22
|
-
return (a: any, b: any, _idxA: any, _idxB: any, _parentA: any, _parentB: any, state: State<any>) => {
|
|
23
|
-
if (isFunctions(a, b)) {
|
|
24
|
-
// Assume all functions are equivalent
|
|
25
|
-
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return comparator(a, b, state);
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
/** Implements a deep equals using the `fast-equal.createCustomEqual` function, that provides a customized comparator that
|
|
3
|
+
/** Implements a deep equals using the `lodash.isEqualWith` function, that provides a customized comparator that
|
|
35
4
|
* assumes all functions are equivalent.
|
|
36
5
|
*
|
|
37
6
|
* @param a - The first element to compare
|
|
@@ -39,8 +8,12 @@ const customDeepEqual = createCustomEqual({
|
|
|
39
8
|
* @returns - True if the `a` and `b` are deeply equal, false otherwise
|
|
40
9
|
*/
|
|
41
10
|
export default function deepEquals(a: any, b: any): boolean {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
11
|
+
return isEqualWith(a, b, (obj: any, other: any) => {
|
|
12
|
+
if (typeof obj === 'function' && typeof other === 'function') {
|
|
13
|
+
// Assume all functions are equivalent
|
|
14
|
+
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return undefined; // fallback to default isEquals behavior
|
|
18
|
+
});
|
|
46
19
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import isEqual from 'lodash/isEqual';
|
|
2
|
+
|
|
1
3
|
import { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
4
|
import enumOptionsValueForIndex from './enumOptionsValueForIndex';
|
|
3
|
-
import deepEquals from './deepEquals';
|
|
4
5
|
|
|
5
6
|
/** Removes the enum option value at the `valueIndex` from the currently `selected` (list of) value(s). If `selected` is
|
|
6
7
|
* a list, then that list is updated to remove the enum option value with the `valueIndex` in `allEnumOptions`. If it is
|
|
@@ -21,7 +22,7 @@ export default function enumOptionsDeselectValue<S extends StrictRJSFSchema = RJ
|
|
|
21
22
|
): EnumOptionsType<S>['value'] | EnumOptionsType<S>['value'][] | undefined {
|
|
22
23
|
const value = enumOptionsValueForIndex<S>(valueIndex, allEnumOptions);
|
|
23
24
|
if (Array.isArray(selected)) {
|
|
24
|
-
return selected.filter((v) => !
|
|
25
|
+
return selected.filter((v) => !isEqual(v, value));
|
|
25
26
|
}
|
|
26
|
-
return
|
|
27
|
+
return isEqual(value, selected) ? undefined : selected;
|
|
27
28
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import isEqual from 'lodash/isEqual';
|
|
2
|
+
|
|
2
3
|
import { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
4
|
|
|
4
5
|
/** Determines whether the given `value` is (one of) the `selected` value(s).
|
|
@@ -12,7 +13,7 @@ export default function enumOptionsIsSelected<S extends StrictRJSFSchema = RJSFS
|
|
|
12
13
|
selected: EnumOptionsType<S>['value'] | EnumOptionsType<S>['value'][]
|
|
13
14
|
) {
|
|
14
15
|
if (Array.isArray(selected)) {
|
|
15
|
-
return selected.some((sel) =>
|
|
16
|
+
return selected.some((sel) => isEqual(sel, value));
|
|
16
17
|
}
|
|
17
|
-
return
|
|
18
|
+
return isEqual(selected, value);
|
|
18
19
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
+
import isEqual from 'lodash/isEqual';
|
|
2
3
|
|
|
3
4
|
import { ID_KEY } from '../constants';
|
|
4
5
|
import hashForSchema from '../hashForSchema';
|
|
@@ -14,7 +15,6 @@ import {
|
|
|
14
15
|
ValidationData,
|
|
15
16
|
ValidatorType,
|
|
16
17
|
} from '../types';
|
|
17
|
-
import deepEquals from '../deepEquals';
|
|
18
18
|
|
|
19
19
|
/** The type of the map of schema hash to schema
|
|
20
20
|
*/
|
|
@@ -67,7 +67,7 @@ export default class ParserValidator<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
67
67
|
const existing = this.schemaMap[key];
|
|
68
68
|
if (!existing) {
|
|
69
69
|
this.schemaMap[key] = identifiedSchema;
|
|
70
|
-
} else if (!
|
|
70
|
+
} else if (!isEqual(existing, identifiedSchema)) {
|
|
71
71
|
console.error('existing schema:', JSON.stringify(existing, null, 2));
|
|
72
72
|
console.error('new schema:', JSON.stringify(identifiedSchema, null, 2));
|
|
73
73
|
throw new Error(
|
|
@@ -91,7 +91,7 @@ export default class ParserValidator<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
91
91
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
92
92
|
*/
|
|
93
93
|
isValid(schema: S, _formData: T, rootSchema: S): boolean {
|
|
94
|
-
if (!
|
|
94
|
+
if (!isEqual(rootSchema, this.rootSchema)) {
|
|
95
95
|
throw new Error('Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema');
|
|
96
96
|
}
|
|
97
97
|
this.addSchema(schema, hashForSchema<S>(schema));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import forEach from 'lodash/forEach';
|
|
2
|
+
import isEqual from 'lodash/isEqual';
|
|
2
3
|
|
|
3
4
|
import { FormContextType, RJSFSchema, StrictRJSFSchema } from '../types';
|
|
4
|
-
import {
|
|
5
|
+
import { PROPERTIES_KEY, ITEMS_KEY } from '../constants';
|
|
5
6
|
import ParserValidator, { SchemaMap } from './ParserValidator';
|
|
6
|
-
import {
|
|
7
|
-
import deepEquals from '../deepEquals';
|
|
7
|
+
import { retrieveSchemaInternal, resolveAnyOrOneOfSchemas } from '../schema/retrieveSchema';
|
|
8
8
|
|
|
9
9
|
/** Recursive function used to parse the given `schema` belonging to the `rootSchema`. The `validator` is used to
|
|
10
10
|
* capture the sub-schemas that the `isValid()` function is called with. For each schema returned by the
|
|
@@ -24,7 +24,7 @@ function parseSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
24
24
|
) {
|
|
25
25
|
const schemas = retrieveSchemaInternal<T, S, F>(validator, schema, rootSchema, undefined, true);
|
|
26
26
|
schemas.forEach((schema) => {
|
|
27
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
27
|
+
const sameSchemaIndex = recurseList.findIndex((item) => isEqual(item, schema));
|
|
28
28
|
if (sameSchemaIndex === -1) {
|
|
29
29
|
recurseList.push(schema);
|
|
30
30
|
const allOptions = resolveAnyOrOneOfSchemas<T, S, F>(validator, schema, rootSchema, true);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
+
import isEqual from 'lodash/isEqual';
|
|
2
3
|
import set from 'lodash/set';
|
|
3
4
|
import times from 'lodash/times';
|
|
4
5
|
import transform from 'lodash/transform';
|
|
@@ -14,10 +15,10 @@ import {
|
|
|
14
15
|
ANY_OF_KEY,
|
|
15
16
|
DEPENDENCIES_KEY,
|
|
16
17
|
IF_KEY,
|
|
17
|
-
ITEMS_KEY,
|
|
18
18
|
ONE_OF_KEY,
|
|
19
|
-
PROPERTIES_KEY,
|
|
20
19
|
REF_KEY,
|
|
20
|
+
PROPERTIES_KEY,
|
|
21
|
+
ITEMS_KEY,
|
|
21
22
|
} from '../constants';
|
|
22
23
|
import findSchemaDefinition, { splitKeyElementFromObject } from '../findSchemaDefinition';
|
|
23
24
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
@@ -26,7 +27,6 @@ import isObject from '../isObject';
|
|
|
26
27
|
import mergeSchemas from '../mergeSchemas';
|
|
27
28
|
import { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
28
29
|
import getFirstMatchingOption from './getFirstMatchingOption';
|
|
29
|
-
import deepEquals from '../deepEquals';
|
|
30
30
|
|
|
31
31
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
|
|
32
32
|
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
|
|
@@ -196,10 +196,7 @@ export function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
196
196
|
)
|
|
197
197
|
);
|
|
198
198
|
const allPermutations = getAllPermutationsOfXxxOf<S>(allOfSchemaElements);
|
|
199
|
-
return allPermutations.map((permutation) => ({
|
|
200
|
-
...schema,
|
|
201
|
-
allOf: permutation,
|
|
202
|
-
}));
|
|
199
|
+
return allPermutations.map((permutation) => ({ ...schema, allOf: permutation }));
|
|
203
200
|
}
|
|
204
201
|
// No $ref or dependencies or allOf attribute was found, returning the original schema.
|
|
205
202
|
return [schema];
|
|
@@ -296,7 +293,7 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
296
293
|
};
|
|
297
294
|
}
|
|
298
295
|
|
|
299
|
-
return
|
|
296
|
+
return isEqual(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
300
297
|
}
|
|
301
298
|
|
|
302
299
|
/** Creates new 'properties' items for each key in the `formData`
|
|
@@ -415,9 +412,24 @@ export function retrieveSchemaInternal<
|
|
|
415
412
|
return [...(allOf as S[]), restOfSchema as S];
|
|
416
413
|
}
|
|
417
414
|
try {
|
|
415
|
+
const withContainsSchemas = [] as S[];
|
|
416
|
+
const withoutContainsSchemas = [] as S[];
|
|
417
|
+
resolvedSchema.allOf?.forEach((s) => {
|
|
418
|
+
if (typeof s === 'object' && s.contains) {
|
|
419
|
+
withContainsSchemas.push(s as S);
|
|
420
|
+
} else {
|
|
421
|
+
withoutContainsSchemas.push(s as S);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
if (withContainsSchemas.length) {
|
|
425
|
+
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
426
|
+
}
|
|
418
427
|
resolvedSchema = mergeAllOf(resolvedSchema, {
|
|
419
428
|
deep: false,
|
|
420
429
|
} as Options) as S;
|
|
430
|
+
if (withContainsSchemas.length) {
|
|
431
|
+
resolvedSchema.allOf = withContainsSchemas;
|
|
432
|
+
}
|
|
421
433
|
} catch (e) {
|
|
422
434
|
console.warn('could not merge subschemas in allOf:\n', e);
|
|
423
435
|
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
|
package/src/schema/toIdSchema.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
+
import isEqual from 'lodash/isEqual';
|
|
2
3
|
|
|
3
4
|
import { ALL_OF_KEY, DEPENDENCIES_KEY, ID_KEY, ITEMS_KEY, PROPERTIES_KEY, REF_KEY } from '../constants';
|
|
4
5
|
import isObject from '../isObject';
|
|
5
6
|
import { FormContextType, GenericObjectType, IdSchema, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
6
7
|
import retrieveSchema from './retrieveSchema';
|
|
7
8
|
import getSchemaType from '../getSchemaType';
|
|
8
|
-
import deepEquals from '../deepEquals';
|
|
9
9
|
|
|
10
10
|
/** An internal helper that generates an `IdSchema` object for the `schema`, recursively with protection against
|
|
11
11
|
* infinite recursion
|
|
@@ -32,7 +32,7 @@ function toIdSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
32
32
|
): IdSchema<T> {
|
|
33
33
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
34
34
|
const _schema = retrieveSchema<T, S, F>(validator, schema, rootSchema, formData);
|
|
35
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
35
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual(item, _schema));
|
|
36
36
|
if (sameSchemaIndex === -1) {
|
|
37
37
|
return toIdSchemaInternal<T, S, F>(
|
|
38
38
|
validator,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
+
import isEqual from 'lodash/isEqual';
|
|
2
3
|
import set from 'lodash/set';
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
|
-
ADDITIONAL_PROPERTIES_KEY,
|
|
6
6
|
ALL_OF_KEY,
|
|
7
7
|
ANY_OF_KEY,
|
|
8
|
+
ADDITIONAL_PROPERTIES_KEY,
|
|
8
9
|
DEPENDENCIES_KEY,
|
|
9
10
|
ITEMS_KEY,
|
|
10
11
|
NAME_KEY,
|
|
@@ -17,7 +18,6 @@ import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema'
|
|
|
17
18
|
import { FormContextType, GenericObjectType, PathSchema, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
18
19
|
import getClosestMatchingOption from './getClosestMatchingOption';
|
|
19
20
|
import retrieveSchema from './retrieveSchema';
|
|
20
|
-
import deepEquals from '../deepEquals';
|
|
21
21
|
|
|
22
22
|
/** An internal helper that generates an `PathSchema` object for the `schema`, recursively with protection against
|
|
23
23
|
* infinite recursion
|
|
@@ -40,7 +40,7 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
40
40
|
): PathSchema<T> {
|
|
41
41
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
42
42
|
const _schema = retrieveSchema<T, S, F>(validator, schema, rootSchema, formData);
|
|
43
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
43
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual(item, _schema));
|
|
44
44
|
if (sameSchemaIndex === -1) {
|
|
45
45
|
return toPathSchemaInternal<T, S, F>(
|
|
46
46
|
validator,
|