@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/index.js
CHANGED
|
@@ -265,25 +265,14 @@ function createErrorHandler(formData) {
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
// src/deepEquals.ts
|
|
268
|
-
var
|
|
269
|
-
function isFunctions(a, b) {
|
|
270
|
-
return typeof a === "function" && typeof b === "function";
|
|
271
|
-
}
|
|
272
|
-
var customDeepEqual = (0, import_fast_equals.createCustomEqual)({
|
|
273
|
-
createInternalComparator: (comparator) => {
|
|
274
|
-
return (a, b, _idxA, _idxB, _parentA, _parentB, state) => {
|
|
275
|
-
if (isFunctions(a, b)) {
|
|
276
|
-
return true;
|
|
277
|
-
}
|
|
278
|
-
return comparator(a, b, state);
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
});
|
|
268
|
+
var import_isEqualWith = __toESM(require("lodash/isEqualWith"));
|
|
282
269
|
function deepEquals(a, b) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
270
|
+
return (0, import_isEqualWith.default)(a, b, (obj, other) => {
|
|
271
|
+
if (typeof obj === "function" && typeof other === "function") {
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
return void 0;
|
|
275
|
+
});
|
|
287
276
|
}
|
|
288
277
|
|
|
289
278
|
// src/schema/getDefaultFormState.ts
|
|
@@ -427,6 +416,7 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
427
416
|
|
|
428
417
|
// src/schema/retrieveSchema.ts
|
|
429
418
|
var import_get4 = __toESM(require("lodash/get"));
|
|
419
|
+
var import_isEqual = __toESM(require("lodash/isEqual"));
|
|
430
420
|
var import_set = __toESM(require("lodash/set"));
|
|
431
421
|
var import_times = __toESM(require("lodash/times"));
|
|
432
422
|
var import_transform = __toESM(require("lodash/transform"));
|
|
@@ -606,10 +596,7 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
606
596
|
)
|
|
607
597
|
);
|
|
608
598
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
609
|
-
return allPermutations.map((permutation) => ({
|
|
610
|
-
...schema,
|
|
611
|
-
allOf: permutation
|
|
612
|
-
}));
|
|
599
|
+
return allPermutations.map((permutation) => ({ ...schema, allOf: permutation }));
|
|
613
600
|
}
|
|
614
601
|
return [schema];
|
|
615
602
|
}
|
|
@@ -661,7 +648,7 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
661
648
|
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
662
649
|
};
|
|
663
650
|
}
|
|
664
|
-
return
|
|
651
|
+
return (0, import_isEqual.default)(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
665
652
|
}
|
|
666
653
|
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
667
654
|
const schema = {
|
|
@@ -730,9 +717,24 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
730
717
|
return [...allOf, restOfSchema];
|
|
731
718
|
}
|
|
732
719
|
try {
|
|
720
|
+
const withContainsSchemas = [];
|
|
721
|
+
const withoutContainsSchemas = [];
|
|
722
|
+
resolvedSchema.allOf?.forEach((s2) => {
|
|
723
|
+
if (typeof s2 === "object" && s2.contains) {
|
|
724
|
+
withContainsSchemas.push(s2);
|
|
725
|
+
} else {
|
|
726
|
+
withoutContainsSchemas.push(s2);
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
if (withContainsSchemas.length) {
|
|
730
|
+
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
731
|
+
}
|
|
733
732
|
resolvedSchema = (0, import_json_schema_merge_allof.default)(resolvedSchema, {
|
|
734
733
|
deep: false
|
|
735
734
|
});
|
|
735
|
+
if (withContainsSchemas.length) {
|
|
736
|
+
resolvedSchema.allOf = withContainsSchemas;
|
|
737
|
+
}
|
|
736
738
|
} catch (e) {
|
|
737
739
|
console.warn("could not merge subschemas in allOf:\n", e);
|
|
738
740
|
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
|
|
@@ -1566,10 +1568,11 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1566
1568
|
|
|
1567
1569
|
// src/schema/toIdSchema.ts
|
|
1568
1570
|
var import_get9 = __toESM(require("lodash/get"));
|
|
1571
|
+
var import_isEqual2 = __toESM(require("lodash/isEqual"));
|
|
1569
1572
|
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1570
1573
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1571
1574
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1572
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1575
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => (0, import_isEqual2.default)(item, _schema));
|
|
1573
1576
|
if (sameSchemaIndex === -1) {
|
|
1574
1577
|
return toIdSchemaInternal(
|
|
1575
1578
|
validator,
|
|
@@ -1623,11 +1626,12 @@ function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "roo
|
|
|
1623
1626
|
|
|
1624
1627
|
// src/schema/toPathSchema.ts
|
|
1625
1628
|
var import_get10 = __toESM(require("lodash/get"));
|
|
1629
|
+
var import_isEqual3 = __toESM(require("lodash/isEqual"));
|
|
1626
1630
|
var import_set2 = __toESM(require("lodash/set"));
|
|
1627
1631
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1628
1632
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1629
1633
|
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1630
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1634
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => (0, import_isEqual3.default)(item, _schema));
|
|
1631
1635
|
if (sameSchemaIndex === -1) {
|
|
1632
1636
|
return toPathSchemaInternal(
|
|
1633
1637
|
validator,
|
|
@@ -1998,6 +2002,9 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
1998
2002
|
return replaceStringParameters(stringToTranslate, params);
|
|
1999
2003
|
}
|
|
2000
2004
|
|
|
2005
|
+
// src/enumOptionsDeselectValue.ts
|
|
2006
|
+
var import_isEqual4 = __toESM(require("lodash/isEqual"));
|
|
2007
|
+
|
|
2001
2008
|
// src/enumOptionsValueForIndex.ts
|
|
2002
2009
|
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
2003
2010
|
if (Array.isArray(valueIndex)) {
|
|
@@ -2012,17 +2019,18 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
2012
2019
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
2013
2020
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
2014
2021
|
if (Array.isArray(selected)) {
|
|
2015
|
-
return selected.filter((v) => !
|
|
2022
|
+
return selected.filter((v) => !(0, import_isEqual4.default)(v, value));
|
|
2016
2023
|
}
|
|
2017
|
-
return
|
|
2024
|
+
return (0, import_isEqual4.default)(value, selected) ? void 0 : selected;
|
|
2018
2025
|
}
|
|
2019
2026
|
|
|
2020
2027
|
// src/enumOptionsIsSelected.ts
|
|
2028
|
+
var import_isEqual5 = __toESM(require("lodash/isEqual"));
|
|
2021
2029
|
function enumOptionsIsSelected(value, selected) {
|
|
2022
2030
|
if (Array.isArray(selected)) {
|
|
2023
|
-
return selected.some((sel) =>
|
|
2031
|
+
return selected.some((sel) => (0, import_isEqual5.default)(sel, value));
|
|
2024
2032
|
}
|
|
2025
|
-
return
|
|
2033
|
+
return (0, import_isEqual5.default)(selected, value);
|
|
2026
2034
|
}
|
|
2027
2035
|
|
|
2028
2036
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -2051,6 +2059,7 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
2051
2059
|
var import_cloneDeep = __toESM(require("lodash/cloneDeep"));
|
|
2052
2060
|
var import_get11 = __toESM(require("lodash/get"));
|
|
2053
2061
|
var import_set3 = __toESM(require("lodash/set"));
|
|
2062
|
+
var import_setWith = __toESM(require("lodash/setWith"));
|
|
2054
2063
|
var ErrorSchemaBuilder = class {
|
|
2055
2064
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
2056
2065
|
*
|
|
@@ -2080,7 +2089,7 @@ var ErrorSchemaBuilder = class {
|
|
|
2080
2089
|
let errorBlock = hasPath ? (0, import_get11.default)(this.errorSchema, pathOfError) : this.errorSchema;
|
|
2081
2090
|
if (!errorBlock && pathOfError) {
|
|
2082
2091
|
errorBlock = {};
|
|
2083
|
-
(0,
|
|
2092
|
+
(0, import_setWith.default)(this.errorSchema, pathOfError, errorBlock, Object);
|
|
2084
2093
|
}
|
|
2085
2094
|
return errorBlock;
|
|
2086
2095
|
}
|
|
@@ -2717,9 +2726,11 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2717
2726
|
|
|
2718
2727
|
// src/parser/schemaParser.ts
|
|
2719
2728
|
var import_forEach = __toESM(require("lodash/forEach"));
|
|
2729
|
+
var import_isEqual7 = __toESM(require("lodash/isEqual"));
|
|
2720
2730
|
|
|
2721
2731
|
// src/parser/ParserValidator.ts
|
|
2722
2732
|
var import_get13 = __toESM(require("lodash/get"));
|
|
2733
|
+
var import_isEqual6 = __toESM(require("lodash/isEqual"));
|
|
2723
2734
|
var ParserValidator = class {
|
|
2724
2735
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2725
2736
|
* first.
|
|
@@ -2750,7 +2761,7 @@ var ParserValidator = class {
|
|
|
2750
2761
|
const existing = this.schemaMap[key];
|
|
2751
2762
|
if (!existing) {
|
|
2752
2763
|
this.schemaMap[key] = identifiedSchema;
|
|
2753
|
-
} else if (!
|
|
2764
|
+
} else if (!(0, import_isEqual6.default)(existing, identifiedSchema)) {
|
|
2754
2765
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2755
2766
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2756
2767
|
throw new Error(
|
|
@@ -2772,7 +2783,7 @@ var ParserValidator = class {
|
|
|
2772
2783
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2773
2784
|
*/
|
|
2774
2785
|
isValid(schema, _formData, rootSchema) {
|
|
2775
|
-
if (!
|
|
2786
|
+
if (!(0, import_isEqual6.default)(rootSchema, this.rootSchema)) {
|
|
2776
2787
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2777
2788
|
}
|
|
2778
2789
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2812,7 +2823,7 @@ var ParserValidator = class {
|
|
|
2812
2823
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2813
2824
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
2814
2825
|
schemas.forEach((schema2) => {
|
|
2815
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
2826
|
+
const sameSchemaIndex = recurseList.findIndex((item) => (0, import_isEqual7.default)(item, schema2));
|
|
2816
2827
|
if (sameSchemaIndex === -1) {
|
|
2817
2828
|
recurseList.push(schema2);
|
|
2818
2829
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|