@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.
Files changed (289) hide show
  1. package/LICENSE.md +201 -0
  2. package/dist/index.cjs +534 -376
  3. package/dist/index.cjs.map +4 -4
  4. package/dist/utils.esm.js +534 -376
  5. package/dist/utils.esm.js.map +4 -4
  6. package/dist/utils.umd.js +561 -400
  7. package/lib/ErrorSchemaBuilder.d.ts +1 -1
  8. package/lib/SelectedOptionDescription.d.ts +4 -0
  9. package/lib/SelectedOptionDescription.js +24 -0
  10. package/lib/SelectedOptionDescription.js.map +1 -0
  11. package/lib/allowAdditionalItems.d.ts +1 -1
  12. package/lib/allowAdditionalItems.js +1 -0
  13. package/lib/allowAdditionalItems.js.map +1 -1
  14. package/lib/asNumber.js +2 -0
  15. package/lib/asNumber.js.map +1 -1
  16. package/lib/canExpand.d.ts +1 -1
  17. package/lib/constIsAjvDataReference.d.ts +1 -1
  18. package/lib/constants.d.ts +8 -5
  19. package/lib/constants.js +10 -7
  20. package/lib/constants.js.map +1 -1
  21. package/lib/createErrorHandler.d.ts +1 -1
  22. package/lib/createErrorHandler.js +2 -6
  23. package/lib/createErrorHandler.js.map +1 -1
  24. package/lib/createSchemaUtils.d.ts +1 -1
  25. package/lib/createSchemaUtils.js +3 -1
  26. package/lib/createSchemaUtils.js.map +1 -1
  27. package/lib/dataURItoBlob.js +3 -3
  28. package/lib/dataURItoBlob.js.map +1 -1
  29. package/lib/dateRangeOptions.d.ts +1 -1
  30. package/lib/dateRangeOptions.js +8 -7
  31. package/lib/dateRangeOptions.js.map +1 -1
  32. package/lib/englishStringTranslator.d.ts +1 -1
  33. package/lib/enumOptionSelectedValue.d.ts +1 -1
  34. package/lib/enumOptionValueDecoder.d.ts +1 -1
  35. package/lib/enumOptionValueDecoder.js +1 -1
  36. package/lib/enumOptionValueDecoder.js.map +1 -1
  37. package/lib/enumOptionValueEncoder.d.ts +1 -1
  38. package/lib/enumOptionsDeselectValue.d.ts +1 -1
  39. package/lib/enumOptionsIndexForValue.d.ts +1 -1
  40. package/lib/enumOptionsIndexForValue.js.map +1 -1
  41. package/lib/enumOptionsIsSelected.d.ts +1 -1
  42. package/lib/enumOptionsSelectValue.d.ts +1 -1
  43. package/lib/enumOptionsValueForIndex.d.ts +2 -2
  44. package/lib/enumOptionsValueForIndex.js.map +1 -1
  45. package/lib/enums.d.ts +4 -0
  46. package/lib/enums.js +4 -0
  47. package/lib/enums.js.map +1 -1
  48. package/lib/findSchemaDefinition.d.ts +1 -1
  49. package/lib/findSchemaDefinition.js +15 -15
  50. package/lib/findSchemaDefinition.js.map +1 -1
  51. package/lib/getChangedFields.js +4 -6
  52. package/lib/getChangedFields.js.map +1 -1
  53. package/lib/getDateElementProps.d.ts +3 -3
  54. package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
  55. package/lib/getDiscriminatorFieldFromSchema.js +1 -0
  56. package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
  57. package/lib/getInputProps.d.ts +1 -1
  58. package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
  59. package/lib/getOptionMatchingSimpleDiscriminator.js +10 -11
  60. package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
  61. package/lib/getOptionValueFormat.d.ts +1 -1
  62. package/lib/getSchemaType.d.ts +1 -1
  63. package/lib/getSchemaType.js +2 -1
  64. package/lib/getSchemaType.js.map +1 -1
  65. package/lib/getSubmitButtonOptions.d.ts +1 -1
  66. package/lib/getSubmitButtonOptions.js +1 -1
  67. package/lib/getSubmitButtonOptions.js.map +1 -1
  68. package/lib/getTemplate.d.ts +1 -1
  69. package/lib/getTestIds.d.ts +1 -1
  70. package/lib/getUiOptions.d.ts +1 -1
  71. package/lib/getUiOptions.js +2 -1
  72. package/lib/getUiOptions.js.map +1 -1
  73. package/lib/getWidget.d.ts +1 -1
  74. package/lib/getWidget.js +4 -4
  75. package/lib/getWidget.js.map +1 -1
  76. package/lib/guessType.js +1 -1
  77. package/lib/guessType.js.map +1 -1
  78. package/lib/hasWidget.d.ts +1 -1
  79. package/lib/hashForSchema.d.ts +3 -1
  80. package/lib/hashForSchema.js +11 -4
  81. package/lib/hashForSchema.js.map +1 -1
  82. package/lib/idGenerators.d.ts +1 -1
  83. package/lib/index.d.ts +14 -7
  84. package/lib/index.js +5 -2
  85. package/lib/index.js.map +1 -1
  86. package/lib/isConstant.d.ts +1 -1
  87. package/lib/isCustomWidget.d.ts +1 -1
  88. package/lib/isCustomWidget.js +1 -1
  89. package/lib/isCustomWidget.js.map +1 -1
  90. package/lib/isFixedItems.d.ts +3 -3
  91. package/lib/isFixedItems.js +3 -3
  92. package/lib/isFixedItems.js.map +1 -1
  93. package/lib/isRootSchema.d.ts +1 -1
  94. package/lib/isRootSchema.js +2 -3
  95. package/lib/isRootSchema.js.map +1 -1
  96. package/lib/labelValue.d.ts +1 -1
  97. package/lib/logUnsupportedDefaultForEnum.d.ts +9 -0
  98. package/lib/logUnsupportedDefaultForEnum.js +18 -0
  99. package/lib/logUnsupportedDefaultForEnum.js.map +1 -0
  100. package/lib/lookupFromFormContext.d.ts +1 -1
  101. package/lib/mergeDefaultsWithFormData.js +6 -5
  102. package/lib/mergeDefaultsWithFormData.js.map +1 -1
  103. package/lib/mergeObjects.d.ts +4 -2
  104. package/lib/mergeObjects.js +1 -1
  105. package/lib/mergeObjects.js.map +1 -1
  106. package/lib/mergeSchemas.d.ts +4 -2
  107. package/lib/mergeSchemas.js +13 -6
  108. package/lib/mergeSchemas.js.map +1 -1
  109. package/lib/nameGenerators.d.ts +1 -1
  110. package/lib/optionsList.d.ts +1 -1
  111. package/lib/optionsList.js +22 -21
  112. package/lib/optionsList.js.map +1 -1
  113. package/lib/orderProperties.js +3 -3
  114. package/lib/orderProperties.js.map +1 -1
  115. package/lib/pad.js +1 -1
  116. package/lib/pad.js.map +1 -1
  117. package/lib/parseDateString.d.ts +1 -1
  118. package/lib/parseDateString.js +1 -1
  119. package/lib/parseDateString.js.map +1 -1
  120. package/lib/parser/ParserValidator.d.ts +2 -4
  121. package/lib/parser/ParserValidator.js +2 -0
  122. package/lib/parser/ParserValidator.js.map +1 -1
  123. package/lib/parser/index.d.ts +1 -1
  124. package/lib/parser/schemaParser.d.ts +2 -2
  125. package/lib/parser/schemaParser.js +7 -7
  126. package/lib/parser/schemaParser.js.map +1 -1
  127. package/lib/rangeSpec.d.ts +1 -2
  128. package/lib/rangeSpec.js.map +1 -1
  129. package/lib/removeOptionalEmptyObjects.d.ts +1 -1
  130. package/lib/removeOptionalEmptyObjects.js +6 -8
  131. package/lib/removeOptionalEmptyObjects.js.map +1 -1
  132. package/lib/resolveUiSchema.d.ts +1 -1
  133. package/lib/resolveUiSchema.js +16 -16
  134. package/lib/resolveUiSchema.js.map +1 -1
  135. package/lib/schema/findFieldInSchema.d.ts +1 -1
  136. package/lib/schema/findSelectedOptionInXxxOf.d.ts +1 -1
  137. package/lib/schema/findSelectedOptionInXxxOf.js +1 -3
  138. package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
  139. package/lib/schema/getClosestMatchingOption.d.ts +1 -1
  140. package/lib/schema/getClosestMatchingOption.js +6 -9
  141. package/lib/schema/getClosestMatchingOption.js.map +1 -1
  142. package/lib/schema/getDefaultFormState.d.ts +4 -4
  143. package/lib/schema/getDefaultFormState.js +81 -43
  144. package/lib/schema/getDefaultFormState.js.map +1 -1
  145. package/lib/schema/getDisplayLabel.d.ts +1 -1
  146. package/lib/schema/getDisplayLabel.js +2 -3
  147. package/lib/schema/getDisplayLabel.js.map +1 -1
  148. package/lib/schema/getFirstMatchingOption.d.ts +1 -1
  149. package/lib/schema/getFirstMatchingOption.js +2 -2
  150. package/lib/schema/getFirstMatchingOption.js.map +1 -1
  151. package/lib/schema/getFromSchema.d.ts +1 -1
  152. package/lib/schema/index.js +9 -3
  153. package/lib/schema/index.js.map +1 -1
  154. package/lib/schema/isFilesArray.d.ts +1 -1
  155. package/lib/schema/isMultiSelect.d.ts +1 -1
  156. package/lib/schema/isMultiSelect.js.map +1 -1
  157. package/lib/schema/isSelect.d.ts +1 -1
  158. package/lib/schema/isSelect.js +1 -1
  159. package/lib/schema/isSelect.js.map +1 -1
  160. package/lib/schema/omitExtraData.d.ts +1 -1
  161. package/lib/schema/omitExtraData.js +66 -52
  162. package/lib/schema/omitExtraData.js.map +1 -1
  163. package/lib/schema/retrieveSchema.d.ts +7 -3
  164. package/lib/schema/retrieveSchema.js +83 -56
  165. package/lib/schema/retrieveSchema.js.map +1 -1
  166. package/lib/schema/sanitizeDataForNewSchema.d.ts +1 -1
  167. package/lib/schema/sanitizeDataForNewSchema.js +48 -7
  168. package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
  169. package/lib/schema/toPathSchema.d.ts +1 -1
  170. package/lib/schema/toPathSchema.js +9 -5
  171. package/lib/schema/toPathSchema.js.map +1 -1
  172. package/lib/schemaRequiresTrueValue.d.ts +1 -1
  173. package/lib/schemaRequiresTrueValue.js +4 -3
  174. package/lib/schemaRequiresTrueValue.js.map +1 -1
  175. package/lib/shallowEquals.js +2 -2
  176. package/lib/shallowEquals.js.map +1 -1
  177. package/lib/shouldRenderOptionalField.d.ts +1 -1
  178. package/lib/toConstant.d.ts +1 -1
  179. package/lib/toDateString.d.ts +1 -1
  180. package/lib/toErrorList.d.ts +1 -1
  181. package/lib/toErrorList.js +3 -3
  182. package/lib/toErrorList.js.map +1 -1
  183. package/lib/toErrorSchema.d.ts +1 -1
  184. package/lib/toFieldPathId.d.ts +1 -1
  185. package/lib/tsconfig.tsbuildinfo +1 -1
  186. package/lib/types.d.ts +63 -57
  187. package/lib/unwrapErrorHandler.d.ts +1 -1
  188. package/lib/unwrapErrorHandler.js +7 -9
  189. package/lib/unwrapErrorHandler.js.map +1 -1
  190. package/lib/useAltDateWidgetProps.d.ts +6 -6
  191. package/lib/useAltDateWidgetProps.js +3 -3
  192. package/lib/useAltDateWidgetProps.js.map +1 -1
  193. package/lib/useFileWidgetProps.d.ts +2 -2
  194. package/lib/useFileWidgetProps.js +3 -3
  195. package/lib/useFileWidgetProps.js.map +1 -1
  196. package/lib/validationDataMerge.d.ts +1 -1
  197. package/lib/withIdRefPrefix.d.ts +1 -1
  198. package/lib/withIdRefPrefix.js +12 -12
  199. package/lib/withIdRefPrefix.js.map +1 -1
  200. package/package.json +19 -19
  201. package/src/ErrorSchemaBuilder.ts +1 -1
  202. package/src/SelectedOptionDescription.tsx +48 -0
  203. package/src/allowAdditionalItems.ts +2 -1
  204. package/src/asNumber.ts +2 -0
  205. package/src/canExpand.ts +1 -1
  206. package/src/constIsAjvDataReference.ts +2 -2
  207. package/src/constants.ts +10 -7
  208. package/src/createErrorHandler.ts +6 -7
  209. package/src/createSchemaUtils.ts +4 -2
  210. package/src/dataURItoBlob.ts +3 -3
  211. package/src/dateRangeOptions.ts +9 -7
  212. package/src/englishStringTranslator.ts +1 -1
  213. package/src/enumOptionSelectedValue.ts +1 -1
  214. package/src/enumOptionValueDecoder.ts +2 -2
  215. package/src/enumOptionValueEncoder.ts +1 -1
  216. package/src/enumOptionsDeselectValue.ts +1 -1
  217. package/src/enumOptionsIndexForValue.ts +2 -2
  218. package/src/enumOptionsIsSelected.ts +1 -1
  219. package/src/enumOptionsSelectValue.ts +1 -1
  220. package/src/enumOptionsValueForIndex.ts +2 -2
  221. package/src/enums.ts +4 -0
  222. package/src/findSchemaDefinition.ts +18 -17
  223. package/src/getChangedFields.ts +5 -5
  224. package/src/getDateElementProps.ts +3 -3
  225. package/src/getDiscriminatorFieldFromSchema.ts +2 -1
  226. package/src/getInputProps.ts +1 -1
  227. package/src/getOptionMatchingSimpleDiscriminator.ts +11 -15
  228. package/src/getOptionValueFormat.ts +1 -1
  229. package/src/getSchemaType.ts +3 -2
  230. package/src/getSubmitButtonOptions.ts +3 -3
  231. package/src/getTemplate.ts +1 -1
  232. package/src/getTestIds.ts +1 -1
  233. package/src/getUiOptions.ts +10 -2
  234. package/src/getWidget.tsx +5 -6
  235. package/src/guessType.ts +1 -1
  236. package/src/hasWidget.ts +1 -1
  237. package/src/hashForSchema.ts +12 -5
  238. package/src/idGenerators.ts +1 -1
  239. package/src/index.ts +16 -5
  240. package/src/isConstant.ts +1 -1
  241. package/src/isCustomWidget.ts +2 -2
  242. package/src/isFixedItems.ts +4 -4
  243. package/src/isRootSchema.ts +3 -5
  244. package/src/labelValue.ts +1 -1
  245. package/src/logUnsupportedDefaultForEnum.ts +28 -0
  246. package/src/lookupFromFormContext.ts +1 -1
  247. package/src/mergeDefaultsWithFormData.ts +8 -7
  248. package/src/mergeObjects.ts +2 -2
  249. package/src/mergeSchemas.ts +14 -7
  250. package/src/nameGenerators.ts +1 -1
  251. package/src/optionsList.ts +21 -23
  252. package/src/orderProperties.ts +4 -4
  253. package/src/pad.ts +1 -1
  254. package/src/parseDateString.ts +2 -2
  255. package/src/parser/ParserValidator.ts +4 -4
  256. package/src/parser/index.ts +1 -1
  257. package/src/parser/schemaParser.ts +10 -9
  258. package/src/rangeSpec.ts +1 -2
  259. package/src/removeOptionalEmptyObjects.ts +8 -11
  260. package/src/resolveUiSchema.ts +32 -25
  261. package/src/schema/findFieldInSchema.ts +1 -1
  262. package/src/schema/findSelectedOptionInXxxOf.ts +17 -7
  263. package/src/schema/getClosestMatchingOption.ts +17 -11
  264. package/src/schema/getDefaultFormState.ts +104 -43
  265. package/src/schema/getDisplayLabel.ts +4 -5
  266. package/src/schema/getFirstMatchingOption.ts +3 -3
  267. package/src/schema/getFromSchema.ts +1 -1
  268. package/src/schema/index.ts +3 -0
  269. package/src/schema/isFilesArray.ts +1 -1
  270. package/src/schema/isMultiSelect.ts +7 -1
  271. package/src/schema/isSelect.ts +8 -2
  272. package/src/schema/omitExtraData.ts +73 -60
  273. package/src/schema/retrieveSchema.ts +131 -83
  274. package/src/schema/sanitizeDataForNewSchema.ts +57 -8
  275. package/src/schema/toPathSchema.ts +11 -7
  276. package/src/schemaRequiresTrueValue.ts +4 -4
  277. package/src/shallowEquals.ts +2 -2
  278. package/src/shouldRenderOptionalField.ts +1 -1
  279. package/src/toConstant.ts +1 -1
  280. package/src/toDateString.ts +1 -1
  281. package/src/toErrorList.ts +4 -4
  282. package/src/toErrorSchema.ts +1 -1
  283. package/src/toFieldPathId.ts +1 -1
  284. package/src/types.ts +92 -63
  285. package/src/unwrapErrorHandler.ts +11 -12
  286. package/src/useAltDateWidgetProps.tsx +10 -8
  287. package/src/useFileWidgetProps.ts +7 -7
  288. package/src/validationDataMerge.ts +1 -1
  289. package/src/withIdRefPrefix.ts +12 -12
@@ -1,4 +1,4 @@
1
- import { DateObject } from './types';
1
+ import type { DateObject } from './types';
2
2
 
3
3
  /** Parses the `dateString` into a `DateObject`, including the time information when `includeTime` is true
4
4
  *
@@ -20,7 +20,7 @@ export default function parseDateString(dateString?: string, includeTime = true)
20
20
  }
21
21
  const date = new Date(dateString);
22
22
  if (Number.isNaN(date.getTime())) {
23
- throw new Error('Unable to parse date ' + dateString);
23
+ throw new Error(`Unable to parse date ${dateString}`);
24
24
  }
25
25
  return {
26
26
  year: date.getUTCFullYear(),
@@ -3,7 +3,7 @@ import get from 'lodash/get';
3
3
  import { ID_KEY } from '../constants';
4
4
  import deepEquals from '../deepEquals';
5
5
  import hashForSchema from '../hashForSchema';
6
- import {
6
+ import type {
7
7
  CustomValidator,
8
8
  ErrorSchema,
9
9
  ErrorTransformer,
@@ -18,9 +18,7 @@ import {
18
18
 
19
19
  /** The type of the map of schema hash to schema
20
20
  */
21
- export type SchemaMap<S extends StrictRJSFSchema = RJSFSchema> = {
22
- [hash: string]: S;
23
- };
21
+ export type SchemaMap<S extends StrictRJSFSchema = RJSFSchema> = Record<string, S>;
24
22
 
25
23
  /** An implementation of the `ValidatorType` interface that is designed for use in capturing schemas used by the
26
24
  * `isValid()` function. The rest of the implementation of the interface throws errors when it is attempted to be used.
@@ -70,7 +68,9 @@ export default class ParserValidator<
70
68
  if (!existing) {
71
69
  this.schemaMap[key] = identifiedSchema;
72
70
  } else if (!deepEquals(existing, identifiedSchema)) {
71
+ // oxlint-disable-next-line no-console
73
72
  console.error('existing schema:', JSON.stringify(existing, null, 2));
73
+ // oxlint-disable-next-line no-console
74
74
  console.error('new schema:', JSON.stringify(identifiedSchema, null, 2));
75
75
  throw new Error(
76
76
  `Two different schemas exist with the same key ${key}! What a bad coincidence. If possible, try adding an $id to one of the schemas`,
@@ -1,4 +1,4 @@
1
- import { SchemaMap } from './ParserValidator';
1
+ import type { SchemaMap } from './ParserValidator';
2
2
  import schemaParser from './schemaParser';
3
3
 
4
4
  export type { SchemaMap };
@@ -3,8 +3,9 @@ import forEach from 'lodash/forEach';
3
3
  import { ITEMS_KEY, PROPERTIES_KEY } from '../constants';
4
4
  import deepEquals from '../deepEquals';
5
5
  import { resolveAnyOrOneOfSchemas, retrieveSchemaInternal } from '../schema/retrieveSchema';
6
- import { FormContextType, RJSFSchema, StrictRJSFSchema } from '../types';
7
- import ParserValidator, { SchemaMap } from './ParserValidator';
6
+ import type { FormContextType, RJSFSchema, StrictRJSFSchema } from '../types';
7
+ import type { SchemaMap } from './ParserValidator';
8
+ import ParserValidator from './ParserValidator';
8
9
 
9
10
  /** Recursive function used to parse the given `schema` belonging to the `rootSchema`. The `validator` is used to
10
11
  * capture the sub-schemas that the `isValid()` function is called with. For each schema returned by the
@@ -23,20 +24,20 @@ function parseSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
23
24
  schema: S,
24
25
  ) {
25
26
  const schemas = retrieveSchemaInternal<T, S, F>(validator, schema, rootSchema, undefined, true);
26
- schemas.forEach((schema) => {
27
- const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, schema));
27
+ schemas.forEach((localSchema) => {
28
+ const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, localSchema));
28
29
  if (sameSchemaIndex === -1) {
29
- recurseList.push(schema);
30
- const allOptions = resolveAnyOrOneOfSchemas<T, S, F>(validator, schema, rootSchema, true);
30
+ recurseList.push(localSchema);
31
+ const allOptions = resolveAnyOrOneOfSchemas<T, S, F>(validator, localSchema, rootSchema, true);
31
32
  allOptions.forEach((s) => {
32
33
  if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
33
- forEach(schema[PROPERTIES_KEY], (value) => {
34
+ forEach(localSchema[PROPERTIES_KEY], (value) => {
34
35
  parseSchema<T, S, F>(validator, recurseList, rootSchema, value as S);
35
36
  });
36
37
  }
37
38
  });
38
- if (ITEMS_KEY in schema && !Array.isArray(schema.items) && typeof schema.items !== 'boolean') {
39
- parseSchema<T, S, F>(validator, recurseList, rootSchema, schema.items as S);
39
+ if (ITEMS_KEY in localSchema && !Array.isArray(localSchema.items) && typeof localSchema.items !== 'boolean') {
40
+ parseSchema<T, S, F>(validator, recurseList, rootSchema, localSchema.items as S);
40
41
  }
41
42
  }
42
43
  });
package/src/rangeSpec.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { RangeSpecType, StrictRJSFSchema } from './types';
2
- import { RJSFSchema } from './types';
1
+ import type { RangeSpecType, RJSFSchema, StrictRJSFSchema } from './types';
3
2
 
4
3
  /** Extracts the range spec information `{ step?: number, min?: number, max?: number }` that can be spread onto an HTML
5
4
  * input from the range analog in the schema `{ multipleOf?: number, minimum?: number, maximum?: number }`.
@@ -1,6 +1,6 @@
1
1
  import isObject from './isObject';
2
2
  import { isValueEmpty, retrieveSchema } from './schema';
3
- import { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, ValidatorType } from './types';
3
+ import type { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, ValidatorType } from './types';
4
4
 
5
5
  /** Recursively removes optional objects from the `formData` that are empty (i.e., all their fields
6
6
  * are undefined, null, empty strings, or themselves empty optional objects). This solves the problem
@@ -19,7 +19,7 @@ import { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, Valid
19
19
  * @deprecated - This function will be removed in a future release. The equivalent pruning behavior
20
20
  * is now built into `omitExtraData` — use that instead.
21
21
  */
22
- // eslint-disable-next-line @typescript-eslint/no-deprecated
22
+ // oxlint-disable-next-line @typescript-eslint/no-deprecated
23
23
  export default function removeOptionalEmptyObjects<
24
24
  T = any,
25
25
  S extends StrictRJSFSchema = RJSFSchema,
@@ -43,7 +43,7 @@ export default function removeOptionalEmptyObjects<
43
43
  if (Array.isArray(itemsSchema)) {
44
44
  itemSchema = itemsSchema[index] || (resolvedSchema.additionalItems as S) || ({} as S);
45
45
  }
46
- // eslint-disable-next-line @typescript-eslint/no-deprecated
46
+ // oxlint-disable-next-line @typescript-eslint/no-deprecated
47
47
  const cleaned = removeOptionalEmptyObjects<T, S, F>(validator, itemSchema, rootSchema, item);
48
48
  if (cleaned !== item) {
49
49
  hasChanges = true;
@@ -69,23 +69,20 @@ export default function removeOptionalEmptyObjects<
69
69
  for (const key of Object.keys(data)) {
70
70
  const value = data[key];
71
71
  const propertySchema = (properties[key] || {}) as S;
72
- const isRequired = (requiredFields as string[]).includes(key);
72
+ const isRequired = requiredFields.includes(key);
73
73
 
74
74
  const isObj = isObject(value);
75
75
  const isArr = Array.isArray(value);
76
76
 
77
77
  if ((isObj || isArr) && properties[key]) {
78
78
  // Recursively process nested objects and arrays
79
- // eslint-disable-next-line @typescript-eslint/no-deprecated
79
+ // oxlint-disable-next-line @typescript-eslint/no-deprecated
80
80
  const cleaned = removeOptionalEmptyObjects<T, S, F>(validator, propertySchema, rootSchema, value as T);
81
81
 
82
- if (!isRequired && isValueEmpty(cleaned)) {
83
- // This is an optional property and the cleaned result is empty — omit it
84
- continue;
82
+ if (isRequired || !isValueEmpty(cleaned)) {
83
+ result[key] = cleaned;
84
+ hasAnyValue = true;
85
85
  }
86
-
87
- result[key] = cleaned;
88
- hasAnyValue = true;
89
86
  } else if (isRequired || !isValueEmpty(value) || !properties[key]) {
90
87
  // Keep: required, non-empty, or not schema-defined; skip optional empty scalars silently
91
88
  result[key] = value;
@@ -3,7 +3,15 @@ import isEmpty from 'lodash/isEmpty';
3
3
  import { ANY_OF_KEY, ONE_OF_KEY, REF_KEY, RJSF_REF_KEY } from './constants';
4
4
  import findSchemaDefinition from './findSchemaDefinition';
5
5
  import mergeObjects from './mergeObjects';
6
- import { FormContextType, GenericObjectType, Registry, RJSFSchema, StrictRJSFSchema, UiSchema } from './types';
6
+ import type {
7
+ FormContextType,
8
+ GenericObjectType,
9
+ Registry,
10
+ RJSFMarkedSchema,
11
+ RJSFSchema,
12
+ StrictRJSFSchema,
13
+ UiSchema,
14
+ } from './types';
7
15
 
8
16
  /** Resolves the uiSchema for a given schema, considering `ui:definitions` stored in the registry.
9
17
  *
@@ -26,7 +34,7 @@ export default function resolveUiSchema<
26
34
  S extends StrictRJSFSchema = RJSFSchema,
27
35
  F extends FormContextType = any,
28
36
  >(schema: S, localUiSchema: UiSchema<T, S, F> | undefined, registry: Registry<T, S, F>): UiSchema<T, S, F> {
29
- const ref = ((schema as GenericObjectType)[RJSF_REF_KEY] ?? schema[REF_KEY]) as string | undefined;
37
+ const ref = ((schema as RJSFMarkedSchema)[RJSF_REF_KEY] ?? schema[REF_KEY]) as string | undefined;
30
38
  const definitions = registry.uiSchemaDefinitions;
31
39
  const definitionUiSchema = ref && definitions ? definitions[ref] : undefined;
32
40
 
@@ -47,10 +55,11 @@ export default function resolveUiSchema<
47
55
  // can read dropdown option titles at the parent level.
48
56
  if (definitions) {
49
57
  let resolvedSchema: S = schema;
50
- if (ref && schema[REF_KEY] && !(schema as GenericObjectType)[RJSF_REF_KEY]) {
58
+ if (ref && schema[REF_KEY] && !(schema as RJSFMarkedSchema)[RJSF_REF_KEY]) {
51
59
  try {
52
- resolvedSchema = findSchemaDefinition<S>(ref, registry.rootSchema as S);
60
+ resolvedSchema = findSchemaDefinition<S>(ref, registry.rootSchema);
53
61
  } catch (e) {
62
+ // oxlint-disable-next-line no-console
54
63
  console.warn('could not resolve $ref in resolveUiSchema:\n', e);
55
64
  return result;
56
65
  }
@@ -58,30 +67,28 @@ export default function resolveUiSchema<
58
67
 
59
68
  for (const keyword of [ONE_OF_KEY, ANY_OF_KEY] as const) {
60
69
  const schemaOptions = resolvedSchema[keyword];
61
- if (!Array.isArray(schemaOptions) || schemaOptions.length === 0) {
62
- continue;
63
- }
64
-
65
- const currentUiSchemaArray = (result as GenericObjectType)[keyword];
66
- const uiSchemaArray: UiSchema<T, S, F>[] = Array.isArray(currentUiSchemaArray) ? [...currentUiSchemaArray] : [];
70
+ if (Array.isArray(schemaOptions) && schemaOptions.length > 0) {
71
+ const currentUiSchemaArray = (result as GenericObjectType)[keyword];
72
+ const uiSchemaArray: UiSchema<T, S, F>[] = Array.isArray(currentUiSchemaArray) ? [...currentUiSchemaArray] : [];
67
73
 
68
- let hasExpanded = false;
69
- for (let i = 0; i < schemaOptions.length; i++) {
70
- const option = schemaOptions[i] as GenericObjectType | undefined;
71
- const optionRef = (option?.[RJSF_REF_KEY] ?? option?.[REF_KEY]) as string | undefined;
72
- if (optionRef && optionRef in definitions) {
73
- const optionUiSchema = (uiSchemaArray[i] || {}) as GenericObjectType;
74
- uiSchemaArray[i] = mergeObjects(definitions[optionRef] as GenericObjectType, optionUiSchema) as UiSchema<
75
- T,
76
- S,
77
- F
78
- >;
79
- hasExpanded = true;
74
+ let hasExpanded = false;
75
+ for (let i = 0; i < schemaOptions.length; i++) {
76
+ const option = schemaOptions[i] as GenericObjectType | undefined;
77
+ const optionRef = ((option as RJSFMarkedSchema)?.[RJSF_REF_KEY] ?? option?.[REF_KEY]) as string | undefined;
78
+ if (optionRef && optionRef in definitions) {
79
+ const optionUiSchema = (uiSchemaArray[i] || {}) as GenericObjectType;
80
+ uiSchemaArray[i] = mergeObjects(definitions[optionRef] as GenericObjectType, optionUiSchema) as UiSchema<
81
+ T,
82
+ S,
83
+ F
84
+ >;
85
+ hasExpanded = true;
86
+ }
80
87
  }
81
- }
82
88
 
83
- if (hasExpanded) {
84
- (result as GenericObjectType)[keyword] = uiSchemaArray;
89
+ if (hasExpanded) {
90
+ (result as GenericObjectType)[keyword] = uiSchemaArray;
91
+ }
85
92
  }
86
93
  }
87
94
  }
@@ -2,7 +2,7 @@ import get from 'lodash/get';
2
2
  import has from 'lodash/has';
3
3
 
4
4
  import { ANY_OF_KEY, ONE_OF_KEY, PROPERTIES_KEY, REQUIRED_KEY } from '../constants';
5
- import {
5
+ import type {
6
6
  Experimental_CustomMergeAllOf,
7
7
  FormContextType,
8
8
  FoundFieldType,
@@ -3,7 +3,13 @@ import get from 'lodash/get';
3
3
  import { CONST_KEY, DEFAULT_KEY, PROPERTIES_KEY } from '../constants';
4
4
  import deepEquals from '../deepEquals';
5
5
  import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
6
- import { Experimental_CustomMergeAllOf, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
6
+ import type {
7
+ Experimental_CustomMergeAllOf,
8
+ FormContextType,
9
+ RJSFSchema,
10
+ StrictRJSFSchema,
11
+ ValidatorType,
12
+ } from '../types';
7
13
  import retrieveSchema from './retrieveSchema';
8
14
 
9
15
  /** Finds the option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` or
@@ -36,17 +42,21 @@ export default function findSelectedOptionInXxxOf<
36
42
  if (Array.isArray(schema[xxx])) {
37
43
  const discriminator = getDiscriminatorFieldFromSchema<S>(schema);
38
44
  const selectorField = discriminator || fallbackField;
39
- const xxxOfs = schema[xxx]!.map((xxxOf) =>
45
+ const xxxOfs = schema[xxx].map((xxxOf) =>
40
46
  retrieveSchema<T, S, F>(validator, xxxOf as S, rootSchema, formData, experimental_customMergeAllOf),
41
47
  );
42
48
  const data = get(formData, selectorField);
43
49
  if (data !== undefined) {
44
- return xxxOfs.find((xxx) => {
45
- return deepEquals(
46
- get(xxx, [PROPERTIES_KEY, selectorField, DEFAULT_KEY], get(xxx, [PROPERTIES_KEY, selectorField, CONST_KEY])),
50
+ return xxxOfs.find((xxxOfOption) =>
51
+ deepEquals(
52
+ get(
53
+ xxxOfOption,
54
+ [PROPERTIES_KEY, selectorField, DEFAULT_KEY],
55
+ get(xxxOfOption, [PROPERTIES_KEY, selectorField, CONST_KEY]),
56
+ ),
47
57
  data,
48
- );
49
- });
58
+ ),
59
+ );
50
60
  }
51
61
  }
52
62
  return undefined;
@@ -10,7 +10,13 @@ import { ONE_OF_KEY, REF_KEY, JUNK_OPTION_ID, ANY_OF_KEY } from '../constants';
10
10
  import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
11
11
  import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator';
12
12
  import guessType from '../guessType';
13
- import { Experimental_CustomMergeAllOf, FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
13
+ import type {
14
+ Experimental_CustomMergeAllOf,
15
+ FormContextType,
16
+ RJSFSchema,
17
+ StrictRJSFSchema,
18
+ ValidatorType,
19
+ } from '../types';
14
20
  import getFirstMatchingOption from './getFirstMatchingOption';
15
21
  import retrieveSchema, { resolveAllReferences } from './retrieveSchema';
16
22
 
@@ -85,7 +91,7 @@ export function calculateIndexScore<T = any, S extends StrictRJSFSchema = RJSFSc
85
91
  );
86
92
  }
87
93
  if ((has(value, ONE_OF_KEY) || has(value, ANY_OF_KEY)) && formValue) {
88
- const key = has(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
94
+ const xxxOfKey = has(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
89
95
  const discriminator = getDiscriminatorFieldFromSchema<S>(value as S);
90
96
  return (
91
97
  score +
@@ -93,7 +99,7 @@ export function calculateIndexScore<T = any, S extends StrictRJSFSchema = RJSFSc
93
99
  validator,
94
100
  rootSchema,
95
101
  formValue,
96
- get(value, key) as S[],
102
+ get(value, xxxOfKey) as S[],
97
103
  -1,
98
104
  discriminator,
99
105
  experimental_customMergeAllOf,
@@ -101,12 +107,11 @@ export function calculateIndexScore<T = any, S extends StrictRJSFSchema = RJSFSc
101
107
  );
102
108
  }
103
109
  if (value.type === 'object') {
104
- if (isObject(formValue)) {
105
- // If the structure is matching then give it a little boost in score
106
- score += 1;
107
- }
110
+ // If the structure is matching then give it a little boost in score
111
+ const structureBoost = isObject(formValue) ? 1 : 0;
108
112
  return (
109
113
  score +
114
+ structureBoost +
110
115
  calculateIndexScore<T, S, F>(validator, rootSchema, value as S, formValue, experimental_customMergeAllOf)
111
116
  );
112
117
  }
@@ -173,9 +178,7 @@ export default function getClosestMatchingOption<
173
178
  experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
174
179
  ): number {
175
180
  // First resolve any refs in the options
176
- const resolvedOptions = options.map((option) => {
177
- return resolveAllReferences<S>(option, rootSchema, []);
178
- });
181
+ const resolvedOptions = options.map((option) => resolveAllReferences<S>(option, rootSchema, []));
179
182
 
180
183
  const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
181
184
  if (isNumber(simpleDiscriminatorMatch)) {
@@ -201,7 +204,10 @@ export default function getClosestMatchingOption<
201
204
  // No indexes were valid, so we'll score all the options, add all the indexes
202
205
  times(resolvedOptions.length, (i) => allValidIndexes.push(i));
203
206
  }
204
- type BestType = { bestIndex: number; bestScore: number };
207
+ interface BestType {
208
+ bestIndex: number;
209
+ bestScore: number;
210
+ }
205
211
  const scoreCount = new Set<number>();
206
212
  // Score all the options in the list of valid indexes and return the index with the best score
207
213
  const { bestIndex }: BestType = allValidIndexes.reduce(