@rjsf/utils 6.0.0-alpha.0 → 6.0.0-beta.1
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 +1281 -625
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +1254 -598
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +1201 -570
- package/lib/ErrorSchemaBuilder.d.ts +8 -4
- package/lib/ErrorSchemaBuilder.js +10 -8
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -1
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +1 -1
- package/lib/canExpand.js +2 -2
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.d.ts +9 -0
- package/lib/constIsAjvDataReference.js +15 -0
- package/lib/constIsAjvDataReference.js.map +1 -0
- package/lib/constants.d.ts +11 -3
- package/lib/constants.js +11 -3
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.d.ts +1 -1
- package/lib/createErrorHandler.js +2 -2
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +3 -2
- package/lib/createSchemaUtils.js +56 -46
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +1 -1
- package/lib/dateRangeOptions.js +1 -1
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/deepEquals.js +1 -1
- package/lib/deepEquals.js.map +1 -1
- package/lib/englishStringTranslator.d.ts +1 -1
- package/lib/englishStringTranslator.js +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +1 -1
- package/lib/enumOptionsDeselectValue.js +4 -4
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.js +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +1 -1
- package/lib/enumOptionsIsSelected.js +3 -3
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.d.ts +1 -1
- package/lib/enumOptionsSelectValue.js +2 -2
- package/lib/enumOptionsSelectValue.js.map +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +1 -1
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +2 -0
- package/lib/enums.js +2 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +1 -1
- package/lib/findSchemaDefinition.js +2 -2
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.d.ts +17 -0
- package/lib/getChangedFields.js +42 -0
- package/lib/getChangedFields.js.map +1 -0
- package/lib/getDateElementProps.d.ts +1 -1
- package/lib/getDateElementProps.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +4 -3
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +1 -1
- package/lib/getInputProps.js +4 -1
- package/lib/getInputProps.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js +2 -2
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getSchemaType.d.ts +2 -1
- package/lib/getSchemaType.js +3 -2
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +1 -1
- package/lib/getSubmitButtonOptions.js +2 -2
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +1 -1
- package/lib/getTemplate.js +9 -0
- package/lib/getTemplate.js.map +1 -1
- package/lib/getTestIds.d.ts +17 -0
- package/lib/getTestIds.js +34 -0
- package/lib/getTestIds.js.map +1 -0
- package/lib/getUiOptions.d.ts +1 -1
- package/lib/getUiOptions.js +2 -2
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +1 -1
- package/lib/getWidget.js +3 -3
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.d.ts +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.d.ts +1 -1
- package/lib/hasWidget.js +1 -1
- package/lib/hasWidget.js.map +1 -1
- package/lib/hashForSchema.d.ts +23 -1
- package/lib/hashForSchema.js +24 -6
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +8 -1
- package/lib/idGenerators.js +11 -2
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +63 -60
- package/lib/index.js +63 -60
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +1 -1
- package/lib/isConstant.js +1 -1
- package/lib/isCustomWidget.d.ts +1 -1
- package/lib/isCustomWidget.js +1 -1
- package/lib/isFixedItems.d.ts +1 -1
- package/lib/isFixedItems.js +1 -1
- package/lib/isObject.d.ts +2 -2
- package/lib/isObject.js +11 -4
- package/lib/isObject.js.map +1 -1
- package/lib/lookupFromFormContext.d.ts +11 -0
- package/lib/lookupFromFormContext.js +20 -0
- package/lib/lookupFromFormContext.js.map +1 -0
- package/lib/mergeDefaultsWithFormData.d.ts +8 -2
- package/lib/mergeDefaultsWithFormData.js +39 -10
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +1 -1
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +1 -1
- package/lib/mergeSchemas.js +4 -4
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/optionsList.d.ts +9 -7
- package/lib/optionsList.js +30 -19
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js.map +1 -1
- package/lib/pad.js.map +1 -1
- package/lib/parseDateString.d.ts +1 -1
- package/lib/parseDateString.js +1 -1
- package/lib/parseDateString.js.map +1 -1
- package/lib/parser/ParserValidator.d.ts +1 -1
- package/lib/parser/ParserValidator.js +6 -6
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +2 -2
- package/lib/parser/index.js +1 -1
- package/lib/parser/schemaParser.d.ts +2 -2
- package/lib/parser/schemaParser.js +6 -6
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/rangeSpec.d.ts +2 -2
- package/lib/rangeSpec.js.map +1 -1
- package/lib/replaceStringParameters.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +19 -0
- package/lib/schema/findFieldInSchema.js +61 -0
- package/lib/schema/findFieldInSchema.js.map +1 -0
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +16 -0
- package/lib/schema/findSelectedOptionInXxxOf.js +34 -0
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -0
- package/lib/schema/getClosestMatchingOption.d.ts +5 -3
- package/lib/schema/getClosestMatchingOption.js +28 -20
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +60 -13
- package/lib/schema/getDefaultFormState.js +304 -166
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +3 -2
- package/lib/schema/getDisplayLabel.js +10 -9
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +70 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +14 -0
- package/lib/schema/getFromSchema.js +39 -0
- package/lib/schema/getFromSchema.js.map +1 -0
- package/lib/schema/index.d.ts +15 -14
- package/lib/schema/index.js +15 -14
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +3 -2
- package/lib/schema/isFilesArray.js +5 -4
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.d.ts +3 -2
- package/lib/schema/isMultiSelect.js +4 -3
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +3 -2
- package/lib/schema/isSelect.js +5 -4
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +28 -11
- package/lib/schema/retrieveSchema.js +142 -66
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +3 -2
- package/lib/schema/sanitizeDataForNewSchema.js +12 -11
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toIdSchema.d.ts +3 -2
- package/lib/schema/toIdSchema.js +30 -27
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +3 -2
- package/lib/schema/toPathSchema.js +22 -20
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +1 -1
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shouldRender.js +1 -1
- package/lib/toConstant.d.ts +1 -1
- package/lib/toConstant.js +1 -1
- package/lib/toConstant.js.map +1 -1
- package/lib/toDateString.d.ts +1 -1
- package/lib/toErrorList.d.ts +1 -1
- package/lib/toErrorList.js +2 -2
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +1 -1
- package/lib/toErrorSchema.js +2 -2
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +160 -131
- package/lib/unwrapErrorHandler.d.ts +1 -1
- package/lib/unwrapErrorHandler.js +1 -1
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/utcToLocal.js +1 -1
- package/lib/utcToLocal.js.map +1 -1
- package/lib/validationDataMerge.d.ts +1 -1
- package/lib/validationDataMerge.js +3 -3
- package/lib/validationDataMerge.js.map +1 -1
- package/lib/withIdRefPrefix.d.ts +1 -1
- package/lib/withIdRefPrefix.js +2 -2
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +36 -26
- package/src/ErrorSchemaBuilder.ts +15 -8
- package/src/canExpand.ts +2 -2
- package/src/constIsAjvDataReference.ts +17 -0
- package/src/constants.ts +12 -3
- package/src/createSchemaUtils.ts +140 -50
- package/src/dataURItoBlob.ts +1 -1
- package/src/dateRangeOptions.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +4 -5
- package/src/enumOptionsIndexForValue.ts +1 -1
- package/src/enumOptionsIsSelected.ts +4 -5
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +1 -1
- package/src/enums.ts +2 -0
- package/src/findSchemaDefinition.ts +2 -2
- package/src/getChangedFields.ts +40 -0
- package/src/getDateElementProps.ts +2 -2
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +6 -2
- package/src/getOptionMatchingSimpleDiscriminator.ts +2 -2
- package/src/getSchemaType.ts +3 -2
- package/src/getSubmitButtonOptions.ts +1 -1
- package/src/getTemplate.ts +12 -1
- package/src/getTestIds.ts +40 -0
- package/src/getUiOptions.ts +2 -2
- package/src/getWidget.tsx +2 -2
- package/src/hasWidget.ts +1 -1
- package/src/hashForSchema.ts +26 -6
- package/src/idGenerators.ts +10 -0
- package/src/index.ts +21 -2
- package/src/isCustomWidget.ts +1 -1
- package/src/isObject.ts +12 -5
- package/src/labelValue.ts +2 -2
- package/src/lookupFromFormContext.ts +26 -0
- package/src/mergeDefaultsWithFormData.ts +54 -9
- package/src/mergeObjects.ts +24 -21
- package/src/optionsList.ts +31 -22
- package/src/parser/ParserValidator.ts +5 -5
- package/src/parser/schemaParser.ts +6 -6
- package/src/schema/findFieldInSchema.ts +138 -0
- package/src/schema/findSelectedOptionInXxxOf.ts +53 -0
- package/src/schema/getClosestMatchingOption.ts +38 -11
- package/src/schema/getDefaultFormState.ts +447 -191
- package/src/schema/getDisplayLabel.ts +7 -4
- package/src/schema/getFirstMatchingOption.ts +79 -4
- package/src/schema/getFromSchema.ts +100 -0
- package/src/schema/index.ts +6 -4
- package/src/schema/isFilesArray.ts +18 -3
- package/src/schema/isMultiSelect.ts +10 -4
- package/src/schema/isSelect.ts +5 -3
- package/src/schema/retrieveSchema.ts +256 -75
- package/src/schema/sanitizeDataForNewSchema.ts +52 -11
- package/src/schema/toIdSchema.ts +69 -43
- package/src/schema/toPathSchema.ts +49 -16
- package/src/toErrorList.ts +2 -2
- package/src/types.ts +266 -174
- package/src/validationDataMerge.ts +1 -1
- package/src/withIdRefPrefix.ts +1 -1
- package/LICENSE.md +0 -201
- package/lib/schema/getMatchingOption.d.ts +0 -14
- package/lib/schema/getMatchingOption.js +0 -85
- package/lib/schema/getMatchingOption.js.map +0 -1
- package/lib/schema/mergeValidationData.d.ts +0 -14
- package/lib/schema/mergeValidationData.js +0 -28
- package/lib/schema/mergeValidationData.js.map +0 -1
- package/src/schema/getMatchingOption.ts +0 -103
- package/src/schema/mergeValidationData.ts +0 -38
package/dist/utils.esm.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
// src/isObject.ts
|
|
2
2
|
function isObject(thing) {
|
|
3
|
-
if (typeof
|
|
3
|
+
if (typeof thing !== "object" || thing === null) {
|
|
4
4
|
return false;
|
|
5
5
|
}
|
|
6
|
-
if (typeof
|
|
6
|
+
if (typeof thing.lastModified === "number" && typeof File !== "undefined" && thing instanceof File) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
if (typeof thing.getMonth === "function" && typeof Date !== "undefined" && thing instanceof Date) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return !Array.isArray(thing);
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
// src/allowAdditionalItems.ts
|
|
@@ -56,11 +59,15 @@ var ITEMS_KEY = "items";
|
|
|
56
59
|
var JUNK_OPTION_ID = "_$junk_option_schema_id$_";
|
|
57
60
|
var NAME_KEY = "$name";
|
|
58
61
|
var ONE_OF_KEY = "oneOf";
|
|
62
|
+
var PATTERN_PROPERTIES_KEY = "patternProperties";
|
|
59
63
|
var PROPERTIES_KEY = "properties";
|
|
64
|
+
var READONLY_KEY = "readonly";
|
|
60
65
|
var REQUIRED_KEY = "required";
|
|
61
66
|
var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
62
67
|
var REF_KEY = "$ref";
|
|
63
|
-
var
|
|
68
|
+
var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
|
|
69
|
+
var FORM_CONTEXT_NAME = "formContext";
|
|
70
|
+
var LOOKUP_MAP_NAME = "layoutGridLookupMap";
|
|
64
71
|
var RJSF_ADDITIONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
|
|
65
72
|
var ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
|
|
66
73
|
var UI_FIELD_KEY = "ui:field";
|
|
@@ -88,7 +95,7 @@ function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
|
88
95
|
|
|
89
96
|
// src/canExpand.ts
|
|
90
97
|
function canExpand(schema, uiSchema = {}, formData) {
|
|
91
|
-
if (!schema.additionalProperties) {
|
|
98
|
+
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
92
99
|
return false;
|
|
93
100
|
}
|
|
94
101
|
const { expandable = true } = getUiOptions(uiSchema);
|
|
@@ -138,9 +145,23 @@ function deepEquals(a, b) {
|
|
|
138
145
|
});
|
|
139
146
|
}
|
|
140
147
|
|
|
141
|
-
// src/schema/
|
|
148
|
+
// src/schema/findFieldInSchema.ts
|
|
142
149
|
import get7 from "lodash/get";
|
|
143
|
-
import
|
|
150
|
+
import has3 from "lodash/has";
|
|
151
|
+
|
|
152
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
153
|
+
import get5 from "lodash/get";
|
|
154
|
+
import isEqual from "lodash/isEqual";
|
|
155
|
+
|
|
156
|
+
// src/schema/retrieveSchema.ts
|
|
157
|
+
import get4 from "lodash/get";
|
|
158
|
+
import set from "lodash/set";
|
|
159
|
+
import times from "lodash/times";
|
|
160
|
+
import transform from "lodash/transform";
|
|
161
|
+
import merge from "lodash/merge";
|
|
162
|
+
import flattenDeep from "lodash/flattenDeep";
|
|
163
|
+
import uniq from "lodash/uniq";
|
|
164
|
+
import mergeAllOf from "json-schema-merge-allof";
|
|
144
165
|
|
|
145
166
|
// src/findSchemaDefinition.ts
|
|
146
167
|
import jsonpointer from "jsonpointer";
|
|
@@ -186,114 +207,12 @@ function findSchemaDefinition($ref, rootSchema = {}) {
|
|
|
186
207
|
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList);
|
|
187
208
|
}
|
|
188
209
|
|
|
189
|
-
// src/schema/getClosestMatchingOption.ts
|
|
190
|
-
import get5 from "lodash/get";
|
|
191
|
-
import has2 from "lodash/has";
|
|
192
|
-
import isNumber2 from "lodash/isNumber";
|
|
193
|
-
import isObject2 from "lodash/isObject";
|
|
194
|
-
import isString2 from "lodash/isString";
|
|
195
|
-
import reduce from "lodash/reduce";
|
|
196
|
-
import times2 from "lodash/times";
|
|
197
|
-
|
|
198
|
-
// src/schema/getMatchingOption.ts
|
|
199
|
-
import get2 from "lodash/get";
|
|
200
|
-
import has from "lodash/has";
|
|
201
|
-
import isNumber from "lodash/isNumber";
|
|
202
|
-
|
|
203
|
-
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
204
|
-
import get from "lodash/get";
|
|
205
|
-
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
206
|
-
if (formData && discriminatorField) {
|
|
207
|
-
const value = get(formData, discriminatorField);
|
|
208
|
-
if (value === void 0) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
for (let i = 0; i < options.length; i++) {
|
|
212
|
-
const option = options[i];
|
|
213
|
-
const discriminator = get(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
214
|
-
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
if (discriminator.const === value) {
|
|
218
|
-
return i;
|
|
219
|
-
}
|
|
220
|
-
if (discriminator.enum?.includes(value)) {
|
|
221
|
-
return i;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// src/schema/getMatchingOption.ts
|
|
229
|
-
function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
230
|
-
if (formData === void 0) {
|
|
231
|
-
return 0;
|
|
232
|
-
}
|
|
233
|
-
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
234
|
-
if (isNumber(simpleDiscriminatorMatch)) {
|
|
235
|
-
return simpleDiscriminatorMatch;
|
|
236
|
-
}
|
|
237
|
-
for (let i = 0; i < options.length; i++) {
|
|
238
|
-
const option = options[i];
|
|
239
|
-
if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
240
|
-
const value = get2(formData, discriminatorField);
|
|
241
|
-
const discriminator = get2(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
242
|
-
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
243
|
-
return i;
|
|
244
|
-
}
|
|
245
|
-
} else if (option[PROPERTIES_KEY]) {
|
|
246
|
-
const requiresAnyOf = {
|
|
247
|
-
anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
|
|
248
|
-
required: [key]
|
|
249
|
-
}))
|
|
250
|
-
};
|
|
251
|
-
let augmentedSchema;
|
|
252
|
-
if (option.anyOf) {
|
|
253
|
-
const { ...shallowClone } = option;
|
|
254
|
-
if (!shallowClone.allOf) {
|
|
255
|
-
shallowClone.allOf = [];
|
|
256
|
-
} else {
|
|
257
|
-
shallowClone.allOf = shallowClone.allOf.slice();
|
|
258
|
-
}
|
|
259
|
-
shallowClone.allOf.push(requiresAnyOf);
|
|
260
|
-
augmentedSchema = shallowClone;
|
|
261
|
-
} else {
|
|
262
|
-
augmentedSchema = Object.assign({}, option, requiresAnyOf);
|
|
263
|
-
}
|
|
264
|
-
delete augmentedSchema.required;
|
|
265
|
-
if (validator.isValid(augmentedSchema, formData, rootSchema)) {
|
|
266
|
-
return i;
|
|
267
|
-
}
|
|
268
|
-
} else if (validator.isValid(option, formData, rootSchema)) {
|
|
269
|
-
return i;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return 0;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// src/schema/getFirstMatchingOption.ts
|
|
276
|
-
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
277
|
-
return getMatchingOption(validator, formData, options, rootSchema, discriminatorField);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// src/schema/retrieveSchema.ts
|
|
281
|
-
import get4 from "lodash/get";
|
|
282
|
-
import isEqual from "lodash/isEqual";
|
|
283
|
-
import set from "lodash/set";
|
|
284
|
-
import times from "lodash/times";
|
|
285
|
-
import transform from "lodash/transform";
|
|
286
|
-
import merge from "lodash/merge";
|
|
287
|
-
import flattenDeep from "lodash/flattenDeep";
|
|
288
|
-
import uniq from "lodash/uniq";
|
|
289
|
-
import mergeAllOf from "json-schema-merge-allof";
|
|
290
|
-
|
|
291
210
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
292
|
-
import
|
|
211
|
+
import get from "lodash/get";
|
|
293
212
|
import isString from "lodash/isString";
|
|
294
213
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
295
214
|
let discriminator;
|
|
296
|
-
const maybeString =
|
|
215
|
+
const maybeString = get(schema, DISCRIMINATOR_PATH);
|
|
297
216
|
if (isString(maybeString)) {
|
|
298
217
|
discriminator = maybeString;
|
|
299
218
|
} else if (maybeString !== void 0) {
|
|
@@ -337,7 +256,7 @@ function getSchemaType(schema) {
|
|
|
337
256
|
if (!type && schema.enum) {
|
|
338
257
|
return "string";
|
|
339
258
|
}
|
|
340
|
-
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
259
|
+
if (!type && (schema.properties || schema.additionalProperties || schema.patternProperties)) {
|
|
341
260
|
return "object";
|
|
342
261
|
}
|
|
343
262
|
if (Array.isArray(type)) {
|
|
@@ -366,11 +285,97 @@ function mergeSchemas(obj1, obj2) {
|
|
|
366
285
|
}, acc);
|
|
367
286
|
}
|
|
368
287
|
|
|
288
|
+
// src/schema/getFirstMatchingOption.ts
|
|
289
|
+
import get3 from "lodash/get";
|
|
290
|
+
import has from "lodash/has";
|
|
291
|
+
import isNumber from "lodash/isNumber";
|
|
292
|
+
|
|
293
|
+
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
294
|
+
import get2 from "lodash/get";
|
|
295
|
+
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
296
|
+
if (formData && discriminatorField) {
|
|
297
|
+
const value = get2(formData, discriminatorField);
|
|
298
|
+
if (value === void 0) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
for (let i = 0; i < options.length; i++) {
|
|
302
|
+
const option = options[i];
|
|
303
|
+
const discriminator = get2(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
304
|
+
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (discriminator.const === value) {
|
|
308
|
+
return i;
|
|
309
|
+
}
|
|
310
|
+
if (discriminator.enum?.includes(value)) {
|
|
311
|
+
return i;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// src/schema/getFirstMatchingOption.ts
|
|
319
|
+
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
320
|
+
if (formData === void 0) {
|
|
321
|
+
return 0;
|
|
322
|
+
}
|
|
323
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
324
|
+
if (isNumber(simpleDiscriminatorMatch)) {
|
|
325
|
+
return simpleDiscriminatorMatch;
|
|
326
|
+
}
|
|
327
|
+
for (let i = 0; i < options.length; i++) {
|
|
328
|
+
const option = options[i];
|
|
329
|
+
if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
330
|
+
const value = get3(formData, discriminatorField);
|
|
331
|
+
const discriminator = get3(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
332
|
+
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
333
|
+
return i;
|
|
334
|
+
}
|
|
335
|
+
} else if (option[PROPERTIES_KEY]) {
|
|
336
|
+
const requiresAnyOf = {
|
|
337
|
+
anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
|
|
338
|
+
required: [key]
|
|
339
|
+
}))
|
|
340
|
+
};
|
|
341
|
+
let augmentedSchema;
|
|
342
|
+
if (option.anyOf) {
|
|
343
|
+
const { ...shallowClone } = option;
|
|
344
|
+
if (!shallowClone.allOf) {
|
|
345
|
+
shallowClone.allOf = [];
|
|
346
|
+
} else {
|
|
347
|
+
shallowClone.allOf = shallowClone.allOf.slice();
|
|
348
|
+
}
|
|
349
|
+
shallowClone.allOf.push(requiresAnyOf);
|
|
350
|
+
augmentedSchema = shallowClone;
|
|
351
|
+
} else {
|
|
352
|
+
augmentedSchema = Object.assign({}, option, requiresAnyOf);
|
|
353
|
+
}
|
|
354
|
+
delete augmentedSchema.required;
|
|
355
|
+
if (validator.isValid(augmentedSchema, formData, rootSchema)) {
|
|
356
|
+
return i;
|
|
357
|
+
}
|
|
358
|
+
} else if (validator.isValid(option, formData, rootSchema)) {
|
|
359
|
+
return i;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return 0;
|
|
363
|
+
}
|
|
364
|
+
|
|
369
365
|
// src/schema/retrieveSchema.ts
|
|
370
|
-
|
|
371
|
-
|
|
366
|
+
import isEmpty from "lodash/isEmpty";
|
|
367
|
+
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf) {
|
|
368
|
+
return retrieveSchemaInternal(
|
|
369
|
+
validator,
|
|
370
|
+
schema,
|
|
371
|
+
rootSchema,
|
|
372
|
+
rawFormData,
|
|
373
|
+
void 0,
|
|
374
|
+
void 0,
|
|
375
|
+
experimental_customMergeAllOf
|
|
376
|
+
)[0];
|
|
372
377
|
}
|
|
373
|
-
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
378
|
+
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
374
379
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
375
380
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
376
381
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
@@ -378,12 +383,28 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
378
383
|
if (expandAllBranches) {
|
|
379
384
|
if (then && typeof then !== "boolean") {
|
|
380
385
|
schemas = schemas.concat(
|
|
381
|
-
retrieveSchemaInternal(
|
|
386
|
+
retrieveSchemaInternal(
|
|
387
|
+
validator,
|
|
388
|
+
then,
|
|
389
|
+
rootSchema,
|
|
390
|
+
formData,
|
|
391
|
+
expandAllBranches,
|
|
392
|
+
recurseList,
|
|
393
|
+
experimental_customMergeAllOf
|
|
394
|
+
)
|
|
382
395
|
);
|
|
383
396
|
}
|
|
384
397
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
385
398
|
schemas = schemas.concat(
|
|
386
|
-
retrieveSchemaInternal(
|
|
399
|
+
retrieveSchemaInternal(
|
|
400
|
+
validator,
|
|
401
|
+
otherwise,
|
|
402
|
+
rootSchema,
|
|
403
|
+
formData,
|
|
404
|
+
expandAllBranches,
|
|
405
|
+
recurseList,
|
|
406
|
+
experimental_customMergeAllOf
|
|
407
|
+
)
|
|
387
408
|
);
|
|
388
409
|
}
|
|
389
410
|
} else {
|
|
@@ -396,7 +417,8 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
396
417
|
rootSchema,
|
|
397
418
|
formData,
|
|
398
419
|
expandAllBranches,
|
|
399
|
-
recurseList
|
|
420
|
+
recurseList,
|
|
421
|
+
experimental_customMergeAllOf
|
|
400
422
|
)
|
|
401
423
|
);
|
|
402
424
|
}
|
|
@@ -405,7 +427,15 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
405
427
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
406
428
|
}
|
|
407
429
|
return resolvedSchemas.flatMap(
|
|
408
|
-
(s) => retrieveSchemaInternal(
|
|
430
|
+
(s) => retrieveSchemaInternal(
|
|
431
|
+
validator,
|
|
432
|
+
s,
|
|
433
|
+
rootSchema,
|
|
434
|
+
formData,
|
|
435
|
+
expandAllBranches,
|
|
436
|
+
recurseList,
|
|
437
|
+
experimental_customMergeAllOf
|
|
438
|
+
)
|
|
409
439
|
);
|
|
410
440
|
}
|
|
411
441
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
@@ -422,7 +452,16 @@ function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
422
452
|
);
|
|
423
453
|
return allPermutations;
|
|
424
454
|
}
|
|
425
|
-
function
|
|
455
|
+
function getMatchingPatternProperties(schema, key) {
|
|
456
|
+
return Object.keys(schema.patternProperties).filter((pattern) => RegExp(pattern).test(key)).reduce(
|
|
457
|
+
(obj, pattern) => {
|
|
458
|
+
set(obj, [pattern], schema.patternProperties[pattern]);
|
|
459
|
+
return obj;
|
|
460
|
+
},
|
|
461
|
+
{}
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
426
465
|
const updatedSchemas = resolveReference(
|
|
427
466
|
validator,
|
|
428
467
|
schema,
|
|
@@ -444,7 +483,15 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
444
483
|
formData
|
|
445
484
|
);
|
|
446
485
|
return resolvedSchemas.flatMap((s) => {
|
|
447
|
-
return retrieveSchemaInternal(
|
|
486
|
+
return retrieveSchemaInternal(
|
|
487
|
+
validator,
|
|
488
|
+
s,
|
|
489
|
+
rootSchema,
|
|
490
|
+
formData,
|
|
491
|
+
expandAllBranches,
|
|
492
|
+
recurseList,
|
|
493
|
+
experimental_customMergeAllOf
|
|
494
|
+
);
|
|
448
495
|
});
|
|
449
496
|
}
|
|
450
497
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
@@ -455,15 +502,19 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
455
502
|
rootSchema,
|
|
456
503
|
formData,
|
|
457
504
|
expandAllBranches,
|
|
458
|
-
recurseList
|
|
505
|
+
recurseList,
|
|
506
|
+
experimental_customMergeAllOf
|
|
459
507
|
)
|
|
460
508
|
);
|
|
461
509
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
462
|
-
return allPermutations.map((permutation) => ({
|
|
510
|
+
return allPermutations.map((permutation) => ({
|
|
511
|
+
...schema,
|
|
512
|
+
allOf: permutation
|
|
513
|
+
}));
|
|
463
514
|
}
|
|
464
515
|
return [schema];
|
|
465
516
|
}
|
|
466
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
517
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
467
518
|
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
468
519
|
if (updatedSchema !== schema) {
|
|
469
520
|
return retrieveSchemaInternal(
|
|
@@ -472,7 +523,8 @@ function resolveReference(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
472
523
|
rootSchema,
|
|
473
524
|
formData,
|
|
474
525
|
expandAllBranches,
|
|
475
|
-
recurseList
|
|
526
|
+
recurseList,
|
|
527
|
+
experimental_customMergeAllOf
|
|
476
528
|
);
|
|
477
529
|
}
|
|
478
530
|
return [schema];
|
|
@@ -511,9 +563,9 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
511
563
|
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
512
564
|
};
|
|
513
565
|
}
|
|
514
|
-
return
|
|
566
|
+
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
515
567
|
}
|
|
516
|
-
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
568
|
+
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
517
569
|
const schema = {
|
|
518
570
|
...theSchema,
|
|
519
571
|
properties: { ...theSchema.properties }
|
|
@@ -523,34 +575,54 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
523
575
|
if (key in schema.properties) {
|
|
524
576
|
return;
|
|
525
577
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
if (
|
|
529
|
-
|
|
578
|
+
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
579
|
+
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
580
|
+
if (!isEmpty(matchingProperties)) {
|
|
581
|
+
schema.properties[key] = retrieveSchema(
|
|
530
582
|
validator,
|
|
531
|
-
{
|
|
583
|
+
{ allOf: Object.values(matchingProperties) },
|
|
532
584
|
rootSchema,
|
|
533
|
-
formData
|
|
585
|
+
formData,
|
|
586
|
+
experimental_customMergeAllOf
|
|
534
587
|
);
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
588
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema.additionalProperties !== false) {
|
|
593
|
+
let additionalProperties = {};
|
|
594
|
+
if (typeof schema.additionalProperties !== "boolean") {
|
|
595
|
+
if (REF_KEY in schema.additionalProperties) {
|
|
596
|
+
additionalProperties = retrieveSchema(
|
|
597
|
+
validator,
|
|
598
|
+
{ $ref: get4(schema.additionalProperties, [REF_KEY]) },
|
|
599
|
+
rootSchema,
|
|
600
|
+
formData,
|
|
601
|
+
experimental_customMergeAllOf
|
|
602
|
+
);
|
|
603
|
+
} else if ("type" in schema.additionalProperties) {
|
|
604
|
+
additionalProperties = { ...schema.additionalProperties };
|
|
605
|
+
} else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
|
|
606
|
+
additionalProperties = {
|
|
607
|
+
type: "object",
|
|
608
|
+
...schema.additionalProperties
|
|
609
|
+
};
|
|
610
|
+
} else {
|
|
611
|
+
additionalProperties = { type: guessType(get4(formData, [key])) };
|
|
612
|
+
}
|
|
542
613
|
} else {
|
|
543
614
|
additionalProperties = { type: guessType(get4(formData, [key])) };
|
|
544
615
|
}
|
|
616
|
+
schema.properties[key] = additionalProperties;
|
|
617
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
545
618
|
} else {
|
|
546
|
-
|
|
619
|
+
schema.properties[key] = { type: "null" };
|
|
620
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
547
621
|
}
|
|
548
|
-
schema.properties[key] = additionalProperties;
|
|
549
|
-
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
550
622
|
});
|
|
551
623
|
return schema;
|
|
552
624
|
}
|
|
553
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
625
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf) {
|
|
554
626
|
if (!isObject(schema)) {
|
|
555
627
|
return [{}];
|
|
556
628
|
}
|
|
@@ -560,7 +632,8 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
560
632
|
rootSchema,
|
|
561
633
|
expandAllBranches,
|
|
562
634
|
recurseList,
|
|
563
|
-
rawFormData
|
|
635
|
+
rawFormData,
|
|
636
|
+
experimental_customMergeAllOf
|
|
564
637
|
);
|
|
565
638
|
return resolvedSchemas.flatMap((s) => {
|
|
566
639
|
let resolvedSchema = s;
|
|
@@ -571,7 +644,8 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
571
644
|
rootSchema,
|
|
572
645
|
expandAllBranches,
|
|
573
646
|
recurseList,
|
|
574
|
-
rawFormData
|
|
647
|
+
rawFormData,
|
|
648
|
+
experimental_customMergeAllOf
|
|
575
649
|
);
|
|
576
650
|
}
|
|
577
651
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
@@ -580,18 +654,60 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
580
654
|
return [...allOf, restOfSchema];
|
|
581
655
|
}
|
|
582
656
|
try {
|
|
583
|
-
|
|
657
|
+
const withContainsSchemas = [];
|
|
658
|
+
const withoutContainsSchemas = [];
|
|
659
|
+
resolvedSchema.allOf?.forEach((s2) => {
|
|
660
|
+
if (typeof s2 === "object" && s2.contains) {
|
|
661
|
+
withContainsSchemas.push(s2);
|
|
662
|
+
} else {
|
|
663
|
+
withoutContainsSchemas.push(s2);
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
if (withContainsSchemas.length) {
|
|
667
|
+
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
668
|
+
}
|
|
669
|
+
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : mergeAllOf(resolvedSchema, {
|
|
584
670
|
deep: false
|
|
585
671
|
});
|
|
672
|
+
if (withContainsSchemas.length) {
|
|
673
|
+
resolvedSchema.allOf = withContainsSchemas;
|
|
674
|
+
}
|
|
586
675
|
} catch (e) {
|
|
587
676
|
console.warn("could not merge subschemas in allOf:\n", e);
|
|
588
677
|
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
|
|
589
678
|
return resolvedSchemaWithoutAllOf;
|
|
590
679
|
}
|
|
591
680
|
}
|
|
592
|
-
|
|
681
|
+
if (PROPERTIES_KEY in resolvedSchema && PATTERN_PROPERTIES_KEY in resolvedSchema) {
|
|
682
|
+
resolvedSchema = Object.keys(resolvedSchema.properties).reduce(
|
|
683
|
+
(schema2, key) => {
|
|
684
|
+
const matchingProperties = getMatchingPatternProperties(schema2, key);
|
|
685
|
+
if (!isEmpty(matchingProperties)) {
|
|
686
|
+
schema2.properties[key] = retrieveSchema(
|
|
687
|
+
validator,
|
|
688
|
+
{ allOf: [schema2.properties[key], ...Object.values(matchingProperties)] },
|
|
689
|
+
rootSchema,
|
|
690
|
+
rawFormData,
|
|
691
|
+
experimental_customMergeAllOf
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
return schema2;
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
...resolvedSchema,
|
|
698
|
+
properties: { ...resolvedSchema.properties }
|
|
699
|
+
}
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
const hasAdditionalProperties = PATTERN_PROPERTIES_KEY in resolvedSchema || ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
|
|
593
703
|
if (hasAdditionalProperties) {
|
|
594
|
-
return stubExistingAdditionalProperties(
|
|
704
|
+
return stubExistingAdditionalProperties(
|
|
705
|
+
validator,
|
|
706
|
+
resolvedSchema,
|
|
707
|
+
rootSchema,
|
|
708
|
+
rawFormData,
|
|
709
|
+
experimental_customMergeAllOf
|
|
710
|
+
);
|
|
595
711
|
}
|
|
596
712
|
return resolvedSchema;
|
|
597
713
|
});
|
|
@@ -618,7 +734,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
618
734
|
}
|
|
619
735
|
return [schema];
|
|
620
736
|
}
|
|
621
|
-
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
737
|
+
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
622
738
|
const { dependencies, ...remainingSchema } = schema;
|
|
623
739
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
624
740
|
validator,
|
|
@@ -635,11 +751,12 @@ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, r
|
|
|
635
751
|
rootSchema,
|
|
636
752
|
expandAllBranches,
|
|
637
753
|
recurseList,
|
|
638
|
-
formData
|
|
754
|
+
formData,
|
|
755
|
+
experimental_customMergeAllOf
|
|
639
756
|
)
|
|
640
757
|
);
|
|
641
758
|
}
|
|
642
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
759
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
643
760
|
let schemas = [resolvedSchema];
|
|
644
761
|
for (const dependencyKey in dependencies) {
|
|
645
762
|
if (!expandAllBranches && get4(formData, [dependencyKey]) === void 0) {
|
|
@@ -663,7 +780,8 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
663
780
|
dependencyValue,
|
|
664
781
|
expandAllBranches,
|
|
665
782
|
recurseList,
|
|
666
|
-
formData
|
|
783
|
+
formData,
|
|
784
|
+
experimental_customMergeAllOf
|
|
667
785
|
);
|
|
668
786
|
}
|
|
669
787
|
return schemas.flatMap(
|
|
@@ -674,7 +792,8 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
674
792
|
rootSchema,
|
|
675
793
|
expandAllBranches,
|
|
676
794
|
recurseList,
|
|
677
|
-
formData
|
|
795
|
+
formData,
|
|
796
|
+
experimental_customMergeAllOf
|
|
678
797
|
)
|
|
679
798
|
);
|
|
680
799
|
}
|
|
@@ -687,14 +806,15 @@ function withDependentProperties(schema, additionallyRequired) {
|
|
|
687
806
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
688
807
|
return { ...schema, required };
|
|
689
808
|
}
|
|
690
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
809
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
691
810
|
const dependentSchemas = retrieveSchemaInternal(
|
|
692
811
|
validator,
|
|
693
812
|
dependencyValue,
|
|
694
813
|
rootSchema,
|
|
695
814
|
formData,
|
|
696
815
|
expandAllBranches,
|
|
697
|
-
recurseList
|
|
816
|
+
recurseList,
|
|
817
|
+
experimental_customMergeAllOf
|
|
698
818
|
);
|
|
699
819
|
return dependentSchemas.flatMap((dependent) => {
|
|
700
820
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -718,12 +838,13 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
718
838
|
resolvedOneOf,
|
|
719
839
|
expandAllBranches,
|
|
720
840
|
recurseList,
|
|
721
|
-
formData
|
|
841
|
+
formData,
|
|
842
|
+
experimental_customMergeAllOf
|
|
722
843
|
)
|
|
723
844
|
);
|
|
724
845
|
});
|
|
725
846
|
}
|
|
726
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
847
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
727
848
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
728
849
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
729
850
|
return false;
|
|
@@ -754,13 +875,166 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
754
875
|
rootSchema,
|
|
755
876
|
formData,
|
|
756
877
|
expandAllBranches,
|
|
757
|
-
recurseList
|
|
878
|
+
recurseList,
|
|
879
|
+
experimental_customMergeAllOf
|
|
758
880
|
);
|
|
759
881
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
760
882
|
});
|
|
761
883
|
}
|
|
762
884
|
|
|
885
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
886
|
+
function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField, xxx, formData = {}, experimental_customMergeAllOf) {
|
|
887
|
+
if (Array.isArray(schema[xxx])) {
|
|
888
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
889
|
+
const selectorField = discriminator || fallbackField;
|
|
890
|
+
const xxxOfs = schema[xxx].map(
|
|
891
|
+
(xxxOf) => retrieveSchema(validator, xxxOf, rootSchema, formData, experimental_customMergeAllOf)
|
|
892
|
+
);
|
|
893
|
+
const data = get5(formData, selectorField);
|
|
894
|
+
if (data !== void 0) {
|
|
895
|
+
return xxxOfs.find((xxx2) => {
|
|
896
|
+
return isEqual(
|
|
897
|
+
get5(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get5(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
898
|
+
data
|
|
899
|
+
);
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
return void 0;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
// src/schema/getFromSchema.ts
|
|
907
|
+
import get6 from "lodash/get";
|
|
908
|
+
import has2 from "lodash/has";
|
|
909
|
+
import isEmpty2 from "lodash/isEmpty";
|
|
910
|
+
function getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf) {
|
|
911
|
+
let fieldSchema = schema;
|
|
912
|
+
if (has2(schema, REF_KEY)) {
|
|
913
|
+
fieldSchema = retrieveSchema(validator, schema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
914
|
+
}
|
|
915
|
+
if (isEmpty2(path)) {
|
|
916
|
+
return fieldSchema;
|
|
917
|
+
}
|
|
918
|
+
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
919
|
+
const [part, ...nestedPath] = pathList;
|
|
920
|
+
if (part && has2(fieldSchema, part)) {
|
|
921
|
+
fieldSchema = get6(fieldSchema, part);
|
|
922
|
+
return getFromSchemaInternal(
|
|
923
|
+
validator,
|
|
924
|
+
rootSchema,
|
|
925
|
+
fieldSchema,
|
|
926
|
+
nestedPath,
|
|
927
|
+
experimental_customMergeAllOf
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
return void 0;
|
|
931
|
+
}
|
|
932
|
+
function getFromSchema(validator, rootSchema, schema, path, defaultValue, experimental_customMergeAllOf) {
|
|
933
|
+
const result = getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf);
|
|
934
|
+
if (result === void 0) {
|
|
935
|
+
return defaultValue;
|
|
936
|
+
}
|
|
937
|
+
return result;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// src/schema/findFieldInSchema.ts
|
|
941
|
+
var NOT_FOUND_SCHEMA = { title: "!@#$_UNKNOWN_$#@!" };
|
|
942
|
+
function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, experimental_customMergeAllOf) {
|
|
943
|
+
const pathList = Array.isArray(path) ? [...path] : path.split(".");
|
|
944
|
+
let parentField = schema;
|
|
945
|
+
const fieldName = pathList.pop();
|
|
946
|
+
if (pathList.length) {
|
|
947
|
+
pathList.forEach((subPath) => {
|
|
948
|
+
parentField = getFromSchema(
|
|
949
|
+
validator,
|
|
950
|
+
rootSchema,
|
|
951
|
+
parentField,
|
|
952
|
+
[PROPERTIES_KEY, subPath],
|
|
953
|
+
{},
|
|
954
|
+
experimental_customMergeAllOf
|
|
955
|
+
);
|
|
956
|
+
if (has3(parentField, ONE_OF_KEY)) {
|
|
957
|
+
parentField = findSelectedOptionInXxxOf(
|
|
958
|
+
validator,
|
|
959
|
+
rootSchema,
|
|
960
|
+
parentField,
|
|
961
|
+
fieldName,
|
|
962
|
+
ONE_OF_KEY,
|
|
963
|
+
get7(formData, subPath),
|
|
964
|
+
experimental_customMergeAllOf
|
|
965
|
+
);
|
|
966
|
+
} else if (has3(parentField, ANY_OF_KEY)) {
|
|
967
|
+
parentField = findSelectedOptionInXxxOf(
|
|
968
|
+
validator,
|
|
969
|
+
rootSchema,
|
|
970
|
+
parentField,
|
|
971
|
+
fieldName,
|
|
972
|
+
ANY_OF_KEY,
|
|
973
|
+
get7(formData, subPath),
|
|
974
|
+
experimental_customMergeAllOf
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
if (has3(parentField, ONE_OF_KEY)) {
|
|
980
|
+
parentField = findSelectedOptionInXxxOf(
|
|
981
|
+
validator,
|
|
982
|
+
rootSchema,
|
|
983
|
+
parentField,
|
|
984
|
+
fieldName,
|
|
985
|
+
ONE_OF_KEY,
|
|
986
|
+
formData,
|
|
987
|
+
experimental_customMergeAllOf
|
|
988
|
+
);
|
|
989
|
+
} else if (has3(parentField, ANY_OF_KEY)) {
|
|
990
|
+
parentField = findSelectedOptionInXxxOf(
|
|
991
|
+
validator,
|
|
992
|
+
rootSchema,
|
|
993
|
+
parentField,
|
|
994
|
+
fieldName,
|
|
995
|
+
ANY_OF_KEY,
|
|
996
|
+
formData,
|
|
997
|
+
experimental_customMergeAllOf
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
let field = getFromSchema(
|
|
1001
|
+
validator,
|
|
1002
|
+
rootSchema,
|
|
1003
|
+
parentField,
|
|
1004
|
+
[PROPERTIES_KEY, fieldName],
|
|
1005
|
+
NOT_FOUND_SCHEMA,
|
|
1006
|
+
experimental_customMergeAllOf
|
|
1007
|
+
);
|
|
1008
|
+
if (field === NOT_FOUND_SCHEMA) {
|
|
1009
|
+
field = void 0;
|
|
1010
|
+
}
|
|
1011
|
+
const requiredArray = getFromSchema(
|
|
1012
|
+
validator,
|
|
1013
|
+
rootSchema,
|
|
1014
|
+
parentField,
|
|
1015
|
+
REQUIRED_KEY,
|
|
1016
|
+
[],
|
|
1017
|
+
experimental_customMergeAllOf
|
|
1018
|
+
);
|
|
1019
|
+
let isRequired;
|
|
1020
|
+
if (field && Array.isArray(requiredArray)) {
|
|
1021
|
+
isRequired = requiredArray.includes(fieldName);
|
|
1022
|
+
}
|
|
1023
|
+
return { field, isRequired };
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
// src/schema/getDefaultFormState.ts
|
|
1027
|
+
import get11 from "lodash/get";
|
|
1028
|
+
import isEmpty3 from "lodash/isEmpty";
|
|
1029
|
+
|
|
763
1030
|
// src/schema/getClosestMatchingOption.ts
|
|
1031
|
+
import get8 from "lodash/get";
|
|
1032
|
+
import has4 from "lodash/has";
|
|
1033
|
+
import isNumber2 from "lodash/isNumber";
|
|
1034
|
+
import isObject2 from "lodash/isObject";
|
|
1035
|
+
import isString2 from "lodash/isString";
|
|
1036
|
+
import reduce from "lodash/reduce";
|
|
1037
|
+
import times2 from "lodash/times";
|
|
764
1038
|
var JUNK_OPTION = {
|
|
765
1039
|
type: "object",
|
|
766
1040
|
$id: JUNK_OPTION_ID,
|
|
@@ -770,35 +1044,51 @@ var JUNK_OPTION = {
|
|
|
770
1044
|
}
|
|
771
1045
|
}
|
|
772
1046
|
};
|
|
773
|
-
function calculateIndexScore(validator, rootSchema, schema, formData
|
|
1047
|
+
function calculateIndexScore(validator, rootSchema, schema, formData, experimental_customMergeAllOf) {
|
|
774
1048
|
let totalScore = 0;
|
|
775
1049
|
if (schema) {
|
|
776
1050
|
if (isObject2(schema.properties)) {
|
|
777
1051
|
totalScore += reduce(
|
|
778
1052
|
schema.properties,
|
|
779
1053
|
(score, value, key) => {
|
|
780
|
-
const formValue =
|
|
1054
|
+
const formValue = get8(formData, key);
|
|
781
1055
|
if (typeof value === "boolean") {
|
|
782
1056
|
return score;
|
|
783
1057
|
}
|
|
784
|
-
if (
|
|
785
|
-
const newSchema = retrieveSchema(
|
|
786
|
-
|
|
1058
|
+
if (has4(value, REF_KEY)) {
|
|
1059
|
+
const newSchema = retrieveSchema(
|
|
1060
|
+
validator,
|
|
1061
|
+
value,
|
|
1062
|
+
rootSchema,
|
|
1063
|
+
formValue,
|
|
1064
|
+
experimental_customMergeAllOf
|
|
1065
|
+
);
|
|
1066
|
+
return score + calculateIndexScore(
|
|
1067
|
+
validator,
|
|
1068
|
+
rootSchema,
|
|
1069
|
+
newSchema,
|
|
1070
|
+
formValue || {},
|
|
1071
|
+
experimental_customMergeAllOf
|
|
1072
|
+
);
|
|
787
1073
|
}
|
|
788
|
-
if ((
|
|
789
|
-
const key2 =
|
|
1074
|
+
if ((has4(value, ONE_OF_KEY) || has4(value, ANY_OF_KEY)) && formValue) {
|
|
1075
|
+
const key2 = has4(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
790
1076
|
const discriminator = getDiscriminatorFieldFromSchema(value);
|
|
791
1077
|
return score + getClosestMatchingOption(
|
|
792
1078
|
validator,
|
|
793
1079
|
rootSchema,
|
|
794
1080
|
formValue,
|
|
795
|
-
|
|
1081
|
+
get8(value, key2),
|
|
796
1082
|
-1,
|
|
797
|
-
discriminator
|
|
1083
|
+
discriminator,
|
|
1084
|
+
experimental_customMergeAllOf
|
|
798
1085
|
);
|
|
799
1086
|
}
|
|
800
1087
|
if (value.type === "object") {
|
|
801
|
-
|
|
1088
|
+
if (isObject2(formValue)) {
|
|
1089
|
+
score += 1;
|
|
1090
|
+
}
|
|
1091
|
+
return score + calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf);
|
|
802
1092
|
}
|
|
803
1093
|
if (value.type === guessType(formValue)) {
|
|
804
1094
|
let newScore = score + 1;
|
|
@@ -819,7 +1109,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
819
1109
|
}
|
|
820
1110
|
return totalScore;
|
|
821
1111
|
}
|
|
822
|
-
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
1112
|
+
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField, experimental_customMergeAllOf) {
|
|
823
1113
|
const resolvedOptions = options.map((option) => {
|
|
824
1114
|
return resolveAllReferences(option, rootSchema, []);
|
|
825
1115
|
});
|
|
@@ -846,7 +1136,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
846
1136
|
(scoreData, index) => {
|
|
847
1137
|
const { bestScore } = scoreData;
|
|
848
1138
|
const option = resolvedOptions[index];
|
|
849
|
-
const score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1139
|
+
const score = calculateIndexScore(validator, rootSchema, option, formData, experimental_customMergeAllOf);
|
|
850
1140
|
scoreCount.add(score);
|
|
851
1141
|
if (score > bestScore) {
|
|
852
1142
|
return { bestIndex: index, bestScore: score };
|
|
@@ -867,57 +1157,79 @@ function isFixedItems(schema) {
|
|
|
867
1157
|
}
|
|
868
1158
|
|
|
869
1159
|
// src/mergeDefaultsWithFormData.ts
|
|
870
|
-
import
|
|
871
|
-
|
|
1160
|
+
import get9 from "lodash/get";
|
|
1161
|
+
import isNil from "lodash/isNil";
|
|
1162
|
+
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false, overrideFormDataWithDefaults = false) {
|
|
872
1163
|
if (Array.isArray(formData)) {
|
|
873
1164
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
874
|
-
const
|
|
875
|
-
|
|
876
|
-
|
|
1165
|
+
const overrideArray = overrideFormDataWithDefaults ? defaultsArray : formData;
|
|
1166
|
+
const overrideOppositeArray = overrideFormDataWithDefaults ? formData : defaultsArray;
|
|
1167
|
+
const mapped = overrideArray.map((value, idx) => {
|
|
1168
|
+
if (overrideOppositeArray[idx] !== void 0) {
|
|
1169
|
+
return mergeDefaultsWithFormData(
|
|
1170
|
+
defaultsArray[idx],
|
|
1171
|
+
formData[idx],
|
|
1172
|
+
mergeExtraArrayDefaults,
|
|
1173
|
+
defaultSupercedesUndefined,
|
|
1174
|
+
overrideFormDataWithDefaults
|
|
1175
|
+
);
|
|
877
1176
|
}
|
|
878
1177
|
return value;
|
|
879
1178
|
});
|
|
880
|
-
if (mergeExtraArrayDefaults && mapped.length <
|
|
881
|
-
mapped.push(...
|
|
1179
|
+
if ((mergeExtraArrayDefaults || overrideFormDataWithDefaults) && mapped.length < overrideOppositeArray.length) {
|
|
1180
|
+
mapped.push(...overrideOppositeArray.slice(mapped.length));
|
|
882
1181
|
}
|
|
883
1182
|
return mapped;
|
|
884
1183
|
}
|
|
885
1184
|
if (isObject(formData)) {
|
|
886
1185
|
const acc = Object.assign({}, defaults);
|
|
887
1186
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
1187
|
+
const keyValue = get9(formData, key);
|
|
1188
|
+
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
1189
|
+
const keyExistsInFormData = key in formData;
|
|
888
1190
|
acc2[key] = mergeDefaultsWithFormData(
|
|
889
|
-
defaults ?
|
|
890
|
-
|
|
891
|
-
mergeExtraArrayDefaults
|
|
1191
|
+
defaults ? get9(defaults, key) : {},
|
|
1192
|
+
keyValue,
|
|
1193
|
+
mergeExtraArrayDefaults,
|
|
1194
|
+
defaultSupercedesUndefined,
|
|
1195
|
+
// overrideFormDataWithDefaults can be true only when the key value exists in defaults
|
|
1196
|
+
// Or if the key value doesn't exist in formData
|
|
1197
|
+
overrideFormDataWithDefaults && (keyExistsInDefaults || !keyExistsInFormData)
|
|
892
1198
|
);
|
|
893
1199
|
return acc2;
|
|
894
1200
|
}, acc);
|
|
895
1201
|
}
|
|
1202
|
+
if (defaultSupercedesUndefined && (!isNil(defaults) && isNil(formData) || typeof formData === "number" && isNaN(formData)) || overrideFormDataWithDefaults && !isNil(formData)) {
|
|
1203
|
+
return defaults;
|
|
1204
|
+
}
|
|
896
1205
|
return formData;
|
|
897
1206
|
}
|
|
898
1207
|
|
|
899
1208
|
// src/mergeObjects.ts
|
|
900
1209
|
function mergeObjects(obj1, obj2, concatArrays = false) {
|
|
901
|
-
return Object.keys(obj2).reduce(
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1210
|
+
return Object.keys(obj2).reduce(
|
|
1211
|
+
(acc, key) => {
|
|
1212
|
+
const left = obj1 ? obj1[key] : {}, right = obj2[key];
|
|
1213
|
+
if (obj1 && key in obj1 && isObject(right)) {
|
|
1214
|
+
acc[key] = mergeObjects(left, right, concatArrays);
|
|
1215
|
+
} else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
|
|
1216
|
+
let toMerge = right;
|
|
1217
|
+
if (concatArrays === "preventDuplicates") {
|
|
1218
|
+
toMerge = right.reduce((result, value) => {
|
|
1219
|
+
if (!left.includes(value)) {
|
|
1220
|
+
result.push(value);
|
|
1221
|
+
}
|
|
1222
|
+
return result;
|
|
1223
|
+
}, []);
|
|
1224
|
+
}
|
|
1225
|
+
acc[key] = left.concat(toMerge);
|
|
1226
|
+
} else {
|
|
1227
|
+
acc[key] = right;
|
|
914
1228
|
}
|
|
915
|
-
acc
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
return acc;
|
|
920
|
-
}, Object.assign({}, obj1));
|
|
1229
|
+
return acc;
|
|
1230
|
+
},
|
|
1231
|
+
Object.assign({}, obj1)
|
|
1232
|
+
);
|
|
921
1233
|
}
|
|
922
1234
|
|
|
923
1235
|
// src/isConstant.ts
|
|
@@ -926,8 +1238,8 @@ function isConstant(schema) {
|
|
|
926
1238
|
}
|
|
927
1239
|
|
|
928
1240
|
// src/schema/isSelect.ts
|
|
929
|
-
function isSelect(validator, theSchema, rootSchema = {}) {
|
|
930
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0);
|
|
1241
|
+
function isSelect(validator, theSchema, rootSchema = {}, experimental_customMergeAllOf) {
|
|
1242
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
931
1243
|
const altSchemas = schema.oneOf || schema.anyOf;
|
|
932
1244
|
if (Array.isArray(schema.enum)) {
|
|
933
1245
|
return true;
|
|
@@ -939,14 +1251,85 @@ function isSelect(validator, theSchema, rootSchema = {}) {
|
|
|
939
1251
|
}
|
|
940
1252
|
|
|
941
1253
|
// src/schema/isMultiSelect.ts
|
|
942
|
-
function isMultiSelect(validator, schema, rootSchema) {
|
|
1254
|
+
function isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) {
|
|
943
1255
|
if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
|
|
944
1256
|
return false;
|
|
945
1257
|
}
|
|
946
|
-
return isSelect(validator, schema.items, rootSchema);
|
|
1258
|
+
return isSelect(validator, schema.items, rootSchema, experimental_customMergeAllOf);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
// src/constIsAjvDataReference.ts
|
|
1262
|
+
import isString3 from "lodash/isString";
|
|
1263
|
+
function constIsAjvDataReference(schema) {
|
|
1264
|
+
const schemaConst = schema[CONST_KEY];
|
|
1265
|
+
const schemaType = getSchemaType(schema);
|
|
1266
|
+
return isObject(schemaConst) && isString3(schemaConst?.$data) && schemaType !== "object" && schemaType !== "array";
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
// src/optionsList.ts
|
|
1270
|
+
import get10 from "lodash/get";
|
|
1271
|
+
|
|
1272
|
+
// src/toConstant.ts
|
|
1273
|
+
function toConstant(schema) {
|
|
1274
|
+
if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
|
|
1275
|
+
return schema.enum[0];
|
|
1276
|
+
}
|
|
1277
|
+
if (CONST_KEY in schema) {
|
|
1278
|
+
return schema.const;
|
|
1279
|
+
}
|
|
1280
|
+
throw new Error("schema cannot be inferred as a constant");
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
// src/optionsList.ts
|
|
1284
|
+
function optionsList(schema, uiSchema) {
|
|
1285
|
+
if (schema.enum) {
|
|
1286
|
+
let enumNames;
|
|
1287
|
+
if (uiSchema) {
|
|
1288
|
+
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
1289
|
+
enumNames = uiEnumNames;
|
|
1290
|
+
}
|
|
1291
|
+
return schema.enum.map((value, i) => {
|
|
1292
|
+
const label = enumNames?.[i] || String(value);
|
|
1293
|
+
return { label, value };
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
let altSchemas = void 0;
|
|
1297
|
+
let altUiSchemas = void 0;
|
|
1298
|
+
if (schema.anyOf) {
|
|
1299
|
+
altSchemas = schema.anyOf;
|
|
1300
|
+
altUiSchemas = uiSchema?.anyOf;
|
|
1301
|
+
} else if (schema.oneOf) {
|
|
1302
|
+
altSchemas = schema.oneOf;
|
|
1303
|
+
altUiSchemas = uiSchema?.oneOf;
|
|
1304
|
+
}
|
|
1305
|
+
let selectorField = getDiscriminatorFieldFromSchema(schema);
|
|
1306
|
+
if (uiSchema) {
|
|
1307
|
+
const { optionsSchemaSelector = selectorField } = getUiOptions(uiSchema);
|
|
1308
|
+
selectorField = optionsSchemaSelector;
|
|
1309
|
+
}
|
|
1310
|
+
return altSchemas && altSchemas.map((aSchemaDef, index) => {
|
|
1311
|
+
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
1312
|
+
const aSchema = aSchemaDef;
|
|
1313
|
+
let value;
|
|
1314
|
+
let label = title;
|
|
1315
|
+
if (selectorField) {
|
|
1316
|
+
const innerSchema = get10(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
1317
|
+
value = get10(innerSchema, DEFAULT_KEY, get10(innerSchema, CONST_KEY));
|
|
1318
|
+
label = label || innerSchema?.title || aSchema.title || String(value);
|
|
1319
|
+
} else {
|
|
1320
|
+
value = toConstant(aSchema);
|
|
1321
|
+
label = label || aSchema.title || String(value);
|
|
1322
|
+
}
|
|
1323
|
+
return {
|
|
1324
|
+
schema: aSchema,
|
|
1325
|
+
label,
|
|
1326
|
+
value
|
|
1327
|
+
};
|
|
1328
|
+
});
|
|
947
1329
|
}
|
|
948
1330
|
|
|
949
1331
|
// src/schema/getDefaultFormState.ts
|
|
1332
|
+
var PRIMITIVE_TYPES = ["string", "number", "integer", "boolean", "null"];
|
|
950
1333
|
function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, idx = -1) {
|
|
951
1334
|
if (idx >= 0) {
|
|
952
1335
|
if (Array.isArray(schema.items) && idx < schema.items.length) {
|
|
@@ -963,47 +1346,54 @@ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, id
|
|
|
963
1346
|
}
|
|
964
1347
|
return {};
|
|
965
1348
|
}
|
|
966
|
-
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}) {
|
|
1349
|
+
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
|
|
967
1350
|
const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
|
|
968
|
-
if (includeUndefinedValues) {
|
|
1351
|
+
if (includeUndefinedValues || isConst) {
|
|
969
1352
|
obj[key] = computedDefault;
|
|
970
1353
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
1354
|
+
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
971
1355
|
if (isObject(computedDefault)) {
|
|
972
|
-
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
973
1356
|
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
974
|
-
if (!
|
|
1357
|
+
if (!isEmpty3(computedDefault)) {
|
|
975
1358
|
obj[key] = computedDefault;
|
|
976
1359
|
}
|
|
977
|
-
} else if ((!
|
|
1360
|
+
} else if ((!isEmpty3(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
978
1361
|
obj[key] = computedDefault;
|
|
979
1362
|
}
|
|
980
1363
|
} else if (
|
|
981
1364
|
// Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
|
|
982
1365
|
// Condition 1: computedDefault is not undefined
|
|
983
|
-
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
984
|
-
|
|
1366
|
+
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
1367
|
+
// Or if isSelfOrParentRequired is 'true' and the key is a required field
|
|
1368
|
+
computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || emptyObjectFields === "skipEmptyDefaults" || isSelfOrParentRequired && requiredFields.includes(key))
|
|
985
1369
|
) {
|
|
986
1370
|
obj[key] = computedDefault;
|
|
987
1371
|
}
|
|
988
1372
|
}
|
|
989
1373
|
}
|
|
990
|
-
function computeDefaults(validator, rawSchema, {
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1374
|
+
function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
1375
|
+
const {
|
|
1376
|
+
parentDefaults,
|
|
1377
|
+
rawFormData,
|
|
1378
|
+
rootSchema = {},
|
|
1379
|
+
includeUndefinedValues = false,
|
|
1380
|
+
_recurseList = [],
|
|
1381
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1382
|
+
experimental_customMergeAllOf = void 0,
|
|
1383
|
+
required,
|
|
1384
|
+
shouldMergeDefaultsIntoFormData = false
|
|
1385
|
+
} = computeDefaultsProps;
|
|
999
1386
|
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1000
1387
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
1001
1388
|
let defaults = parentDefaults;
|
|
1002
1389
|
let schemaToCompute = null;
|
|
1390
|
+
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
|
|
1003
1391
|
let updatedRecurseList = _recurseList;
|
|
1004
|
-
if (
|
|
1392
|
+
if (schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1393
|
+
defaults = schema[CONST_KEY];
|
|
1394
|
+
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1005
1395
|
defaults = mergeObjects(defaults, schema.default);
|
|
1006
|
-
} else if (DEFAULT_KEY in schema) {
|
|
1396
|
+
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY]) {
|
|
1007
1397
|
defaults = schema.default;
|
|
1008
1398
|
} else if (REF_KEY in schema) {
|
|
1009
1399
|
const refName = schema[REF_KEY];
|
|
@@ -1012,7 +1402,19 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1012
1402
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1013
1403
|
}
|
|
1014
1404
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
1015
|
-
const
|
|
1405
|
+
const defaultFormData = {
|
|
1406
|
+
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults),
|
|
1407
|
+
...formData
|
|
1408
|
+
};
|
|
1409
|
+
const resolvedSchema = resolveDependencies(
|
|
1410
|
+
validator,
|
|
1411
|
+
schema,
|
|
1412
|
+
rootSchema,
|
|
1413
|
+
false,
|
|
1414
|
+
[],
|
|
1415
|
+
defaultFormData,
|
|
1416
|
+
experimental_customMergeAllOf
|
|
1417
|
+
);
|
|
1016
1418
|
schemaToCompute = resolvedSchema[0];
|
|
1017
1419
|
} else if (isFixedItems(schema)) {
|
|
1018
1420
|
defaults = schema.items.map(
|
|
@@ -1021,9 +1423,11 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1021
1423
|
includeUndefinedValues,
|
|
1022
1424
|
_recurseList,
|
|
1023
1425
|
experimental_defaultFormStateBehavior,
|
|
1426
|
+
experimental_customMergeAllOf,
|
|
1024
1427
|
parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : void 0,
|
|
1025
1428
|
rawFormData: formData,
|
|
1026
|
-
required
|
|
1429
|
+
required,
|
|
1430
|
+
shouldMergeDefaultsIntoFormData
|
|
1027
1431
|
})
|
|
1028
1432
|
);
|
|
1029
1433
|
} else if (ONE_OF_KEY in schema) {
|
|
@@ -1032,13 +1436,21 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1032
1436
|
return void 0;
|
|
1033
1437
|
}
|
|
1034
1438
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1439
|
+
const { type = "null" } = remaining;
|
|
1440
|
+
if (!Array.isArray(type) && PRIMITIVE_TYPES.includes(type) && experimental_dfsb_to_compute?.constAsDefaults === "skipOneOf") {
|
|
1441
|
+
experimental_dfsb_to_compute = {
|
|
1442
|
+
...experimental_dfsb_to_compute,
|
|
1443
|
+
constAsDefaults: "never"
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1035
1446
|
schemaToCompute = oneOf[getClosestMatchingOption(
|
|
1036
1447
|
validator,
|
|
1037
1448
|
rootSchema,
|
|
1038
|
-
|
|
1449
|
+
rawFormData ?? schema.default,
|
|
1039
1450
|
oneOf,
|
|
1040
1451
|
0,
|
|
1041
|
-
discriminator
|
|
1452
|
+
discriminator,
|
|
1453
|
+
experimental_customMergeAllOf
|
|
1042
1454
|
)];
|
|
1043
1455
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1044
1456
|
} else if (ANY_OF_KEY in schema) {
|
|
@@ -1050,10 +1462,11 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1050
1462
|
schemaToCompute = anyOf[getClosestMatchingOption(
|
|
1051
1463
|
validator,
|
|
1052
1464
|
rootSchema,
|
|
1053
|
-
|
|
1465
|
+
rawFormData ?? schema.default,
|
|
1054
1466
|
anyOf,
|
|
1055
1467
|
0,
|
|
1056
|
-
discriminator
|
|
1468
|
+
discriminator,
|
|
1469
|
+
experimental_customMergeAllOf
|
|
1057
1470
|
)];
|
|
1058
1471
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1059
1472
|
}
|
|
@@ -1062,159 +1475,257 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1062
1475
|
rootSchema,
|
|
1063
1476
|
includeUndefinedValues,
|
|
1064
1477
|
_recurseList: updatedRecurseList,
|
|
1065
|
-
experimental_defaultFormStateBehavior,
|
|
1478
|
+
experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
|
|
1479
|
+
experimental_customMergeAllOf,
|
|
1066
1480
|
parentDefaults: defaults,
|
|
1067
1481
|
rawFormData: formData,
|
|
1068
|
-
required
|
|
1482
|
+
required,
|
|
1483
|
+
shouldMergeDefaultsIntoFormData
|
|
1069
1484
|
});
|
|
1070
1485
|
}
|
|
1071
1486
|
if (defaults === void 0) {
|
|
1072
1487
|
defaults = schema.default;
|
|
1073
1488
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
required,
|
|
1094
|
-
retrievedSchema.required,
|
|
1095
|
-
experimental_defaultFormStateBehavior
|
|
1096
|
-
);
|
|
1097
|
-
return acc;
|
|
1098
|
-
},
|
|
1099
|
-
{}
|
|
1489
|
+
const defaultBasedOnSchemaType = getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults);
|
|
1490
|
+
let defaultsWithFormData = defaultBasedOnSchemaType ?? defaults;
|
|
1491
|
+
if (shouldMergeDefaultsIntoFormData) {
|
|
1492
|
+
const { arrayMinItems = {} } = experimental_defaultFormStateBehavior || {};
|
|
1493
|
+
const { mergeExtraDefaults } = arrayMinItems;
|
|
1494
|
+
const matchingFormData = ensureFormDataMatchingSchema(
|
|
1495
|
+
validator,
|
|
1496
|
+
schema,
|
|
1497
|
+
rootSchema,
|
|
1498
|
+
rawFormData,
|
|
1499
|
+
experimental_defaultFormStateBehavior,
|
|
1500
|
+
experimental_customMergeAllOf
|
|
1501
|
+
);
|
|
1502
|
+
if (!isObject(rawFormData) || ALL_OF_KEY in schema) {
|
|
1503
|
+
defaultsWithFormData = mergeDefaultsWithFormData(
|
|
1504
|
+
defaultsWithFormData,
|
|
1505
|
+
matchingFormData,
|
|
1506
|
+
mergeExtraDefaults,
|
|
1507
|
+
true
|
|
1100
1508
|
);
|
|
1101
|
-
if (retrievedSchema.additionalProperties) {
|
|
1102
|
-
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1103
|
-
const keys = /* @__PURE__ */ new Set();
|
|
1104
|
-
if (isObject(defaults)) {
|
|
1105
|
-
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys.add(key));
|
|
1106
|
-
}
|
|
1107
|
-
const formDataRequired = [];
|
|
1108
|
-
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1109
|
-
keys.add(key);
|
|
1110
|
-
formDataRequired.push(key);
|
|
1111
|
-
});
|
|
1112
|
-
keys.forEach((key) => {
|
|
1113
|
-
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1114
|
-
rootSchema,
|
|
1115
|
-
_recurseList,
|
|
1116
|
-
experimental_defaultFormStateBehavior,
|
|
1117
|
-
includeUndefinedValues: includeUndefinedValues === true,
|
|
1118
|
-
parentDefaults: get7(defaults, [key]),
|
|
1119
|
-
rawFormData: get7(formData, [key]),
|
|
1120
|
-
required: retrievedSchema.required?.includes(key)
|
|
1121
|
-
});
|
|
1122
|
-
maybeAddDefaultToObject(
|
|
1123
|
-
objectDefaults,
|
|
1124
|
-
key,
|
|
1125
|
-
computedDefault,
|
|
1126
|
-
includeUndefinedValues,
|
|
1127
|
-
required,
|
|
1128
|
-
formDataRequired
|
|
1129
|
-
);
|
|
1130
|
-
});
|
|
1131
|
-
}
|
|
1132
|
-
return objectDefaults;
|
|
1133
1509
|
}
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1510
|
+
}
|
|
1511
|
+
return defaultsWithFormData;
|
|
1512
|
+
}
|
|
1513
|
+
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1514
|
+
const isSelectField = !isConstant(schema) && isSelect(validator, schema, rootSchema, experimental_customMergeAllOf);
|
|
1515
|
+
let validFormData = formData;
|
|
1516
|
+
if (isSelectField) {
|
|
1517
|
+
const getOptionsList = optionsList(schema);
|
|
1518
|
+
const isValid = getOptionsList?.some((option) => deepEquals(option.value, formData));
|
|
1519
|
+
validFormData = isValid ? formData : void 0;
|
|
1520
|
+
}
|
|
1521
|
+
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
1522
|
+
if (constTakesPrecedence) {
|
|
1523
|
+
validFormData = schema.const;
|
|
1524
|
+
}
|
|
1525
|
+
return validFormData;
|
|
1526
|
+
}
|
|
1527
|
+
function getObjectDefaults(validator, rawSchema, {
|
|
1528
|
+
rawFormData,
|
|
1529
|
+
rootSchema = {},
|
|
1530
|
+
includeUndefinedValues = false,
|
|
1531
|
+
_recurseList = [],
|
|
1532
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1533
|
+
experimental_customMergeAllOf = void 0,
|
|
1534
|
+
required,
|
|
1535
|
+
shouldMergeDefaultsIntoFormData
|
|
1536
|
+
} = {}, defaults) {
|
|
1537
|
+
{
|
|
1538
|
+
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1539
|
+
const schema = rawSchema;
|
|
1540
|
+
const retrievedSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema ? retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf) : schema;
|
|
1541
|
+
const parentConst = retrievedSchema[CONST_KEY];
|
|
1542
|
+
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1543
|
+
(acc, key) => {
|
|
1544
|
+
const propertySchema = get11(retrievedSchema, [PROPERTIES_KEY, key], {});
|
|
1545
|
+
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1546
|
+
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1547
|
+
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
1548
|
+
rootSchema,
|
|
1549
|
+
_recurseList,
|
|
1550
|
+
experimental_defaultFormStateBehavior,
|
|
1551
|
+
experimental_customMergeAllOf,
|
|
1552
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1553
|
+
parentDefaults: get11(defaults, [key]),
|
|
1554
|
+
rawFormData: get11(formData, [key]),
|
|
1555
|
+
required: retrievedSchema.required?.includes(key),
|
|
1556
|
+
shouldMergeDefaultsIntoFormData
|
|
1150
1557
|
});
|
|
1558
|
+
maybeAddDefaultToObject(
|
|
1559
|
+
acc,
|
|
1560
|
+
key,
|
|
1561
|
+
computedDefault,
|
|
1562
|
+
includeUndefinedValues,
|
|
1563
|
+
required,
|
|
1564
|
+
retrievedSchema.required,
|
|
1565
|
+
experimental_defaultFormStateBehavior,
|
|
1566
|
+
hasConst
|
|
1567
|
+
);
|
|
1568
|
+
return acc;
|
|
1569
|
+
},
|
|
1570
|
+
{}
|
|
1571
|
+
);
|
|
1572
|
+
if (retrievedSchema.additionalProperties) {
|
|
1573
|
+
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1574
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
1575
|
+
if (isObject(defaults)) {
|
|
1576
|
+
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1151
1577
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1578
|
+
const formDataRequired = [];
|
|
1579
|
+
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1580
|
+
keys2.add(key);
|
|
1581
|
+
formDataRequired.push(key);
|
|
1582
|
+
});
|
|
1583
|
+
keys2.forEach((key) => {
|
|
1584
|
+
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1585
|
+
rootSchema,
|
|
1586
|
+
_recurseList,
|
|
1587
|
+
experimental_defaultFormStateBehavior,
|
|
1588
|
+
experimental_customMergeAllOf,
|
|
1589
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1590
|
+
parentDefaults: get11(defaults, [key]),
|
|
1591
|
+
rawFormData: get11(formData, [key]),
|
|
1592
|
+
required: retrievedSchema.required?.includes(key),
|
|
1593
|
+
shouldMergeDefaultsIntoFormData
|
|
1594
|
+
});
|
|
1595
|
+
maybeAddDefaultToObject(
|
|
1596
|
+
objectDefaults,
|
|
1597
|
+
key,
|
|
1598
|
+
computedDefault,
|
|
1599
|
+
includeUndefinedValues,
|
|
1600
|
+
required,
|
|
1601
|
+
formDataRequired
|
|
1602
|
+
);
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
return objectDefaults;
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
function getArrayDefaults(validator, rawSchema, {
|
|
1609
|
+
rawFormData,
|
|
1610
|
+
rootSchema = {},
|
|
1611
|
+
_recurseList = [],
|
|
1612
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1613
|
+
experimental_customMergeAllOf = void 0,
|
|
1614
|
+
required,
|
|
1615
|
+
shouldMergeDefaultsIntoFormData
|
|
1616
|
+
} = {}, defaults) {
|
|
1617
|
+
const schema = rawSchema;
|
|
1618
|
+
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems ?? {};
|
|
1619
|
+
const { populate: arrayMinItemsPopulate, mergeExtraDefaults: arrayMergeExtraDefaults } = arrayMinItemsStateBehavior;
|
|
1620
|
+
const neverPopulate = arrayMinItemsPopulate === "never";
|
|
1621
|
+
const ignoreMinItemsFlagSet = arrayMinItemsPopulate === "requiredOnly";
|
|
1622
|
+
const isPopulateAll = arrayMinItemsPopulate === "all" || !neverPopulate && !ignoreMinItemsFlagSet;
|
|
1623
|
+
const computeSkipPopulate = arrayMinItemsStateBehavior?.computeSkipPopulate ?? (() => false);
|
|
1624
|
+
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
|
|
1625
|
+
const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
|
|
1626
|
+
if (Array.isArray(defaults)) {
|
|
1627
|
+
defaults = defaults.map((item, idx) => {
|
|
1628
|
+
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
1629
|
+
return computeDefaults(validator, schemaItem, {
|
|
1630
|
+
rootSchema,
|
|
1631
|
+
_recurseList,
|
|
1632
|
+
experimental_defaultFormStateBehavior,
|
|
1633
|
+
experimental_customMergeAllOf,
|
|
1634
|
+
parentDefaults: item,
|
|
1635
|
+
required,
|
|
1636
|
+
shouldMergeDefaultsIntoFormData
|
|
1637
|
+
});
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
if (Array.isArray(rawFormData)) {
|
|
1641
|
+
const schemaItem = getInnerSchemaForArrayItem(schema);
|
|
1642
|
+
if (neverPopulate) {
|
|
1643
|
+
defaults = rawFormData;
|
|
1644
|
+
} else {
|
|
1645
|
+
const itemDefaults = rawFormData.map((item, idx) => {
|
|
1646
|
+
return computeDefaults(validator, schemaItem, {
|
|
1185
1647
|
rootSchema,
|
|
1186
1648
|
_recurseList,
|
|
1187
1649
|
experimental_defaultFormStateBehavior,
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1650
|
+
experimental_customMergeAllOf,
|
|
1651
|
+
rawFormData: item,
|
|
1652
|
+
parentDefaults: get11(defaults, [idx]),
|
|
1653
|
+
required,
|
|
1654
|
+
shouldMergeDefaultsIntoFormData
|
|
1655
|
+
});
|
|
1656
|
+
});
|
|
1657
|
+
const mergeExtraDefaults = (ignoreMinItemsFlagSet && required || isPopulateAll) && arrayMergeExtraDefaults;
|
|
1658
|
+
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
const hasConst = isObject(schema) && CONST_KEY in schema && experimental_defaultFormStateBehavior?.constAsDefaults !== "never";
|
|
1662
|
+
if (hasConst === false) {
|
|
1663
|
+
if (neverPopulate) {
|
|
1664
|
+
return defaults ?? emptyDefault;
|
|
1665
|
+
}
|
|
1666
|
+
if (ignoreMinItemsFlagSet && !required) {
|
|
1667
|
+
return defaults ? defaults : void 0;
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1671
|
+
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1672
|
+
return defaults ? defaults : emptyDefault;
|
|
1673
|
+
}
|
|
1674
|
+
const defaultEntries = defaults || [];
|
|
1675
|
+
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
1676
|
+
const fillerDefault = fillerSchema.default;
|
|
1677
|
+
const fillerEntries = new Array(schema.minItems - defaultsLength).fill(
|
|
1678
|
+
computeDefaults(validator, fillerSchema, {
|
|
1679
|
+
parentDefaults: fillerDefault,
|
|
1680
|
+
rootSchema,
|
|
1681
|
+
_recurseList,
|
|
1682
|
+
experimental_defaultFormStateBehavior,
|
|
1683
|
+
experimental_customMergeAllOf,
|
|
1684
|
+
required,
|
|
1685
|
+
shouldMergeDefaultsIntoFormData
|
|
1686
|
+
})
|
|
1687
|
+
);
|
|
1688
|
+
return defaultEntries.concat(fillerEntries);
|
|
1689
|
+
}
|
|
1690
|
+
function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps = {}, defaults) {
|
|
1691
|
+
switch (getSchemaType(rawSchema)) {
|
|
1692
|
+
// We need to recurse for object schema inner default values.
|
|
1693
|
+
case "object": {
|
|
1694
|
+
return getObjectDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1695
|
+
}
|
|
1696
|
+
case "array": {
|
|
1697
|
+
return getArrayDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1192
1698
|
}
|
|
1193
1699
|
}
|
|
1194
|
-
return defaults;
|
|
1195
1700
|
}
|
|
1196
|
-
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
|
|
1701
|
+
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1197
1702
|
if (!isObject(theSchema)) {
|
|
1198
1703
|
throw new Error("Invalid schema: " + theSchema);
|
|
1199
1704
|
}
|
|
1200
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1705
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1201
1706
|
const defaults = computeDefaults(validator, schema, {
|
|
1202
1707
|
rootSchema,
|
|
1203
1708
|
includeUndefinedValues,
|
|
1204
1709
|
experimental_defaultFormStateBehavior,
|
|
1205
|
-
|
|
1710
|
+
experimental_customMergeAllOf,
|
|
1711
|
+
rawFormData: formData,
|
|
1712
|
+
shouldMergeDefaultsIntoFormData: true
|
|
1206
1713
|
});
|
|
1207
|
-
if (formData
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1714
|
+
if (isObject(formData) || Array.isArray(formData)) {
|
|
1715
|
+
const { mergeDefaultsIntoFormData } = experimental_defaultFormStateBehavior || {};
|
|
1716
|
+
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
1717
|
+
const result = mergeDefaultsWithFormData(
|
|
1718
|
+
defaults,
|
|
1719
|
+
formData,
|
|
1720
|
+
true,
|
|
1721
|
+
// set to true to add any additional default array entries.
|
|
1722
|
+
defaultSupercedesUndefined,
|
|
1723
|
+
true
|
|
1724
|
+
// set to true to override formData with defaults if they exist.
|
|
1725
|
+
);
|
|
1726
|
+
return result;
|
|
1216
1727
|
}
|
|
1217
|
-
return
|
|
1728
|
+
return defaults;
|
|
1218
1729
|
}
|
|
1219
1730
|
|
|
1220
1731
|
// src/isCustomWidget.ts
|
|
@@ -1227,25 +1738,31 @@ function isCustomWidget(uiSchema = {}) {
|
|
|
1227
1738
|
}
|
|
1228
1739
|
|
|
1229
1740
|
// src/schema/isFilesArray.ts
|
|
1230
|
-
function isFilesArray(validator, schema, uiSchema = {}, rootSchema) {
|
|
1741
|
+
function isFilesArray(validator, schema, uiSchema = {}, rootSchema, experimental_customMergeAllOf) {
|
|
1231
1742
|
if (uiSchema[UI_WIDGET_KEY] === "files") {
|
|
1232
1743
|
return true;
|
|
1233
1744
|
}
|
|
1234
1745
|
if (schema.items) {
|
|
1235
|
-
const itemsSchema = retrieveSchema(
|
|
1746
|
+
const itemsSchema = retrieveSchema(
|
|
1747
|
+
validator,
|
|
1748
|
+
schema.items,
|
|
1749
|
+
rootSchema,
|
|
1750
|
+
void 0,
|
|
1751
|
+
experimental_customMergeAllOf
|
|
1752
|
+
);
|
|
1236
1753
|
return itemsSchema.type === "string" && itemsSchema.format === "data-url";
|
|
1237
1754
|
}
|
|
1238
1755
|
return false;
|
|
1239
1756
|
}
|
|
1240
1757
|
|
|
1241
1758
|
// src/schema/getDisplayLabel.ts
|
|
1242
|
-
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
|
|
1759
|
+
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions, experimental_customMergeAllOf) {
|
|
1243
1760
|
const uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
1244
1761
|
const { label = true } = uiOptions;
|
|
1245
1762
|
let displayLabel = !!label;
|
|
1246
1763
|
const schemaType = getSchemaType(schema);
|
|
1247
1764
|
if (schemaType === "array") {
|
|
1248
|
-
displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
|
|
1765
|
+
displayLabel = isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || isFilesArray(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) || isCustomWidget(uiSchema);
|
|
1249
1766
|
}
|
|
1250
1767
|
if (schemaType === "object") {
|
|
1251
1768
|
displayLabel = false;
|
|
@@ -1259,54 +1776,50 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1259
1776
|
return displayLabel;
|
|
1260
1777
|
}
|
|
1261
1778
|
|
|
1262
|
-
// src/schema/mergeValidationData.ts
|
|
1263
|
-
import isEmpty2 from "lodash/isEmpty";
|
|
1264
|
-
function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
1265
|
-
if (!additionalErrorSchema) {
|
|
1266
|
-
return validationData;
|
|
1267
|
-
}
|
|
1268
|
-
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
1269
|
-
let errors = validator.toErrorList(additionalErrorSchema);
|
|
1270
|
-
let errorSchema = additionalErrorSchema;
|
|
1271
|
-
if (!isEmpty2(oldErrorSchema)) {
|
|
1272
|
-
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
1273
|
-
errors = [...oldErrors].concat(errors);
|
|
1274
|
-
}
|
|
1275
|
-
return { errorSchema, errors };
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
1779
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
1279
|
-
import
|
|
1280
|
-
import
|
|
1780
|
+
import get12 from "lodash/get";
|
|
1781
|
+
import has5 from "lodash/has";
|
|
1281
1782
|
var NO_VALUE = Symbol("no Value");
|
|
1282
|
-
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
1783
|
+
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
1283
1784
|
let newFormData;
|
|
1284
|
-
if (
|
|
1785
|
+
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
1285
1786
|
const removeOldSchemaData = {};
|
|
1286
|
-
if (
|
|
1287
|
-
const properties =
|
|
1787
|
+
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
1788
|
+
const properties = get12(oldSchema, PROPERTIES_KEY, {});
|
|
1288
1789
|
Object.keys(properties).forEach((key) => {
|
|
1289
|
-
if (
|
|
1790
|
+
if (has5(data, key)) {
|
|
1290
1791
|
removeOldSchemaData[key] = void 0;
|
|
1291
1792
|
}
|
|
1292
1793
|
});
|
|
1293
1794
|
}
|
|
1294
|
-
const
|
|
1795
|
+
const keys2 = Object.keys(get12(newSchema, PROPERTIES_KEY, {}));
|
|
1295
1796
|
const nestedData = {};
|
|
1296
|
-
|
|
1297
|
-
const formValue =
|
|
1298
|
-
let oldKeyedSchema =
|
|
1299
|
-
let newKeyedSchema =
|
|
1300
|
-
if (
|
|
1301
|
-
oldKeyedSchema = retrieveSchema(
|
|
1797
|
+
keys2.forEach((key) => {
|
|
1798
|
+
const formValue = get12(data, key);
|
|
1799
|
+
let oldKeyedSchema = get12(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1800
|
+
let newKeyedSchema = get12(newSchema, [PROPERTIES_KEY, key], {});
|
|
1801
|
+
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
1802
|
+
oldKeyedSchema = retrieveSchema(
|
|
1803
|
+
validator,
|
|
1804
|
+
oldKeyedSchema,
|
|
1805
|
+
rootSchema,
|
|
1806
|
+
formValue,
|
|
1807
|
+
experimental_customMergeAllOf
|
|
1808
|
+
);
|
|
1302
1809
|
}
|
|
1303
|
-
if (
|
|
1304
|
-
newKeyedSchema = retrieveSchema(
|
|
1810
|
+
if (has5(newKeyedSchema, REF_KEY)) {
|
|
1811
|
+
newKeyedSchema = retrieveSchema(
|
|
1812
|
+
validator,
|
|
1813
|
+
newKeyedSchema,
|
|
1814
|
+
rootSchema,
|
|
1815
|
+
formValue,
|
|
1816
|
+
experimental_customMergeAllOf
|
|
1817
|
+
);
|
|
1305
1818
|
}
|
|
1306
|
-
const oldSchemaTypeForKey =
|
|
1307
|
-
const newSchemaTypeForKey =
|
|
1819
|
+
const oldSchemaTypeForKey = get12(oldKeyedSchema, "type");
|
|
1820
|
+
const newSchemaTypeForKey = get12(newKeyedSchema, "type");
|
|
1308
1821
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1309
|
-
if (
|
|
1822
|
+
if (has5(removeOldSchemaData, key)) {
|
|
1310
1823
|
delete removeOldSchemaData[key];
|
|
1311
1824
|
}
|
|
1312
1825
|
if (newSchemaTypeForKey === "object" || newSchemaTypeForKey === "array" && Array.isArray(formValue)) {
|
|
@@ -1315,23 +1828,24 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1315
1828
|
rootSchema,
|
|
1316
1829
|
newKeyedSchema,
|
|
1317
1830
|
oldKeyedSchema,
|
|
1318
|
-
formValue
|
|
1831
|
+
formValue,
|
|
1832
|
+
experimental_customMergeAllOf
|
|
1319
1833
|
);
|
|
1320
1834
|
if (itemData !== void 0 || newSchemaTypeForKey === "array") {
|
|
1321
1835
|
nestedData[key] = itemData;
|
|
1322
1836
|
}
|
|
1323
1837
|
} else {
|
|
1324
|
-
const newOptionDefault =
|
|
1325
|
-
const oldOptionDefault =
|
|
1838
|
+
const newOptionDefault = get12(newKeyedSchema, "default", NO_VALUE);
|
|
1839
|
+
const oldOptionDefault = get12(oldKeyedSchema, "default", NO_VALUE);
|
|
1326
1840
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1327
1841
|
if (oldOptionDefault === formValue) {
|
|
1328
1842
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1329
|
-
} else if (
|
|
1843
|
+
} else if (get12(newKeyedSchema, "readOnly") === true) {
|
|
1330
1844
|
removeOldSchemaData[key] = void 0;
|
|
1331
1845
|
}
|
|
1332
1846
|
}
|
|
1333
|
-
const newOptionConst =
|
|
1334
|
-
const oldOptionConst =
|
|
1847
|
+
const newOptionConst = get12(newKeyedSchema, "const", NO_VALUE);
|
|
1848
|
+
const oldOptionConst = get12(oldKeyedSchema, "const", NO_VALUE);
|
|
1335
1849
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1336
1850
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1337
1851
|
}
|
|
@@ -1343,20 +1857,32 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1343
1857
|
...removeOldSchemaData,
|
|
1344
1858
|
...nestedData
|
|
1345
1859
|
};
|
|
1346
|
-
} else if (
|
|
1347
|
-
let oldSchemaItems =
|
|
1348
|
-
let newSchemaItems =
|
|
1860
|
+
} else if (get12(oldSchema, "type") === "array" && get12(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1861
|
+
let oldSchemaItems = get12(oldSchema, "items");
|
|
1862
|
+
let newSchemaItems = get12(newSchema, "items");
|
|
1349
1863
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1350
|
-
if (
|
|
1351
|
-
oldSchemaItems = retrieveSchema(
|
|
1864
|
+
if (has5(oldSchemaItems, REF_KEY)) {
|
|
1865
|
+
oldSchemaItems = retrieveSchema(
|
|
1866
|
+
validator,
|
|
1867
|
+
oldSchemaItems,
|
|
1868
|
+
rootSchema,
|
|
1869
|
+
data,
|
|
1870
|
+
experimental_customMergeAllOf
|
|
1871
|
+
);
|
|
1352
1872
|
}
|
|
1353
|
-
if (
|
|
1354
|
-
newSchemaItems = retrieveSchema(
|
|
1873
|
+
if (has5(newSchemaItems, REF_KEY)) {
|
|
1874
|
+
newSchemaItems = retrieveSchema(
|
|
1875
|
+
validator,
|
|
1876
|
+
newSchemaItems,
|
|
1877
|
+
rootSchema,
|
|
1878
|
+
data,
|
|
1879
|
+
experimental_customMergeAllOf
|
|
1880
|
+
);
|
|
1355
1881
|
}
|
|
1356
|
-
const oldSchemaType =
|
|
1357
|
-
const newSchemaType =
|
|
1882
|
+
const oldSchemaType = get12(oldSchemaItems, "type");
|
|
1883
|
+
const newSchemaType = get12(newSchemaItems, "type");
|
|
1358
1884
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1359
|
-
const maxItems =
|
|
1885
|
+
const maxItems = get12(newSchema, "maxItems", -1);
|
|
1360
1886
|
if (newSchemaType === "object") {
|
|
1361
1887
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1362
1888
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1364,7 +1890,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1364
1890
|
rootSchema,
|
|
1365
1891
|
newSchemaItems,
|
|
1366
1892
|
oldSchemaItems,
|
|
1367
|
-
aValue
|
|
1893
|
+
aValue,
|
|
1894
|
+
experimental_customMergeAllOf
|
|
1368
1895
|
);
|
|
1369
1896
|
if (itemValue !== void 0 && (maxItems < 0 || newValue.length < maxItems)) {
|
|
1370
1897
|
newValue.push(itemValue);
|
|
@@ -1383,71 +1910,84 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1383
1910
|
}
|
|
1384
1911
|
|
|
1385
1912
|
// src/schema/toIdSchema.ts
|
|
1386
|
-
import
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1913
|
+
import get13 from "lodash/get";
|
|
1914
|
+
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1915
|
+
const $id = id || idPrefix;
|
|
1916
|
+
const idSchema = { $id };
|
|
1917
|
+
if (typeof schema === "object") {
|
|
1918
|
+
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1919
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1920
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1921
|
+
if (sameSchemaIndex === -1) {
|
|
1922
|
+
return toIdSchemaInternal(
|
|
1923
|
+
validator,
|
|
1924
|
+
_schema,
|
|
1925
|
+
idPrefix,
|
|
1926
|
+
idSeparator,
|
|
1927
|
+
id,
|
|
1928
|
+
rootSchema,
|
|
1929
|
+
formData,
|
|
1930
|
+
_recurseList.concat(_schema),
|
|
1931
|
+
experimental_customMergeAllOf
|
|
1932
|
+
);
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
if (ITEMS_KEY in schema && !get13(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1393
1936
|
return toIdSchemaInternal(
|
|
1394
1937
|
validator,
|
|
1395
|
-
|
|
1938
|
+
get13(schema, ITEMS_KEY),
|
|
1396
1939
|
idPrefix,
|
|
1397
1940
|
idSeparator,
|
|
1398
1941
|
id,
|
|
1399
1942
|
rootSchema,
|
|
1400
1943
|
formData,
|
|
1401
|
-
_recurseList
|
|
1944
|
+
_recurseList,
|
|
1945
|
+
experimental_customMergeAllOf
|
|
1402
1946
|
);
|
|
1403
1947
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1423
|
-
idSchema[name] = toIdSchemaInternal(
|
|
1424
|
-
validator,
|
|
1425
|
-
isObject(field) ? field : {},
|
|
1426
|
-
idPrefix,
|
|
1427
|
-
idSeparator,
|
|
1428
|
-
fieldId,
|
|
1429
|
-
rootSchema,
|
|
1430
|
-
// It's possible that formData is not an object -- this can happen if an
|
|
1431
|
-
// array item has just been added, but not populated with data yet
|
|
1432
|
-
get9(formData, [name]),
|
|
1433
|
-
_recurseList
|
|
1434
|
-
);
|
|
1948
|
+
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1949
|
+
for (const name in schema.properties) {
|
|
1950
|
+
const field = schema[PROPERTIES_KEY][name];
|
|
1951
|
+
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1952
|
+
idSchema[name] = toIdSchemaInternal(
|
|
1953
|
+
validator,
|
|
1954
|
+
field,
|
|
1955
|
+
idPrefix,
|
|
1956
|
+
idSeparator,
|
|
1957
|
+
fieldId,
|
|
1958
|
+
rootSchema,
|
|
1959
|
+
// It's possible that formData is not an object -- this can happen if an
|
|
1960
|
+
// array item has just been added, but not populated with data yet
|
|
1961
|
+
get13(formData, [name]),
|
|
1962
|
+
_recurseList,
|
|
1963
|
+
experimental_customMergeAllOf
|
|
1964
|
+
);
|
|
1965
|
+
}
|
|
1435
1966
|
}
|
|
1436
1967
|
}
|
|
1437
1968
|
return idSchema;
|
|
1438
1969
|
}
|
|
1439
|
-
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_") {
|
|
1440
|
-
return toIdSchemaInternal(
|
|
1970
|
+
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_", experimental_customMergeAllOf) {
|
|
1971
|
+
return toIdSchemaInternal(
|
|
1972
|
+
validator,
|
|
1973
|
+
schema,
|
|
1974
|
+
idPrefix,
|
|
1975
|
+
idSeparator,
|
|
1976
|
+
id,
|
|
1977
|
+
rootSchema,
|
|
1978
|
+
formData,
|
|
1979
|
+
void 0,
|
|
1980
|
+
experimental_customMergeAllOf
|
|
1981
|
+
);
|
|
1441
1982
|
}
|
|
1442
1983
|
|
|
1443
1984
|
// src/schema/toPathSchema.ts
|
|
1444
|
-
import
|
|
1445
|
-
import isEqual3 from "lodash/isEqual";
|
|
1985
|
+
import get14 from "lodash/get";
|
|
1446
1986
|
import set2 from "lodash/set";
|
|
1447
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1987
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1448
1988
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1449
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1450
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1989
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1990
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1451
1991
|
if (sameSchemaIndex === -1) {
|
|
1452
1992
|
return toPathSchemaInternal(
|
|
1453
1993
|
validator,
|
|
@@ -1455,7 +1995,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1455
1995
|
name,
|
|
1456
1996
|
rootSchema,
|
|
1457
1997
|
formData,
|
|
1458
|
-
_recurseList.concat(_schema)
|
|
1998
|
+
_recurseList.concat(_schema),
|
|
1999
|
+
experimental_customMergeAllOf
|
|
1459
2000
|
);
|
|
1460
2001
|
}
|
|
1461
2002
|
}
|
|
@@ -1465,11 +2006,27 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1465
2006
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
1466
2007
|
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
1467
2008
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1468
|
-
const index = getClosestMatchingOption(
|
|
2009
|
+
const index = getClosestMatchingOption(
|
|
2010
|
+
validator,
|
|
2011
|
+
rootSchema,
|
|
2012
|
+
formData,
|
|
2013
|
+
xxxOf,
|
|
2014
|
+
0,
|
|
2015
|
+
discriminator,
|
|
2016
|
+
experimental_customMergeAllOf
|
|
2017
|
+
);
|
|
1469
2018
|
const _schema = xxxOf[index];
|
|
1470
2019
|
pathSchema = {
|
|
1471
2020
|
...pathSchema,
|
|
1472
|
-
...toPathSchemaInternal(
|
|
2021
|
+
...toPathSchemaInternal(
|
|
2022
|
+
validator,
|
|
2023
|
+
_schema,
|
|
2024
|
+
name,
|
|
2025
|
+
rootSchema,
|
|
2026
|
+
formData,
|
|
2027
|
+
_recurseList,
|
|
2028
|
+
experimental_customMergeAllOf
|
|
2029
|
+
)
|
|
1473
2030
|
};
|
|
1474
2031
|
}
|
|
1475
2032
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
@@ -1486,7 +2043,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1486
2043
|
`${name}.${i}`,
|
|
1487
2044
|
rootSchema,
|
|
1488
2045
|
element,
|
|
1489
|
-
_recurseList
|
|
2046
|
+
_recurseList,
|
|
2047
|
+
experimental_customMergeAllOf
|
|
1490
2048
|
);
|
|
1491
2049
|
} else if (schemaAdditionalItems) {
|
|
1492
2050
|
pathSchema[i] = toPathSchemaInternal(
|
|
@@ -1495,7 +2053,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1495
2053
|
`${name}.${i}`,
|
|
1496
2054
|
rootSchema,
|
|
1497
2055
|
element,
|
|
1498
|
-
_recurseList
|
|
2056
|
+
_recurseList,
|
|
2057
|
+
experimental_customMergeAllOf
|
|
1499
2058
|
);
|
|
1500
2059
|
} else {
|
|
1501
2060
|
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
@@ -1509,13 +2068,14 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1509
2068
|
`${name}.${i}`,
|
|
1510
2069
|
rootSchema,
|
|
1511
2070
|
element,
|
|
1512
|
-
_recurseList
|
|
2071
|
+
_recurseList,
|
|
2072
|
+
experimental_customMergeAllOf
|
|
1513
2073
|
);
|
|
1514
2074
|
});
|
|
1515
2075
|
}
|
|
1516
2076
|
} else if (PROPERTIES_KEY in schema) {
|
|
1517
2077
|
for (const property in schema.properties) {
|
|
1518
|
-
const field =
|
|
2078
|
+
const field = get14(schema, [PROPERTIES_KEY, property], {});
|
|
1519
2079
|
pathSchema[property] = toPathSchemaInternal(
|
|
1520
2080
|
validator,
|
|
1521
2081
|
field,
|
|
@@ -1523,15 +2083,16 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1523
2083
|
rootSchema,
|
|
1524
2084
|
// It's possible that formData is not an object -- this can happen if an
|
|
1525
2085
|
// array item has just been added, but not populated with data yet
|
|
1526
|
-
|
|
1527
|
-
_recurseList
|
|
2086
|
+
get14(formData, [property]),
|
|
2087
|
+
_recurseList,
|
|
2088
|
+
experimental_customMergeAllOf
|
|
1528
2089
|
);
|
|
1529
2090
|
}
|
|
1530
2091
|
}
|
|
1531
2092
|
return pathSchema;
|
|
1532
2093
|
}
|
|
1533
|
-
function toPathSchema(validator, schema, name = "", rootSchema, formData) {
|
|
1534
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
|
|
2094
|
+
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2095
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
1535
2096
|
}
|
|
1536
2097
|
|
|
1537
2098
|
// src/createSchemaUtils.ts
|
|
@@ -1541,11 +2102,13 @@ var SchemaUtils = class {
|
|
|
1541
2102
|
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
1542
2103
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
1543
2104
|
* @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
|
|
2105
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1544
2106
|
*/
|
|
1545
|
-
constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
|
|
2107
|
+
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1546
2108
|
this.rootSchema = rootSchema;
|
|
1547
2109
|
this.validator = validator;
|
|
1548
2110
|
this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
|
|
2111
|
+
this.experimental_customMergeAllOf = experimental_customMergeAllOf;
|
|
1549
2112
|
}
|
|
1550
2113
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
1551
2114
|
*
|
|
@@ -1561,13 +2124,55 @@ var SchemaUtils = class {
|
|
|
1561
2124
|
* @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
|
|
1562
2125
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
1563
2126
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
2127
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1564
2128
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
1565
2129
|
*/
|
|
1566
|
-
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
2130
|
+
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
1567
2131
|
if (!validator || !rootSchema) {
|
|
1568
2132
|
return false;
|
|
1569
2133
|
}
|
|
1570
|
-
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
|
|
2134
|
+
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
2135
|
+
}
|
|
2136
|
+
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
2137
|
+
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
2138
|
+
* field is in the `required` list for its parent and if so, it is marked as required on return.
|
|
2139
|
+
*
|
|
2140
|
+
* @param schema - The current node within the JSON schema
|
|
2141
|
+
* @param path - The remaining keys in the path to the desired field
|
|
2142
|
+
* @param [formData] - The form data that is used to determine which oneOf option
|
|
2143
|
+
* @returns - An object that contains the field and its required state. If no field can be found then
|
|
2144
|
+
* `{ field: undefined, isRequired: undefined }` is returned.
|
|
2145
|
+
*/
|
|
2146
|
+
findFieldInSchema(schema, path, formData) {
|
|
2147
|
+
return findFieldInSchema(
|
|
2148
|
+
this.validator,
|
|
2149
|
+
this.rootSchema,
|
|
2150
|
+
schema,
|
|
2151
|
+
path,
|
|
2152
|
+
formData,
|
|
2153
|
+
this.experimental_customMergeAllOf
|
|
2154
|
+
);
|
|
2155
|
+
}
|
|
2156
|
+
/** Finds the oneOf option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` that
|
|
2157
|
+
* matches the `formData[selectorField]` value. For the purposes of this function, `selectorField` is either
|
|
2158
|
+
* `schema.discriminator.propertyName` or `fallbackField`.
|
|
2159
|
+
*
|
|
2160
|
+
* @param schema - The schema element in which to search for the selected oneOf option
|
|
2161
|
+
* @param fallbackField - The field to use as a backup selector field if the schema does not have a required field
|
|
2162
|
+
* @param xxx - Either `oneOf` or `anyOf`, defines which value is being sought
|
|
2163
|
+
* @param [formData={}] - The form data that is used to determine which oneOf option
|
|
2164
|
+
* @returns - The anyOf/oneOf option that matches the selector field in the schema or undefined if nothing is selected
|
|
2165
|
+
*/
|
|
2166
|
+
findSelectedOptionInXxxOf(schema, fallbackField, xxx, formData) {
|
|
2167
|
+
return findSelectedOptionInXxxOf(
|
|
2168
|
+
this.validator,
|
|
2169
|
+
this.rootSchema,
|
|
2170
|
+
schema,
|
|
2171
|
+
fallbackField,
|
|
2172
|
+
xxx,
|
|
2173
|
+
formData,
|
|
2174
|
+
this.experimental_customMergeAllOf
|
|
2175
|
+
);
|
|
1571
2176
|
}
|
|
1572
2177
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
1573
2178
|
* computed to have defaults provided in the `schema`.
|
|
@@ -1586,7 +2191,8 @@ var SchemaUtils = class {
|
|
|
1586
2191
|
formData,
|
|
1587
2192
|
this.rootSchema,
|
|
1588
2193
|
includeUndefinedValues,
|
|
1589
|
-
this.experimental_defaultFormStateBehavior
|
|
2194
|
+
this.experimental_defaultFormStateBehavior,
|
|
2195
|
+
this.experimental_customMergeAllOf
|
|
1590
2196
|
);
|
|
1591
2197
|
}
|
|
1592
2198
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
@@ -1598,7 +2204,14 @@ var SchemaUtils = class {
|
|
|
1598
2204
|
* @returns - True if the label should be displayed or false if it should not
|
|
1599
2205
|
*/
|
|
1600
2206
|
getDisplayLabel(schema, uiSchema, globalOptions) {
|
|
1601
|
-
return getDisplayLabel(
|
|
2207
|
+
return getDisplayLabel(
|
|
2208
|
+
this.validator,
|
|
2209
|
+
schema,
|
|
2210
|
+
uiSchema,
|
|
2211
|
+
this.rootSchema,
|
|
2212
|
+
globalOptions,
|
|
2213
|
+
this.experimental_customMergeAllOf
|
|
2214
|
+
);
|
|
1602
2215
|
}
|
|
1603
2216
|
/** Determines which of the given `options` provided most closely matches the `formData`.
|
|
1604
2217
|
* Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
|
|
@@ -1620,7 +2233,8 @@ var SchemaUtils = class {
|
|
|
1620
2233
|
formData,
|
|
1621
2234
|
options,
|
|
1622
2235
|
selectedOption,
|
|
1623
|
-
discriminatorField
|
|
2236
|
+
discriminatorField,
|
|
2237
|
+
this.experimental_customMergeAllOf
|
|
1624
2238
|
);
|
|
1625
2239
|
}
|
|
1626
2240
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
@@ -1635,18 +2249,16 @@ var SchemaUtils = class {
|
|
|
1635
2249
|
getFirstMatchingOption(formData, options, discriminatorField) {
|
|
1636
2250
|
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
1637
2251
|
}
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
getMatchingOption(formData, options, discriminatorField) {
|
|
1649
|
-
return getMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
2252
|
+
getFromSchema(schema, path, defaultValue) {
|
|
2253
|
+
return getFromSchema(
|
|
2254
|
+
this.validator,
|
|
2255
|
+
this.rootSchema,
|
|
2256
|
+
schema,
|
|
2257
|
+
path,
|
|
2258
|
+
// @ts-expect-error TS2769: No overload matches this call
|
|
2259
|
+
defaultValue,
|
|
2260
|
+
this.experimental_customMergeAllOf
|
|
2261
|
+
);
|
|
1650
2262
|
}
|
|
1651
2263
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
1652
2264
|
*
|
|
@@ -1655,7 +2267,7 @@ var SchemaUtils = class {
|
|
|
1655
2267
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1656
2268
|
*/
|
|
1657
2269
|
isFilesArray(schema, uiSchema) {
|
|
1658
|
-
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
|
|
2270
|
+
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1659
2271
|
}
|
|
1660
2272
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
1661
2273
|
*
|
|
@@ -1663,7 +2275,7 @@ var SchemaUtils = class {
|
|
|
1663
2275
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1664
2276
|
*/
|
|
1665
2277
|
isMultiSelect(schema) {
|
|
1666
|
-
return isMultiSelect(this.validator, schema, this.rootSchema);
|
|
2278
|
+
return isMultiSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1667
2279
|
}
|
|
1668
2280
|
/** Checks to see if the `schema` combination represents a select
|
|
1669
2281
|
*
|
|
@@ -1671,21 +2283,7 @@ var SchemaUtils = class {
|
|
|
1671
2283
|
* @returns - True if schema contains a select, otherwise false
|
|
1672
2284
|
*/
|
|
1673
2285
|
isSelect(schema) {
|
|
1674
|
-
return isSelect(this.validator, schema, this.rootSchema);
|
|
1675
|
-
}
|
|
1676
|
-
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
|
|
1677
|
-
* the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
1678
|
-
* `getValidator().toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed,
|
|
1679
|
-
* then `validationData` is returned.
|
|
1680
|
-
*
|
|
1681
|
-
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
1682
|
-
* @param [additionalErrorSchema] - The additional set of errors
|
|
1683
|
-
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1684
|
-
* @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
|
|
1685
|
-
* removed in the next major release.
|
|
1686
|
-
*/
|
|
1687
|
-
mergeValidationData(validationData, additionalErrorSchema) {
|
|
1688
|
-
return mergeValidationData(this.validator, validationData, additionalErrorSchema);
|
|
2286
|
+
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1689
2287
|
}
|
|
1690
2288
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
1691
2289
|
* dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
|
|
@@ -1696,7 +2294,13 @@ var SchemaUtils = class {
|
|
|
1696
2294
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
1697
2295
|
*/
|
|
1698
2296
|
retrieveSchema(schema, rawFormData) {
|
|
1699
|
-
return retrieveSchema(
|
|
2297
|
+
return retrieveSchema(
|
|
2298
|
+
this.validator,
|
|
2299
|
+
schema,
|
|
2300
|
+
this.rootSchema,
|
|
2301
|
+
rawFormData,
|
|
2302
|
+
this.experimental_customMergeAllOf
|
|
2303
|
+
);
|
|
1700
2304
|
}
|
|
1701
2305
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
|
|
1702
2306
|
* new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
|
|
@@ -1710,7 +2314,14 @@ var SchemaUtils = class {
|
|
|
1710
2314
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
1711
2315
|
*/
|
|
1712
2316
|
sanitizeDataForNewSchema(newSchema, oldSchema, data) {
|
|
1713
|
-
return sanitizeDataForNewSchema(
|
|
2317
|
+
return sanitizeDataForNewSchema(
|
|
2318
|
+
this.validator,
|
|
2319
|
+
this.rootSchema,
|
|
2320
|
+
newSchema,
|
|
2321
|
+
oldSchema,
|
|
2322
|
+
data,
|
|
2323
|
+
this.experimental_customMergeAllOf
|
|
2324
|
+
);
|
|
1714
2325
|
}
|
|
1715
2326
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
1716
2327
|
*
|
|
@@ -1722,7 +2333,16 @@ var SchemaUtils = class {
|
|
|
1722
2333
|
* @returns - The `IdSchema` object for the `schema`
|
|
1723
2334
|
*/
|
|
1724
2335
|
toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
|
|
1725
|
-
return toIdSchema(
|
|
2336
|
+
return toIdSchema(
|
|
2337
|
+
this.validator,
|
|
2338
|
+
schema,
|
|
2339
|
+
id,
|
|
2340
|
+
this.rootSchema,
|
|
2341
|
+
formData,
|
|
2342
|
+
idPrefix,
|
|
2343
|
+
idSeparator,
|
|
2344
|
+
this.experimental_customMergeAllOf
|
|
2345
|
+
);
|
|
1726
2346
|
}
|
|
1727
2347
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1728
2348
|
*
|
|
@@ -1732,11 +2352,23 @@ var SchemaUtils = class {
|
|
|
1732
2352
|
* @returns - The `PathSchema` object for the `schema`
|
|
1733
2353
|
*/
|
|
1734
2354
|
toPathSchema(schema, name, formData) {
|
|
1735
|
-
return toPathSchema(
|
|
2355
|
+
return toPathSchema(
|
|
2356
|
+
this.validator,
|
|
2357
|
+
schema,
|
|
2358
|
+
name,
|
|
2359
|
+
this.rootSchema,
|
|
2360
|
+
formData,
|
|
2361
|
+
this.experimental_customMergeAllOf
|
|
2362
|
+
);
|
|
1736
2363
|
}
|
|
1737
2364
|
};
|
|
1738
|
-
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
1739
|
-
return new SchemaUtils(
|
|
2365
|
+
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
2366
|
+
return new SchemaUtils(
|
|
2367
|
+
validator,
|
|
2368
|
+
rootSchema,
|
|
2369
|
+
experimental_defaultFormStateBehavior,
|
|
2370
|
+
experimental_customMergeAllOf
|
|
2371
|
+
);
|
|
1740
2372
|
}
|
|
1741
2373
|
|
|
1742
2374
|
// src/dataURItoBlob.ts
|
|
@@ -1818,9 +2450,6 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
1818
2450
|
return replaceStringParameters(stringToTranslate, params);
|
|
1819
2451
|
}
|
|
1820
2452
|
|
|
1821
|
-
// src/enumOptionsDeselectValue.ts
|
|
1822
|
-
import isEqual4 from "lodash/isEqual";
|
|
1823
|
-
|
|
1824
2453
|
// src/enumOptionsValueForIndex.ts
|
|
1825
2454
|
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
1826
2455
|
if (Array.isArray(valueIndex)) {
|
|
@@ -1835,18 +2464,17 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
1835
2464
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1836
2465
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1837
2466
|
if (Array.isArray(selected)) {
|
|
1838
|
-
return selected.filter((v) => !
|
|
2467
|
+
return selected.filter((v) => !deepEquals(v, value));
|
|
1839
2468
|
}
|
|
1840
|
-
return
|
|
2469
|
+
return deepEquals(value, selected) ? void 0 : selected;
|
|
1841
2470
|
}
|
|
1842
2471
|
|
|
1843
2472
|
// src/enumOptionsIsSelected.ts
|
|
1844
|
-
import isEqual5 from "lodash/isEqual";
|
|
1845
2473
|
function enumOptionsIsSelected(value, selected) {
|
|
1846
2474
|
if (Array.isArray(selected)) {
|
|
1847
|
-
return selected.some((sel) =>
|
|
2475
|
+
return selected.some((sel) => deepEquals(sel, value));
|
|
1848
2476
|
}
|
|
1849
|
-
return
|
|
2477
|
+
return deepEquals(selected, value);
|
|
1850
2478
|
}
|
|
1851
2479
|
|
|
1852
2480
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1859,10 +2487,10 @@ function enumOptionsIndexForValue(value, allEnumOptions = [], multiple = false)
|
|
|
1859
2487
|
}
|
|
1860
2488
|
|
|
1861
2489
|
// src/enumOptionsSelectValue.ts
|
|
1862
|
-
import
|
|
2490
|
+
import isNil2 from "lodash/isNil";
|
|
1863
2491
|
function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1864
2492
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1865
|
-
if (!
|
|
2493
|
+
if (!isNil2(value)) {
|
|
1866
2494
|
const index = allEnumOptions.findIndex((opt) => value === opt.value);
|
|
1867
2495
|
const all = allEnumOptions.map(({ value: val }) => val);
|
|
1868
2496
|
const updated = selected.slice(0, index).concat(value, selected.slice(index));
|
|
@@ -1873,8 +2501,9 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
1873
2501
|
|
|
1874
2502
|
// src/ErrorSchemaBuilder.ts
|
|
1875
2503
|
import cloneDeep from "lodash/cloneDeep";
|
|
1876
|
-
import
|
|
2504
|
+
import get15 from "lodash/get";
|
|
1877
2505
|
import set3 from "lodash/set";
|
|
2506
|
+
import setWith from "lodash/setWith";
|
|
1878
2507
|
var ErrorSchemaBuilder = class {
|
|
1879
2508
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
1880
2509
|
*
|
|
@@ -1901,10 +2530,10 @@ var ErrorSchemaBuilder = class {
|
|
|
1901
2530
|
*/
|
|
1902
2531
|
getOrCreateErrorBlock(pathOfError) {
|
|
1903
2532
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
1904
|
-
let errorBlock = hasPath ?
|
|
2533
|
+
let errorBlock = hasPath ? get15(this.errorSchema, pathOfError) : this.errorSchema;
|
|
1905
2534
|
if (!errorBlock && pathOfError) {
|
|
1906
2535
|
errorBlock = {};
|
|
1907
|
-
|
|
2536
|
+
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
1908
2537
|
}
|
|
1909
2538
|
return errorBlock;
|
|
1910
2539
|
}
|
|
@@ -1927,15 +2556,15 @@ var ErrorSchemaBuilder = class {
|
|
|
1927
2556
|
*/
|
|
1928
2557
|
addErrors(errorOrList, pathOfError) {
|
|
1929
2558
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1930
|
-
let errorsList =
|
|
2559
|
+
let errorsList = get15(errorBlock, ERRORS_KEY);
|
|
1931
2560
|
if (!Array.isArray(errorsList)) {
|
|
1932
2561
|
errorsList = [];
|
|
1933
2562
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
1934
2563
|
}
|
|
1935
2564
|
if (Array.isArray(errorOrList)) {
|
|
1936
|
-
|
|
2565
|
+
set3(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, ...errorOrList])]);
|
|
1937
2566
|
} else {
|
|
1938
|
-
errorsList
|
|
2567
|
+
set3(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, errorOrList])]);
|
|
1939
2568
|
}
|
|
1940
2569
|
return this;
|
|
1941
2570
|
}
|
|
@@ -1949,7 +2578,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1949
2578
|
*/
|
|
1950
2579
|
setErrors(errorOrList, pathOfError) {
|
|
1951
2580
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1952
|
-
const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
|
|
2581
|
+
const listToAdd = Array.isArray(errorOrList) ? [.../* @__PURE__ */ new Set([...errorOrList])] : [errorOrList];
|
|
1953
2582
|
set3(errorBlock, ERRORS_KEY, listToAdd);
|
|
1954
2583
|
return this;
|
|
1955
2584
|
}
|
|
@@ -2034,6 +2663,9 @@ function getInputProps(schema, defaultType, options = {}, autoDefaultStepAny = t
|
|
|
2034
2663
|
if (options.autocomplete) {
|
|
2035
2664
|
inputProps.autoComplete = options.autocomplete;
|
|
2036
2665
|
}
|
|
2666
|
+
if (options.accept) {
|
|
2667
|
+
inputProps.accept = options.accept;
|
|
2668
|
+
}
|
|
2037
2669
|
return inputProps;
|
|
2038
2670
|
}
|
|
2039
2671
|
|
|
@@ -2060,6 +2692,10 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2060
2692
|
if (name === "ButtonTemplates") {
|
|
2061
2693
|
return templates[name];
|
|
2062
2694
|
}
|
|
2695
|
+
if (Object.hasOwn(uiOptions, name) && typeof uiOptions[name] === "string" && Object.hasOwn(templates, uiOptions[name])) {
|
|
2696
|
+
const key = uiOptions[name];
|
|
2697
|
+
return templates[key];
|
|
2698
|
+
}
|
|
2063
2699
|
return (
|
|
2064
2700
|
// Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
|
|
2065
2701
|
// To avoid that, we cast uiOptions to `any` before accessing the name field
|
|
@@ -2067,10 +2703,31 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2067
2703
|
);
|
|
2068
2704
|
}
|
|
2069
2705
|
|
|
2706
|
+
// src/getTestIds.ts
|
|
2707
|
+
import { nanoid } from "nanoid";
|
|
2708
|
+
import get16 from "lodash/get";
|
|
2709
|
+
function getTestIds() {
|
|
2710
|
+
if (typeof process === "undefined" || get16(process, "env.NODE_ENV") !== "test") {
|
|
2711
|
+
return {};
|
|
2712
|
+
}
|
|
2713
|
+
const ids = /* @__PURE__ */ new Map();
|
|
2714
|
+
return new Proxy(
|
|
2715
|
+
{},
|
|
2716
|
+
{
|
|
2717
|
+
get(_obj, prop) {
|
|
2718
|
+
if (!ids.has(prop)) {
|
|
2719
|
+
ids.set(prop, nanoid());
|
|
2720
|
+
}
|
|
2721
|
+
return ids.get(prop);
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
);
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2070
2727
|
// src/getWidget.tsx
|
|
2071
2728
|
import { createElement } from "react";
|
|
2072
2729
|
import ReactIs from "react-is";
|
|
2073
|
-
import
|
|
2730
|
+
import get17 from "lodash/get";
|
|
2074
2731
|
import set4 from "lodash/set";
|
|
2075
2732
|
import { jsx } from "react/jsx-runtime";
|
|
2076
2733
|
var widgetMap = {
|
|
@@ -2126,7 +2783,7 @@ var widgetMap = {
|
|
|
2126
2783
|
}
|
|
2127
2784
|
};
|
|
2128
2785
|
function mergeWidgetOptions(AWidget) {
|
|
2129
|
-
let MergedWidget =
|
|
2786
|
+
let MergedWidget = get17(AWidget, "MergedWidget");
|
|
2130
2787
|
if (!MergedWidget) {
|
|
2131
2788
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2132
2789
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2170,10 +2827,16 @@ function hashString(string) {
|
|
|
2170
2827
|
}
|
|
2171
2828
|
return hash.toString(16);
|
|
2172
2829
|
}
|
|
2173
|
-
function
|
|
2830
|
+
function sortedJSONStringify(object) {
|
|
2174
2831
|
const allKeys = /* @__PURE__ */ new Set();
|
|
2175
|
-
JSON.stringify(
|
|
2176
|
-
return
|
|
2832
|
+
JSON.stringify(object, (key, value) => (allKeys.add(key), value));
|
|
2833
|
+
return JSON.stringify(object, Array.from(allKeys).sort());
|
|
2834
|
+
}
|
|
2835
|
+
function hashObject(object) {
|
|
2836
|
+
return hashString(sortedJSONStringify(object));
|
|
2837
|
+
}
|
|
2838
|
+
function hashForSchema(schema) {
|
|
2839
|
+
return hashObject(schema);
|
|
2177
2840
|
}
|
|
2178
2841
|
|
|
2179
2842
|
// src/hasWidget.ts
|
|
@@ -2191,9 +2854,9 @@ function hasWidget(schema, widget, registeredWidgets = {}) {
|
|
|
2191
2854
|
}
|
|
2192
2855
|
|
|
2193
2856
|
// src/idGenerators.ts
|
|
2194
|
-
import
|
|
2857
|
+
import isString4 from "lodash/isString";
|
|
2195
2858
|
function idGenerator(id, suffix) {
|
|
2196
|
-
const theId =
|
|
2859
|
+
const theId = isString4(id) ? id : id[ID_KEY];
|
|
2197
2860
|
return `${theId}__${suffix}`;
|
|
2198
2861
|
}
|
|
2199
2862
|
function descriptionId(id) {
|
|
@@ -2218,6 +2881,9 @@ function ariaDescribedByIds(id, includeExamples = false) {
|
|
|
2218
2881
|
function optionId(id, optionIndex) {
|
|
2219
2882
|
return `${id}-${optionIndex}`;
|
|
2220
2883
|
}
|
|
2884
|
+
function buttonId(id, btn) {
|
|
2885
|
+
return idGenerator(id, btn);
|
|
2886
|
+
}
|
|
2221
2887
|
|
|
2222
2888
|
// src/labelValue.ts
|
|
2223
2889
|
function labelValue(label, hideLabel, fallback) {
|
|
@@ -2229,59 +2895,15 @@ function localToUTC(dateString) {
|
|
|
2229
2895
|
return dateString ? new Date(dateString).toJSON() : void 0;
|
|
2230
2896
|
}
|
|
2231
2897
|
|
|
2232
|
-
// src/
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
if (
|
|
2238
|
-
|
|
2239
|
-
}
|
|
2240
|
-
throw new Error("schema cannot be inferred as a constant");
|
|
2241
|
-
}
|
|
2242
|
-
|
|
2243
|
-
// src/optionsList.ts
|
|
2244
|
-
function optionsList(schema, uiSchema) {
|
|
2245
|
-
const schemaWithEnumNames = schema;
|
|
2246
|
-
if (schema.enum) {
|
|
2247
|
-
let enumNames;
|
|
2248
|
-
if (uiSchema) {
|
|
2249
|
-
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
2250
|
-
enumNames = uiEnumNames;
|
|
2251
|
-
}
|
|
2252
|
-
if (!enumNames && schemaWithEnumNames.enumNames) {
|
|
2253
|
-
if (true) {
|
|
2254
|
-
console.warn(
|
|
2255
|
-
'The "enumNames" property in the schema is deprecated and will be removed in a future major release. Use the "ui:enumNames" property in the uiSchema instead.'
|
|
2256
|
-
);
|
|
2257
|
-
}
|
|
2258
|
-
enumNames = schemaWithEnumNames.enumNames;
|
|
2259
|
-
}
|
|
2260
|
-
return schema.enum.map((value, i) => {
|
|
2261
|
-
const label = enumNames?.[i] || String(value);
|
|
2262
|
-
return { label, value };
|
|
2263
|
-
});
|
|
2264
|
-
}
|
|
2265
|
-
let altSchemas = void 0;
|
|
2266
|
-
let altUiSchemas = void 0;
|
|
2267
|
-
if (schema.anyOf) {
|
|
2268
|
-
altSchemas = schema.anyOf;
|
|
2269
|
-
altUiSchemas = uiSchema?.anyOf;
|
|
2270
|
-
} else if (schema.oneOf) {
|
|
2271
|
-
altSchemas = schema.oneOf;
|
|
2272
|
-
altUiSchemas = uiSchema?.oneOf;
|
|
2898
|
+
// src/lookupFromFormContext.ts
|
|
2899
|
+
import get18 from "lodash/get";
|
|
2900
|
+
import has6 from "lodash/has";
|
|
2901
|
+
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
2902
|
+
const lookupPath = [LOOKUP_MAP_NAME];
|
|
2903
|
+
if (has6(regOrFc, FORM_CONTEXT_NAME)) {
|
|
2904
|
+
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2273
2905
|
}
|
|
2274
|
-
return
|
|
2275
|
-
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
2276
|
-
const aSchema = aSchemaDef;
|
|
2277
|
-
const value = toConstant(aSchema);
|
|
2278
|
-
const label = title || aSchema.title || String(value);
|
|
2279
|
-
return {
|
|
2280
|
-
schema: aSchema,
|
|
2281
|
-
label,
|
|
2282
|
-
value
|
|
2283
|
-
};
|
|
2284
|
-
});
|
|
2906
|
+
return get18(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2285
2907
|
}
|
|
2286
2908
|
|
|
2287
2909
|
// src/orderProperties.ts
|
|
@@ -2460,7 +3082,7 @@ function utcToLocal(jsonDate) {
|
|
|
2460
3082
|
}
|
|
2461
3083
|
|
|
2462
3084
|
// src/validationDataMerge.ts
|
|
2463
|
-
import
|
|
3085
|
+
import isEmpty4 from "lodash/isEmpty";
|
|
2464
3086
|
function validationDataMerge(validationData, additionalErrorSchema) {
|
|
2465
3087
|
if (!additionalErrorSchema) {
|
|
2466
3088
|
return validationData;
|
|
@@ -2468,7 +3090,7 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
2468
3090
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
2469
3091
|
let errors = toErrorList(additionalErrorSchema);
|
|
2470
3092
|
let errorSchema = additionalErrorSchema;
|
|
2471
|
-
if (!
|
|
3093
|
+
if (!isEmpty4(oldErrorSchema)) {
|
|
2472
3094
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
2473
3095
|
errors = [...oldErrors].concat(errors);
|
|
2474
3096
|
}
|
|
@@ -2505,10 +3127,34 @@ function withIdRefPrefix(schemaNode) {
|
|
|
2505
3127
|
return schemaNode;
|
|
2506
3128
|
}
|
|
2507
3129
|
|
|
3130
|
+
// src/getChangedFields.ts
|
|
3131
|
+
import keys from "lodash/keys";
|
|
3132
|
+
import pickBy from "lodash/pickBy";
|
|
3133
|
+
import isPlainObject4 from "lodash/isPlainObject";
|
|
3134
|
+
import get19 from "lodash/get";
|
|
3135
|
+
import difference from "lodash/difference";
|
|
3136
|
+
function getChangedFields(a, b) {
|
|
3137
|
+
const aIsPlainObject = isPlainObject4(a);
|
|
3138
|
+
const bIsPlainObject = isPlainObject4(b);
|
|
3139
|
+
if (a === b || !aIsPlainObject && !bIsPlainObject) {
|
|
3140
|
+
return [];
|
|
3141
|
+
}
|
|
3142
|
+
if (aIsPlainObject && !bIsPlainObject) {
|
|
3143
|
+
return keys(a);
|
|
3144
|
+
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3145
|
+
return keys(b);
|
|
3146
|
+
} else {
|
|
3147
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get19(b, key))));
|
|
3148
|
+
const diffFields = difference(keys(b), keys(a));
|
|
3149
|
+
return [...unequalFields, ...diffFields];
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
|
|
2508
3153
|
// src/enums.ts
|
|
2509
3154
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
2510
3155
|
TranslatableString2["ArrayItemTitle"] = "Item";
|
|
2511
3156
|
TranslatableString2["MissingItems"] = "Missing items definition";
|
|
3157
|
+
TranslatableString2["EmptyArray"] = "No items yet. Use the button below to add some.";
|
|
2512
3158
|
TranslatableString2["YesLabel"] = "Yes";
|
|
2513
3159
|
TranslatableString2["NoLabel"] = "No";
|
|
2514
3160
|
TranslatableString2["CloseLabel"] = "Close";
|
|
@@ -2541,11 +3187,9 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2541
3187
|
|
|
2542
3188
|
// src/parser/schemaParser.ts
|
|
2543
3189
|
import forEach from "lodash/forEach";
|
|
2544
|
-
import isEqual7 from "lodash/isEqual";
|
|
2545
3190
|
|
|
2546
3191
|
// src/parser/ParserValidator.ts
|
|
2547
|
-
import
|
|
2548
|
-
import isEqual6 from "lodash/isEqual";
|
|
3192
|
+
import get20 from "lodash/get";
|
|
2549
3193
|
var ParserValidator = class {
|
|
2550
3194
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2551
3195
|
* first.
|
|
@@ -2571,12 +3215,12 @@ var ParserValidator = class {
|
|
|
2571
3215
|
* @param hash - The hash value at which to map the schema
|
|
2572
3216
|
*/
|
|
2573
3217
|
addSchema(schema, hash) {
|
|
2574
|
-
const key =
|
|
3218
|
+
const key = get20(schema, ID_KEY, hash);
|
|
2575
3219
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2576
3220
|
const existing = this.schemaMap[key];
|
|
2577
3221
|
if (!existing) {
|
|
2578
3222
|
this.schemaMap[key] = identifiedSchema;
|
|
2579
|
-
} else if (!
|
|
3223
|
+
} else if (!deepEquals(existing, identifiedSchema)) {
|
|
2580
3224
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2581
3225
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2582
3226
|
throw new Error(
|
|
@@ -2598,7 +3242,7 @@ var ParserValidator = class {
|
|
|
2598
3242
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2599
3243
|
*/
|
|
2600
3244
|
isValid(schema, _formData, rootSchema) {
|
|
2601
|
-
if (!
|
|
3245
|
+
if (!deepEquals(rootSchema, this.rootSchema)) {
|
|
2602
3246
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2603
3247
|
}
|
|
2604
3248
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2638,7 +3282,7 @@ var ParserValidator = class {
|
|
|
2638
3282
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2639
3283
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
2640
3284
|
schemas.forEach((schema2) => {
|
|
2641
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
3285
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, schema2));
|
|
2642
3286
|
if (sameSchemaIndex === -1) {
|
|
2643
3287
|
recurseList.push(schema2);
|
|
2644
3288
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
@@ -2670,20 +3314,24 @@ export {
|
|
|
2670
3314
|
DEFAULT_KEY,
|
|
2671
3315
|
DEFINITIONS_KEY,
|
|
2672
3316
|
DEPENDENCIES_KEY,
|
|
3317
|
+
DISCRIMINATOR_PATH,
|
|
2673
3318
|
ENUM_KEY,
|
|
2674
3319
|
ERRORS_KEY,
|
|
2675
3320
|
ErrorSchemaBuilder,
|
|
3321
|
+
FORM_CONTEXT_NAME,
|
|
2676
3322
|
ID_KEY,
|
|
2677
3323
|
IF_KEY,
|
|
2678
3324
|
ITEMS_KEY,
|
|
2679
3325
|
JUNK_OPTION_ID,
|
|
3326
|
+
LOOKUP_MAP_NAME,
|
|
2680
3327
|
NAME_KEY,
|
|
2681
3328
|
ONE_OF_KEY,
|
|
3329
|
+
PATTERN_PROPERTIES_KEY,
|
|
2682
3330
|
PROPERTIES_KEY,
|
|
3331
|
+
READONLY_KEY,
|
|
2683
3332
|
REF_KEY,
|
|
2684
3333
|
REQUIRED_KEY,
|
|
2685
3334
|
RJSF_ADDITIONAL_PROPERTIES_FLAG,
|
|
2686
|
-
RJSF_ADDITONAL_PROPERTIES_FLAG,
|
|
2687
3335
|
ROOT_SCHEMA_PREFIX,
|
|
2688
3336
|
SUBMIT_BTN_OPTIONS_KEY,
|
|
2689
3337
|
TranslatableString,
|
|
@@ -2694,6 +3342,7 @@ export {
|
|
|
2694
3342
|
allowAdditionalItems,
|
|
2695
3343
|
ariaDescribedByIds,
|
|
2696
3344
|
asNumber,
|
|
3345
|
+
buttonId,
|
|
2697
3346
|
canExpand,
|
|
2698
3347
|
createErrorHandler,
|
|
2699
3348
|
createSchemaUtils,
|
|
@@ -2709,24 +3358,30 @@ export {
|
|
|
2709
3358
|
enumOptionsValueForIndex,
|
|
2710
3359
|
errorId,
|
|
2711
3360
|
examplesId,
|
|
3361
|
+
findFieldInSchema,
|
|
2712
3362
|
findSchemaDefinition,
|
|
3363
|
+
findSelectedOptionInXxxOf,
|
|
3364
|
+
getChangedFields,
|
|
2713
3365
|
getClosestMatchingOption,
|
|
2714
3366
|
getDateElementProps,
|
|
2715
3367
|
getDefaultFormState,
|
|
2716
3368
|
getDiscriminatorFieldFromSchema,
|
|
2717
3369
|
getDisplayLabel,
|
|
2718
3370
|
getFirstMatchingOption,
|
|
3371
|
+
getFromSchema,
|
|
2719
3372
|
getInputProps,
|
|
2720
|
-
getMatchingOption,
|
|
2721
3373
|
getOptionMatchingSimpleDiscriminator,
|
|
2722
3374
|
getSchemaType,
|
|
2723
3375
|
getSubmitButtonOptions,
|
|
2724
3376
|
getTemplate,
|
|
3377
|
+
getTestIds,
|
|
2725
3378
|
getUiOptions,
|
|
2726
3379
|
getWidget,
|
|
2727
3380
|
guessType,
|
|
2728
3381
|
hasWidget,
|
|
2729
3382
|
hashForSchema,
|
|
3383
|
+
hashObject,
|
|
3384
|
+
hashString,
|
|
2730
3385
|
helpId,
|
|
2731
3386
|
isConstant,
|
|
2732
3387
|
isCustomWidget,
|
|
@@ -2737,10 +3392,10 @@ export {
|
|
|
2737
3392
|
isSelect,
|
|
2738
3393
|
labelValue,
|
|
2739
3394
|
localToUTC,
|
|
3395
|
+
lookupFromFormContext,
|
|
2740
3396
|
mergeDefaultsWithFormData,
|
|
2741
3397
|
mergeObjects,
|
|
2742
3398
|
mergeSchemas,
|
|
2743
|
-
mergeValidationData,
|
|
2744
3399
|
optionId,
|
|
2745
3400
|
optionsList,
|
|
2746
3401
|
orderProperties,
|
|
@@ -2753,6 +3408,7 @@ export {
|
|
|
2753
3408
|
schemaParser,
|
|
2754
3409
|
schemaRequiresTrueValue,
|
|
2755
3410
|
shouldRender,
|
|
3411
|
+
sortedJSONStringify,
|
|
2756
3412
|
titleId,
|
|
2757
3413
|
toConstant,
|
|
2758
3414
|
toDateString,
|