@rjsf/utils 6.6.1 → 6.7.0
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/LICENSE.md +201 -0
- package/dist/index.cjs +534 -376
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +534 -376
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +561 -400
- package/lib/ErrorSchemaBuilder.d.ts +1 -1
- package/lib/SelectedOptionDescription.d.ts +4 -0
- package/lib/SelectedOptionDescription.js +24 -0
- package/lib/SelectedOptionDescription.js.map +1 -0
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -0
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js +2 -0
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +1 -1
- package/lib/constIsAjvDataReference.d.ts +1 -1
- package/lib/constants.d.ts +8 -5
- package/lib/constants.js +10 -7
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.d.ts +1 -1
- package/lib/createErrorHandler.js +2 -6
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +1 -1
- package/lib/createSchemaUtils.js +3 -1
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js +3 -3
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +1 -1
- package/lib/dateRangeOptions.js +8 -7
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/englishStringTranslator.d.ts +1 -1
- package/lib/enumOptionSelectedValue.d.ts +1 -1
- package/lib/enumOptionValueDecoder.d.ts +1 -1
- package/lib/enumOptionValueDecoder.js +1 -1
- package/lib/enumOptionValueDecoder.js.map +1 -1
- package/lib/enumOptionValueEncoder.d.ts +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +1 -1
- package/lib/enumOptionsSelectValue.d.ts +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +2 -2
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +4 -0
- package/lib/enums.js +4 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +1 -1
- package/lib/findSchemaDefinition.js +15 -15
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.js +4 -6
- package/lib/getChangedFields.js.map +1 -1
- package/lib/getDateElementProps.d.ts +3 -3
- package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +1 -0
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js +10 -11
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getOptionValueFormat.d.ts +1 -1
- package/lib/getSchemaType.d.ts +1 -1
- package/lib/getSchemaType.js +2 -1
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +1 -1
- package/lib/getSubmitButtonOptions.js +1 -1
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +1 -1
- package/lib/getTestIds.d.ts +1 -1
- package/lib/getUiOptions.d.ts +1 -1
- package/lib/getUiOptions.js +2 -1
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +1 -1
- package/lib/getWidget.js +4 -4
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.js +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.d.ts +1 -1
- package/lib/hashForSchema.d.ts +3 -1
- package/lib/hashForSchema.js +11 -4
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +1 -1
- package/lib/index.d.ts +14 -7
- package/lib/index.js +5 -2
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +1 -1
- package/lib/isCustomWidget.d.ts +1 -1
- package/lib/isCustomWidget.js +1 -1
- package/lib/isCustomWidget.js.map +1 -1
- package/lib/isFixedItems.d.ts +3 -3
- package/lib/isFixedItems.js +3 -3
- package/lib/isFixedItems.js.map +1 -1
- package/lib/isRootSchema.d.ts +1 -1
- package/lib/isRootSchema.js +2 -3
- package/lib/isRootSchema.js.map +1 -1
- package/lib/labelValue.d.ts +1 -1
- package/lib/logUnsupportedDefaultForEnum.d.ts +9 -0
- package/lib/logUnsupportedDefaultForEnum.js +18 -0
- package/lib/logUnsupportedDefaultForEnum.js.map +1 -0
- package/lib/lookupFromFormContext.d.ts +1 -1
- package/lib/mergeDefaultsWithFormData.js +6 -5
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +4 -2
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +4 -2
- package/lib/mergeSchemas.js +13 -6
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/nameGenerators.d.ts +1 -1
- package/lib/optionsList.d.ts +1 -1
- package/lib/optionsList.js +22 -21
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js +3 -3
- package/lib/orderProperties.js.map +1 -1
- package/lib/pad.js +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 +2 -4
- package/lib/parser/ParserValidator.js +2 -0
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +1 -1
- package/lib/parser/schemaParser.d.ts +2 -2
- package/lib/parser/schemaParser.js +7 -7
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/rangeSpec.d.ts +1 -2
- package/lib/rangeSpec.js.map +1 -1
- package/lib/removeOptionalEmptyObjects.d.ts +1 -1
- package/lib/removeOptionalEmptyObjects.js +6 -8
- package/lib/removeOptionalEmptyObjects.js.map +1 -1
- package/lib/resolveUiSchema.d.ts +1 -1
- package/lib/resolveUiSchema.js +16 -16
- package/lib/resolveUiSchema.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js +1 -3
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.d.ts +1 -1
- package/lib/schema/getClosestMatchingOption.js +6 -9
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +4 -4
- package/lib/schema/getDefaultFormState.js +81 -43
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +1 -1
- package/lib/schema/getDisplayLabel.js +2 -3
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +2 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +1 -1
- package/lib/schema/index.js +9 -3
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +1 -1
- package/lib/schema/isMultiSelect.d.ts +1 -1
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +1 -1
- package/lib/schema/isSelect.js +1 -1
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/omitExtraData.d.ts +1 -1
- package/lib/schema/omitExtraData.js +66 -52
- package/lib/schema/omitExtraData.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +7 -3
- package/lib/schema/retrieveSchema.js +83 -56
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +1 -1
- package/lib/schema/sanitizeDataForNewSchema.js +48 -7
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +1 -1
- package/lib/schema/toPathSchema.js +9 -5
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +1 -1
- package/lib/schemaRequiresTrueValue.js +4 -3
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shallowEquals.js +2 -2
- package/lib/shallowEquals.js.map +1 -1
- package/lib/shouldRenderOptionalField.d.ts +1 -1
- package/lib/toConstant.d.ts +1 -1
- package/lib/toDateString.d.ts +1 -1
- package/lib/toErrorList.d.ts +1 -1
- package/lib/toErrorList.js +3 -3
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +1 -1
- package/lib/toFieldPathId.d.ts +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +63 -57
- package/lib/unwrapErrorHandler.d.ts +1 -1
- package/lib/unwrapErrorHandler.js +7 -9
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/useAltDateWidgetProps.d.ts +6 -6
- package/lib/useAltDateWidgetProps.js +3 -3
- package/lib/useAltDateWidgetProps.js.map +1 -1
- package/lib/useFileWidgetProps.d.ts +2 -2
- package/lib/useFileWidgetProps.js +3 -3
- package/lib/useFileWidgetProps.js.map +1 -1
- package/lib/validationDataMerge.d.ts +1 -1
- package/lib/withIdRefPrefix.d.ts +1 -1
- package/lib/withIdRefPrefix.js +12 -12
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +19 -19
- package/src/ErrorSchemaBuilder.ts +1 -1
- package/src/SelectedOptionDescription.tsx +48 -0
- package/src/allowAdditionalItems.ts +2 -1
- package/src/asNumber.ts +2 -0
- package/src/canExpand.ts +1 -1
- package/src/constIsAjvDataReference.ts +2 -2
- package/src/constants.ts +10 -7
- package/src/createErrorHandler.ts +6 -7
- package/src/createSchemaUtils.ts +4 -2
- package/src/dataURItoBlob.ts +3 -3
- package/src/dateRangeOptions.ts +9 -7
- package/src/englishStringTranslator.ts +1 -1
- package/src/enumOptionSelectedValue.ts +1 -1
- package/src/enumOptionValueDecoder.ts +2 -2
- package/src/enumOptionValueEncoder.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +1 -1
- package/src/enumOptionsIndexForValue.ts +2 -2
- package/src/enumOptionsIsSelected.ts +1 -1
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +2 -2
- package/src/enums.ts +4 -0
- package/src/findSchemaDefinition.ts +18 -17
- package/src/getChangedFields.ts +5 -5
- package/src/getDateElementProps.ts +3 -3
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +1 -1
- package/src/getOptionMatchingSimpleDiscriminator.ts +11 -15
- package/src/getOptionValueFormat.ts +1 -1
- package/src/getSchemaType.ts +3 -2
- package/src/getSubmitButtonOptions.ts +3 -3
- package/src/getTemplate.ts +1 -1
- package/src/getTestIds.ts +1 -1
- package/src/getUiOptions.ts +10 -2
- package/src/getWidget.tsx +5 -6
- package/src/guessType.ts +1 -1
- package/src/hasWidget.ts +1 -1
- package/src/hashForSchema.ts +12 -5
- package/src/idGenerators.ts +1 -1
- package/src/index.ts +16 -5
- package/src/isConstant.ts +1 -1
- package/src/isCustomWidget.ts +2 -2
- package/src/isFixedItems.ts +4 -4
- package/src/isRootSchema.ts +3 -5
- package/src/labelValue.ts +1 -1
- package/src/logUnsupportedDefaultForEnum.ts +28 -0
- package/src/lookupFromFormContext.ts +1 -1
- package/src/mergeDefaultsWithFormData.ts +8 -7
- package/src/mergeObjects.ts +2 -2
- package/src/mergeSchemas.ts +14 -7
- package/src/nameGenerators.ts +1 -1
- package/src/optionsList.ts +21 -23
- package/src/orderProperties.ts +4 -4
- package/src/pad.ts +1 -1
- package/src/parseDateString.ts +2 -2
- package/src/parser/ParserValidator.ts +4 -4
- package/src/parser/index.ts +1 -1
- package/src/parser/schemaParser.ts +10 -9
- package/src/rangeSpec.ts +1 -2
- package/src/removeOptionalEmptyObjects.ts +8 -11
- package/src/resolveUiSchema.ts +32 -25
- package/src/schema/findFieldInSchema.ts +1 -1
- package/src/schema/findSelectedOptionInXxxOf.ts +17 -7
- package/src/schema/getClosestMatchingOption.ts +17 -11
- package/src/schema/getDefaultFormState.ts +104 -43
- package/src/schema/getDisplayLabel.ts +4 -5
- package/src/schema/getFirstMatchingOption.ts +3 -3
- package/src/schema/getFromSchema.ts +1 -1
- package/src/schema/index.ts +3 -0
- package/src/schema/isFilesArray.ts +1 -1
- package/src/schema/isMultiSelect.ts +7 -1
- package/src/schema/isSelect.ts +8 -2
- package/src/schema/omitExtraData.ts +73 -60
- package/src/schema/retrieveSchema.ts +131 -83
- package/src/schema/sanitizeDataForNewSchema.ts +57 -8
- package/src/schema/toPathSchema.ts +11 -7
- package/src/schemaRequiresTrueValue.ts +4 -4
- package/src/shallowEquals.ts +2 -2
- package/src/shouldRenderOptionalField.ts +1 -1
- package/src/toConstant.ts +1 -1
- package/src/toDateString.ts +1 -1
- package/src/toErrorList.ts +4 -4
- package/src/toErrorSchema.ts +1 -1
- package/src/toFieldPathId.ts +1 -1
- package/src/types.ts +92 -63
- package/src/unwrapErrorHandler.ts +11 -12
- package/src/useAltDateWidgetProps.tsx +10 -8
- package/src/useFileWidgetProps.ts +7 -7
- package/src/validationDataMerge.ts +1 -1
- package/src/withIdRefPrefix.ts +12 -12
|
@@ -8,7 +8,7 @@ import findSchemaDefinition from '../findSchemaDefinition';
|
|
|
8
8
|
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
9
9
|
import getSchemaType from '../getSchemaType';
|
|
10
10
|
import isObject from '../isObject';
|
|
11
|
-
import {
|
|
11
|
+
import type {
|
|
12
12
|
Experimental_CustomMergeAllOf,
|
|
13
13
|
FormContextType,
|
|
14
14
|
GenericObjectType,
|
|
@@ -48,6 +48,7 @@ export function getUsedFormData<T = any>(formData: T | undefined, fields: string
|
|
|
48
48
|
* @param [formData] - The form data to use while checking for empty objects/arrays
|
|
49
49
|
* @deprecated - To be removed as an exported `@rjsf/utils` function in a future release
|
|
50
50
|
*/
|
|
51
|
+
// oxlint-disable-next-line typescript/no-deprecated
|
|
51
52
|
export function getFieldNames<T = any>(pathSchema: PathSchema<T>, formData?: T): string[][] {
|
|
52
53
|
const formValueHasData = (value: T, isLeaf: boolean) =>
|
|
53
54
|
typeof value !== 'object' || isEmpty(value) || (isLeaf && !isEmpty(value));
|
|
@@ -170,14 +171,14 @@ export default function omitExtraData<
|
|
|
170
171
|
* are always written when defined. Always returns `target` — pruning of the object itself is
|
|
171
172
|
* the caller's responsibility.
|
|
172
173
|
*
|
|
173
|
-
* @param
|
|
174
|
+
* @param childSchema - The object schema describing which properties are allowed
|
|
174
175
|
* @param source - The source form data object to read values from
|
|
175
176
|
* @param target - The accumulator object to write filtered values into
|
|
176
177
|
* @returns - `target` after all schema-defined properties have been processed
|
|
177
178
|
*/
|
|
178
|
-
function handleObject(
|
|
179
|
-
const { properties, additionalProperties, patternProperties, propertyNames } =
|
|
180
|
-
const requiredSet = new Set(
|
|
179
|
+
function handleObject(childSchema: S, source: GenericObjectType, target: GenericObjectType): GenericObjectType {
|
|
180
|
+
const { properties, additionalProperties, patternProperties, propertyNames } = childSchema;
|
|
181
|
+
const requiredSet = new Set(childSchema.required ?? []);
|
|
181
182
|
|
|
182
183
|
/** Recursively omits extra data from `value` via `omit`, then conditionally writes the result to
|
|
183
184
|
* `target[key]`. Optional object-valued properties are dropped when every key in the filtered
|
|
@@ -196,11 +197,11 @@ export default function omitExtraData<
|
|
|
196
197
|
const v = omit(schemaDef, value, target[key]);
|
|
197
198
|
if (!required && isObject(v)) {
|
|
198
199
|
// Resolve $ref so we can inspect the effective required list for the inner schema.
|
|
199
|
-
let sd = isSchemaObj(schemaDef
|
|
200
|
+
let sd = isSchemaObj(schemaDef) ? schemaDef : ({} as S);
|
|
200
201
|
if (sd.$ref !== undefined) {
|
|
201
|
-
sd = findSchemaDefinition(sd.$ref, rootSchema)
|
|
202
|
+
sd = findSchemaDefinition<S>(sd.$ref, rootSchema);
|
|
202
203
|
}
|
|
203
|
-
const innerRequired = new Set(
|
|
204
|
+
const innerRequired = new Set(sd.required ?? []);
|
|
204
205
|
// Drop this optional object when every key in v is both optional in the inner schema
|
|
205
206
|
// and has an empty value. Vacuously true for {} so empty objects are always dropped.
|
|
206
207
|
const shouldDrop = Object.entries(v as GenericObjectType).every(
|
|
@@ -211,6 +212,7 @@ export default function omitExtraData<
|
|
|
211
212
|
}
|
|
212
213
|
}
|
|
213
214
|
if (v !== undefined) {
|
|
215
|
+
// oxlint-disable-next-line no-param-reassign
|
|
214
216
|
target[key] = v;
|
|
215
217
|
}
|
|
216
218
|
}
|
|
@@ -231,15 +233,14 @@ export default function omitExtraData<
|
|
|
231
233
|
]);
|
|
232
234
|
const knownProperties = new Set(Object.keys(properties ?? {}));
|
|
233
235
|
for (const [key, value] of Object.entries(source)) {
|
|
234
|
-
if (knownProperties.has(key)) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
236
|
+
if (!knownProperties.has(key)) {
|
|
237
|
+
const matched = patterns.find(([re]) => re.test(key));
|
|
238
|
+
if (matched === undefined) {
|
|
239
|
+
patternPropertiesRest.push(key);
|
|
240
|
+
} else {
|
|
241
|
+
setProperty(key, matched[1], value);
|
|
242
|
+
}
|
|
241
243
|
}
|
|
242
|
-
setProperty(key, matched[1], value);
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
246
|
|
|
@@ -254,10 +255,9 @@ export default function omitExtraData<
|
|
|
254
255
|
} else {
|
|
255
256
|
const knownProperties = new Set(Object.keys(properties ?? {}));
|
|
256
257
|
for (const [key, value] of Object.entries(source)) {
|
|
257
|
-
if (knownProperties.has(key)) {
|
|
258
|
-
|
|
258
|
+
if (!knownProperties.has(key)) {
|
|
259
|
+
setProperty(key, addlSchema, value);
|
|
259
260
|
}
|
|
260
|
-
setProperty(key, addlSchema, value);
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
}
|
|
@@ -265,6 +265,7 @@ export default function omitExtraData<
|
|
|
265
265
|
// When propertyNames is present, the schema only constrains key names — all source keys are valid.
|
|
266
266
|
if (propertyNames !== undefined) {
|
|
267
267
|
for (const [key, value] of Object.entries(source)) {
|
|
268
|
+
// oxlint-disable-next-line no-param-reassign
|
|
268
269
|
target[key] = value;
|
|
269
270
|
}
|
|
270
271
|
}
|
|
@@ -277,27 +278,27 @@ export default function omitExtraData<
|
|
|
277
278
|
* per-index schema; elements beyond the tuple length are covered by `additionalItems` when present.
|
|
278
279
|
* For list schemas (`items` is a single schema) every element is filtered by that schema.
|
|
279
280
|
*
|
|
280
|
-
* @param
|
|
281
|
+
* @param childSchema - The array schema describing `items` and optionally `additionalItems`
|
|
281
282
|
* @param source - The source array to read elements from
|
|
282
283
|
* @param target - The accumulator array to push filtered elements into
|
|
283
284
|
* @returns - `target` after all applicable source elements have been pushed
|
|
284
285
|
*/
|
|
285
|
-
function handleArray(
|
|
286
|
-
const { items, additionalItems } =
|
|
286
|
+
function handleArray(childSchema: S, source: unknown[], target: unknown[]): unknown[] {
|
|
287
|
+
const { items, additionalItems } = childSchema;
|
|
287
288
|
if (items !== undefined) {
|
|
288
289
|
if (Array.isArray(items)) {
|
|
289
|
-
for (let i = 0; i < items.length; i
|
|
290
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
290
291
|
target.push(omit(items[i] as S | boolean, source[i]));
|
|
291
292
|
}
|
|
292
293
|
} else {
|
|
293
|
-
for (let i = 0; i < source.length; i
|
|
294
|
+
for (let i = 0; i < source.length; i += 1) {
|
|
294
295
|
target.push(omit(items as S | boolean, source[i]));
|
|
295
296
|
}
|
|
296
297
|
}
|
|
297
298
|
}
|
|
298
299
|
// additionalItems covers tuple items beyond the items array length.
|
|
299
300
|
if (additionalItems) {
|
|
300
|
-
for (let i = target.length; i < source.length; i
|
|
301
|
+
for (let i = target.length; i < source.length; i += 1) {
|
|
301
302
|
target.push(omit(additionalItems as S | boolean, source[i]));
|
|
302
303
|
}
|
|
303
304
|
}
|
|
@@ -310,13 +311,13 @@ export default function omitExtraData<
|
|
|
310
311
|
* (`then` or `else`) is applied via `omit`. When the selected branch is absent, `target` is returned
|
|
311
312
|
* unchanged.
|
|
312
313
|
*
|
|
313
|
-
* @param
|
|
314
|
+
* @param childSchema - The schema potentially containing `if`, `then`, and `else` keywords
|
|
314
315
|
* @param source - The current form data value, passed to `validator.isValid` and the branch `omit`
|
|
315
316
|
* @param target - The already-filtered value to merge the branch result into
|
|
316
317
|
* @returns - The result of applying the matched branch, or `target` when no branch applies
|
|
317
318
|
*/
|
|
318
|
-
function handleConditions(
|
|
319
|
-
const { if: condition, then, else: otherwise } =
|
|
319
|
+
function handleConditions(childSchema: S, source: unknown, target: unknown): unknown {
|
|
320
|
+
const { if: condition, then, else: otherwise } = childSchema;
|
|
320
321
|
if (condition === undefined) {
|
|
321
322
|
return target;
|
|
322
323
|
}
|
|
@@ -335,33 +336,33 @@ export default function omitExtraData<
|
|
|
335
336
|
* actual `omit` call.
|
|
336
337
|
*
|
|
337
338
|
* @param oneOf - The `oneOf` array from the schema, or `undefined`
|
|
338
|
-
* @param
|
|
339
|
+
* @param childSchema - The parent schema containing the `oneOf` keyword
|
|
339
340
|
* @param source - The current form data value used to score each option
|
|
340
341
|
* @param target - The already-filtered value to merge the winning option's result into
|
|
341
342
|
* @returns - The result of applying the best-matching option, or `target` when no matching applies
|
|
342
343
|
*/
|
|
343
|
-
function handleOneOf(oneOf: S['oneOf'],
|
|
344
|
-
if (!Array.isArray(oneOf) || isSelect(validator,
|
|
344
|
+
function handleOneOf(oneOf: S['oneOf'], childSchema: S, source: unknown, target: unknown): unknown {
|
|
345
|
+
if (!Array.isArray(oneOf) || isSelect(validator, childSchema, rootSchema, experimental_customMergeAllOf)) {
|
|
345
346
|
return target;
|
|
346
347
|
}
|
|
347
348
|
// Resolve $refs and relax additionalProperties:false → true in one pass for scoring only.
|
|
348
349
|
// The unrelaxed resolved schema is re-derived for the winning option so that omit() still
|
|
349
350
|
// respects additionalProperties:false during filtering.
|
|
350
|
-
const scoringOptions = relaxOptionsForScoring<S>(oneOf as
|
|
351
|
+
const scoringOptions = relaxOptionsForScoring<S>(oneOf as (S | boolean)[], true, rootSchema);
|
|
351
352
|
const bestIndex = getClosestMatchingOption<T, S, F>(
|
|
352
353
|
validator,
|
|
353
354
|
rootSchema,
|
|
354
355
|
source as T,
|
|
355
356
|
scoringOptions,
|
|
356
357
|
0,
|
|
357
|
-
getDiscriminatorFieldFromSchema<S>(
|
|
358
|
+
getDiscriminatorFieldFromSchema<S>(childSchema),
|
|
358
359
|
experimental_customMergeAllOf,
|
|
359
360
|
);
|
|
360
|
-
const winning = (oneOf as
|
|
361
|
+
const winning = (oneOf as (S | boolean)[])[bestIndex];
|
|
361
362
|
// For object options, re-resolve without relaxation so additionalProperties:false is respected.
|
|
362
363
|
// For boolean options, scoringOptions already holds the converted schema (true→{}, false→{not:{}}).
|
|
363
364
|
const resolved: S = isObject(winning)
|
|
364
|
-
? resolveAllReferences<S>(winning
|
|
365
|
+
? resolveAllReferences<S>(winning, rootSchema, [])
|
|
365
366
|
: scoringOptions[bestIndex];
|
|
366
367
|
return omit(resolved, source, target);
|
|
367
368
|
}
|
|
@@ -371,13 +372,13 @@ export default function omitExtraData<
|
|
|
371
372
|
* defaults can flow through all branches) every branch is applied in sequence. For non-empty sources
|
|
372
373
|
* the best-matching branch is selected via `handleOneOf`.
|
|
373
374
|
*
|
|
374
|
-
* @param
|
|
375
|
+
* @param childSchema - The schema potentially containing an `anyOf` keyword
|
|
375
376
|
* @param source - The current form data value; empty or undefined triggers all-branch application
|
|
376
377
|
* @param target - The already-filtered value to merge branch results into
|
|
377
378
|
* @returns - The result after applying the relevant `anyOf` branch(es), or `target` when inapplicable
|
|
378
379
|
*/
|
|
379
|
-
function handleAnyOf(
|
|
380
|
-
const { anyOf } =
|
|
380
|
+
function handleAnyOf(childSchema: S, source: unknown, target: unknown): unknown {
|
|
381
|
+
const { anyOf } = childSchema;
|
|
381
382
|
if (!Array.isArray(anyOf)) {
|
|
382
383
|
return target;
|
|
383
384
|
}
|
|
@@ -385,14 +386,15 @@ export default function omitExtraData<
|
|
|
385
386
|
if (
|
|
386
387
|
source === undefined ||
|
|
387
388
|
(Array.isArray(source) && source.length === 0) ||
|
|
388
|
-
(isObject(source) && Object.keys(source
|
|
389
|
+
(isObject(source) && Object.keys(source).length === 0)
|
|
389
390
|
) {
|
|
390
|
-
|
|
391
|
-
|
|
391
|
+
let result = target;
|
|
392
|
+
for (const branch of anyOf as (S | boolean)[]) {
|
|
393
|
+
result = omit(branch, source, result);
|
|
392
394
|
}
|
|
393
|
-
return
|
|
395
|
+
return result;
|
|
394
396
|
}
|
|
395
|
-
return handleOneOf(anyOf,
|
|
397
|
+
return handleOneOf(anyOf, childSchema, source, target);
|
|
396
398
|
}
|
|
397
399
|
|
|
398
400
|
/** Applies schema-based `dependencies` from `schema` to `source`, merging each active dependency's
|
|
@@ -400,24 +402,24 @@ export default function omitExtraData<
|
|
|
400
402
|
* schema dependencies are processed. A dependency is considered active when its trigger key is
|
|
401
403
|
* present on `source`.
|
|
402
404
|
*
|
|
403
|
-
* @param
|
|
405
|
+
* @param childSchema - The schema potentially containing a `dependencies` keyword
|
|
404
406
|
* @param source - The current form data value; must be a plain object for dependencies to apply
|
|
405
407
|
* @param target - The already-filtered value to merge dependency results into
|
|
406
408
|
* @returns - The result after applying all active schema dependencies, or `target` when inapplicable
|
|
407
409
|
*/
|
|
408
|
-
function handleDependencies(
|
|
409
|
-
const { dependencies } =
|
|
410
|
+
function handleDependencies(childSchema: S, source: unknown, target: unknown): unknown {
|
|
411
|
+
const { dependencies } = childSchema;
|
|
410
412
|
if (dependencies === undefined || !isObjectValue(source)) {
|
|
411
413
|
return target;
|
|
412
414
|
}
|
|
415
|
+
let result = target;
|
|
413
416
|
for (const [key, deps] of Object.entries(dependencies)) {
|
|
414
417
|
// Skip property dependencies (string arrays); only process schema dependencies.
|
|
415
|
-
if (
|
|
416
|
-
|
|
418
|
+
if (key in source && !Array.isArray(deps)) {
|
|
419
|
+
result = omit(deps as S | boolean, source, result);
|
|
417
420
|
}
|
|
418
|
-
target = omit(deps as S | boolean, source, target);
|
|
419
421
|
}
|
|
420
|
-
return
|
|
422
|
+
return result;
|
|
421
423
|
}
|
|
422
424
|
|
|
423
425
|
/** Core recursive filter. Resolves `$ref`s, merges `allOf`, then delegates to the type-specific
|
|
@@ -438,34 +440,45 @@ export default function omitExtraData<
|
|
|
438
440
|
return source;
|
|
439
441
|
}
|
|
440
442
|
|
|
441
|
-
let
|
|
442
|
-
const { $ref: ref, allOf } =
|
|
443
|
+
let localSchema = schemaDef;
|
|
444
|
+
const { $ref: ref, allOf } = localSchema;
|
|
443
445
|
|
|
444
446
|
if (ref !== undefined) {
|
|
445
447
|
return omit(findSchemaDefinition<S>(ref, rootSchema), source, target);
|
|
446
448
|
}
|
|
447
449
|
if (allOf) {
|
|
448
|
-
|
|
450
|
+
localSchema = doMergeAllOf<S>(localSchema, experimental_customMergeAllOf);
|
|
451
|
+
// Schemas whose allOf entries contain if/then/else keywords may not fully merge: the merger
|
|
452
|
+
// can only hoist one if/then/else triple to the parent level, so additional entries stay in
|
|
453
|
+
// allOf. Process any that remain so their conditional properties are not silently dropped.
|
|
454
|
+
// See: https://github.com/rjsf-team/react-jsonschema-form/issues/5142
|
|
455
|
+
const remainingAllOf = localSchema.allOf;
|
|
456
|
+
if (remainingAllOf) {
|
|
457
|
+
for (let i = 0; i < remainingAllOf.length; i++) {
|
|
458
|
+
// oxlint-disable-next-line no-param-reassign
|
|
459
|
+
target = omit(remainingAllOf[i] as S | boolean, source, target);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
449
462
|
}
|
|
450
463
|
|
|
451
|
-
|
|
464
|
+
let filtered = handleAnyOf(localSchema, source, handleOneOf(localSchema.oneOf, localSchema, source, target));
|
|
452
465
|
|
|
453
|
-
const type = getSchemaType<S>(
|
|
466
|
+
const type = getSchemaType<S>(localSchema);
|
|
454
467
|
if (type === 'object') {
|
|
455
468
|
if (!isObjectValue(source)) {
|
|
456
469
|
return undefined;
|
|
457
470
|
}
|
|
458
|
-
|
|
471
|
+
filtered = handleObject(localSchema, source, isObjectValue(filtered) ? filtered : {});
|
|
459
472
|
} else if (type === 'array') {
|
|
460
473
|
if (!Array.isArray(source)) {
|
|
461
474
|
return undefined;
|
|
462
475
|
}
|
|
463
|
-
|
|
464
|
-
} else if (
|
|
465
|
-
|
|
476
|
+
filtered = handleArray(localSchema, source, Array.isArray(filtered) ? filtered : []);
|
|
477
|
+
} else if (filtered === undefined) {
|
|
478
|
+
filtered = source;
|
|
466
479
|
}
|
|
467
480
|
|
|
468
|
-
return handleDependencies(
|
|
481
|
+
return handleDependencies(localSchema, source, handleConditions(localSchema, source, filtered));
|
|
469
482
|
}
|
|
470
483
|
|
|
471
484
|
return omit(schema, formData) as T | undefined;
|