@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.umd.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash/isPlainObject'), require('lodash/isEqualWith'), require('lodash/get'), require('lodash/
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'lodash/isPlainObject', 'lodash/isEqualWith', 'lodash/get', 'lodash/
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.
|
|
5
|
-
})(this, (function (exports,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash/isPlainObject'), require('lodash/isEqualWith'), require('lodash/get'), require('lodash/has'), require('lodash/isEqual'), require('lodash/set'), require('lodash/times'), require('lodash/transform'), require('lodash/merge'), require('lodash/flattenDeep'), require('lodash/uniq'), require('json-schema-merge-allof'), require('jsonpointer'), require('lodash/omit'), require('lodash/isObject'), require('lodash/isEmpty'), require('fast-uri'), require('lodash/isString'), require('lodash/union'), require('lodash/isNumber'), require('lodash/reduce'), require('lodash/isNil'), require('lodash/cloneDeep'), require('lodash/setWith'), require('nanoid'), require('react'), require('react-is'), require('react/jsx-runtime'), require('lodash/toPath'), require('lodash/keys'), require('lodash/pickBy'), require('lodash/difference'), require('lodash/forEach')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'lodash/isPlainObject', 'lodash/isEqualWith', 'lodash/get', 'lodash/has', 'lodash/isEqual', 'lodash/set', 'lodash/times', 'lodash/transform', 'lodash/merge', 'lodash/flattenDeep', 'lodash/uniq', 'json-schema-merge-allof', 'jsonpointer', 'lodash/omit', 'lodash/isObject', 'lodash/isEmpty', 'fast-uri', 'lodash/isString', 'lodash/union', 'lodash/isNumber', 'lodash/reduce', 'lodash/isNil', 'lodash/cloneDeep', 'lodash/setWith', 'nanoid', 'react', 'react-is', 'react/jsx-runtime', 'lodash/toPath', 'lodash/keys', 'lodash/pickBy', 'lodash/difference', 'lodash/forEach'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/utils"] = {}, global.isPlainObject4, global.isEqualWith, global.get13, global.has5, global.isEqual, global.set, global.times, global.transform, global.merge, global.flattenDeep, global.uniq, global.mergeAllOf, global.jsonpointer, global.omit, global.isObject3, global.isEmpty2, global.UriResolver, global.isString, global.union, global.isNumber, global.reduce, global.isNil, global.cloneDeep, global.setWith, global.nanoid, global.react, global.ReactIs, global.jsxRuntime, global.toPath, global.keys, global.pickBy, global.difference, global.forEach));
|
|
5
|
+
})(this, (function (exports, isPlainObject4, isEqualWith, get13, has5, isEqual, set, times, transform, merge, flattenDeep, uniq, mergeAllOf, jsonpointer, omit, isObject3, isEmpty2, UriResolver, isString, union, isNumber, reduce, isNil, cloneDeep, setWith, nanoid, react, ReactIs, jsxRuntime, toPath, keys, pickBy, difference, forEach) { 'use strict';
|
|
6
6
|
|
|
7
7
|
// src/isObject.ts
|
|
8
8
|
function isObject(thing) {
|
|
9
|
-
if (typeof
|
|
9
|
+
if (typeof thing !== "object" || thing === null) {
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
|
-
if (typeof
|
|
12
|
+
if (typeof thing.lastModified === "number" && typeof File !== "undefined" && thing instanceof File) {
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
if (typeof thing.getMonth === "function" && typeof Date !== "undefined" && thing instanceof Date) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return !Array.isArray(thing);
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
// src/allowAdditionalItems.ts
|
|
@@ -62,17 +65,23 @@
|
|
|
62
65
|
var JUNK_OPTION_ID = "_$junk_option_schema_id$_";
|
|
63
66
|
var NAME_KEY = "$name";
|
|
64
67
|
var ONE_OF_KEY = "oneOf";
|
|
68
|
+
var PATTERN_PROPERTIES_KEY = "patternProperties";
|
|
65
69
|
var PROPERTIES_KEY = "properties";
|
|
70
|
+
var READONLY_KEY = "readonly";
|
|
66
71
|
var REQUIRED_KEY = "required";
|
|
67
72
|
var SUBMIT_BTN_OPTIONS_KEY = "submitButtonOptions";
|
|
68
73
|
var REF_KEY = "$ref";
|
|
69
|
-
var
|
|
74
|
+
var SCHEMA_KEY = "$schema";
|
|
75
|
+
var DISCRIMINATOR_PATH = ["discriminator", "propertyName"];
|
|
76
|
+
var FORM_CONTEXT_NAME = "formContext";
|
|
77
|
+
var LOOKUP_MAP_NAME = "layoutGridLookupMap";
|
|
70
78
|
var RJSF_ADDITIONAL_PROPERTIES_FLAG = "__rjsf_additionalProperties";
|
|
71
79
|
var ROOT_SCHEMA_PREFIX = "__rjsf_rootSchema";
|
|
72
80
|
var UI_FIELD_KEY = "ui:field";
|
|
73
81
|
var UI_WIDGET_KEY = "ui:widget";
|
|
74
82
|
var UI_OPTIONS_KEY = "ui:options";
|
|
75
83
|
var UI_GLOBAL_OPTIONS_KEY = "ui:globalOptions";
|
|
84
|
+
var JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
76
85
|
|
|
77
86
|
// src/getUiOptions.ts
|
|
78
87
|
function getUiOptions(uiSchema = {}, globalOptions = {}) {
|
|
@@ -94,7 +103,7 @@
|
|
|
94
103
|
|
|
95
104
|
// src/canExpand.ts
|
|
96
105
|
function canExpand(schema, uiSchema = {}, formData) {
|
|
97
|
-
if (!schema.additionalProperties) {
|
|
106
|
+
if (!(schema.additionalProperties || schema.patternProperties)) {
|
|
98
107
|
return false;
|
|
99
108
|
}
|
|
100
109
|
const { expandable = true } = getUiOptions(uiSchema);
|
|
@@ -121,7 +130,7 @@
|
|
|
121
130
|
return { ...acc, [key]: createErrorHandler(value) };
|
|
122
131
|
}, handler);
|
|
123
132
|
}
|
|
124
|
-
if (
|
|
133
|
+
if (isPlainObject4(formData)) {
|
|
125
134
|
const formObject = formData;
|
|
126
135
|
return Object.keys(formObject).reduce((acc, key) => {
|
|
127
136
|
return { ...acc, [key]: createErrorHandler(formObject[key]) };
|
|
@@ -137,20 +146,49 @@
|
|
|
137
146
|
return void 0;
|
|
138
147
|
});
|
|
139
148
|
}
|
|
149
|
+
function findEmbeddedSchemaRecursive(schema, ref) {
|
|
150
|
+
if (ID_KEY in schema && UriResolver.equal(schema[ID_KEY], ref)) {
|
|
151
|
+
return schema;
|
|
152
|
+
}
|
|
153
|
+
for (const subSchema of Object.values(schema)) {
|
|
154
|
+
if (isObject3(subSchema)) {
|
|
155
|
+
const result = findEmbeddedSchemaRecursive(subSchema, ref);
|
|
156
|
+
if (result !== void 0) {
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return void 0;
|
|
162
|
+
}
|
|
140
163
|
function splitKeyElementFromObject(key, object) {
|
|
141
164
|
const value = object[key];
|
|
142
165
|
const remaining = omit(object, [key]);
|
|
143
166
|
return [remaining, value];
|
|
144
167
|
}
|
|
145
|
-
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = []) {
|
|
168
|
+
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [], baseURI = get13(rootSchema, [ID_KEY])) {
|
|
146
169
|
const ref = $ref || "";
|
|
147
|
-
let
|
|
170
|
+
let current = void 0;
|
|
148
171
|
if (ref.startsWith("#")) {
|
|
149
|
-
decodedRef = decodeURIComponent(ref.substring(1));
|
|
150
|
-
|
|
151
|
-
|
|
172
|
+
const decodedRef = decodeURIComponent(ref.substring(1));
|
|
173
|
+
if (baseURI === void 0 || ID_KEY in rootSchema && rootSchema[ID_KEY] === baseURI) {
|
|
174
|
+
current = jsonpointer.get(rootSchema, decodedRef);
|
|
175
|
+
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
176
|
+
current = findEmbeddedSchemaRecursive(rootSchema, baseURI.replace(/\/$/, ""));
|
|
177
|
+
if (current !== void 0) {
|
|
178
|
+
current = jsonpointer.get(current, decodedRef);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
182
|
+
const resolvedRef = baseURI ? UriResolver.resolve(baseURI, ref) : ref;
|
|
183
|
+
const [refId, ...refAnchor] = resolvedRef.replace(/#\/?$/, "").split("#");
|
|
184
|
+
current = findEmbeddedSchemaRecursive(rootSchema, refId.replace(/\/$/, ""));
|
|
185
|
+
if (current !== void 0) {
|
|
186
|
+
baseURI = current[ID_KEY];
|
|
187
|
+
if (!isEmpty2(refAnchor)) {
|
|
188
|
+
current = jsonpointer.get(current, decodeURIComponent(refAnchor.join("#")));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
152
191
|
}
|
|
153
|
-
const current = jsonpointer.get(rootSchema, decodedRef);
|
|
154
192
|
if (current === void 0) {
|
|
155
193
|
throw new Error(`Could not find a definition for ${$ref}.`);
|
|
156
194
|
}
|
|
@@ -165,7 +203,7 @@
|
|
|
165
203
|
throw new Error(`Definition for ${firstRef} contains a circular reference through ${circularPath}`);
|
|
166
204
|
}
|
|
167
205
|
const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
|
|
168
|
-
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref]);
|
|
206
|
+
const subSchema = findSchemaDefinitionRecursive(theRef, rootSchema, [...recurseList, ref], baseURI);
|
|
169
207
|
if (Object.keys(remaining).length > 0) {
|
|
170
208
|
return { ...remaining, ...subSchema };
|
|
171
209
|
}
|
|
@@ -173,87 +211,13 @@
|
|
|
173
211
|
}
|
|
174
212
|
return current;
|
|
175
213
|
}
|
|
176
|
-
function findSchemaDefinition($ref, rootSchema = {}) {
|
|
214
|
+
function findSchemaDefinition($ref, rootSchema = {}, baseURI = get13(rootSchema, [ID_KEY])) {
|
|
177
215
|
const recurseList = [];
|
|
178
|
-
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList);
|
|
179
|
-
}
|
|
180
|
-
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
181
|
-
if (formData && discriminatorField) {
|
|
182
|
-
const value = get8(formData, discriminatorField);
|
|
183
|
-
if (value === void 0) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
for (let i = 0; i < options.length; i++) {
|
|
187
|
-
const option = options[i];
|
|
188
|
-
const discriminator = get8(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
189
|
-
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
if (discriminator.const === value) {
|
|
193
|
-
return i;
|
|
194
|
-
}
|
|
195
|
-
if (discriminator.enum?.includes(value)) {
|
|
196
|
-
return i;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// src/schema/getMatchingOption.ts
|
|
204
|
-
function getMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
205
|
-
if (formData === void 0) {
|
|
206
|
-
return 0;
|
|
207
|
-
}
|
|
208
|
-
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
209
|
-
if (isNumber(simpleDiscriminatorMatch)) {
|
|
210
|
-
return simpleDiscriminatorMatch;
|
|
211
|
-
}
|
|
212
|
-
for (let i = 0; i < options.length; i++) {
|
|
213
|
-
const option = options[i];
|
|
214
|
-
if (discriminatorField && has3(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
215
|
-
const value = get8(formData, discriminatorField);
|
|
216
|
-
const discriminator = get8(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
217
|
-
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
218
|
-
return i;
|
|
219
|
-
}
|
|
220
|
-
} else if (option[PROPERTIES_KEY]) {
|
|
221
|
-
const requiresAnyOf = {
|
|
222
|
-
anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
|
|
223
|
-
required: [key]
|
|
224
|
-
}))
|
|
225
|
-
};
|
|
226
|
-
let augmentedSchema;
|
|
227
|
-
if (option.anyOf) {
|
|
228
|
-
const { ...shallowClone } = option;
|
|
229
|
-
if (!shallowClone.allOf) {
|
|
230
|
-
shallowClone.allOf = [];
|
|
231
|
-
} else {
|
|
232
|
-
shallowClone.allOf = shallowClone.allOf.slice();
|
|
233
|
-
}
|
|
234
|
-
shallowClone.allOf.push(requiresAnyOf);
|
|
235
|
-
augmentedSchema = shallowClone;
|
|
236
|
-
} else {
|
|
237
|
-
augmentedSchema = Object.assign({}, option, requiresAnyOf);
|
|
238
|
-
}
|
|
239
|
-
delete augmentedSchema.required;
|
|
240
|
-
if (validator.isValid(augmentedSchema, formData, rootSchema)) {
|
|
241
|
-
return i;
|
|
242
|
-
}
|
|
243
|
-
} else if (validator.isValid(option, formData, rootSchema)) {
|
|
244
|
-
return i;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return 0;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// src/schema/getFirstMatchingOption.ts
|
|
251
|
-
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
252
|
-
return getMatchingOption(validator, formData, options, rootSchema, discriminatorField);
|
|
216
|
+
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList, baseURI);
|
|
253
217
|
}
|
|
254
218
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
255
219
|
let discriminator;
|
|
256
|
-
const maybeString =
|
|
220
|
+
const maybeString = get13(schema, DISCRIMINATOR_PATH);
|
|
257
221
|
if (isString(maybeString)) {
|
|
258
222
|
discriminator = maybeString;
|
|
259
223
|
} else if (maybeString !== void 0) {
|
|
@@ -294,7 +258,7 @@
|
|
|
294
258
|
if (!type && schema.enum) {
|
|
295
259
|
return "string";
|
|
296
260
|
}
|
|
297
|
-
if (!type && (schema.properties || schema.additionalProperties)) {
|
|
261
|
+
if (!type && (schema.properties || schema.additionalProperties || schema.patternProperties)) {
|
|
298
262
|
return "object";
|
|
299
263
|
}
|
|
300
264
|
if (Array.isArray(type)) {
|
|
@@ -322,12 +286,87 @@
|
|
|
322
286
|
return acc2;
|
|
323
287
|
}, acc);
|
|
324
288
|
}
|
|
289
|
+
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
290
|
+
if (formData && discriminatorField) {
|
|
291
|
+
const value = get13(formData, discriminatorField);
|
|
292
|
+
if (value === void 0) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
for (let i = 0; i < options.length; i++) {
|
|
296
|
+
const option = options[i];
|
|
297
|
+
const discriminator = get13(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
298
|
+
if (discriminator.type === "object" || discriminator.type === "array") {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (discriminator.const === value) {
|
|
302
|
+
return i;
|
|
303
|
+
}
|
|
304
|
+
if (discriminator.enum?.includes(value)) {
|
|
305
|
+
return i;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
325
311
|
|
|
326
|
-
// src/schema/
|
|
327
|
-
function
|
|
328
|
-
|
|
312
|
+
// src/schema/getFirstMatchingOption.ts
|
|
313
|
+
function getFirstMatchingOption(validator, formData, options, rootSchema, discriminatorField) {
|
|
314
|
+
if (formData === void 0) {
|
|
315
|
+
return 0;
|
|
316
|
+
}
|
|
317
|
+
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
318
|
+
if (isNumber(simpleDiscriminatorMatch)) {
|
|
319
|
+
return simpleDiscriminatorMatch;
|
|
320
|
+
}
|
|
321
|
+
for (let i = 0; i < options.length; i++) {
|
|
322
|
+
const option = options[i];
|
|
323
|
+
if (discriminatorField && has5(option, [PROPERTIES_KEY, discriminatorField])) {
|
|
324
|
+
const value = get13(formData, discriminatorField);
|
|
325
|
+
const discriminator = get13(option, [PROPERTIES_KEY, discriminatorField], {});
|
|
326
|
+
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
327
|
+
return i;
|
|
328
|
+
}
|
|
329
|
+
} else if (option[PROPERTIES_KEY]) {
|
|
330
|
+
const requiresAnyOf = {
|
|
331
|
+
anyOf: Object.keys(option[PROPERTIES_KEY]).map((key) => ({
|
|
332
|
+
required: [key]
|
|
333
|
+
}))
|
|
334
|
+
};
|
|
335
|
+
let augmentedSchema;
|
|
336
|
+
if (option.anyOf) {
|
|
337
|
+
const { ...shallowClone } = option;
|
|
338
|
+
if (!shallowClone.allOf) {
|
|
339
|
+
shallowClone.allOf = [];
|
|
340
|
+
} else {
|
|
341
|
+
shallowClone.allOf = shallowClone.allOf.slice();
|
|
342
|
+
}
|
|
343
|
+
shallowClone.allOf.push(requiresAnyOf);
|
|
344
|
+
augmentedSchema = shallowClone;
|
|
345
|
+
} else {
|
|
346
|
+
augmentedSchema = Object.assign({}, option, requiresAnyOf);
|
|
347
|
+
}
|
|
348
|
+
delete augmentedSchema.required;
|
|
349
|
+
if (validator.isValid(augmentedSchema, formData, rootSchema)) {
|
|
350
|
+
return i;
|
|
351
|
+
}
|
|
352
|
+
} else if (validator.isValid(option, formData, rootSchema)) {
|
|
353
|
+
return i;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return 0;
|
|
329
357
|
}
|
|
330
|
-
function
|
|
358
|
+
function retrieveSchema(validator, schema, rootSchema = {}, rawFormData, experimental_customMergeAllOf) {
|
|
359
|
+
return retrieveSchemaInternal(
|
|
360
|
+
validator,
|
|
361
|
+
schema,
|
|
362
|
+
rootSchema,
|
|
363
|
+
rawFormData,
|
|
364
|
+
void 0,
|
|
365
|
+
void 0,
|
|
366
|
+
experimental_customMergeAllOf
|
|
367
|
+
)[0];
|
|
368
|
+
}
|
|
369
|
+
function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
331
370
|
const { if: expression, then, else: otherwise, ...resolvedSchemaLessConditional } = schema;
|
|
332
371
|
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
333
372
|
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
@@ -335,12 +374,28 @@
|
|
|
335
374
|
if (expandAllBranches) {
|
|
336
375
|
if (then && typeof then !== "boolean") {
|
|
337
376
|
schemas = schemas.concat(
|
|
338
|
-
retrieveSchemaInternal(
|
|
377
|
+
retrieveSchemaInternal(
|
|
378
|
+
validator,
|
|
379
|
+
then,
|
|
380
|
+
rootSchema,
|
|
381
|
+
formData,
|
|
382
|
+
expandAllBranches,
|
|
383
|
+
recurseList,
|
|
384
|
+
experimental_customMergeAllOf
|
|
385
|
+
)
|
|
339
386
|
);
|
|
340
387
|
}
|
|
341
388
|
if (otherwise && typeof otherwise !== "boolean") {
|
|
342
389
|
schemas = schemas.concat(
|
|
343
|
-
retrieveSchemaInternal(
|
|
390
|
+
retrieveSchemaInternal(
|
|
391
|
+
validator,
|
|
392
|
+
otherwise,
|
|
393
|
+
rootSchema,
|
|
394
|
+
formData,
|
|
395
|
+
expandAllBranches,
|
|
396
|
+
recurseList,
|
|
397
|
+
experimental_customMergeAllOf
|
|
398
|
+
)
|
|
344
399
|
);
|
|
345
400
|
}
|
|
346
401
|
} else {
|
|
@@ -353,7 +408,8 @@
|
|
|
353
408
|
rootSchema,
|
|
354
409
|
formData,
|
|
355
410
|
expandAllBranches,
|
|
356
|
-
recurseList
|
|
411
|
+
recurseList,
|
|
412
|
+
experimental_customMergeAllOf
|
|
357
413
|
)
|
|
358
414
|
);
|
|
359
415
|
}
|
|
@@ -362,7 +418,15 @@
|
|
|
362
418
|
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
363
419
|
}
|
|
364
420
|
return resolvedSchemas.flatMap(
|
|
365
|
-
(s) => retrieveSchemaInternal(
|
|
421
|
+
(s) => retrieveSchemaInternal(
|
|
422
|
+
validator,
|
|
423
|
+
s,
|
|
424
|
+
rootSchema,
|
|
425
|
+
formData,
|
|
426
|
+
expandAllBranches,
|
|
427
|
+
recurseList,
|
|
428
|
+
experimental_customMergeAllOf
|
|
429
|
+
)
|
|
366
430
|
);
|
|
367
431
|
}
|
|
368
432
|
function getAllPermutationsOfXxxOf(listOfLists) {
|
|
@@ -379,7 +443,16 @@
|
|
|
379
443
|
);
|
|
380
444
|
return allPermutations;
|
|
381
445
|
}
|
|
382
|
-
function
|
|
446
|
+
function getMatchingPatternProperties(schema, key) {
|
|
447
|
+
return Object.keys(schema.patternProperties).filter((pattern) => RegExp(pattern).test(key)).reduce(
|
|
448
|
+
(obj, pattern) => {
|
|
449
|
+
set(obj, [pattern], schema.patternProperties[pattern]);
|
|
450
|
+
return obj;
|
|
451
|
+
},
|
|
452
|
+
{}
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
383
456
|
const updatedSchemas = resolveReference(
|
|
384
457
|
validator,
|
|
385
458
|
schema,
|
|
@@ -401,7 +474,15 @@
|
|
|
401
474
|
formData
|
|
402
475
|
);
|
|
403
476
|
return resolvedSchemas.flatMap((s) => {
|
|
404
|
-
return retrieveSchemaInternal(
|
|
477
|
+
return retrieveSchemaInternal(
|
|
478
|
+
validator,
|
|
479
|
+
s,
|
|
480
|
+
rootSchema,
|
|
481
|
+
formData,
|
|
482
|
+
expandAllBranches,
|
|
483
|
+
recurseList,
|
|
484
|
+
experimental_customMergeAllOf
|
|
485
|
+
);
|
|
405
486
|
});
|
|
406
487
|
}
|
|
407
488
|
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
@@ -412,15 +493,19 @@
|
|
|
412
493
|
rootSchema,
|
|
413
494
|
formData,
|
|
414
495
|
expandAllBranches,
|
|
415
|
-
recurseList
|
|
496
|
+
recurseList,
|
|
497
|
+
experimental_customMergeAllOf
|
|
416
498
|
)
|
|
417
499
|
);
|
|
418
500
|
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
419
|
-
return allPermutations.map((permutation) => ({
|
|
501
|
+
return allPermutations.map((permutation) => ({
|
|
502
|
+
...schema,
|
|
503
|
+
allOf: permutation
|
|
504
|
+
}));
|
|
420
505
|
}
|
|
421
506
|
return [schema];
|
|
422
507
|
}
|
|
423
|
-
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
508
|
+
function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
424
509
|
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList);
|
|
425
510
|
if (updatedSchema !== schema) {
|
|
426
511
|
return retrieveSchemaInternal(
|
|
@@ -429,12 +514,13 @@
|
|
|
429
514
|
rootSchema,
|
|
430
515
|
formData,
|
|
431
516
|
expandAllBranches,
|
|
432
|
-
recurseList
|
|
517
|
+
recurseList,
|
|
518
|
+
experimental_customMergeAllOf
|
|
433
519
|
);
|
|
434
520
|
}
|
|
435
521
|
return [schema];
|
|
436
522
|
}
|
|
437
|
-
function resolveAllReferences(schema, rootSchema, recurseList) {
|
|
523
|
+
function resolveAllReferences(schema, rootSchema, recurseList, baseURI) {
|
|
438
524
|
if (!isObject(schema)) {
|
|
439
525
|
return schema;
|
|
440
526
|
}
|
|
@@ -445,8 +531,11 @@
|
|
|
445
531
|
return resolvedSchema;
|
|
446
532
|
}
|
|
447
533
|
recurseList.push($ref);
|
|
448
|
-
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
534
|
+
const refSchema = findSchemaDefinition($ref, rootSchema, baseURI);
|
|
449
535
|
resolvedSchema = { ...refSchema, ...localSchema };
|
|
536
|
+
if (ID_KEY in resolvedSchema) {
|
|
537
|
+
baseURI = resolvedSchema[ID_KEY];
|
|
538
|
+
}
|
|
450
539
|
}
|
|
451
540
|
if (PROPERTIES_KEY in resolvedSchema) {
|
|
452
541
|
const childrenLists = [];
|
|
@@ -454,7 +543,7 @@
|
|
|
454
543
|
resolvedSchema[PROPERTIES_KEY],
|
|
455
544
|
(result, value, key) => {
|
|
456
545
|
const childList = [...recurseList];
|
|
457
|
-
result[key] = resolveAllReferences(value, rootSchema, childList);
|
|
546
|
+
result[key] = resolveAllReferences(value, rootSchema, childList, baseURI);
|
|
458
547
|
childrenLists.push(childList);
|
|
459
548
|
},
|
|
460
549
|
{}
|
|
@@ -465,12 +554,12 @@
|
|
|
465
554
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
466
555
|
resolvedSchema = {
|
|
467
556
|
...resolvedSchema,
|
|
468
|
-
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList)
|
|
557
|
+
items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList, baseURI)
|
|
469
558
|
};
|
|
470
559
|
}
|
|
471
|
-
return
|
|
560
|
+
return deepEquals(schema, resolvedSchema) ? schema : resolvedSchema;
|
|
472
561
|
}
|
|
473
|
-
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
562
|
+
function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData, experimental_customMergeAllOf) {
|
|
474
563
|
const schema = {
|
|
475
564
|
...theSchema,
|
|
476
565
|
properties: { ...theSchema.properties }
|
|
@@ -480,34 +569,54 @@
|
|
|
480
569
|
if (key in schema.properties) {
|
|
481
570
|
return;
|
|
482
571
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
if (
|
|
486
|
-
|
|
572
|
+
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
573
|
+
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
574
|
+
if (!isEmpty2(matchingProperties)) {
|
|
575
|
+
schema.properties[key] = retrieveSchema(
|
|
487
576
|
validator,
|
|
488
|
-
{
|
|
577
|
+
{ allOf: Object.values(matchingProperties) },
|
|
489
578
|
rootSchema,
|
|
490
|
-
formData
|
|
579
|
+
get13(formData, [key]),
|
|
580
|
+
experimental_customMergeAllOf
|
|
491
581
|
);
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
582
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (ADDITIONAL_PROPERTIES_KEY in schema && schema.additionalProperties !== false) {
|
|
587
|
+
let additionalProperties = {};
|
|
588
|
+
if (typeof schema.additionalProperties !== "boolean") {
|
|
589
|
+
if (REF_KEY in schema.additionalProperties) {
|
|
590
|
+
additionalProperties = retrieveSchema(
|
|
591
|
+
validator,
|
|
592
|
+
{ $ref: get13(schema.additionalProperties, [REF_KEY]) },
|
|
593
|
+
rootSchema,
|
|
594
|
+
formData,
|
|
595
|
+
experimental_customMergeAllOf
|
|
596
|
+
);
|
|
597
|
+
} else if ("type" in schema.additionalProperties) {
|
|
598
|
+
additionalProperties = { ...schema.additionalProperties };
|
|
599
|
+
} else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
|
|
600
|
+
additionalProperties = {
|
|
601
|
+
type: "object",
|
|
602
|
+
...schema.additionalProperties
|
|
603
|
+
};
|
|
604
|
+
} else {
|
|
605
|
+
additionalProperties = { type: guessType(get13(formData, [key])) };
|
|
606
|
+
}
|
|
499
607
|
} else {
|
|
500
|
-
additionalProperties = { type: guessType(
|
|
608
|
+
additionalProperties = { type: guessType(get13(formData, [key])) };
|
|
501
609
|
}
|
|
610
|
+
schema.properties[key] = additionalProperties;
|
|
611
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
502
612
|
} else {
|
|
503
|
-
|
|
613
|
+
schema.properties[key] = { type: "null" };
|
|
614
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
504
615
|
}
|
|
505
|
-
schema.properties[key] = additionalProperties;
|
|
506
|
-
set3(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
507
616
|
});
|
|
508
617
|
return schema;
|
|
509
618
|
}
|
|
510
|
-
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) {
|
|
619
|
+
function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = [], experimental_customMergeAllOf) {
|
|
511
620
|
if (!isObject(schema)) {
|
|
512
621
|
return [{}];
|
|
513
622
|
}
|
|
@@ -517,7 +626,8 @@
|
|
|
517
626
|
rootSchema,
|
|
518
627
|
expandAllBranches,
|
|
519
628
|
recurseList,
|
|
520
|
-
rawFormData
|
|
629
|
+
rawFormData,
|
|
630
|
+
experimental_customMergeAllOf
|
|
521
631
|
);
|
|
522
632
|
return resolvedSchemas.flatMap((s) => {
|
|
523
633
|
let resolvedSchema = s;
|
|
@@ -528,7 +638,8 @@
|
|
|
528
638
|
rootSchema,
|
|
529
639
|
expandAllBranches,
|
|
530
640
|
recurseList,
|
|
531
|
-
rawFormData
|
|
641
|
+
rawFormData,
|
|
642
|
+
experimental_customMergeAllOf
|
|
532
643
|
);
|
|
533
644
|
}
|
|
534
645
|
if (ALL_OF_KEY in resolvedSchema) {
|
|
@@ -537,18 +648,63 @@
|
|
|
537
648
|
return [...allOf, restOfSchema];
|
|
538
649
|
}
|
|
539
650
|
try {
|
|
540
|
-
|
|
541
|
-
|
|
651
|
+
const withContainsSchemas = [];
|
|
652
|
+
const withoutContainsSchemas = [];
|
|
653
|
+
resolvedSchema.allOf?.forEach((s2) => {
|
|
654
|
+
if (typeof s2 === "object" && s2.contains) {
|
|
655
|
+
withContainsSchemas.push(s2);
|
|
656
|
+
} else {
|
|
657
|
+
withoutContainsSchemas.push(s2);
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
if (withContainsSchemas.length) {
|
|
661
|
+
resolvedSchema = { ...resolvedSchema, allOf: withoutContainsSchemas };
|
|
662
|
+
}
|
|
663
|
+
resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) : mergeAllOf(resolvedSchema, {
|
|
664
|
+
deep: false,
|
|
665
|
+
resolvers: {
|
|
666
|
+
$defs: mergeAllOf.options.resolvers.definitions
|
|
667
|
+
}
|
|
542
668
|
});
|
|
669
|
+
if (withContainsSchemas.length) {
|
|
670
|
+
resolvedSchema.allOf = withContainsSchemas;
|
|
671
|
+
}
|
|
543
672
|
} catch (e) {
|
|
544
673
|
console.warn("could not merge subschemas in allOf:\n", e);
|
|
545
674
|
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
|
|
546
675
|
return resolvedSchemaWithoutAllOf;
|
|
547
676
|
}
|
|
548
677
|
}
|
|
549
|
-
|
|
678
|
+
if (PROPERTIES_KEY in resolvedSchema && PATTERN_PROPERTIES_KEY in resolvedSchema) {
|
|
679
|
+
resolvedSchema = Object.keys(resolvedSchema.properties).reduce(
|
|
680
|
+
(schema2, key) => {
|
|
681
|
+
const matchingProperties = getMatchingPatternProperties(schema2, key);
|
|
682
|
+
if (!isEmpty2(matchingProperties)) {
|
|
683
|
+
schema2.properties[key] = retrieveSchema(
|
|
684
|
+
validator,
|
|
685
|
+
{ allOf: [schema2.properties[key], ...Object.values(matchingProperties)] },
|
|
686
|
+
rootSchema,
|
|
687
|
+
get13(rawFormData, [key]),
|
|
688
|
+
experimental_customMergeAllOf
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
return schema2;
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
...resolvedSchema,
|
|
695
|
+
properties: { ...resolvedSchema.properties }
|
|
696
|
+
}
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
const hasAdditionalProperties = PATTERN_PROPERTIES_KEY in resolvedSchema || ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
|
|
550
700
|
if (hasAdditionalProperties) {
|
|
551
|
-
return stubExistingAdditionalProperties(
|
|
701
|
+
return stubExistingAdditionalProperties(
|
|
702
|
+
validator,
|
|
703
|
+
resolvedSchema,
|
|
704
|
+
rootSchema,
|
|
705
|
+
rawFormData,
|
|
706
|
+
experimental_customMergeAllOf
|
|
707
|
+
);
|
|
552
708
|
}
|
|
553
709
|
return resolvedSchema;
|
|
554
710
|
});
|
|
@@ -575,7 +731,7 @@
|
|
|
575
731
|
}
|
|
576
732
|
return [schema];
|
|
577
733
|
}
|
|
578
|
-
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
734
|
+
function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
579
735
|
const { dependencies, ...remainingSchema } = schema;
|
|
580
736
|
const resolvedSchemas = resolveAnyOrOneOfSchemas(
|
|
581
737
|
validator,
|
|
@@ -592,14 +748,15 @@
|
|
|
592
748
|
rootSchema,
|
|
593
749
|
expandAllBranches,
|
|
594
750
|
recurseList,
|
|
595
|
-
formData
|
|
751
|
+
formData,
|
|
752
|
+
experimental_customMergeAllOf
|
|
596
753
|
)
|
|
597
754
|
);
|
|
598
755
|
}
|
|
599
|
-
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) {
|
|
756
|
+
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
600
757
|
let schemas = [resolvedSchema];
|
|
601
758
|
for (const dependencyKey in dependencies) {
|
|
602
|
-
if (!expandAllBranches &&
|
|
759
|
+
if (!expandAllBranches && get13(formData, [dependencyKey]) === void 0) {
|
|
603
760
|
continue;
|
|
604
761
|
}
|
|
605
762
|
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
@@ -620,7 +777,8 @@
|
|
|
620
777
|
dependencyValue,
|
|
621
778
|
expandAllBranches,
|
|
622
779
|
recurseList,
|
|
623
|
-
formData
|
|
780
|
+
formData,
|
|
781
|
+
experimental_customMergeAllOf
|
|
624
782
|
);
|
|
625
783
|
}
|
|
626
784
|
return schemas.flatMap(
|
|
@@ -631,7 +789,8 @@
|
|
|
631
789
|
rootSchema,
|
|
632
790
|
expandAllBranches,
|
|
633
791
|
recurseList,
|
|
634
|
-
formData
|
|
792
|
+
formData,
|
|
793
|
+
experimental_customMergeAllOf
|
|
635
794
|
)
|
|
636
795
|
);
|
|
637
796
|
}
|
|
@@ -644,14 +803,15 @@
|
|
|
644
803
|
const required = Array.isArray(schema.required) ? Array.from(/* @__PURE__ */ new Set([...schema.required, ...additionallyRequired])) : additionallyRequired;
|
|
645
804
|
return { ...schema, required };
|
|
646
805
|
}
|
|
647
|
-
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) {
|
|
806
|
+
function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
648
807
|
const dependentSchemas = retrieveSchemaInternal(
|
|
649
808
|
validator,
|
|
650
809
|
dependencyValue,
|
|
651
810
|
rootSchema,
|
|
652
811
|
formData,
|
|
653
812
|
expandAllBranches,
|
|
654
|
-
recurseList
|
|
813
|
+
recurseList,
|
|
814
|
+
experimental_customMergeAllOf
|
|
655
815
|
);
|
|
656
816
|
return dependentSchemas.flatMap((dependent) => {
|
|
657
817
|
const { oneOf, ...dependentSchema } = dependent;
|
|
@@ -675,12 +835,13 @@
|
|
|
675
835
|
resolvedOneOf,
|
|
676
836
|
expandAllBranches,
|
|
677
837
|
recurseList,
|
|
678
|
-
formData
|
|
838
|
+
formData,
|
|
839
|
+
experimental_customMergeAllOf
|
|
679
840
|
)
|
|
680
841
|
);
|
|
681
842
|
});
|
|
682
843
|
}
|
|
683
|
-
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) {
|
|
844
|
+
function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
684
845
|
const validSubschemas = oneOf.filter((subschema) => {
|
|
685
846
|
if (typeof subschema === "boolean" || !subschema || !subschema.properties) {
|
|
686
847
|
return false;
|
|
@@ -711,13 +872,148 @@
|
|
|
711
872
|
rootSchema,
|
|
712
873
|
formData,
|
|
713
874
|
expandAllBranches,
|
|
714
|
-
recurseList
|
|
875
|
+
recurseList,
|
|
876
|
+
experimental_customMergeAllOf
|
|
715
877
|
);
|
|
716
878
|
return schemas.map((s2) => mergeSchemas(schema, s2));
|
|
717
879
|
});
|
|
718
880
|
}
|
|
719
881
|
|
|
720
|
-
// src/schema/
|
|
882
|
+
// src/schema/findSelectedOptionInXxxOf.ts
|
|
883
|
+
function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField, xxx, formData = {}, experimental_customMergeAllOf) {
|
|
884
|
+
if (Array.isArray(schema[xxx])) {
|
|
885
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
886
|
+
const selectorField = discriminator || fallbackField;
|
|
887
|
+
const xxxOfs = schema[xxx].map(
|
|
888
|
+
(xxxOf) => retrieveSchema(validator, xxxOf, rootSchema, formData, experimental_customMergeAllOf)
|
|
889
|
+
);
|
|
890
|
+
const data = get13(formData, selectorField);
|
|
891
|
+
if (data !== void 0) {
|
|
892
|
+
return xxxOfs.find((xxx2) => {
|
|
893
|
+
return isEqual(
|
|
894
|
+
get13(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get13(xxx2, [PROPERTIES_KEY, selectorField, CONST_KEY])),
|
|
895
|
+
data
|
|
896
|
+
);
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
return void 0;
|
|
901
|
+
}
|
|
902
|
+
function getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf) {
|
|
903
|
+
let fieldSchema = schema;
|
|
904
|
+
if (has5(schema, REF_KEY)) {
|
|
905
|
+
fieldSchema = retrieveSchema(validator, schema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
906
|
+
}
|
|
907
|
+
if (isEmpty2(path)) {
|
|
908
|
+
return fieldSchema;
|
|
909
|
+
}
|
|
910
|
+
const pathList = Array.isArray(path) ? path : path.split(".");
|
|
911
|
+
const [part, ...nestedPath] = pathList;
|
|
912
|
+
if (part && has5(fieldSchema, part)) {
|
|
913
|
+
fieldSchema = get13(fieldSchema, part);
|
|
914
|
+
return getFromSchemaInternal(
|
|
915
|
+
validator,
|
|
916
|
+
rootSchema,
|
|
917
|
+
fieldSchema,
|
|
918
|
+
nestedPath,
|
|
919
|
+
experimental_customMergeAllOf
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
return void 0;
|
|
923
|
+
}
|
|
924
|
+
function getFromSchema(validator, rootSchema, schema, path, defaultValue, experimental_customMergeAllOf) {
|
|
925
|
+
const result = getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf);
|
|
926
|
+
if (result === void 0) {
|
|
927
|
+
return defaultValue;
|
|
928
|
+
}
|
|
929
|
+
return result;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// src/schema/findFieldInSchema.ts
|
|
933
|
+
var NOT_FOUND_SCHEMA = { title: "!@#$_UNKNOWN_$#@!" };
|
|
934
|
+
function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, experimental_customMergeAllOf) {
|
|
935
|
+
const pathList = Array.isArray(path) ? [...path] : path.split(".");
|
|
936
|
+
let parentField = schema;
|
|
937
|
+
const fieldName = pathList.pop();
|
|
938
|
+
if (pathList.length) {
|
|
939
|
+
pathList.forEach((subPath) => {
|
|
940
|
+
parentField = getFromSchema(
|
|
941
|
+
validator,
|
|
942
|
+
rootSchema,
|
|
943
|
+
parentField,
|
|
944
|
+
[PROPERTIES_KEY, subPath],
|
|
945
|
+
{},
|
|
946
|
+
experimental_customMergeAllOf
|
|
947
|
+
);
|
|
948
|
+
if (has5(parentField, ONE_OF_KEY)) {
|
|
949
|
+
parentField = findSelectedOptionInXxxOf(
|
|
950
|
+
validator,
|
|
951
|
+
rootSchema,
|
|
952
|
+
parentField,
|
|
953
|
+
fieldName,
|
|
954
|
+
ONE_OF_KEY,
|
|
955
|
+
get13(formData, subPath),
|
|
956
|
+
experimental_customMergeAllOf
|
|
957
|
+
);
|
|
958
|
+
} else if (has5(parentField, ANY_OF_KEY)) {
|
|
959
|
+
parentField = findSelectedOptionInXxxOf(
|
|
960
|
+
validator,
|
|
961
|
+
rootSchema,
|
|
962
|
+
parentField,
|
|
963
|
+
fieldName,
|
|
964
|
+
ANY_OF_KEY,
|
|
965
|
+
get13(formData, subPath),
|
|
966
|
+
experimental_customMergeAllOf
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
if (has5(parentField, ONE_OF_KEY)) {
|
|
972
|
+
parentField = findSelectedOptionInXxxOf(
|
|
973
|
+
validator,
|
|
974
|
+
rootSchema,
|
|
975
|
+
parentField,
|
|
976
|
+
fieldName,
|
|
977
|
+
ONE_OF_KEY,
|
|
978
|
+
formData,
|
|
979
|
+
experimental_customMergeAllOf
|
|
980
|
+
);
|
|
981
|
+
} else if (has5(parentField, ANY_OF_KEY)) {
|
|
982
|
+
parentField = findSelectedOptionInXxxOf(
|
|
983
|
+
validator,
|
|
984
|
+
rootSchema,
|
|
985
|
+
parentField,
|
|
986
|
+
fieldName,
|
|
987
|
+
ANY_OF_KEY,
|
|
988
|
+
formData,
|
|
989
|
+
experimental_customMergeAllOf
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
let field = getFromSchema(
|
|
993
|
+
validator,
|
|
994
|
+
rootSchema,
|
|
995
|
+
parentField,
|
|
996
|
+
[PROPERTIES_KEY, fieldName],
|
|
997
|
+
NOT_FOUND_SCHEMA,
|
|
998
|
+
experimental_customMergeAllOf
|
|
999
|
+
);
|
|
1000
|
+
if (field === NOT_FOUND_SCHEMA) {
|
|
1001
|
+
field = void 0;
|
|
1002
|
+
}
|
|
1003
|
+
const requiredArray = getFromSchema(
|
|
1004
|
+
validator,
|
|
1005
|
+
rootSchema,
|
|
1006
|
+
parentField,
|
|
1007
|
+
REQUIRED_KEY,
|
|
1008
|
+
[],
|
|
1009
|
+
experimental_customMergeAllOf
|
|
1010
|
+
);
|
|
1011
|
+
let isRequired;
|
|
1012
|
+
if (field && Array.isArray(requiredArray)) {
|
|
1013
|
+
isRequired = requiredArray.includes(fieldName);
|
|
1014
|
+
}
|
|
1015
|
+
return { field, isRequired };
|
|
1016
|
+
}
|
|
721
1017
|
var JUNK_OPTION = {
|
|
722
1018
|
type: "object",
|
|
723
1019
|
$id: JUNK_OPTION_ID,
|
|
@@ -727,35 +1023,51 @@
|
|
|
727
1023
|
}
|
|
728
1024
|
}
|
|
729
1025
|
};
|
|
730
|
-
function calculateIndexScore(validator, rootSchema, schema, formData
|
|
1026
|
+
function calculateIndexScore(validator, rootSchema, schema, formData, experimental_customMergeAllOf) {
|
|
731
1027
|
let totalScore = 0;
|
|
732
1028
|
if (schema) {
|
|
733
|
-
if (
|
|
1029
|
+
if (isObject3(schema.properties)) {
|
|
734
1030
|
totalScore += reduce(
|
|
735
1031
|
schema.properties,
|
|
736
1032
|
(score, value, key) => {
|
|
737
|
-
const formValue =
|
|
1033
|
+
const formValue = get13(formData, key);
|
|
738
1034
|
if (typeof value === "boolean") {
|
|
739
1035
|
return score;
|
|
740
1036
|
}
|
|
741
|
-
if (
|
|
742
|
-
const newSchema = retrieveSchema(
|
|
743
|
-
|
|
1037
|
+
if (has5(value, REF_KEY)) {
|
|
1038
|
+
const newSchema = retrieveSchema(
|
|
1039
|
+
validator,
|
|
1040
|
+
value,
|
|
1041
|
+
rootSchema,
|
|
1042
|
+
formValue,
|
|
1043
|
+
experimental_customMergeAllOf
|
|
1044
|
+
);
|
|
1045
|
+
return score + calculateIndexScore(
|
|
1046
|
+
validator,
|
|
1047
|
+
rootSchema,
|
|
1048
|
+
newSchema,
|
|
1049
|
+
formValue || {},
|
|
1050
|
+
experimental_customMergeAllOf
|
|
1051
|
+
);
|
|
744
1052
|
}
|
|
745
|
-
if ((
|
|
746
|
-
const key2 =
|
|
1053
|
+
if ((has5(value, ONE_OF_KEY) || has5(value, ANY_OF_KEY)) && formValue) {
|
|
1054
|
+
const key2 = has5(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
747
1055
|
const discriminator = getDiscriminatorFieldFromSchema(value);
|
|
748
1056
|
return score + getClosestMatchingOption(
|
|
749
1057
|
validator,
|
|
750
1058
|
rootSchema,
|
|
751
1059
|
formValue,
|
|
752
|
-
|
|
1060
|
+
get13(value, key2),
|
|
753
1061
|
-1,
|
|
754
|
-
discriminator
|
|
1062
|
+
discriminator,
|
|
1063
|
+
experimental_customMergeAllOf
|
|
755
1064
|
);
|
|
756
1065
|
}
|
|
757
1066
|
if (value.type === "object") {
|
|
758
|
-
|
|
1067
|
+
if (isObject3(formValue)) {
|
|
1068
|
+
score += 1;
|
|
1069
|
+
}
|
|
1070
|
+
return score + calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf);
|
|
759
1071
|
}
|
|
760
1072
|
if (value.type === guessType(formValue)) {
|
|
761
1073
|
let newScore = score + 1;
|
|
@@ -776,7 +1088,7 @@
|
|
|
776
1088
|
}
|
|
777
1089
|
return totalScore;
|
|
778
1090
|
}
|
|
779
|
-
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField) {
|
|
1091
|
+
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField, experimental_customMergeAllOf) {
|
|
780
1092
|
const resolvedOptions = options.map((option) => {
|
|
781
1093
|
return resolveAllReferences(option, rootSchema, []);
|
|
782
1094
|
});
|
|
@@ -803,7 +1115,7 @@
|
|
|
803
1115
|
(scoreData, index) => {
|
|
804
1116
|
const { bestScore } = scoreData;
|
|
805
1117
|
const option = resolvedOptions[index];
|
|
806
|
-
const score = calculateIndexScore(validator, rootSchema, option, formData);
|
|
1118
|
+
const score = calculateIndexScore(validator, rootSchema, option, formData, experimental_customMergeAllOf);
|
|
807
1119
|
scoreCount.add(score);
|
|
808
1120
|
if (score > bestScore) {
|
|
809
1121
|
return { bestIndex: index, bestScore: score };
|
|
@@ -822,56 +1134,77 @@
|
|
|
822
1134
|
function isFixedItems(schema) {
|
|
823
1135
|
return Array.isArray(schema.items) && schema.items.length > 0 && schema.items.every((item) => isObject(item));
|
|
824
1136
|
}
|
|
825
|
-
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false) {
|
|
1137
|
+
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false, overrideFormDataWithDefaults = false) {
|
|
826
1138
|
if (Array.isArray(formData)) {
|
|
827
1139
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
828
|
-
const
|
|
829
|
-
|
|
830
|
-
|
|
1140
|
+
const overrideArray = overrideFormDataWithDefaults ? defaultsArray : formData;
|
|
1141
|
+
const overrideOppositeArray = overrideFormDataWithDefaults ? formData : defaultsArray;
|
|
1142
|
+
const mapped = overrideArray.map((value, idx) => {
|
|
1143
|
+
if (overrideOppositeArray[idx] !== void 0) {
|
|
1144
|
+
return mergeDefaultsWithFormData(
|
|
1145
|
+
defaultsArray[idx],
|
|
1146
|
+
formData[idx],
|
|
1147
|
+
mergeExtraArrayDefaults,
|
|
1148
|
+
defaultSupercedesUndefined,
|
|
1149
|
+
overrideFormDataWithDefaults
|
|
1150
|
+
);
|
|
831
1151
|
}
|
|
832
1152
|
return value;
|
|
833
1153
|
});
|
|
834
|
-
if (mergeExtraArrayDefaults && mapped.length <
|
|
835
|
-
mapped.push(...
|
|
1154
|
+
if ((mergeExtraArrayDefaults || overrideFormDataWithDefaults) && mapped.length < overrideOppositeArray.length) {
|
|
1155
|
+
mapped.push(...overrideOppositeArray.slice(mapped.length));
|
|
836
1156
|
}
|
|
837
1157
|
return mapped;
|
|
838
1158
|
}
|
|
839
1159
|
if (isObject(formData)) {
|
|
840
1160
|
const acc = Object.assign({}, defaults);
|
|
841
1161
|
return Object.keys(formData).reduce((acc2, key) => {
|
|
1162
|
+
const keyValue = get13(formData, key);
|
|
1163
|
+
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
1164
|
+
const keyExistsInFormData = key in formData;
|
|
842
1165
|
acc2[key] = mergeDefaultsWithFormData(
|
|
843
|
-
defaults ?
|
|
844
|
-
|
|
845
|
-
mergeExtraArrayDefaults
|
|
1166
|
+
defaults ? get13(defaults, key) : {},
|
|
1167
|
+
keyValue,
|
|
1168
|
+
mergeExtraArrayDefaults,
|
|
1169
|
+
defaultSupercedesUndefined,
|
|
1170
|
+
// overrideFormDataWithDefaults can be true only when the key value exists in defaults
|
|
1171
|
+
// Or if the key value doesn't exist in formData
|
|
1172
|
+
overrideFormDataWithDefaults && (keyExistsInDefaults || !keyExistsInFormData)
|
|
846
1173
|
);
|
|
847
1174
|
return acc2;
|
|
848
1175
|
}, acc);
|
|
849
1176
|
}
|
|
1177
|
+
if (defaultSupercedesUndefined && (!isNil(defaults) && isNil(formData) || typeof formData === "number" && isNaN(formData)) || overrideFormDataWithDefaults && !isNil(formData)) {
|
|
1178
|
+
return defaults;
|
|
1179
|
+
}
|
|
850
1180
|
return formData;
|
|
851
1181
|
}
|
|
852
1182
|
|
|
853
1183
|
// src/mergeObjects.ts
|
|
854
1184
|
function mergeObjects(obj1, obj2, concatArrays = false) {
|
|
855
|
-
return Object.keys(obj2).reduce(
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
1185
|
+
return Object.keys(obj2).reduce(
|
|
1186
|
+
(acc, key) => {
|
|
1187
|
+
const left = obj1 ? obj1[key] : {}, right = obj2[key];
|
|
1188
|
+
if (obj1 && key in obj1 && isObject(right)) {
|
|
1189
|
+
acc[key] = mergeObjects(left, right, concatArrays);
|
|
1190
|
+
} else if (concatArrays && Array.isArray(left) && Array.isArray(right)) {
|
|
1191
|
+
let toMerge = right;
|
|
1192
|
+
if (concatArrays === "preventDuplicates") {
|
|
1193
|
+
toMerge = right.reduce((result, value) => {
|
|
1194
|
+
if (!left.includes(value)) {
|
|
1195
|
+
result.push(value);
|
|
1196
|
+
}
|
|
1197
|
+
return result;
|
|
1198
|
+
}, []);
|
|
1199
|
+
}
|
|
1200
|
+
acc[key] = left.concat(toMerge);
|
|
1201
|
+
} else {
|
|
1202
|
+
acc[key] = right;
|
|
868
1203
|
}
|
|
869
|
-
acc
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
return acc;
|
|
874
|
-
}, Object.assign({}, obj1));
|
|
1204
|
+
return acc;
|
|
1205
|
+
},
|
|
1206
|
+
Object.assign({}, obj1)
|
|
1207
|
+
);
|
|
875
1208
|
}
|
|
876
1209
|
|
|
877
1210
|
// src/isConstant.ts
|
|
@@ -880,8 +1213,8 @@
|
|
|
880
1213
|
}
|
|
881
1214
|
|
|
882
1215
|
// src/schema/isSelect.ts
|
|
883
|
-
function isSelect(validator, theSchema, rootSchema = {}) {
|
|
884
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0);
|
|
1216
|
+
function isSelect(validator, theSchema, rootSchema = {}, experimental_customMergeAllOf) {
|
|
1217
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
885
1218
|
const altSchemas = schema.oneOf || schema.anyOf;
|
|
886
1219
|
if (Array.isArray(schema.enum)) {
|
|
887
1220
|
return true;
|
|
@@ -893,14 +1226,79 @@
|
|
|
893
1226
|
}
|
|
894
1227
|
|
|
895
1228
|
// src/schema/isMultiSelect.ts
|
|
896
|
-
function isMultiSelect(validator, schema, rootSchema) {
|
|
1229
|
+
function isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) {
|
|
897
1230
|
if (!schema.uniqueItems || !schema.items || typeof schema.items === "boolean") {
|
|
898
1231
|
return false;
|
|
899
1232
|
}
|
|
900
|
-
return isSelect(validator, schema.items, rootSchema);
|
|
1233
|
+
return isSelect(validator, schema.items, rootSchema, experimental_customMergeAllOf);
|
|
1234
|
+
}
|
|
1235
|
+
function constIsAjvDataReference(schema) {
|
|
1236
|
+
const schemaConst = schema[CONST_KEY];
|
|
1237
|
+
const schemaType = getSchemaType(schema);
|
|
1238
|
+
return isObject(schemaConst) && isString(schemaConst?.$data) && schemaType !== "object" && schemaType !== "array";
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
// src/toConstant.ts
|
|
1242
|
+
function toConstant(schema) {
|
|
1243
|
+
if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
|
|
1244
|
+
return schema.enum[0];
|
|
1245
|
+
}
|
|
1246
|
+
if (CONST_KEY in schema) {
|
|
1247
|
+
return schema.const;
|
|
1248
|
+
}
|
|
1249
|
+
throw new Error("schema cannot be inferred as a constant");
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
// src/optionsList.ts
|
|
1253
|
+
function optionsList(schema, uiSchema) {
|
|
1254
|
+
if (schema.enum) {
|
|
1255
|
+
let enumNames;
|
|
1256
|
+
if (uiSchema) {
|
|
1257
|
+
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
1258
|
+
enumNames = uiEnumNames;
|
|
1259
|
+
}
|
|
1260
|
+
return schema.enum.map((value, i) => {
|
|
1261
|
+
const label = enumNames?.[i] || String(value);
|
|
1262
|
+
return { label, value };
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
let altSchemas = void 0;
|
|
1266
|
+
let altUiSchemas = void 0;
|
|
1267
|
+
if (schema.anyOf) {
|
|
1268
|
+
altSchemas = schema.anyOf;
|
|
1269
|
+
altUiSchemas = uiSchema?.anyOf;
|
|
1270
|
+
} else if (schema.oneOf) {
|
|
1271
|
+
altSchemas = schema.oneOf;
|
|
1272
|
+
altUiSchemas = uiSchema?.oneOf;
|
|
1273
|
+
}
|
|
1274
|
+
let selectorField = getDiscriminatorFieldFromSchema(schema);
|
|
1275
|
+
if (uiSchema) {
|
|
1276
|
+
const { optionsSchemaSelector = selectorField } = getUiOptions(uiSchema);
|
|
1277
|
+
selectorField = optionsSchemaSelector;
|
|
1278
|
+
}
|
|
1279
|
+
return altSchemas && altSchemas.map((aSchemaDef, index) => {
|
|
1280
|
+
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
1281
|
+
const aSchema = aSchemaDef;
|
|
1282
|
+
let value;
|
|
1283
|
+
let label = title;
|
|
1284
|
+
if (selectorField) {
|
|
1285
|
+
const innerSchema = get13(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
1286
|
+
value = get13(innerSchema, DEFAULT_KEY, get13(innerSchema, CONST_KEY));
|
|
1287
|
+
label = label || innerSchema?.title || aSchema.title || String(value);
|
|
1288
|
+
} else {
|
|
1289
|
+
value = toConstant(aSchema);
|
|
1290
|
+
label = label || aSchema.title || String(value);
|
|
1291
|
+
}
|
|
1292
|
+
return {
|
|
1293
|
+
schema: aSchema,
|
|
1294
|
+
label,
|
|
1295
|
+
value
|
|
1296
|
+
};
|
|
1297
|
+
});
|
|
901
1298
|
}
|
|
902
1299
|
|
|
903
1300
|
// src/schema/getDefaultFormState.ts
|
|
1301
|
+
var PRIMITIVE_TYPES = ["string", "number", "integer", "boolean", "null"];
|
|
904
1302
|
function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, idx = -1) {
|
|
905
1303
|
if (idx >= 0) {
|
|
906
1304
|
if (Array.isArray(schema.items) && idx < schema.items.length) {
|
|
@@ -917,47 +1315,54 @@
|
|
|
917
1315
|
}
|
|
918
1316
|
return {};
|
|
919
1317
|
}
|
|
920
|
-
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}) {
|
|
1318
|
+
function maybeAddDefaultToObject(obj, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false) {
|
|
921
1319
|
const { emptyObjectFields = "populateAllDefaults" } = experimental_defaultFormStateBehavior;
|
|
922
|
-
if (includeUndefinedValues) {
|
|
1320
|
+
if (includeUndefinedValues || isConst) {
|
|
923
1321
|
obj[key] = computedDefault;
|
|
924
1322
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
1323
|
+
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
925
1324
|
if (isObject(computedDefault)) {
|
|
926
|
-
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
927
1325
|
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
928
|
-
if (!
|
|
1326
|
+
if (!isEmpty2(computedDefault)) {
|
|
929
1327
|
obj[key] = computedDefault;
|
|
930
1328
|
}
|
|
931
|
-
} else if ((!
|
|
1329
|
+
} else if ((!isEmpty2(computedDefault) || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
932
1330
|
obj[key] = computedDefault;
|
|
933
1331
|
}
|
|
934
1332
|
} else if (
|
|
935
1333
|
// Store computedDefault if it's a defined primitive (e.g., true) and satisfies certain conditions
|
|
936
1334
|
// Condition 1: computedDefault is not undefined
|
|
937
|
-
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
938
|
-
|
|
1335
|
+
// Condition 2: If emptyObjectFields is 'populateAllDefaults' or 'skipEmptyDefaults)
|
|
1336
|
+
// Or if isSelfOrParentRequired is 'true' and the key is a required field
|
|
1337
|
+
computedDefault !== void 0 && (emptyObjectFields === "populateAllDefaults" || emptyObjectFields === "skipEmptyDefaults" || isSelfOrParentRequired && requiredFields.includes(key))
|
|
939
1338
|
) {
|
|
940
1339
|
obj[key] = computedDefault;
|
|
941
1340
|
}
|
|
942
1341
|
}
|
|
943
1342
|
}
|
|
944
|
-
function computeDefaults(validator, rawSchema, {
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
1343
|
+
function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
1344
|
+
const {
|
|
1345
|
+
parentDefaults,
|
|
1346
|
+
rawFormData,
|
|
1347
|
+
rootSchema = {},
|
|
1348
|
+
includeUndefinedValues = false,
|
|
1349
|
+
_recurseList = [],
|
|
1350
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1351
|
+
experimental_customMergeAllOf = void 0,
|
|
1352
|
+
required,
|
|
1353
|
+
shouldMergeDefaultsIntoFormData = false
|
|
1354
|
+
} = computeDefaultsProps;
|
|
1355
|
+
let formData = isObject(rawFormData) ? rawFormData : {};
|
|
954
1356
|
const schema = isObject(rawSchema) ? rawSchema : {};
|
|
955
1357
|
let defaults = parentDefaults;
|
|
956
1358
|
let schemaToCompute = null;
|
|
1359
|
+
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
|
|
957
1360
|
let updatedRecurseList = _recurseList;
|
|
958
|
-
if (
|
|
1361
|
+
if (schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(schema)) {
|
|
1362
|
+
defaults = schema[CONST_KEY];
|
|
1363
|
+
} else if (isObject(defaults) && isObject(schema.default)) {
|
|
959
1364
|
defaults = mergeObjects(defaults, schema.default);
|
|
960
|
-
} else if (DEFAULT_KEY in schema) {
|
|
1365
|
+
} else if (DEFAULT_KEY in schema && !schema[ANY_OF_KEY] && !schema[ONE_OF_KEY] && !schema[REF_KEY]) {
|
|
961
1366
|
defaults = schema.default;
|
|
962
1367
|
} else if (REF_KEY in schema) {
|
|
963
1368
|
const refName = schema[REF_KEY];
|
|
@@ -965,8 +1370,26 @@
|
|
|
965
1370
|
updatedRecurseList = _recurseList.concat(refName);
|
|
966
1371
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
967
1372
|
}
|
|
1373
|
+
if (schemaToCompute && !defaults) {
|
|
1374
|
+
defaults = schema.default;
|
|
1375
|
+
}
|
|
1376
|
+
if (shouldMergeDefaultsIntoFormData && schemaToCompute && !isObject(rawFormData)) {
|
|
1377
|
+
formData = rawFormData;
|
|
1378
|
+
}
|
|
968
1379
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
969
|
-
const
|
|
1380
|
+
const defaultFormData = {
|
|
1381
|
+
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults),
|
|
1382
|
+
...formData
|
|
1383
|
+
};
|
|
1384
|
+
const resolvedSchema = resolveDependencies(
|
|
1385
|
+
validator,
|
|
1386
|
+
schema,
|
|
1387
|
+
rootSchema,
|
|
1388
|
+
false,
|
|
1389
|
+
[],
|
|
1390
|
+
defaultFormData,
|
|
1391
|
+
experimental_customMergeAllOf
|
|
1392
|
+
);
|
|
970
1393
|
schemaToCompute = resolvedSchema[0];
|
|
971
1394
|
} else if (isFixedItems(schema)) {
|
|
972
1395
|
defaults = schema.items.map(
|
|
@@ -975,9 +1398,11 @@
|
|
|
975
1398
|
includeUndefinedValues,
|
|
976
1399
|
_recurseList,
|
|
977
1400
|
experimental_defaultFormStateBehavior,
|
|
1401
|
+
experimental_customMergeAllOf,
|
|
978
1402
|
parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : void 0,
|
|
979
1403
|
rawFormData: formData,
|
|
980
|
-
required
|
|
1404
|
+
required,
|
|
1405
|
+
shouldMergeDefaultsIntoFormData
|
|
981
1406
|
})
|
|
982
1407
|
);
|
|
983
1408
|
} else if (ONE_OF_KEY in schema) {
|
|
@@ -986,13 +1411,21 @@
|
|
|
986
1411
|
return void 0;
|
|
987
1412
|
}
|
|
988
1413
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1414
|
+
const { type = "null" } = remaining;
|
|
1415
|
+
if (!Array.isArray(type) && PRIMITIVE_TYPES.includes(type) && experimental_dfsb_to_compute?.constAsDefaults === "skipOneOf") {
|
|
1416
|
+
experimental_dfsb_to_compute = {
|
|
1417
|
+
...experimental_dfsb_to_compute,
|
|
1418
|
+
constAsDefaults: "never"
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
989
1421
|
schemaToCompute = oneOf[getClosestMatchingOption(
|
|
990
1422
|
validator,
|
|
991
1423
|
rootSchema,
|
|
992
|
-
|
|
1424
|
+
rawFormData ?? schema.default,
|
|
993
1425
|
oneOf,
|
|
994
1426
|
0,
|
|
995
|
-
discriminator
|
|
1427
|
+
discriminator,
|
|
1428
|
+
experimental_customMergeAllOf
|
|
996
1429
|
)];
|
|
997
1430
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
998
1431
|
} else if (ANY_OF_KEY in schema) {
|
|
@@ -1004,171 +1437,270 @@
|
|
|
1004
1437
|
schemaToCompute = anyOf[getClosestMatchingOption(
|
|
1005
1438
|
validator,
|
|
1006
1439
|
rootSchema,
|
|
1007
|
-
|
|
1440
|
+
rawFormData ?? schema.default,
|
|
1008
1441
|
anyOf,
|
|
1009
1442
|
0,
|
|
1010
|
-
discriminator
|
|
1443
|
+
discriminator,
|
|
1444
|
+
experimental_customMergeAllOf
|
|
1011
1445
|
)];
|
|
1012
1446
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1013
1447
|
}
|
|
1014
|
-
if (schemaToCompute) {
|
|
1015
|
-
return computeDefaults(validator, schemaToCompute, {
|
|
1448
|
+
if (schemaToCompute) {
|
|
1449
|
+
return computeDefaults(validator, schemaToCompute, {
|
|
1450
|
+
rootSchema,
|
|
1451
|
+
includeUndefinedValues,
|
|
1452
|
+
_recurseList: updatedRecurseList,
|
|
1453
|
+
experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
|
|
1454
|
+
experimental_customMergeAllOf,
|
|
1455
|
+
parentDefaults: defaults,
|
|
1456
|
+
rawFormData: formData,
|
|
1457
|
+
required,
|
|
1458
|
+
shouldMergeDefaultsIntoFormData
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
if (defaults === void 0) {
|
|
1462
|
+
defaults = schema.default;
|
|
1463
|
+
}
|
|
1464
|
+
const defaultBasedOnSchemaType = getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults);
|
|
1465
|
+
let defaultsWithFormData = defaultBasedOnSchemaType ?? defaults;
|
|
1466
|
+
if (shouldMergeDefaultsIntoFormData) {
|
|
1467
|
+
const { arrayMinItems = {} } = experimental_defaultFormStateBehavior || {};
|
|
1468
|
+
const { mergeExtraDefaults } = arrayMinItems;
|
|
1469
|
+
const matchingFormData = ensureFormDataMatchingSchema(
|
|
1470
|
+
validator,
|
|
1471
|
+
schema,
|
|
1472
|
+
rootSchema,
|
|
1473
|
+
rawFormData,
|
|
1474
|
+
experimental_defaultFormStateBehavior,
|
|
1475
|
+
experimental_customMergeAllOf
|
|
1476
|
+
);
|
|
1477
|
+
if (!isObject(rawFormData) || ALL_OF_KEY in schema) {
|
|
1478
|
+
defaultsWithFormData = mergeDefaultsWithFormData(
|
|
1479
|
+
defaultsWithFormData,
|
|
1480
|
+
matchingFormData,
|
|
1481
|
+
mergeExtraDefaults,
|
|
1482
|
+
true
|
|
1483
|
+
);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return defaultsWithFormData;
|
|
1487
|
+
}
|
|
1488
|
+
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1489
|
+
const isSelectField = !isConstant(schema) && isSelect(validator, schema, rootSchema, experimental_customMergeAllOf);
|
|
1490
|
+
let validFormData = formData;
|
|
1491
|
+
if (isSelectField) {
|
|
1492
|
+
const getOptionsList = optionsList(schema);
|
|
1493
|
+
const isValid = getOptionsList?.some((option) => deepEquals(option.value, formData));
|
|
1494
|
+
validFormData = isValid ? formData : void 0;
|
|
1495
|
+
}
|
|
1496
|
+
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
1497
|
+
if (constTakesPrecedence) {
|
|
1498
|
+
validFormData = schema.const;
|
|
1499
|
+
}
|
|
1500
|
+
return validFormData;
|
|
1501
|
+
}
|
|
1502
|
+
function getObjectDefaults(validator, rawSchema, {
|
|
1503
|
+
rawFormData,
|
|
1504
|
+
rootSchema = {},
|
|
1505
|
+
includeUndefinedValues = false,
|
|
1506
|
+
_recurseList = [],
|
|
1507
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1508
|
+
experimental_customMergeAllOf = void 0,
|
|
1509
|
+
required,
|
|
1510
|
+
shouldMergeDefaultsIntoFormData
|
|
1511
|
+
} = {}, defaults) {
|
|
1512
|
+
{
|
|
1513
|
+
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1514
|
+
const schema = rawSchema;
|
|
1515
|
+
const retrievedSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema ? retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf) : schema;
|
|
1516
|
+
const parentConst = retrievedSchema[CONST_KEY];
|
|
1517
|
+
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1518
|
+
(acc, key) => {
|
|
1519
|
+
const propertySchema = get13(retrievedSchema, [PROPERTIES_KEY, key], {});
|
|
1520
|
+
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1521
|
+
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1522
|
+
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
1523
|
+
rootSchema,
|
|
1524
|
+
_recurseList,
|
|
1525
|
+
experimental_defaultFormStateBehavior,
|
|
1526
|
+
experimental_customMergeAllOf,
|
|
1527
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1528
|
+
parentDefaults: get13(defaults, [key]),
|
|
1529
|
+
rawFormData: get13(formData, [key]),
|
|
1530
|
+
required: retrievedSchema.required?.includes(key),
|
|
1531
|
+
shouldMergeDefaultsIntoFormData
|
|
1532
|
+
});
|
|
1533
|
+
maybeAddDefaultToObject(
|
|
1534
|
+
acc,
|
|
1535
|
+
key,
|
|
1536
|
+
computedDefault,
|
|
1537
|
+
includeUndefinedValues,
|
|
1538
|
+
required,
|
|
1539
|
+
retrievedSchema.required,
|
|
1540
|
+
experimental_defaultFormStateBehavior,
|
|
1541
|
+
hasConst
|
|
1542
|
+
);
|
|
1543
|
+
return acc;
|
|
1544
|
+
},
|
|
1545
|
+
{}
|
|
1546
|
+
);
|
|
1547
|
+
if (retrievedSchema.additionalProperties) {
|
|
1548
|
+
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1549
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
1550
|
+
if (isObject(defaults)) {
|
|
1551
|
+
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1552
|
+
}
|
|
1553
|
+
const formDataRequired = [];
|
|
1554
|
+
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1555
|
+
keys2.add(key);
|
|
1556
|
+
formDataRequired.push(key);
|
|
1557
|
+
});
|
|
1558
|
+
keys2.forEach((key) => {
|
|
1559
|
+
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1560
|
+
rootSchema,
|
|
1561
|
+
_recurseList,
|
|
1562
|
+
experimental_defaultFormStateBehavior,
|
|
1563
|
+
experimental_customMergeAllOf,
|
|
1564
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1565
|
+
parentDefaults: get13(defaults, [key]),
|
|
1566
|
+
rawFormData: get13(formData, [key]),
|
|
1567
|
+
required: retrievedSchema.required?.includes(key),
|
|
1568
|
+
shouldMergeDefaultsIntoFormData
|
|
1569
|
+
});
|
|
1570
|
+
maybeAddDefaultToObject(
|
|
1571
|
+
objectDefaults,
|
|
1572
|
+
key,
|
|
1573
|
+
computedDefault,
|
|
1574
|
+
includeUndefinedValues,
|
|
1575
|
+
required,
|
|
1576
|
+
formDataRequired
|
|
1577
|
+
);
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
return objectDefaults;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
function getArrayDefaults(validator, rawSchema, {
|
|
1584
|
+
rawFormData,
|
|
1585
|
+
rootSchema = {},
|
|
1586
|
+
_recurseList = [],
|
|
1587
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1588
|
+
experimental_customMergeAllOf = void 0,
|
|
1589
|
+
required,
|
|
1590
|
+
shouldMergeDefaultsIntoFormData
|
|
1591
|
+
} = {}, defaults) {
|
|
1592
|
+
const schema = rawSchema;
|
|
1593
|
+
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems ?? {};
|
|
1594
|
+
const { populate: arrayMinItemsPopulate, mergeExtraDefaults: arrayMergeExtraDefaults } = arrayMinItemsStateBehavior;
|
|
1595
|
+
const neverPopulate = arrayMinItemsPopulate === "never";
|
|
1596
|
+
const ignoreMinItemsFlagSet = arrayMinItemsPopulate === "requiredOnly";
|
|
1597
|
+
const isPopulateAll = arrayMinItemsPopulate === "all" || !neverPopulate && !ignoreMinItemsFlagSet;
|
|
1598
|
+
const computeSkipPopulate = arrayMinItemsStateBehavior?.computeSkipPopulate ?? (() => false);
|
|
1599
|
+
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
|
|
1600
|
+
const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
|
|
1601
|
+
if (Array.isArray(defaults)) {
|
|
1602
|
+
defaults = defaults.map((item, idx) => {
|
|
1603
|
+
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
1604
|
+
return computeDefaults(validator, schemaItem, {
|
|
1605
|
+
rootSchema,
|
|
1606
|
+
_recurseList,
|
|
1607
|
+
experimental_defaultFormStateBehavior,
|
|
1608
|
+
experimental_customMergeAllOf,
|
|
1609
|
+
parentDefaults: item,
|
|
1610
|
+
required,
|
|
1611
|
+
shouldMergeDefaultsIntoFormData
|
|
1612
|
+
});
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
if (Array.isArray(rawFormData)) {
|
|
1616
|
+
const schemaItem = getInnerSchemaForArrayItem(schema);
|
|
1617
|
+
if (neverPopulate) {
|
|
1618
|
+
defaults = rawFormData;
|
|
1619
|
+
} else {
|
|
1620
|
+
const itemDefaults = rawFormData.map((item, idx) => {
|
|
1621
|
+
return computeDefaults(validator, schemaItem, {
|
|
1622
|
+
rootSchema,
|
|
1623
|
+
_recurseList,
|
|
1624
|
+
experimental_defaultFormStateBehavior,
|
|
1625
|
+
experimental_customMergeAllOf,
|
|
1626
|
+
rawFormData: item,
|
|
1627
|
+
parentDefaults: get13(defaults, [idx]),
|
|
1628
|
+
required,
|
|
1629
|
+
shouldMergeDefaultsIntoFormData
|
|
1630
|
+
});
|
|
1631
|
+
});
|
|
1632
|
+
const mergeExtraDefaults = (ignoreMinItemsFlagSet && required || isPopulateAll) && arrayMergeExtraDefaults;
|
|
1633
|
+
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
const hasConst = isObject(schema) && CONST_KEY in schema && experimental_defaultFormStateBehavior?.constAsDefaults !== "never";
|
|
1637
|
+
if (hasConst === false) {
|
|
1638
|
+
if (neverPopulate) {
|
|
1639
|
+
return defaults ?? emptyDefault;
|
|
1640
|
+
}
|
|
1641
|
+
if (ignoreMinItemsFlagSet && !required) {
|
|
1642
|
+
return defaults ? defaults : void 0;
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1646
|
+
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1647
|
+
return defaults ? defaults : emptyDefault;
|
|
1648
|
+
}
|
|
1649
|
+
const defaultEntries = defaults || [];
|
|
1650
|
+
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
1651
|
+
const fillerDefault = fillerSchema.default;
|
|
1652
|
+
const fillerEntries = new Array(schema.minItems - defaultsLength).fill(
|
|
1653
|
+
computeDefaults(validator, fillerSchema, {
|
|
1654
|
+
parentDefaults: fillerDefault,
|
|
1016
1655
|
rootSchema,
|
|
1017
|
-
|
|
1018
|
-
_recurseList: updatedRecurseList,
|
|
1656
|
+
_recurseList,
|
|
1019
1657
|
experimental_defaultFormStateBehavior,
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
})
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
switch (getSchemaType(
|
|
1658
|
+
experimental_customMergeAllOf,
|
|
1659
|
+
required,
|
|
1660
|
+
shouldMergeDefaultsIntoFormData
|
|
1661
|
+
})
|
|
1662
|
+
);
|
|
1663
|
+
return defaultEntries.concat(fillerEntries);
|
|
1664
|
+
}
|
|
1665
|
+
function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps = {}, defaults) {
|
|
1666
|
+
switch (getSchemaType(rawSchema)) {
|
|
1667
|
+
// We need to recurse for object schema inner default values.
|
|
1029
1668
|
case "object": {
|
|
1030
|
-
|
|
1031
|
-
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1032
|
-
(acc, key) => {
|
|
1033
|
-
const computedDefault = computeDefaults(validator, get8(retrievedSchema, [PROPERTIES_KEY, key]), {
|
|
1034
|
-
rootSchema,
|
|
1035
|
-
_recurseList,
|
|
1036
|
-
experimental_defaultFormStateBehavior,
|
|
1037
|
-
includeUndefinedValues: includeUndefinedValues === true,
|
|
1038
|
-
parentDefaults: get8(defaults, [key]),
|
|
1039
|
-
rawFormData: get8(formData, [key]),
|
|
1040
|
-
required: retrievedSchema.required?.includes(key)
|
|
1041
|
-
});
|
|
1042
|
-
maybeAddDefaultToObject(
|
|
1043
|
-
acc,
|
|
1044
|
-
key,
|
|
1045
|
-
computedDefault,
|
|
1046
|
-
includeUndefinedValues,
|
|
1047
|
-
required,
|
|
1048
|
-
retrievedSchema.required,
|
|
1049
|
-
experimental_defaultFormStateBehavior
|
|
1050
|
-
);
|
|
1051
|
-
return acc;
|
|
1052
|
-
},
|
|
1053
|
-
{}
|
|
1054
|
-
);
|
|
1055
|
-
if (retrievedSchema.additionalProperties) {
|
|
1056
|
-
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1057
|
-
const keys = /* @__PURE__ */ new Set();
|
|
1058
|
-
if (isObject(defaults)) {
|
|
1059
|
-
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys.add(key));
|
|
1060
|
-
}
|
|
1061
|
-
const formDataRequired = [];
|
|
1062
|
-
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1063
|
-
keys.add(key);
|
|
1064
|
-
formDataRequired.push(key);
|
|
1065
|
-
});
|
|
1066
|
-
keys.forEach((key) => {
|
|
1067
|
-
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1068
|
-
rootSchema,
|
|
1069
|
-
_recurseList,
|
|
1070
|
-
experimental_defaultFormStateBehavior,
|
|
1071
|
-
includeUndefinedValues: includeUndefinedValues === true,
|
|
1072
|
-
parentDefaults: get8(defaults, [key]),
|
|
1073
|
-
rawFormData: get8(formData, [key]),
|
|
1074
|
-
required: retrievedSchema.required?.includes(key)
|
|
1075
|
-
});
|
|
1076
|
-
maybeAddDefaultToObject(
|
|
1077
|
-
objectDefaults,
|
|
1078
|
-
key,
|
|
1079
|
-
computedDefault,
|
|
1080
|
-
includeUndefinedValues,
|
|
1081
|
-
required,
|
|
1082
|
-
formDataRequired
|
|
1083
|
-
);
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
return objectDefaults;
|
|
1669
|
+
return getObjectDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1087
1670
|
}
|
|
1088
1671
|
case "array": {
|
|
1089
|
-
|
|
1090
|
-
const ignoreMinItemsFlagSet = experimental_defaultFormStateBehavior?.arrayMinItems?.populate === "requiredOnly";
|
|
1091
|
-
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
|
|
1092
|
-
const computeSkipPopulate = experimental_defaultFormStateBehavior?.arrayMinItems?.computeSkipPopulate ?? (() => false);
|
|
1093
|
-
const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
|
|
1094
|
-
if (Array.isArray(defaults)) {
|
|
1095
|
-
defaults = defaults.map((item, idx) => {
|
|
1096
|
-
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
1097
|
-
return computeDefaults(validator, schemaItem, {
|
|
1098
|
-
rootSchema,
|
|
1099
|
-
_recurseList,
|
|
1100
|
-
experimental_defaultFormStateBehavior,
|
|
1101
|
-
parentDefaults: item,
|
|
1102
|
-
required
|
|
1103
|
-
});
|
|
1104
|
-
});
|
|
1105
|
-
}
|
|
1106
|
-
if (Array.isArray(rawFormData)) {
|
|
1107
|
-
const schemaItem = getInnerSchemaForArrayItem(schema);
|
|
1108
|
-
if (neverPopulate) {
|
|
1109
|
-
defaults = rawFormData;
|
|
1110
|
-
} else {
|
|
1111
|
-
defaults = rawFormData.map((item, idx) => {
|
|
1112
|
-
return computeDefaults(validator, schemaItem, {
|
|
1113
|
-
rootSchema,
|
|
1114
|
-
_recurseList,
|
|
1115
|
-
experimental_defaultFormStateBehavior,
|
|
1116
|
-
rawFormData: item,
|
|
1117
|
-
parentDefaults: get8(defaults, [idx]),
|
|
1118
|
-
required
|
|
1119
|
-
});
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
if (neverPopulate) {
|
|
1124
|
-
return defaults ?? emptyDefault;
|
|
1125
|
-
}
|
|
1126
|
-
if (ignoreMinItemsFlagSet && !required) {
|
|
1127
|
-
return defaults ? defaults : void 0;
|
|
1128
|
-
}
|
|
1129
|
-
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1130
|
-
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1131
|
-
return defaults ? defaults : emptyDefault;
|
|
1132
|
-
}
|
|
1133
|
-
const defaultEntries = defaults || [];
|
|
1134
|
-
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
1135
|
-
const fillerDefault = fillerSchema.default;
|
|
1136
|
-
const fillerEntries = new Array(schema.minItems - defaultsLength).fill(
|
|
1137
|
-
computeDefaults(validator, fillerSchema, {
|
|
1138
|
-
parentDefaults: fillerDefault,
|
|
1139
|
-
rootSchema,
|
|
1140
|
-
_recurseList,
|
|
1141
|
-
experimental_defaultFormStateBehavior,
|
|
1142
|
-
required
|
|
1143
|
-
})
|
|
1144
|
-
);
|
|
1145
|
-
return defaultEntries.concat(fillerEntries);
|
|
1672
|
+
return getArrayDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1146
1673
|
}
|
|
1147
1674
|
}
|
|
1148
|
-
return defaults;
|
|
1149
1675
|
}
|
|
1150
|
-
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
|
|
1676
|
+
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1151
1677
|
if (!isObject(theSchema)) {
|
|
1152
1678
|
throw new Error("Invalid schema: " + theSchema);
|
|
1153
1679
|
}
|
|
1154
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1680
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1155
1681
|
const defaults = computeDefaults(validator, schema, {
|
|
1156
1682
|
rootSchema,
|
|
1157
1683
|
includeUndefinedValues,
|
|
1158
1684
|
experimental_defaultFormStateBehavior,
|
|
1159
|
-
|
|
1685
|
+
experimental_customMergeAllOf,
|
|
1686
|
+
rawFormData: formData,
|
|
1687
|
+
shouldMergeDefaultsIntoFormData: true
|
|
1160
1688
|
});
|
|
1161
|
-
if (formData
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1689
|
+
if (isObject(formData) || Array.isArray(formData)) {
|
|
1690
|
+
const { mergeDefaultsIntoFormData } = experimental_defaultFormStateBehavior || {};
|
|
1691
|
+
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
1692
|
+
const result = mergeDefaultsWithFormData(
|
|
1693
|
+
defaults,
|
|
1694
|
+
formData,
|
|
1695
|
+
true,
|
|
1696
|
+
// set to true to add any additional default array entries.
|
|
1697
|
+
defaultSupercedesUndefined,
|
|
1698
|
+
true
|
|
1699
|
+
// set to true to override formData with defaults if they exist.
|
|
1700
|
+
);
|
|
1701
|
+
return result;
|
|
1170
1702
|
}
|
|
1171
|
-
return
|
|
1703
|
+
return defaults;
|
|
1172
1704
|
}
|
|
1173
1705
|
|
|
1174
1706
|
// src/isCustomWidget.ts
|
|
@@ -1181,25 +1713,31 @@
|
|
|
1181
1713
|
}
|
|
1182
1714
|
|
|
1183
1715
|
// src/schema/isFilesArray.ts
|
|
1184
|
-
function isFilesArray(validator, schema, uiSchema = {}, rootSchema) {
|
|
1716
|
+
function isFilesArray(validator, schema, uiSchema = {}, rootSchema, experimental_customMergeAllOf) {
|
|
1185
1717
|
if (uiSchema[UI_WIDGET_KEY] === "files") {
|
|
1186
1718
|
return true;
|
|
1187
1719
|
}
|
|
1188
1720
|
if (schema.items) {
|
|
1189
|
-
const itemsSchema = retrieveSchema(
|
|
1721
|
+
const itemsSchema = retrieveSchema(
|
|
1722
|
+
validator,
|
|
1723
|
+
schema.items,
|
|
1724
|
+
rootSchema,
|
|
1725
|
+
void 0,
|
|
1726
|
+
experimental_customMergeAllOf
|
|
1727
|
+
);
|
|
1190
1728
|
return itemsSchema.type === "string" && itemsSchema.format === "data-url";
|
|
1191
1729
|
}
|
|
1192
1730
|
return false;
|
|
1193
1731
|
}
|
|
1194
1732
|
|
|
1195
1733
|
// src/schema/getDisplayLabel.ts
|
|
1196
|
-
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
|
|
1734
|
+
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions, experimental_customMergeAllOf) {
|
|
1197
1735
|
const uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
1198
1736
|
const { label = true } = uiOptions;
|
|
1199
1737
|
let displayLabel = !!label;
|
|
1200
1738
|
const schemaType = getSchemaType(schema);
|
|
1201
1739
|
if (schemaType === "array") {
|
|
1202
|
-
displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
|
|
1740
|
+
displayLabel = isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || isFilesArray(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) || isCustomWidget(uiSchema);
|
|
1203
1741
|
}
|
|
1204
1742
|
if (schemaType === "object") {
|
|
1205
1743
|
displayLabel = false;
|
|
@@ -1212,48 +1750,47 @@
|
|
|
1212
1750
|
}
|
|
1213
1751
|
return displayLabel;
|
|
1214
1752
|
}
|
|
1215
|
-
function mergeValidationData(validator, validationData, additionalErrorSchema) {
|
|
1216
|
-
if (!additionalErrorSchema) {
|
|
1217
|
-
return validationData;
|
|
1218
|
-
}
|
|
1219
|
-
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
1220
|
-
let errors = validator.toErrorList(additionalErrorSchema);
|
|
1221
|
-
let errorSchema = additionalErrorSchema;
|
|
1222
|
-
if (!isEmpty(oldErrorSchema)) {
|
|
1223
|
-
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
1224
|
-
errors = [...oldErrors].concat(errors);
|
|
1225
|
-
}
|
|
1226
|
-
return { errorSchema, errors };
|
|
1227
|
-
}
|
|
1228
1753
|
var NO_VALUE = Symbol("no Value");
|
|
1229
|
-
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
1754
|
+
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
1230
1755
|
let newFormData;
|
|
1231
|
-
if (
|
|
1756
|
+
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
1232
1757
|
const removeOldSchemaData = {};
|
|
1233
|
-
if (
|
|
1234
|
-
const properties =
|
|
1758
|
+
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
1759
|
+
const properties = get13(oldSchema, PROPERTIES_KEY, {});
|
|
1235
1760
|
Object.keys(properties).forEach((key) => {
|
|
1236
|
-
if (
|
|
1761
|
+
if (has5(data, key)) {
|
|
1237
1762
|
removeOldSchemaData[key] = void 0;
|
|
1238
1763
|
}
|
|
1239
1764
|
});
|
|
1240
1765
|
}
|
|
1241
|
-
const
|
|
1766
|
+
const keys2 = Object.keys(get13(newSchema, PROPERTIES_KEY, {}));
|
|
1242
1767
|
const nestedData = {};
|
|
1243
|
-
|
|
1244
|
-
const formValue =
|
|
1245
|
-
let oldKeyedSchema =
|
|
1246
|
-
let newKeyedSchema =
|
|
1247
|
-
if (
|
|
1248
|
-
oldKeyedSchema = retrieveSchema(
|
|
1768
|
+
keys2.forEach((key) => {
|
|
1769
|
+
const formValue = get13(data, key);
|
|
1770
|
+
let oldKeyedSchema = get13(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1771
|
+
let newKeyedSchema = get13(newSchema, [PROPERTIES_KEY, key], {});
|
|
1772
|
+
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
1773
|
+
oldKeyedSchema = retrieveSchema(
|
|
1774
|
+
validator,
|
|
1775
|
+
oldKeyedSchema,
|
|
1776
|
+
rootSchema,
|
|
1777
|
+
formValue,
|
|
1778
|
+
experimental_customMergeAllOf
|
|
1779
|
+
);
|
|
1249
1780
|
}
|
|
1250
|
-
if (
|
|
1251
|
-
newKeyedSchema = retrieveSchema(
|
|
1781
|
+
if (has5(newKeyedSchema, REF_KEY)) {
|
|
1782
|
+
newKeyedSchema = retrieveSchema(
|
|
1783
|
+
validator,
|
|
1784
|
+
newKeyedSchema,
|
|
1785
|
+
rootSchema,
|
|
1786
|
+
formValue,
|
|
1787
|
+
experimental_customMergeAllOf
|
|
1788
|
+
);
|
|
1252
1789
|
}
|
|
1253
|
-
const oldSchemaTypeForKey =
|
|
1254
|
-
const newSchemaTypeForKey =
|
|
1790
|
+
const oldSchemaTypeForKey = get13(oldKeyedSchema, "type");
|
|
1791
|
+
const newSchemaTypeForKey = get13(newKeyedSchema, "type");
|
|
1255
1792
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1256
|
-
if (
|
|
1793
|
+
if (has5(removeOldSchemaData, key)) {
|
|
1257
1794
|
delete removeOldSchemaData[key];
|
|
1258
1795
|
}
|
|
1259
1796
|
if (newSchemaTypeForKey === "object" || newSchemaTypeForKey === "array" && Array.isArray(formValue)) {
|
|
@@ -1262,23 +1799,24 @@
|
|
|
1262
1799
|
rootSchema,
|
|
1263
1800
|
newKeyedSchema,
|
|
1264
1801
|
oldKeyedSchema,
|
|
1265
|
-
formValue
|
|
1802
|
+
formValue,
|
|
1803
|
+
experimental_customMergeAllOf
|
|
1266
1804
|
);
|
|
1267
1805
|
if (itemData !== void 0 || newSchemaTypeForKey === "array") {
|
|
1268
1806
|
nestedData[key] = itemData;
|
|
1269
1807
|
}
|
|
1270
1808
|
} else {
|
|
1271
|
-
const newOptionDefault =
|
|
1272
|
-
const oldOptionDefault =
|
|
1809
|
+
const newOptionDefault = get13(newKeyedSchema, "default", NO_VALUE);
|
|
1810
|
+
const oldOptionDefault = get13(oldKeyedSchema, "default", NO_VALUE);
|
|
1273
1811
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1274
1812
|
if (oldOptionDefault === formValue) {
|
|
1275
1813
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1276
|
-
} else if (
|
|
1814
|
+
} else if (get13(newKeyedSchema, "readOnly") === true) {
|
|
1277
1815
|
removeOldSchemaData[key] = void 0;
|
|
1278
1816
|
}
|
|
1279
1817
|
}
|
|
1280
|
-
const newOptionConst =
|
|
1281
|
-
const oldOptionConst =
|
|
1818
|
+
const newOptionConst = get13(newKeyedSchema, "const", NO_VALUE);
|
|
1819
|
+
const oldOptionConst = get13(oldKeyedSchema, "const", NO_VALUE);
|
|
1282
1820
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1283
1821
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1284
1822
|
}
|
|
@@ -1290,20 +1828,32 @@
|
|
|
1290
1828
|
...removeOldSchemaData,
|
|
1291
1829
|
...nestedData
|
|
1292
1830
|
};
|
|
1293
|
-
} else if (
|
|
1294
|
-
let oldSchemaItems =
|
|
1295
|
-
let newSchemaItems =
|
|
1831
|
+
} else if (get13(oldSchema, "type") === "array" && get13(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1832
|
+
let oldSchemaItems = get13(oldSchema, "items");
|
|
1833
|
+
let newSchemaItems = get13(newSchema, "items");
|
|
1296
1834
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1297
|
-
if (
|
|
1298
|
-
oldSchemaItems = retrieveSchema(
|
|
1835
|
+
if (has5(oldSchemaItems, REF_KEY)) {
|
|
1836
|
+
oldSchemaItems = retrieveSchema(
|
|
1837
|
+
validator,
|
|
1838
|
+
oldSchemaItems,
|
|
1839
|
+
rootSchema,
|
|
1840
|
+
data,
|
|
1841
|
+
experimental_customMergeAllOf
|
|
1842
|
+
);
|
|
1299
1843
|
}
|
|
1300
|
-
if (
|
|
1301
|
-
newSchemaItems = retrieveSchema(
|
|
1844
|
+
if (has5(newSchemaItems, REF_KEY)) {
|
|
1845
|
+
newSchemaItems = retrieveSchema(
|
|
1846
|
+
validator,
|
|
1847
|
+
newSchemaItems,
|
|
1848
|
+
rootSchema,
|
|
1849
|
+
data,
|
|
1850
|
+
experimental_customMergeAllOf
|
|
1851
|
+
);
|
|
1302
1852
|
}
|
|
1303
|
-
const oldSchemaType =
|
|
1304
|
-
const newSchemaType =
|
|
1853
|
+
const oldSchemaType = get13(oldSchemaItems, "type");
|
|
1854
|
+
const newSchemaType = get13(newSchemaItems, "type");
|
|
1305
1855
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1306
|
-
const maxItems =
|
|
1856
|
+
const maxItems = get13(newSchema, "maxItems", -1);
|
|
1307
1857
|
if (newSchemaType === "object") {
|
|
1308
1858
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1309
1859
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1311,7 +1861,8 @@
|
|
|
1311
1861
|
rootSchema,
|
|
1312
1862
|
newSchemaItems,
|
|
1313
1863
|
oldSchemaItems,
|
|
1314
|
-
aValue
|
|
1864
|
+
aValue,
|
|
1865
|
+
experimental_customMergeAllOf
|
|
1315
1866
|
);
|
|
1316
1867
|
if (itemValue !== void 0 && (maxItems < 0 || newValue.length < maxItems)) {
|
|
1317
1868
|
newValue.push(itemValue);
|
|
@@ -1328,64 +1879,79 @@
|
|
|
1328
1879
|
}
|
|
1329
1880
|
return newFormData;
|
|
1330
1881
|
}
|
|
1331
|
-
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
if (
|
|
1882
|
+
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1883
|
+
const $id = id || idPrefix;
|
|
1884
|
+
const idSchema = { $id };
|
|
1885
|
+
if (typeof schema === "object") {
|
|
1886
|
+
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1887
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1888
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1889
|
+
if (sameSchemaIndex === -1) {
|
|
1890
|
+
return toIdSchemaInternal(
|
|
1891
|
+
validator,
|
|
1892
|
+
_schema,
|
|
1893
|
+
idPrefix,
|
|
1894
|
+
idSeparator,
|
|
1895
|
+
id,
|
|
1896
|
+
rootSchema,
|
|
1897
|
+
formData,
|
|
1898
|
+
_recurseList.concat(_schema),
|
|
1899
|
+
experimental_customMergeAllOf
|
|
1900
|
+
);
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
if (ITEMS_KEY in schema && !get13(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1336
1904
|
return toIdSchemaInternal(
|
|
1337
1905
|
validator,
|
|
1338
|
-
|
|
1906
|
+
get13(schema, ITEMS_KEY),
|
|
1339
1907
|
idPrefix,
|
|
1340
1908
|
idSeparator,
|
|
1341
1909
|
id,
|
|
1342
1910
|
rootSchema,
|
|
1343
1911
|
formData,
|
|
1344
|
-
_recurseList
|
|
1912
|
+
_recurseList,
|
|
1913
|
+
experimental_customMergeAllOf
|
|
1345
1914
|
);
|
|
1346
1915
|
}
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1366
|
-
idSchema[name] = toIdSchemaInternal(
|
|
1367
|
-
validator,
|
|
1368
|
-
isObject(field) ? field : {},
|
|
1369
|
-
idPrefix,
|
|
1370
|
-
idSeparator,
|
|
1371
|
-
fieldId,
|
|
1372
|
-
rootSchema,
|
|
1373
|
-
// It's possible that formData is not an object -- this can happen if an
|
|
1374
|
-
// array item has just been added, but not populated with data yet
|
|
1375
|
-
get8(formData, [name]),
|
|
1376
|
-
_recurseList
|
|
1377
|
-
);
|
|
1916
|
+
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1917
|
+
for (const name in schema.properties) {
|
|
1918
|
+
const field = schema[PROPERTIES_KEY][name];
|
|
1919
|
+
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1920
|
+
idSchema[name] = toIdSchemaInternal(
|
|
1921
|
+
validator,
|
|
1922
|
+
field,
|
|
1923
|
+
idPrefix,
|
|
1924
|
+
idSeparator,
|
|
1925
|
+
fieldId,
|
|
1926
|
+
rootSchema,
|
|
1927
|
+
// It's possible that formData is not an object -- this can happen if an
|
|
1928
|
+
// array item has just been added, but not populated with data yet
|
|
1929
|
+
get13(formData, [name]),
|
|
1930
|
+
_recurseList,
|
|
1931
|
+
experimental_customMergeAllOf
|
|
1932
|
+
);
|
|
1933
|
+
}
|
|
1378
1934
|
}
|
|
1379
1935
|
}
|
|
1380
1936
|
return idSchema;
|
|
1381
1937
|
}
|
|
1382
|
-
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_") {
|
|
1383
|
-
return toIdSchemaInternal(
|
|
1938
|
+
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_", experimental_customMergeAllOf) {
|
|
1939
|
+
return toIdSchemaInternal(
|
|
1940
|
+
validator,
|
|
1941
|
+
schema,
|
|
1942
|
+
idPrefix,
|
|
1943
|
+
idSeparator,
|
|
1944
|
+
id,
|
|
1945
|
+
rootSchema,
|
|
1946
|
+
formData,
|
|
1947
|
+
void 0,
|
|
1948
|
+
experimental_customMergeAllOf
|
|
1949
|
+
);
|
|
1384
1950
|
}
|
|
1385
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1951
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1386
1952
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1387
|
-
const _schema = retrieveSchema(validator, schema, rootSchema, formData);
|
|
1388
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
1953
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1954
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1389
1955
|
if (sameSchemaIndex === -1) {
|
|
1390
1956
|
return toPathSchemaInternal(
|
|
1391
1957
|
validator,
|
|
@@ -1393,7 +1959,8 @@
|
|
|
1393
1959
|
name,
|
|
1394
1960
|
rootSchema,
|
|
1395
1961
|
formData,
|
|
1396
|
-
_recurseList.concat(_schema)
|
|
1962
|
+
_recurseList.concat(_schema),
|
|
1963
|
+
experimental_customMergeAllOf
|
|
1397
1964
|
);
|
|
1398
1965
|
}
|
|
1399
1966
|
}
|
|
@@ -1403,15 +1970,31 @@
|
|
|
1403
1970
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
1404
1971
|
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
1405
1972
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1406
|
-
const index = getClosestMatchingOption(
|
|
1973
|
+
const index = getClosestMatchingOption(
|
|
1974
|
+
validator,
|
|
1975
|
+
rootSchema,
|
|
1976
|
+
formData,
|
|
1977
|
+
xxxOf,
|
|
1978
|
+
0,
|
|
1979
|
+
discriminator,
|
|
1980
|
+
experimental_customMergeAllOf
|
|
1981
|
+
);
|
|
1407
1982
|
const _schema = xxxOf[index];
|
|
1408
1983
|
pathSchema = {
|
|
1409
1984
|
...pathSchema,
|
|
1410
|
-
...toPathSchemaInternal(
|
|
1985
|
+
...toPathSchemaInternal(
|
|
1986
|
+
validator,
|
|
1987
|
+
_schema,
|
|
1988
|
+
name,
|
|
1989
|
+
rootSchema,
|
|
1990
|
+
formData,
|
|
1991
|
+
_recurseList,
|
|
1992
|
+
experimental_customMergeAllOf
|
|
1993
|
+
)
|
|
1411
1994
|
};
|
|
1412
1995
|
}
|
|
1413
1996
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
1414
|
-
|
|
1997
|
+
set(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
|
|
1415
1998
|
}
|
|
1416
1999
|
if (ITEMS_KEY in schema && Array.isArray(formData)) {
|
|
1417
2000
|
const { items: schemaItems, additionalItems: schemaAdditionalItems } = schema;
|
|
@@ -1424,7 +2007,8 @@
|
|
|
1424
2007
|
`${name}.${i}`,
|
|
1425
2008
|
rootSchema,
|
|
1426
2009
|
element,
|
|
1427
|
-
_recurseList
|
|
2010
|
+
_recurseList,
|
|
2011
|
+
experimental_customMergeAllOf
|
|
1428
2012
|
);
|
|
1429
2013
|
} else if (schemaAdditionalItems) {
|
|
1430
2014
|
pathSchema[i] = toPathSchemaInternal(
|
|
@@ -1433,7 +2017,8 @@
|
|
|
1433
2017
|
`${name}.${i}`,
|
|
1434
2018
|
rootSchema,
|
|
1435
2019
|
element,
|
|
1436
|
-
_recurseList
|
|
2020
|
+
_recurseList,
|
|
2021
|
+
experimental_customMergeAllOf
|
|
1437
2022
|
);
|
|
1438
2023
|
} else {
|
|
1439
2024
|
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
@@ -1447,13 +2032,14 @@
|
|
|
1447
2032
|
`${name}.${i}`,
|
|
1448
2033
|
rootSchema,
|
|
1449
2034
|
element,
|
|
1450
|
-
_recurseList
|
|
2035
|
+
_recurseList,
|
|
2036
|
+
experimental_customMergeAllOf
|
|
1451
2037
|
);
|
|
1452
2038
|
});
|
|
1453
2039
|
}
|
|
1454
2040
|
} else if (PROPERTIES_KEY in schema) {
|
|
1455
2041
|
for (const property in schema.properties) {
|
|
1456
|
-
const field =
|
|
2042
|
+
const field = get13(schema, [PROPERTIES_KEY, property], {});
|
|
1457
2043
|
pathSchema[property] = toPathSchemaInternal(
|
|
1458
2044
|
validator,
|
|
1459
2045
|
field,
|
|
@@ -1461,15 +2047,16 @@
|
|
|
1461
2047
|
rootSchema,
|
|
1462
2048
|
// It's possible that formData is not an object -- this can happen if an
|
|
1463
2049
|
// array item has just been added, but not populated with data yet
|
|
1464
|
-
|
|
1465
|
-
_recurseList
|
|
2050
|
+
get13(formData, [property]),
|
|
2051
|
+
_recurseList,
|
|
2052
|
+
experimental_customMergeAllOf
|
|
1466
2053
|
);
|
|
1467
2054
|
}
|
|
1468
2055
|
}
|
|
1469
2056
|
return pathSchema;
|
|
1470
2057
|
}
|
|
1471
|
-
function toPathSchema(validator, schema, name = "", rootSchema, formData) {
|
|
1472
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
|
|
2058
|
+
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2059
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
1473
2060
|
}
|
|
1474
2061
|
|
|
1475
2062
|
// src/createSchemaUtils.ts
|
|
@@ -1479,11 +2066,13 @@
|
|
|
1479
2066
|
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
1480
2067
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
1481
2068
|
* @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
|
|
2069
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1482
2070
|
*/
|
|
1483
|
-
constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
|
|
2071
|
+
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1484
2072
|
this.rootSchema = rootSchema;
|
|
1485
2073
|
this.validator = validator;
|
|
1486
2074
|
this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
|
|
2075
|
+
this.experimental_customMergeAllOf = experimental_customMergeAllOf;
|
|
1487
2076
|
}
|
|
1488
2077
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
1489
2078
|
*
|
|
@@ -1499,13 +2088,55 @@
|
|
|
1499
2088
|
* @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
|
|
1500
2089
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
1501
2090
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
2091
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1502
2092
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
1503
2093
|
*/
|
|
1504
|
-
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
2094
|
+
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
1505
2095
|
if (!validator || !rootSchema) {
|
|
1506
2096
|
return false;
|
|
1507
2097
|
}
|
|
1508
|
-
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
|
|
2098
|
+
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
2099
|
+
}
|
|
2100
|
+
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
2101
|
+
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
2102
|
+
* field is in the `required` list for its parent and if so, it is marked as required on return.
|
|
2103
|
+
*
|
|
2104
|
+
* @param schema - The current node within the JSON schema
|
|
2105
|
+
* @param path - The remaining keys in the path to the desired field
|
|
2106
|
+
* @param [formData] - The form data that is used to determine which oneOf option
|
|
2107
|
+
* @returns - An object that contains the field and its required state. If no field can be found then
|
|
2108
|
+
* `{ field: undefined, isRequired: undefined }` is returned.
|
|
2109
|
+
*/
|
|
2110
|
+
findFieldInSchema(schema, path, formData) {
|
|
2111
|
+
return findFieldInSchema(
|
|
2112
|
+
this.validator,
|
|
2113
|
+
this.rootSchema,
|
|
2114
|
+
schema,
|
|
2115
|
+
path,
|
|
2116
|
+
formData,
|
|
2117
|
+
this.experimental_customMergeAllOf
|
|
2118
|
+
);
|
|
2119
|
+
}
|
|
2120
|
+
/** Finds the oneOf option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` that
|
|
2121
|
+
* matches the `formData[selectorField]` value. For the purposes of this function, `selectorField` is either
|
|
2122
|
+
* `schema.discriminator.propertyName` or `fallbackField`.
|
|
2123
|
+
*
|
|
2124
|
+
* @param schema - The schema element in which to search for the selected oneOf option
|
|
2125
|
+
* @param fallbackField - The field to use as a backup selector field if the schema does not have a required field
|
|
2126
|
+
* @param xxx - Either `oneOf` or `anyOf`, defines which value is being sought
|
|
2127
|
+
* @param [formData={}] - The form data that is used to determine which oneOf option
|
|
2128
|
+
* @returns - The anyOf/oneOf option that matches the selector field in the schema or undefined if nothing is selected
|
|
2129
|
+
*/
|
|
2130
|
+
findSelectedOptionInXxxOf(schema, fallbackField, xxx, formData) {
|
|
2131
|
+
return findSelectedOptionInXxxOf(
|
|
2132
|
+
this.validator,
|
|
2133
|
+
this.rootSchema,
|
|
2134
|
+
schema,
|
|
2135
|
+
fallbackField,
|
|
2136
|
+
xxx,
|
|
2137
|
+
formData,
|
|
2138
|
+
this.experimental_customMergeAllOf
|
|
2139
|
+
);
|
|
1509
2140
|
}
|
|
1510
2141
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
1511
2142
|
* computed to have defaults provided in the `schema`.
|
|
@@ -1524,7 +2155,8 @@
|
|
|
1524
2155
|
formData,
|
|
1525
2156
|
this.rootSchema,
|
|
1526
2157
|
includeUndefinedValues,
|
|
1527
|
-
this.experimental_defaultFormStateBehavior
|
|
2158
|
+
this.experimental_defaultFormStateBehavior,
|
|
2159
|
+
this.experimental_customMergeAllOf
|
|
1528
2160
|
);
|
|
1529
2161
|
}
|
|
1530
2162
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
@@ -1536,7 +2168,14 @@
|
|
|
1536
2168
|
* @returns - True if the label should be displayed or false if it should not
|
|
1537
2169
|
*/
|
|
1538
2170
|
getDisplayLabel(schema, uiSchema, globalOptions) {
|
|
1539
|
-
return getDisplayLabel(
|
|
2171
|
+
return getDisplayLabel(
|
|
2172
|
+
this.validator,
|
|
2173
|
+
schema,
|
|
2174
|
+
uiSchema,
|
|
2175
|
+
this.rootSchema,
|
|
2176
|
+
globalOptions,
|
|
2177
|
+
this.experimental_customMergeAllOf
|
|
2178
|
+
);
|
|
1540
2179
|
}
|
|
1541
2180
|
/** Determines which of the given `options` provided most closely matches the `formData`.
|
|
1542
2181
|
* Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
|
|
@@ -1558,7 +2197,8 @@
|
|
|
1558
2197
|
formData,
|
|
1559
2198
|
options,
|
|
1560
2199
|
selectedOption,
|
|
1561
|
-
discriminatorField
|
|
2200
|
+
discriminatorField,
|
|
2201
|
+
this.experimental_customMergeAllOf
|
|
1562
2202
|
);
|
|
1563
2203
|
}
|
|
1564
2204
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
@@ -1573,18 +2213,16 @@
|
|
|
1573
2213
|
getFirstMatchingOption(formData, options, discriminatorField) {
|
|
1574
2214
|
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
1575
2215
|
}
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
getMatchingOption(formData, options, discriminatorField) {
|
|
1587
|
-
return getMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
2216
|
+
getFromSchema(schema, path, defaultValue) {
|
|
2217
|
+
return getFromSchema(
|
|
2218
|
+
this.validator,
|
|
2219
|
+
this.rootSchema,
|
|
2220
|
+
schema,
|
|
2221
|
+
path,
|
|
2222
|
+
// @ts-expect-error TS2769: No overload matches this call
|
|
2223
|
+
defaultValue,
|
|
2224
|
+
this.experimental_customMergeAllOf
|
|
2225
|
+
);
|
|
1588
2226
|
}
|
|
1589
2227
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
1590
2228
|
*
|
|
@@ -1593,7 +2231,7 @@
|
|
|
1593
2231
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1594
2232
|
*/
|
|
1595
2233
|
isFilesArray(schema, uiSchema) {
|
|
1596
|
-
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
|
|
2234
|
+
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1597
2235
|
}
|
|
1598
2236
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
1599
2237
|
*
|
|
@@ -1601,7 +2239,7 @@
|
|
|
1601
2239
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1602
2240
|
*/
|
|
1603
2241
|
isMultiSelect(schema) {
|
|
1604
|
-
return isMultiSelect(this.validator, schema, this.rootSchema);
|
|
2242
|
+
return isMultiSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1605
2243
|
}
|
|
1606
2244
|
/** Checks to see if the `schema` combination represents a select
|
|
1607
2245
|
*
|
|
@@ -1609,21 +2247,7 @@
|
|
|
1609
2247
|
* @returns - True if schema contains a select, otherwise false
|
|
1610
2248
|
*/
|
|
1611
2249
|
isSelect(schema) {
|
|
1612
|
-
return isSelect(this.validator, schema, this.rootSchema);
|
|
1613
|
-
}
|
|
1614
|
-
/** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in
|
|
1615
|
-
* the two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
|
|
1616
|
-
* `getValidator().toErrorList()` onto the `errors` in the `validationData`. If no `additionalErrorSchema` is passed,
|
|
1617
|
-
* then `validationData` is returned.
|
|
1618
|
-
*
|
|
1619
|
-
* @param validationData - The current `ValidationData` into which to merge the additional errors
|
|
1620
|
-
* @param [additionalErrorSchema] - The additional set of errors
|
|
1621
|
-
* @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
|
|
1622
|
-
* @deprecated - Use the `validationDataMerge()` function exported from `@rjsf/utils` instead. This function will be
|
|
1623
|
-
* removed in the next major release.
|
|
1624
|
-
*/
|
|
1625
|
-
mergeValidationData(validationData, additionalErrorSchema) {
|
|
1626
|
-
return mergeValidationData(this.validator, validationData, additionalErrorSchema);
|
|
2250
|
+
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1627
2251
|
}
|
|
1628
2252
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
1629
2253
|
* dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
|
|
@@ -1634,7 +2258,13 @@
|
|
|
1634
2258
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
1635
2259
|
*/
|
|
1636
2260
|
retrieveSchema(schema, rawFormData) {
|
|
1637
|
-
return retrieveSchema(
|
|
2261
|
+
return retrieveSchema(
|
|
2262
|
+
this.validator,
|
|
2263
|
+
schema,
|
|
2264
|
+
this.rootSchema,
|
|
2265
|
+
rawFormData,
|
|
2266
|
+
this.experimental_customMergeAllOf
|
|
2267
|
+
);
|
|
1638
2268
|
}
|
|
1639
2269
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
|
|
1640
2270
|
* new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
|
|
@@ -1648,7 +2278,14 @@
|
|
|
1648
2278
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
1649
2279
|
*/
|
|
1650
2280
|
sanitizeDataForNewSchema(newSchema, oldSchema, data) {
|
|
1651
|
-
return sanitizeDataForNewSchema(
|
|
2281
|
+
return sanitizeDataForNewSchema(
|
|
2282
|
+
this.validator,
|
|
2283
|
+
this.rootSchema,
|
|
2284
|
+
newSchema,
|
|
2285
|
+
oldSchema,
|
|
2286
|
+
data,
|
|
2287
|
+
this.experimental_customMergeAllOf
|
|
2288
|
+
);
|
|
1652
2289
|
}
|
|
1653
2290
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
1654
2291
|
*
|
|
@@ -1660,7 +2297,16 @@
|
|
|
1660
2297
|
* @returns - The `IdSchema` object for the `schema`
|
|
1661
2298
|
*/
|
|
1662
2299
|
toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
|
|
1663
|
-
return toIdSchema(
|
|
2300
|
+
return toIdSchema(
|
|
2301
|
+
this.validator,
|
|
2302
|
+
schema,
|
|
2303
|
+
id,
|
|
2304
|
+
this.rootSchema,
|
|
2305
|
+
formData,
|
|
2306
|
+
idPrefix,
|
|
2307
|
+
idSeparator,
|
|
2308
|
+
this.experimental_customMergeAllOf
|
|
2309
|
+
);
|
|
1664
2310
|
}
|
|
1665
2311
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1666
2312
|
*
|
|
@@ -1670,11 +2316,23 @@
|
|
|
1670
2316
|
* @returns - The `PathSchema` object for the `schema`
|
|
1671
2317
|
*/
|
|
1672
2318
|
toPathSchema(schema, name, formData) {
|
|
1673
|
-
return toPathSchema(
|
|
2319
|
+
return toPathSchema(
|
|
2320
|
+
this.validator,
|
|
2321
|
+
schema,
|
|
2322
|
+
name,
|
|
2323
|
+
this.rootSchema,
|
|
2324
|
+
formData,
|
|
2325
|
+
this.experimental_customMergeAllOf
|
|
2326
|
+
);
|
|
1674
2327
|
}
|
|
1675
2328
|
};
|
|
1676
|
-
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
1677
|
-
return new SchemaUtils(
|
|
2329
|
+
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
2330
|
+
return new SchemaUtils(
|
|
2331
|
+
validator,
|
|
2332
|
+
rootSchema,
|
|
2333
|
+
experimental_defaultFormStateBehavior,
|
|
2334
|
+
experimental_customMergeAllOf
|
|
2335
|
+
);
|
|
1678
2336
|
}
|
|
1679
2337
|
|
|
1680
2338
|
// src/dataURItoBlob.ts
|
|
@@ -1770,15 +2428,17 @@
|
|
|
1770
2428
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1771
2429
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1772
2430
|
if (Array.isArray(selected)) {
|
|
1773
|
-
return selected.filter((v) => !
|
|
2431
|
+
return selected.filter((v) => !deepEquals(v, value));
|
|
1774
2432
|
}
|
|
1775
|
-
return
|
|
2433
|
+
return deepEquals(value, selected) ? void 0 : selected;
|
|
1776
2434
|
}
|
|
2435
|
+
|
|
2436
|
+
// src/enumOptionsIsSelected.ts
|
|
1777
2437
|
function enumOptionsIsSelected(value, selected) {
|
|
1778
2438
|
if (Array.isArray(selected)) {
|
|
1779
|
-
return selected.some((sel) =>
|
|
2439
|
+
return selected.some((sel) => deepEquals(sel, value));
|
|
1780
2440
|
}
|
|
1781
|
-
return
|
|
2441
|
+
return deepEquals(selected, value);
|
|
1782
2442
|
}
|
|
1783
2443
|
|
|
1784
2444
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1825,10 +2485,10 @@
|
|
|
1825
2485
|
*/
|
|
1826
2486
|
getOrCreateErrorBlock(pathOfError) {
|
|
1827
2487
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
1828
|
-
let errorBlock = hasPath ?
|
|
2488
|
+
let errorBlock = hasPath ? get13(this.errorSchema, pathOfError) : this.errorSchema;
|
|
1829
2489
|
if (!errorBlock && pathOfError) {
|
|
1830
2490
|
errorBlock = {};
|
|
1831
|
-
|
|
2491
|
+
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
1832
2492
|
}
|
|
1833
2493
|
return errorBlock;
|
|
1834
2494
|
}
|
|
@@ -1851,15 +2511,15 @@
|
|
|
1851
2511
|
*/
|
|
1852
2512
|
addErrors(errorOrList, pathOfError) {
|
|
1853
2513
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1854
|
-
let errorsList =
|
|
2514
|
+
let errorsList = get13(errorBlock, ERRORS_KEY);
|
|
1855
2515
|
if (!Array.isArray(errorsList)) {
|
|
1856
2516
|
errorsList = [];
|
|
1857
2517
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
1858
2518
|
}
|
|
1859
2519
|
if (Array.isArray(errorOrList)) {
|
|
1860
|
-
|
|
2520
|
+
set(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, ...errorOrList])]);
|
|
1861
2521
|
} else {
|
|
1862
|
-
errorsList
|
|
2522
|
+
set(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, errorOrList])]);
|
|
1863
2523
|
}
|
|
1864
2524
|
return this;
|
|
1865
2525
|
}
|
|
@@ -1873,8 +2533,8 @@
|
|
|
1873
2533
|
*/
|
|
1874
2534
|
setErrors(errorOrList, pathOfError) {
|
|
1875
2535
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1876
|
-
const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
|
|
1877
|
-
|
|
2536
|
+
const listToAdd = Array.isArray(errorOrList) ? [.../* @__PURE__ */ new Set([...errorOrList])] : [errorOrList];
|
|
2537
|
+
set(errorBlock, ERRORS_KEY, listToAdd);
|
|
1878
2538
|
return this;
|
|
1879
2539
|
}
|
|
1880
2540
|
/** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
|
|
@@ -1886,7 +2546,7 @@
|
|
|
1886
2546
|
*/
|
|
1887
2547
|
clearErrors(pathOfError) {
|
|
1888
2548
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1889
|
-
|
|
2549
|
+
set(errorBlock, ERRORS_KEY, []);
|
|
1890
2550
|
return this;
|
|
1891
2551
|
}
|
|
1892
2552
|
};
|
|
@@ -1958,6 +2618,9 @@
|
|
|
1958
2618
|
if (options.autocomplete) {
|
|
1959
2619
|
inputProps.autoComplete = options.autocomplete;
|
|
1960
2620
|
}
|
|
2621
|
+
if (options.accept) {
|
|
2622
|
+
inputProps.accept = options.accept;
|
|
2623
|
+
}
|
|
1961
2624
|
return inputProps;
|
|
1962
2625
|
}
|
|
1963
2626
|
|
|
@@ -1984,12 +2647,33 @@
|
|
|
1984
2647
|
if (name === "ButtonTemplates") {
|
|
1985
2648
|
return templates[name];
|
|
1986
2649
|
}
|
|
2650
|
+
if (Object.hasOwn(uiOptions, name) && typeof uiOptions[name] === "string" && Object.hasOwn(templates, uiOptions[name])) {
|
|
2651
|
+
const key = uiOptions[name];
|
|
2652
|
+
return templates[key];
|
|
2653
|
+
}
|
|
1987
2654
|
return (
|
|
1988
2655
|
// Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
|
|
1989
2656
|
// To avoid that, we cast uiOptions to `any` before accessing the name field
|
|
1990
2657
|
uiOptions[name] || templates[name]
|
|
1991
2658
|
);
|
|
1992
2659
|
}
|
|
2660
|
+
function getTestIds() {
|
|
2661
|
+
if (typeof process === "undefined" || get13(process, "env.NODE_ENV") !== "test") {
|
|
2662
|
+
return {};
|
|
2663
|
+
}
|
|
2664
|
+
const ids = /* @__PURE__ */ new Map();
|
|
2665
|
+
return new Proxy(
|
|
2666
|
+
{},
|
|
2667
|
+
{
|
|
2668
|
+
get(_obj, prop) {
|
|
2669
|
+
if (!ids.has(prop)) {
|
|
2670
|
+
ids.set(prop, nanoid.nanoid());
|
|
2671
|
+
}
|
|
2672
|
+
return ids.get(prop);
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
);
|
|
2676
|
+
}
|
|
1993
2677
|
var widgetMap = {
|
|
1994
2678
|
boolean: {
|
|
1995
2679
|
checkbox: "CheckboxWidget",
|
|
@@ -2043,13 +2727,13 @@
|
|
|
2043
2727
|
}
|
|
2044
2728
|
};
|
|
2045
2729
|
function mergeWidgetOptions(AWidget) {
|
|
2046
|
-
let MergedWidget =
|
|
2730
|
+
let MergedWidget = get13(AWidget, "MergedWidget");
|
|
2047
2731
|
if (!MergedWidget) {
|
|
2048
2732
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2049
2733
|
MergedWidget = ({ options, ...props }) => {
|
|
2050
2734
|
return /* @__PURE__ */ jsxRuntime.jsx(AWidget, { options: { ...defaultOptions, ...options }, ...props });
|
|
2051
2735
|
};
|
|
2052
|
-
|
|
2736
|
+
set(AWidget, "MergedWidget", MergedWidget);
|
|
2053
2737
|
}
|
|
2054
2738
|
return MergedWidget;
|
|
2055
2739
|
}
|
|
@@ -2087,10 +2771,16 @@
|
|
|
2087
2771
|
}
|
|
2088
2772
|
return hash.toString(16);
|
|
2089
2773
|
}
|
|
2090
|
-
function
|
|
2774
|
+
function sortedJSONStringify(object) {
|
|
2091
2775
|
const allKeys = /* @__PURE__ */ new Set();
|
|
2092
|
-
JSON.stringify(
|
|
2093
|
-
return
|
|
2776
|
+
JSON.stringify(object, (key, value) => (allKeys.add(key), value));
|
|
2777
|
+
return JSON.stringify(object, Array.from(allKeys).sort());
|
|
2778
|
+
}
|
|
2779
|
+
function hashObject(object) {
|
|
2780
|
+
return hashString(sortedJSONStringify(object));
|
|
2781
|
+
}
|
|
2782
|
+
function hashForSchema(schema) {
|
|
2783
|
+
return hashObject(schema);
|
|
2094
2784
|
}
|
|
2095
2785
|
|
|
2096
2786
|
// src/hasWidget.ts
|
|
@@ -2132,6 +2822,9 @@
|
|
|
2132
2822
|
function optionId(id, optionIndex) {
|
|
2133
2823
|
return `${id}-${optionIndex}`;
|
|
2134
2824
|
}
|
|
2825
|
+
function buttonId(id, btn) {
|
|
2826
|
+
return idGenerator(id, btn);
|
|
2827
|
+
}
|
|
2135
2828
|
|
|
2136
2829
|
// src/labelValue.ts
|
|
2137
2830
|
function labelValue(label, hideLabel, fallback) {
|
|
@@ -2142,60 +2835,12 @@
|
|
|
2142
2835
|
function localToUTC(dateString) {
|
|
2143
2836
|
return dateString ? new Date(dateString).toJSON() : void 0;
|
|
2144
2837
|
}
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
return schema.enum[0];
|
|
2150
|
-
}
|
|
2151
|
-
if (CONST_KEY in schema) {
|
|
2152
|
-
return schema.const;
|
|
2153
|
-
}
|
|
2154
|
-
throw new Error("schema cannot be inferred as a constant");
|
|
2155
|
-
}
|
|
2156
|
-
|
|
2157
|
-
// src/optionsList.ts
|
|
2158
|
-
function optionsList(schema, uiSchema) {
|
|
2159
|
-
const schemaWithEnumNames = schema;
|
|
2160
|
-
if (schema.enum) {
|
|
2161
|
-
let enumNames;
|
|
2162
|
-
if (uiSchema) {
|
|
2163
|
-
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
2164
|
-
enumNames = uiEnumNames;
|
|
2165
|
-
}
|
|
2166
|
-
if (!enumNames && schemaWithEnumNames.enumNames) {
|
|
2167
|
-
{
|
|
2168
|
-
console.warn(
|
|
2169
|
-
'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.'
|
|
2170
|
-
);
|
|
2171
|
-
}
|
|
2172
|
-
enumNames = schemaWithEnumNames.enumNames;
|
|
2173
|
-
}
|
|
2174
|
-
return schema.enum.map((value, i) => {
|
|
2175
|
-
const label = enumNames?.[i] || String(value);
|
|
2176
|
-
return { label, value };
|
|
2177
|
-
});
|
|
2178
|
-
}
|
|
2179
|
-
let altSchemas = void 0;
|
|
2180
|
-
let altUiSchemas = void 0;
|
|
2181
|
-
if (schema.anyOf) {
|
|
2182
|
-
altSchemas = schema.anyOf;
|
|
2183
|
-
altUiSchemas = uiSchema?.anyOf;
|
|
2184
|
-
} else if (schema.oneOf) {
|
|
2185
|
-
altSchemas = schema.oneOf;
|
|
2186
|
-
altUiSchemas = uiSchema?.oneOf;
|
|
2838
|
+
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
2839
|
+
const lookupPath = [LOOKUP_MAP_NAME];
|
|
2840
|
+
if (has5(regOrFc, FORM_CONTEXT_NAME)) {
|
|
2841
|
+
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2187
2842
|
}
|
|
2188
|
-
return
|
|
2189
|
-
const { title } = getUiOptions(altUiSchemas?.[index]);
|
|
2190
|
-
const aSchema = aSchemaDef;
|
|
2191
|
-
const value = toConstant(aSchema);
|
|
2192
|
-
const label = title || aSchema.title || String(value);
|
|
2193
|
-
return {
|
|
2194
|
-
schema: aSchema,
|
|
2195
|
-
label,
|
|
2196
|
-
value
|
|
2197
|
-
};
|
|
2198
|
-
});
|
|
2843
|
+
return get13(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2199
2844
|
}
|
|
2200
2845
|
|
|
2201
2846
|
// src/orderProperties.ts
|
|
@@ -2308,7 +2953,7 @@
|
|
|
2308
2953
|
return Object.keys(errorSchema).reduce((acc, key) => {
|
|
2309
2954
|
if (key !== ERRORS_KEY) {
|
|
2310
2955
|
const childSchema = errorSchema[key];
|
|
2311
|
-
if (
|
|
2956
|
+
if (isPlainObject4(childSchema)) {
|
|
2312
2957
|
acc = acc.concat(toErrorList(childSchema, [...fieldPath, key]));
|
|
2313
2958
|
}
|
|
2314
2959
|
}
|
|
@@ -2337,7 +2982,7 @@
|
|
|
2337
2982
|
return acc;
|
|
2338
2983
|
} else {
|
|
2339
2984
|
const childSchema = errorHandler[key];
|
|
2340
|
-
if (
|
|
2985
|
+
if (isPlainObject4(childSchema)) {
|
|
2341
2986
|
return {
|
|
2342
2987
|
...acc,
|
|
2343
2988
|
[key]: unwrapErrorHandler(childSchema)
|
|
@@ -2370,7 +3015,7 @@
|
|
|
2370
3015
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
2371
3016
|
let errors = toErrorList(additionalErrorSchema);
|
|
2372
3017
|
let errorSchema = additionalErrorSchema;
|
|
2373
|
-
if (!
|
|
3018
|
+
if (!isEmpty2(oldErrorSchema)) {
|
|
2374
3019
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
2375
3020
|
errors = [...oldErrors].concat(errors);
|
|
2376
3021
|
}
|
|
@@ -2398,16 +3043,33 @@
|
|
|
2398
3043
|
if (Array.isArray(schemaNode)) {
|
|
2399
3044
|
return withIdRefPrefixArray([...schemaNode]);
|
|
2400
3045
|
}
|
|
2401
|
-
if (
|
|
3046
|
+
if (isObject3(schemaNode)) {
|
|
2402
3047
|
return withIdRefPrefixObject({ ...schemaNode });
|
|
2403
3048
|
}
|
|
2404
3049
|
return schemaNode;
|
|
2405
3050
|
}
|
|
3051
|
+
function getChangedFields(a, b) {
|
|
3052
|
+
const aIsPlainObject = isPlainObject4(a);
|
|
3053
|
+
const bIsPlainObject = isPlainObject4(b);
|
|
3054
|
+
if (a === b || !aIsPlainObject && !bIsPlainObject) {
|
|
3055
|
+
return [];
|
|
3056
|
+
}
|
|
3057
|
+
if (aIsPlainObject && !bIsPlainObject) {
|
|
3058
|
+
return keys(a);
|
|
3059
|
+
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3060
|
+
return keys(b);
|
|
3061
|
+
} else {
|
|
3062
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get13(b, key))));
|
|
3063
|
+
const diffFields = difference(keys(b), keys(a));
|
|
3064
|
+
return [...unequalFields, ...diffFields];
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
2406
3067
|
|
|
2407
3068
|
// src/enums.ts
|
|
2408
3069
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
2409
3070
|
TranslatableString2["ArrayItemTitle"] = "Item";
|
|
2410
3071
|
TranslatableString2["MissingItems"] = "Missing items definition";
|
|
3072
|
+
TranslatableString2["EmptyArray"] = "No items yet. Use the button below to add some.";
|
|
2411
3073
|
TranslatableString2["YesLabel"] = "Yes";
|
|
2412
3074
|
TranslatableString2["NoLabel"] = "No";
|
|
2413
3075
|
TranslatableString2["CloseLabel"] = "Close";
|
|
@@ -2462,12 +3124,12 @@
|
|
|
2462
3124
|
* @param hash - The hash value at which to map the schema
|
|
2463
3125
|
*/
|
|
2464
3126
|
addSchema(schema, hash) {
|
|
2465
|
-
const key =
|
|
3127
|
+
const key = get13(schema, ID_KEY, hash);
|
|
2466
3128
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2467
3129
|
const existing = this.schemaMap[key];
|
|
2468
3130
|
if (!existing) {
|
|
2469
3131
|
this.schemaMap[key] = identifiedSchema;
|
|
2470
|
-
} else if (!
|
|
3132
|
+
} else if (!deepEquals(existing, identifiedSchema)) {
|
|
2471
3133
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2472
3134
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2473
3135
|
throw new Error(
|
|
@@ -2489,7 +3151,7 @@
|
|
|
2489
3151
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2490
3152
|
*/
|
|
2491
3153
|
isValid(schema, _formData, rootSchema) {
|
|
2492
|
-
if (!
|
|
3154
|
+
if (!deepEquals(rootSchema, this.rootSchema)) {
|
|
2493
3155
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2494
3156
|
}
|
|
2495
3157
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2529,7 +3191,7 @@
|
|
|
2529
3191
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2530
3192
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
2531
3193
|
schemas.forEach((schema2) => {
|
|
2532
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
3194
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, schema2));
|
|
2533
3195
|
if (sameSchemaIndex === -1) {
|
|
2534
3196
|
recurseList.push(schema2);
|
|
2535
3197
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
@@ -2561,21 +3223,27 @@
|
|
|
2561
3223
|
exports.DEFAULT_KEY = DEFAULT_KEY;
|
|
2562
3224
|
exports.DEFINITIONS_KEY = DEFINITIONS_KEY;
|
|
2563
3225
|
exports.DEPENDENCIES_KEY = DEPENDENCIES_KEY;
|
|
3226
|
+
exports.DISCRIMINATOR_PATH = DISCRIMINATOR_PATH;
|
|
2564
3227
|
exports.ENUM_KEY = ENUM_KEY;
|
|
2565
3228
|
exports.ERRORS_KEY = ERRORS_KEY;
|
|
2566
3229
|
exports.ErrorSchemaBuilder = ErrorSchemaBuilder;
|
|
3230
|
+
exports.FORM_CONTEXT_NAME = FORM_CONTEXT_NAME;
|
|
2567
3231
|
exports.ID_KEY = ID_KEY;
|
|
2568
3232
|
exports.IF_KEY = IF_KEY;
|
|
2569
3233
|
exports.ITEMS_KEY = ITEMS_KEY;
|
|
3234
|
+
exports.JSON_SCHEMA_DRAFT_2020_12 = JSON_SCHEMA_DRAFT_2020_12;
|
|
2570
3235
|
exports.JUNK_OPTION_ID = JUNK_OPTION_ID;
|
|
3236
|
+
exports.LOOKUP_MAP_NAME = LOOKUP_MAP_NAME;
|
|
2571
3237
|
exports.NAME_KEY = NAME_KEY;
|
|
2572
3238
|
exports.ONE_OF_KEY = ONE_OF_KEY;
|
|
3239
|
+
exports.PATTERN_PROPERTIES_KEY = PATTERN_PROPERTIES_KEY;
|
|
2573
3240
|
exports.PROPERTIES_KEY = PROPERTIES_KEY;
|
|
3241
|
+
exports.READONLY_KEY = READONLY_KEY;
|
|
2574
3242
|
exports.REF_KEY = REF_KEY;
|
|
2575
3243
|
exports.REQUIRED_KEY = REQUIRED_KEY;
|
|
2576
3244
|
exports.RJSF_ADDITIONAL_PROPERTIES_FLAG = RJSF_ADDITIONAL_PROPERTIES_FLAG;
|
|
2577
|
-
exports.RJSF_ADDITONAL_PROPERTIES_FLAG = RJSF_ADDITONAL_PROPERTIES_FLAG;
|
|
2578
3245
|
exports.ROOT_SCHEMA_PREFIX = ROOT_SCHEMA_PREFIX;
|
|
3246
|
+
exports.SCHEMA_KEY = SCHEMA_KEY;
|
|
2579
3247
|
exports.SUBMIT_BTN_OPTIONS_KEY = SUBMIT_BTN_OPTIONS_KEY;
|
|
2580
3248
|
exports.TranslatableString = TranslatableString;
|
|
2581
3249
|
exports.UI_FIELD_KEY = UI_FIELD_KEY;
|
|
@@ -2585,6 +3253,7 @@
|
|
|
2585
3253
|
exports.allowAdditionalItems = allowAdditionalItems;
|
|
2586
3254
|
exports.ariaDescribedByIds = ariaDescribedByIds;
|
|
2587
3255
|
exports.asNumber = asNumber;
|
|
3256
|
+
exports.buttonId = buttonId;
|
|
2588
3257
|
exports.canExpand = canExpand;
|
|
2589
3258
|
exports.createErrorHandler = createErrorHandler;
|
|
2590
3259
|
exports.createSchemaUtils = createSchemaUtils;
|
|
@@ -2600,24 +3269,30 @@
|
|
|
2600
3269
|
exports.enumOptionsValueForIndex = enumOptionsValueForIndex;
|
|
2601
3270
|
exports.errorId = errorId;
|
|
2602
3271
|
exports.examplesId = examplesId;
|
|
3272
|
+
exports.findFieldInSchema = findFieldInSchema;
|
|
2603
3273
|
exports.findSchemaDefinition = findSchemaDefinition;
|
|
3274
|
+
exports.findSelectedOptionInXxxOf = findSelectedOptionInXxxOf;
|
|
3275
|
+
exports.getChangedFields = getChangedFields;
|
|
2604
3276
|
exports.getClosestMatchingOption = getClosestMatchingOption;
|
|
2605
3277
|
exports.getDateElementProps = getDateElementProps;
|
|
2606
3278
|
exports.getDefaultFormState = getDefaultFormState;
|
|
2607
3279
|
exports.getDiscriminatorFieldFromSchema = getDiscriminatorFieldFromSchema;
|
|
2608
3280
|
exports.getDisplayLabel = getDisplayLabel;
|
|
2609
3281
|
exports.getFirstMatchingOption = getFirstMatchingOption;
|
|
3282
|
+
exports.getFromSchema = getFromSchema;
|
|
2610
3283
|
exports.getInputProps = getInputProps;
|
|
2611
|
-
exports.getMatchingOption = getMatchingOption;
|
|
2612
3284
|
exports.getOptionMatchingSimpleDiscriminator = getOptionMatchingSimpleDiscriminator;
|
|
2613
3285
|
exports.getSchemaType = getSchemaType;
|
|
2614
3286
|
exports.getSubmitButtonOptions = getSubmitButtonOptions;
|
|
2615
3287
|
exports.getTemplate = getTemplate;
|
|
3288
|
+
exports.getTestIds = getTestIds;
|
|
2616
3289
|
exports.getUiOptions = getUiOptions;
|
|
2617
3290
|
exports.getWidget = getWidget;
|
|
2618
3291
|
exports.guessType = guessType;
|
|
2619
3292
|
exports.hasWidget = hasWidget;
|
|
2620
3293
|
exports.hashForSchema = hashForSchema;
|
|
3294
|
+
exports.hashObject = hashObject;
|
|
3295
|
+
exports.hashString = hashString;
|
|
2621
3296
|
exports.helpId = helpId;
|
|
2622
3297
|
exports.isConstant = isConstant;
|
|
2623
3298
|
exports.isCustomWidget = isCustomWidget;
|
|
@@ -2628,10 +3303,10 @@
|
|
|
2628
3303
|
exports.isSelect = isSelect;
|
|
2629
3304
|
exports.labelValue = labelValue;
|
|
2630
3305
|
exports.localToUTC = localToUTC;
|
|
3306
|
+
exports.lookupFromFormContext = lookupFromFormContext;
|
|
2631
3307
|
exports.mergeDefaultsWithFormData = mergeDefaultsWithFormData;
|
|
2632
3308
|
exports.mergeObjects = mergeObjects;
|
|
2633
3309
|
exports.mergeSchemas = mergeSchemas;
|
|
2634
|
-
exports.mergeValidationData = mergeValidationData;
|
|
2635
3310
|
exports.optionId = optionId;
|
|
2636
3311
|
exports.optionsList = optionsList;
|
|
2637
3312
|
exports.orderProperties = orderProperties;
|
|
@@ -2644,6 +3319,7 @@
|
|
|
2644
3319
|
exports.schemaParser = schemaParser;
|
|
2645
3320
|
exports.schemaRequiresTrueValue = schemaRequiresTrueValue;
|
|
2646
3321
|
exports.shouldRender = shouldRender;
|
|
3322
|
+
exports.sortedJSONStringify = sortedJSONStringify;
|
|
2647
3323
|
exports.titleId = titleId;
|
|
2648
3324
|
exports.toConstant = toConstant;
|
|
2649
3325
|
exports.toDateString = toDateString;
|