@rjsf/utils 6.0.0-alpha.0 → 6.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1340 -639
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +1316 -615
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +1262 -589
- package/lib/ErrorSchemaBuilder.d.ts +8 -4
- package/lib/ErrorSchemaBuilder.js +10 -8
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -1
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +1 -1
- package/lib/canExpand.js +2 -2
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.d.ts +9 -0
- package/lib/constIsAjvDataReference.js +15 -0
- package/lib/constIsAjvDataReference.js.map +1 -0
- package/lib/constants.d.ts +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 +53 -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 +309 -166
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +3 -2
- package/lib/schema/getDisplayLabel.js +10 -9
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +70 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +14 -0
- package/lib/schema/getFromSchema.js +39 -0
- package/lib/schema/getFromSchema.js.map +1 -0
- package/lib/schema/index.d.ts +15 -14
- package/lib/schema/index.js +15 -14
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +3 -2
- package/lib/schema/isFilesArray.js +5 -4
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.d.ts +3 -2
- package/lib/schema/isMultiSelect.js +4 -3
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +3 -2
- package/lib/schema/isSelect.js +5 -4
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +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 +165 -139
- 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 +54 -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 +453 -191
- package/src/schema/getDisplayLabel.ts +7 -4
- package/src/schema/getFirstMatchingOption.ts +79 -4
- package/src/schema/getFromSchema.ts +100 -0
- package/src/schema/index.ts +6 -4
- package/src/schema/isFilesArray.ts +18 -3
- package/src/schema/isMultiSelect.ts +10 -4
- package/src/schema/isSelect.ts +5 -3
- package/src/schema/retrieveSchema.ts +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 +271 -181
- 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.get12, 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, get12, 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 = ID_KEY in rootSchema ? rootSchema[ID_KEY] : void 0) {
|
|
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 = ID_KEY in rootSchema ? rootSchema[ID_KEY] : void 0) {
|
|
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 = get12(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 = get12(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 = get12(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 = get12(formData, discriminatorField);
|
|
325
|
+
const discriminator = get12(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
|
+
formData,
|
|
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: get12(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(get12(formData, [key])) };
|
|
606
|
+
}
|
|
499
607
|
} else {
|
|
500
|
-
additionalProperties = { type: guessType(
|
|
608
|
+
additionalProperties = { type: guessType(get12(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
|
+
}
|
|
542
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
|
+
}
|
|
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
|
+
rawFormData,
|
|
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 && get12(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 = get12(formData, selectorField);
|
|
891
|
+
if (data !== void 0) {
|
|
892
|
+
return xxxOfs.find((xxx2) => {
|
|
893
|
+
return isEqual(
|
|
894
|
+
get12(xxx2, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get12(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 = get12(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
|
+
get12(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
|
+
get12(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 = get12(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
|
+
get12(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 = get12(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 ? get12(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 = get12(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
1286
|
+
value = get12(innerSchema, DEFAULT_KEY, get12(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
|
-
|
|
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;
|
|
953
1355
|
const 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,23 @@
|
|
|
965
1370
|
updatedRecurseList = _recurseList.concat(refName);
|
|
966
1371
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
967
1372
|
}
|
|
1373
|
+
if (schemaToCompute && !defaults) {
|
|
1374
|
+
defaults = schema.default;
|
|
1375
|
+
}
|
|
968
1376
|
} else if (DEPENDENCIES_KEY in schema) {
|
|
969
|
-
const
|
|
1377
|
+
const defaultFormData = {
|
|
1378
|
+
...getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults),
|
|
1379
|
+
...formData
|
|
1380
|
+
};
|
|
1381
|
+
const resolvedSchema = resolveDependencies(
|
|
1382
|
+
validator,
|
|
1383
|
+
schema,
|
|
1384
|
+
rootSchema,
|
|
1385
|
+
false,
|
|
1386
|
+
[],
|
|
1387
|
+
defaultFormData,
|
|
1388
|
+
experimental_customMergeAllOf
|
|
1389
|
+
);
|
|
970
1390
|
schemaToCompute = resolvedSchema[0];
|
|
971
1391
|
} else if (isFixedItems(schema)) {
|
|
972
1392
|
defaults = schema.items.map(
|
|
@@ -975,9 +1395,11 @@
|
|
|
975
1395
|
includeUndefinedValues,
|
|
976
1396
|
_recurseList,
|
|
977
1397
|
experimental_defaultFormStateBehavior,
|
|
1398
|
+
experimental_customMergeAllOf,
|
|
978
1399
|
parentDefaults: Array.isArray(parentDefaults) ? parentDefaults[idx] : void 0,
|
|
979
1400
|
rawFormData: formData,
|
|
980
|
-
required
|
|
1401
|
+
required,
|
|
1402
|
+
shouldMergeDefaultsIntoFormData
|
|
981
1403
|
})
|
|
982
1404
|
);
|
|
983
1405
|
} else if (ONE_OF_KEY in schema) {
|
|
@@ -986,13 +1408,21 @@
|
|
|
986
1408
|
return void 0;
|
|
987
1409
|
}
|
|
988
1410
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1411
|
+
const { type = "null" } = remaining;
|
|
1412
|
+
if (!Array.isArray(type) && PRIMITIVE_TYPES.includes(type) && experimental_dfsb_to_compute?.constAsDefaults === "skipOneOf") {
|
|
1413
|
+
experimental_dfsb_to_compute = {
|
|
1414
|
+
...experimental_dfsb_to_compute,
|
|
1415
|
+
constAsDefaults: "never"
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
989
1418
|
schemaToCompute = oneOf[getClosestMatchingOption(
|
|
990
1419
|
validator,
|
|
991
1420
|
rootSchema,
|
|
992
|
-
|
|
1421
|
+
rawFormData ?? schema.default,
|
|
993
1422
|
oneOf,
|
|
994
1423
|
0,
|
|
995
|
-
discriminator
|
|
1424
|
+
discriminator,
|
|
1425
|
+
experimental_customMergeAllOf
|
|
996
1426
|
)];
|
|
997
1427
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
998
1428
|
} else if (ANY_OF_KEY in schema) {
|
|
@@ -1004,171 +1434,270 @@
|
|
|
1004
1434
|
schemaToCompute = anyOf[getClosestMatchingOption(
|
|
1005
1435
|
validator,
|
|
1006
1436
|
rootSchema,
|
|
1007
|
-
|
|
1437
|
+
rawFormData ?? schema.default,
|
|
1008
1438
|
anyOf,
|
|
1009
1439
|
0,
|
|
1010
|
-
discriminator
|
|
1440
|
+
discriminator,
|
|
1441
|
+
experimental_customMergeAllOf
|
|
1011
1442
|
)];
|
|
1012
1443
|
schemaToCompute = mergeSchemas(remaining, schemaToCompute);
|
|
1013
1444
|
}
|
|
1014
|
-
if (schemaToCompute) {
|
|
1015
|
-
return computeDefaults(validator, schemaToCompute, {
|
|
1445
|
+
if (schemaToCompute) {
|
|
1446
|
+
return computeDefaults(validator, schemaToCompute, {
|
|
1447
|
+
rootSchema,
|
|
1448
|
+
includeUndefinedValues,
|
|
1449
|
+
_recurseList: updatedRecurseList,
|
|
1450
|
+
experimental_defaultFormStateBehavior: experimental_dfsb_to_compute,
|
|
1451
|
+
experimental_customMergeAllOf,
|
|
1452
|
+
parentDefaults: defaults,
|
|
1453
|
+
rawFormData: formData,
|
|
1454
|
+
required,
|
|
1455
|
+
shouldMergeDefaultsIntoFormData
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
if (defaults === void 0) {
|
|
1459
|
+
defaults = schema.default;
|
|
1460
|
+
}
|
|
1461
|
+
const defaultBasedOnSchemaType = getDefaultBasedOnSchemaType(validator, schema, computeDefaultsProps, defaults);
|
|
1462
|
+
let defaultsWithFormData = defaultBasedOnSchemaType ?? defaults;
|
|
1463
|
+
if (shouldMergeDefaultsIntoFormData) {
|
|
1464
|
+
const { arrayMinItems = {} } = experimental_defaultFormStateBehavior || {};
|
|
1465
|
+
const { mergeExtraDefaults } = arrayMinItems;
|
|
1466
|
+
const matchingFormData = ensureFormDataMatchingSchema(
|
|
1467
|
+
validator,
|
|
1468
|
+
schema,
|
|
1469
|
+
rootSchema,
|
|
1470
|
+
rawFormData,
|
|
1471
|
+
experimental_defaultFormStateBehavior,
|
|
1472
|
+
experimental_customMergeAllOf
|
|
1473
|
+
);
|
|
1474
|
+
if (!isObject(rawFormData) || ALL_OF_KEY in schema) {
|
|
1475
|
+
defaultsWithFormData = mergeDefaultsWithFormData(
|
|
1476
|
+
defaultsWithFormData,
|
|
1477
|
+
matchingFormData,
|
|
1478
|
+
mergeExtraDefaults,
|
|
1479
|
+
true
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
return defaultsWithFormData;
|
|
1484
|
+
}
|
|
1485
|
+
function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1486
|
+
const isSelectField = !isConstant(schema) && isSelect(validator, schema, rootSchema, experimental_customMergeAllOf);
|
|
1487
|
+
let validFormData = formData;
|
|
1488
|
+
if (isSelectField) {
|
|
1489
|
+
const getOptionsList = optionsList(schema);
|
|
1490
|
+
const isValid = getOptionsList?.some((option) => deepEquals(option.value, formData));
|
|
1491
|
+
validFormData = isValid ? formData : void 0;
|
|
1492
|
+
}
|
|
1493
|
+
const constTakesPrecedence = schema[CONST_KEY] && experimental_defaultFormStateBehavior?.constAsDefaults === "always";
|
|
1494
|
+
if (constTakesPrecedence) {
|
|
1495
|
+
validFormData = schema.const;
|
|
1496
|
+
}
|
|
1497
|
+
return validFormData;
|
|
1498
|
+
}
|
|
1499
|
+
function getObjectDefaults(validator, rawSchema, {
|
|
1500
|
+
rawFormData,
|
|
1501
|
+
rootSchema = {},
|
|
1502
|
+
includeUndefinedValues = false,
|
|
1503
|
+
_recurseList = [],
|
|
1504
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1505
|
+
experimental_customMergeAllOf = void 0,
|
|
1506
|
+
required,
|
|
1507
|
+
shouldMergeDefaultsIntoFormData
|
|
1508
|
+
} = {}, defaults) {
|
|
1509
|
+
{
|
|
1510
|
+
const formData = isObject(rawFormData) ? rawFormData : {};
|
|
1511
|
+
const schema = rawSchema;
|
|
1512
|
+
const retrievedSchema = experimental_defaultFormStateBehavior?.allOf === "populateDefaults" && ALL_OF_KEY in schema ? retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf) : schema;
|
|
1513
|
+
const parentConst = retrievedSchema[CONST_KEY];
|
|
1514
|
+
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1515
|
+
(acc, key) => {
|
|
1516
|
+
const propertySchema = get12(retrievedSchema, [PROPERTIES_KEY, key], {});
|
|
1517
|
+
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1518
|
+
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1519
|
+
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
1520
|
+
rootSchema,
|
|
1521
|
+
_recurseList,
|
|
1522
|
+
experimental_defaultFormStateBehavior,
|
|
1523
|
+
experimental_customMergeAllOf,
|
|
1524
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1525
|
+
parentDefaults: get12(defaults, [key]),
|
|
1526
|
+
rawFormData: get12(formData, [key]),
|
|
1527
|
+
required: retrievedSchema.required?.includes(key),
|
|
1528
|
+
shouldMergeDefaultsIntoFormData
|
|
1529
|
+
});
|
|
1530
|
+
maybeAddDefaultToObject(
|
|
1531
|
+
acc,
|
|
1532
|
+
key,
|
|
1533
|
+
computedDefault,
|
|
1534
|
+
includeUndefinedValues,
|
|
1535
|
+
required,
|
|
1536
|
+
retrievedSchema.required,
|
|
1537
|
+
experimental_defaultFormStateBehavior,
|
|
1538
|
+
hasConst
|
|
1539
|
+
);
|
|
1540
|
+
return acc;
|
|
1541
|
+
},
|
|
1542
|
+
{}
|
|
1543
|
+
);
|
|
1544
|
+
if (retrievedSchema.additionalProperties) {
|
|
1545
|
+
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
1546
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
1547
|
+
if (isObject(defaults)) {
|
|
1548
|
+
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys2.add(key));
|
|
1549
|
+
}
|
|
1550
|
+
const formDataRequired = [];
|
|
1551
|
+
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
1552
|
+
keys2.add(key);
|
|
1553
|
+
formDataRequired.push(key);
|
|
1554
|
+
});
|
|
1555
|
+
keys2.forEach((key) => {
|
|
1556
|
+
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
1557
|
+
rootSchema,
|
|
1558
|
+
_recurseList,
|
|
1559
|
+
experimental_defaultFormStateBehavior,
|
|
1560
|
+
experimental_customMergeAllOf,
|
|
1561
|
+
includeUndefinedValues: includeUndefinedValues === true,
|
|
1562
|
+
parentDefaults: get12(defaults, [key]),
|
|
1563
|
+
rawFormData: get12(formData, [key]),
|
|
1564
|
+
required: retrievedSchema.required?.includes(key),
|
|
1565
|
+
shouldMergeDefaultsIntoFormData
|
|
1566
|
+
});
|
|
1567
|
+
maybeAddDefaultToObject(
|
|
1568
|
+
objectDefaults,
|
|
1569
|
+
key,
|
|
1570
|
+
computedDefault,
|
|
1571
|
+
includeUndefinedValues,
|
|
1572
|
+
required,
|
|
1573
|
+
formDataRequired
|
|
1574
|
+
);
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
return objectDefaults;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
function getArrayDefaults(validator, rawSchema, {
|
|
1581
|
+
rawFormData,
|
|
1582
|
+
rootSchema = {},
|
|
1583
|
+
_recurseList = [],
|
|
1584
|
+
experimental_defaultFormStateBehavior = void 0,
|
|
1585
|
+
experimental_customMergeAllOf = void 0,
|
|
1586
|
+
required,
|
|
1587
|
+
shouldMergeDefaultsIntoFormData
|
|
1588
|
+
} = {}, defaults) {
|
|
1589
|
+
const schema = rawSchema;
|
|
1590
|
+
const arrayMinItemsStateBehavior = experimental_defaultFormStateBehavior?.arrayMinItems ?? {};
|
|
1591
|
+
const { populate: arrayMinItemsPopulate, mergeExtraDefaults: arrayMergeExtraDefaults } = arrayMinItemsStateBehavior;
|
|
1592
|
+
const neverPopulate = arrayMinItemsPopulate === "never";
|
|
1593
|
+
const ignoreMinItemsFlagSet = arrayMinItemsPopulate === "requiredOnly";
|
|
1594
|
+
const isPopulateAll = arrayMinItemsPopulate === "all" || !neverPopulate && !ignoreMinItemsFlagSet;
|
|
1595
|
+
const computeSkipPopulate = arrayMinItemsStateBehavior?.computeSkipPopulate ?? (() => false);
|
|
1596
|
+
const isSkipEmptyDefaults = experimental_defaultFormStateBehavior?.emptyObjectFields === "skipEmptyDefaults";
|
|
1597
|
+
const emptyDefault = isSkipEmptyDefaults ? void 0 : [];
|
|
1598
|
+
if (Array.isArray(defaults)) {
|
|
1599
|
+
defaults = defaults.map((item, idx) => {
|
|
1600
|
+
const schemaItem = getInnerSchemaForArrayItem(schema, 2 /* Fallback */, idx);
|
|
1601
|
+
return computeDefaults(validator, schemaItem, {
|
|
1602
|
+
rootSchema,
|
|
1603
|
+
_recurseList,
|
|
1604
|
+
experimental_defaultFormStateBehavior,
|
|
1605
|
+
experimental_customMergeAllOf,
|
|
1606
|
+
parentDefaults: item,
|
|
1607
|
+
required,
|
|
1608
|
+
shouldMergeDefaultsIntoFormData
|
|
1609
|
+
});
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1612
|
+
if (Array.isArray(rawFormData)) {
|
|
1613
|
+
const schemaItem = getInnerSchemaForArrayItem(schema);
|
|
1614
|
+
if (neverPopulate) {
|
|
1615
|
+
defaults = rawFormData;
|
|
1616
|
+
} else {
|
|
1617
|
+
const itemDefaults = rawFormData.map((item, idx) => {
|
|
1618
|
+
return computeDefaults(validator, schemaItem, {
|
|
1619
|
+
rootSchema,
|
|
1620
|
+
_recurseList,
|
|
1621
|
+
experimental_defaultFormStateBehavior,
|
|
1622
|
+
experimental_customMergeAllOf,
|
|
1623
|
+
rawFormData: item,
|
|
1624
|
+
parentDefaults: get12(defaults, [idx]),
|
|
1625
|
+
required,
|
|
1626
|
+
shouldMergeDefaultsIntoFormData
|
|
1627
|
+
});
|
|
1628
|
+
});
|
|
1629
|
+
const mergeExtraDefaults = (ignoreMinItemsFlagSet && required || isPopulateAll) && arrayMergeExtraDefaults;
|
|
1630
|
+
defaults = mergeDefaultsWithFormData(defaults, itemDefaults, mergeExtraDefaults);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
const hasConst = isObject(schema) && CONST_KEY in schema && experimental_defaultFormStateBehavior?.constAsDefaults !== "never";
|
|
1634
|
+
if (hasConst === false) {
|
|
1635
|
+
if (neverPopulate) {
|
|
1636
|
+
return defaults ?? emptyDefault;
|
|
1637
|
+
}
|
|
1638
|
+
if (ignoreMinItemsFlagSet && !required) {
|
|
1639
|
+
return defaults ? defaults : void 0;
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
const defaultsLength = Array.isArray(defaults) ? defaults.length : 0;
|
|
1643
|
+
if (!schema.minItems || isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || computeSkipPopulate(validator, schema, rootSchema) || schema.minItems <= defaultsLength) {
|
|
1644
|
+
return defaults ? defaults : emptyDefault;
|
|
1645
|
+
}
|
|
1646
|
+
const defaultEntries = defaults || [];
|
|
1647
|
+
const fillerSchema = getInnerSchemaForArrayItem(schema, 1 /* Invert */);
|
|
1648
|
+
const fillerDefault = fillerSchema.default;
|
|
1649
|
+
const fillerEntries = new Array(schema.minItems - defaultsLength).fill(
|
|
1650
|
+
computeDefaults(validator, fillerSchema, {
|
|
1651
|
+
parentDefaults: fillerDefault,
|
|
1016
1652
|
rootSchema,
|
|
1017
|
-
|
|
1018
|
-
_recurseList: updatedRecurseList,
|
|
1653
|
+
_recurseList,
|
|
1019
1654
|
experimental_defaultFormStateBehavior,
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
})
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
switch (getSchemaType(
|
|
1655
|
+
experimental_customMergeAllOf,
|
|
1656
|
+
required,
|
|
1657
|
+
shouldMergeDefaultsIntoFormData
|
|
1658
|
+
})
|
|
1659
|
+
);
|
|
1660
|
+
return defaultEntries.concat(fillerEntries);
|
|
1661
|
+
}
|
|
1662
|
+
function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps = {}, defaults) {
|
|
1663
|
+
switch (getSchemaType(rawSchema)) {
|
|
1664
|
+
// We need to recurse for object schema inner default values.
|
|
1029
1665
|
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;
|
|
1666
|
+
return getObjectDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1087
1667
|
}
|
|
1088
1668
|
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);
|
|
1669
|
+
return getArrayDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
1146
1670
|
}
|
|
1147
1671
|
}
|
|
1148
|
-
return defaults;
|
|
1149
1672
|
}
|
|
1150
|
-
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior) {
|
|
1673
|
+
function getDefaultFormState(validator, theSchema, formData, rootSchema, includeUndefinedValues = false, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1151
1674
|
if (!isObject(theSchema)) {
|
|
1152
1675
|
throw new Error("Invalid schema: " + theSchema);
|
|
1153
1676
|
}
|
|
1154
|
-
const schema = retrieveSchema(validator, theSchema, rootSchema, formData);
|
|
1677
|
+
const schema = retrieveSchema(validator, theSchema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1155
1678
|
const defaults = computeDefaults(validator, schema, {
|
|
1156
1679
|
rootSchema,
|
|
1157
1680
|
includeUndefinedValues,
|
|
1158
1681
|
experimental_defaultFormStateBehavior,
|
|
1159
|
-
|
|
1682
|
+
experimental_customMergeAllOf,
|
|
1683
|
+
rawFormData: formData,
|
|
1684
|
+
shouldMergeDefaultsIntoFormData: true
|
|
1160
1685
|
});
|
|
1161
|
-
if (formData
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1686
|
+
if (isObject(formData) || Array.isArray(formData)) {
|
|
1687
|
+
const { mergeDefaultsIntoFormData } = experimental_defaultFormStateBehavior || {};
|
|
1688
|
+
const defaultSupercedesUndefined = mergeDefaultsIntoFormData === "useDefaultIfFormDataUndefined";
|
|
1689
|
+
const result = mergeDefaultsWithFormData(
|
|
1690
|
+
defaults,
|
|
1691
|
+
formData,
|
|
1692
|
+
true,
|
|
1693
|
+
// set to true to add any additional default array entries.
|
|
1694
|
+
defaultSupercedesUndefined,
|
|
1695
|
+
true
|
|
1696
|
+
// set to true to override formData with defaults if they exist.
|
|
1697
|
+
);
|
|
1698
|
+
return result;
|
|
1170
1699
|
}
|
|
1171
|
-
return
|
|
1700
|
+
return defaults;
|
|
1172
1701
|
}
|
|
1173
1702
|
|
|
1174
1703
|
// src/isCustomWidget.ts
|
|
@@ -1181,25 +1710,31 @@
|
|
|
1181
1710
|
}
|
|
1182
1711
|
|
|
1183
1712
|
// src/schema/isFilesArray.ts
|
|
1184
|
-
function isFilesArray(validator, schema, uiSchema = {}, rootSchema) {
|
|
1713
|
+
function isFilesArray(validator, schema, uiSchema = {}, rootSchema, experimental_customMergeAllOf) {
|
|
1185
1714
|
if (uiSchema[UI_WIDGET_KEY] === "files") {
|
|
1186
1715
|
return true;
|
|
1187
1716
|
}
|
|
1188
1717
|
if (schema.items) {
|
|
1189
|
-
const itemsSchema = retrieveSchema(
|
|
1718
|
+
const itemsSchema = retrieveSchema(
|
|
1719
|
+
validator,
|
|
1720
|
+
schema.items,
|
|
1721
|
+
rootSchema,
|
|
1722
|
+
void 0,
|
|
1723
|
+
experimental_customMergeAllOf
|
|
1724
|
+
);
|
|
1190
1725
|
return itemsSchema.type === "string" && itemsSchema.format === "data-url";
|
|
1191
1726
|
}
|
|
1192
1727
|
return false;
|
|
1193
1728
|
}
|
|
1194
1729
|
|
|
1195
1730
|
// src/schema/getDisplayLabel.ts
|
|
1196
|
-
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions) {
|
|
1731
|
+
function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOptions, experimental_customMergeAllOf) {
|
|
1197
1732
|
const uiOptions = getUiOptions(uiSchema, globalOptions);
|
|
1198
1733
|
const { label = true } = uiOptions;
|
|
1199
1734
|
let displayLabel = !!label;
|
|
1200
1735
|
const schemaType = getSchemaType(schema);
|
|
1201
1736
|
if (schemaType === "array") {
|
|
1202
|
-
displayLabel = isMultiSelect(validator, schema, rootSchema) || isFilesArray(validator, schema, uiSchema, rootSchema) || isCustomWidget(uiSchema);
|
|
1737
|
+
displayLabel = isMultiSelect(validator, schema, rootSchema, experimental_customMergeAllOf) || isFilesArray(validator, schema, uiSchema, rootSchema, experimental_customMergeAllOf) || isCustomWidget(uiSchema);
|
|
1203
1738
|
}
|
|
1204
1739
|
if (schemaType === "object") {
|
|
1205
1740
|
displayLabel = false;
|
|
@@ -1212,48 +1747,47 @@
|
|
|
1212
1747
|
}
|
|
1213
1748
|
return displayLabel;
|
|
1214
1749
|
}
|
|
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
1750
|
var NO_VALUE = Symbol("no Value");
|
|
1229
|
-
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
|
|
1751
|
+
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
1230
1752
|
let newFormData;
|
|
1231
|
-
if (
|
|
1753
|
+
if (has5(newSchema, PROPERTIES_KEY)) {
|
|
1232
1754
|
const removeOldSchemaData = {};
|
|
1233
|
-
if (
|
|
1234
|
-
const properties =
|
|
1755
|
+
if (has5(oldSchema, PROPERTIES_KEY)) {
|
|
1756
|
+
const properties = get12(oldSchema, PROPERTIES_KEY, {});
|
|
1235
1757
|
Object.keys(properties).forEach((key) => {
|
|
1236
|
-
if (
|
|
1758
|
+
if (has5(data, key)) {
|
|
1237
1759
|
removeOldSchemaData[key] = void 0;
|
|
1238
1760
|
}
|
|
1239
1761
|
});
|
|
1240
1762
|
}
|
|
1241
|
-
const
|
|
1763
|
+
const keys2 = Object.keys(get12(newSchema, PROPERTIES_KEY, {}));
|
|
1242
1764
|
const nestedData = {};
|
|
1243
|
-
|
|
1244
|
-
const formValue =
|
|
1245
|
-
let oldKeyedSchema =
|
|
1246
|
-
let newKeyedSchema =
|
|
1247
|
-
if (
|
|
1248
|
-
oldKeyedSchema = retrieveSchema(
|
|
1765
|
+
keys2.forEach((key) => {
|
|
1766
|
+
const formValue = get12(data, key);
|
|
1767
|
+
let oldKeyedSchema = get12(oldSchema, [PROPERTIES_KEY, key], {});
|
|
1768
|
+
let newKeyedSchema = get12(newSchema, [PROPERTIES_KEY, key], {});
|
|
1769
|
+
if (has5(oldKeyedSchema, REF_KEY)) {
|
|
1770
|
+
oldKeyedSchema = retrieveSchema(
|
|
1771
|
+
validator,
|
|
1772
|
+
oldKeyedSchema,
|
|
1773
|
+
rootSchema,
|
|
1774
|
+
formValue,
|
|
1775
|
+
experimental_customMergeAllOf
|
|
1776
|
+
);
|
|
1249
1777
|
}
|
|
1250
|
-
if (
|
|
1251
|
-
newKeyedSchema = retrieveSchema(
|
|
1778
|
+
if (has5(newKeyedSchema, REF_KEY)) {
|
|
1779
|
+
newKeyedSchema = retrieveSchema(
|
|
1780
|
+
validator,
|
|
1781
|
+
newKeyedSchema,
|
|
1782
|
+
rootSchema,
|
|
1783
|
+
formValue,
|
|
1784
|
+
experimental_customMergeAllOf
|
|
1785
|
+
);
|
|
1252
1786
|
}
|
|
1253
|
-
const oldSchemaTypeForKey =
|
|
1254
|
-
const newSchemaTypeForKey =
|
|
1787
|
+
const oldSchemaTypeForKey = get12(oldKeyedSchema, "type");
|
|
1788
|
+
const newSchemaTypeForKey = get12(newKeyedSchema, "type");
|
|
1255
1789
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
1256
|
-
if (
|
|
1790
|
+
if (has5(removeOldSchemaData, key)) {
|
|
1257
1791
|
delete removeOldSchemaData[key];
|
|
1258
1792
|
}
|
|
1259
1793
|
if (newSchemaTypeForKey === "object" || newSchemaTypeForKey === "array" && Array.isArray(formValue)) {
|
|
@@ -1262,23 +1796,24 @@
|
|
|
1262
1796
|
rootSchema,
|
|
1263
1797
|
newKeyedSchema,
|
|
1264
1798
|
oldKeyedSchema,
|
|
1265
|
-
formValue
|
|
1799
|
+
formValue,
|
|
1800
|
+
experimental_customMergeAllOf
|
|
1266
1801
|
);
|
|
1267
1802
|
if (itemData !== void 0 || newSchemaTypeForKey === "array") {
|
|
1268
1803
|
nestedData[key] = itemData;
|
|
1269
1804
|
}
|
|
1270
1805
|
} else {
|
|
1271
|
-
const newOptionDefault =
|
|
1272
|
-
const oldOptionDefault =
|
|
1806
|
+
const newOptionDefault = get12(newKeyedSchema, "default", NO_VALUE);
|
|
1807
|
+
const oldOptionDefault = get12(oldKeyedSchema, "default", NO_VALUE);
|
|
1273
1808
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
1274
1809
|
if (oldOptionDefault === formValue) {
|
|
1275
1810
|
removeOldSchemaData[key] = newOptionDefault;
|
|
1276
|
-
} else if (
|
|
1811
|
+
} else if (get12(newKeyedSchema, "readOnly") === true) {
|
|
1277
1812
|
removeOldSchemaData[key] = void 0;
|
|
1278
1813
|
}
|
|
1279
1814
|
}
|
|
1280
|
-
const newOptionConst =
|
|
1281
|
-
const oldOptionConst =
|
|
1815
|
+
const newOptionConst = get12(newKeyedSchema, "const", NO_VALUE);
|
|
1816
|
+
const oldOptionConst = get12(oldKeyedSchema, "const", NO_VALUE);
|
|
1282
1817
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
1283
1818
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
1284
1819
|
}
|
|
@@ -1290,20 +1825,32 @@
|
|
|
1290
1825
|
...removeOldSchemaData,
|
|
1291
1826
|
...nestedData
|
|
1292
1827
|
};
|
|
1293
|
-
} else if (
|
|
1294
|
-
let oldSchemaItems =
|
|
1295
|
-
let newSchemaItems =
|
|
1828
|
+
} else if (get12(oldSchema, "type") === "array" && get12(newSchema, "type") === "array" && Array.isArray(data)) {
|
|
1829
|
+
let oldSchemaItems = get12(oldSchema, "items");
|
|
1830
|
+
let newSchemaItems = get12(newSchema, "items");
|
|
1296
1831
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
1297
|
-
if (
|
|
1298
|
-
oldSchemaItems = retrieveSchema(
|
|
1832
|
+
if (has5(oldSchemaItems, REF_KEY)) {
|
|
1833
|
+
oldSchemaItems = retrieveSchema(
|
|
1834
|
+
validator,
|
|
1835
|
+
oldSchemaItems,
|
|
1836
|
+
rootSchema,
|
|
1837
|
+
data,
|
|
1838
|
+
experimental_customMergeAllOf
|
|
1839
|
+
);
|
|
1299
1840
|
}
|
|
1300
|
-
if (
|
|
1301
|
-
newSchemaItems = retrieveSchema(
|
|
1841
|
+
if (has5(newSchemaItems, REF_KEY)) {
|
|
1842
|
+
newSchemaItems = retrieveSchema(
|
|
1843
|
+
validator,
|
|
1844
|
+
newSchemaItems,
|
|
1845
|
+
rootSchema,
|
|
1846
|
+
data,
|
|
1847
|
+
experimental_customMergeAllOf
|
|
1848
|
+
);
|
|
1302
1849
|
}
|
|
1303
|
-
const oldSchemaType =
|
|
1304
|
-
const newSchemaType =
|
|
1850
|
+
const oldSchemaType = get12(oldSchemaItems, "type");
|
|
1851
|
+
const newSchemaType = get12(newSchemaItems, "type");
|
|
1305
1852
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
1306
|
-
const maxItems =
|
|
1853
|
+
const maxItems = get12(newSchema, "maxItems", -1);
|
|
1307
1854
|
if (newSchemaType === "object") {
|
|
1308
1855
|
newFormData = data.reduce((newValue, aValue) => {
|
|
1309
1856
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -1311,7 +1858,8 @@
|
|
|
1311
1858
|
rootSchema,
|
|
1312
1859
|
newSchemaItems,
|
|
1313
1860
|
oldSchemaItems,
|
|
1314
|
-
aValue
|
|
1861
|
+
aValue,
|
|
1862
|
+
experimental_customMergeAllOf
|
|
1315
1863
|
);
|
|
1316
1864
|
if (itemValue !== void 0 && (maxItems < 0 || newValue.length < maxItems)) {
|
|
1317
1865
|
newValue.push(itemValue);
|
|
@@ -1328,64 +1876,79 @@
|
|
|
1328
1876
|
}
|
|
1329
1877
|
return newFormData;
|
|
1330
1878
|
}
|
|
1331
|
-
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
if (
|
|
1879
|
+
function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1880
|
+
const $id = id || idPrefix;
|
|
1881
|
+
const idSchema = { $id };
|
|
1882
|
+
if (typeof schema === "object") {
|
|
1883
|
+
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
1884
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1885
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1886
|
+
if (sameSchemaIndex === -1) {
|
|
1887
|
+
return toIdSchemaInternal(
|
|
1888
|
+
validator,
|
|
1889
|
+
_schema,
|
|
1890
|
+
idPrefix,
|
|
1891
|
+
idSeparator,
|
|
1892
|
+
id,
|
|
1893
|
+
rootSchema,
|
|
1894
|
+
formData,
|
|
1895
|
+
_recurseList.concat(_schema),
|
|
1896
|
+
experimental_customMergeAllOf
|
|
1897
|
+
);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
if (ITEMS_KEY in schema && !get12(schema, [ITEMS_KEY, REF_KEY])) {
|
|
1336
1901
|
return toIdSchemaInternal(
|
|
1337
1902
|
validator,
|
|
1338
|
-
|
|
1903
|
+
get12(schema, ITEMS_KEY),
|
|
1339
1904
|
idPrefix,
|
|
1340
1905
|
idSeparator,
|
|
1341
1906
|
id,
|
|
1342
1907
|
rootSchema,
|
|
1343
1908
|
formData,
|
|
1344
|
-
_recurseList
|
|
1909
|
+
_recurseList,
|
|
1910
|
+
experimental_customMergeAllOf
|
|
1345
1911
|
);
|
|
1346
1912
|
}
|
|
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
|
-
);
|
|
1913
|
+
if (getSchemaType(schema) === "object" && PROPERTIES_KEY in schema) {
|
|
1914
|
+
for (const name in schema.properties) {
|
|
1915
|
+
const field = schema[PROPERTIES_KEY][name];
|
|
1916
|
+
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
1917
|
+
idSchema[name] = toIdSchemaInternal(
|
|
1918
|
+
validator,
|
|
1919
|
+
field,
|
|
1920
|
+
idPrefix,
|
|
1921
|
+
idSeparator,
|
|
1922
|
+
fieldId,
|
|
1923
|
+
rootSchema,
|
|
1924
|
+
// It's possible that formData is not an object -- this can happen if an
|
|
1925
|
+
// array item has just been added, but not populated with data yet
|
|
1926
|
+
get12(formData, [name]),
|
|
1927
|
+
_recurseList,
|
|
1928
|
+
experimental_customMergeAllOf
|
|
1929
|
+
);
|
|
1930
|
+
}
|
|
1378
1931
|
}
|
|
1379
1932
|
}
|
|
1380
1933
|
return idSchema;
|
|
1381
1934
|
}
|
|
1382
|
-
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_") {
|
|
1383
|
-
return toIdSchemaInternal(
|
|
1935
|
+
function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = "root", idSeparator = "_", experimental_customMergeAllOf) {
|
|
1936
|
+
return toIdSchemaInternal(
|
|
1937
|
+
validator,
|
|
1938
|
+
schema,
|
|
1939
|
+
idPrefix,
|
|
1940
|
+
idSeparator,
|
|
1941
|
+
id,
|
|
1942
|
+
rootSchema,
|
|
1943
|
+
formData,
|
|
1944
|
+
void 0,
|
|
1945
|
+
experimental_customMergeAllOf
|
|
1946
|
+
);
|
|
1384
1947
|
}
|
|
1385
|
-
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
|
|
1948
|
+
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
1386
1949
|
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) =>
|
|
1950
|
+
const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
1951
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
1389
1952
|
if (sameSchemaIndex === -1) {
|
|
1390
1953
|
return toPathSchemaInternal(
|
|
1391
1954
|
validator,
|
|
@@ -1393,7 +1956,8 @@
|
|
|
1393
1956
|
name,
|
|
1394
1957
|
rootSchema,
|
|
1395
1958
|
formData,
|
|
1396
|
-
_recurseList.concat(_schema)
|
|
1959
|
+
_recurseList.concat(_schema),
|
|
1960
|
+
experimental_customMergeAllOf
|
|
1397
1961
|
);
|
|
1398
1962
|
}
|
|
1399
1963
|
}
|
|
@@ -1403,15 +1967,31 @@
|
|
|
1403
1967
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
1404
1968
|
const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
|
|
1405
1969
|
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
1406
|
-
const index = getClosestMatchingOption(
|
|
1970
|
+
const index = getClosestMatchingOption(
|
|
1971
|
+
validator,
|
|
1972
|
+
rootSchema,
|
|
1973
|
+
formData,
|
|
1974
|
+
xxxOf,
|
|
1975
|
+
0,
|
|
1976
|
+
discriminator,
|
|
1977
|
+
experimental_customMergeAllOf
|
|
1978
|
+
);
|
|
1407
1979
|
const _schema = xxxOf[index];
|
|
1408
1980
|
pathSchema = {
|
|
1409
1981
|
...pathSchema,
|
|
1410
|
-
...toPathSchemaInternal(
|
|
1982
|
+
...toPathSchemaInternal(
|
|
1983
|
+
validator,
|
|
1984
|
+
_schema,
|
|
1985
|
+
name,
|
|
1986
|
+
rootSchema,
|
|
1987
|
+
formData,
|
|
1988
|
+
_recurseList,
|
|
1989
|
+
experimental_customMergeAllOf
|
|
1990
|
+
)
|
|
1411
1991
|
};
|
|
1412
1992
|
}
|
|
1413
1993
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
1414
|
-
|
|
1994
|
+
set(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
|
|
1415
1995
|
}
|
|
1416
1996
|
if (ITEMS_KEY in schema && Array.isArray(formData)) {
|
|
1417
1997
|
const { items: schemaItems, additionalItems: schemaAdditionalItems } = schema;
|
|
@@ -1424,7 +2004,8 @@
|
|
|
1424
2004
|
`${name}.${i}`,
|
|
1425
2005
|
rootSchema,
|
|
1426
2006
|
element,
|
|
1427
|
-
_recurseList
|
|
2007
|
+
_recurseList,
|
|
2008
|
+
experimental_customMergeAllOf
|
|
1428
2009
|
);
|
|
1429
2010
|
} else if (schemaAdditionalItems) {
|
|
1430
2011
|
pathSchema[i] = toPathSchemaInternal(
|
|
@@ -1433,7 +2014,8 @@
|
|
|
1433
2014
|
`${name}.${i}`,
|
|
1434
2015
|
rootSchema,
|
|
1435
2016
|
element,
|
|
1436
|
-
_recurseList
|
|
2017
|
+
_recurseList,
|
|
2018
|
+
experimental_customMergeAllOf
|
|
1437
2019
|
);
|
|
1438
2020
|
} else {
|
|
1439
2021
|
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
@@ -1447,13 +2029,14 @@
|
|
|
1447
2029
|
`${name}.${i}`,
|
|
1448
2030
|
rootSchema,
|
|
1449
2031
|
element,
|
|
1450
|
-
_recurseList
|
|
2032
|
+
_recurseList,
|
|
2033
|
+
experimental_customMergeAllOf
|
|
1451
2034
|
);
|
|
1452
2035
|
});
|
|
1453
2036
|
}
|
|
1454
2037
|
} else if (PROPERTIES_KEY in schema) {
|
|
1455
2038
|
for (const property in schema.properties) {
|
|
1456
|
-
const field =
|
|
2039
|
+
const field = get12(schema, [PROPERTIES_KEY, property], {});
|
|
1457
2040
|
pathSchema[property] = toPathSchemaInternal(
|
|
1458
2041
|
validator,
|
|
1459
2042
|
field,
|
|
@@ -1461,15 +2044,16 @@
|
|
|
1461
2044
|
rootSchema,
|
|
1462
2045
|
// It's possible that formData is not an object -- this can happen if an
|
|
1463
2046
|
// array item has just been added, but not populated with data yet
|
|
1464
|
-
|
|
1465
|
-
_recurseList
|
|
2047
|
+
get12(formData, [property]),
|
|
2048
|
+
_recurseList,
|
|
2049
|
+
experimental_customMergeAllOf
|
|
1466
2050
|
);
|
|
1467
2051
|
}
|
|
1468
2052
|
}
|
|
1469
2053
|
return pathSchema;
|
|
1470
2054
|
}
|
|
1471
|
-
function toPathSchema(validator, schema, name = "", rootSchema, formData) {
|
|
1472
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
|
|
2055
|
+
function toPathSchema(validator, schema, name = "", rootSchema, formData, experimental_customMergeAllOf) {
|
|
2056
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, void 0, experimental_customMergeAllOf);
|
|
1473
2057
|
}
|
|
1474
2058
|
|
|
1475
2059
|
// src/createSchemaUtils.ts
|
|
@@ -1479,11 +2063,13 @@
|
|
|
1479
2063
|
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
1480
2064
|
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
1481
2065
|
* @param experimental_defaultFormStateBehavior - Configuration flags to allow users to override default form state behavior
|
|
2066
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1482
2067
|
*/
|
|
1483
|
-
constructor(validator, rootSchema, experimental_defaultFormStateBehavior) {
|
|
2068
|
+
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
1484
2069
|
this.rootSchema = rootSchema;
|
|
1485
2070
|
this.validator = validator;
|
|
1486
2071
|
this.experimental_defaultFormStateBehavior = experimental_defaultFormStateBehavior;
|
|
2072
|
+
this.experimental_customMergeAllOf = experimental_customMergeAllOf;
|
|
1487
2073
|
}
|
|
1488
2074
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
1489
2075
|
*
|
|
@@ -1499,13 +2085,55 @@
|
|
|
1499
2085
|
* @param validator - An implementation of the `ValidatorType` interface that will be compared against the current one
|
|
1500
2086
|
* @param rootSchema - The root schema that will be compared against the current one
|
|
1501
2087
|
* @param [experimental_defaultFormStateBehavior] Optional configuration object, if provided, allows users to override default form state behavior
|
|
2088
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
1502
2089
|
* @returns - True if the `SchemaUtilsType` differs from the given `validator` or `rootSchema`
|
|
1503
2090
|
*/
|
|
1504
|
-
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
2091
|
+
doesSchemaUtilsDiffer(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
1505
2092
|
if (!validator || !rootSchema) {
|
|
1506
2093
|
return false;
|
|
1507
2094
|
}
|
|
1508
|
-
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior);
|
|
2095
|
+
return this.validator !== validator || !deepEquals(this.rootSchema, rootSchema) || !deepEquals(this.experimental_defaultFormStateBehavior, experimental_defaultFormStateBehavior) || this.experimental_customMergeAllOf !== experimental_customMergeAllOf;
|
|
2096
|
+
}
|
|
2097
|
+
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
2098
|
+
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
2099
|
+
* field is in the `required` list for its parent and if so, it is marked as required on return.
|
|
2100
|
+
*
|
|
2101
|
+
* @param schema - The current node within the JSON schema
|
|
2102
|
+
* @param path - The remaining keys in the path to the desired field
|
|
2103
|
+
* @param [formData] - The form data that is used to determine which oneOf option
|
|
2104
|
+
* @returns - An object that contains the field and its required state. If no field can be found then
|
|
2105
|
+
* `{ field: undefined, isRequired: undefined }` is returned.
|
|
2106
|
+
*/
|
|
2107
|
+
findFieldInSchema(schema, path, formData) {
|
|
2108
|
+
return findFieldInSchema(
|
|
2109
|
+
this.validator,
|
|
2110
|
+
this.rootSchema,
|
|
2111
|
+
schema,
|
|
2112
|
+
path,
|
|
2113
|
+
formData,
|
|
2114
|
+
this.experimental_customMergeAllOf
|
|
2115
|
+
);
|
|
2116
|
+
}
|
|
2117
|
+
/** Finds the oneOf option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` that
|
|
2118
|
+
* matches the `formData[selectorField]` value. For the purposes of this function, `selectorField` is either
|
|
2119
|
+
* `schema.discriminator.propertyName` or `fallbackField`.
|
|
2120
|
+
*
|
|
2121
|
+
* @param schema - The schema element in which to search for the selected oneOf option
|
|
2122
|
+
* @param fallbackField - The field to use as a backup selector field if the schema does not have a required field
|
|
2123
|
+
* @param xxx - Either `oneOf` or `anyOf`, defines which value is being sought
|
|
2124
|
+
* @param [formData={}] - The form data that is used to determine which oneOf option
|
|
2125
|
+
* @returns - The anyOf/oneOf option that matches the selector field in the schema or undefined if nothing is selected
|
|
2126
|
+
*/
|
|
2127
|
+
findSelectedOptionInXxxOf(schema, fallbackField, xxx, formData) {
|
|
2128
|
+
return findSelectedOptionInXxxOf(
|
|
2129
|
+
this.validator,
|
|
2130
|
+
this.rootSchema,
|
|
2131
|
+
schema,
|
|
2132
|
+
fallbackField,
|
|
2133
|
+
xxx,
|
|
2134
|
+
formData,
|
|
2135
|
+
this.experimental_customMergeAllOf
|
|
2136
|
+
);
|
|
1509
2137
|
}
|
|
1510
2138
|
/** Returns the superset of `formData` that includes the given set updated to include any missing fields that have
|
|
1511
2139
|
* computed to have defaults provided in the `schema`.
|
|
@@ -1524,7 +2152,8 @@
|
|
|
1524
2152
|
formData,
|
|
1525
2153
|
this.rootSchema,
|
|
1526
2154
|
includeUndefinedValues,
|
|
1527
|
-
this.experimental_defaultFormStateBehavior
|
|
2155
|
+
this.experimental_defaultFormStateBehavior,
|
|
2156
|
+
this.experimental_customMergeAllOf
|
|
1528
2157
|
);
|
|
1529
2158
|
}
|
|
1530
2159
|
/** Determines whether the combination of `schema` and `uiSchema` properties indicates that the label for the `schema`
|
|
@@ -1536,7 +2165,14 @@
|
|
|
1536
2165
|
* @returns - True if the label should be displayed or false if it should not
|
|
1537
2166
|
*/
|
|
1538
2167
|
getDisplayLabel(schema, uiSchema, globalOptions) {
|
|
1539
|
-
return getDisplayLabel(
|
|
2168
|
+
return getDisplayLabel(
|
|
2169
|
+
this.validator,
|
|
2170
|
+
schema,
|
|
2171
|
+
uiSchema,
|
|
2172
|
+
this.rootSchema,
|
|
2173
|
+
globalOptions,
|
|
2174
|
+
this.experimental_customMergeAllOf
|
|
2175
|
+
);
|
|
1540
2176
|
}
|
|
1541
2177
|
/** Determines which of the given `options` provided most closely matches the `formData`.
|
|
1542
2178
|
* Returns the index of the option that is valid and is the closest match, or 0 if there is no match.
|
|
@@ -1558,7 +2194,8 @@
|
|
|
1558
2194
|
formData,
|
|
1559
2195
|
options,
|
|
1560
2196
|
selectedOption,
|
|
1561
|
-
discriminatorField
|
|
2197
|
+
discriminatorField,
|
|
2198
|
+
this.experimental_customMergeAllOf
|
|
1562
2199
|
);
|
|
1563
2200
|
}
|
|
1564
2201
|
/** Given the `formData` and list of `options`, attempts to find the index of the first option that matches the data.
|
|
@@ -1573,18 +2210,16 @@
|
|
|
1573
2210
|
getFirstMatchingOption(formData, options, discriminatorField) {
|
|
1574
2211
|
return getFirstMatchingOption(this.validator, formData, options, this.rootSchema, discriminatorField);
|
|
1575
2212
|
}
|
|
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);
|
|
2213
|
+
getFromSchema(schema, path, defaultValue) {
|
|
2214
|
+
return getFromSchema(
|
|
2215
|
+
this.validator,
|
|
2216
|
+
this.rootSchema,
|
|
2217
|
+
schema,
|
|
2218
|
+
path,
|
|
2219
|
+
// @ts-expect-error TS2769: No overload matches this call
|
|
2220
|
+
defaultValue,
|
|
2221
|
+
this.experimental_customMergeAllOf
|
|
2222
|
+
);
|
|
1588
2223
|
}
|
|
1589
2224
|
/** Checks to see if the `schema` and `uiSchema` combination represents an array of files
|
|
1590
2225
|
*
|
|
@@ -1593,7 +2228,7 @@
|
|
|
1593
2228
|
* @returns - True if schema/uiSchema contains an array of files, otherwise false
|
|
1594
2229
|
*/
|
|
1595
2230
|
isFilesArray(schema, uiSchema) {
|
|
1596
|
-
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema);
|
|
2231
|
+
return isFilesArray(this.validator, schema, uiSchema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1597
2232
|
}
|
|
1598
2233
|
/** Checks to see if the `schema` combination represents a multi-select
|
|
1599
2234
|
*
|
|
@@ -1601,7 +2236,7 @@
|
|
|
1601
2236
|
* @returns - True if schema contains a multi-select, otherwise false
|
|
1602
2237
|
*/
|
|
1603
2238
|
isMultiSelect(schema) {
|
|
1604
|
-
return isMultiSelect(this.validator, schema, this.rootSchema);
|
|
2239
|
+
return isMultiSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1605
2240
|
}
|
|
1606
2241
|
/** Checks to see if the `schema` combination represents a select
|
|
1607
2242
|
*
|
|
@@ -1609,21 +2244,7 @@
|
|
|
1609
2244
|
* @returns - True if schema contains a select, otherwise false
|
|
1610
2245
|
*/
|
|
1611
2246
|
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);
|
|
2247
|
+
return isSelect(this.validator, schema, this.rootSchema, this.experimental_customMergeAllOf);
|
|
1627
2248
|
}
|
|
1628
2249
|
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and
|
|
1629
2250
|
* dependencies resolved and merged into the `schema` given a `rawFormData` that is used to do the potentially
|
|
@@ -1634,7 +2255,13 @@
|
|
|
1634
2255
|
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
1635
2256
|
*/
|
|
1636
2257
|
retrieveSchema(schema, rawFormData) {
|
|
1637
|
-
return retrieveSchema(
|
|
2258
|
+
return retrieveSchema(
|
|
2259
|
+
this.validator,
|
|
2260
|
+
schema,
|
|
2261
|
+
this.rootSchema,
|
|
2262
|
+
rawFormData,
|
|
2263
|
+
this.experimental_customMergeAllOf
|
|
2264
|
+
);
|
|
1638
2265
|
}
|
|
1639
2266
|
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the
|
|
1640
2267
|
* new schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the
|
|
@@ -1648,7 +2275,14 @@
|
|
|
1648
2275
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
1649
2276
|
*/
|
|
1650
2277
|
sanitizeDataForNewSchema(newSchema, oldSchema, data) {
|
|
1651
|
-
return sanitizeDataForNewSchema(
|
|
2278
|
+
return sanitizeDataForNewSchema(
|
|
2279
|
+
this.validator,
|
|
2280
|
+
this.rootSchema,
|
|
2281
|
+
newSchema,
|
|
2282
|
+
oldSchema,
|
|
2283
|
+
data,
|
|
2284
|
+
this.experimental_customMergeAllOf
|
|
2285
|
+
);
|
|
1652
2286
|
}
|
|
1653
2287
|
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
1654
2288
|
*
|
|
@@ -1660,7 +2294,16 @@
|
|
|
1660
2294
|
* @returns - The `IdSchema` object for the `schema`
|
|
1661
2295
|
*/
|
|
1662
2296
|
toIdSchema(schema, id, formData, idPrefix = "root", idSeparator = "_") {
|
|
1663
|
-
return toIdSchema(
|
|
2297
|
+
return toIdSchema(
|
|
2298
|
+
this.validator,
|
|
2299
|
+
schema,
|
|
2300
|
+
id,
|
|
2301
|
+
this.rootSchema,
|
|
2302
|
+
formData,
|
|
2303
|
+
idPrefix,
|
|
2304
|
+
idSeparator,
|
|
2305
|
+
this.experimental_customMergeAllOf
|
|
2306
|
+
);
|
|
1664
2307
|
}
|
|
1665
2308
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1666
2309
|
*
|
|
@@ -1670,11 +2313,23 @@
|
|
|
1670
2313
|
* @returns - The `PathSchema` object for the `schema`
|
|
1671
2314
|
*/
|
|
1672
2315
|
toPathSchema(schema, name, formData) {
|
|
1673
|
-
return toPathSchema(
|
|
2316
|
+
return toPathSchema(
|
|
2317
|
+
this.validator,
|
|
2318
|
+
schema,
|
|
2319
|
+
name,
|
|
2320
|
+
this.rootSchema,
|
|
2321
|
+
formData,
|
|
2322
|
+
this.experimental_customMergeAllOf
|
|
2323
|
+
);
|
|
1674
2324
|
}
|
|
1675
2325
|
};
|
|
1676
|
-
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}) {
|
|
1677
|
-
return new SchemaUtils(
|
|
2326
|
+
function createSchemaUtils(validator, rootSchema, experimental_defaultFormStateBehavior = {}, experimental_customMergeAllOf) {
|
|
2327
|
+
return new SchemaUtils(
|
|
2328
|
+
validator,
|
|
2329
|
+
rootSchema,
|
|
2330
|
+
experimental_defaultFormStateBehavior,
|
|
2331
|
+
experimental_customMergeAllOf
|
|
2332
|
+
);
|
|
1678
2333
|
}
|
|
1679
2334
|
|
|
1680
2335
|
// src/dataURItoBlob.ts
|
|
@@ -1770,15 +2425,17 @@
|
|
|
1770
2425
|
function enumOptionsDeselectValue(valueIndex, selected, allEnumOptions = []) {
|
|
1771
2426
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
1772
2427
|
if (Array.isArray(selected)) {
|
|
1773
|
-
return selected.filter((v) => !
|
|
2428
|
+
return selected.filter((v) => !deepEquals(v, value));
|
|
1774
2429
|
}
|
|
1775
|
-
return
|
|
2430
|
+
return deepEquals(value, selected) ? void 0 : selected;
|
|
1776
2431
|
}
|
|
2432
|
+
|
|
2433
|
+
// src/enumOptionsIsSelected.ts
|
|
1777
2434
|
function enumOptionsIsSelected(value, selected) {
|
|
1778
2435
|
if (Array.isArray(selected)) {
|
|
1779
|
-
return selected.some((sel) =>
|
|
2436
|
+
return selected.some((sel) => deepEquals(sel, value));
|
|
1780
2437
|
}
|
|
1781
|
-
return
|
|
2438
|
+
return deepEquals(selected, value);
|
|
1782
2439
|
}
|
|
1783
2440
|
|
|
1784
2441
|
// src/enumOptionsIndexForValue.ts
|
|
@@ -1825,10 +2482,10 @@
|
|
|
1825
2482
|
*/
|
|
1826
2483
|
getOrCreateErrorBlock(pathOfError) {
|
|
1827
2484
|
const hasPath = Array.isArray(pathOfError) && pathOfError.length > 0 || typeof pathOfError === "string";
|
|
1828
|
-
let errorBlock = hasPath ?
|
|
2485
|
+
let errorBlock = hasPath ? get12(this.errorSchema, pathOfError) : this.errorSchema;
|
|
1829
2486
|
if (!errorBlock && pathOfError) {
|
|
1830
2487
|
errorBlock = {};
|
|
1831
|
-
|
|
2488
|
+
setWith(this.errorSchema, pathOfError, errorBlock, Object);
|
|
1832
2489
|
}
|
|
1833
2490
|
return errorBlock;
|
|
1834
2491
|
}
|
|
@@ -1851,15 +2508,15 @@
|
|
|
1851
2508
|
*/
|
|
1852
2509
|
addErrors(errorOrList, pathOfError) {
|
|
1853
2510
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1854
|
-
let errorsList =
|
|
2511
|
+
let errorsList = get12(errorBlock, ERRORS_KEY);
|
|
1855
2512
|
if (!Array.isArray(errorsList)) {
|
|
1856
2513
|
errorsList = [];
|
|
1857
2514
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
1858
2515
|
}
|
|
1859
2516
|
if (Array.isArray(errorOrList)) {
|
|
1860
|
-
|
|
2517
|
+
set(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, ...errorOrList])]);
|
|
1861
2518
|
} else {
|
|
1862
|
-
errorsList
|
|
2519
|
+
set(errorBlock, ERRORS_KEY, [.../* @__PURE__ */ new Set([...errorsList, errorOrList])]);
|
|
1863
2520
|
}
|
|
1864
2521
|
return this;
|
|
1865
2522
|
}
|
|
@@ -1873,8 +2530,8 @@
|
|
|
1873
2530
|
*/
|
|
1874
2531
|
setErrors(errorOrList, pathOfError) {
|
|
1875
2532
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1876
|
-
const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
|
|
1877
|
-
|
|
2533
|
+
const listToAdd = Array.isArray(errorOrList) ? [.../* @__PURE__ */ new Set([...errorOrList])] : [errorOrList];
|
|
2534
|
+
set(errorBlock, ERRORS_KEY, listToAdd);
|
|
1878
2535
|
return this;
|
|
1879
2536
|
}
|
|
1880
2537
|
/** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
|
|
@@ -1886,7 +2543,7 @@
|
|
|
1886
2543
|
*/
|
|
1887
2544
|
clearErrors(pathOfError) {
|
|
1888
2545
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
1889
|
-
|
|
2546
|
+
set(errorBlock, ERRORS_KEY, []);
|
|
1890
2547
|
return this;
|
|
1891
2548
|
}
|
|
1892
2549
|
};
|
|
@@ -1958,6 +2615,9 @@
|
|
|
1958
2615
|
if (options.autocomplete) {
|
|
1959
2616
|
inputProps.autoComplete = options.autocomplete;
|
|
1960
2617
|
}
|
|
2618
|
+
if (options.accept) {
|
|
2619
|
+
inputProps.accept = options.accept;
|
|
2620
|
+
}
|
|
1961
2621
|
return inputProps;
|
|
1962
2622
|
}
|
|
1963
2623
|
|
|
@@ -1984,12 +2644,33 @@
|
|
|
1984
2644
|
if (name === "ButtonTemplates") {
|
|
1985
2645
|
return templates[name];
|
|
1986
2646
|
}
|
|
2647
|
+
if (Object.hasOwn(uiOptions, name) && typeof uiOptions[name] === "string" && Object.hasOwn(templates, uiOptions[name])) {
|
|
2648
|
+
const key = uiOptions[name];
|
|
2649
|
+
return templates[key];
|
|
2650
|
+
}
|
|
1987
2651
|
return (
|
|
1988
2652
|
// Evaluating uiOptions[name] results in TS2590: Expression produces a union type that is too complex to represent
|
|
1989
2653
|
// To avoid that, we cast uiOptions to `any` before accessing the name field
|
|
1990
2654
|
uiOptions[name] || templates[name]
|
|
1991
2655
|
);
|
|
1992
2656
|
}
|
|
2657
|
+
function getTestIds() {
|
|
2658
|
+
if (typeof process === "undefined" || get12(process, "env.NODE_ENV") !== "test") {
|
|
2659
|
+
return {};
|
|
2660
|
+
}
|
|
2661
|
+
const ids = /* @__PURE__ */ new Map();
|
|
2662
|
+
return new Proxy(
|
|
2663
|
+
{},
|
|
2664
|
+
{
|
|
2665
|
+
get(_obj, prop) {
|
|
2666
|
+
if (!ids.has(prop)) {
|
|
2667
|
+
ids.set(prop, nanoid.nanoid());
|
|
2668
|
+
}
|
|
2669
|
+
return ids.get(prop);
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
);
|
|
2673
|
+
}
|
|
1993
2674
|
var widgetMap = {
|
|
1994
2675
|
boolean: {
|
|
1995
2676
|
checkbox: "CheckboxWidget",
|
|
@@ -2043,13 +2724,13 @@
|
|
|
2043
2724
|
}
|
|
2044
2725
|
};
|
|
2045
2726
|
function mergeWidgetOptions(AWidget) {
|
|
2046
|
-
let MergedWidget =
|
|
2727
|
+
let MergedWidget = get12(AWidget, "MergedWidget");
|
|
2047
2728
|
if (!MergedWidget) {
|
|
2048
2729
|
const defaultOptions = AWidget.defaultProps && AWidget.defaultProps.options || {};
|
|
2049
2730
|
MergedWidget = ({ options, ...props }) => {
|
|
2050
2731
|
return /* @__PURE__ */ jsxRuntime.jsx(AWidget, { options: { ...defaultOptions, ...options }, ...props });
|
|
2051
2732
|
};
|
|
2052
|
-
|
|
2733
|
+
set(AWidget, "MergedWidget", MergedWidget);
|
|
2053
2734
|
}
|
|
2054
2735
|
return MergedWidget;
|
|
2055
2736
|
}
|
|
@@ -2087,10 +2768,16 @@
|
|
|
2087
2768
|
}
|
|
2088
2769
|
return hash.toString(16);
|
|
2089
2770
|
}
|
|
2090
|
-
function
|
|
2771
|
+
function sortedJSONStringify(object) {
|
|
2091
2772
|
const allKeys = /* @__PURE__ */ new Set();
|
|
2092
|
-
JSON.stringify(
|
|
2093
|
-
return
|
|
2773
|
+
JSON.stringify(object, (key, value) => (allKeys.add(key), value));
|
|
2774
|
+
return JSON.stringify(object, Array.from(allKeys).sort());
|
|
2775
|
+
}
|
|
2776
|
+
function hashObject(object) {
|
|
2777
|
+
return hashString(sortedJSONStringify(object));
|
|
2778
|
+
}
|
|
2779
|
+
function hashForSchema(schema) {
|
|
2780
|
+
return hashObject(schema);
|
|
2094
2781
|
}
|
|
2095
2782
|
|
|
2096
2783
|
// src/hasWidget.ts
|
|
@@ -2132,6 +2819,9 @@
|
|
|
2132
2819
|
function optionId(id, optionIndex) {
|
|
2133
2820
|
return `${id}-${optionIndex}`;
|
|
2134
2821
|
}
|
|
2822
|
+
function buttonId(id, btn) {
|
|
2823
|
+
return idGenerator(id, btn);
|
|
2824
|
+
}
|
|
2135
2825
|
|
|
2136
2826
|
// src/labelValue.ts
|
|
2137
2827
|
function labelValue(label, hideLabel, fallback) {
|
|
@@ -2142,60 +2832,12 @@
|
|
|
2142
2832
|
function localToUTC(dateString) {
|
|
2143
2833
|
return dateString ? new Date(dateString).toJSON() : void 0;
|
|
2144
2834
|
}
|
|
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;
|
|
2835
|
+
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
2836
|
+
const lookupPath = [LOOKUP_MAP_NAME];
|
|
2837
|
+
if (has5(regOrFc, FORM_CONTEXT_NAME)) {
|
|
2838
|
+
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
2187
2839
|
}
|
|
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
|
-
});
|
|
2840
|
+
return get12(regOrFc, [...lookupPath, toLookup], fallback);
|
|
2199
2841
|
}
|
|
2200
2842
|
|
|
2201
2843
|
// src/orderProperties.ts
|
|
@@ -2308,7 +2950,7 @@
|
|
|
2308
2950
|
return Object.keys(errorSchema).reduce((acc, key) => {
|
|
2309
2951
|
if (key !== ERRORS_KEY) {
|
|
2310
2952
|
const childSchema = errorSchema[key];
|
|
2311
|
-
if (
|
|
2953
|
+
if (isPlainObject4(childSchema)) {
|
|
2312
2954
|
acc = acc.concat(toErrorList(childSchema, [...fieldPath, key]));
|
|
2313
2955
|
}
|
|
2314
2956
|
}
|
|
@@ -2337,7 +2979,7 @@
|
|
|
2337
2979
|
return acc;
|
|
2338
2980
|
} else {
|
|
2339
2981
|
const childSchema = errorHandler[key];
|
|
2340
|
-
if (
|
|
2982
|
+
if (isPlainObject4(childSchema)) {
|
|
2341
2983
|
return {
|
|
2342
2984
|
...acc,
|
|
2343
2985
|
[key]: unwrapErrorHandler(childSchema)
|
|
@@ -2370,7 +3012,7 @@
|
|
|
2370
3012
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
2371
3013
|
let errors = toErrorList(additionalErrorSchema);
|
|
2372
3014
|
let errorSchema = additionalErrorSchema;
|
|
2373
|
-
if (!
|
|
3015
|
+
if (!isEmpty2(oldErrorSchema)) {
|
|
2374
3016
|
errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
|
|
2375
3017
|
errors = [...oldErrors].concat(errors);
|
|
2376
3018
|
}
|
|
@@ -2398,16 +3040,33 @@
|
|
|
2398
3040
|
if (Array.isArray(schemaNode)) {
|
|
2399
3041
|
return withIdRefPrefixArray([...schemaNode]);
|
|
2400
3042
|
}
|
|
2401
|
-
if (
|
|
3043
|
+
if (isObject3(schemaNode)) {
|
|
2402
3044
|
return withIdRefPrefixObject({ ...schemaNode });
|
|
2403
3045
|
}
|
|
2404
3046
|
return schemaNode;
|
|
2405
3047
|
}
|
|
3048
|
+
function getChangedFields(a, b) {
|
|
3049
|
+
const aIsPlainObject = isPlainObject4(a);
|
|
3050
|
+
const bIsPlainObject = isPlainObject4(b);
|
|
3051
|
+
if (a === b || !aIsPlainObject && !bIsPlainObject) {
|
|
3052
|
+
return [];
|
|
3053
|
+
}
|
|
3054
|
+
if (aIsPlainObject && !bIsPlainObject) {
|
|
3055
|
+
return keys(a);
|
|
3056
|
+
} else if (!aIsPlainObject && bIsPlainObject) {
|
|
3057
|
+
return keys(b);
|
|
3058
|
+
} else {
|
|
3059
|
+
const unequalFields = keys(pickBy(a, (value, key) => !deepEquals(value, get12(b, key))));
|
|
3060
|
+
const diffFields = difference(keys(b), keys(a));
|
|
3061
|
+
return [...unequalFields, ...diffFields];
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
2406
3064
|
|
|
2407
3065
|
// src/enums.ts
|
|
2408
3066
|
var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
2409
3067
|
TranslatableString2["ArrayItemTitle"] = "Item";
|
|
2410
3068
|
TranslatableString2["MissingItems"] = "Missing items definition";
|
|
3069
|
+
TranslatableString2["EmptyArray"] = "No items yet. Use the button below to add some.";
|
|
2411
3070
|
TranslatableString2["YesLabel"] = "Yes";
|
|
2412
3071
|
TranslatableString2["NoLabel"] = "No";
|
|
2413
3072
|
TranslatableString2["CloseLabel"] = "Close";
|
|
@@ -2462,12 +3121,12 @@
|
|
|
2462
3121
|
* @param hash - The hash value at which to map the schema
|
|
2463
3122
|
*/
|
|
2464
3123
|
addSchema(schema, hash) {
|
|
2465
|
-
const key =
|
|
3124
|
+
const key = get12(schema, ID_KEY, hash);
|
|
2466
3125
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
2467
3126
|
const existing = this.schemaMap[key];
|
|
2468
3127
|
if (!existing) {
|
|
2469
3128
|
this.schemaMap[key] = identifiedSchema;
|
|
2470
|
-
} else if (!
|
|
3129
|
+
} else if (!deepEquals(existing, identifiedSchema)) {
|
|
2471
3130
|
console.error("existing schema:", JSON.stringify(existing, null, 2));
|
|
2472
3131
|
console.error("new schema:", JSON.stringify(identifiedSchema, null, 2));
|
|
2473
3132
|
throw new Error(
|
|
@@ -2489,7 +3148,7 @@
|
|
|
2489
3148
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
2490
3149
|
*/
|
|
2491
3150
|
isValid(schema, _formData, rootSchema) {
|
|
2492
|
-
if (!
|
|
3151
|
+
if (!deepEquals(rootSchema, this.rootSchema)) {
|
|
2493
3152
|
throw new Error("Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema");
|
|
2494
3153
|
}
|
|
2495
3154
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -2529,7 +3188,7 @@
|
|
|
2529
3188
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
2530
3189
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, void 0, true);
|
|
2531
3190
|
schemas.forEach((schema2) => {
|
|
2532
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
3191
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, schema2));
|
|
2533
3192
|
if (sameSchemaIndex === -1) {
|
|
2534
3193
|
recurseList.push(schema2);
|
|
2535
3194
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema2, rootSchema, true);
|
|
@@ -2561,21 +3220,27 @@
|
|
|
2561
3220
|
exports.DEFAULT_KEY = DEFAULT_KEY;
|
|
2562
3221
|
exports.DEFINITIONS_KEY = DEFINITIONS_KEY;
|
|
2563
3222
|
exports.DEPENDENCIES_KEY = DEPENDENCIES_KEY;
|
|
3223
|
+
exports.DISCRIMINATOR_PATH = DISCRIMINATOR_PATH;
|
|
2564
3224
|
exports.ENUM_KEY = ENUM_KEY;
|
|
2565
3225
|
exports.ERRORS_KEY = ERRORS_KEY;
|
|
2566
3226
|
exports.ErrorSchemaBuilder = ErrorSchemaBuilder;
|
|
3227
|
+
exports.FORM_CONTEXT_NAME = FORM_CONTEXT_NAME;
|
|
2567
3228
|
exports.ID_KEY = ID_KEY;
|
|
2568
3229
|
exports.IF_KEY = IF_KEY;
|
|
2569
3230
|
exports.ITEMS_KEY = ITEMS_KEY;
|
|
3231
|
+
exports.JSON_SCHEMA_DRAFT_2020_12 = JSON_SCHEMA_DRAFT_2020_12;
|
|
2570
3232
|
exports.JUNK_OPTION_ID = JUNK_OPTION_ID;
|
|
3233
|
+
exports.LOOKUP_MAP_NAME = LOOKUP_MAP_NAME;
|
|
2571
3234
|
exports.NAME_KEY = NAME_KEY;
|
|
2572
3235
|
exports.ONE_OF_KEY = ONE_OF_KEY;
|
|
3236
|
+
exports.PATTERN_PROPERTIES_KEY = PATTERN_PROPERTIES_KEY;
|
|
2573
3237
|
exports.PROPERTIES_KEY = PROPERTIES_KEY;
|
|
3238
|
+
exports.READONLY_KEY = READONLY_KEY;
|
|
2574
3239
|
exports.REF_KEY = REF_KEY;
|
|
2575
3240
|
exports.REQUIRED_KEY = REQUIRED_KEY;
|
|
2576
3241
|
exports.RJSF_ADDITIONAL_PROPERTIES_FLAG = RJSF_ADDITIONAL_PROPERTIES_FLAG;
|
|
2577
|
-
exports.RJSF_ADDITONAL_PROPERTIES_FLAG = RJSF_ADDITONAL_PROPERTIES_FLAG;
|
|
2578
3242
|
exports.ROOT_SCHEMA_PREFIX = ROOT_SCHEMA_PREFIX;
|
|
3243
|
+
exports.SCHEMA_KEY = SCHEMA_KEY;
|
|
2579
3244
|
exports.SUBMIT_BTN_OPTIONS_KEY = SUBMIT_BTN_OPTIONS_KEY;
|
|
2580
3245
|
exports.TranslatableString = TranslatableString;
|
|
2581
3246
|
exports.UI_FIELD_KEY = UI_FIELD_KEY;
|
|
@@ -2585,6 +3250,7 @@
|
|
|
2585
3250
|
exports.allowAdditionalItems = allowAdditionalItems;
|
|
2586
3251
|
exports.ariaDescribedByIds = ariaDescribedByIds;
|
|
2587
3252
|
exports.asNumber = asNumber;
|
|
3253
|
+
exports.buttonId = buttonId;
|
|
2588
3254
|
exports.canExpand = canExpand;
|
|
2589
3255
|
exports.createErrorHandler = createErrorHandler;
|
|
2590
3256
|
exports.createSchemaUtils = createSchemaUtils;
|
|
@@ -2600,24 +3266,30 @@
|
|
|
2600
3266
|
exports.enumOptionsValueForIndex = enumOptionsValueForIndex;
|
|
2601
3267
|
exports.errorId = errorId;
|
|
2602
3268
|
exports.examplesId = examplesId;
|
|
3269
|
+
exports.findFieldInSchema = findFieldInSchema;
|
|
2603
3270
|
exports.findSchemaDefinition = findSchemaDefinition;
|
|
3271
|
+
exports.findSelectedOptionInXxxOf = findSelectedOptionInXxxOf;
|
|
3272
|
+
exports.getChangedFields = getChangedFields;
|
|
2604
3273
|
exports.getClosestMatchingOption = getClosestMatchingOption;
|
|
2605
3274
|
exports.getDateElementProps = getDateElementProps;
|
|
2606
3275
|
exports.getDefaultFormState = getDefaultFormState;
|
|
2607
3276
|
exports.getDiscriminatorFieldFromSchema = getDiscriminatorFieldFromSchema;
|
|
2608
3277
|
exports.getDisplayLabel = getDisplayLabel;
|
|
2609
3278
|
exports.getFirstMatchingOption = getFirstMatchingOption;
|
|
3279
|
+
exports.getFromSchema = getFromSchema;
|
|
2610
3280
|
exports.getInputProps = getInputProps;
|
|
2611
|
-
exports.getMatchingOption = getMatchingOption;
|
|
2612
3281
|
exports.getOptionMatchingSimpleDiscriminator = getOptionMatchingSimpleDiscriminator;
|
|
2613
3282
|
exports.getSchemaType = getSchemaType;
|
|
2614
3283
|
exports.getSubmitButtonOptions = getSubmitButtonOptions;
|
|
2615
3284
|
exports.getTemplate = getTemplate;
|
|
3285
|
+
exports.getTestIds = getTestIds;
|
|
2616
3286
|
exports.getUiOptions = getUiOptions;
|
|
2617
3287
|
exports.getWidget = getWidget;
|
|
2618
3288
|
exports.guessType = guessType;
|
|
2619
3289
|
exports.hasWidget = hasWidget;
|
|
2620
3290
|
exports.hashForSchema = hashForSchema;
|
|
3291
|
+
exports.hashObject = hashObject;
|
|
3292
|
+
exports.hashString = hashString;
|
|
2621
3293
|
exports.helpId = helpId;
|
|
2622
3294
|
exports.isConstant = isConstant;
|
|
2623
3295
|
exports.isCustomWidget = isCustomWidget;
|
|
@@ -2628,10 +3300,10 @@
|
|
|
2628
3300
|
exports.isSelect = isSelect;
|
|
2629
3301
|
exports.labelValue = labelValue;
|
|
2630
3302
|
exports.localToUTC = localToUTC;
|
|
3303
|
+
exports.lookupFromFormContext = lookupFromFormContext;
|
|
2631
3304
|
exports.mergeDefaultsWithFormData = mergeDefaultsWithFormData;
|
|
2632
3305
|
exports.mergeObjects = mergeObjects;
|
|
2633
3306
|
exports.mergeSchemas = mergeSchemas;
|
|
2634
|
-
exports.mergeValidationData = mergeValidationData;
|
|
2635
3307
|
exports.optionId = optionId;
|
|
2636
3308
|
exports.optionsList = optionsList;
|
|
2637
3309
|
exports.orderProperties = orderProperties;
|
|
@@ -2644,6 +3316,7 @@
|
|
|
2644
3316
|
exports.schemaParser = schemaParser;
|
|
2645
3317
|
exports.schemaRequiresTrueValue = schemaRequiresTrueValue;
|
|
2646
3318
|
exports.shouldRender = shouldRender;
|
|
3319
|
+
exports.sortedJSONStringify = sortedJSONStringify;
|
|
2647
3320
|
exports.titleId = titleId;
|
|
2648
3321
|
exports.toConstant = toConstant;
|
|
2649
3322
|
exports.toDateString = toDateString;
|