@rjsf/utils 6.7.1 → 6.10.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 (477) hide show
  1. package/dist/index.cjs +521 -425
  2. package/dist/index.cjs.map +4 -4
  3. package/dist/utils.esm.js +520 -424
  4. package/dist/utils.esm.js.map +4 -4
  5. package/dist/utils.umd.js +579 -333
  6. package/lib/ErrorSchemaBuilder.d.ts +8 -7
  7. package/lib/ErrorSchemaBuilder.d.ts.map +1 -0
  8. package/lib/ErrorSchemaBuilder.js +29 -27
  9. package/lib/ErrorSchemaBuilder.js.map +1 -1
  10. package/lib/SelectedOptionDescription.d.ts +2 -1
  11. package/lib/SelectedOptionDescription.d.ts.map +1 -0
  12. package/lib/SelectedOptionDescription.js +6 -7
  13. package/lib/SelectedOptionDescription.js.map +1 -1
  14. package/lib/allowAdditionalItems.d.ts +2 -1
  15. package/lib/allowAdditionalItems.d.ts.map +1 -0
  16. package/lib/allowAdditionalItems.js +1 -1
  17. package/lib/allowAdditionalItems.js.map +1 -1
  18. package/lib/asNumber.d.ts +1 -0
  19. package/lib/asNumber.d.ts.map +1 -0
  20. package/lib/asNumber.js +1 -1
  21. package/lib/asNumber.js.map +1 -1
  22. package/lib/canExpand.d.ts +2 -1
  23. package/lib/canExpand.d.ts.map +1 -0
  24. package/lib/canExpand.js +1 -1
  25. package/lib/canExpand.js.map +1 -1
  26. package/lib/constIsAjvDataReference.d.ts +2 -1
  27. package/lib/constIsAjvDataReference.d.ts.map +1 -0
  28. package/lib/constIsAjvDataReference.js +2 -3
  29. package/lib/constIsAjvDataReference.js.map +1 -1
  30. package/lib/constants.d.ts +1 -0
  31. package/lib/constants.d.ts.map +1 -0
  32. package/lib/createErrorHandler.d.ts +2 -1
  33. package/lib/createErrorHandler.d.ts.map +1 -0
  34. package/lib/createErrorHandler.js +3 -4
  35. package/lib/createErrorHandler.js.map +1 -1
  36. package/lib/createSchemaUtils.d.ts +2 -1
  37. package/lib/createSchemaUtils.d.ts.map +1 -0
  38. package/lib/createSchemaUtils.js +10 -7
  39. package/lib/createSchemaUtils.js.map +1 -1
  40. package/lib/dataURItoBlob.d.ts +1 -0
  41. package/lib/dataURItoBlob.d.ts.map +1 -0
  42. package/lib/dataURItoBlob.js +1 -2
  43. package/lib/dataURItoBlob.js.map +1 -1
  44. package/lib/dateRangeOptions.d.ts +2 -1
  45. package/lib/dateRangeOptions.d.ts.map +1 -0
  46. package/lib/dateRangeOptions.js +1 -1
  47. package/lib/dateRangeOptions.js.map +1 -1
  48. package/lib/deepEquals.d.ts +1 -0
  49. package/lib/deepEquals.d.ts.map +1 -0
  50. package/lib/englishStringTranslator.d.ts +2 -1
  51. package/lib/englishStringTranslator.d.ts.map +1 -0
  52. package/lib/englishStringTranslator.js +1 -1
  53. package/lib/englishStringTranslator.js.map +1 -1
  54. package/lib/enumOptionSelectedValue.d.ts +2 -1
  55. package/lib/enumOptionSelectedValue.d.ts.map +1 -0
  56. package/lib/enumOptionSelectedValue.js +1 -1
  57. package/lib/enumOptionSelectedValue.js.map +1 -1
  58. package/lib/enumOptionValueDecoder.d.ts +2 -1
  59. package/lib/enumOptionValueDecoder.d.ts.map +1 -0
  60. package/lib/enumOptionValueDecoder.js +1 -1
  61. package/lib/enumOptionValueDecoder.js.map +1 -1
  62. package/lib/enumOptionValueEncoder.d.ts +2 -1
  63. package/lib/enumOptionValueEncoder.d.ts.map +1 -0
  64. package/lib/enumOptionValueEncoder.js +1 -2
  65. package/lib/enumOptionValueEncoder.js.map +1 -1
  66. package/lib/enumOptionsDeselectValue.d.ts +2 -1
  67. package/lib/enumOptionsDeselectValue.d.ts.map +1 -0
  68. package/lib/enumOptionsDeselectValue.js +2 -2
  69. package/lib/enumOptionsDeselectValue.js.map +1 -1
  70. package/lib/enumOptionsIndexForValue.d.ts +2 -1
  71. package/lib/enumOptionsIndexForValue.d.ts.map +1 -0
  72. package/lib/enumOptionsIndexForValue.js +1 -1
  73. package/lib/enumOptionsIndexForValue.js.map +1 -1
  74. package/lib/enumOptionsIsSelected.d.ts +2 -1
  75. package/lib/enumOptionsIsSelected.d.ts.map +1 -0
  76. package/lib/enumOptionsIsSelected.js +1 -1
  77. package/lib/enumOptionsIsSelected.js.map +1 -1
  78. package/lib/enumOptionsSelectValue.d.ts +2 -1
  79. package/lib/enumOptionsSelectValue.d.ts.map +1 -0
  80. package/lib/enumOptionsSelectValue.js +2 -3
  81. package/lib/enumOptionsSelectValue.js.map +1 -1
  82. package/lib/enumOptionsValueForIndex.d.ts +2 -1
  83. package/lib/enumOptionsValueForIndex.d.ts.map +1 -0
  84. package/lib/enums.d.ts +1 -0
  85. package/lib/enums.d.ts.map +1 -0
  86. package/lib/findSchemaDefinition.d.ts +2 -1
  87. package/lib/findSchemaDefinition.d.ts.map +1 -0
  88. package/lib/findSchemaDefinition.js +7 -11
  89. package/lib/findSchemaDefinition.js.map +1 -1
  90. package/lib/getChangedFields.d.ts +11 -2
  91. package/lib/getChangedFields.d.ts.map +1 -0
  92. package/lib/getChangedFields.js +57 -18
  93. package/lib/getChangedFields.js.map +1 -1
  94. package/lib/getDateElementProps.d.ts +2 -1
  95. package/lib/getDateElementProps.d.ts.map +1 -0
  96. package/lib/getDecimalSeparator.d.ts +1 -0
  97. package/lib/getDecimalSeparator.d.ts.map +1 -0
  98. package/lib/getDecimalSeparator.js +1 -2
  99. package/lib/getDecimalSeparator.js.map +1 -1
  100. package/lib/getDiscriminatorFieldFromSchema.d.ts +2 -1
  101. package/lib/getDiscriminatorFieldFromSchema.d.ts.map +1 -0
  102. package/lib/getDiscriminatorFieldFromSchema.js +4 -5
  103. package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
  104. package/lib/getInputProps.d.ts +2 -1
  105. package/lib/getInputProps.d.ts.map +1 -0
  106. package/lib/getInputProps.js +4 -1
  107. package/lib/getInputProps.js.map +1 -1
  108. package/lib/getOptionMatchingSimpleDiscriminator.d.ts +2 -1
  109. package/lib/getOptionMatchingSimpleDiscriminator.d.ts.map +1 -0
  110. package/lib/getOptionMatchingSimpleDiscriminator.js +6 -6
  111. package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
  112. package/lib/getOptionValueFormat.d.ts +2 -1
  113. package/lib/getOptionValueFormat.d.ts.map +1 -0
  114. package/lib/getOptionValueFormat.js +1 -2
  115. package/lib/getOptionValueFormat.js.map +1 -1
  116. package/lib/getPropertySchema.d.ts +12 -0
  117. package/lib/getPropertySchema.d.ts.map +1 -0
  118. package/lib/getPropertySchema.js +14 -0
  119. package/lib/getPropertySchema.js.map +1 -0
  120. package/lib/getSchemaType.d.ts +2 -1
  121. package/lib/getSchemaType.d.ts.map +1 -0
  122. package/lib/getSchemaType.js +1 -1
  123. package/lib/getSchemaType.js.map +1 -1
  124. package/lib/getSubmitButtonOptions.d.ts +2 -1
  125. package/lib/getSubmitButtonOptions.d.ts.map +1 -0
  126. package/lib/getSubmitButtonOptions.js +3 -3
  127. package/lib/getSubmitButtonOptions.js.map +1 -1
  128. package/lib/getTemplate.d.ts +2 -1
  129. package/lib/getTemplate.d.ts.map +1 -0
  130. package/lib/getTestIds.d.ts +2 -1
  131. package/lib/getTestIds.d.ts.map +1 -0
  132. package/lib/getTestIds.js +6 -5
  133. package/lib/getTestIds.js.map +1 -1
  134. package/lib/getUiOptions.d.ts +2 -1
  135. package/lib/getUiOptions.d.ts.map +1 -0
  136. package/lib/getUiOptions.js +2 -2
  137. package/lib/getUiOptions.js.map +1 -1
  138. package/lib/getWidget.d.ts +2 -1
  139. package/lib/getWidget.d.ts.map +1 -0
  140. package/lib/getWidget.js +6 -7
  141. package/lib/getWidget.js.map +1 -1
  142. package/lib/guessType.d.ts +2 -1
  143. package/lib/guessType.d.ts.map +1 -0
  144. package/lib/hasWidget.d.ts +2 -1
  145. package/lib/hasWidget.d.ts.map +1 -0
  146. package/lib/hasWidget.js +1 -1
  147. package/lib/hasWidget.js.map +1 -1
  148. package/lib/hashForSchema.d.ts +4 -2
  149. package/lib/hashForSchema.d.ts.map +1 -0
  150. package/lib/hashForSchema.js +17 -8
  151. package/lib/hashForSchema.js.map +1 -1
  152. package/lib/idGenerators.d.ts +2 -1
  153. package/lib/idGenerators.d.ts.map +1 -0
  154. package/lib/idGenerators.js +2 -3
  155. package/lib/idGenerators.js.map +1 -1
  156. package/lib/index.d.ts +93 -87
  157. package/lib/index.d.ts.map +1 -0
  158. package/lib/index.js +85 -81
  159. package/lib/index.js.map +1 -1
  160. package/lib/isConstant.d.ts +2 -1
  161. package/lib/isConstant.d.ts.map +1 -0
  162. package/lib/isConstant.js +1 -1
  163. package/lib/isConstant.js.map +1 -1
  164. package/lib/isCustomWidget.d.ts +2 -1
  165. package/lib/isCustomWidget.d.ts.map +1 -0
  166. package/lib/isCustomWidget.js +1 -1
  167. package/lib/isCustomWidget.js.map +1 -1
  168. package/lib/isFixedItems.d.ts +2 -1
  169. package/lib/isFixedItems.d.ts.map +1 -0
  170. package/lib/isFixedItems.js +1 -1
  171. package/lib/isFixedItems.js.map +1 -1
  172. package/lib/isFormDataAvailable.d.ts +1 -0
  173. package/lib/isFormDataAvailable.d.ts.map +1 -0
  174. package/lib/isFormDataAvailable.js +7 -4
  175. package/lib/isFormDataAvailable.js.map +1 -1
  176. package/lib/isObject.d.ts +3 -1
  177. package/lib/isObject.d.ts.map +1 -0
  178. package/lib/isObject.js +8 -2
  179. package/lib/isObject.js.map +1 -1
  180. package/lib/isPlainObject.d.ts +9 -0
  181. package/lib/isPlainObject.d.ts.map +1 -0
  182. package/lib/isPlainObject.js +15 -0
  183. package/lib/isPlainObject.js.map +1 -0
  184. package/lib/isRootSchema.d.ts +2 -1
  185. package/lib/isRootSchema.d.ts.map +1 -0
  186. package/lib/isRootSchema.js +2 -2
  187. package/lib/isRootSchema.js.map +1 -1
  188. package/lib/jsonSchemaAugmentation.d.ts +1 -0
  189. package/lib/jsonSchemaAugmentation.d.ts.map +1 -0
  190. package/lib/labelValue.d.ts +1 -0
  191. package/lib/labelValue.d.ts.map +1 -0
  192. package/lib/localToUTC.d.ts +1 -0
  193. package/lib/localToUTC.d.ts.map +1 -0
  194. package/lib/logUnsupportedDefaultForEnum.d.ts +2 -1
  195. package/lib/logUnsupportedDefaultForEnum.d.ts.map +1 -0
  196. package/lib/logUnsupportedDefaultForEnum.js +1 -1
  197. package/lib/logUnsupportedDefaultForEnum.js.map +1 -1
  198. package/lib/lookupFromFormContext.d.ts +3 -2
  199. package/lib/lookupFromFormContext.d.ts.map +1 -0
  200. package/lib/lookupFromFormContext.js +4 -5
  201. package/lib/lookupFromFormContext.js.map +1 -1
  202. package/lib/mergeDefaultsWithFormData.d.ts +1 -0
  203. package/lib/mergeDefaultsWithFormData.d.ts.map +1 -0
  204. package/lib/mergeDefaultsWithFormData.js +20 -16
  205. package/lib/mergeDefaultsWithFormData.js.map +1 -1
  206. package/lib/mergeObjects.d.ts +2 -1
  207. package/lib/mergeObjects.d.ts.map +1 -0
  208. package/lib/mergeObjects.js +1 -1
  209. package/lib/mergeObjects.js.map +1 -1
  210. package/lib/mergeSchemas.d.ts +2 -1
  211. package/lib/mergeSchemas.d.ts.map +1 -0
  212. package/lib/mergeSchemas.js +4 -5
  213. package/lib/mergeSchemas.js.map +1 -1
  214. package/lib/nameGenerators.d.ts +2 -1
  215. package/lib/nameGenerators.d.ts.map +1 -0
  216. package/lib/noop.d.ts +5 -0
  217. package/lib/noop.d.ts.map +1 -0
  218. package/lib/noop.js +5 -0
  219. package/lib/noop.js.map +1 -0
  220. package/lib/optionsList.d.ts +2 -1
  221. package/lib/optionsList.d.ts.map +1 -0
  222. package/lib/optionsList.js +15 -15
  223. package/lib/optionsList.js.map +1 -1
  224. package/lib/orderProperties.d.ts +1 -0
  225. package/lib/orderProperties.d.ts.map +1 -0
  226. package/lib/pad.d.ts +1 -0
  227. package/lib/pad.d.ts.map +1 -0
  228. package/lib/parseDateString.d.ts +2 -1
  229. package/lib/parseDateString.d.ts.map +1 -0
  230. package/lib/parser/ParserValidator.d.ts +2 -1
  231. package/lib/parser/ParserValidator.d.ts.map +1 -0
  232. package/lib/parser/ParserValidator.js +8 -7
  233. package/lib/parser/ParserValidator.js.map +1 -1
  234. package/lib/parser/index.d.ts +3 -2
  235. package/lib/parser/index.d.ts.map +1 -0
  236. package/lib/parser/index.js +1 -1
  237. package/lib/parser/index.js.map +1 -1
  238. package/lib/parser/schemaParser.d.ts +3 -2
  239. package/lib/parser/schemaParser.d.ts.map +1 -0
  240. package/lib/parser/schemaParser.js +6 -7
  241. package/lib/parser/schemaParser.js.map +1 -1
  242. package/lib/pathUtils.d.ts +77 -0
  243. package/lib/pathUtils.d.ts.map +1 -0
  244. package/lib/pathUtils.js +192 -0
  245. package/lib/pathUtils.js.map +1 -0
  246. package/lib/rangeSpec.d.ts +2 -1
  247. package/lib/rangeSpec.d.ts.map +1 -0
  248. package/lib/removeOptionalEmptyObjects.d.ts +2 -1
  249. package/lib/removeOptionalEmptyObjects.d.ts.map +1 -0
  250. package/lib/removeOptionalEmptyObjects.js +2 -2
  251. package/lib/removeOptionalEmptyObjects.js.map +1 -1
  252. package/lib/replaceStringParameters.d.ts +1 -0
  253. package/lib/replaceStringParameters.d.ts.map +1 -0
  254. package/lib/resolveUiSchema.d.ts +2 -1
  255. package/lib/resolveUiSchema.d.ts.map +1 -0
  256. package/lib/resolveUiSchema.js +6 -8
  257. package/lib/resolveUiSchema.js.map +1 -1
  258. package/lib/schema/findFieldInSchema.d.ts +2 -1
  259. package/lib/schema/findFieldInSchema.d.ts.map +1 -0
  260. package/lib/schema/findFieldInSchema.js +10 -11
  261. package/lib/schema/findFieldInSchema.js.map +1 -1
  262. package/lib/schema/findSelectedOptionInXxxOf.d.ts +2 -1
  263. package/lib/schema/findSelectedOptionInXxxOf.d.ts.map +1 -0
  264. package/lib/schema/findSelectedOptionInXxxOf.js +7 -7
  265. package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
  266. package/lib/schema/getClosestMatchingOption.d.ts +2 -1
  267. package/lib/schema/getClosestMatchingOption.d.ts.map +1 -0
  268. package/lib/schema/getClosestMatchingOption.js +18 -23
  269. package/lib/schema/getClosestMatchingOption.js.map +1 -1
  270. package/lib/schema/getDefaultFormState.d.ts +2 -1
  271. package/lib/schema/getDefaultFormState.d.ts.map +1 -0
  272. package/lib/schema/getDefaultFormState.js +78 -56
  273. package/lib/schema/getDefaultFormState.js.map +1 -1
  274. package/lib/schema/getDisplayLabel.d.ts +2 -1
  275. package/lib/schema/getDisplayLabel.d.ts.map +1 -0
  276. package/lib/schema/getDisplayLabel.js +7 -7
  277. package/lib/schema/getDisplayLabel.js.map +1 -1
  278. package/lib/schema/getFirstMatchingOption.d.ts +2 -1
  279. package/lib/schema/getFirstMatchingOption.d.ts.map +1 -0
  280. package/lib/schema/getFirstMatchingOption.js +9 -9
  281. package/lib/schema/getFirstMatchingOption.js.map +1 -1
  282. package/lib/schema/getFromSchema.d.ts +3 -2
  283. package/lib/schema/getFromSchema.d.ts.map +1 -0
  284. package/lib/schema/getFromSchema.js +10 -11
  285. package/lib/schema/getFromSchema.js.map +1 -1
  286. package/lib/schema/index.d.ts +15 -14
  287. package/lib/schema/index.d.ts.map +1 -0
  288. package/lib/schema/index.js +14 -14
  289. package/lib/schema/index.js.map +1 -1
  290. package/lib/schema/isFilesArray.d.ts +2 -1
  291. package/lib/schema/isFilesArray.d.ts.map +1 -0
  292. package/lib/schema/isFilesArray.js +2 -2
  293. package/lib/schema/isFilesArray.js.map +1 -1
  294. package/lib/schema/isMultiSelect.d.ts +2 -1
  295. package/lib/schema/isMultiSelect.d.ts.map +1 -0
  296. package/lib/schema/isMultiSelect.js +1 -1
  297. package/lib/schema/isMultiSelect.js.map +1 -1
  298. package/lib/schema/isSelect.d.ts +2 -1
  299. package/lib/schema/isSelect.d.ts.map +1 -0
  300. package/lib/schema/isSelect.js +2 -2
  301. package/lib/schema/isSelect.js.map +1 -1
  302. package/lib/schema/omitExtraData.d.ts +2 -1
  303. package/lib/schema/omitExtraData.d.ts.map +1 -0
  304. package/lib/schema/omitExtraData.js +100 -64
  305. package/lib/schema/omitExtraData.js.map +1 -1
  306. package/lib/schema/retrieveSchema.d.ts +2 -1
  307. package/lib/schema/retrieveSchema.d.ts.map +1 -0
  308. package/lib/schema/retrieveSchema.js +32 -40
  309. package/lib/schema/retrieveSchema.js.map +1 -1
  310. package/lib/schema/sanitizeDataForNewSchema.d.ts +4 -3
  311. package/lib/schema/sanitizeDataForNewSchema.d.ts.map +1 -0
  312. package/lib/schema/sanitizeDataForNewSchema.js +41 -39
  313. package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
  314. package/lib/schema/shallowAllOfMerge.d.ts +1 -0
  315. package/lib/schema/shallowAllOfMerge.d.ts.map +1 -0
  316. package/lib/schema/toPathSchema.d.ts +2 -1
  317. package/lib/schema/toPathSchema.d.ts.map +1 -0
  318. package/lib/schema/toPathSchema.js +14 -14
  319. package/lib/schema/toPathSchema.js.map +1 -1
  320. package/lib/schemaRequiresTrueValue.d.ts +2 -1
  321. package/lib/schemaRequiresTrueValue.d.ts.map +1 -0
  322. package/lib/schemaRequiresTrueValue.js +3 -4
  323. package/lib/schemaRequiresTrueValue.js.map +1 -1
  324. package/lib/shallowEquals.d.ts +1 -0
  325. package/lib/shallowEquals.d.ts.map +1 -0
  326. package/lib/shouldRender.d.ts +2 -1
  327. package/lib/shouldRender.d.ts.map +1 -0
  328. package/lib/shouldRender.js +2 -2
  329. package/lib/shouldRender.js.map +1 -1
  330. package/lib/shouldRenderOptionalField.d.ts +2 -1
  331. package/lib/shouldRenderOptionalField.d.ts.map +1 -0
  332. package/lib/shouldRenderOptionalField.js +11 -10
  333. package/lib/shouldRenderOptionalField.js.map +1 -1
  334. package/lib/toConstant.d.ts +2 -1
  335. package/lib/toConstant.d.ts.map +1 -0
  336. package/lib/toConstant.js +1 -1
  337. package/lib/toConstant.js.map +1 -1
  338. package/lib/toDateString.d.ts +2 -1
  339. package/lib/toDateString.d.ts.map +1 -0
  340. package/lib/toErrorList.d.ts +2 -1
  341. package/lib/toErrorList.d.ts.map +1 -0
  342. package/lib/toErrorList.js +20 -21
  343. package/lib/toErrorList.js.map +1 -1
  344. package/lib/toErrorSchema.d.ts +2 -1
  345. package/lib/toErrorSchema.d.ts.map +1 -0
  346. package/lib/toErrorSchema.js +4 -9
  347. package/lib/toErrorSchema.js.map +1 -1
  348. package/lib/toFieldPathId.d.ts +2 -1
  349. package/lib/toFieldPathId.d.ts.map +1 -0
  350. package/lib/toFieldPathId.js +2 -2
  351. package/lib/toFieldPathId.js.map +1 -1
  352. package/lib/types.d.ts +15 -5
  353. package/lib/types.d.ts.map +1 -0
  354. package/lib/types.js +1 -1
  355. package/lib/types.js.map +1 -1
  356. package/lib/unwrapErrorHandler.d.ts +2 -1
  357. package/lib/unwrapErrorHandler.d.ts.map +1 -0
  358. package/lib/unwrapErrorHandler.js +13 -4
  359. package/lib/unwrapErrorHandler.js.map +1 -1
  360. package/lib/useAltDateWidgetProps.d.ts +3 -2
  361. package/lib/useAltDateWidgetProps.d.ts.map +1 -0
  362. package/lib/useAltDateWidgetProps.js +5 -5
  363. package/lib/useAltDateWidgetProps.js.map +1 -1
  364. package/lib/useDeepCompareMemo.d.ts +1 -0
  365. package/lib/useDeepCompareMemo.d.ts.map +1 -0
  366. package/lib/useDeepCompareMemo.js +1 -1
  367. package/lib/useDeepCompareMemo.js.map +1 -1
  368. package/lib/useFileWidgetProps.d.ts +1 -0
  369. package/lib/useFileWidgetProps.d.ts.map +1 -0
  370. package/lib/useFileWidgetProps.js +3 -4
  371. package/lib/useFileWidgetProps.js.map +1 -1
  372. package/lib/utcToLocal.d.ts +1 -0
  373. package/lib/utcToLocal.d.ts.map +1 -0
  374. package/lib/utcToLocal.js +1 -1
  375. package/lib/utcToLocal.js.map +1 -1
  376. package/lib/validationDataMerge.d.ts +2 -1
  377. package/lib/validationDataMerge.d.ts.map +1 -0
  378. package/lib/validationDataMerge.js +3 -4
  379. package/lib/validationDataMerge.js.map +1 -1
  380. package/lib/withIdRefPrefix.d.ts +2 -1
  381. package/lib/withIdRefPrefix.d.ts.map +1 -0
  382. package/lib/withIdRefPrefix.js +2 -2
  383. package/lib/withIdRefPrefix.js.map +1 -1
  384. package/package.json +5 -6
  385. package/src/ErrorSchemaBuilder.ts +25 -24
  386. package/src/SelectedOptionDescription.tsx +5 -5
  387. package/src/allowAdditionalItems.ts +2 -2
  388. package/src/asNumber.ts +1 -1
  389. package/src/canExpand.ts +2 -2
  390. package/src/constIsAjvDataReference.ts +5 -4
  391. package/src/createErrorHandler.ts +5 -7
  392. package/src/createSchemaUtils.ts +8 -10
  393. package/src/dateRangeOptions.ts +2 -2
  394. package/src/englishStringTranslator.ts +2 -2
  395. package/src/enumOptionSelectedValue.ts +2 -2
  396. package/src/enumOptionValueDecoder.ts +2 -2
  397. package/src/enumOptionValueEncoder.ts +2 -4
  398. package/src/enumOptionsDeselectValue.ts +3 -3
  399. package/src/enumOptionsIndexForValue.ts +2 -2
  400. package/src/enumOptionsIsSelected.ts +2 -2
  401. package/src/enumOptionsSelectValue.ts +3 -5
  402. package/src/enumOptionsValueForIndex.ts +1 -1
  403. package/src/findSchemaDefinition.ts +8 -12
  404. package/src/getChangedFields.ts +57 -18
  405. package/src/getDateElementProps.ts +1 -1
  406. package/src/getDiscriminatorFieldFromSchema.ts +5 -7
  407. package/src/getInputProps.ts +6 -2
  408. package/src/getOptionMatchingSimpleDiscriminator.ts +7 -7
  409. package/src/getOptionValueFormat.ts +1 -1
  410. package/src/getPropertySchema.ts +18 -0
  411. package/src/getSchemaType.ts +2 -2
  412. package/src/getSubmitButtonOptions.ts +3 -3
  413. package/src/getTemplate.ts +1 -1
  414. package/src/getTestIds.ts +7 -6
  415. package/src/getUiOptions.ts +3 -3
  416. package/src/getWidget.tsx +6 -6
  417. package/src/hasWidget.ts +2 -2
  418. package/src/hashForSchema.ts +20 -9
  419. package/src/idGenerators.ts +3 -5
  420. package/src/index.ts +99 -85
  421. package/src/isConstant.ts +2 -2
  422. package/src/isCustomWidget.ts +2 -2
  423. package/src/isFixedItems.ts +2 -2
  424. package/src/isFormDataAvailable.ts +7 -5
  425. package/src/isObject.ts +15 -3
  426. package/src/isPlainObject.ts +14 -0
  427. package/src/isRootSchema.ts +3 -3
  428. package/src/logUnsupportedDefaultForEnum.ts +2 -2
  429. package/src/lookupFromFormContext.ts +7 -8
  430. package/src/mergeDefaultsWithFormData.ts +22 -18
  431. package/src/mergeObjects.ts +2 -2
  432. package/src/mergeSchemas.ts +5 -7
  433. package/src/nameGenerators.ts +1 -1
  434. package/src/noop.ts +4 -0
  435. package/src/optionsList.ts +9 -9
  436. package/src/orderProperties.ts +1 -1
  437. package/src/parseDateString.ts +1 -1
  438. package/src/parser/ParserValidator.ts +5 -7
  439. package/src/parser/index.ts +2 -2
  440. package/src/parser/schemaParser.ts +8 -10
  441. package/src/pathUtils.ts +203 -0
  442. package/src/rangeSpec.ts +1 -1
  443. package/src/removeOptionalEmptyObjects.ts +3 -3
  444. package/src/resolveUiSchema.ts +5 -7
  445. package/src/schema/findFieldInSchema.ts +11 -13
  446. package/src/schema/findSelectedOptionInXxxOf.ts +9 -10
  447. package/src/schema/getClosestMatchingOption.ts +73 -83
  448. package/src/schema/getDefaultFormState.ts +62 -34
  449. package/src/schema/getDisplayLabel.ts +7 -7
  450. package/src/schema/getFirstMatchingOption.ts +10 -11
  451. package/src/schema/getFromSchema.ts +12 -14
  452. package/src/schema/index.ts +14 -14
  453. package/src/schema/isFilesArray.ts +3 -3
  454. package/src/schema/isMultiSelect.ts +2 -2
  455. package/src/schema/isSelect.ts +3 -3
  456. package/src/schema/omitExtraData.ts +104 -68
  457. package/src/schema/retrieveSchema.ts +47 -60
  458. package/src/schema/sanitizeDataForNewSchema.ts +42 -41
  459. package/src/schema/toPathSchema.ts +14 -14
  460. package/src/schemaRequiresTrueValue.ts +1 -1
  461. package/src/shouldRender.ts +3 -3
  462. package/src/shouldRenderOptionalField.ts +14 -14
  463. package/src/toConstant.ts +2 -2
  464. package/src/toDateString.ts +1 -1
  465. package/src/toErrorList.ts +22 -25
  466. package/src/toErrorSchema.ts +5 -11
  467. package/src/toFieldPathId.ts +2 -2
  468. package/src/types.ts +14 -5
  469. package/src/unwrapErrorHandler.ts +15 -6
  470. package/src/useAltDateWidgetProps.tsx +7 -7
  471. package/src/useDeepCompareMemo.ts +1 -1
  472. package/src/useFileWidgetProps.ts +1 -1
  473. package/src/utcToLocal.ts +1 -1
  474. package/src/validationDataMerge.ts +4 -6
  475. package/src/withIdRefPrefix.ts +3 -4
  476. package/lib/tsconfig.tsbuildinfo +0 -1
  477. package/src/tsconfig.json +0 -9
@@ -0,0 +1,203 @@
1
+ import type { FieldPathList } from './types.ts';
2
+
3
+ /** A path into an object: either a list of path segments or a single property key (string or number).
4
+ * A bare string is ALWAYS treated as one literal key — `'a.b'` is the key `'a.b'`, not a deep path. To
5
+ * traverse a dotted path string, convert it explicitly with {@link toPath}
6
+ */
7
+ export type ObjectPath = string | number | FieldPathList;
8
+
9
+ /** Matches unsigned integer strings that represent valid array indexes */
10
+ const reIsIndex = /^(?:0|[1-9]\d*)$/;
11
+
12
+ /** Converts a dotted path string, such as produced for validation error properties, into its list of
13
+ * path segments. Array indexes may be written bracketed (`'a[0].b'`) or dotted (`'a.0.b'`), and empty
14
+ * segments — from a leading `.`, a trailing `.` or a `..` run — are dropped.
15
+ *
16
+ * Only the grammar RJSF itself produces is supported: dots and brackets are always separators, so
17
+ * quoted keys are not recognized and keys containing dots must be addressed with a segment list
18
+ * instead of a string.
19
+ *
20
+ * @param path - The string path to convert, such as `'.level1.level2[2].level3'`
21
+ * @returns - The list of path segments, such as `['level1', 'level2', '2', 'level3']`
22
+ */
23
+ export function toPath(path: string): string[] {
24
+ return path.split(/[.[\]]+/).filter(Boolean);
25
+ }
26
+
27
+ /** Normalizes an `ObjectPath` into a list of path segments, wrapping a single key into a one-element list */
28
+ function normalizePath(path: ObjectPath): FieldPathList {
29
+ return Array.isArray(path) ? path : [path];
30
+ }
31
+
32
+ /** Determines whether a path segment could mutate the prototype chain. Only `__proto__` can: assigning to it
33
+ * invokes the prototype setter rather than creating an own property. `constructor` and `prototype` are safe
34
+ * here — and are legal JSON Schema property names — because both reads and writes below are own-property-only,
35
+ * so `['constructor', 'prototype', 'polluted']` shadows `constructor` with a fresh object instead of walking
36
+ * into `Object.prototype`. Only writes need this check; reads are already own-property-only
37
+ */
38
+ function isUnsafeSegment(segment: string | number): boolean {
39
+ return segment === '__proto__';
40
+ }
41
+
42
+ /** Determines whether a path segment represents a valid array index */
43
+ function isIndex(segment: string | number): boolean {
44
+ return typeof segment === 'number' ? Number.isInteger(segment) && segment >= 0 : reIsIndex.test(segment);
45
+ }
46
+
47
+ /** Determines whether `value` can hold properties, i.e. is an object (arrays included) or a function */
48
+ function isSettable(value: unknown): value is Record<PropertyKey, unknown> {
49
+ return value != null && (typeof value === 'object' || typeof value === 'function');
50
+ }
51
+
52
+ /** Gets the value at `path` of `obj`, returning `defaultValue` when the resolved value is `undefined`
53
+ *
54
+ * Every segment must be an OWN property, matching {@link hasByPath}, so the two can be used as a
55
+ * guard/read pair. Inherited members are never resolved: `getByPath({}, 'toString')` returns
56
+ * `defaultValue`, not `Function.prototype.toString`. For the plain form data and schemas RJSF navigates,
57
+ * an inherited member is never data, and the own-property rule also makes prototype internals such as
58
+ * `__proto__` unreachable unless they are genuine own data keys
59
+ *
60
+ * An empty segment list resolves to nothing, so `defaultValue` is returned. This matches {@link hasByPath},
61
+ * which is `false` for an empty path, and keeps a computed-but-empty path (`toPath('')` for a root-level
62
+ * validation error, say) from resolving to the whole object
63
+ *
64
+ * The value at a runtime-computed path cannot be known statically, so `R` is the CALLER'S declaration of
65
+ * the expected type (like `Map.get()`); it defaults to `unknown`, which forces narrowing when no type is given
66
+ *
67
+ * @param obj - The object to query
68
+ * @param path - The single key or list of path segments at which to get the value
69
+ * @param [defaultValue] - The value returned when the resolved value is `undefined`
70
+ * @returns - The resolved value, otherwise `defaultValue`
71
+ */
72
+ export function getByPath<R = unknown>(obj: unknown, path: ObjectPath, defaultValue?: R): R {
73
+ let current: unknown;
74
+ if (!Array.isArray(path)) {
75
+ // Fast path for the most common call shape, a single constant key, avoiding the segment-list allocation
76
+ current = isSettable(obj) && Object.hasOwn(obj, path) ? obj[path] : undefined;
77
+ } else if (path.length === 0) {
78
+ // An empty path resolves to nothing, mirroring `hasByPath()`
79
+ current = undefined;
80
+ } else {
81
+ current = obj;
82
+ for (let i = 0; i < path.length; i++) {
83
+ const segment = path[i];
84
+ // Only own data keys resolve, so inherited members and prototype internals are never read
85
+ if (!isSettable(current) || !Object.hasOwn(current, segment)) {
86
+ current = undefined;
87
+ break;
88
+ }
89
+ current = current[segment];
90
+ }
91
+ }
92
+ // The single deliberate cast in these utilities: the resolved value is trusted to be the `R` the caller declared
93
+ return (current === undefined ? defaultValue : current) as R;
94
+ }
95
+
96
+ /** Sets `value` at `path` of `obj`, mutating and returning `obj`. Missing intermediate containers are
97
+ * created: arrays when the next segment is a valid array index, plain objects otherwise (or always plain
98
+ * objects when `createIntermediateObjects` is true)
99
+ *
100
+ * A `__proto__` segment is refused in any position — assigning to it would mutate the prototype chain rather
101
+ * than create an own property — and the write is silently skipped. Every other key, `constructor` and
102
+ * `prototype` included, is written as an own property
103
+ *
104
+ * @param obj - The object to modify
105
+ * @param path - The single key or list of path segments at which to set the value
106
+ * @param value - The value to set
107
+ * @param [createIntermediateObjects] - When true, always create plain objects for missing intermediate
108
+ * containers, even for numeric path segments
109
+ * @returns - The mutated `obj`
110
+ */
111
+ export function setByPath<O>(obj: O, path: ObjectPath, value: unknown, createIntermediateObjects = false): O {
112
+ if (!isSettable(obj)) {
113
+ return obj;
114
+ }
115
+ // Fast path for a single constant key, avoiding the segment-list allocation
116
+ if (!Array.isArray(path)) {
117
+ // Refuse a segment that could mutate the prototype chain (prototype pollution)
118
+ if (!isUnsafeSegment(path)) {
119
+ const target: Record<PropertyKey, unknown> = obj;
120
+ target[path] = value;
121
+ }
122
+ return obj;
123
+ }
124
+ const segments = path;
125
+ // Refuse paths that could mutate the prototype chain (prototype pollution)
126
+ if (segments.some(isUnsafeSegment)) {
127
+ return obj;
128
+ }
129
+ let current: Record<PropertyKey, unknown> = obj;
130
+ for (let i = 0; i < segments.length; i++) {
131
+ const segment = segments[i];
132
+ if (i === segments.length - 1) {
133
+ current[segment] = value;
134
+ } else {
135
+ // Own properties only, so an inherited member is never traversed into
136
+ const existing = Object.hasOwn(current, segment) ? current[segment] : undefined;
137
+ if (isSettable(existing)) {
138
+ current = existing;
139
+ } else {
140
+ const next = createIntermediateObjects || !isIndex(segments[i + 1]) ? {} : [];
141
+ current[segment] = next;
142
+ /* v8 ignore next -- a fresh {} or [] is always settable; the guard exists only to narrow the type */
143
+ if (isSettable(next)) {
144
+ current = next;
145
+ }
146
+ }
147
+ }
148
+ }
149
+ return obj;
150
+ }
151
+
152
+ /** Determines whether `obj` has an own property at `path`
153
+ *
154
+ * Every segment is checked with `Object.hasOwn()`, so inherited properties report `false` —
155
+ * `hasByPath({}, 'toString')` is `false`. {@link getByPath} applies the same own-property rule, so the
156
+ * two can be used as a guard/read pair
157
+ *
158
+ * @param obj - The object to query
159
+ * @param path - The single key or list of path segments to check for
160
+ * @returns - True if the own property exists at `path`, otherwise false
161
+ */
162
+ export function hasByPath(obj: unknown, path: ObjectPath): boolean {
163
+ // Fast path for a single constant key, avoiding the segment-list allocation
164
+ if (!Array.isArray(path)) {
165
+ return isSettable(obj) && Object.hasOwn(obj, path);
166
+ }
167
+ let current: unknown = obj;
168
+ for (let i = 0; i < path.length; i++) {
169
+ if (!isSettable(current) || !Object.hasOwn(current, path[i])) {
170
+ return false;
171
+ }
172
+ current = current[path[i]];
173
+ }
174
+ return path.length > 0;
175
+ }
176
+
177
+ /** Removes the own property at `path` of `obj`, mutating `obj`
178
+ *
179
+ * Both the parent lookup and the delete are own-property-only, so no segment can reach the prototype chain and
180
+ * no `UNSAFE_SEGMENTS`-style guard is needed: deleting a `__proto__` that is not an own property is a no-op
181
+ *
182
+ * @param obj - The object to modify
183
+ * @param path - The single key or list of path segments at which to remove the property
184
+ * @returns - True if the property was removed or did not exist, otherwise false
185
+ */
186
+ export function unsetByPath(obj: unknown, path: ObjectPath): boolean {
187
+ const segments = normalizePath(path);
188
+ // An empty path names no property, so there is nothing to remove
189
+ if (segments.length === 0) {
190
+ return true;
191
+ }
192
+ const parent = segments.length > 1 ? getByPath(obj, segments.slice(0, -1)) : obj;
193
+ if (parent == null) {
194
+ return true;
195
+ }
196
+ try {
197
+ // Returns false for a non-configurable property instead of throwing like `delete` in strict mode
198
+ return Reflect.deleteProperty(parent, segments[segments.length - 1]);
199
+ } catch {
200
+ // Reflect.deleteProperty throws when the target is a primitive
201
+ return false;
202
+ }
203
+ }
package/src/rangeSpec.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { RangeSpecType, RJSFSchema, StrictRJSFSchema } from './types';
1
+ import type { RangeSpecType, RJSFSchema, StrictRJSFSchema } from './types.ts';
2
2
 
3
3
  /** Extracts the range spec information `{ step?: number, min?: number, max?: number }` that can be spread onto an HTML
4
4
  * input from the range analog in the schema `{ multipleOf?: number, minimum?: number, maximum?: number }`.
@@ -1,6 +1,6 @@
1
- import isObject from './isObject';
2
- import { isValueEmpty, retrieveSchema } from './schema';
3
- import type { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, ValidatorType } from './types';
1
+ import isObject from './isObject.ts';
2
+ import { isValueEmpty, retrieveSchema } from './schema/index.ts';
3
+ import type { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, ValidatorType } from './types.ts';
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
@@ -1,8 +1,6 @@
1
- import isEmpty from 'lodash/isEmpty';
2
-
3
- import { ANY_OF_KEY, ONE_OF_KEY, REF_KEY, RJSF_REF_KEY } from './constants';
4
- import findSchemaDefinition from './findSchemaDefinition';
5
- import mergeObjects from './mergeObjects';
1
+ import { ANY_OF_KEY, ONE_OF_KEY, REF_KEY, RJSF_REF_KEY } from './constants.ts';
2
+ import findSchemaDefinition from './findSchemaDefinition.ts';
3
+ import mergeObjects from './mergeObjects.ts';
6
4
  import type {
7
5
  FormContextType,
8
6
  GenericObjectType,
@@ -11,7 +9,7 @@ import type {
11
9
  RJSFSchema,
12
10
  StrictRJSFSchema,
13
11
  UiSchema,
14
- } from './types';
12
+ } from './types.ts';
15
13
 
16
14
  /** Resolves the uiSchema for a given schema, considering `ui:definitions` stored in the registry.
17
15
  *
@@ -41,7 +39,7 @@ export default function resolveUiSchema<
41
39
  let result: UiSchema<T, S, F>;
42
40
  if (!definitionUiSchema) {
43
41
  result = localUiSchema || {};
44
- } else if (!localUiSchema || isEmpty(localUiSchema)) {
42
+ } else if (!localUiSchema || Object.keys(localUiSchema).length === 0) {
45
43
  result = { ...definitionUiSchema };
46
44
  } else {
47
45
  result = mergeObjects(definitionUiSchema as GenericObjectType, localUiSchema as GenericObjectType) as UiSchema<
@@ -1,7 +1,5 @@
1
- import get from 'lodash/get';
2
- import has from 'lodash/has';
3
-
4
- import { ANY_OF_KEY, ONE_OF_KEY, PROPERTIES_KEY, REQUIRED_KEY } from '../constants';
1
+ import { ANY_OF_KEY, ONE_OF_KEY, PROPERTIES_KEY, REQUIRED_KEY } from '../constants.ts';
2
+ import { getByPath, hasByPath } from '../pathUtils.ts';
5
3
  import type {
6
4
  Experimental_CustomMergeAllOf,
7
5
  FormContextType,
@@ -10,9 +8,9 @@ import type {
10
8
  SchemaFieldPath,
11
9
  StrictRJSFSchema,
12
10
  ValidatorType,
13
- } from '../types';
14
- import findSelectedOptionInXxxOf from './findSelectedOptionInXxxOf';
15
- import getFromSchema from './getFromSchema';
11
+ } from '../types.ts';
12
+ import findSelectedOptionInXxxOf from './findSelectedOptionInXxxOf.ts';
13
+ import getFromSchema from './getFromSchema.ts';
16
14
 
17
15
  /** Unique schema that represents no schema was found, exported for testing purposes */
18
16
  export const NOT_FOUND_SCHEMA = { title: '!@#$_UNKNOWN_$#@!' };
@@ -60,7 +58,7 @@ export default function findFieldInSchema<
60
58
  {} as S,
61
59
  experimental_customMergeAllOf,
62
60
  );
63
- if (has(parentField, ONE_OF_KEY)) {
61
+ if (hasByPath(parentField, ONE_OF_KEY)) {
64
62
  // if this sub-path has a `oneOf` then use the formData to drill into the schema with the selected option
65
63
  parentField = findSelectedOptionInXxxOf(
66
64
  validator,
@@ -68,10 +66,10 @@ export default function findFieldInSchema<
68
66
  parentField,
69
67
  fieldNameKey,
70
68
  ONE_OF_KEY,
71
- get(formData, subPath),
69
+ getByPath<T>(formData, subPath),
72
70
  experimental_customMergeAllOf,
73
71
  )!;
74
- } else if (has(parentField, ANY_OF_KEY)) {
72
+ } else if (hasByPath(parentField, ANY_OF_KEY)) {
75
73
  // if this sub-path has a `anyOf` then use the formData to drill into the schema with the selected option
76
74
  parentField = findSelectedOptionInXxxOf(
77
75
  validator,
@@ -79,14 +77,14 @@ export default function findFieldInSchema<
79
77
  parentField,
80
78
  fieldNameKey,
81
79
  ANY_OF_KEY,
82
- get(formData, subPath),
80
+ getByPath<T>(formData, subPath),
83
81
  experimental_customMergeAllOf,
84
82
  )!;
85
83
  }
86
84
  });
87
85
  }
88
86
 
89
- if (has(parentField, ONE_OF_KEY)) {
87
+ if (hasByPath(parentField, ONE_OF_KEY)) {
90
88
  // When oneOf is in the root schema, use the formData to drill into the schema with the selected option
91
89
  parentField = findSelectedOptionInXxxOf(
92
90
  validator,
@@ -97,7 +95,7 @@ export default function findFieldInSchema<
97
95
  formData,
98
96
  experimental_customMergeAllOf,
99
97
  )!;
100
- } else if (has(parentField, ANY_OF_KEY)) {
98
+ } else if (hasByPath(parentField, ANY_OF_KEY)) {
101
99
  // When anyOf is in the root schema, use the formData to drill into the schema with the selected option
102
100
  parentField = findSelectedOptionInXxxOf(
103
101
  validator,
@@ -1,16 +1,15 @@
1
- import get from 'lodash/get';
2
-
3
- import { CONST_KEY, DEFAULT_KEY, PROPERTIES_KEY } from '../constants';
4
- import deepEquals from '../deepEquals';
5
- import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
1
+ import { CONST_KEY, DEFAULT_KEY, PROPERTIES_KEY } from '../constants.ts';
2
+ import deepEquals from '../deepEquals.ts';
3
+ import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema.ts';
4
+ import { getByPath } from '../pathUtils.ts';
6
5
  import type {
7
6
  Experimental_CustomMergeAllOf,
8
7
  FormContextType,
9
8
  RJSFSchema,
10
9
  StrictRJSFSchema,
11
10
  ValidatorType,
12
- } from '../types';
13
- import retrieveSchema from './retrieveSchema';
11
+ } from '../types.ts';
12
+ import retrieveSchema from './retrieveSchema.ts';
14
13
 
15
14
  /** Finds the option inside the `schema['any/oneOf']` list which has the `properties[selectorField].default` or
16
15
  * `properties[selectorField].const` that matches the `formData[selectorField]` value. For the purposes of this
@@ -45,14 +44,14 @@ export default function findSelectedOptionInXxxOf<
45
44
  const xxxOfs = schema[xxx].map((xxxOf) =>
46
45
  retrieveSchema<T, S, F>(validator, xxxOf as S, rootSchema, formData, experimental_customMergeAllOf),
47
46
  );
48
- const data = get(formData, selectorField);
47
+ const data = getByPath(formData, selectorField);
49
48
  if (data !== undefined) {
50
49
  return xxxOfs.find((xxxOfOption) =>
51
50
  deepEquals(
52
- get(
51
+ getByPath(
53
52
  xxxOfOption,
54
53
  [PROPERTIES_KEY, selectorField, DEFAULT_KEY],
55
- get(xxxOfOption, [PROPERTIES_KEY, selectorField, CONST_KEY]),
54
+ getByPath(xxxOfOption, [PROPERTIES_KEY, selectorField, CONST_KEY]),
56
55
  ),
57
56
  data,
58
57
  ),
@@ -1,24 +1,18 @@
1
- import get from 'lodash/get';
2
- import has from 'lodash/has';
3
- import isNumber from 'lodash/isNumber';
4
- import isObject from 'lodash/isObject';
5
- import isString from 'lodash/isString';
6
- import reduce from 'lodash/reduce';
7
- import times from 'lodash/times';
8
-
9
- import { ONE_OF_KEY, REF_KEY, JUNK_OPTION_ID, ANY_OF_KEY } from '../constants';
10
- import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
11
- import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator';
12
- import guessType from '../guessType';
1
+ import { ONE_OF_KEY, REF_KEY, JUNK_OPTION_ID, ANY_OF_KEY } from '../constants.ts';
2
+ import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema.ts';
3
+ import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator.ts';
4
+ import guessType from '../guessType.ts';
5
+ import isObject from '../isObject.ts';
6
+ import { getByPath, hasByPath } from '../pathUtils.ts';
13
7
  import type {
14
8
  Experimental_CustomMergeAllOf,
15
9
  FormContextType,
16
10
  RJSFSchema,
17
11
  StrictRJSFSchema,
18
12
  ValidatorType,
19
- } from '../types';
20
- import getFirstMatchingOption from './getFirstMatchingOption';
21
- import retrieveSchema, { resolveAllReferences } from './retrieveSchema';
13
+ } from '../types.ts';
14
+ import getFirstMatchingOption from './getFirstMatchingOption.ts';
15
+ import retrieveSchema, { resolveAllReferences } from './retrieveSchema.ts';
22
16
 
23
17
  /** A junk option used to determine when the getFirstMatchingOption call really matches an option rather than returning
24
18
  * the first item
@@ -64,77 +58,73 @@ export function calculateIndexScore<T = any, S extends StrictRJSFSchema = RJSFSc
64
58
  let totalScore = 0;
65
59
  if (schema) {
66
60
  if (isObject(schema.properties)) {
67
- totalScore += reduce(
68
- schema.properties,
69
- (score, value, key) => {
70
- const formValue = get(formData, key);
71
- if (typeof value === 'boolean') {
72
- return score;
73
- }
74
- if (has(value, REF_KEY)) {
75
- const newSchema = retrieveSchema<T, S, F>(
61
+ totalScore += Object.entries(schema.properties).reduce((score, [key, value]) => {
62
+ const formValue = formData?.[key];
63
+ if (typeof value === 'boolean') {
64
+ return score;
65
+ }
66
+ if (hasByPath(value, REF_KEY)) {
67
+ const newSchema = retrieveSchema<T, S, F>(
68
+ validator,
69
+ value as S,
70
+ rootSchema,
71
+ formValue,
72
+ experimental_customMergeAllOf,
73
+ );
74
+ return (
75
+ score +
76
+ calculateIndexScore<T, S, F>(
77
+ validator,
78
+ rootSchema,
79
+ newSchema,
80
+ formValue || {},
81
+ experimental_customMergeAllOf,
82
+ )
83
+ );
84
+ }
85
+ if ((hasByPath(value, ONE_OF_KEY) || hasByPath(value, ANY_OF_KEY)) && formValue) {
86
+ const xxxOfKey = hasByPath(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
87
+ const discriminator = getDiscriminatorFieldFromSchema<S>(value as S);
88
+ return (
89
+ score +
90
+ getClosestMatchingOption<T, S, F>(
76
91
  validator,
77
- value as S,
78
92
  rootSchema,
79
93
  formValue,
94
+ getByPath<S[]>(value, xxxOfKey),
95
+ -1,
96
+ discriminator,
80
97
  experimental_customMergeAllOf,
81
- );
82
- return (
83
- score +
84
- calculateIndexScore<T, S, F>(
85
- validator,
86
- rootSchema,
87
- newSchema,
88
- formValue || {},
89
- experimental_customMergeAllOf,
90
- )
91
- );
92
- }
93
- if ((has(value, ONE_OF_KEY) || has(value, ANY_OF_KEY)) && formValue) {
94
- const xxxOfKey = has(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
95
- const discriminator = getDiscriminatorFieldFromSchema<S>(value as S);
96
- return (
97
- score +
98
- getClosestMatchingOption<T, S, F>(
99
- validator,
100
- rootSchema,
101
- formValue,
102
- get(value, xxxOfKey) as S[],
103
- -1,
104
- discriminator,
105
- experimental_customMergeAllOf,
106
- )
107
- );
108
- }
109
- if (value.type === 'object') {
110
- // If the structure is matching then give it a little boost in score
111
- const structureBoost = isObject(formValue) ? 1 : 0;
112
- return (
113
- score +
114
- structureBoost +
115
- calculateIndexScore<T, S, F>(validator, rootSchema, value as S, formValue, experimental_customMergeAllOf)
116
- );
98
+ )
99
+ );
100
+ }
101
+ if (value.type === 'object') {
102
+ // If the structure is matching then give it a little boost in score
103
+ const structureBoost = typeof formValue === 'object' && formValue !== null ? 1 : 0;
104
+ return (
105
+ score +
106
+ structureBoost +
107
+ calculateIndexScore<T, S, F>(validator, rootSchema, value as S, formValue, experimental_customMergeAllOf)
108
+ );
109
+ }
110
+ if (value.type === guessType(formValue)) {
111
+ // If the types match, then we bump the score by one
112
+ let newScore = score + 1;
113
+ if (value.default) {
114
+ // If the schema contains a readonly default value score the value that matches the default higher and
115
+ // any non-matching value lower
116
+ newScore += formValue === value.default ? 1 : -1;
117
+ } else if (value.const) {
118
+ // If the schema contains a const value score the value that matches the default higher and
119
+ // any non-matching value lower
120
+ newScore += formValue === value.const ? 1 : -1;
117
121
  }
118
- if (value.type === guessType(formValue)) {
119
- // If the types match, then we bump the score by one
120
- let newScore = score + 1;
121
- if (value.default) {
122
- // If the schema contains a readonly default value score the value that matches the default higher and
123
- // any non-matching value lower
124
- newScore += formValue === value.default ? 1 : -1;
125
- } else if (value.const) {
126
- // If the schema contains a const value score the value that matches the default higher and
127
- // any non-matching value lower
128
- newScore += formValue === value.const ? 1 : -1;
129
- }
130
- // TODO eventually, deal with enums/arrays
131
- return newScore;
132
- }
133
- return score;
134
- },
135
- 0,
136
- );
137
- } else if (isString(schema.type) && schema.type === guessType(formData)) {
122
+ // TODO eventually, deal with enums/arrays
123
+ return newScore;
124
+ }
125
+ return score;
126
+ }, 0);
127
+ } else if (typeof schema.type === 'string' && schema.type === guessType(formData)) {
138
128
  totalScore += 1;
139
129
  }
140
130
  }
@@ -181,7 +171,7 @@ export default function getClosestMatchingOption<
181
171
  const resolvedOptions = options.map((option) => resolveAllReferences<S>(option, rootSchema, []));
182
172
 
183
173
  const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
184
- if (isNumber(simpleDiscriminatorMatch)) {
174
+ if (typeof simpleDiscriminatorMatch === 'number') {
185
175
  return simpleDiscriminatorMatch;
186
176
  }
187
177
 
@@ -202,7 +192,7 @@ export default function getClosestMatchingOption<
202
192
  }
203
193
  if (!allValidIndexes.length) {
204
194
  // No indexes were valid, so we'll score all the options, add all the indexes
205
- times(resolvedOptions.length, (i) => allValidIndexes.push(i));
195
+ allValidIndexes.push(...resolvedOptions.keys());
206
196
  }
207
197
  interface BestType {
208
198
  bestIndex: number;