@rjsf/utils 6.0.0-alpha.0 → 6.0.0-beta.10
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 +1347 -642
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +1324 -619
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +1266 -590
- 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 +2 -2
- 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 +15 -3
- package/lib/constants.js +15 -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 +5 -3
- package/lib/findSchemaDefinition.js +54 -11
- 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 +316 -167
- 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 +30 -12
- package/lib/schema/retrieveSchema.js +153 -70
- 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 +172 -142
- 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 +37 -26
- package/src/ErrorSchemaBuilder.ts +15 -8
- package/src/canExpand.ts +2 -2
- package/src/constIsAjvDataReference.ts +17 -0
- package/src/constants.ts +17 -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 +55 -10
- 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 +461 -193
- 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 +268 -78
- 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 +278 -184
- 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,17 +59,23 @@ 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 SCHEMA_KEY = "$schema";
|
|
69
|
+
var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
|
|
70
|
+
var FORM_CONTEXT_NAME = "formContext";
|
|
71
|
+
var LOOKUP_MAP_NAME = "layoutGridLookupMap";
|
|
64
72
|
var RJSF_ADDITIONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
|
|
65
73
|
var ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
|
|
66
74
|
var UI_FIELD_KEY = "ui:field";
|
|
67
75
|
var UI_WIDGET_KEY = "ui:widget";
|
|
68
76
|
var UI_OPTIONS_KEY = "ui:options";
|
|
69
77
|
var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
|
|
78
|
+
var JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
70
79
|
|
|
71
80
|
// src/getUiOptions.ts
|
|
72
81
|
function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
@@ -88,7 +97,7 @@ function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
|
88
97
|
|
|
89
98
|
// src/canExpand.ts
|
|
90
99
|
function canExpand(schema, uiSchema = {}, formData) {
|
|
91
|
-
if (!schema.additionalProperties) {
|
|
100
|
+
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
92
101
|
return false;
|
|
93
102
|
}
|
|
94
103
|
const { expandable = true } = getUiOptions(uiSchema);
|
|
@@ -138,27 +147,74 @@ function deepEquals(a, b) {
|
|
|
138
147
|
});
|
|
139
148
|
}
|
|
140
149
|
|
|
141
|
-
// src/schema/
|
|
142
|
-
import
|
|
143
|
-
import
|
|
150
|
+
// src/schema/findFieldInSchema.ts
|
|
151
|
+
import get8 from "lodash/get";
|
|
152
|
+
import has3 from "lodash/has";
|
|
153
|
+
|
|
154
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
155
|
+
import get6 from "lodash/get";
|
|
156
|
+
import isEqual from "lodash/isEqual";
|
|
157
|
+
|
|
158
|
+
// src/schema/retrieveSchema.ts
|
|
159
|
+
import get5 from "lodash/get";
|
|
160
|
+
import set from "lodash/set";
|
|
161
|
+
import times from "lodash/times";
|
|
162
|
+
import transform from "lodash/transform";
|
|
163
|
+
import merge from "lodash/merge";
|
|
164
|
+
import flattenDeep from "lodash/flattenDeep";
|
|
165
|
+
import uniq from "lodash/uniq";
|
|
166
|
+
import mergeAllOf from "json-schema-merge-allof";
|
|
144
167
|
|
|
145
168
|
// src/findSchemaDefinition.ts
|
|
146
169
|
import jsonpointer from "jsonpointer";
|
|
147
170
|
import omit from "lodash/omit";
|
|
171
|
+
import isObject2 from "lodash/isObject";
|
|
172
|
+
import isEmpty from "lodash/isEmpty";
|
|
173
|
+
import UriResolver from "fast-uri";
|
|
174
|
+
import get from "lodash/get";
|
|
175
|
+
function findEmbeddedSchemaRecursive(schema, ref) {
|
|
176
|
+
if (ID_KEY in schema && UriResolver.equal(schema[ID_KEY], ref)) {
|
|
177
|
+
return schema;
|
|
178
|
+
}
|
|
179
|
+
for (const subSchema of Object.values(schema)) {
|
|
180
|
+
if (isObject2(subSchema)) {
|
|
181
|
+
const result = findEmbeddedSchemaRecursive(subSchema, ref);
|
|
182
|
+
if (result !== void 0) {
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return void 0;
|
|
188
|
+
}
|
|
148
189
|
function splitKeyElementFromObject(key, object) {
|
|
149
190
|
const value = object[key];
|
|
150
191
|
const remaining = omit(object, [key]);
|
|
151
192
|
return [remaining, value];
|
|
152
193
|
}
|
|
153
|
-
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = []) {
|
|
194
|
+
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [], baseURI = get(rootSchema, [ID_KEY])) {
|
|
154
195
|
const ref = $ref || "";
|
|
155
|
-
let
|
|
196
|
+
let current = void 0;
|
|
156
197
|
if (ref.startsWith("#")) {
|
|
157
|
-
decodedRef = decodeURIComponent(ref.substring(1));
|
|
158
|
-
|
|
159
|
-
|
|
198
|
+
const decodedRef = decodeURIComponent(ref.substring(1));
|
|
199
|
+
if (baseURI === void 0 || ID_KEY in rootSchema && rootSchema[ID_KEY] === baseURI) {
|
|
200
|
+
current = jsonpointer.get(rootSchema, decodedRef);
|
|
201
|
+
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
202
|
+
current = findEmbeddedSchemaRecursive(rootSchema, baseURI.replace(/\/$/, ""));
|
|
203
|
+
if (current !== void 0) {
|
|
204
|
+
current = jsonpointer.get(current, decodedRef);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
208
|
+
const resolvedRef = baseURI ? UriResolver.resolve(baseURI, ref) : ref;
|
|
209
|
+
const [refId, ...refAnchor] = resolvedRef.replace(/#\/?$/, "").split("#");
|
|
210
|
+
current = findEmbeddedSchemaRecursive(rootSchema, refId.replace(/\/$/, ""));
|
|
211
|
+
if (current !== void 0) {
|
|
212
|
+
baseURI = current[ID_KEY];
|
|
213
|
+
if (!isEmpty(refAnchor)) {
|
|
214
|
+
current = jsonpointer.get(current, decodeURIComponent(refAnchor.join("#")));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
160
217
|
}
|
|
161
|
-
const current = jsonpointer.get(rootSchema, decodedRef);
|
|
162
218
|
if (current === void 0) {
|
|
163
219
|
throw new Error(`Could not find a definition for ${$ref}.`);
|
|
164
220
|
}
|
|
@@ -173,7 +229,7 @@ function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [])
|
|
|
173
229
|
throw new Error(`Definition for ${firstRef} contains a circular reference through ${circularPath}`);
|
|
174
230
|
}
|
|
175
231
|
const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
|
|
176
|
-
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref]);
|
|
232
|
+
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref], baseURI);
|
|
177
233
|
if (Object.keys(remaining).length > 0) {
|
|
178
234
|
return { ...remaining, ...subSchema };
|
|
179
235
|
}
|
|
@@ -181,119 +237,17 @@ function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [])
|
|
|
181
237
|
}
|
|
182
238
|
return current;
|
|
183
239
|
}
|
|
184
|
-
function findSchemaDefinition($ref, rootSchema = {}) {
|
|
240
|
+
function findSchemaDefinition($ref, rootSchema = {}, baseURI = get(rootSchema, [ID_KEY])) {
|
|
185
241
|
const recurseList = [];
|
|
186
|
-
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList);
|
|
242
|
+
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList, baseURI);
|
|
187
243
|
}
|
|
188
244
|
|
|
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
245
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
292
|
-
import
|
|
246
|
+
import get2 from "lodash/get";
|
|
293
247
|
import isString from "lodash/isString";
|
|
294
248
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
295
249
|
let discriminator;
|
|
296
|
-
const maybeString =
|
|
250
|
+
const maybeString = get2(schema, DISCRIMINATOR_PATH);
|
|
297
251
|
if (isString(maybeString)) {
|
|
298
252
|
discriminator = maybeString;
|
|
299
253
|
} else if (maybeString !== void 0) {
|
|
@@ -337,7 +291,7 @@ function getSchemaType(schema) {
|
|
|
337
291
|
if (!type && schema.enum) {
|
|
338
292
|
return "string";
|
|
339
293
|
}
|
|
340
|
-
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
294
|
+
if (!type && (schema.properties || schema.additionalProperties || schema.patternProperties)) {
|
|
341
295
|
return "object";
|
|
342
296
|
}
|
|
343
297
|
if (Array.isArray(type)) {
|
|
@@ -366,11 +320,97 @@ function mergeSchemas(obj1, obj2) {
|
|
|
366
320
|
}, acc);
|
|
367
321
|
}
|
|
368
322
|
|
|
323
|
+
// src/schema/getFirstMatchingOption.ts
|
|
324
|
+
import get4 from "lodash/get";
|
|
325
|
+
import has from "lodash/has";
|
|
326
|
+
import isNumber from "lodash/isNumber";
|
|
327
|
+
|
|
328
|
+
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
329
|
+
import get3 from "lodash/get";
|
|
330
|
+
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
331
|
+
if (formData && discriminatorField) {
|
|
332
|
+
const value = get3(formData, discriminatorField);
|
|
333
|
+
if (value === void 0) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
for (let i = 0; i < options.length; i++) {
|
|
337
|
+
const option = options[i];
|
|
338
|
+
const discriminator = get3(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
339
|
+
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (discriminator.const === value) {
|
|
343
|
+
return i;
|
|
344
|
+
}
|
|
345
|
+
if (discriminator.enum?.includes(value)) {
|
|
346
|
+
return i;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// src/schema/getFirstMatchingOption.ts
|
|
354
|
+
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
355
|
+
if (formData === void 0) {
|
|
356
|
+
return 0;
|
|
357
|
+
}
|
|
358
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
359
|
+
if (isNumber(simpleDiscriminatorMatch)) {
|
|
360
|
+
return simpleDiscriminatorMatch;
|
|
361
|
+
}
|
|
362
|
+
for (let i = 0; i < options.length; i++) {
|
|
363
|
+
const option = options[i];
|
|
364
|
+
if (discriminatorField && has(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
365
|
+
const value = get4(formData, discriminatorField);
|
|
366
|
+
const discriminator = get4(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
367
|
+
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
368
|
+
return i;
|
|
369
|
+
}
|
|
370
|
+
} else if (option[PROPERTIES_KEY]) {
|
|
371
|
+
const requiresAnyOf = {
|
|
372
|
+
anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
|
|
373
|
+
required: [key]
|
|
374
|
+
}))
|
|
375
|
+
};
|
|
376
|
+
let augmentedSchema;
|
|
377
|
+
if (option.anyOf) {
|
|
378
|
+
const { ...shallowClone } = option;
|
|
379
|
+
if (!shallowClone.allOf) {
|
|
380
|
+
shallowClone.allOf = [];
|
|
381
|
+
} else {
|
|
382
|
+
shallowClone.allOf = shallowClone.allOf.slice();
|
|
383
|
+
}
|
|
384
|
+
shallowClone.allOf.push(requiresAnyOf);
|
|
385
|
+
augmentedSchema = shallowClone;
|
|
386
|
+
} else {
|
|
387
|
+
augmentedSchema = Object.assign({}, option, requiresAnyOf);
|
|
388
|
+
}
|
|
389
|
+
delete augmentedSchema.required;
|
|
390
|
+
if (validator.isValid(augmentedSchema, formData, rootSchema)) {
|
|
391
|
+
return i;
|
|
392
|
+
}
|
|
393
|
+
} else if (validator.isValid(option, formData, rootSchema)) {
|
|
394
|
+
return i;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return 0;
|
|
398
|
+
}
|
|
399
|
+
|
|
369
400
|
// src/schema/retrieveSchema.ts
|
|
370
|
-
|
|
371
|
-
|
|
401
|
+
import isEmpty2 from "lodash/isEmpty";
|
|
402
|
+
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf) {
|
|
403
|
+
return retrieveSchemaInternal(
|
|
404
|
+
validator,
|
|
405
|
+
schema,
|
|
406
|
+
rootSchema,
|
|
407
|
+
rawFormData,
|
|
408
|
+
void 0,
|
|
409
|
+
void 0,
|
|
410
|
+
experimental_customMergeAllOf
|
|
411
|
+
)[0];
|
|
372
412
|
}
|
|
373
|
-
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
413
|
+
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
374
414
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
375
415
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
376
416
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
@@ -378,12 +418,28 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
378
418
|
if (expandAllBranches) {
|
|
379
419
|
if (then && typeof then !== "boolean") {
|
|
380
420
|
schemas = schemas.concat(
|
|
381
|
-
retrieveSchemaInternal(
|
|
421
|
+
retrieveSchemaInternal(
|
|
422
|
+
validator,
|
|
423
|
+
then,
|
|
424
|
+
rootSchema,
|
|
425
|
+
formData,
|
|
426
|
+
expandAllBranches,
|
|
427
|
+
recurseList,
|
|
428
|
+
experimental_customMergeAllOf
|
|
429
|
+
)
|
|
382
430
|
);
|
|
383
431
|
}
|
|
384
432
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
385
433
|
schemas = schemas.concat(
|
|
386
|
-
retrieveSchemaInternal(
|
|
434
|
+
retrieveSchemaInternal(
|
|
435
|
+
validator,
|
|
436
|
+
otherwise,
|
|
437
|
+
rootSchema,
|
|
438
|
+
formData,
|
|
439
|
+
expandAllBranches,
|
|
440
|
+
recurseList,
|
|
441
|
+
experimental_customMergeAllOf
|
|
442
|
+
)
|
|
387
443
|
);
|
|
388
444
|
}
|
|
389
445
|
} else {
|
|
@@ -396,7 +452,8 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
396
452
|
rootSchema,
|
|
397
453
|
formData,
|
|
398
454
|
expandAllBranches,
|
|
399
|
-
recurseList
|
|
455
|
+
recurseList,
|
|
456
|
+
experimental_customMergeAllOf
|
|
400
457
|
)
|
|
401
458
|
);
|
|
402
459
|
}
|
|
@@ -405,7 +462,15 @@ function resolveCondition(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
405
462
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
406
463
|
}
|
|
407
464
|
return resolvedSchemas.flatMap(
|
|
408
|
-
(s) => retrieveSchemaInternal(
|
|
465
|
+
(s) => retrieveSchemaInternal(
|
|
466
|
+
validator,
|
|
467
|
+
s,
|
|
468
|
+
rootSchema,
|
|
469
|
+
formData,
|
|
470
|
+
expandAllBranches,
|
|
471
|
+
recurseList,
|
|
472
|
+
experimental_customMergeAllOf
|
|
473
|
+
)
|
|
409
474
|
);
|
|
410
475
|
}
|
|
411
476
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
@@ -422,7 +487,16 @@ function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
422
487
|
);
|
|
423
488
|
return allPermutations;
|
|
424
489
|
}
|
|
425
|
-
function
|
|
490
|
+
function getMatchingPatternProperties(schema, key) {
|
|
491
|
+
return Object.keys(schema.patternProperties).filter((pattern) => RegExp(pattern).test(key)).reduce(
|
|
492
|
+
(obj, pattern) => {
|
|
493
|
+
set(obj, [pattern], schema.patternProperties[pattern]);
|
|
494
|
+
return obj;
|
|
495
|
+
},
|
|
496
|
+
{}
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
426
500
|
const updatedSchemas = resolveReference(
|
|
427
501
|
validator,
|
|
428
502
|
schema,
|
|
@@ -444,7 +518,15 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
444
518
|
formData
|
|
445
519
|
);
|
|
446
520
|
return resolvedSchemas.flatMap((s) => {
|
|
447
|
-
return retrieveSchemaInternal(
|
|
521
|
+
return retrieveSchemaInternal(
|
|
522
|
+
validator,
|
|
523
|
+
s,
|
|
524
|
+
rootSchema,
|
|
525
|
+
formData,
|
|
526
|
+
expandAllBranches,
|
|
527
|
+
recurseList,
|
|
528
|
+
experimental_customMergeAllOf
|
|
529
|
+
);
|
|
448
530
|
});
|
|
449
531
|
}
|
|
450
532
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
@@ -455,15 +537,19 @@ function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurse
|
|
|
455
537
|
rootSchema,
|
|
456
538
|
formData,
|
|
457
539
|
expandAllBranches,
|
|
458
|
-
recurseList
|
|
540
|
+
recurseList,
|
|
541
|
+
experimental_customMergeAllOf
|
|
459
542
|
)
|
|
460
543
|
);
|
|
461
544
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
462
|
-
return allPermutations.map((permutation) => ({
|
|
545
|
+
return allPermutations.map((permutation) => ({
|
|
546
|
+
...schema,
|
|
547
|
+
allOf: permutation
|
|
548
|
+
}));
|
|
463
549
|
}
|
|
464
550
|
return [schema];
|
|
465
551
|
}
|
|
466
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
552
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
467
553
|
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
468
554
|
if (updatedSchema !== schema) {
|
|
469
555
|
return retrieveSchemaInternal(
|
|
@@ -472,12 +558,13 @@ function resolveReference(validator, schema, rootSchema, expandAllBranches, recu
|
|
|
472
558
|
rootSchema,
|
|
473
559
|
formData,
|
|
474
560
|
expandAllBranches,
|
|
475
|
-
recurseList
|
|
561
|
+
recurseList,
|
|
562
|
+
experimental_customMergeAllOf
|
|
476
563
|
);
|
|
477
564
|
}
|
|
478
565
|
return [schema];
|
|
479
566
|
}
|
|
480
|
-
function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
567
|
+
function resolveAllReferences(schema, rootSchema, recurseList, baseURI) {
|
|
481
568
|
if (!isObject(schema)) {
|
|
482
569
|
return schema;
|
|
483
570
|
}
|
|
@@ -488,8 +575,11 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
488
575
|
return resolvedSchema;
|
|
489
576
|
}
|
|
490
577
|
recurseList.push($ref);
|
|
491
|
-
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
578
|
+
const refSchema = findSchemaDefinition($ref, rootSchema, baseURI);
|
|
492
579
|
resolvedSchema = { ...refSchema, ...localSchema };
|
|
580
|
+
if (ID_KEY in resolvedSchema) {
|
|
581
|
+
baseURI = resolvedSchema[ID_KEY];
|
|
582
|
+
}
|
|
493
583
|
}
|
|
494
584
|
if (PROPERTIES_KEY in resolvedSchema) {
|
|
495
585
|
const childrenLists = [];
|
|
@@ -497,7 +587,7 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
497
587
|
resolvedSchema[PROPERTIES_KEY],
|
|
498
588
|
(result, value, key) => {
|
|
499
589
|
const childList = [...recurseList];
|
|
500
|
-
result[key] = resolveAllReferences(value, rootSchema, childList);
|
|
590
|
+
result[key] = resolveAllReferences(value, rootSchema, childList, baseURI);
|
|
501
591
|
childrenLists.push(childList);
|
|
502
592
|
},
|
|
503
593
|
{}
|
|
@@ -508,12 +598,12 @@ function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
|
508
598
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
509
599
|
resolvedSchema = {
|
|
510
600
|
...resolvedSchema,
|
|
511
|
-
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
601
|
+
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList, baseURI)
|
|
512
602
|
};
|
|
513
603
|
}
|
|
514
|
-
return
|
|
604
|
+
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
515
605
|
}
|
|
516
|
-
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
606
|
+
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
517
607
|
const schema = {
|
|
518
608
|
...theSchema,
|
|
519
609
|
properties: { ...theSchema.properties }
|
|
@@ -523,34 +613,54 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
523
613
|
if (key in schema.properties) {
|
|
524
614
|
return;
|
|
525
615
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
if (
|
|
529
|
-
|
|
616
|
+
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
617
|
+
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
618
|
+
if (!isEmpty2(matchingProperties)) {
|
|
619
|
+
schema.properties[key] = retrieveSchema(
|
|
530
620
|
validator,
|
|
531
|
-
{
|
|
621
|
+
{ allOf: Object.values(matchingProperties) },
|
|
532
622
|
rootSchema,
|
|
533
|
-
formData
|
|
623
|
+
get5(formData, [key]),
|
|
624
|
+
experimental_customMergeAllOf
|
|
534
625
|
);
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
626
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema.additionalProperties !== false) {
|
|
631
|
+
let additionalProperties = {};
|
|
632
|
+
if (typeof schema.additionalProperties !== "boolean") {
|
|
633
|
+
if (REF_KEY in schema.additionalProperties) {
|
|
634
|
+
additionalProperties = retrieveSchema(
|
|
635
|
+
validator,
|
|
636
|
+
{ $ref: get5(schema.additionalProperties, [REF_KEY]) },
|
|
637
|
+
rootSchema,
|
|
638
|
+
formData,
|
|
639
|
+
experimental_customMergeAllOf
|
|
640
|
+
);
|
|
641
|
+
} else if ("type" in schema.additionalProperties) {
|
|
642
|
+
additionalProperties = { ...schema.additionalProperties };
|
|
643
|
+
} else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
|
|
644
|
+
additionalProperties = {
|
|
645
|
+
type: "object",
|
|
646
|
+
...schema.additionalProperties
|
|
647
|
+
};
|
|
648
|
+
} else {
|
|
649
|
+
additionalProperties = { type: guessType(get5(formData, [key])) };
|
|
650
|
+
}
|
|
542
651
|
} else {
|
|
543
|
-
additionalProperties = { type: guessType(
|
|
652
|
+
additionalProperties = { type: guessType(get5(formData, [key])) };
|
|
544
653
|
}
|
|
654
|
+
schema.properties[key] = additionalProperties;
|
|
655
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
545
656
|
} else {
|
|
546
|
-
|
|
657
|
+
schema.properties[key] = { type: "null" };
|
|
658
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
547
659
|
}
|
|
548
|
-
schema.properties[key] = additionalProperties;
|
|
549
|
-
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
550
660
|
});
|
|
551
661
|
return schema;
|
|
552
662
|
}
|
|
553
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
663
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf) {
|
|
554
664
|
if (!isObject(schema)) {
|
|
555
665
|
return [{}];
|
|
556
666
|
}
|
|
@@ -560,7 +670,8 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
560
670
|
rootSchema,
|
|
561
671
|
expandAllBranches,
|
|
562
672
|
recurseList,
|
|
563
|
-
rawFormData
|
|
673
|
+
rawFormData,
|
|
674
|
+
experimental_customMergeAllOf
|
|
564
675
|
);
|
|
565
676
|
return resolvedSchemas.flatMap((s) => {
|
|
566
677
|
let resolvedSchema = s;
|
|
@@ -571,7 +682,8 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
571
682
|
rootSchema,
|
|
572
683
|
expandAllBranches,
|
|
573
684
|
recurseList,
|
|
574
|
-
rawFormData
|
|
685
|
+
rawFormData,
|
|
686
|
+
experimental_customMergeAllOf
|
|
575
687
|
);
|
|
576
688
|
}
|
|
577
689
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
@@ -580,18 +692,63 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
580
692
|
return [...allOf, restOfSchema];
|
|
581
693
|
}
|
|
582
694
|
try {
|
|
583
|
-
|
|
584
|
-
|
|
695
|
+
const withContainsSchemas = [];
|
|
696
|
+
const withoutContainsSchemas = [];
|
|
697
|
+
resolvedSchema.allOf?.forEach((s2) => {
|
|
698
|
+
if (typeof s2 === "object" && s2.contains) {
|
|
699
|
+
withContainsSchemas.push(s2);
|
|
700
|
+
} else {
|
|
701
|
+
withoutContainsSchemas.push(s2);
|
|
702
|
+
}
|
|
585
703
|
});
|
|
704
|
+
if (withContainsSchemas.length) {
|
|
705
|
+
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
706
|
+
}
|
|
707
|
+
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : mergeAllOf(resolvedSchema, {
|
|
708
|
+
deep: false,
|
|
709
|
+
resolvers: {
|
|
710
|
+
$defs: mergeAllOf.options.resolvers.definitions
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
if (withContainsSchemas.length) {
|
|
714
|
+
resolvedSchema.allOf = withContainsSchemas;
|
|
715
|
+
}
|
|
586
716
|
} catch (e) {
|
|
587
717
|
console.warn("could not merge subschemas in allOf:\n", e);
|
|
588
718
|
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
|
|
589
719
|
return resolvedSchemaWithoutAllOf;
|
|
590
720
|
}
|
|
591
721
|
}
|
|
592
|
-
|
|
722
|
+
if (PROPERTIES_KEY in resolvedSchema && PATTERN_PROPERTIES_KEY in resolvedSchema) {
|
|
723
|
+
resolvedSchema = Object.keys(resolvedSchema.properties).reduce(
|
|
724
|
+
(schema2, key) => {
|
|
725
|
+
const matchingProperties = getMatchingPatternProperties(schema2, key);
|
|
726
|
+
if (!isEmpty2(matchingProperties)) {
|
|
727
|
+
schema2.properties[key] = retrieveSchema(
|
|
728
|
+
validator,
|
|
729
|
+
{ allOf: [schema2.properties[key], ...Object.values(matchingProperties)] },
|
|
730
|
+
rootSchema,
|
|
731
|
+
get5(rawFormData, [key]),
|
|
732
|
+
experimental_customMergeAllOf
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
return schema2;
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
...resolvedSchema,
|
|
739
|
+
properties: { ...resolvedSchema.properties }
|
|
740
|
+
}
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
const hasAdditionalProperties = PATTERN_PROPERTIES_KEY in resolvedSchema || ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
|
|
593
744
|
if (hasAdditionalProperties) {
|
|
594
|
-
return stubExistingAdditionalProperties(
|
|
745
|
+
return stubExistingAdditionalProperties(
|
|
746
|
+
validator,
|
|
747
|
+
resolvedSchema,
|
|
748
|
+
rootSchema,
|
|
749
|
+
rawFormData,
|
|
750
|
+
experimental_customMergeAllOf
|
|
751
|
+
);
|
|
595
752
|
}
|
|
596
753
|
return resolvedSchema;
|
|
597
754
|
});
|
|
@@ -618,7 +775,7 @@ function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranch
|
|
|
618
775
|
}
|
|
619
776
|
return [schema];
|
|
620
777
|
}
|
|
621
|
-
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
778
|
+
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
622
779
|
const { dependencies, ...remainingSchema } = schema;
|
|
623
780
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
624
781
|
validator,
|
|
@@ -635,14 +792,15 @@ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, r
|
|
|
635
792
|
rootSchema,
|
|
636
793
|
expandAllBranches,
|
|
637
794
|
recurseList,
|
|
638
|
-
formData
|
|
795
|
+
formData,
|
|
796
|
+
experimental_customMergeAllOf
|
|
639
797
|
)
|
|
640
798
|
);
|
|
641
799
|
}
|
|
642
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
800
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
643
801
|
let schemas = [resolvedSchema];
|
|
644
802
|
for (const dependencyKey in dependencies) {
|
|
645
|
-
if (!expandAllBranches &&
|
|
803
|
+
if (!expandAllBranches && get5(formData, [dependencyKey]) === void 0) {
|
|
646
804
|
continue;
|
|
647
805
|
}
|
|
648
806
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
@@ -663,7 +821,8 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
663
821
|
dependencyValue,
|
|
664
822
|
expandAllBranches,
|
|
665
823
|
recurseList,
|
|
666
|
-
formData
|
|
824
|
+
formData,
|
|
825
|
+
experimental_customMergeAllOf
|
|
667
826
|
);
|
|
668
827
|
}
|
|
669
828
|
return schemas.flatMap(
|
|
@@ -674,7 +833,8 @@ function processDependencies(validator, dependencies, resolvedSchema, rootSchema
|
|
|
674
833
|
rootSchema,
|
|
675
834
|
expandAllBranches,
|
|
676
835
|
recurseList,
|
|
677
|
-
formData
|
|
836
|
+
formData,
|
|
837
|
+
experimental_customMergeAllOf
|
|
678
838
|
)
|
|
679
839
|
);
|
|
680
840
|
}
|
|
@@ -687,14 +847,15 @@ function withDependentProperties(schema, additionallyRequired) {
|
|
|
687
847
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
688
848
|
return { ...schema, required };
|
|
689
849
|
}
|
|
690
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
850
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
691
851
|
const dependentSchemas = retrieveSchemaInternal(
|
|
692
852
|
validator,
|
|
693
853
|
dependencyValue,
|
|
694
854
|
rootSchema,
|
|
695
855
|
formData,
|
|
696
856
|
expandAllBranches,
|
|
697
|
-
recurseList
|
|
857
|
+
recurseList,
|
|
858
|
+
experimental_customMergeAllOf
|
|
698
859
|
);
|
|
699
860
|
return dependentSchemas.flatMap((dependent) => {
|
|
700
861
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -718,12 +879,13 @@ function withDependentSchema(validator, schema, rootSchema, dependencyKey, depen
|
|
|
718
879
|
resolvedOneOf,
|
|
719
880
|
expandAllBranches,
|
|
720
881
|
recurseList,
|
|
721
|
-
formData
|
|
882
|
+
formData,
|
|
883
|
+
experimental_customMergeAllOf
|
|
722
884
|
)
|
|
723
885
|
);
|
|
724
886
|
});
|
|
725
887
|
}
|
|
726
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
888
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
727
889
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
728
890
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
729
891
|
return false;
|
|
@@ -754,13 +916,166 @@ function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, o
|
|
|
754
916
|
rootSchema,
|
|
755
917
|
formData,
|
|
756
918
|
expandAllBranches,
|
|
757
|
-
recurseList
|
|
919
|
+
recurseList,
|
|
920
|
+
experimental_customMergeAllOf
|
|
758
921
|
);
|
|
759
922
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
760
923
|
});
|
|
761
924
|
}
|
|
762
925
|
|
|
926
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
927
|
+
function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField, xxx, formData = {}, experimental_customMergeAllOf) {
|
|
928
|
+
if (Array.isArray(schema[xxx])) {
|
|
929
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
930
|
+
const selectorField = discriminator || fallbackField;
|
|
931
|
+
const xxxOfs = schema[xxx].map(
|
|
932
|
+
(xxxOf) => retrieveSchema(validator, xxxOf, rootSchema, formData, experimental_customMergeAllOf)
|
|
933
|
+
);
|
|
934
|
+
const data = get6(formData, selectorField);
|
|
935
|
+
if (data !== void 0) {
|
|
936
|
+
return xxxOfs.find((xxx2) => {
|
|
937
|
+
return isEqual(
|
|
938
|
+
get6(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get6(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
939
|
+
data
|
|
940
|
+
);
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
return void 0;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// src/schema/getFromSchema.ts
|
|
948
|
+
import get7 from "lodash/get";
|
|
949
|
+
import has2 from "lodash/has";
|
|
950
|
+
import isEmpty3 from "lodash/isEmpty";
|
|
951
|
+
function getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf) {
|
|
952
|
+
let fieldSchema = schema;
|
|
953
|
+
if (has2(schema, REF_KEY)) {
|
|
954
|
+
fieldSchema = retrieveSchema(validator, schema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
955
|
+
}
|
|
956
|
+
if (isEmpty3(path)) {
|
|
957
|
+
return fieldSchema;
|
|
958
|
+
}
|
|
959
|
+
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
960
|
+
const [part, ...nestedPath] = pathList;
|
|
961
|
+
if (part && has2(fieldSchema, part)) {
|
|
962
|
+
fieldSchema = get7(fieldSchema, part);
|
|
963
|
+
return getFromSchemaInternal(
|
|
964
|
+
validator,
|
|
965
|
+
rootSchema,
|
|
966
|
+
fieldSchema,
|
|
967
|
+
nestedPath,
|
|
968
|
+
experimental_customMergeAllOf
|
|
969
|
+
);
|
|
970
|
+
}
|
|
971
|
+
return void 0;
|
|
972
|
+
}
|
|
973
|
+
function getFromSchema(validator, rootSchema, schema, path, defaultValue, experimental_customMergeAllOf) {
|
|
974
|
+
const result = getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf);
|
|
975
|
+
if (result === void 0) {
|
|
976
|
+
return defaultValue;
|
|
977
|
+
}
|
|
978
|
+
return result;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
// src/schema/findFieldInSchema.ts
|
|
982
|
+
var NOT_FOUND_SCHEMA = { title: "!@#$_UNKNOWN_$#@!" };
|
|
983
|
+
function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, experimental_customMergeAllOf) {
|
|
984
|
+
const pathList = Array.isArray(path) ? [...path] : path.split(".");
|
|
985
|
+
let parentField = schema;
|
|
986
|
+
const fieldName = pathList.pop();
|
|
987
|
+
if (pathList.length) {
|
|
988
|
+
pathList.forEach((subPath) => {
|
|
989
|
+
parentField = getFromSchema(
|
|
990
|
+
validator,
|
|
991
|
+
rootSchema,
|
|
992
|
+
parentField,
|
|
993
|
+
[PROPERTIES_KEY, subPath],
|
|
994
|
+
{},
|
|
995
|
+
experimental_customMergeAllOf
|
|
996
|
+
);
|
|
997
|
+
if (has3(parentField, ONE_OF_KEY)) {
|
|
998
|
+
parentField = findSelectedOptionInXxxOf(
|
|
999
|
+
validator,
|
|
1000
|
+
rootSchema,
|
|
1001
|
+
parentField,
|
|
1002
|
+
fieldName,
|
|
1003
|
+
ONE_OF_KEY,
|
|
1004
|
+
get8(formData, subPath),
|
|
1005
|
+
experimental_customMergeAllOf
|
|
1006
|
+
);
|
|
1007
|
+
} else if (has3(parentField, ANY_OF_KEY)) {
|
|
1008
|
+
parentField = findSelectedOptionInXxxOf(
|
|
1009
|
+
validator,
|
|
1010
|
+
rootSchema,
|
|
1011
|
+
parentField,
|
|
1012
|
+
fieldName,
|
|
1013
|
+
ANY_OF_KEY,
|
|
1014
|
+
get8(formData, subPath),
|
|
1015
|
+
experimental_customMergeAllOf
|
|
1016
|
+
);
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
if (has3(parentField, ONE_OF_KEY)) {
|
|
1021
|
+
parentField = findSelectedOptionInXxxOf(
|
|
1022
|
+
validator,
|
|
1023
|
+
rootSchema,
|
|
1024
|
+
parentField,
|
|
1025
|
+
fieldName,
|
|
1026
|
+
ONE_OF_KEY,
|
|
1027
|
+
formData,
|
|
1028
|
+
experimental_customMergeAllOf
|
|
1029
|
+
);
|
|
1030
|
+
} else if (has3(parentField, ANY_OF_KEY)) {
|
|
1031
|
+
parentField = findSelectedOptionInXxxOf(
|
|
1032
|
+
validator,
|
|
1033
|
+
rootSchema,
|
|
1034
|
+
parentField,
|
|
1035
|
+
fieldName,
|
|
1036
|
+
ANY_OF_KEY,
|
|
1037
|
+
formData,
|
|
1038
|
+
experimental_customMergeAllOf
|
|
1039
|
+
);
|
|
1040
|
+
}
|
|
1041
|
+
let field = getFromSchema(
|
|
1042
|
+
validator,
|
|
1043
|
+
rootSchema,
|
|
1044
|
+
parentField,
|
|
1045
|
+
[PROPERTIES_KEY, fieldName],
|
|
1046
|
+
NOT_FOUND_SCHEMA,
|
|
1047
|
+
experimental_customMergeAllOf
|
|
1048
|
+
);
|
|
1049
|
+
if (field === NOT_FOUND_SCHEMA) {
|
|
1050
|
+
field = void 0;
|
|
1051
|
+
}
|
|
1052
|
+
const requiredArray = getFromSchema(
|
|
1053
|
+
validator,
|
|
1054
|
+
rootSchema,
|
|
1055
|
+
parentField,
|
|
1056
|
+
REQUIRED_KEY,
|
|
1057
|
+
[],
|
|
1058
|
+
experimental_customMergeAllOf
|
|
1059
|
+
);
|
|
1060
|
+
let isRequired;
|
|
1061
|
+
if (field && Array.isArray(requiredArray)) {
|
|
1062
|
+
isRequired = requiredArray.includes(fieldName);
|
|
1063
|
+
}
|
|
1064
|
+
return { field, isRequired };
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// src/schema/getDefaultFormState.ts
|
|
1068
|
+
import get12 from "lodash/get";
|
|
1069
|
+
import isEmpty4 from "lodash/isEmpty";
|
|
1070
|
+
|
|
763
1071
|
// src/schema/getClosestMatchingOption.ts
|
|
1072
|
+
import get9 from "lodash/get";
|
|
1073
|
+
import has4 from "lodash/has";
|
|
1074
|
+
import isNumber2 from "lodash/isNumber";
|
|
1075
|
+
import isObject3 from "lodash/isObject";
|
|
1076
|
+
import isString2 from "lodash/isString";
|
|
1077
|
+
import reduce from "lodash/reduce";
|
|
1078
|
+
import times2 from "lodash/times";
|
|
764
1079
|
var JUNK_OPTION = {
|
|
765
1080
|
type: "object",
|
|
766
1081
|
$id: JUNK_OPTION_ID,
|
|
@@ -770,35 +1085,51 @@ var JUNK_OPTION = {
|
|
|
770
1085
|
}
|
|
771
1086
|
}
|
|
772
1087
|
};
|
|
773
|
-
function calculateIndexScore(validator, rootSchema, schema, formData
|
|
1088
|
+
function calculateIndexScore(validator, rootSchema, schema, formData, experimental_customMergeAllOf) {
|
|
774
1089
|
let totalScore = 0;
|
|
775
1090
|
if (schema) {
|
|
776
|
-
if (
|
|
1091
|
+
if (isObject3(schema.properties)) {
|
|
777
1092
|
totalScore += reduce(
|
|
778
1093
|
schema.properties,
|
|
779
1094
|
(score, value, key) => {
|
|
780
|
-
const formValue =
|
|
1095
|
+
const formValue = get9(formData, key);
|
|
781
1096
|
if (typeof value === "boolean") {
|
|
782
1097
|
return score;
|
|
783
1098
|
}
|
|
784
|
-
if (
|
|
785
|
-
const newSchema = retrieveSchema(
|
|
786
|
-
|
|
1099
|
+
if (has4(value, REF_KEY)) {
|
|
1100
|
+
const newSchema = retrieveSchema(
|
|
1101
|
+
validator,
|
|
1102
|
+
value,
|
|
1103
|
+
rootSchema,
|
|
1104
|
+
formValue,
|
|
1105
|
+
experimental_customMergeAllOf
|
|
1106
|
+
);
|
|
1107
|
+
return score + calculateIndexScore(
|
|
1108
|
+
validator,
|
|
1109
|
+
rootSchema,
|
|
1110
|
+
newSchema,
|
|
1111
|
+
formValue || {},
|
|
1112
|
+
experimental_customMergeAllOf
|
|
1113
|
+
);
|
|
787
1114
|
}
|
|
788
|
-
if ((
|
|
789
|
-
const key2 =
|
|
1115
|
+
if ((has4(value, ONE_OF_KEY) || has4(value, ANY_OF_KEY)) && formValue) {
|
|
1116
|
+
const key2 = has4(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
790
1117
|
const discriminator = getDiscriminatorFieldFromSchema(value);
|
|
791
1118
|
return score + getClosestMatchingOption(
|
|
792
1119
|
validator,
|
|
793
1120
|
rootSchema,
|
|
794
1121
|
formValue,
|
|
795
|
-
|
|
1122
|
+
get9(value, key2),
|
|
796
1123
|
-1,
|
|
797
|
-
discriminator
|
|
1124
|
+
discriminator,
|
|
1125
|
+
experimental_customMergeAllOf
|
|
798
1126
|
);
|
|
799
1127
|
}
|
|
800
1128
|
if (value.type === "object") {
|
|
801
|
-
|
|
1129
|
+
if (isObject3(formValue)) {
|
|
1130
|
+
score += 1;
|
|
1131
|
+
}
|
|
1132
|
+
return score + calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf);
|
|
802
1133
|
}
|
|
803
1134
|
if (value.type === guessType(formValue)) {
|
|
804
1135
|
let newScore = score + 1;
|
|
@@ -819,7 +1150,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData = {}) {
|
|
|
819
1150
|
}
|
|
820
1151
|
return totalScore;
|
|
821
1152
|
}
|
|
822
|
-
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
1153
|
+
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField, experimental_customMergeAllOf) {
|
|
823
1154
|
const resolvedOptions = options.map((option) => {
|
|
824
1155
|
return resolveAllReferences(option, rootSchema, []);
|
|
825
1156
|
});
|
|
@@ -846,7 +1177,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
846
1177
|
(scoreData, index) => {
|
|
847
1178
|
const { bestScore } = scoreData;
|
|
848
1179
|
const option = resolvedOptions[index];
|
|
849
|
-
const score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1180
|
+
const score = calculateIndexScore(validator, rootSchema, option, formData, experimental_customMergeAllOf);
|
|
850
1181
|
scoreCount.add(score);
|
|
851
1182
|
if (score > bestScore) {
|
|
852
1183
|
return { bestIndex: index, bestScore: score };
|
|
@@ -867,57 +1198,79 @@ function isFixedItems(schema) {
|
|
|
867
1198
|
}
|
|
868
1199
|
|
|
869
1200
|
// src/mergeDefaultsWithFormData.ts
|
|
870
|
-
import
|
|
871
|
-
|
|
1201
|
+
import get10 from "lodash/get";
|
|
1202
|
+
import isNil from "lodash/isNil";
|
|
1203
|
+
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false, overrideFormDataWithDefaults = false) {
|
|
872
1204
|
if (Array.isArray(formData)) {
|
|
873
1205
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
874
|
-
const
|
|
875
|
-
|
|
876
|
-
|
|
1206
|
+
const overrideArray = overrideFormDataWithDefaults ? defaultsArray : formData;
|
|
1207
|
+
const overrideOppositeArray = overrideFormDataWithDefaults ? formData : defaultsArray;
|
|
1208
|
+
const mapped = overrideArray.map((value, idx) => {
|
|
1209
|
+
if (overrideOppositeArray[idx] !== void 0) {
|
|
1210
|
+
return mergeDefaultsWithFormData(
|
|
1211
|
+
defaultsArray[idx],
|
|
1212
|
+
formData[idx],
|
|
1213
|
+
mergeExtraArrayDefaults,
|
|
1214
|
+
defaultSupercedesUndefined,
|
|
1215
|
+
overrideFormDataWithDefaults
|
|
1216
|
+
);
|
|
877
1217
|
}
|
|
878
1218
|
return value;
|
|
879
1219
|
});
|
|
880
|
-
if (mergeExtraArrayDefaults && mapped.length <
|
|
881
|
-
mapped.push(...
|
|
1220
|
+
if ((mergeExtraArrayDefaults || overrideFormDataWithDefaults) && mapped.length < overrideOppositeArray.length) {
|
|
1221
|
+
mapped.push(...overrideOppositeArray.slice(mapped.length));
|
|
882
1222
|
}
|
|
883
1223
|
return mapped;
|
|
884
1224
|
}
|
|
885
1225
|
if (isObject(formData)) {
|
|
886
1226
|
const acc = Object.assign({}, defaults);
|
|
887
1227
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
1228
|
+
const keyValue = get10(formData, key);
|
|
1229
|
+
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
1230
|
+
const keyExistsInFormData = key in formData;
|
|
888
1231
|
acc2[key] = mergeDefaultsWithFormData(
|
|
889
|
-
defaults ?
|
|
890
|
-
|
|
891
|
-
mergeExtraArrayDefaults
|
|
1232
|
+
defaults ? get10(defaults, key) : {},
|
|
1233
|
+
keyValue,
|
|
1234
|
+
mergeExtraArrayDefaults,
|
|
1235
|
+
defaultSupercedesUndefined,
|
|
1236
|
+
// overrideFormDataWithDefaults can be true only when the key value exists in defaults
|
|
1237
|
+
// Or if the key value doesn't exist in formData
|
|
1238
|
+
overrideFormDataWithDefaults && (keyExistsInDefaults || !keyExistsInFormData)
|
|
892
1239
|
);
|
|
893
1240
|
return acc2;
|
|
894
1241
|
}, acc);
|
|
895
1242
|
}
|
|
1243
|
+
if (defaultSupercedesUndefined && (!isNil(defaults) && isNil(formData) || typeof formData === "number" && isNaN(formData)) || overrideFormDataWithDefaults && !isNil(formData)) {
|
|
1244
|
+
return defaults;
|
|
1245
|
+
}
|
|
896
1246
|
return formData;
|
|
897
1247
|
}
|
|
898
1248
|
|
|
899
1249
|
// src/mergeObjects.ts
|
|
900
1250
|
function mergeObjects(obj1, obj2, concatArrays = false) {
|
|
901
|
-
return Object.keys(obj2).reduce(
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1251
|
+
return Object.keys(obj2).reduce(
|
|
1252
|
+
(acc, key) => {
|
|
1253
|
+
const left = obj1 ? obj1[key] : {}, right = obj2[key];
|
|
1254
|
+
if (obj1 && key in obj1 && isObject(right)) {
|
|
1255
|
+
acc[key] = mergeObjects(left, right, concatArrays);
|
|
1256
|
+
} else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
|
|
1257
|
+
let toMerge = right;
|
|
1258
|
+
if (concatArrays === "preventDuplicates") {
|
|
1259
|
+
toMerge = right.reduce((result, value) => {
|
|
1260
|
+
if (!left.includes(value)) {
|
|
1261
|
+
result.push(value);
|
|
1262
|
+
}
|
|
1263
|
+
return result;
|
|
1264
|
+
}, []);
|
|
1265
|
+
}
|
|
1266
|
+
acc[key] = left.concat(toMerge);
|
|
1267
|
+
} else {
|
|
1268
|
+
acc[key] = right;
|
|
914
1269
|
}
|
|
915
|
-
acc
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
return acc;
|
|
920
|
-
}, Object.assign({}, obj1));
|
|
1270
|
+
return acc;
|
|
1271
|
+
},
|
|
1272
|
+
Object.assign({}, obj1)
|
|
1273
|
+
);
|
|
921
1274
|
}
|
|
922
1275
|
|
|
923
1276
|
// src/isConstant.ts
|
|
@@ -926,8 +1279,8 @@ function isConstant(schema) {
|
|
|
926
1279
|
}
|
|
927
1280
|
|
|
928
1281
|
// src/schema/isSelect.ts
|
|
929
|
-
function isSelect(validator, theSchema, rootSchema = {}) {
|
|
930
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0);
|
|
1282
|
+
function isSelect(validator, theSchema, rootSchema = {}, experimental_customMergeAllOf) {
|
|
1283
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
931
1284
|
const altSchemas = schema.oneOf || schema.anyOf;
|
|
932
1285
|
if (Array.isArray(schema.enum)) {
|
|
933
1286
|
return true;
|
|
@@ -939,14 +1292,85 @@ function isSelect(validator, theSchema, rootSchema = {}) {
|
|
|
939
1292
|
}
|
|
940
1293
|
|
|
941
1294
|
// src/schema/isMultiSelect.ts
|
|
942
|
-
function isMultiSelect(validator, schema, rootSchema) {
|
|
1295
|
+
function isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) {
|
|
943
1296
|
if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
|
|
944
1297
|
return false;
|
|
945
1298
|
}
|
|
946
|
-
return isSelect(validator, schema.items, rootSchema);
|
|
1299
|
+
return isSelect(validator, schema.items, rootSchema, experimental_customMergeAllOf);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// src/constIsAjvDataReference.ts
|
|
1303
|
+
import isString3 from "lodash/isString";
|
|
1304
|
+
function constIsAjvDataReference(schema) {
|
|
1305
|
+
const schemaConst = schema[CONST_KEY];
|
|
1306
|
+
const schemaType = getSchemaType(schema);
|
|
1307
|
+
return isObject(schemaConst) && isString3(schemaConst?.$data) && schemaType !== "object" && schemaType !== "array";
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
// src/optionsList.ts
|
|
1311
|
+
import get11 from "lodash/get";
|
|
1312
|
+
|
|
1313
|
+
// src/toConstant.ts
|
|
1314
|
+
function toConstant(schema) {
|
|
1315
|
+
if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
|
|
1316
|
+
return schema.enum[0];
|
|
1317
|
+
}
|
|
1318
|
+
if (CONST_KEY in schema) {
|
|
1319
|
+
return schema.const;
|
|
1320
|
+
}
|
|
1321
|
+
throw new Error("schema cannot be inferred as a constant");
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
// src/optionsList.ts
|
|
1325
|
+
function optionsList(schema, uiSchema) {
|
|
1326
|
+
if (schema.enum) {
|
|
1327
|
+
let enumNames;
|
|
1328
|
+
if (uiSchema) {
|
|
1329
|
+
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
1330
|
+
enumNames = uiEnumNames;
|
|
1331
|
+
}
|
|
1332
|
+
return schema.enum.map((value, i) => {
|
|
1333
|
+
const label = enumNames?.[i] || String(value);
|
|
1334
|
+
return { label, value };
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
let altSchemas = void 0;
|
|
1338
|
+
let altUiSchemas = void 0;
|
|
1339
|
+
if (schema.anyOf) {
|
|
1340
|
+
altSchemas = schema.anyOf;
|
|
1341
|
+
altUiSchemas = uiSchema?.anyOf;
|
|
1342
|
+
} else if (schema.oneOf) {
|
|
1343
|
+
altSchemas = schema.oneOf;
|
|
1344
|
+
altUiSchemas = uiSchema?.oneOf;
|
|
1345
|
+
}
|
|
1346
|
+
let selectorField = getDiscriminatorFieldFromSchema(schema);
|
|
1347
|
+
if (uiSchema) {
|
|
1348
|
+
const { optionsSchemaSelector = selectorField } = getUiOptions(uiSchema);
|
|
1349
|
+
selectorField = optionsSchemaSelector;
|
|
1350
|
+
}
|
|
1351
|
+
return altSchemas && altSchemas.map((aSchemaDef, index) => {
|
|
1352
|
+
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
1353
|
+
const aSchema = aSchemaDef;
|
|
1354
|
+
let value;
|
|
1355
|
+
let label = title;
|
|
1356
|
+
if (selectorField) {
|
|
1357
|
+
const innerSchema = get11(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
1358
|
+
value = get11(innerSchema, DEFAULT_KEY, get11(innerSchema, CONST_KEY));
|
|
1359
|
+
label = label || innerSchema?.title || aSchema.title || String(value);
|
|
1360
|
+
} else {
|
|
1361
|
+
value = toConstant(aSchema);
|
|
1362
|
+
label = label || aSchema.title || String(value);
|
|
1363
|
+
}
|
|
1364
|
+
return {
|
|
1365
|
+
schema: aSchema,
|
|
1366
|
+
label,
|
|
1367
|
+
value
|
|
1368
|
+
};
|
|
1369
|
+
});
|
|
947
1370
|
}
|
|
948
1371
|
|
|
949
1372
|
// src/schema/getDefaultFormState.ts
|
|
1373
|
+
var PRIMITIVE_TYPES = ["string", "number", "integer", "boolean", "null"];
|
|
950
1374
|
function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, idx = -1) {
|
|
951
1375
|
if (idx >= 0) {
|
|
952
1376
|
if (Array.isArray(schema.items) && idx < schema.items.length) {
|
|
@@ -963,47 +1387,54 @@ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, id
|
|
|
963
1387
|
}
|
|
964
1388
|
return {};
|
|
965
1389
|
}
|
|
966
|
-
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}) {
|
|
1390
|
+
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
|
|
967
1391
|
const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
|
|
968
|
-
if (includeUndefinedValues) {
|
|
1392
|
+
if (includeUndefinedValues || isConst) {
|
|
969
1393
|
obj[key] = computedDefault;
|
|
970
1394
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
1395
|
+
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
971
1396
|
if (isObject(computedDefault)) {
|
|
972
|
-
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
973
1397
|
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
974
|
-
if (!
|
|
1398
|
+
if (!isEmpty4(computedDefault)) {
|
|
975
1399
|
obj[key] = computedDefault;
|
|
976
1400
|
}
|
|
977
|
-
} else if ((!
|
|
1401
|
+
} else if ((!isEmpty4(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
978
1402
|
obj[key] = computedDefault;
|
|
979
1403
|
}
|
|
980
1404
|
} else if (
|
|
981
1405
|
// Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
|
|
982
1406
|
// Condition 1: computedDefault is not undefined
|
|
983
|
-
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
984
|
-
|
|
1407
|
+
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
1408
|
+
// Or if isSelfOrParentRequired is 'true' and the key is a required field
|
|
1409
|
+
computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || emptyObjectFields === "skipEmptyDefaults" || isSelfOrParentRequired && requiredFields.includes(key))
|
|
985
1410
|
) {
|
|
986
1411
|
obj[key] = computedDefault;
|
|
987
1412
|
}
|
|
988
1413
|
}
|
|
989
1414
|
}
|
|
990
|
-
function computeDefaults(validator, rawSchema, {
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1415
|
+
function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
1416
|
+
const {
|
|
1417
|
+
parentDefaults,
|
|
1418
|
+
rawFormData,
|
|
1419
|
+
rootSchema = {},
|
|
1420
|
+
includeUndefinedValues = false,
|
|
1421
|
+
_recurseList = [],
|
|
1422
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1423
|
+
experimental_customMergeAllOf = void 0,
|
|
1424
|
+
required,
|
|
1425
|
+
shouldMergeDefaultsIntoFormData = false
|
|
1426
|
+
} = computeDefaultsProps;
|
|
1427
|
+
let formData = isObject(rawFormData) ? rawFormData : {};
|
|
1000
1428
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
1001
1429
|
let defaults = parentDefaults;
|
|
1002
1430
|
let schemaToCompute = null;
|
|
1431
|
+
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
|
|
1003
1432
|
let updatedRecurseList = _recurseList;
|
|
1004
|
-
if (
|
|
1433
|
+
if (schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1434
|
+
defaults = schema[CONST_KEY];
|
|
1435
|
+
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
1005
1436
|
defaults = mergeObjects(defaults, schema.default);
|
|
1006
|
-
} else if (DEFAULT_KEY in schema) {
|
|
1437
|
+
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
1007
1438
|
defaults = schema.default;
|
|
1008
1439
|
} else if (REF_KEY in schema) {
|
|
1009
1440
|
const refName = schema[REF_KEY];
|
|
@@ -1011,8 +1442,26 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1011
1442
|
updatedRecurseList = _recurseList.concat(refName);
|
|
1012
1443
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1013
1444
|
}
|
|
1445
|
+
if (schemaToCompute && !defaults) {
|
|
1446
|
+
defaults = schema.default;
|
|
1447
|
+
}
|
|
1448
|
+
if (shouldMergeDefaultsIntoFormData && schemaToCompute && !isObject(rawFormData)) {
|
|
1449
|
+
formData = rawFormData;
|
|
1450
|
+
}
|
|
1014
1451
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
1015
|
-
const
|
|
1452
|
+
const defaultFormData = {
|
|
1453
|
+
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults),
|
|
1454
|
+
...formData
|
|
1455
|
+
};
|
|
1456
|
+
const resolvedSchema = resolveDependencies(
|
|
1457
|
+
validator,
|
|
1458
|
+
schema,
|
|
1459
|
+
rootSchema,
|
|
1460
|
+
false,
|
|
1461
|
+
[],
|
|
1462
|
+
defaultFormData,
|
|
1463
|
+
experimental_customMergeAllOf
|
|
1464
|
+
);
|
|
1016
1465
|
schemaToCompute = resolvedSchema[0];
|
|
1017
1466
|
} else if (isFixedItems(schema)) {
|
|
1018
1467
|
defaults = schema.items.map(
|
|
@@ -1021,9 +1470,11 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1021
1470
|
includeUndefinedValues,
|
|
1022
1471
|
_recurseList,
|
|
1023
1472
|
experimental_defaultFormStateBehavior,
|
|
1473
|
+
experimental_customMergeAllOf,
|
|
1024
1474
|
parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : void 0,
|
|
1025
1475
|
rawFormData: formData,
|
|
1026
|
-
required
|
|
1476
|
+
required,
|
|
1477
|
+
shouldMergeDefaultsIntoFormData
|
|
1027
1478
|
})
|
|
1028
1479
|
);
|
|
1029
1480
|
} else if (ONE_OF_KEY in schema) {
|
|
@@ -1032,13 +1483,21 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1032
1483
|
return void 0;
|
|
1033
1484
|
}
|
|
1034
1485
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1486
|
+
const { type = "null" } = remaining;
|
|
1487
|
+
if (!Array.isArray(type) && PRIMITIVE_TYPES.includes(type) && experimental_dfsb_to_compute?.constAsDefaults === "skipOneOf") {
|
|
1488
|
+
experimental_dfsb_to_compute = {
|
|
1489
|
+
...experimental_dfsb_to_compute,
|
|
1490
|
+
constAsDefaults: "never"
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1035
1493
|
schemaToCompute = oneOf[getClosestMatchingOption(
|
|
1036
1494
|
validator,
|
|
1037
1495
|
rootSchema,
|
|
1038
|
-
|
|
1496
|
+
rawFormData ?? schema.default,
|
|
1039
1497
|
oneOf,
|
|
1040
1498
|
0,
|
|
1041
|
-
discriminator
|
|
1499
|
+
discriminator,
|
|
1500
|
+
experimental_customMergeAllOf
|
|
1042
1501
|
)];
|
|
1043
1502
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1044
1503
|
} else if (ANY_OF_KEY in schema) {
|
|
@@ -1050,10 +1509,11 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1050
1509
|
schemaToCompute = anyOf[getClosestMatchingOption(
|
|
1051
1510
|
validator,
|
|
1052
1511
|
rootSchema,
|
|
1053
|
-
|
|
1512
|
+
rawFormData ?? schema.default,
|
|
1054
1513
|
anyOf,
|
|
1055
1514
|
0,
|
|
1056
|
-
discriminator
|
|
1515
|
+
discriminator,
|
|
1516
|
+
experimental_customMergeAllOf
|
|
1057
1517
|
)];
|
|
1058
1518
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1059
1519
|
}
|
|
@@ -1062,159 +1522,257 @@ function computeDefaults(validator, rawSchema, {
|
|
|
1062
1522
|
rootSchema,
|
|
1063
1523
|
includeUndefinedValues,
|
|
1064
1524
|
_recurseList: updatedRecurseList,
|
|
1065
|
-
experimental_defaultFormStateBehavior,
|
|
1525
|
+
experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
|
|
1526
|
+
experimental_customMergeAllOf,
|
|
1066
1527
|
parentDefaults: defaults,
|
|
1067
1528
|
rawFormData: formData,
|
|
1068
|
-
required
|
|
1529
|
+
required,
|
|
1530
|
+
shouldMergeDefaultsIntoFormData
|
|
1069
1531
|
});
|
|
1070
1532
|
}
|
|
1071
1533
|
if (defaults === void 0) {
|
|
1072
1534
|
defaults = schema.default;
|
|
1073
1535
|
}
|
|
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
|
-
{}
|
|
1536
|
+
const defaultBasedOnSchemaType = getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults);
|
|
1537
|
+
let defaultsWithFormData = defaultBasedOnSchemaType ?? defaults;
|
|
1538
|
+
if (shouldMergeDefaultsIntoFormData) {
|
|
1539
|
+
const { arrayMinItems = {} } = experimental_defaultFormStateBehavior || {};
|
|
1540
|
+
const { mergeExtraDefaults } = arrayMinItems;
|
|
1541
|
+
const matchingFormData = ensureFormDataMatchingSchema(
|
|
1542
|
+
validator,
|
|
1543
|
+
schema,
|
|
1544
|
+
rootSchema,
|
|
1545
|
+
rawFormData,
|
|
1546
|
+
experimental_defaultFormStateBehavior,
|
|
1547
|
+
experimental_customMergeAllOf
|
|
1548
|
+
);
|
|
1549
|
+
if (!isObject(rawFormData) || ALL_OF_KEY in schema) {
|
|
1550
|
+
defaultsWithFormData = mergeDefaultsWithFormData(
|
|
1551
|
+
defaultsWithFormData,
|
|
1552
|
+
matchingFormData,
|
|
1553
|
+
mergeExtraDefaults,
|
|
1554
|
+
true
|
|
1100
1555
|
);
|
|
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
1556
|
}
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1557
|
+
}
|
|
1558
|
+
return defaultsWithFormData;
|
|
1559
|
+
}
|
|
1560
|
+
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1561
|
+
const isSelectField = !isConstant(schema) && isSelect(validator, schema, rootSchema, experimental_customMergeAllOf);
|
|
1562
|
+
let validFormData = formData;
|
|
1563
|
+
if (isSelectField) {
|
|
1564
|
+
const getOptionsList = optionsList(schema);
|
|
1565
|
+
const isValid = getOptionsList?.some((option) => deepEquals(option.value, formData));
|
|
1566
|
+
validFormData = isValid ? formData : void 0;
|
|
1567
|
+
}
|
|
1568
|
+
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
1569
|
+
if (constTakesPrecedence) {
|
|
1570
|
+
validFormData = schema.const;
|
|
1571
|
+
}
|
|
1572
|
+
return validFormData;
|
|
1573
|
+
}
|
|
1574
|
+
function getObjectDefaults(validator, rawSchema, {
|
|
1575
|
+
rawFormData,
|
|
1576
|
+
rootSchema = {},
|
|
1577
|
+
includeUndefinedValues = false,
|
|
1578
|
+
_recurseList = [],
|
|
1579
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1580
|
+
experimental_customMergeAllOf = void 0,
|
|
1581
|
+
required,
|
|
1582
|
+
shouldMergeDefaultsIntoFormData
|
|
1583
|
+
} = {}, defaults) {
|
|
1584
|
+
{
|
|
1585
|
+
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1586
|
+
const schema = rawSchema;
|
|
1587
|
+
const retrievedSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema ? retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf) : schema;
|
|
1588
|
+
const parentConst = retrievedSchema[CONST_KEY];
|
|
1589
|
+
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1590
|
+
(acc, key) => {
|
|
1591
|
+
const propertySchema = get12(retrievedSchema, [PROPERTIES_KEY, key], {});
|
|
1592
|
+
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1593
|
+
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1594
|
+
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
1595
|
+
rootSchema,
|
|
1596
|
+
_recurseList,
|
|
1597
|
+
experimental_defaultFormStateBehavior,
|
|
1598
|
+
experimental_customMergeAllOf,
|
|
1599
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1600
|
+
parentDefaults: get12(defaults, [key]),
|
|
1601
|
+
rawFormData: get12(formData, [key]),
|
|
1602
|
+
required: retrievedSchema.required?.includes(key),
|
|
1603
|
+
shouldMergeDefaultsIntoFormData
|
|
1150
1604
|
});
|
|
1605
|
+
maybeAddDefaultToObject(
|
|
1606
|
+
acc,
|
|
1607
|
+
key,
|
|
1608
|
+
computedDefault,
|
|
1609
|
+
includeUndefinedValues,
|
|
1610
|
+
required,
|
|
1611
|
+
retrievedSchema.required,
|
|
1612
|
+
experimental_defaultFormStateBehavior,
|
|
1613
|
+
hasConst
|
|
1614
|
+
);
|
|
1615
|
+
return acc;
|
|
1616
|
+
},
|
|
1617
|
+
{}
|
|
1618
|
+
);
|
|
1619
|
+
if (retrievedSchema.additionalProperties) {
|
|
1620
|
+
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1621
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
1622
|
+
if (isObject(defaults)) {
|
|
1623
|
+
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1151
1624
|
}
|
|
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
|
-
|
|
1625
|
+
const formDataRequired = [];
|
|
1626
|
+
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1627
|
+
keys2.add(key);
|
|
1628
|
+
formDataRequired.push(key);
|
|
1629
|
+
});
|
|
1630
|
+
keys2.forEach((key) => {
|
|
1631
|
+
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1632
|
+
rootSchema,
|
|
1633
|
+
_recurseList,
|
|
1634
|
+
experimental_defaultFormStateBehavior,
|
|
1635
|
+
experimental_customMergeAllOf,
|
|
1636
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1637
|
+
parentDefaults: get12(defaults, [key]),
|
|
1638
|
+
rawFormData: get12(formData, [key]),
|
|
1639
|
+
required: retrievedSchema.required?.includes(key),
|
|
1640
|
+
shouldMergeDefaultsIntoFormData
|
|
1641
|
+
});
|
|
1642
|
+
maybeAddDefaultToObject(
|
|
1643
|
+
objectDefaults,
|
|
1644
|
+
key,
|
|
1645
|
+
computedDefault,
|
|
1646
|
+
includeUndefinedValues,
|
|
1647
|
+
required,
|
|
1648
|
+
formDataRequired
|
|
1649
|
+
);
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
return objectDefaults;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
function getArrayDefaults(validator, rawSchema, {
|
|
1656
|
+
rawFormData,
|
|
1657
|
+
rootSchema = {},
|
|
1658
|
+
_recurseList = [],
|
|
1659
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1660
|
+
experimental_customMergeAllOf = void 0,
|
|
1661
|
+
required,
|
|
1662
|
+
shouldMergeDefaultsIntoFormData
|
|
1663
|
+
} = {}, defaults) {
|
|
1664
|
+
const schema = rawSchema;
|
|
1665
|
+
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems ?? {};
|
|
1666
|
+
const { populate: arrayMinItemsPopulate, mergeExtraDefaults: arrayMergeExtraDefaults } = arrayMinItemsStateBehavior;
|
|
1667
|
+
const neverPopulate = arrayMinItemsPopulate === "never";
|
|
1668
|
+
const ignoreMinItemsFlagSet = arrayMinItemsPopulate === "requiredOnly";
|
|
1669
|
+
const isPopulateAll = arrayMinItemsPopulate === "all" || !neverPopulate && !ignoreMinItemsFlagSet;
|
|
1670
|
+
const computeSkipPopulate = arrayMinItemsStateBehavior?.computeSkipPopulate ?? (() => false);
|
|
1671
|
+
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
|
|
1672
|
+
const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
|
|
1673
|
+
if (Array.isArray(defaults)) {
|
|
1674
|
+
defaults = defaults.map((item, idx) => {
|
|
1675
|
+
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
1676
|
+
return computeDefaults(validator, schemaItem, {
|
|
1677
|
+
rootSchema,
|
|
1678
|
+
_recurseList,
|
|
1679
|
+
experimental_defaultFormStateBehavior,
|
|
1680
|
+
experimental_customMergeAllOf,
|
|
1681
|
+
parentDefaults: item,
|
|
1682
|
+
required,
|
|
1683
|
+
shouldMergeDefaultsIntoFormData
|
|
1684
|
+
});
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
if (Array.isArray(rawFormData)) {
|
|
1688
|
+
const schemaItem = getInnerSchemaForArrayItem(schema);
|
|
1689
|
+
if (neverPopulate) {
|
|
1690
|
+
defaults = rawFormData;
|
|
1691
|
+
} else {
|
|
1692
|
+
const itemDefaults = rawFormData.map((item, idx) => {
|
|
1693
|
+
return computeDefaults(validator, schemaItem, {
|
|
1185
1694
|
rootSchema,
|
|
1186
1695
|
_recurseList,
|
|
1187
1696
|
experimental_defaultFormStateBehavior,
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1697
|
+
experimental_customMergeAllOf,
|
|
1698
|
+
rawFormData: item,
|
|
1699
|
+
parentDefaults: get12(defaults, [idx]),
|
|
1700
|
+
required,
|
|
1701
|
+
shouldMergeDefaultsIntoFormData
|
|
1702
|
+
});
|
|
1703
|
+
});
|
|
1704
|
+
const mergeExtraDefaults = (ignoreMinItemsFlagSet && required || isPopulateAll) && arrayMergeExtraDefaults;
|
|
1705
|
+
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
const hasConst = isObject(schema) && CONST_KEY in schema && experimental_defaultFormStateBehavior?.constAsDefaults !== "never";
|
|
1709
|
+
if (hasConst === false) {
|
|
1710
|
+
if (neverPopulate) {
|
|
1711
|
+
return defaults ?? emptyDefault;
|
|
1712
|
+
}
|
|
1713
|
+
if (ignoreMinItemsFlagSet && !required) {
|
|
1714
|
+
return defaults ? defaults : void 0;
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1718
|
+
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1719
|
+
return defaults ? defaults : emptyDefault;
|
|
1720
|
+
}
|
|
1721
|
+
const defaultEntries = defaults || [];
|
|
1722
|
+
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
1723
|
+
const fillerDefault = fillerSchema.default;
|
|
1724
|
+
const fillerEntries = new Array(schema.minItems - defaultsLength).fill(
|
|
1725
|
+
computeDefaults(validator, fillerSchema, {
|
|
1726
|
+
parentDefaults: fillerDefault,
|
|
1727
|
+
rootSchema,
|
|
1728
|
+
_recurseList,
|
|
1729
|
+
experimental_defaultFormStateBehavior,
|
|
1730
|
+
experimental_customMergeAllOf,
|
|
1731
|
+
required,
|
|
1732
|
+
shouldMergeDefaultsIntoFormData
|
|
1733
|
+
})
|
|
1734
|
+
);
|
|
1735
|
+
return defaultEntries.concat(fillerEntries);
|
|
1736
|
+
}
|
|
1737
|
+
function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps = {}, defaults) {
|
|
1738
|
+
switch (getSchemaType(rawSchema)) {
|
|
1739
|
+
// We need to recurse for object schema inner default values.
|
|
1740
|
+
case "object": {
|
|
1741
|
+
return getObjectDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1742
|
+
}
|
|
1743
|
+
case "array": {
|
|
1744
|
+
return getArrayDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1192
1745
|
}
|
|
1193
1746
|
}
|
|
1194
|
-
return defaults;
|
|
1195
1747
|
}
|
|
1196
|
-
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
|
|
1748
|
+
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1197
1749
|
if (!isObject(theSchema)) {
|
|
1198
1750
|
throw new Error("Invalid schema: " + theSchema);
|
|
1199
1751
|
}
|
|
1200
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1752
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1201
1753
|
const defaults = computeDefaults(validator, schema, {
|
|
1202
1754
|
rootSchema,
|
|
1203
1755
|
includeUndefinedValues,
|
|
1204
1756
|
experimental_defaultFormStateBehavior,
|
|
1205
|
-
|
|
1757
|
+
experimental_customMergeAllOf,
|
|
1758
|
+
rawFormData: formData,
|
|
1759
|
+
shouldMergeDefaultsIntoFormData: true
|
|
1206
1760
|
});
|
|
1207
|
-
if (formData
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1761
|
+
if (isObject(formData) || Array.isArray(formData)) {
|
|
1762
|
+
const { mergeDefaultsIntoFormData } = experimental_defaultFormStateBehavior || {};
|
|
1763
|
+
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
1764
|
+
const result = mergeDefaultsWithFormData(
|
|
1765
|
+
defaults,
|
|
1766
|
+
formData,
|
|
1767
|
+
true,
|
|
1768
|
+
// set to true to add any additional default array entries.
|
|
1769
|
+
defaultSupercedesUndefined,
|
|
1770
|
+
true
|
|
1771
|
+
// set to true to override formData with defaults if they exist.
|
|
1772
|
+
);
|
|
1773
|
+
return result;
|
|
1216
1774
|
}
|
|
1217
|
-
return
|
|
1775
|
+
return defaults;
|
|
1218
1776
|
}
|
|
1219
1777
|
|
|
1220
1778
|
// src/isCustomWidget.ts
|
|
@@ -1227,25 +1785,31 @@ function isCustomWidget(uiSchema = {}) {
|
|
|
1227
1785
|
}
|
|
1228
1786
|
|
|
1229
1787
|
// src/schema/isFilesArray.ts
|
|
1230
|
-
function isFilesArray(validator, schema, uiSchema = {}, rootSchema) {
|
|
1788
|
+
function isFilesArray(validator, schema, uiSchema = {}, rootSchema, experimental_customMergeAllOf) {
|
|
1231
1789
|
if (uiSchema[UI_WIDGET_KEY] === "files") {
|
|
1232
1790
|
return true;
|
|
1233
1791
|
}
|
|
1234
1792
|
if (schema.items) {
|
|
1235
|
-
const itemsSchema = retrieveSchema(
|
|
1793
|
+
const itemsSchema = retrieveSchema(
|
|
1794
|
+
validator,
|
|
1795
|
+
schema.items,
|
|
1796
|
+
rootSchema,
|
|
1797
|
+
void 0,
|
|
1798
|
+
experimental_customMergeAllOf
|
|
1799
|
+
);
|
|
1236
1800
|
return itemsSchema.type === "string" && itemsSchema.format === "data-url";
|
|
1237
1801
|
}
|
|
1238
1802
|
return false;
|
|
1239
1803
|
}
|
|
1240
1804
|
|
|
1241
1805
|
// src/schema/getDisplayLabel.ts
|
|
1242
|
-
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
|
|
1806
|
+
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions, experimental_customMergeAllOf) {
|
|
1243
1807
|
const uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
1244
1808
|
const { label = true } = uiOptions;
|
|
1245
1809
|
let displayLabel = !!label;
|
|
1246
1810
|
const schemaType = getSchemaType(schema);
|
|
1247
1811
|
if (schemaType === "array") {
|
|
1248
|
-
displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
|
|
1812
|
+
displayLabel = isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || isFilesArray(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) || isCustomWidget(uiSchema);
|
|
1249
1813
|
}
|
|
1250
1814
|
if (schemaType === "object") {
|
|
1251
1815
|
displayLabel = false;
|
|
@@ -1259,54 +1823,50 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
1259
1823
|
return displayLabel;
|
|
1260
1824
|
}
|
|
1261
1825
|
|
|
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
1826
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
1279
|
-
import
|
|
1280
|
-
import
|
|
1827
|
+
import get13 from "lodash/get";
|
|
1828
|
+
import has5 from "lodash/has";
|
|
1281
1829
|
var NO_VALUE = Symbol("no Value");
|
|
1282
|
-
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
1830
|
+
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
1283
1831
|
let newFormData;
|
|
1284
|
-
if (
|
|
1832
|
+
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
1285
1833
|
const removeOldSchemaData = {};
|
|
1286
|
-
if (
|
|
1287
|
-
const properties =
|
|
1834
|
+
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
1835
|
+
const properties = get13(oldSchema, PROPERTIES_KEY, {});
|
|
1288
1836
|
Object.keys(properties).forEach((key) => {
|
|
1289
|
-
if (
|
|
1837
|
+
if (has5(data, key)) {
|
|
1290
1838
|
removeOldSchemaData[key] = void 0;
|
|
1291
1839
|
}
|
|
1292
1840
|
});
|
|
1293
1841
|
}
|
|
1294
|
-
const
|
|
1842
|
+
const keys2 = Object.keys(get13(newSchema, PROPERTIES_KEY, {}));
|
|
1295
1843
|
const nestedData = {};
|
|
1296
|
-
|
|
1297
|
-
const formValue =
|
|
1298
|
-
let oldKeyedSchema =
|
|
1299
|
-
let newKeyedSchema =
|
|
1300
|
-
if (
|
|
1301
|
-
oldKeyedSchema = retrieveSchema(
|
|
1844
|
+
keys2.forEach((key) => {
|
|
1845
|
+
const formValue = get13(data, key);
|
|
1846
|
+
let oldKeyedSchema = get13(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1847
|
+
let newKeyedSchema = get13(newSchema, [PROPERTIES_KEY, key], {});
|
|
1848
|
+
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
1849
|
+
oldKeyedSchema = retrieveSchema(
|
|
1850
|
+
validator,
|
|
1851
|
+
oldKeyedSchema,
|
|
1852
|
+
rootSchema,
|
|
1853
|
+
formValue,
|
|
1854
|
+
experimental_customMergeAllOf
|
|
1855
|
+
);
|
|
1302
1856
|
}
|
|
1303
|
-
if (
|
|
1304
|
-
newKeyedSchema = retrieveSchema(
|
|
1857
|
+
if (has5(newKeyedSchema, REF_KEY)) {
|
|
1858
|
+
newKeyedSchema = retrieveSchema(
|
|
1859
|
+
validator,
|
|
1860
|
+
newKeyedSchema,
|
|
1861
|
+
rootSchema,
|
|
1862
|
+
formValue,
|
|
1863
|
+
experimental_customMergeAllOf
|
|
1864
|
+
);
|
|
1305
1865
|
}
|
|
1306
|
-
const oldSchemaTypeForKey =
|
|
1307
|
-
const newSchemaTypeForKey =
|
|
1866
|
+
const oldSchemaTypeForKey = get13(oldKeyedSchema, "type");
|
|
1867
|
+
const newSchemaTypeForKey = get13(newKeyedSchema, "type");
|
|
1308
1868
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1309
|
-
if (
|
|
1869
|
+
if (has5(removeOldSchemaData, key)) {
|
|
1310
1870
|
delete removeOldSchemaData[key];
|
|
1311
1871
|
}
|
|
1312
1872
|
if (newSchemaTypeForKey === "object" || newSchemaTypeForKey === "array" && Array.isArray(formValue)) {
|
|
@@ -1315,23 +1875,24 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1315
1875
|
rootSchema,
|
|
1316
1876
|
newKeyedSchema,
|
|
1317
1877
|
oldKeyedSchema,
|
|
1318
|
-
formValue
|
|
1878
|
+
formValue,
|
|
1879
|
+
experimental_customMergeAllOf
|
|
1319
1880
|
);
|
|
1320
1881
|
if (itemData !== void 0 || newSchemaTypeForKey === "array") {
|
|
1321
1882
|
nestedData[key] = itemData;
|
|
1322
1883
|
}
|
|
1323
1884
|
} else {
|
|
1324
|
-
const newOptionDefault =
|
|
1325
|
-
const oldOptionDefault =
|
|
1885
|
+
const newOptionDefault = get13(newKeyedSchema, "default", NO_VALUE);
|
|
1886
|
+
const oldOptionDefault = get13(oldKeyedSchema, "default", NO_VALUE);
|
|
1326
1887
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1327
1888
|
if (oldOptionDefault === formValue) {
|
|
1328
1889
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1329
|
-
} else if (
|
|
1890
|
+
} else if (get13(newKeyedSchema, "readOnly") === true) {
|
|
1330
1891
|
removeOldSchemaData[key] = void 0;
|
|
1331
1892
|
}
|
|
1332
1893
|
}
|
|
1333
|
-
const newOptionConst =
|
|
1334
|
-
const oldOptionConst =
|
|
1894
|
+
const newOptionConst = get13(newKeyedSchema, "const", NO_VALUE);
|
|
1895
|
+
const oldOptionConst = get13(oldKeyedSchema, "const", NO_VALUE);
|
|
1335
1896
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1336
1897
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1337
1898
|
}
|
|
@@ -1343,20 +1904,32 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1343
1904
|
...removeOldSchemaData,
|
|
1344
1905
|
...nestedData
|
|
1345
1906
|
};
|
|
1346
|
-
} else if (
|
|
1347
|
-
let oldSchemaItems =
|
|
1348
|
-
let newSchemaItems =
|
|
1907
|
+
} else if (get13(oldSchema, "type") === "array" && get13(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1908
|
+
let oldSchemaItems = get13(oldSchema, "items");
|
|
1909
|
+
let newSchemaItems = get13(newSchema, "items");
|
|
1349
1910
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1350
|
-
if (
|
|
1351
|
-
oldSchemaItems = retrieveSchema(
|
|
1911
|
+
if (has5(oldSchemaItems, REF_KEY)) {
|
|
1912
|
+
oldSchemaItems = retrieveSchema(
|
|
1913
|
+
validator,
|
|
1914
|
+
oldSchemaItems,
|
|
1915
|
+
rootSchema,
|
|
1916
|
+
data,
|
|
1917
|
+
experimental_customMergeAllOf
|
|
1918
|
+
);
|
|
1352
1919
|
}
|
|
1353
|
-
if (
|
|
1354
|
-
newSchemaItems = retrieveSchema(
|
|
1920
|
+
if (has5(newSchemaItems, REF_KEY)) {
|
|
1921
|
+
newSchemaItems = retrieveSchema(
|
|
1922
|
+
validator,
|
|
1923
|
+
newSchemaItems,
|
|
1924
|
+
rootSchema,
|
|
1925
|
+
data,
|
|
1926
|
+
experimental_customMergeAllOf
|
|
1927
|
+
);
|
|
1355
1928
|
}
|
|
1356
|
-
const oldSchemaType =
|
|
1357
|
-
const newSchemaType =
|
|
1929
|
+
const oldSchemaType = get13(oldSchemaItems, "type");
|
|
1930
|
+
const newSchemaType = get13(newSchemaItems, "type");
|
|
1358
1931
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1359
|
-
const maxItems =
|
|
1932
|
+
const maxItems = get13(newSchema, "maxItems", -1);
|
|
1360
1933
|
if (newSchemaType === "object") {
|
|
1361
1934
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1362
1935
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1364,7 +1937,8 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1364
1937
|
rootSchema,
|
|
1365
1938
|
newSchemaItems,
|
|
1366
1939
|
oldSchemaItems,
|
|
1367
|
-
aValue
|
|
1940
|
+
aValue,
|
|
1941
|
+
experimental_customMergeAllOf
|
|
1368
1942
|
);
|
|
1369
1943
|
if (itemValue !== void 0 && (maxItems < 0 || newValue.length < maxItems)) {
|
|
1370
1944
|
newValue.push(itemValue);
|
|
@@ -1383,71 +1957,84 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
1383
1957
|
}
|
|
1384
1958
|
|
|
1385
1959
|
// src/schema/toIdSchema.ts
|
|
1386
|
-
import
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1960
|
+
import get14 from "lodash/get";
|
|
1961
|
+
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1962
|
+
const $id = id || idPrefix;
|
|
1963
|
+
const idSchema = { $id };
|
|
1964
|
+
if (typeof schema === "object") {
|
|
1965
|
+
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1966
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1967
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1968
|
+
if (sameSchemaIndex === -1) {
|
|
1969
|
+
return toIdSchemaInternal(
|
|
1970
|
+
validator,
|
|
1971
|
+
_schema,
|
|
1972
|
+
idPrefix,
|
|
1973
|
+
idSeparator,
|
|
1974
|
+
id,
|
|
1975
|
+
rootSchema,
|
|
1976
|
+
formData,
|
|
1977
|
+
_recurseList.concat(_schema),
|
|
1978
|
+
experimental_customMergeAllOf
|
|
1979
|
+
);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
if (ITEMS_KEY in schema && !get14(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1393
1983
|
return toIdSchemaInternal(
|
|
1394
1984
|
validator,
|
|
1395
|
-
|
|
1985
|
+
get14(schema, ITEMS_KEY),
|
|
1396
1986
|
idPrefix,
|
|
1397
1987
|
idSeparator,
|
|
1398
1988
|
id,
|
|
1399
1989
|
rootSchema,
|
|
1400
1990
|
formData,
|
|
1401
|
-
_recurseList
|
|
1991
|
+
_recurseList,
|
|
1992
|
+
experimental_customMergeAllOf
|
|
1402
1993
|
);
|
|
1403
1994
|
}
|
|
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
|
-
);
|
|
1995
|
+
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1996
|
+
for (const name in schema.properties) {
|
|
1997
|
+
const field = schema[PROPERTIES_KEY][name];
|
|
1998
|
+
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1999
|
+
idSchema[name] = toIdSchemaInternal(
|
|
2000
|
+
validator,
|
|
2001
|
+
field,
|
|
2002
|
+
idPrefix,
|
|
2003
|
+
idSeparator,
|
|
2004
|
+
fieldId,
|
|
2005
|
+
rootSchema,
|
|
2006
|
+
// It's possible that formData is not an object -- this can happen if an
|
|
2007
|
+
// array item has just been added, but not populated with data yet
|
|
2008
|
+
get14(formData, [name]),
|
|
2009
|
+
_recurseList,
|
|
2010
|
+
experimental_customMergeAllOf
|
|
2011
|
+
);
|
|
2012
|
+
}
|
|
1435
2013
|
}
|
|
1436
2014
|
}
|
|
1437
2015
|
return idSchema;
|
|
1438
2016
|
}
|
|
1439
|
-
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_") {
|
|
1440
|
-
return toIdSchemaInternal(
|
|
2017
|
+
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_", experimental_customMergeAllOf) {
|
|
2018
|
+
return toIdSchemaInternal(
|
|
2019
|
+
validator,
|
|
2020
|
+
schema,
|
|
2021
|
+
idPrefix,
|
|
2022
|
+
idSeparator,
|
|
2023
|
+
id,
|
|
2024
|
+
rootSchema,
|
|
2025
|
+
formData,
|
|
2026
|
+
void 0,
|
|
2027
|
+
experimental_customMergeAllOf
|
|
2028
|
+
);
|
|
1441
2029
|
}
|
|
1442
2030
|
|
|
1443
2031
|
// src/schema/toPathSchema.ts
|
|
1444
|
-
import
|
|
1445
|
-
import isEqual3 from "lodash/isEqual";
|
|
2032
|
+
import get15 from "lodash/get";
|
|
1446
2033
|
import set2 from "lodash/set";
|
|
1447
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
2034
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1448
2035
|
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) =>
|
|
2036
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
2037
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1451
2038
|
if (sameSchemaIndex === -1) {
|
|
1452
2039
|
return toPathSchemaInternal(
|
|
1453
2040
|
validator,
|
|
@@ -1455,7 +2042,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1455
2042
|
name,
|
|
1456
2043
|
rootSchema,
|
|
1457
2044
|
formData,
|
|
1458
|
-
_recurseList.concat(_schema)
|
|
2045
|
+
_recurseList.concat(_schema),
|
|
2046
|
+
experimental_customMergeAllOf
|
|
1459
2047
|
);
|
|
1460
2048
|
}
|
|
1461
2049
|
}
|
|
@@ -1465,11 +2053,27 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1465
2053
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
1466
2054
|
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
1467
2055
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1468
|
-
const index = getClosestMatchingOption(
|
|
2056
|
+
const index = getClosestMatchingOption(
|
|
2057
|
+
validator,
|
|
2058
|
+
rootSchema,
|
|
2059
|
+
formData,
|
|
2060
|
+
xxxOf,
|
|
2061
|
+
0,
|
|
2062
|
+
discriminator,
|
|
2063
|
+
experimental_customMergeAllOf
|
|
2064
|
+
);
|
|
1469
2065
|
const _schema = xxxOf[index];
|
|
1470
2066
|
pathSchema = {
|
|
1471
2067
|
...pathSchema,
|
|
1472
|
-
...toPathSchemaInternal(
|
|
2068
|
+
...toPathSchemaInternal(
|
|
2069
|
+
validator,
|
|
2070
|
+
_schema,
|
|
2071
|
+
name,
|
|
2072
|
+
rootSchema,
|
|
2073
|
+
formData,
|
|
2074
|
+
_recurseList,
|
|
2075
|
+
experimental_customMergeAllOf
|
|
2076
|
+
)
|
|
1473
2077
|
};
|
|
1474
2078
|
}
|
|
1475
2079
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
@@ -1486,7 +2090,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1486
2090
|
`${name}.${i}`,
|
|
1487
2091
|
rootSchema,
|
|
1488
2092
|
element,
|
|
1489
|
-
_recurseList
|
|
2093
|
+
_recurseList,
|
|
2094
|
+
experimental_customMergeAllOf
|
|
1490
2095
|
);
|
|
1491
2096
|
} else if (schemaAdditionalItems) {
|
|
1492
2097
|
pathSchema[i] = toPathSchemaInternal(
|
|
@@ -1495,7 +2100,8 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1495
2100
|
`${name}.${i}`,
|
|
1496
2101
|
rootSchema,
|
|
1497
2102
|
element,
|
|
1498
|
-
_recurseList
|
|
2103
|
+
_recurseList,
|
|
2104
|
+
experimental_customMergeAllOf
|
|
1499
2105
|
);
|
|
1500
2106
|
} else {
|
|
1501
2107
|
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
@@ -1509,13 +2115,14 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1509
2115
|
`${name}.${i}`,
|
|
1510
2116
|
rootSchema,
|
|
1511
2117
|
element,
|
|
1512
|
-
_recurseList
|
|
2118
|
+
_recurseList,
|
|
2119
|
+
experimental_customMergeAllOf
|
|
1513
2120
|
);
|
|
1514
2121
|
});
|
|
1515
2122
|
}
|
|
1516
2123
|
} else if (PROPERTIES_KEY in schema) {
|
|
1517
2124
|
for (const property in schema.properties) {
|
|
1518
|
-
const field =
|
|
2125
|
+
const field = get15(schema, [PROPERTIES_KEY, property], {});
|
|
1519
2126
|
pathSchema[property] = toPathSchemaInternal(
|
|
1520
2127
|
validator,
|
|
1521
2128
|
field,
|
|
@@ -1523,15 +2130,16 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
1523
2130
|
rootSchema,
|
|
1524
2131
|
// It's possible that formData is not an object -- this can happen if an
|
|
1525
2132
|
// array item has just been added, but not populated with data yet
|
|
1526
|
-
|
|
1527
|
-
_recurseList
|
|
2133
|
+
get15(formData, [property]),
|
|
2134
|
+
_recurseList,
|
|
2135
|
+
experimental_customMergeAllOf
|
|
1528
2136
|
);
|
|
1529
2137
|
}
|
|
1530
2138
|
}
|
|
1531
2139
|
return pathSchema;
|
|
1532
2140
|
}
|
|
1533
|
-
function toPathSchema(validator, schema, name = "", rootSchema, formData) {
|
|
1534
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
|
|
2141
|
+
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2142
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
1535
2143
|
}
|
|
1536
2144
|
|
|
1537
2145
|
// src/createSchemaUtils.ts
|
|
@@ -1541,11 +2149,13 @@ var SchemaUtils = class {
|
|
|
1541
2149
|
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
1542
2150
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
1543
2151
|
* @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
|
|
2152
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1544
2153
|
*/
|
|
1545
|
-
constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
|
|
2154
|
+
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1546
2155
|
this.rootSchema = rootSchema;
|
|
1547
2156
|
this.validator = validator;
|
|
1548
2157
|
this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
|
|
2158
|
+
this.experimental_customMergeAllOf = experimental_customMergeAllOf;
|
|
1549
2159
|
}
|
|
1550
2160
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
1551
2161
|
*
|
|
@@ -1561,13 +2171,55 @@ var SchemaUtils = class {
|
|
|
1561
2171
|
* @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
|
|
1562
2172
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
1563
2173
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
2174
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1564
2175
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
1565
2176
|
*/
|
|
1566
|
-
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
2177
|
+
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
1567
2178
|
if (!validator || !rootSchema) {
|
|
1568
2179
|
return false;
|
|
1569
2180
|
}
|
|
1570
|
-
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
|
|
2181
|
+
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
2182
|
+
}
|
|
2183
|
+
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
2184
|
+
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
2185
|
+
* field is in the `required` list for its parent and if so, it is marked as required on return.
|
|
2186
|
+
*
|
|
2187
|
+
* @param schema - The current node within the JSON schema
|
|
2188
|
+
* @param path - The remaining keys in the path to the desired field
|
|
2189
|
+
* @param [formData] - The form data that is used to determine which oneOf option
|
|
2190
|
+
* @returns - An object that contains the field and its required state. If no field can be found then
|
|
2191
|
+
* `{ field: undefined, isRequired: undefined }` is returned.
|
|
2192
|
+
*/
|
|
2193
|
+
findFieldInSchema(schema, path, formData) {
|
|
2194
|
+
return findFieldInSchema(
|
|
2195
|
+
this.validator,
|
|
2196
|
+
this.rootSchema,
|
|
2197
|
+
schema,
|
|
2198
|
+
path,
|
|
2199
|
+
formData,
|
|
2200
|
+
this.experimental_customMergeAllOf
|
|
2201
|
+
);
|
|
2202
|
+
}
|
|
2203
|
+
/** Finds the oneOf option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` that
|
|
2204
|
+
* matches the `formData[selectorField]` value. For the purposes of this function, `selectorField` is either
|
|
2205
|
+
* `schema.discriminator.propertyName` or `fallbackField`.
|
|
2206
|
+
*
|
|
2207
|
+
* @param schema - The schema element in which to search for the selected oneOf option
|
|
2208
|
+
* @param fallbackField - The field to use as a backup selector field if the schema does not have a required field
|
|
2209
|
+
* @param xxx - Either `oneOf` or `anyOf`, defines which value is being sought
|
|
2210
|
+
* @param [formData={}] - The form data that is used to determine which oneOf option
|
|
2211
|
+
* @returns - The anyOf/oneOf option that matches the selector field in the schema or undefined if nothing is selected
|
|
2212
|
+
*/
|
|
2213
|
+
findSelectedOptionInXxxOf(schema, fallbackField, xxx, formData) {
|
|
2214
|
+
return findSelectedOptionInXxxOf(
|
|
2215
|
+
this.validator,
|
|
2216
|
+
this.rootSchema,
|
|
2217
|
+
schema,
|
|
2218
|
+
fallbackField,
|
|
2219
|
+
xxx,
|
|
2220
|
+
formData,
|
|
2221
|
+
this.experimental_customMergeAllOf
|
|
2222
|
+
);
|
|
1571
2223
|
}
|
|
1572
2224
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
1573
2225
|
* computed to have defaults provided in the `schema`.
|
|
@@ -1586,7 +2238,8 @@ var SchemaUtils = class {
|
|
|
1586
2238
|
formData,
|
|
1587
2239
|
this.rootSchema,
|
|
1588
2240
|
includeUndefinedValues,
|
|
1589
|
-
this.experimental_defaultFormStateBehavior
|
|
2241
|
+
this.experimental_defaultFormStateBehavior,
|
|
2242
|
+
this.experimental_customMergeAllOf
|
|
1590
2243
|
);
|
|
1591
2244
|
}
|
|
1592
2245
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
@@ -1598,7 +2251,14 @@ var SchemaUtils = class {
|
|
|
1598
2251
|
* @returns - True if the label should be displayed or false if it should not
|
|
1599
2252
|
*/
|
|
1600
2253
|
getDisplayLabel(schema, uiSchema, globalOptions) {
|
|
1601
|
-
return getDisplayLabel(
|
|
2254
|
+
return getDisplayLabel(
|
|
2255
|
+
this.validator,
|
|
2256
|
+
schema,
|
|
2257
|
+
uiSchema,
|
|
2258
|
+
this.rootSchema,
|
|
2259
|
+
globalOptions,
|
|
2260
|
+
this.experimental_customMergeAllOf
|
|
2261
|
+
);
|
|
1602
2262
|
}
|
|
1603
2263
|
/** Determines which of the given `options` provided most closely matches the `formData`.
|
|
1604
2264
|
* Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
|
|
@@ -1620,7 +2280,8 @@ var SchemaUtils = class {
|
|
|
1620
2280
|
formData,
|
|
1621
2281
|
options,
|
|
1622
2282
|
selectedOption,
|
|
1623
|
-
discriminatorField
|
|
2283
|
+
discriminatorField,
|
|
2284
|
+
this.experimental_customMergeAllOf
|
|
1624
2285
|
);
|
|
1625
2286
|
}
|
|
1626
2287
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
@@ -1635,18 +2296,16 @@ var SchemaUtils = class {
|
|
|
1635
2296
|
getFirstMatchingOption(formData, options, discriminatorField) {
|
|
1636
2297
|
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
1637
2298
|
}
|
|
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);
|
|
2299
|
+
getFromSchema(schema, path, defaultValue) {
|
|
2300
|
+
return getFromSchema(
|
|
2301
|
+
this.validator,
|
|
2302
|
+
this.rootSchema,
|
|
2303
|
+
schema,
|
|
2304
|
+
path,
|
|
2305
|
+
// @ts-expect-error TS2769: No overload matches this call
|
|
2306
|
+
defaultValue,
|
|
2307
|
+
this.experimental_customMergeAllOf
|
|
2308
|
+
);
|
|
1650
2309
|
}
|
|
1651
2310
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
1652
2311
|
*
|
|
@@ -1655,7 +2314,7 @@ var SchemaUtils = class {
|
|
|
1655
2314
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1656
2315
|
*/
|
|
1657
2316
|
isFilesArray(schema, uiSchema) {
|
|
1658
|
-
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
|
|
2317
|
+
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1659
2318
|
}
|
|
1660
2319
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
1661
2320
|
*
|
|
@@ -1663,7 +2322,7 @@ var SchemaUtils = class {
|
|
|
1663
2322
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1664
2323
|
*/
|
|
1665
2324
|
isMultiSelect(schema) {
|
|
1666
|
-
return isMultiSelect(this.validator, schema, this.rootSchema);
|
|
2325
|
+
return isMultiSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1667
2326
|
}
|
|
1668
2327
|
/** Checks to see if the `schema` combination represents a select
|
|
1669
2328
|
*
|
|
@@ -1671,21 +2330,7 @@ var SchemaUtils = class {
|
|
|
1671
2330
|
* @returns - True if schema contains a select, otherwise false
|
|
1672
2331
|
*/
|
|
1673
2332
|
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);
|
|
2333
|
+
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1689
2334
|
}
|
|
1690
2335
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
1691
2336
|
* dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
|
|
@@ -1696,7 +2341,13 @@ var SchemaUtils = class {
|
|
|
1696
2341
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
1697
2342
|
*/
|
|
1698
2343
|
retrieveSchema(schema, rawFormData) {
|
|
1699
|
-
return retrieveSchema(
|
|
2344
|
+
return retrieveSchema(
|
|
2345
|
+
this.validator,
|
|
2346
|
+
schema,
|
|
2347
|
+
this.rootSchema,
|
|
2348
|
+
rawFormData,
|
|
2349
|
+
this.experimental_customMergeAllOf
|
|
2350
|
+
);
|
|
1700
2351
|
}
|
|
1701
2352
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
|
|
1702
2353
|
* new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
|
|
@@ -1710,7 +2361,14 @@ var SchemaUtils = class {
|
|
|
1710
2361
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
1711
2362
|
*/
|
|
1712
2363
|
sanitizeDataForNewSchema(newSchema, oldSchema, data) {
|
|
1713
|
-
return sanitizeDataForNewSchema(
|
|
2364
|
+
return sanitizeDataForNewSchema(
|
|
2365
|
+
this.validator,
|
|
2366
|
+
this.rootSchema,
|
|
2367
|
+
newSchema,
|
|
2368
|
+
oldSchema,
|
|
2369
|
+
data,
|
|
2370
|
+
this.experimental_customMergeAllOf
|
|
2371
|
+
);
|
|
1714
2372
|
}
|
|
1715
2373
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
1716
2374
|
*
|
|
@@ -1722,7 +2380,16 @@ var SchemaUtils = class {
|
|
|
1722
2380
|
* @returns - The `IdSchema` object for the `schema`
|
|
1723
2381
|
*/
|
|
1724
2382
|
toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
|
|
1725
|
-
return toIdSchema(
|
|
2383
|
+
return toIdSchema(
|
|
2384
|
+
this.validator,
|
|
2385
|
+
schema,
|
|
2386
|
+
id,
|
|
2387
|
+
this.rootSchema,
|
|
2388
|
+
formData,
|
|
2389
|
+
idPrefix,
|
|
2390
|
+
idSeparator,
|
|
2391
|
+
this.experimental_customMergeAllOf
|
|
2392
|
+
);
|
|
1726
2393
|
}
|
|
1727
2394
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1728
2395
|
*
|
|
@@ -1732,11 +2399,23 @@ var SchemaUtils = class {
|
|
|
1732
2399
|
* @returns - The `PathSchema` object for the `schema`
|
|
1733
2400
|
*/
|
|
1734
2401
|
toPathSchema(schema, name, formData) {
|
|
1735
|
-
return toPathSchema(
|
|
2402
|
+
return toPathSchema(
|
|
2403
|
+
this.validator,
|
|
2404
|
+
schema,
|
|
2405
|
+
name,
|
|
2406
|
+
this.rootSchema,
|
|
2407
|
+
formData,
|
|
2408
|
+
this.experimental_customMergeAllOf
|
|
2409
|
+
);
|
|
1736
2410
|
}
|
|
1737
2411
|
};
|
|
1738
|
-
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
1739
|
-
return new SchemaUtils(
|
|
2412
|
+
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
2413
|
+
return new SchemaUtils(
|
|
2414
|
+
validator,
|
|
2415
|
+
rootSchema,
|
|
2416
|
+
experimental_defaultFormStateBehavior,
|
|
2417
|
+
experimental_customMergeAllOf
|
|
2418
|
+
);
|
|
1740
2419
|
}
|
|
1741
2420
|
|
|
1742
2421
|
// src/dataURItoBlob.ts
|
|
@@ -1818,9 +2497,6 @@ function englishStringTranslator(stringToTranslate, params) {
|
|
|
1818
2497
|
return replaceStringParameters(stringToTranslate, params);
|
|
1819
2498
|
}
|
|
1820
2499
|
|
|
1821
|
-
// src/enumOptionsDeselectValue.ts
|
|
1822
|
-
import isEqual4 from "lodash/isEqual";
|
|
1823
|
-
|
|
1824
2500
|
// src/enumOptionsValueForIndex.ts
|
|
1825
2501
|
function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
1826
2502
|
if (Array.isArray(valueIndex)) {
|
|
@@ -1835,18 +2511,17 @@ function enumOptionsValueForIndex(valueIndex, allEnumOptions = [], emptyValue) {
|
|
|
1835
2511
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1836
2512
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1837
2513
|
if (Array.isArray(selected)) {
|
|
1838
|
-
return selected.filter((v) => !
|
|
2514
|
+
return selected.filter((v) => !deepEquals(v, value));
|
|
1839
2515
|
}
|
|
1840
|
-
return
|
|
2516
|
+
return deepEquals(value, selected) ? void 0 : selected;
|
|
1841
2517
|
}
|
|
1842
2518
|
|
|
1843
2519
|
// src/enumOptionsIsSelected.ts
|
|
1844
|
-
import isEqual5 from "lodash/isEqual";
|
|
1845
2520
|
function enumOptionsIsSelected(value, selected) {
|
|
1846
2521
|
if (Array.isArray(selected)) {
|
|
1847
|
-
return selected.some((sel) =>
|
|
2522
|
+
return selected.some((sel) => deepEquals(sel, value));
|
|
1848
2523
|
}
|
|
1849
|
-
return
|
|
2524
|
+
return deepEquals(selected, value);
|
|
1850
2525
|
}
|
|
1851
2526
|
|
|
1852
2527
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1859,10 +2534,10 @@ function enumOptionsIndexForValue(value, allEnumOptions = [], multiple = false)
|
|
|
1859
2534
|
}
|
|
1860
2535
|
|
|
1861
2536
|
// src/enumOptionsSelectValue.ts
|
|
1862
|
-
import
|
|
2537
|
+
import isNil2 from "lodash/isNil";
|
|
1863
2538
|
function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1864
2539
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1865
|
-
if (!
|
|
2540
|
+
if (!isNil2(value)) {
|
|
1866
2541
|
const index = allEnumOptions.findIndex((opt) => value === opt.value);
|
|
1867
2542
|
const all = allEnumOptions.map(({ value: val }) => val);
|
|
1868
2543
|
const updated = selected.slice(0, index).concat(value, selected.slice(index));
|
|
@@ -1873,8 +2548,9 @@ function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
|
1873
2548
|
|
|
1874
2549
|
// src/ErrorSchemaBuilder.ts
|
|
1875
2550
|
import cloneDeep from "lodash/cloneDeep";
|
|
1876
|
-
import
|
|
2551
|
+
import get16 from "lodash/get";
|
|
1877
2552
|
import set3 from "lodash/set";
|
|
2553
|
+
import setWith from "lodash/setWith";
|
|
1878
2554
|
var ErrorSchemaBuilder = class {
|
|
1879
2555
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
1880
2556
|
*
|
|
@@ -1901,10 +2577,10 @@ var ErrorSchemaBuilder = class {
|
|
|
1901
2577
|
*/
|
|
1902
2578
|
getOrCreateErrorBlock(pathOfError) {
|
|
1903
2579
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
1904
|
-
let errorBlock = hasPath ?
|
|
2580
|
+
let errorBlock = hasPath ? get16(this.errorSchema, pathOfError) : this.errorSchema;
|
|
1905
2581
|
if (!errorBlock && pathOfError) {
|
|
1906
2582
|
errorBlock = {};
|
|
1907
|
-
|
|
2583
|
+
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
1908
2584
|
}
|
|
1909
2585
|
return errorBlock;
|
|
1910
2586
|
}
|
|
@@ -1927,15 +2603,15 @@ var ErrorSchemaBuilder = class {
|
|
|
1927
2603
|
*/
|
|
1928
2604
|
addErrors(errorOrList, pathOfError) {
|
|
1929
2605
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1930
|
-
let errorsList =
|
|
2606
|
+
let errorsList = get16(errorBlock, ERRORS_KEY);
|
|
1931
2607
|
if (!Array.isArray(errorsList)) {
|
|
1932
2608
|
errorsList = [];
|
|
1933
2609
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
1934
2610
|
}
|
|
1935
2611
|
if (Array.isArray(errorOrList)) {
|
|
1936
|
-
|
|
2612
|
+
set3(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, ...errorOrList])]);
|
|
1937
2613
|
} else {
|
|
1938
|
-
errorsList
|
|
2614
|
+
set3(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, errorOrList])]);
|
|
1939
2615
|
}
|
|
1940
2616
|
return this;
|
|
1941
2617
|
}
|
|
@@ -1949,7 +2625,7 @@ var ErrorSchemaBuilder = class {
|
|
|
1949
2625
|
*/
|
|
1950
2626
|
setErrors(errorOrList, pathOfError) {
|
|
1951
2627
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1952
|
-
const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
|
|
2628
|
+
const listToAdd = Array.isArray(errorOrList) ? [.../* @__PURE__ */ new Set([...errorOrList])] : [errorOrList];
|
|
1953
2629
|
set3(errorBlock, ERRORS_KEY, listToAdd);
|
|
1954
2630
|
return this;
|
|
1955
2631
|
}
|
|
@@ -2034,6 +2710,9 @@ function getInputProps(schema, defaultType, options = {}, autoDefaultStepAny = t
|
|
|
2034
2710
|
if (options.autocomplete) {
|
|
2035
2711
|
inputProps.autoComplete = options.autocomplete;
|
|
2036
2712
|
}
|
|
2713
|
+
if (options.accept) {
|
|
2714
|
+
inputProps.accept = options.accept;
|
|
2715
|
+
}
|
|
2037
2716
|
return inputProps;
|
|
2038
2717
|
}
|
|
2039
2718
|
|
|
@@ -2060,6 +2739,10 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2060
2739
|
if (name === "ButtonTemplates") {
|
|
2061
2740
|
return templates[name];
|
|
2062
2741
|
}
|
|
2742
|
+
if (Object.hasOwn(uiOptions, name) && typeof uiOptions[name] === "string" && Object.hasOwn(templates, uiOptions[name])) {
|
|
2743
|
+
const key = uiOptions[name];
|
|
2744
|
+
return templates[key];
|
|
2745
|
+
}
|
|
2063
2746
|
return (
|
|
2064
2747
|
// Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
|
|
2065
2748
|
// To avoid that, we cast uiOptions to `any` before accessing the name field
|
|
@@ -2067,10 +2750,31 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
2067
2750
|
);
|
|
2068
2751
|
}
|
|
2069
2752
|
|
|
2753
|
+
// src/getTestIds.ts
|
|
2754
|
+
import { nanoid } from "nanoid";
|
|
2755
|
+
import get17 from "lodash/get";
|
|
2756
|
+
function getTestIds() {
|
|
2757
|
+
if (typeof process === "undefined" || get17(process, "env.NODE_ENV") !== "test") {
|
|
2758
|
+
return {};
|
|
2759
|
+
}
|
|
2760
|
+
const ids = /* @__PURE__ */ new Map();
|
|
2761
|
+
return new Proxy(
|
|
2762
|
+
{},
|
|
2763
|
+
{
|
|
2764
|
+
get(_obj, prop) {
|
|
2765
|
+
if (!ids.has(prop)) {
|
|
2766
|
+
ids.set(prop, nanoid());
|
|
2767
|
+
}
|
|
2768
|
+
return ids.get(prop);
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
);
|
|
2772
|
+
}
|
|
2773
|
+
|
|
2070
2774
|
// src/getWidget.tsx
|
|
2071
2775
|
import { createElement } from "react";
|
|
2072
2776
|
import ReactIs from "react-is";
|
|
2073
|
-
import
|
|
2777
|
+
import get18 from "lodash/get";
|
|
2074
2778
|
import set4 from "lodash/set";
|
|
2075
2779
|
import { jsx } from "react/jsx-runtime";
|
|
2076
2780
|
var widgetMap = {
|
|
@@ -2126,7 +2830,7 @@ var widgetMap = {
|
|
|
2126
2830
|
}
|
|
2127
2831
|
};
|
|
2128
2832
|
function mergeWidgetOptions(AWidget) {
|
|
2129
|
-
let MergedWidget =
|
|
2833
|
+
let MergedWidget = get18(AWidget, "MergedWidget");
|
|
2130
2834
|
if (!MergedWidget) {
|
|
2131
2835
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2132
2836
|
MergedWidget = ({ options, ...props }) => {
|
|
@@ -2170,10 +2874,16 @@ function hashString(string) {
|
|
|
2170
2874
|
}
|
|
2171
2875
|
return hash.toString(16);
|
|
2172
2876
|
}
|
|
2173
|
-
function
|
|
2877
|
+
function sortedJSONStringify(object) {
|
|
2174
2878
|
const allKeys = /* @__PURE__ */ new Set();
|
|
2175
|
-
JSON.stringify(
|
|
2176
|
-
return
|
|
2879
|
+
JSON.stringify(object, (key, value) => (allKeys.add(key), value));
|
|
2880
|
+
return JSON.stringify(object, Array.from(allKeys).sort());
|
|
2881
|
+
}
|
|
2882
|
+
function hashObject(object) {
|
|
2883
|
+
return hashString(sortedJSONStringify(object));
|
|
2884
|
+
}
|
|
2885
|
+
function hashForSchema(schema) {
|
|
2886
|
+
return hashObject(schema);
|
|
2177
2887
|
}
|
|
2178
2888
|
|
|
2179
2889
|
// src/hasWidget.ts
|
|
@@ -2191,9 +2901,9 @@ function hasWidget(schema, widget, registeredWidgets = {}) {
|
|
|
2191
2901
|
}
|
|
2192
2902
|
|
|
2193
2903
|
// src/idGenerators.ts
|
|
2194
|
-
import
|
|
2904
|
+
import isString4 from "lodash/isString";
|
|
2195
2905
|
function idGenerator(id, suffix) {
|
|
2196
|
-
const theId =
|
|
2906
|
+
const theId = isString4(id) ? id : id[ID_KEY];
|
|
2197
2907
|
return `${theId}__${suffix}`;
|
|
2198
2908
|
}
|
|
2199
2909
|
function descriptionId(id) {
|
|
@@ -2218,6 +2928,9 @@ function ariaDescribedByIds(id, includeExamples = false) {
|
|
|
2218
2928
|
function optionId(id, optionIndex) {
|
|
2219
2929
|
return `${id}-${optionIndex}`;
|
|
2220
2930
|
}
|
|
2931
|
+
function buttonId(id, btn) {
|
|
2932
|
+
return idGenerator(id, btn);
|
|
2933
|
+
}
|
|
2221
2934
|
|
|
2222
2935
|
// src/labelValue.ts
|
|
2223
2936
|
function labelValue(label, hideLabel, fallback) {
|
|
@@ -2229,59 +2942,15 @@ function localToUTC(dateString) {
|
|
|
2229
2942
|
return dateString ? new Date(dateString).toJSON() : void 0;
|
|
2230
2943
|
}
|
|
2231
2944
|
|
|
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;
|
|
2945
|
+
// src/lookupFromFormContext.ts
|
|
2946
|
+
import get19 from "lodash/get";
|
|
2947
|
+
import has6 from "lodash/has";
|
|
2948
|
+
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
2949
|
+
const lookupPath = [LOOKUP_MAP_NAME];
|
|
2950
|
+
if (has6(regOrFc, FORM_CONTEXT_NAME)) {
|
|
2951
|
+
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2273
2952
|
}
|
|
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
|
-
});
|
|
2953
|
+
return get19(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2285
2954
|
}
|
|
2286
2955
|
|
|
2287
2956
|
// src/orderProperties.ts
|
|
@@ -2460,7 +3129,7 @@ function utcToLocal(jsonDate) {
|
|
|
2460
3129
|
}
|
|
2461
3130
|
|
|
2462
3131
|
// src/validationDataMerge.ts
|
|
2463
|
-
import
|
|
3132
|
+
import isEmpty5 from "lodash/isEmpty";
|
|
2464
3133
|
function validationDataMerge(validationData, additionalErrorSchema) {
|
|
2465
3134
|
if (!additionalErrorSchema) {
|
|
2466
3135
|
return validationData;
|
|
@@ -2468,7 +3137,7 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
2468
3137
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
2469
3138
|
let errors = toErrorList(additionalErrorSchema);
|
|
2470
3139
|
let errorSchema = additionalErrorSchema;
|
|
2471
|
-
if (!
|
|
3140
|
+
if (!isEmpty5(oldErrorSchema)) {
|
|
2472
3141
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
2473
3142
|
errors = [...oldErrors].concat(errors);
|
|
2474
3143
|
}
|
|
@@ -2476,7 +3145,7 @@ function validationDataMerge(validationData, additionalErrorSchema) {
|
|
|
2476
3145
|
}
|
|
2477
3146
|
|
|
2478
3147
|
// src/withIdRefPrefix.ts
|
|
2479
|
-
import
|
|
3148
|
+
import isObject4 from "lodash/isObject";
|
|
2480
3149
|
function withIdRefPrefixObject(node) {
|
|
2481
3150
|
for (const key in node) {
|
|
2482
3151
|
const realObj = node;
|
|
@@ -2499,16 +3168,40 @@ function withIdRefPrefix(schemaNode) {
|
|
|
2499
3168
|
if (Array.isArray(schemaNode)) {
|
|
2500
3169
|
return withIdRefPrefixArray([...schemaNode]);
|
|
2501
3170
|
}
|
|
2502
|
-
if (
|
|
3171
|
+
if (isObject4(schemaNode)) {
|
|
2503
3172
|
return withIdRefPrefixObject({ ...schemaNode });
|
|
2504
3173
|
}
|
|
2505
3174
|
return schemaNode;
|
|
2506
3175
|
}
|
|
2507
3176
|
|
|
3177
|
+
// src/getChangedFields.ts
|
|
3178
|
+
import keys from "lodash/keys";
|
|
3179
|
+
import pickBy from "lodash/pickBy";
|
|
3180
|
+
import isPlainObject4 from "lodash/isPlainObject";
|
|
3181
|
+
import get20 from "lodash/get";
|
|
3182
|
+
import difference from "lodash/difference";
|
|
3183
|
+
function getChangedFields(a, b) {
|
|
3184
|
+
const aIsPlainObject = isPlainObject4(a);
|
|
3185
|
+
const bIsPlainObject = isPlainObject4(b);
|
|
3186
|
+
if (a === b || !aIsPlainObject && !bIsPlainObject) {
|
|
3187
|
+
return [];
|
|
3188
|
+
}
|
|
3189
|
+
if (aIsPlainObject && !bIsPlainObject) {
|
|
3190
|
+
return keys(a);
|
|
3191
|
+
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3192
|
+
return keys(b);
|
|
3193
|
+
} else {
|
|
3194
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get20(b, key))));
|
|
3195
|
+
const diffFields = difference(keys(b), keys(a));
|
|
3196
|
+
return [...unequalFields, ...diffFields];
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
|
|
2508
3200
|
// src/enums.ts
|
|
2509
3201
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
2510
3202
|
TranslatableString2["ArrayItemTitle"] = "Item";
|
|
2511
3203
|
TranslatableString2["MissingItems"] = "Missing items definition";
|
|
3204
|
+
TranslatableString2["EmptyArray"] = "No items yet. Use the button below to add some.";
|
|
2512
3205
|
TranslatableString2["YesLabel"] = "Yes";
|
|
2513
3206
|
TranslatableString2["NoLabel"] = "No";
|
|
2514
3207
|
TranslatableString2["CloseLabel"] = "Close";
|
|
@@ -2541,11 +3234,9 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
2541
3234
|
|
|
2542
3235
|
// src/parser/schemaParser.ts
|
|
2543
3236
|
import forEach from "lodash/forEach";
|
|
2544
|
-
import isEqual7 from "lodash/isEqual";
|
|
2545
3237
|
|
|
2546
3238
|
// src/parser/ParserValidator.ts
|
|
2547
|
-
import
|
|
2548
|
-
import isEqual6 from "lodash/isEqual";
|
|
3239
|
+
import get21 from "lodash/get";
|
|
2549
3240
|
var ParserValidator = class {
|
|
2550
3241
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
2551
3242
|
* first.
|
|
@@ -2571,12 +3262,12 @@ var ParserValidator = class {
|
|
|
2571
3262
|
* @param hash - The hash value at which to map the schema
|
|
2572
3263
|
*/
|
|
2573
3264
|
addSchema(schema, hash) {
|
|
2574
|
-
const key =
|
|
3265
|
+
const key = get21(schema, ID_KEY, hash);
|
|
2575
3266
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2576
3267
|
const existing = this.schemaMap[key];
|
|
2577
3268
|
if (!existing) {
|
|
2578
3269
|
this.schemaMap[key] = identifiedSchema;
|
|
2579
|
-
} else if (!
|
|
3270
|
+
} else if (!deepEquals(existing, identifiedSchema)) {
|
|
2580
3271
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2581
3272
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2582
3273
|
throw new Error(
|
|
@@ -2598,7 +3289,7 @@ var ParserValidator = class {
|
|
|
2598
3289
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2599
3290
|
*/
|
|
2600
3291
|
isValid(schema, _formData, rootSchema) {
|
|
2601
|
-
if (!
|
|
3292
|
+
if (!deepEquals(rootSchema, this.rootSchema)) {
|
|
2602
3293
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2603
3294
|
}
|
|
2604
3295
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2638,7 +3329,7 @@ var ParserValidator = class {
|
|
|
2638
3329
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2639
3330
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
2640
3331
|
schemas.forEach((schema2) => {
|
|
2641
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
3332
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, schema2));
|
|
2642
3333
|
if (sameSchemaIndex === -1) {
|
|
2643
3334
|
recurseList.push(schema2);
|
|
2644
3335
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
@@ -2670,21 +3361,27 @@ export {
|
|
|
2670
3361
|
DEFAULT_KEY,
|
|
2671
3362
|
DEFINITIONS_KEY,
|
|
2672
3363
|
DEPENDENCIES_KEY,
|
|
3364
|
+
DISCRIMINATOR_PATH,
|
|
2673
3365
|
ENUM_KEY,
|
|
2674
3366
|
ERRORS_KEY,
|
|
2675
3367
|
ErrorSchemaBuilder,
|
|
3368
|
+
FORM_CONTEXT_NAME,
|
|
2676
3369
|
ID_KEY,
|
|
2677
3370
|
IF_KEY,
|
|
2678
3371
|
ITEMS_KEY,
|
|
3372
|
+
JSON_SCHEMA_DRAFT_2020_12,
|
|
2679
3373
|
JUNK_OPTION_ID,
|
|
3374
|
+
LOOKUP_MAP_NAME,
|
|
2680
3375
|
NAME_KEY,
|
|
2681
3376
|
ONE_OF_KEY,
|
|
3377
|
+
PATTERN_PROPERTIES_KEY,
|
|
2682
3378
|
PROPERTIES_KEY,
|
|
3379
|
+
READONLY_KEY,
|
|
2683
3380
|
REF_KEY,
|
|
2684
3381
|
REQUIRED_KEY,
|
|
2685
3382
|
RJSF_ADDITIONAL_PROPERTIES_FLAG,
|
|
2686
|
-
RJSF_ADDITONAL_PROPERTIES_FLAG,
|
|
2687
3383
|
ROOT_SCHEMA_PREFIX,
|
|
3384
|
+
SCHEMA_KEY,
|
|
2688
3385
|
SUBMIT_BTN_OPTIONS_KEY,
|
|
2689
3386
|
TranslatableString,
|
|
2690
3387
|
UI_FIELD_KEY,
|
|
@@ -2694,6 +3391,7 @@ export {
|
|
|
2694
3391
|
allowAdditionalItems,
|
|
2695
3392
|
ariaDescribedByIds,
|
|
2696
3393
|
asNumber,
|
|
3394
|
+
buttonId,
|
|
2697
3395
|
canExpand,
|
|
2698
3396
|
createErrorHandler,
|
|
2699
3397
|
createSchemaUtils,
|
|
@@ -2709,24 +3407,30 @@ export {
|
|
|
2709
3407
|
enumOptionsValueForIndex,
|
|
2710
3408
|
errorId,
|
|
2711
3409
|
examplesId,
|
|
3410
|
+
findFieldInSchema,
|
|
2712
3411
|
findSchemaDefinition,
|
|
3412
|
+
findSelectedOptionInXxxOf,
|
|
3413
|
+
getChangedFields,
|
|
2713
3414
|
getClosestMatchingOption,
|
|
2714
3415
|
getDateElementProps,
|
|
2715
3416
|
getDefaultFormState,
|
|
2716
3417
|
getDiscriminatorFieldFromSchema,
|
|
2717
3418
|
getDisplayLabel,
|
|
2718
3419
|
getFirstMatchingOption,
|
|
3420
|
+
getFromSchema,
|
|
2719
3421
|
getInputProps,
|
|
2720
|
-
getMatchingOption,
|
|
2721
3422
|
getOptionMatchingSimpleDiscriminator,
|
|
2722
3423
|
getSchemaType,
|
|
2723
3424
|
getSubmitButtonOptions,
|
|
2724
3425
|
getTemplate,
|
|
3426
|
+
getTestIds,
|
|
2725
3427
|
getUiOptions,
|
|
2726
3428
|
getWidget,
|
|
2727
3429
|
guessType,
|
|
2728
3430
|
hasWidget,
|
|
2729
3431
|
hashForSchema,
|
|
3432
|
+
hashObject,
|
|
3433
|
+
hashString,
|
|
2730
3434
|
helpId,
|
|
2731
3435
|
isConstant,
|
|
2732
3436
|
isCustomWidget,
|
|
@@ -2737,10 +3441,10 @@ export {
|
|
|
2737
3441
|
isSelect,
|
|
2738
3442
|
labelValue,
|
|
2739
3443
|
localToUTC,
|
|
3444
|
+
lookupFromFormContext,
|
|
2740
3445
|
mergeDefaultsWithFormData,
|
|
2741
3446
|
mergeObjects,
|
|
2742
3447
|
mergeSchemas,
|
|
2743
|
-
mergeValidationData,
|
|
2744
3448
|
optionId,
|
|
2745
3449
|
optionsList,
|
|
2746
3450
|
orderProperties,
|
|
@@ -2753,6 +3457,7 @@ export {
|
|
|
2753
3457
|
schemaParser,
|
|
2754
3458
|
schemaRequiresTrueValue,
|
|
2755
3459
|
shouldRender,
|
|
3460
|
+
sortedJSONStringify,
|
|
2756
3461
|
titleId,
|
|
2757
3462
|
toConstant,
|
|
2758
3463
|
toDateString,
|