@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/dist/utils.esm.js
CHANGED
|
@@ -128,25 +128,14 @@ function createErrorHandler(formData) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// src/deepEquals.ts
|
|
131
|
-
import
|
|
132
|
-
function isFunctions(a, b) {
|
|
133
|
-
return typeof a === "function" && typeof b === "function";
|
|
134
|
-
}
|
|
135
|
-
var customDeepEqual = createCustomEqual({
|
|
136
|
-
createInternalComparator: (comparator) => {
|
|
137
|
-
return (a, b, _idxA, _idxB, _parentA, _parentB, state) => {
|
|
138
|
-
if (isFunctions(a, b)) {
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
return comparator(a, b, state);
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
});
|
|
131
|
+
import isEqualWith from "lodash/isEqualWith";
|
|
145
132
|
function deepEquals(a, b) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
133
|
+
return isEqualWith(a, b, (obj, other) => {
|
|
134
|
+
if (typeof obj === "function" && typeof other === "function") {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
return void 0;
|
|
138
|
+
});
|
|
150
139
|
}
|
|
151
140
|
|
|
152
141
|
// src/schema/getDefaultFormState.ts
|
|
@@ -290,6 +279,7 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
290
279
|
|
|
291
280
|
// src/schema/retrieveSchema.ts
|
|
292
281
|
import get4 from "lodash/get";
|
|
282
|
+
import isEqual from "lodash/isEqual";
|
|
293
283
|
import set from "lodash/set";
|
|
294
284
|
import times from "lodash/times";
|
|
295
285
|
import transform from "lodash/transform";
|
|
@@ -469,10 +459,7 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
469
459
|
)
|
|
470
460
|
);
|
|
471
461
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
472
|
-
return allPermutations.map((permutation) => ({
|
|
473
|
-
...schema,
|
|
474
|
-
allOf: permutation
|
|
475
|
-
}));
|
|
462
|
+
return allPermutations.map((permutation) => ({ ...schema, allOf: permutation }));
|
|
476
463
|
}
|
|
477
464
|
return [schema];
|
|
478
465
|
}
|
|
@@ -524,7 +511,7 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
524
511
|
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
525
512
|
};
|
|
526
513
|
}
|
|
527
|
-
return
|
|
514
|
+
return isEqual(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
528
515
|
}
|
|
529
516
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
530
517
|
const schema = {
|
|
@@ -593,9 +580,24 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
593
580
|
return [...allOf, restOfSchema];
|
|
594
581
|
}
|
|
595
582
|
try {
|
|
583
|
+
const withContainsSchemas = [];
|
|
584
|
+
const withoutContainsSchemas = [];
|
|
585
|
+
resolvedSchema.allOf?.forEach((s2) => {
|
|
586
|
+
if (typeof s2 === "object" && s2.contains) {
|
|
587
|
+
withContainsSchemas.push(s2);
|
|
588
|
+
} else {
|
|
589
|
+
withoutContainsSchemas.push(s2);
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
if (withContainsSchemas.length) {
|
|
593
|
+
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
594
|
+
}
|
|
596
595
|
resolvedSchema = mergeAllOf(resolvedSchema, {
|
|
597
596
|
deep: false
|
|
598
597
|
});
|
|
598
|
+
if (withContainsSchemas.length) {
|
|
599
|
+
resolvedSchema.allOf = withContainsSchemas;
|
|
600
|
+
}
|
|
599
601
|
} catch (e) {
|
|
600
602
|
console.warn("could not merge subschemas in allOf:\n", e);
|
|
601
603
|
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
|
|
@@ -1429,10 +1431,11 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1429
1431
|
|
|
1430
1432
|
// src/schema/toIdSchema.ts
|
|
1431
1433
|
import get9 from "lodash/get";
|
|
1434
|
+
import isEqual2 from "lodash/isEqual";
|
|
1432
1435
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1433
1436
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1434
1437
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1435
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1438
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual2(item, _schema));
|
|
1436
1439
|
if (sameSchemaIndex === -1) {
|
|
1437
1440
|
return toIdSchemaInternal(
|
|
1438
1441
|
validator,
|
|
@@ -1486,11 +1489,12 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "roo
|
|
|
1486
1489
|
|
|
1487
1490
|
// src/schema/toPathSchema.ts
|
|
1488
1491
|
import get10 from "lodash/get";
|
|
1492
|
+
import isEqual3 from "lodash/isEqual";
|
|
1489
1493
|
import set2 from "lodash/set";
|
|
1490
1494
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1491
1495
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1492
1496
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1493
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1497
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => isEqual3(item, _schema));
|
|
1494
1498
|
if (sameSchemaIndex === -1) {
|
|
1495
1499
|
return toPathSchemaInternal(
|
|
1496
1500
|
validator,
|
|
@@ -1861,6 +1865,9 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
1861
1865
|
return replaceStringParameters(stringToTranslate, params);
|
|
1862
1866
|
}
|
|
1863
1867
|
|
|
1868
|
+
// src/enumOptionsDeselectValue.ts
|
|
1869
|
+
import isEqual4 from "lodash/isEqual";
|
|
1870
|
+
|
|
1864
1871
|
// src/enumOptionsValueForIndex.ts
|
|
1865
1872
|
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
1866
1873
|
if (Array.isArray(valueIndex)) {
|
|
@@ -1875,17 +1882,18 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
1875
1882
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1876
1883
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1877
1884
|
if (Array.isArray(selected)) {
|
|
1878
|
-
return selected.filter((v) => !
|
|
1885
|
+
return selected.filter((v) => !isEqual4(v, value));
|
|
1879
1886
|
}
|
|
1880
|
-
return
|
|
1887
|
+
return isEqual4(value, selected) ? void 0 : selected;
|
|
1881
1888
|
}
|
|
1882
1889
|
|
|
1883
1890
|
// src/enumOptionsIsSelected.ts
|
|
1891
|
+
import isEqual5 from "lodash/isEqual";
|
|
1884
1892
|
function enumOptionsIsSelected(value, selected) {
|
|
1885
1893
|
if (Array.isArray(selected)) {
|
|
1886
|
-
return selected.some((sel) =>
|
|
1894
|
+
return selected.some((sel) => isEqual5(sel, value));
|
|
1887
1895
|
}
|
|
1888
|
-
return
|
|
1896
|
+
return isEqual5(selected, value);
|
|
1889
1897
|
}
|
|
1890
1898
|
|
|
1891
1899
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1914,6 +1922,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
1914
1922
|
import cloneDeep from "lodash/cloneDeep";
|
|
1915
1923
|
import get11 from "lodash/get";
|
|
1916
1924
|
import set3 from "lodash/set";
|
|
1925
|
+
import setWith from "lodash/setWith";
|
|
1917
1926
|
var ErrorSchemaBuilder = class {
|
|
1918
1927
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
1919
1928
|
*
|
|
@@ -1943,7 +1952,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1943
1952
|
let errorBlock = hasPath ? get11(this.errorSchema, pathOfError) : this.errorSchema;
|
|
1944
1953
|
if (!errorBlock && pathOfError) {
|
|
1945
1954
|
errorBlock = {};
|
|
1946
|
-
|
|
1955
|
+
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
1947
1956
|
}
|
|
1948
1957
|
return errorBlock;
|
|
1949
1958
|
}
|
|
@@ -2580,9 +2589,11 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2580
2589
|
|
|
2581
2590
|
// src/parser/schemaParser.ts
|
|
2582
2591
|
import forEach from "lodash/forEach";
|
|
2592
|
+
import isEqual7 from "lodash/isEqual";
|
|
2583
2593
|
|
|
2584
2594
|
// src/parser/ParserValidator.ts
|
|
2585
2595
|
import get13 from "lodash/get";
|
|
2596
|
+
import isEqual6 from "lodash/isEqual";
|
|
2586
2597
|
var ParserValidator = class {
|
|
2587
2598
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2588
2599
|
* first.
|
|
@@ -2613,7 +2624,7 @@ var ParserValidator = class {
|
|
|
2613
2624
|
const existing = this.schemaMap[key];
|
|
2614
2625
|
if (!existing) {
|
|
2615
2626
|
this.schemaMap[key] = identifiedSchema;
|
|
2616
|
-
} else if (!
|
|
2627
|
+
} else if (!isEqual6(existing, identifiedSchema)) {
|
|
2617
2628
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2618
2629
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2619
2630
|
throw new Error(
|
|
@@ -2635,7 +2646,7 @@ var ParserValidator = class {
|
|
|
2635
2646
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2636
2647
|
*/
|
|
2637
2648
|
isValid(schema, _formData, rootSchema) {
|
|
2638
|
-
if (!
|
|
2649
|
+
if (!isEqual6(rootSchema, this.rootSchema)) {
|
|
2639
2650
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2640
2651
|
}
|
|
2641
2652
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2675,7 +2686,7 @@ var ParserValidator = class {
|
|
|
2675
2686
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2676
2687
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
2677
2688
|
schemas.forEach((schema2) => {
|
|
2678
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
2689
|
+
const sameSchemaIndex = recurseList.findIndex((item) => isEqual7(item, schema2));
|
|
2679
2690
|
if (sameSchemaIndex === -1) {
|
|
2680
2691
|
recurseList.push(schema2);
|
|
2681
2692
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|