@rjsf/utils 6.0.0-alpha.0 → 6.0.0-beta.1

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