@rjsf/utils 6.0.0-alpha.0 → 6.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1281 -625
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +1254 -598
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +1201 -570
- package/lib/ErrorSchemaBuilder.d.ts +8 -4
- package/lib/ErrorSchemaBuilder.js +10 -8
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -1
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +1 -1
- package/lib/canExpand.js +2 -2
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.d.ts +9 -0
- package/lib/constIsAjvDataReference.js +15 -0
- package/lib/constIsAjvDataReference.js.map +1 -0
- package/lib/constants.d.ts +11 -3
- package/lib/constants.js +11 -3
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.d.ts +1 -1
- package/lib/createErrorHandler.js +2 -2
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +3 -2
- package/lib/createSchemaUtils.js +56 -46
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +1 -1
- package/lib/dateRangeOptions.js +1 -1
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/deepEquals.js +1 -1
- package/lib/deepEquals.js.map +1 -1
- package/lib/englishStringTranslator.d.ts +1 -1
- package/lib/englishStringTranslator.js +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +1 -1
- package/lib/enumOptionsDeselectValue.js +4 -4
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.js +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +1 -1
- package/lib/enumOptionsIsSelected.js +3 -3
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.d.ts +1 -1
- package/lib/enumOptionsSelectValue.js +2 -2
- package/lib/enumOptionsSelectValue.js.map +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +1 -1
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +2 -0
- package/lib/enums.js +2 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +1 -1
- package/lib/findSchemaDefinition.js +2 -2
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.d.ts +17 -0
- package/lib/getChangedFields.js +42 -0
- package/lib/getChangedFields.js.map +1 -0
- package/lib/getDateElementProps.d.ts +1 -1
- package/lib/getDateElementProps.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +4 -3
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +1 -1
- package/lib/getInputProps.js +4 -1
- package/lib/getInputProps.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js +2 -2
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getSchemaType.d.ts +2 -1
- package/lib/getSchemaType.js +3 -2
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +1 -1
- package/lib/getSubmitButtonOptions.js +2 -2
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +1 -1
- package/lib/getTemplate.js +9 -0
- package/lib/getTemplate.js.map +1 -1
- package/lib/getTestIds.d.ts +17 -0
- package/lib/getTestIds.js +34 -0
- package/lib/getTestIds.js.map +1 -0
- package/lib/getUiOptions.d.ts +1 -1
- package/lib/getUiOptions.js +2 -2
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +1 -1
- package/lib/getWidget.js +3 -3
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.d.ts +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.d.ts +1 -1
- package/lib/hasWidget.js +1 -1
- package/lib/hasWidget.js.map +1 -1
- package/lib/hashForSchema.d.ts +23 -1
- package/lib/hashForSchema.js +24 -6
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +8 -1
- package/lib/idGenerators.js +11 -2
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +63 -60
- package/lib/index.js +63 -60
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +1 -1
- package/lib/isConstant.js +1 -1
- package/lib/isCustomWidget.d.ts +1 -1
- package/lib/isCustomWidget.js +1 -1
- package/lib/isFixedItems.d.ts +1 -1
- package/lib/isFixedItems.js +1 -1
- package/lib/isObject.d.ts +2 -2
- package/lib/isObject.js +11 -4
- package/lib/isObject.js.map +1 -1
- package/lib/lookupFromFormContext.d.ts +11 -0
- package/lib/lookupFromFormContext.js +20 -0
- package/lib/lookupFromFormContext.js.map +1 -0
- package/lib/mergeDefaultsWithFormData.d.ts +8 -2
- package/lib/mergeDefaultsWithFormData.js +39 -10
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +1 -1
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +1 -1
- package/lib/mergeSchemas.js +4 -4
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/optionsList.d.ts +9 -7
- package/lib/optionsList.js +30 -19
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js.map +1 -1
- package/lib/pad.js.map +1 -1
- package/lib/parseDateString.d.ts +1 -1
- package/lib/parseDateString.js +1 -1
- package/lib/parseDateString.js.map +1 -1
- package/lib/parser/ParserValidator.d.ts +1 -1
- package/lib/parser/ParserValidator.js +6 -6
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +2 -2
- package/lib/parser/index.js +1 -1
- package/lib/parser/schemaParser.d.ts +2 -2
- package/lib/parser/schemaParser.js +6 -6
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/rangeSpec.d.ts +2 -2
- package/lib/rangeSpec.js.map +1 -1
- package/lib/replaceStringParameters.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +19 -0
- package/lib/schema/findFieldInSchema.js +61 -0
- package/lib/schema/findFieldInSchema.js.map +1 -0
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +16 -0
- package/lib/schema/findSelectedOptionInXxxOf.js +34 -0
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -0
- package/lib/schema/getClosestMatchingOption.d.ts +5 -3
- package/lib/schema/getClosestMatchingOption.js +28 -20
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +60 -13
- package/lib/schema/getDefaultFormState.js +304 -166
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +3 -2
- package/lib/schema/getDisplayLabel.js +10 -9
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +70 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +14 -0
- package/lib/schema/getFromSchema.js +39 -0
- package/lib/schema/getFromSchema.js.map +1 -0
- package/lib/schema/index.d.ts +15 -14
- package/lib/schema/index.js +15 -14
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +3 -2
- package/lib/schema/isFilesArray.js +5 -4
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.d.ts +3 -2
- package/lib/schema/isMultiSelect.js +4 -3
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +3 -2
- package/lib/schema/isSelect.js +5 -4
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +28 -11
- package/lib/schema/retrieveSchema.js +142 -66
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +3 -2
- package/lib/schema/sanitizeDataForNewSchema.js +12 -11
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toIdSchema.d.ts +3 -2
- package/lib/schema/toIdSchema.js +30 -27
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +3 -2
- package/lib/schema/toPathSchema.js +22 -20
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +1 -1
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shouldRender.js +1 -1
- package/lib/toConstant.d.ts +1 -1
- package/lib/toConstant.js +1 -1
- package/lib/toConstant.js.map +1 -1
- package/lib/toDateString.d.ts +1 -1
- package/lib/toErrorList.d.ts +1 -1
- package/lib/toErrorList.js +2 -2
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +1 -1
- package/lib/toErrorSchema.js +2 -2
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +160 -131
- package/lib/unwrapErrorHandler.d.ts +1 -1
- package/lib/unwrapErrorHandler.js +1 -1
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/utcToLocal.js +1 -1
- package/lib/utcToLocal.js.map +1 -1
- package/lib/validationDataMerge.d.ts +1 -1
- package/lib/validationDataMerge.js +3 -3
- package/lib/validationDataMerge.js.map +1 -1
- package/lib/withIdRefPrefix.d.ts +1 -1
- package/lib/withIdRefPrefix.js +2 -2
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +36 -26
- package/src/ErrorSchemaBuilder.ts +15 -8
- package/src/canExpand.ts +2 -2
- package/src/constIsAjvDataReference.ts +17 -0
- package/src/constants.ts +12 -3
- package/src/createSchemaUtils.ts +140 -50
- package/src/dataURItoBlob.ts +1 -1
- package/src/dateRangeOptions.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +4 -5
- package/src/enumOptionsIndexForValue.ts +1 -1
- package/src/enumOptionsIsSelected.ts +4 -5
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +1 -1
- package/src/enums.ts +2 -0
- package/src/findSchemaDefinition.ts +2 -2
- package/src/getChangedFields.ts +40 -0
- package/src/getDateElementProps.ts +2 -2
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +6 -2
- package/src/getOptionMatchingSimpleDiscriminator.ts +2 -2
- package/src/getSchemaType.ts +3 -2
- package/src/getSubmitButtonOptions.ts +1 -1
- package/src/getTemplate.ts +12 -1
- package/src/getTestIds.ts +40 -0
- package/src/getUiOptions.ts +2 -2
- package/src/getWidget.tsx +2 -2
- package/src/hasWidget.ts +1 -1
- package/src/hashForSchema.ts +26 -6
- package/src/idGenerators.ts +10 -0
- package/src/index.ts +21 -2
- package/src/isCustomWidget.ts +1 -1
- package/src/isObject.ts +12 -5
- package/src/labelValue.ts +2 -2
- package/src/lookupFromFormContext.ts +26 -0
- package/src/mergeDefaultsWithFormData.ts +54 -9
- package/src/mergeObjects.ts +24 -21
- package/src/optionsList.ts +31 -22
- package/src/parser/ParserValidator.ts +5 -5
- package/src/parser/schemaParser.ts +6 -6
- package/src/schema/findFieldInSchema.ts +138 -0
- package/src/schema/findSelectedOptionInXxxOf.ts +53 -0
- package/src/schema/getClosestMatchingOption.ts +38 -11
- package/src/schema/getDefaultFormState.ts +447 -191
- package/src/schema/getDisplayLabel.ts +7 -4
- package/src/schema/getFirstMatchingOption.ts +79 -4
- package/src/schema/getFromSchema.ts +100 -0
- package/src/schema/index.ts +6 -4
- package/src/schema/isFilesArray.ts +18 -3
- package/src/schema/isMultiSelect.ts +10 -4
- package/src/schema/isSelect.ts +5 -3
- package/src/schema/retrieveSchema.ts +256 -75
- package/src/schema/sanitizeDataForNewSchema.ts +52 -11
- package/src/schema/toIdSchema.ts +69 -43
- package/src/schema/toPathSchema.ts +49 -16
- package/src/toErrorList.ts +2 -2
- package/src/types.ts +266 -174
- package/src/validationDataMerge.ts +1 -1
- package/src/withIdRefPrefix.ts +1 -1
- package/LICENSE.md +0 -201
- package/lib/schema/getMatchingOption.d.ts +0 -14
- package/lib/schema/getMatchingOption.js +0 -85
- package/lib/schema/getMatchingOption.js.map +0 -1
- package/lib/schema/mergeValidationData.d.ts +0 -14
- package/lib/schema/mergeValidationData.js +0 -28
- package/lib/schema/mergeValidationData.js.map +0 -1
- package/src/schema/getMatchingOption.ts +0 -103
- package/src/schema/mergeValidationData.ts +0 -38
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import has from 'lodash/has';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Experimental_CustomMergeAllOf,
|
|
6
|
+
FormContextType,
|
|
7
|
+
GenericObjectType,
|
|
8
|
+
RJSFSchema,
|
|
9
|
+
StrictRJSFSchema,
|
|
10
|
+
ValidatorType,
|
|
11
|
+
} from '../types';
|
|
5
12
|
import { PROPERTIES_KEY, REF_KEY } from '../constants';
|
|
6
13
|
import retrieveSchema from './retrieveSchema';
|
|
7
14
|
|
|
@@ -51,14 +58,22 @@ const NO_VALUE = Symbol('no Value');
|
|
|
51
58
|
* @param [newSchema] - The new schema for which the data is being sanitized
|
|
52
59
|
* @param [oldSchema] - The old schema from which the data originated
|
|
53
60
|
* @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
|
|
61
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
54
62
|
* @returns - The new form data, with all the fields uniquely associated with the old schema set
|
|
55
63
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
56
64
|
*/
|
|
57
65
|
export default function sanitizeDataForNewSchema<
|
|
58
66
|
T = any,
|
|
59
67
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
60
|
-
F extends FormContextType = any
|
|
61
|
-
>(
|
|
68
|
+
F extends FormContextType = any,
|
|
69
|
+
>(
|
|
70
|
+
validator: ValidatorType<T, S, F>,
|
|
71
|
+
rootSchema: S,
|
|
72
|
+
newSchema?: S,
|
|
73
|
+
oldSchema?: S,
|
|
74
|
+
data: any = {},
|
|
75
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
76
|
+
): T {
|
|
62
77
|
// By default, we will clear the form data
|
|
63
78
|
let newFormData;
|
|
64
79
|
// If the new schema is of type object and that object contains a list of properties
|
|
@@ -78,14 +93,26 @@ export default function sanitizeDataForNewSchema<
|
|
|
78
93
|
const nestedData: GenericObjectType = {};
|
|
79
94
|
keys.forEach((key) => {
|
|
80
95
|
const formValue = get(data, key);
|
|
81
|
-
let oldKeyedSchema: S = get(oldSchema, [PROPERTIES_KEY, key], {});
|
|
82
|
-
let newKeyedSchema: S = get(newSchema, [PROPERTIES_KEY, key], {});
|
|
96
|
+
let oldKeyedSchema: S = get(oldSchema, [PROPERTIES_KEY, key], {}) as S;
|
|
97
|
+
let newKeyedSchema: S = get(newSchema, [PROPERTIES_KEY, key], {}) as S;
|
|
83
98
|
// Resolve the refs if they exist
|
|
84
99
|
if (has(oldKeyedSchema, REF_KEY)) {
|
|
85
|
-
oldKeyedSchema = retrieveSchema<T, S, F>(
|
|
100
|
+
oldKeyedSchema = retrieveSchema<T, S, F>(
|
|
101
|
+
validator,
|
|
102
|
+
oldKeyedSchema,
|
|
103
|
+
rootSchema,
|
|
104
|
+
formValue,
|
|
105
|
+
experimental_customMergeAllOf,
|
|
106
|
+
);
|
|
86
107
|
}
|
|
87
108
|
if (has(newKeyedSchema, REF_KEY)) {
|
|
88
|
-
newKeyedSchema = retrieveSchema<T, S, F>(
|
|
109
|
+
newKeyedSchema = retrieveSchema<T, S, F>(
|
|
110
|
+
validator,
|
|
111
|
+
newKeyedSchema,
|
|
112
|
+
rootSchema,
|
|
113
|
+
formValue,
|
|
114
|
+
experimental_customMergeAllOf,
|
|
115
|
+
);
|
|
89
116
|
}
|
|
90
117
|
// Now get types and see if they are the same
|
|
91
118
|
const oldSchemaTypeForKey = get(oldKeyedSchema, 'type');
|
|
@@ -104,7 +131,8 @@ export default function sanitizeDataForNewSchema<
|
|
|
104
131
|
rootSchema,
|
|
105
132
|
newKeyedSchema,
|
|
106
133
|
oldKeyedSchema,
|
|
107
|
-
formValue
|
|
134
|
+
formValue,
|
|
135
|
+
experimental_customMergeAllOf,
|
|
108
136
|
);
|
|
109
137
|
if (itemData !== undefined || newSchemaTypeForKey === 'array') {
|
|
110
138
|
// only put undefined values for the array type and not the object type
|
|
@@ -154,10 +182,22 @@ export default function sanitizeDataForNewSchema<
|
|
|
154
182
|
!Array.isArray(newSchemaItems)
|
|
155
183
|
) {
|
|
156
184
|
if (has(oldSchemaItems, REF_KEY)) {
|
|
157
|
-
oldSchemaItems = retrieveSchema<T, S, F>(
|
|
185
|
+
oldSchemaItems = retrieveSchema<T, S, F>(
|
|
186
|
+
validator,
|
|
187
|
+
oldSchemaItems as S,
|
|
188
|
+
rootSchema,
|
|
189
|
+
data as T,
|
|
190
|
+
experimental_customMergeAllOf,
|
|
191
|
+
);
|
|
158
192
|
}
|
|
159
193
|
if (has(newSchemaItems, REF_KEY)) {
|
|
160
|
-
newSchemaItems = retrieveSchema<T, S, F>(
|
|
194
|
+
newSchemaItems = retrieveSchema<T, S, F>(
|
|
195
|
+
validator,
|
|
196
|
+
newSchemaItems as S,
|
|
197
|
+
rootSchema,
|
|
198
|
+
data as T,
|
|
199
|
+
experimental_customMergeAllOf,
|
|
200
|
+
);
|
|
161
201
|
}
|
|
162
202
|
// Now get types and see if they are the same
|
|
163
203
|
const oldSchemaType = get(oldSchemaItems, 'type');
|
|
@@ -172,7 +212,8 @@ export default function sanitizeDataForNewSchema<
|
|
|
172
212
|
rootSchema,
|
|
173
213
|
newSchemaItems as S,
|
|
174
214
|
oldSchemaItems as S,
|
|
175
|
-
aValue
|
|
215
|
+
aValue,
|
|
216
|
+
experimental_customMergeAllOf,
|
|
176
217
|
);
|
|
177
218
|
if (itemValue !== undefined && (maxItems < 0 || newValue.length < maxItems)) {
|
|
178
219
|
newValue.push(itemValue);
|
package/src/schema/toIdSchema.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
-
import isEqual from 'lodash/isEqual';
|
|
3
2
|
|
|
4
3
|
import { ALL_OF_KEY, DEPENDENCIES_KEY, ID_KEY, ITEMS_KEY, PROPERTIES_KEY, REF_KEY } from '../constants';
|
|
5
|
-
import
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
Experimental_CustomMergeAllOf,
|
|
6
|
+
FormContextType,
|
|
7
|
+
GenericObjectType,
|
|
8
|
+
IdSchema,
|
|
9
|
+
RJSFSchema,
|
|
10
|
+
StrictRJSFSchema,
|
|
11
|
+
ValidatorType,
|
|
12
|
+
} from '../types';
|
|
7
13
|
import retrieveSchema from './retrieveSchema';
|
|
8
14
|
import getSchemaType from '../getSchemaType';
|
|
15
|
+
import deepEquals from '../deepEquals';
|
|
9
16
|
|
|
10
17
|
/** An internal helper that generates an `IdSchema` object for the `schema`, recursively with protection against
|
|
11
18
|
* infinite recursion
|
|
@@ -18,6 +25,7 @@ import getSchemaType from '../getSchemaType';
|
|
|
18
25
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
19
26
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
20
27
|
* @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
|
|
28
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
21
29
|
* @returns - The `IdSchema` object for the `schema`
|
|
22
30
|
*/
|
|
23
31
|
function toIdSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -28,54 +36,60 @@ function toIdSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
28
36
|
id?: string | null,
|
|
29
37
|
rootSchema?: S,
|
|
30
38
|
formData?: T,
|
|
31
|
-
_recurseList: S[] = []
|
|
39
|
+
_recurseList: S[] = [],
|
|
40
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
32
41
|
): IdSchema<T> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
42
|
+
const $id = id || idPrefix;
|
|
43
|
+
const idSchema: IdSchema<T> = { $id } as IdSchema<T>;
|
|
44
|
+
if (typeof schema === 'object') {
|
|
45
|
+
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
46
|
+
const _schema = retrieveSchema<T, S, F>(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
47
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
48
|
+
if (sameSchemaIndex === -1) {
|
|
49
|
+
return toIdSchemaInternal<T, S, F>(
|
|
50
|
+
validator,
|
|
51
|
+
_schema,
|
|
52
|
+
idPrefix,
|
|
53
|
+
idSeparator,
|
|
54
|
+
id,
|
|
55
|
+
rootSchema,
|
|
56
|
+
formData,
|
|
57
|
+
_recurseList.concat(_schema),
|
|
58
|
+
experimental_customMergeAllOf,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (ITEMS_KEY in schema && !get(schema, [ITEMS_KEY, REF_KEY])) {
|
|
37
63
|
return toIdSchemaInternal<T, S, F>(
|
|
38
64
|
validator,
|
|
39
|
-
|
|
65
|
+
get(schema, ITEMS_KEY) as S,
|
|
40
66
|
idPrefix,
|
|
41
67
|
idSeparator,
|
|
42
68
|
id,
|
|
43
69
|
rootSchema,
|
|
44
70
|
formData,
|
|
45
|
-
_recurseList
|
|
71
|
+
_recurseList,
|
|
72
|
+
experimental_customMergeAllOf,
|
|
46
73
|
);
|
|
47
74
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
67
|
-
(idSchema as IdSchema<GenericObjectType>)[name] = toIdSchemaInternal<T, S, F>(
|
|
68
|
-
validator,
|
|
69
|
-
isObject(field) ? field : {},
|
|
70
|
-
idPrefix,
|
|
71
|
-
idSeparator,
|
|
72
|
-
fieldId,
|
|
73
|
-
rootSchema,
|
|
74
|
-
// It's possible that formData is not an object -- this can happen if an
|
|
75
|
-
// array item has just been added, but not populated with data yet
|
|
76
|
-
get(formData, [name]),
|
|
77
|
-
_recurseList
|
|
78
|
-
);
|
|
75
|
+
if (getSchemaType<S>(schema) === 'object' && PROPERTIES_KEY in schema) {
|
|
76
|
+
for (const name in schema.properties) {
|
|
77
|
+
const field: S = schema[PROPERTIES_KEY][name] as S;
|
|
78
|
+
const fieldId = idSchema[ID_KEY] + idSeparator + name;
|
|
79
|
+
(idSchema as IdSchema<GenericObjectType>)[name] = toIdSchemaInternal<T, S, F>(
|
|
80
|
+
validator,
|
|
81
|
+
field,
|
|
82
|
+
idPrefix,
|
|
83
|
+
idSeparator,
|
|
84
|
+
fieldId,
|
|
85
|
+
rootSchema,
|
|
86
|
+
// It's possible that formData is not an object -- this can happen if an
|
|
87
|
+
// array item has just been added, but not populated with data yet
|
|
88
|
+
get(formData, [name]),
|
|
89
|
+
_recurseList,
|
|
90
|
+
experimental_customMergeAllOf,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
79
93
|
}
|
|
80
94
|
}
|
|
81
95
|
return idSchema;
|
|
@@ -90,6 +104,7 @@ function toIdSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
90
104
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
91
105
|
* @param [idPrefix='root'] - The prefix to use for the id
|
|
92
106
|
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
107
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
93
108
|
* @returns - The `IdSchema` object for the `schema`
|
|
94
109
|
*/
|
|
95
110
|
export default function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -99,7 +114,18 @@ export default function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
99
114
|
rootSchema?: S,
|
|
100
115
|
formData?: T,
|
|
101
116
|
idPrefix = 'root',
|
|
102
|
-
idSeparator = '_'
|
|
117
|
+
idSeparator = '_',
|
|
118
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
103
119
|
): IdSchema<T> {
|
|
104
|
-
return toIdSchemaInternal<T, S, F>(
|
|
120
|
+
return toIdSchemaInternal<T, S, F>(
|
|
121
|
+
validator,
|
|
122
|
+
schema,
|
|
123
|
+
idPrefix,
|
|
124
|
+
idSeparator,
|
|
125
|
+
id,
|
|
126
|
+
rootSchema,
|
|
127
|
+
formData,
|
|
128
|
+
undefined,
|
|
129
|
+
experimental_customMergeAllOf,
|
|
130
|
+
);
|
|
105
131
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
|
-
import isEqual from 'lodash/isEqual';
|
|
3
2
|
import set from 'lodash/set';
|
|
4
3
|
|
|
5
4
|
import {
|
|
5
|
+
ADDITIONAL_PROPERTIES_KEY,
|
|
6
6
|
ALL_OF_KEY,
|
|
7
7
|
ANY_OF_KEY,
|
|
8
|
-
ADDITIONAL_PROPERTIES_KEY,
|
|
9
8
|
DEPENDENCIES_KEY,
|
|
10
9
|
ITEMS_KEY,
|
|
11
10
|
NAME_KEY,
|
|
@@ -15,9 +14,18 @@ import {
|
|
|
15
14
|
RJSF_ADDITIONAL_PROPERTIES_FLAG,
|
|
16
15
|
} from '../constants';
|
|
17
16
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
18
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
Experimental_CustomMergeAllOf,
|
|
19
|
+
FormContextType,
|
|
20
|
+
GenericObjectType,
|
|
21
|
+
PathSchema,
|
|
22
|
+
RJSFSchema,
|
|
23
|
+
StrictRJSFSchema,
|
|
24
|
+
ValidatorType,
|
|
25
|
+
} from '../types';
|
|
19
26
|
import getClosestMatchingOption from './getClosestMatchingOption';
|
|
20
27
|
import retrieveSchema from './retrieveSchema';
|
|
28
|
+
import deepEquals from '../deepEquals';
|
|
21
29
|
|
|
22
30
|
/** An internal helper that generates an `PathSchema` object for the `schema`, recursively with protection against
|
|
23
31
|
* infinite recursion
|
|
@@ -28,6 +36,7 @@ import retrieveSchema from './retrieveSchema';
|
|
|
28
36
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
29
37
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
30
38
|
* @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
|
|
39
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
31
40
|
* @returns - The `PathSchema` object for the `schema`
|
|
32
41
|
*/
|
|
33
42
|
function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -36,11 +45,12 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
36
45
|
name: string,
|
|
37
46
|
rootSchema?: S,
|
|
38
47
|
formData?: T,
|
|
39
|
-
_recurseList: S[] = []
|
|
48
|
+
_recurseList: S[] = [],
|
|
49
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
40
50
|
): PathSchema<T> {
|
|
41
51
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
|
|
42
|
-
const _schema = retrieveSchema<T, S, F>(validator, schema, rootSchema, formData);
|
|
43
|
-
const sameSchemaIndex = _recurseList.findIndex((item) =>
|
|
52
|
+
const _schema = retrieveSchema<T, S, F>(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
53
|
+
const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
|
|
44
54
|
if (sameSchemaIndex === -1) {
|
|
45
55
|
return toPathSchemaInternal<T, S, F>(
|
|
46
56
|
validator,
|
|
@@ -48,7 +58,8 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
48
58
|
name,
|
|
49
59
|
rootSchema,
|
|
50
60
|
formData,
|
|
51
|
-
_recurseList.concat(_schema)
|
|
61
|
+
_recurseList.concat(_schema),
|
|
62
|
+
experimental_customMergeAllOf,
|
|
52
63
|
);
|
|
53
64
|
}
|
|
54
65
|
}
|
|
@@ -60,11 +71,27 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
60
71
|
if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
|
|
61
72
|
const xxxOf: S[] = ONE_OF_KEY in schema ? (schema.oneOf as S[]) : (schema.anyOf as S[]);
|
|
62
73
|
const discriminator = getDiscriminatorFieldFromSchema<S>(schema);
|
|
63
|
-
const index = getClosestMatchingOption<T, S, F>(
|
|
74
|
+
const index = getClosestMatchingOption<T, S, F>(
|
|
75
|
+
validator,
|
|
76
|
+
rootSchema!,
|
|
77
|
+
formData,
|
|
78
|
+
xxxOf,
|
|
79
|
+
0,
|
|
80
|
+
discriminator,
|
|
81
|
+
experimental_customMergeAllOf,
|
|
82
|
+
);
|
|
64
83
|
const _schema: S = xxxOf![index] as S;
|
|
65
84
|
pathSchema = {
|
|
66
85
|
...pathSchema,
|
|
67
|
-
...toPathSchemaInternal<T, S, F>(
|
|
86
|
+
...toPathSchemaInternal<T, S, F>(
|
|
87
|
+
validator,
|
|
88
|
+
_schema,
|
|
89
|
+
name,
|
|
90
|
+
rootSchema,
|
|
91
|
+
formData,
|
|
92
|
+
_recurseList,
|
|
93
|
+
experimental_customMergeAllOf,
|
|
94
|
+
),
|
|
68
95
|
};
|
|
69
96
|
}
|
|
70
97
|
|
|
@@ -84,7 +111,8 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
84
111
|
`${name}.${i}`,
|
|
85
112
|
rootSchema,
|
|
86
113
|
element,
|
|
87
|
-
_recurseList
|
|
114
|
+
_recurseList,
|
|
115
|
+
experimental_customMergeAllOf,
|
|
88
116
|
);
|
|
89
117
|
} else if (schemaAdditionalItems) {
|
|
90
118
|
(pathSchema as PathSchema<T[]>)[i] = toPathSchemaInternal<T, S, F>(
|
|
@@ -93,7 +121,8 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
93
121
|
`${name}.${i}`,
|
|
94
122
|
rootSchema,
|
|
95
123
|
element,
|
|
96
|
-
_recurseList
|
|
124
|
+
_recurseList,
|
|
125
|
+
experimental_customMergeAllOf,
|
|
97
126
|
);
|
|
98
127
|
} else {
|
|
99
128
|
console.warn(`Unable to generate path schema for "${name}.${i}". No schema defined for it`);
|
|
@@ -107,13 +136,14 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
107
136
|
`${name}.${i}`,
|
|
108
137
|
rootSchema,
|
|
109
138
|
element,
|
|
110
|
-
_recurseList
|
|
139
|
+
_recurseList,
|
|
140
|
+
experimental_customMergeAllOf,
|
|
111
141
|
);
|
|
112
142
|
});
|
|
113
143
|
}
|
|
114
144
|
} else if (PROPERTIES_KEY in schema) {
|
|
115
145
|
for (const property in schema.properties) {
|
|
116
|
-
const field = get(schema, [PROPERTIES_KEY, property]);
|
|
146
|
+
const field: S = get(schema, [PROPERTIES_KEY, property], {}) as S;
|
|
117
147
|
(pathSchema as PathSchema<GenericObjectType>)[property] = toPathSchemaInternal<T, S, F>(
|
|
118
148
|
validator,
|
|
119
149
|
field,
|
|
@@ -122,7 +152,8 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
122
152
|
// It's possible that formData is not an object -- this can happen if an
|
|
123
153
|
// array item has just been added, but not populated with data yet
|
|
124
154
|
get(formData, [property]),
|
|
125
|
-
_recurseList
|
|
155
|
+
_recurseList,
|
|
156
|
+
experimental_customMergeAllOf,
|
|
126
157
|
);
|
|
127
158
|
}
|
|
128
159
|
}
|
|
@@ -136,6 +167,7 @@ function toPathSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema,
|
|
|
136
167
|
* @param [name=''] - The base name for the schema
|
|
137
168
|
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
|
|
138
169
|
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
170
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
139
171
|
* @returns - The `PathSchema` object for the `schema`
|
|
140
172
|
*/
|
|
141
173
|
export default function toPathSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
@@ -143,7 +175,8 @@ export default function toPathSchema<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
143
175
|
schema: S,
|
|
144
176
|
name = '',
|
|
145
177
|
rootSchema?: S,
|
|
146
|
-
formData?: T
|
|
178
|
+
formData?: T,
|
|
179
|
+
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
147
180
|
): PathSchema<T> {
|
|
148
|
-
return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
|
|
181
|
+
return toPathSchemaInternal(validator, schema, name, rootSchema, formData, undefined, experimental_customMergeAllOf);
|
|
149
182
|
}
|
package/src/toErrorList.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { ErrorSchema, GenericObjectType, RJSFValidationError } from './types';
|
|
|
11
11
|
*/
|
|
12
12
|
export default function toErrorList<T = any>(
|
|
13
13
|
errorSchema?: ErrorSchema<T>,
|
|
14
|
-
fieldPath: string[] = []
|
|
14
|
+
fieldPath: string[] = [],
|
|
15
15
|
): RJSFValidationError[] {
|
|
16
16
|
if (!errorSchema) {
|
|
17
17
|
return [];
|
|
@@ -26,7 +26,7 @@ export default function toErrorList<T = any>(
|
|
|
26
26
|
message,
|
|
27
27
|
stack: `${property} ${message}`,
|
|
28
28
|
};
|
|
29
|
-
})
|
|
29
|
+
}),
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
return Object.keys(errorSchema).reduce((acc, key) => {
|