@rjsf/utils 6.5.2 → 6.6.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.
Files changed (146) hide show
  1. package/dist/index.cjs +628 -441
  2. package/dist/index.cjs.map +4 -4
  3. package/dist/utils.esm.js +624 -437
  4. package/dist/utils.esm.js.map +4 -4
  5. package/dist/utils.umd.js +632 -445
  6. package/lib/ErrorSchemaBuilder.js.map +1 -1
  7. package/lib/canExpand.js.map +1 -1
  8. package/lib/constIsAjvDataReference.js +1 -1
  9. package/lib/constIsAjvDataReference.js.map +1 -1
  10. package/lib/createSchemaUtils.js +3 -3
  11. package/lib/createSchemaUtils.js.map +1 -1
  12. package/lib/enumOptionSelectedValue.js.map +1 -1
  13. package/lib/enumOptionValueDecoder.js.map +1 -1
  14. package/lib/enumOptionsDeselectValue.js +1 -1
  15. package/lib/enumOptionsDeselectValue.js.map +1 -1
  16. package/lib/enumOptionsIndexForValue.js.map +1 -1
  17. package/lib/enumOptionsIsSelected.js.map +1 -1
  18. package/lib/enumOptionsSelectValue.js +1 -1
  19. package/lib/enumOptionsSelectValue.js.map +1 -1
  20. package/lib/enumOptionsValueForIndex.js +2 -2
  21. package/lib/enumOptionsValueForIndex.js.map +1 -1
  22. package/lib/enums.d.ts +2 -0
  23. package/lib/enums.js +2 -0
  24. package/lib/enums.js.map +1 -1
  25. package/lib/findSchemaDefinition.js +4 -4
  26. package/lib/findSchemaDefinition.js.map +1 -1
  27. package/lib/getChangedFields.js +3 -3
  28. package/lib/getChangedFields.js.map +1 -1
  29. package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
  30. package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
  31. package/lib/getTestIds.d.ts +1 -1
  32. package/lib/getTestIds.js +4 -3
  33. package/lib/getTestIds.js.map +1 -1
  34. package/lib/getWidget.js +1 -1
  35. package/lib/getWidget.js.map +1 -1
  36. package/lib/idGenerators.js.map +1 -1
  37. package/lib/index.d.ts +6 -6
  38. package/lib/index.js +6 -6
  39. package/lib/index.js.map +1 -1
  40. package/lib/isFormDataAvailable.js +1 -1
  41. package/lib/isFormDataAvailable.js.map +1 -1
  42. package/lib/isRootSchema.js +1 -1
  43. package/lib/isRootSchema.js.map +1 -1
  44. package/lib/jsonSchemaAugmentation.d.ts +19 -0
  45. package/lib/jsonSchemaAugmentation.js +2 -0
  46. package/lib/jsonSchemaAugmentation.js.map +1 -0
  47. package/lib/mergeDefaultsWithFormData.js +2 -2
  48. package/lib/mergeDefaultsWithFormData.js.map +1 -1
  49. package/lib/parser/ParserValidator.js +1 -1
  50. package/lib/parser/ParserValidator.js.map +1 -1
  51. package/lib/parser/index.d.ts +1 -1
  52. package/lib/parser/index.js.map +1 -1
  53. package/lib/parser/schemaParser.js +2 -2
  54. package/lib/parser/schemaParser.js.map +1 -1
  55. package/lib/removeOptionalEmptyObjects.d.ts +2 -0
  56. package/lib/removeOptionalEmptyObjects.js +8 -29
  57. package/lib/removeOptionalEmptyObjects.js.map +1 -1
  58. package/lib/schema/findFieldInSchema.d.ts +2 -2
  59. package/lib/schema/findFieldInSchema.js +7 -6
  60. package/lib/schema/findFieldInSchema.js.map +1 -1
  61. package/lib/schema/findSelectedOptionInXxxOf.js +1 -1
  62. package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
  63. package/lib/schema/getClosestMatchingOption.js +3 -3
  64. package/lib/schema/getClosestMatchingOption.js.map +1 -1
  65. package/lib/schema/getDefaultFormState.d.ts +4 -4
  66. package/lib/schema/getDefaultFormState.js +17 -22
  67. package/lib/schema/getDefaultFormState.js.map +1 -1
  68. package/lib/schema/getFromSchema.d.ts +3 -3
  69. package/lib/schema/getFromSchema.js +3 -3
  70. package/lib/schema/getFromSchema.js.map +1 -1
  71. package/lib/schema/index.d.ts +4 -4
  72. package/lib/schema/index.js +4 -4
  73. package/lib/schema/index.js.map +1 -1
  74. package/lib/schema/isMultiSelect.js.map +1 -1
  75. package/lib/schema/omitExtraData.d.ts +18 -8
  76. package/lib/schema/omitExtraData.js +352 -16
  77. package/lib/schema/omitExtraData.js.map +1 -1
  78. package/lib/schema/retrieveSchema.d.ts +15 -0
  79. package/lib/schema/retrieveSchema.js +36 -13
  80. package/lib/schema/retrieveSchema.js.map +1 -1
  81. package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
  82. package/lib/schema/shallowAllOfMerge.d.ts +11 -0
  83. package/lib/schema/shallowAllOfMerge.js +18 -0
  84. package/lib/schema/shallowAllOfMerge.js.map +1 -0
  85. package/lib/schema/toPathSchema.d.ts +1 -0
  86. package/lib/schema/toPathSchema.js +2 -1
  87. package/lib/schema/toPathSchema.js.map +1 -1
  88. package/lib/shouldRenderOptionalField.js +1 -1
  89. package/lib/shouldRenderOptionalField.js.map +1 -1
  90. package/lib/toErrorSchema.js.map +1 -1
  91. package/lib/tsconfig.tsbuildinfo +1 -1
  92. package/lib/types.d.ts +17 -5
  93. package/lib/types.js +1 -1
  94. package/lib/types.js.map +1 -1
  95. package/lib/useFileWidgetProps.d.ts +1 -1
  96. package/lib/useFileWidgetProps.js +9 -10
  97. package/lib/useFileWidgetProps.js.map +1 -1
  98. package/lib/withIdRefPrefix.js +1 -1
  99. package/lib/withIdRefPrefix.js.map +1 -1
  100. package/package.json +11 -11
  101. package/src/ErrorSchemaBuilder.ts +1 -1
  102. package/src/canExpand.ts +1 -1
  103. package/src/constIsAjvDataReference.ts +3 -2
  104. package/src/createSchemaUtils.ts +22 -20
  105. package/src/enumOptionSelectedValue.ts +1 -1
  106. package/src/enumOptionValueDecoder.ts +1 -1
  107. package/src/enumOptionsDeselectValue.ts +2 -2
  108. package/src/enumOptionsIndexForValue.ts +1 -1
  109. package/src/enumOptionsIsSelected.ts +1 -1
  110. package/src/enumOptionsSelectValue.ts +3 -2
  111. package/src/enumOptionsValueForIndex.ts +2 -2
  112. package/src/enums.ts +2 -0
  113. package/src/findSchemaDefinition.ts +4 -4
  114. package/src/getChangedFields.ts +4 -3
  115. package/src/getDiscriminatorFieldFromSchema.ts +1 -1
  116. package/src/getOptionMatchingSimpleDiscriminator.ts +1 -0
  117. package/src/getTestIds.ts +4 -3
  118. package/src/getWidget.tsx +2 -2
  119. package/src/idGenerators.ts +1 -1
  120. package/src/index.ts +6 -6
  121. package/src/isFormDataAvailable.ts +1 -1
  122. package/src/isRootSchema.ts +1 -1
  123. package/src/jsonSchemaAugmentation.ts +21 -0
  124. package/src/mergeDefaultsWithFormData.ts +4 -3
  125. package/src/parser/ParserValidator.ts +1 -1
  126. package/src/parser/index.ts +1 -1
  127. package/src/parser/schemaParser.ts +3 -3
  128. package/src/removeOptionalEmptyObjects.ts +8 -30
  129. package/src/schema/findFieldInSchema.ts +10 -8
  130. package/src/schema/findSelectedOptionInXxxOf.ts +1 -1
  131. package/src/schema/getClosestMatchingOption.ts +4 -4
  132. package/src/schema/getDefaultFormState.ts +18 -24
  133. package/src/schema/getFromSchema.ts +15 -8
  134. package/src/schema/index.ts +5 -3
  135. package/src/schema/isMultiSelect.ts +0 -1
  136. package/src/schema/omitExtraData.ts +398 -19
  137. package/src/schema/retrieveSchema.ts +41 -15
  138. package/src/schema/sanitizeDataForNewSchema.ts +1 -1
  139. package/src/schema/shallowAllOfMerge.ts +19 -0
  140. package/src/schema/toPathSchema.ts +2 -1
  141. package/src/shouldRenderOptionalField.ts +2 -2
  142. package/src/toErrorSchema.ts +1 -1
  143. package/src/tsconfig.json +0 -1
  144. package/src/types.ts +18 -5
  145. package/src/useFileWidgetProps.ts +9 -10
  146. package/src/withIdRefPrefix.ts +2 -1
@@ -1,4 +1,4 @@
1
- import { PathSchema, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types.js';
1
+ import { Experimental_CustomMergeAllOf, FormContextType, PathSchema, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types.js';
2
2
  /** Returns the `formData` with only the elements specified in the `fields` list
3
3
  *
4
4
  * @param formData - The data for the `Form`
@@ -13,14 +13,24 @@ export declare function getUsedFormData<T = any>(formData: T | undefined, fields
13
13
  * @deprecated - To be removed as an exported `@rjsf/utils` function in a future release
14
14
  */
15
15
  export declare function getFieldNames<T = any>(pathSchema: PathSchema<T>, formData?: T): string[][];
16
- /** Takes a `schema` and `formData` and returns a copy of the formData with any fields not defined in the schema removed.
17
- * This is useful for ensuring that only data that is relevant to the schema is preserved. Objects with
18
- * `additionalProperties` keyword set to `true` will not have their extra fields removed.
16
+ /** Returns true when a form value is considered empty: null/undefined/'', an empty array, or a plain
17
+ * object whose every own value is itself empty (recursive). Scalars like `0` and `false` are not empty.
18
+ *
19
+ * @param value - The value to check
20
+ * @returns - True if the value is considered empty, false otherwise
21
+ */
22
+ export declare function isValueEmpty(value: unknown): boolean;
23
+ /** A recursive, schema-driven filter that walks `schema` and `formData` in lockstep, keeping only
24
+ * values that are described by the schema. Handles `$ref`, `allOf`, `anyOf`, `oneOf`, `if/then/else`,
25
+ * `patternProperties`, `additionalProperties`, `propertyNames`, and `dependencies`. Optional object
26
+ * properties whose schema-filtered content is entirely empty (per `isValueEmpty`) are pruned; required
27
+ * properties and scalar values are always kept when schema-defined.
19
28
  *
20
29
  * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
21
- * @param schema - The schema to use for filtering the formData
22
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
30
+ * @param schema - The schema for which to filter the formData
31
+ * @param [rootSchema] - The root schema, used primarily to look up `$ref`s
23
32
  * @param [formData] - The data for the `Form`
24
- * @returns The `formData` after omitting extra data
33
+ * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
34
+ * @returns - The `formData` after omitting extra data, or `undefined` when `formData` is undefined
25
35
  */
26
- export default function omitExtraData<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema?: S, formData?: T): T | undefined;
36
+ export default function omitExtraData<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema?: S, formData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): T | undefined;
@@ -1,9 +1,16 @@
1
- import pick from 'lodash-es/pick.js';
2
- import isEmpty from 'lodash-es/isEmpty.js';
3
1
  import get from 'lodash-es/get.js';
2
+ import isEmpty from 'lodash-es/isEmpty.js';
3
+ import isNil from 'lodash-es/isNil.js';
4
+ import pick from 'lodash-es/pick.js';
4
5
  import { NAME_KEY, RJSF_ADDITIONAL_PROPERTIES_FLAG } from '../constants.js';
5
- import retrieveSchema from './retrieveSchema.js';
6
- import toPathSchema from './toPathSchema.js';
6
+ import findSchemaDefinition from '../findSchemaDefinition.js';
7
+ import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema.js';
8
+ import getSchemaType from '../getSchemaType.js';
9
+ import isObject from '../isObject.js';
10
+ import getClosestMatchingOption from './getClosestMatchingOption.js';
11
+ import isSelect from './isSelect.js';
12
+ import { relaxOptionsForScoring, resolveAllReferences } from './retrieveSchema.js';
13
+ import shallowAllOfMerge from './shallowAllOfMerge.js';
7
14
  /** Returns the `formData` with only the elements specified in the `fields` list
8
15
  *
9
16
  * @param formData - The data for the `Form`
@@ -59,21 +66,350 @@ export function getFieldNames(pathSchema, formData) {
59
66
  };
60
67
  return getAllPaths(pathSchema);
61
68
  }
62
- /** Takes a `schema` and `formData` and returns a copy of the formData with any fields not defined in the schema removed.
63
- * This is useful for ensuring that only data that is relevant to the schema is preserved. Objects with
64
- * `additionalProperties` keyword set to `true` will not have their extra fields removed.
69
+ /** Returns true when a form value is considered empty: null/undefined/'', an empty array, or a plain
70
+ * object whose every own value is itself empty (recursive). Scalars like `0` and `false` are not empty.
71
+ *
72
+ * @param value - The value to check
73
+ * @returns - True if the value is considered empty, false otherwise
74
+ */
75
+ export function isValueEmpty(value) {
76
+ if (isNil(value) || value === '') {
77
+ return true;
78
+ }
79
+ if (Array.isArray(value)) {
80
+ return value.length === 0;
81
+ }
82
+ if (isObject(value)) {
83
+ return Object.values(value).every(isValueEmpty);
84
+ }
85
+ return false;
86
+ }
87
+ /** Merges an `allOf` schema into a single flat schema, delegating to `experimental_customMergeAllOf`
88
+ * when provided or falling back to the module-level `shallowAllOfMerge` otherwise.
89
+ *
90
+ * @param schema - A schema containing an `allOf` array to be merged
91
+ * @param [experimental_customMergeAllOf] - Optional custom merge function; see `Form` documentation
92
+ * @returns - The merged schema with `allOf` resolved into a single schema object
93
+ */
94
+ function doMergeAllOf(schema, experimental_customMergeAllOf) {
95
+ return experimental_customMergeAllOf ? experimental_customMergeAllOf(schema) : shallowAllOfMerge(schema);
96
+ }
97
+ /** A recursive, schema-driven filter that walks `schema` and `formData` in lockstep, keeping only
98
+ * values that are described by the schema. Handles `$ref`, `allOf`, `anyOf`, `oneOf`, `if/then/else`,
99
+ * `patternProperties`, `additionalProperties`, `propertyNames`, and `dependencies`. Optional object
100
+ * properties whose schema-filtered content is entirely empty (per `isValueEmpty`) are pruned; required
101
+ * properties and scalar values are always kept when schema-defined.
65
102
  *
66
103
  * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
67
- * @param schema - The schema to use for filtering the formData
68
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
104
+ * @param schema - The schema for which to filter the formData
105
+ * @param [rootSchema] - The root schema, used primarily to look up `$ref`s
69
106
  * @param [formData] - The data for the `Form`
70
- * @returns The `formData` after omitting extra data
107
+ * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
108
+ * @returns - The `formData` after omitting extra data, or `undefined` when `formData` is undefined
71
109
  */
72
- export default function omitExtraData(validator, schema, rootSchema = {}, formData) {
73
- const retrievedSchema = retrieveSchema(validator, schema, rootSchema, formData);
74
- const pathSchema = toPathSchema(validator, retrievedSchema, '', rootSchema, formData);
75
- const fieldNames = getFieldNames(pathSchema, formData);
76
- const lodashFieldNames = fieldNames.map((fieldPaths) => Array.isArray(fieldPaths) ? fieldPaths.join('.') : fieldPaths);
77
- return getUsedFormData(formData, lodashFieldNames);
110
+ export default function omitExtraData(validator, schema, rootSchema = {}, formData, experimental_customMergeAllOf) {
111
+ /** Type predicate that narrows `value` to `GenericObjectType` — true when `value` is a plain,
112
+ * non-array object (i.e. a JSON object). Used to distinguish JSON objects from arrays and primitives.
113
+ *
114
+ * @param value - The value to check
115
+ * @returns - True if `value` is a plain non-array object
116
+ */
117
+ function isObjectValue(value) {
118
+ return isObject(value);
119
+ }
120
+ /** Type predicate that narrows a `S | boolean` schema definition to `S` — true when `schemaDef` is
121
+ * a schema object rather than a JSON Schema boolean shorthand (`true` meaning allow-all, `false`
122
+ * meaning deny-all).
123
+ *
124
+ * @param schemaDef - The schema definition to check
125
+ * @returns - True if `schemaDef` is a schema object
126
+ */
127
+ function isSchemaObj(schemaDef) {
128
+ return isObject(schemaDef);
129
+ }
130
+ /** Copies schema-defined properties from `source` into `target`, applying `omit` recursively for
131
+ * each value. Handles `properties`, `patternProperties`, `additionalProperties`, and `propertyNames`.
132
+ * Optional object-valued properties are pruned when every key in the filtered result is both
133
+ * optional (per the inner schema's `required`) and empty (per `isValueEmpty`). This preserves
134
+ * optional objects whose required children have empty values, while still dropping objects whose
135
+ * schema-filtered content is entirely optional-and-empty. Required properties and scalar values
136
+ * are always written when defined. Always returns `target` — pruning of the object itself is
137
+ * the caller's responsibility.
138
+ *
139
+ * @param schema - The object schema describing which properties are allowed
140
+ * @param source - The source form data object to read values from
141
+ * @param target - The accumulator object to write filtered values into
142
+ * @returns - `target` after all schema-defined properties have been processed
143
+ */
144
+ function handleObject(schema, source, target) {
145
+ var _a;
146
+ const { properties, additionalProperties, patternProperties, propertyNames } = schema;
147
+ const requiredSet = new Set(((_a = schema.required) !== null && _a !== void 0 ? _a : []));
148
+ /** Recursively omits extra data from `value` via `omit`, then conditionally writes the result to
149
+ * `target[key]`. Optional object-valued properties are dropped when every key in the filtered
150
+ * result is both optional (within the inner schema's `required` list) and has an empty value per
151
+ * `isValueEmpty`. This per-key approach prevents required-but-empty child properties — kept by
152
+ * inner `setProperty` calls — from inadvertently causing the parent optional object to be dropped,
153
+ * while still pruning optional objects whose schema-filtered content is entirely empty. Vacuously
154
+ * true for `{}`, so empty results are always dropped. Scalar and array values are not pruned here.
155
+ *
156
+ * @param key - The property key to write on `target`
157
+ * @param schemaDef - The schema (or boolean shorthand) that governs the value at `key`
158
+ * @param value - The raw source value to filter
159
+ * @param [required=false] - When true the property is never pruned regardless of its filtered value
160
+ */
161
+ function setProperty(key, schemaDef, value, required = false) {
162
+ var _a;
163
+ const v = omit(schemaDef, value, target[key]);
164
+ if (!required && isObject(v)) {
165
+ // Resolve $ref so we can inspect the effective required list for the inner schema.
166
+ let sd = isSchemaObj(schemaDef) ? schemaDef : {};
167
+ if (sd.$ref !== undefined) {
168
+ sd = findSchemaDefinition(sd.$ref, rootSchema);
169
+ }
170
+ const innerRequired = new Set(((_a = sd.required) !== null && _a !== void 0 ? _a : []));
171
+ // Drop this optional object when every key in v is both optional in the inner schema
172
+ // and has an empty value. Vacuously true for {} so empty objects are always dropped.
173
+ const shouldDrop = Object.entries(v).every(([k, val]) => !innerRequired.has(k) && isValueEmpty(val));
174
+ if (shouldDrop) {
175
+ return;
176
+ }
177
+ }
178
+ if (v !== undefined) {
179
+ target[key] = v;
180
+ }
181
+ }
182
+ if (properties !== undefined) {
183
+ for (const [key, schemaDef] of Object.entries(properties)) {
184
+ setProperty(key, schemaDef, source[key], requiredSet.has(key));
185
+ }
186
+ }
187
+ // Track keys not handled by properties/patterns so additionalProperties can pick them up.
188
+ let patternPropertiesRest;
189
+ if (patternProperties !== undefined) {
190
+ patternPropertiesRest = [];
191
+ const patterns = Object.entries(patternProperties).map(([pattern, schemaDef]) => [
192
+ new RegExp(pattern),
193
+ schemaDef,
194
+ ]);
195
+ const knownProperties = new Set(Object.keys(properties !== null && properties !== void 0 ? properties : {}));
196
+ for (const [key, value] of Object.entries(source)) {
197
+ if (knownProperties.has(key)) {
198
+ continue;
199
+ }
200
+ const matched = patterns.find(([re]) => re.test(key));
201
+ if (matched === undefined) {
202
+ patternPropertiesRest.push(key);
203
+ continue;
204
+ }
205
+ setProperty(key, matched[1], value);
206
+ }
207
+ }
208
+ // JSON Schema spec: absent additionalProperties defaults to true (allow all extra keys). Here
209
+ // we treat it as false so omitExtraData never inadvertently passes through undescribed keys.
210
+ if (additionalProperties !== undefined && additionalProperties !== false) {
211
+ const addlSchema = additionalProperties;
212
+ if (patternPropertiesRest !== undefined) {
213
+ for (const key of patternPropertiesRest) {
214
+ setProperty(key, addlSchema, source[key]);
215
+ }
216
+ }
217
+ else {
218
+ const knownProperties = new Set(Object.keys(properties !== null && properties !== void 0 ? properties : {}));
219
+ for (const [key, value] of Object.entries(source)) {
220
+ if (knownProperties.has(key)) {
221
+ continue;
222
+ }
223
+ setProperty(key, addlSchema, value);
224
+ }
225
+ }
226
+ }
227
+ // When propertyNames is present, the schema only constrains key names — all source keys are valid.
228
+ if (propertyNames !== undefined) {
229
+ for (const [key, value] of Object.entries(source)) {
230
+ target[key] = value;
231
+ }
232
+ }
233
+ return target;
234
+ }
235
+ /** Filters array elements from `source` into `target` according to `schema.items` and
236
+ * `schema.additionalItems`. For tuple schemas (`items` is an array) each element is filtered by its
237
+ * per-index schema; elements beyond the tuple length are covered by `additionalItems` when present.
238
+ * For list schemas (`items` is a single schema) every element is filtered by that schema.
239
+ *
240
+ * @param schema - The array schema describing `items` and optionally `additionalItems`
241
+ * @param source - The source array to read elements from
242
+ * @param target - The accumulator array to push filtered elements into
243
+ * @returns - `target` after all applicable source elements have been pushed
244
+ */
245
+ function handleArray(schema, source, target) {
246
+ const { items, additionalItems } = schema;
247
+ if (items !== undefined) {
248
+ if (Array.isArray(items)) {
249
+ for (let i = 0; i < items.length; i++) {
250
+ target.push(omit(items[i], source[i]));
251
+ }
252
+ }
253
+ else {
254
+ for (let i = 0; i < source.length; i++) {
255
+ target.push(omit(items, source[i]));
256
+ }
257
+ }
258
+ }
259
+ // additionalItems covers tuple items beyond the items array length.
260
+ if (additionalItems) {
261
+ for (let i = target.length; i < source.length; i++) {
262
+ target.push(omit(additionalItems, source[i]));
263
+ }
264
+ }
265
+ return target;
266
+ }
267
+ /** Applies the `if/then/else` conditional keywords from `schema` to `target`. When `schema.if` is
268
+ * absent the original `target` is returned unchanged. Otherwise the condition is evaluated — using
269
+ * `validator.isValid` for schema conditions or the boolean value directly — and the matching branch
270
+ * (`then` or `else`) is applied via `omit`. When the selected branch is absent, `target` is returned
271
+ * unchanged.
272
+ *
273
+ * @param schema - The schema potentially containing `if`, `then`, and `else` keywords
274
+ * @param source - The current form data value, passed to `validator.isValid` and the branch `omit`
275
+ * @param target - The already-filtered value to merge the branch result into
276
+ * @returns - The result of applying the matched branch, or `target` when no branch applies
277
+ */
278
+ function handleConditions(schema, source, target) {
279
+ const { if: condition, then, else: otherwise } = schema;
280
+ if (condition === undefined) {
281
+ return target;
282
+ }
283
+ // validator.isValid signature: (schema, formData, rootSchema)
284
+ const isThenBranch = isSchemaObj(condition)
285
+ ? validator.isValid(condition, source, rootSchema)
286
+ : condition;
287
+ const branch = isThenBranch ? then : otherwise;
288
+ return branch === undefined ? target : omit(branch, source, target);
289
+ }
290
+ /** Applies the best-matching `oneOf` option to `source`, merging the result into `target`. When
291
+ * `oneOf` is not an array or the schema represents a select widget (enum-driven), `target` is
292
+ * returned unchanged. `additionalProperties: false` is relaxed on each option before scoring so that
293
+ * `getClosestMatchingOption` can validate freely, but the original option schema is used for the
294
+ * actual `omit` call.
295
+ *
296
+ * @param oneOf - The `oneOf` array from the schema, or `undefined`
297
+ * @param schema - The parent schema containing the `oneOf` keyword
298
+ * @param source - The current form data value used to score each option
299
+ * @param target - The already-filtered value to merge the winning option's result into
300
+ * @returns - The result of applying the best-matching option, or `target` when no matching applies
301
+ */
302
+ function handleOneOf(oneOf, schema, source, target) {
303
+ if (!Array.isArray(oneOf) || isSelect(validator, schema, rootSchema, experimental_customMergeAllOf)) {
304
+ return target;
305
+ }
306
+ // Resolve $refs and relax additionalProperties:false → true in one pass for scoring only.
307
+ // The unrelaxed resolved schema is re-derived for the winning option so that omit() still
308
+ // respects additionalProperties:false during filtering.
309
+ const scoringOptions = relaxOptionsForScoring(oneOf, true, rootSchema);
310
+ const bestIndex = getClosestMatchingOption(validator, rootSchema, source, scoringOptions, 0, getDiscriminatorFieldFromSchema(schema), experimental_customMergeAllOf);
311
+ const winning = oneOf[bestIndex];
312
+ // For object options, re-resolve without relaxation so additionalProperties:false is respected.
313
+ // For boolean options, scoringOptions already holds the converted schema (true→{}, false→{not:{}}).
314
+ const resolved = isObject(winning)
315
+ ? resolveAllReferences(winning, rootSchema, [])
316
+ : scoringOptions[bestIndex];
317
+ return omit(resolved, source, target);
318
+ }
319
+ /** Applies `anyOf` branches from `schema` to `source`, merging results into `target`. When `anyOf`
320
+ * is absent or not an array, `target` is returned unchanged. For undefined or empty sources (so that
321
+ * defaults can flow through all branches) every branch is applied in sequence. For non-empty sources
322
+ * the best-matching branch is selected via `handleOneOf`.
323
+ *
324
+ * @param schema - The schema potentially containing an `anyOf` keyword
325
+ * @param source - The current form data value; empty or undefined triggers all-branch application
326
+ * @param target - The already-filtered value to merge branch results into
327
+ * @returns - The result after applying the relevant `anyOf` branch(es), or `target` when inapplicable
328
+ */
329
+ function handleAnyOf(schema, source, target) {
330
+ const { anyOf } = schema;
331
+ if (!Array.isArray(anyOf)) {
332
+ return target;
333
+ }
334
+ // For undefined or empty collections, apply every branch so defaults flow through.
335
+ if (source === undefined ||
336
+ (Array.isArray(source) && source.length === 0) ||
337
+ (isObject(source) && Object.keys(source).length === 0)) {
338
+ for (const branch of anyOf) {
339
+ target = omit(branch, source, target);
340
+ }
341
+ return target;
342
+ }
343
+ return handleOneOf(anyOf, schema, source, target);
344
+ }
345
+ /** Applies schema-based `dependencies` from `schema` to `source`, merging each active dependency's
346
+ * schema into `target` via `omit`. Property dependencies (plain string arrays) are skipped — only
347
+ * schema dependencies are processed. A dependency is considered active when its trigger key is
348
+ * present on `source`.
349
+ *
350
+ * @param schema - The schema potentially containing a `dependencies` keyword
351
+ * @param source - The current form data value; must be a plain object for dependencies to apply
352
+ * @param target - The already-filtered value to merge dependency results into
353
+ * @returns - The result after applying all active schema dependencies, or `target` when inapplicable
354
+ */
355
+ function handleDependencies(schema, source, target) {
356
+ const { dependencies } = schema;
357
+ if (dependencies === undefined || !isObjectValue(source)) {
358
+ return target;
359
+ }
360
+ for (const [key, deps] of Object.entries(dependencies)) {
361
+ // Skip property dependencies (string arrays); only process schema dependencies.
362
+ if (!(key in source) || Array.isArray(deps)) {
363
+ continue;
364
+ }
365
+ target = omit(deps, source, target);
366
+ }
367
+ return target;
368
+ }
369
+ /** Core recursive filter. Resolves `$ref`s, merges `allOf`, then delegates to the type-specific
370
+ * handlers (`handleObject`, `handleArray`) and keyword handlers (`handleAnyOf`, `handleOneOf`,
371
+ * `handleConditions`, `handleDependencies`). Returns `undefined` when `source` is undefined or
372
+ * `schemaDef` is `false`; returns `source` unchanged when `schemaDef` is `true` or empty.
373
+ *
374
+ * @param schemaDef - The schema (or boolean shorthand) to filter `source` against
375
+ * @param source - The raw form data value to filter
376
+ * @param [target] - An optional accumulator carrying results from prior oneOf/anyOf processing
377
+ * @returns - The filtered value, or `undefined` when the schema rejects the value
378
+ */
379
+ function omit(schemaDef, source, target) {
380
+ if (source === undefined || schemaDef === false) {
381
+ return undefined;
382
+ }
383
+ if (schemaDef === true || isEmpty(schemaDef)) {
384
+ return source;
385
+ }
386
+ let schema = schemaDef;
387
+ const { $ref: ref, allOf } = schema;
388
+ if (ref !== undefined) {
389
+ return omit(findSchemaDefinition(ref, rootSchema), source, target);
390
+ }
391
+ if (allOf) {
392
+ schema = doMergeAllOf(schema, experimental_customMergeAllOf);
393
+ }
394
+ target = handleAnyOf(schema, source, handleOneOf(schema.oneOf, schema, source, target));
395
+ const type = getSchemaType(schema);
396
+ if (type === 'object') {
397
+ if (!isObjectValue(source)) {
398
+ return undefined;
399
+ }
400
+ target = handleObject(schema, source, isObjectValue(target) ? target : {});
401
+ }
402
+ else if (type === 'array') {
403
+ if (!Array.isArray(source)) {
404
+ return undefined;
405
+ }
406
+ target = handleArray(schema, source, Array.isArray(target) ? target : []);
407
+ }
408
+ else if (target === undefined) {
409
+ target = source;
410
+ }
411
+ return handleDependencies(schema, source, handleConditions(schema, source, target));
412
+ }
413
+ return omit(schema, formData);
78
414
  }
79
415
  //# sourceMappingURL=omitExtraData.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"omitExtraData.js","sourceRoot":"","sources":["../../src/schema/omitExtraData.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAEzE,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAU,QAAuB,EAAE,MAAgB;IAChF,sCAAsC;IACtC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACxD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,GAAsB,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACvD,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAiB,CAAC;IAC3E,CAAC;IAED,OAAO,IAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAU,UAAyB,EAAE,QAAY;IAC5E,MAAM,gBAAgB,GAAG,CAAC,KAAQ,EAAE,MAAe,EAAE,EAAE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AAC;QAC7E,CAAC;aAAM,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YAC5B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3B,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC5E,CAAC;aAAM,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,GAAG,MAAM,CAAC;QAClB,CAAC;QAED,OAAO,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACtF,CAAC;IAED,OAAO,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAkB,CAAC;AACjD,CAAC"}
@@ -132,6 +132,21 @@ export declare function retrieveSchemaInternal<T = any, S extends StrictRJSFSche
132
132
  * @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
133
133
  */
134
134
  export declare function resolveAnyOrOneOfSchemas<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, rawFormData?: T): S[];
135
+ /** Normalises a list of `oneOf`/`anyOf` options for use in option-scoring only (not for filtering).
136
+ * Boolean schemas are converted to their object equivalents (`true` → `{}`, `false` → `{not:{}}`).
137
+ * When `resolveRefs` is `true`, each object option is first passed through `resolveAllReferences`
138
+ * so that `$ref`-based options expose their `additionalProperties` constraint before relaxation.
139
+ * Any option whose `additionalProperties` is `false` is widened to `true` so that
140
+ * `getClosestMatchingOption` / `validator.isValid()` does not produce false negatives when the
141
+ * form data contains keys not listed in `properties`.
142
+ *
143
+ * @param options - The raw `oneOf`/`anyOf` array, which may contain boolean schemas
144
+ * @param [resolveRefs=false] - When `true`, resolve `$ref`s in each option before relaxing; pass
145
+ * `rootSchema` as well. Set `false` (default) when refs are already resolved at the call site.
146
+ * @param [rootSchema] - Required when `resolveRefs` is `true`; the root schema used to look up `$ref`s
147
+ * @returns - A new array of plain schema objects with `additionalProperties` relaxed where needed
148
+ */
149
+ export declare function relaxOptionsForScoring<S extends StrictRJSFSchema = RJSFSchema>(options: Array<S | boolean>, resolveRefs?: boolean, rootSchema?: S): S[];
135
150
  /** Resolves dependencies within a schema and its 'anyOf/oneOf' children. Passes the `expandAllBranches` flag down to
136
151
  * the `resolveAnyOrOneOfSchema()` and `processDependencies()` helper calls.
137
152
  *
@@ -1,21 +1,20 @@
1
+ import flattenDeep from 'lodash-es/flattenDeep.js';
1
2
  import get from 'lodash-es/get.js';
3
+ import isEmpty from 'lodash-es/isEmpty.js';
4
+ import merge from 'lodash-es/merge.js';
2
5
  import set from 'lodash-es/set.js';
3
6
  import times from 'lodash-es/times.js';
4
7
  import transform from 'lodash-es/transform.js';
5
- import merge from 'lodash-es/merge.js';
6
- import flattenDeep from 'lodash-es/flattenDeep.js';
7
8
  import uniq from 'lodash-es/uniq.js';
8
- import isEmpty from 'lodash-es/isEmpty.js';
9
- import { createComparator, createMerger, createShallowAllOfMerge } from '@x0k/json-schema-merge';
10
- import { createDeduplicator, createIntersector } from '@x0k/json-schema-merge/lib/array';
11
9
  import { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, DEPENDENCIES_KEY, ID_KEY, IF_KEY, ITEMS_KEY, ONE_OF_KEY, PATTERN_PROPERTIES_KEY, PROPERTIES_KEY, REF_KEY, RJSF_REF_KEY, } from '../constants.js';
10
+ import deepEquals from '../deepEquals.js';
12
11
  import findSchemaDefinition, { splitKeyElementFromObject } from '../findSchemaDefinition.js';
13
12
  import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema.js';
14
13
  import guessType from '../guessType.js';
15
14
  import isObject from '../isObject.js';
16
15
  import mergeSchemas from '../mergeSchemas.js';
17
16
  import getFirstMatchingOption from './getFirstMatchingOption.js';
18
- import deepEquals from '../deepEquals.js';
17
+ import shallowAllOfMerge from './shallowAllOfMerge.js';
19
18
  /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
20
19
  * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
21
20
  * potentially recursive resolution.
@@ -305,13 +304,6 @@ export function stubExistingAdditionalProperties(validator, theSchema, rootSchem
305
304
  });
306
305
  return schema;
307
306
  }
308
- // Set up @x0k/json-schema-merge utilities
309
- const { compareSchemaDefinitions, compareSchemaValues } = createComparator();
310
- const { mergeArrayOfSchemaDefinitions } = createMerger({
311
- intersectJson: createIntersector(compareSchemaValues),
312
- deduplicateJsonSchemaDef: createDeduplicator(compareSchemaDefinitions),
313
- });
314
- const shallowAllOfMerge = createShallowAllOfMerge(mergeArrayOfSchemaDefinitions);
315
307
  /**
316
308
  * Internal helper that merges allOf schemas using @x0k/json-schema-merge's shallow allOf merge
317
309
  * @param schema - The schema containing an `allOf` keyword
@@ -434,12 +426,43 @@ export function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAl
434
426
  // Call this to trigger the set of isValid() calls that the schema parser will need
435
427
  const option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
436
428
  if (expandAllBranches) {
429
+ // Also trigger isValid() for the relaxed variants so that precompiled validators capture their hashes.
430
+ // omitExtraData's handleOneOf relaxes additionalProperties:false → true before scoring; those mutated
431
+ // schemas must be present in a precompiled validator's compiled set or isValid() will throw at runtime.
432
+ // Using getFirstMatchingOption (rather than calling isValid directly) ensures that the augmented forms
433
+ // of each option (as constructed internally by getFirstMatchingOption for options with properties) are
434
+ // also captured. The return value is discarded — the call is purely for ParserValidator's side effect.
435
+ const relaxed = relaxOptionsForScoring(anyOrOneOf, false, rootSchema);
436
+ getFirstMatchingOption(validator, formData, relaxed, rootSchema, discriminator);
437
437
  return anyOrOneOf.map((item) => mergeSchemas(remaining, item));
438
438
  }
439
439
  schema = mergeSchemas(remaining, anyOrOneOf[option]);
440
440
  }
441
441
  return [schema];
442
442
  }
443
+ /** Normalises a list of `oneOf`/`anyOf` options for use in option-scoring only (not for filtering).
444
+ * Boolean schemas are converted to their object equivalents (`true` → `{}`, `false` → `{not:{}}`).
445
+ * When `resolveRefs` is `true`, each object option is first passed through `resolveAllReferences`
446
+ * so that `$ref`-based options expose their `additionalProperties` constraint before relaxation.
447
+ * Any option whose `additionalProperties` is `false` is widened to `true` so that
448
+ * `getClosestMatchingOption` / `validator.isValid()` does not produce false negatives when the
449
+ * form data contains keys not listed in `properties`.
450
+ *
451
+ * @param options - The raw `oneOf`/`anyOf` array, which may contain boolean schemas
452
+ * @param [resolveRefs=false] - When `true`, resolve `$ref`s in each option before relaxing; pass
453
+ * `rootSchema` as well. Set `false` (default) when refs are already resolved at the call site.
454
+ * @param [rootSchema] - Required when `resolveRefs` is `true`; the root schema used to look up `$ref`s
455
+ * @returns - A new array of plain schema objects with `additionalProperties` relaxed where needed
456
+ */
457
+ export function relaxOptionsForScoring(options, resolveRefs = false, rootSchema) {
458
+ return options.map((d) => {
459
+ if (!isObject(d)) {
460
+ return (d ? {} : { not: {} });
461
+ }
462
+ const schema = resolveRefs && rootSchema ? resolveAllReferences(d, rootSchema, []) : d;
463
+ return schema.additionalProperties === false ? { ...schema, additionalProperties: true } : schema;
464
+ });
465
+ }
443
466
  /** Resolves dependencies within a schema and its 'anyOf/oneOf' children. Passes the `expandAllBranches` flag down to
444
467
  * the `resolveAnyOrOneOfSchema()` and `processDependencies()` helper calls.
445
468
  *