@rjsf/utils 5.11.2 → 5.12.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 (303) hide show
  1. package/dist/index.js +2544 -5
  2. package/dist/index.js.map +7 -0
  3. package/dist/utils.esm.js +1228 -2113
  4. package/dist/utils.esm.js.map +7 -1
  5. package/dist/utils.umd.js +2414 -0
  6. package/lib/ErrorSchemaBuilder.d.ts +60 -0
  7. package/lib/ErrorSchemaBuilder.js +103 -0
  8. package/lib/ErrorSchemaBuilder.js.map +1 -0
  9. package/lib/allowAdditionalItems.d.ts +8 -0
  10. package/lib/allowAdditionalItems.js +14 -0
  11. package/lib/allowAdditionalItems.js.map +1 -0
  12. package/lib/asNumber.d.ts +10 -0
  13. package/lib/asNumber.js +36 -0
  14. package/lib/asNumber.js.map +1 -0
  15. package/lib/canExpand.d.ts +11 -0
  16. package/lib/canExpand.js +26 -0
  17. package/lib/canExpand.js.map +1 -0
  18. package/lib/constants.d.ts +31 -0
  19. package/lib/constants.js +32 -0
  20. package/lib/constants.js.map +1 -0
  21. package/lib/createErrorHandler.d.ts +7 -0
  22. package/lib/createErrorHandler.js +31 -0
  23. package/lib/createErrorHandler.js.map +1 -0
  24. package/lib/createSchemaUtils.d.ts +10 -0
  25. package/lib/createSchemaUtils.js +207 -0
  26. package/lib/createSchemaUtils.js.map +1 -0
  27. package/lib/dataURItoBlob.d.ts +16 -0
  28. package/lib/dataURItoBlob.js +43 -0
  29. package/lib/dataURItoBlob.js.map +1 -0
  30. package/lib/deepEquals.d.ts +8 -0
  31. package/lib/deepEquals.js +19 -0
  32. package/lib/deepEquals.js.map +1 -0
  33. package/lib/englishStringTranslator.d.ts +10 -0
  34. package/lib/englishStringTranslator.js +13 -0
  35. package/lib/englishStringTranslator.js.map +1 -0
  36. package/lib/enumOptionsDeselectValue.d.ts +14 -0
  37. package/lib/enumOptionsDeselectValue.js +22 -0
  38. package/lib/enumOptionsDeselectValue.js.map +1 -0
  39. package/lib/enumOptionsIndexForValue.d.ts +13 -0
  40. package/lib/enumOptionsIndexForValue.js +22 -0
  41. package/lib/enumOptionsIndexForValue.js.map +1 -0
  42. package/lib/enumOptionsIsSelected.d.ts +8 -0
  43. package/lib/enumOptionsIsSelected.js +14 -0
  44. package/lib/enumOptionsIsSelected.js.map +1 -0
  45. package/lib/enumOptionsSelectValue.d.ts +10 -0
  46. package/lib/enumOptionsSelectValue.js +23 -0
  47. package/lib/enumOptionsSelectValue.js.map +1 -0
  48. package/lib/enumOptionsValueForIndex.d.ts +13 -0
  49. package/lib/enumOptionsValueForIndex.js +21 -0
  50. package/lib/enumOptionsValueForIndex.js.map +1 -0
  51. package/lib/enums.d.ts +72 -0
  52. package/lib/enums.js +76 -0
  53. package/lib/enums.js.map +1 -0
  54. package/lib/findSchemaDefinition.d.ts +20 -0
  55. package/lib/findSchemaDefinition.js +49 -0
  56. package/lib/findSchemaDefinition.js.map +1 -0
  57. package/lib/getDiscriminatorFieldFromSchema.d.ts +8 -0
  58. package/lib/getDiscriminatorFieldFromSchema.js +20 -0
  59. package/lib/getDiscriminatorFieldFromSchema.js.map +1 -0
  60. package/lib/getInputProps.d.ts +10 -0
  61. package/lib/getInputProps.js +41 -0
  62. package/lib/getInputProps.js.map +1 -0
  63. package/lib/getSchemaType.d.ts +13 -0
  64. package/lib/getSchemaType.js +29 -0
  65. package/lib/getSchemaType.js.map +1 -0
  66. package/lib/getSubmitButtonOptions.d.ts +10 -0
  67. package/lib/getSubmitButtonOptions.js +25 -0
  68. package/lib/getSubmitButtonOptions.js.map +1 -0
  69. package/lib/getTemplate.d.ts +10 -0
  70. package/lib/getTemplate.js +19 -0
  71. package/lib/getTemplate.js.map +1 -0
  72. package/lib/getUiOptions.d.ts +9 -0
  73. package/lib/getUiOptions.js +25 -0
  74. package/lib/getUiOptions.js.map +1 -0
  75. package/lib/getWidget.d.ts +13 -0
  76. package/lib/getWidget.js +118 -0
  77. package/lib/getWidget.js.map +1 -0
  78. package/lib/guessType.d.ts +7 -0
  79. package/lib/guessType.js +29 -0
  80. package/lib/guessType.js.map +1 -0
  81. package/lib/hasWidget.d.ts +10 -0
  82. package/lib/hasWidget.js +23 -0
  83. package/lib/hasWidget.js.map +1 -0
  84. package/lib/hashForSchema.d.ts +8 -0
  85. package/lib/hashForSchema.js +29 -0
  86. package/lib/hashForSchema.js.map +1 -0
  87. package/lib/idGenerators.d.ts +47 -0
  88. package/lib/idGenerators.js +73 -0
  89. package/lib/idGenerators.js.map +1 -0
  90. package/lib/index.d.ts +57 -0
  91. package/lib/index.js +58 -0
  92. package/lib/index.js.map +1 -0
  93. package/lib/isConstant.d.ts +8 -0
  94. package/lib/isConstant.js +11 -0
  95. package/lib/isConstant.js.map +1 -0
  96. package/lib/isCustomWidget.d.ts +7 -0
  97. package/lib/isCustomWidget.js +13 -0
  98. package/lib/isCustomWidget.js.map +1 -0
  99. package/lib/isFixedItems.d.ts +8 -0
  100. package/lib/isFixedItems.js +11 -0
  101. package/lib/isFixedItems.js.map +1 -0
  102. package/lib/isObject.d.ts +7 -0
  103. package/lib/isObject.js +16 -0
  104. package/lib/isObject.js.map +1 -0
  105. package/lib/labelValue.d.ts +13 -0
  106. package/lib/labelValue.js +4 -0
  107. package/lib/labelValue.js.map +1 -0
  108. package/lib/localToUTC.d.ts +6 -0
  109. package/lib/localToUTC.js +9 -0
  110. package/lib/localToUTC.js.map +1 -0
  111. package/lib/mergeDefaultsWithFormData.d.ts +17 -0
  112. package/lib/mergeDefaultsWithFormData.js +43 -0
  113. package/lib/mergeDefaultsWithFormData.js.map +1 -0
  114. package/lib/mergeObjects.d.ts +11 -0
  115. package/lib/mergeObjects.js +35 -0
  116. package/lib/mergeObjects.js.map +1 -0
  117. package/lib/mergeSchemas.d.ts +10 -0
  118. package/lib/mergeSchemas.js +35 -0
  119. package/lib/mergeSchemas.js.map +1 -0
  120. package/lib/optionsList.d.ts +10 -0
  121. package/lib/optionsList.js +36 -0
  122. package/lib/optionsList.js.map +1 -0
  123. package/lib/orderProperties.d.ts +11 -0
  124. package/lib/orderProperties.js +38 -0
  125. package/lib/orderProperties.js.map +1 -0
  126. package/lib/pad.d.ts +7 -0
  127. package/lib/pad.js +14 -0
  128. package/lib/pad.js.map +1 -0
  129. package/lib/parseDateString.d.ts +9 -0
  130. package/lib/parseDateString.js +32 -0
  131. package/lib/parseDateString.js.map +1 -0
  132. package/lib/parser/ParserValidator.d.ts +70 -0
  133. package/lib/parser/ParserValidator.js +93 -0
  134. package/lib/parser/ParserValidator.js.map +1 -0
  135. package/lib/parser/index.d.ts +4 -0
  136. package/lib/parser/index.js +3 -0
  137. package/lib/parser/index.js.map +1 -0
  138. package/lib/parser/schemaParser.d.ts +9 -0
  139. package/lib/parser/schemaParser.js +48 -0
  140. package/lib/parser/schemaParser.js.map +1 -0
  141. package/lib/rangeSpec.d.ts +9 -0
  142. package/lib/rangeSpec.js +20 -0
  143. package/lib/rangeSpec.js.map +1 -0
  144. package/lib/replaceStringParameters.d.ts +9 -0
  145. package/lib/replaceStringParameters.js +23 -0
  146. package/lib/replaceStringParameters.js.map +1 -0
  147. package/lib/schema/getClosestMatchingOption.d.ts +49 -0
  148. package/lib/schema/getClosestMatchingOption.js +154 -0
  149. package/lib/schema/getClosestMatchingOption.js.map +1 -0
  150. package/lib/schema/getDefaultFormState.d.ts +66 -0
  151. package/lib/schema/getDefaultFormState.js +351 -0
  152. package/lib/schema/getDefaultFormState.js.map +1 -0
  153. package/lib/schema/getDisplayLabel.d.ts +12 -0
  154. package/lib/schema/getDisplayLabel.js +39 -0
  155. package/lib/schema/getDisplayLabel.js.map +1 -0
  156. package/lib/schema/getFirstMatchingOption.d.ts +13 -0
  157. package/lib/schema/getFirstMatchingOption.js +16 -0
  158. package/lib/schema/getFirstMatchingOption.js.map +1 -0
  159. package/lib/schema/getMatchingOption.d.ts +14 -0
  160. package/lib/schema/getMatchingOption.js +80 -0
  161. package/lib/schema/getMatchingOption.js.map +1 -0
  162. package/lib/schema/index.d.ts +14 -0
  163. package/lib/schema/index.js +15 -0
  164. package/lib/schema/index.js.map +1 -0
  165. package/lib/schema/isFilesArray.d.ts +10 -0
  166. package/lib/schema/isFilesArray.js +21 -0
  167. package/lib/schema/isFilesArray.js.map +1 -0
  168. package/lib/schema/isMultiSelect.d.ts +9 -0
  169. package/lib/schema/isMultiSelect.js +15 -0
  170. package/lib/schema/isMultiSelect.js.map +1 -0
  171. package/lib/schema/isSelect.d.ts +9 -0
  172. package/lib/schema/isSelect.js +21 -0
  173. package/lib/schema/isSelect.js.map +1 -0
  174. package/lib/schema/mergeValidationData.d.ts +14 -0
  175. package/lib/schema/mergeValidationData.js +28 -0
  176. package/lib/schema/mergeValidationData.js.map +1 -0
  177. package/lib/schema/retrieveSchema.d.ts +170 -0
  178. package/lib/schema/retrieveSchema.js +437 -0
  179. package/lib/schema/retrieveSchema.js.map +1 -0
  180. package/lib/schema/sanitizeDataForNewSchema.d.ts +49 -0
  181. package/lib/schema/sanitizeDataForNewSchema.js +173 -0
  182. package/lib/schema/sanitizeDataForNewSchema.js.map +1 -0
  183. package/lib/schema/toIdSchema.d.ts +13 -0
  184. package/lib/schema/toIdSchema.js +59 -0
  185. package/lib/schema/toIdSchema.js.map +1 -0
  186. package/lib/schema/toPathSchema.d.ts +11 -0
  187. package/lib/schema/toPathSchema.js +68 -0
  188. package/lib/schema/toPathSchema.js.map +1 -0
  189. package/lib/schemaRequiresTrueValue.d.ts +11 -0
  190. package/lib/schemaRequiresTrueValue.js +34 -0
  191. package/lib/schemaRequiresTrueValue.js.map +1 -0
  192. package/lib/shouldRender.d.ts +10 -0
  193. package/lib/shouldRender.js +14 -0
  194. package/lib/shouldRender.js.map +1 -0
  195. package/lib/toConstant.d.ts +9 -0
  196. package/lib/toConstant.js +18 -0
  197. package/lib/toConstant.js.map +1 -0
  198. package/lib/toDateString.d.ts +9 -0
  199. package/lib/toDateString.js +14 -0
  200. package/lib/toDateString.js.map +1 -0
  201. package/lib/toErrorList.d.ts +8 -0
  202. package/lib/toErrorList.js +34 -0
  203. package/lib/toErrorList.js.map +1 -0
  204. package/lib/toErrorSchema.d.ts +21 -0
  205. package/lib/toErrorSchema.js +41 -0
  206. package/lib/toErrorSchema.js.map +1 -0
  207. package/lib/types.d.ts +982 -0
  208. package/lib/types.js +2 -0
  209. package/lib/types.js.map +1 -0
  210. package/lib/unwrapErrorHandler.d.ts +7 -0
  211. package/lib/unwrapErrorHandler.js +21 -0
  212. package/lib/unwrapErrorHandler.js.map +1 -0
  213. package/lib/utcToLocal.d.ts +6 -0
  214. package/lib/utcToLocal.js +26 -0
  215. package/lib/utcToLocal.js.map +1 -0
  216. package/lib/validationDataMerge.d.ts +11 -0
  217. package/lib/validationDataMerge.js +26 -0
  218. package/lib/validationDataMerge.js.map +1 -0
  219. package/lib/withIdRefPrefix.d.ts +8 -0
  220. package/lib/withIdRefPrefix.js +47 -0
  221. package/lib/withIdRefPrefix.js.map +1 -0
  222. package/package.json +20 -13
  223. package/src/ErrorSchemaBuilder.ts +112 -0
  224. package/src/allowAdditionalItems.ts +15 -0
  225. package/src/asNumber.ts +38 -0
  226. package/src/canExpand.ts +31 -0
  227. package/src/constants.ts +31 -0
  228. package/src/createErrorHandler.ts +33 -0
  229. package/src/createSchemaUtils.ts +298 -0
  230. package/src/dataURItoBlob.ts +42 -0
  231. package/src/deepEquals.ts +19 -0
  232. package/src/englishStringTranslator.ts +14 -0
  233. package/src/enumOptionsDeselectValue.ts +28 -0
  234. package/src/enumOptionsIndexForValue.ts +27 -0
  235. package/src/enumOptionsIsSelected.ts +19 -0
  236. package/src/enumOptionsSelectValue.ts +28 -0
  237. package/src/enumOptionsValueForIndex.ts +26 -0
  238. package/src/enums.ts +74 -0
  239. package/src/findSchemaDefinition.ts +54 -0
  240. package/src/getDiscriminatorFieldFromSchema.ts +21 -0
  241. package/src/getInputProps.ts +55 -0
  242. package/src/getSchemaType.ts +37 -0
  243. package/src/getSubmitButtonOptions.ts +32 -0
  244. package/src/getTemplate.ts +26 -0
  245. package/src/getUiOptions.ts +32 -0
  246. package/src/getWidget.tsx +133 -0
  247. package/src/guessType.ts +28 -0
  248. package/src/hasWidget.ts +27 -0
  249. package/src/hashForSchema.ts +31 -0
  250. package/src/idGenerators.ts +81 -0
  251. package/src/index.ts +118 -0
  252. package/src/isConstant.ts +12 -0
  253. package/src/isCustomWidget.ts +19 -0
  254. package/src/isFixedItems.ts +12 -0
  255. package/src/isObject.ts +15 -0
  256. package/src/labelValue.ts +16 -0
  257. package/src/localToUTC.ts +8 -0
  258. package/src/mergeDefaultsWithFormData.ts +53 -0
  259. package/src/mergeObjects.ts +39 -0
  260. package/src/mergeSchemas.ts +38 -0
  261. package/src/optionsList.ts +41 -0
  262. package/src/orderProperties.ts +44 -0
  263. package/src/pad.ts +13 -0
  264. package/src/parseDateString.ts +33 -0
  265. package/src/parser/ParserValidator.ts +132 -0
  266. package/src/parser/index.ts +6 -0
  267. package/src/parser/schemaParser.ts +60 -0
  268. package/src/rangeSpec.ts +22 -0
  269. package/src/replaceStringParameters.ts +22 -0
  270. package/src/schema/getClosestMatchingOption.ts +191 -0
  271. package/src/schema/getDefaultFormState.ts +447 -0
  272. package/src/schema/getDisplayLabel.ts +59 -0
  273. package/src/schema/getFirstMatchingOption.ts +27 -0
  274. package/src/schema/getMatchingOption.ts +95 -0
  275. package/src/schema/index.ts +29 -0
  276. package/src/schema/isFilesArray.ts +27 -0
  277. package/src/schema/isMultiSelect.ts +21 -0
  278. package/src/schema/isSelect.ts +26 -0
  279. package/src/schema/mergeValidationData.ts +38 -0
  280. package/src/schema/retrieveSchema.ts +614 -0
  281. package/src/schema/sanitizeDataForNewSchema.ts +197 -0
  282. package/src/schema/toIdSchema.ts +105 -0
  283. package/src/schema/toPathSchema.ts +121 -0
  284. package/src/schemaRequiresTrueValue.ts +40 -0
  285. package/src/shouldRender.ts +16 -0
  286. package/src/toConstant.ts +19 -0
  287. package/src/toDateString.ts +15 -0
  288. package/src/toErrorList.ts +41 -0
  289. package/src/toErrorSchema.ts +43 -0
  290. package/src/types.ts +1139 -0
  291. package/src/unwrapErrorHandler.ts +25 -0
  292. package/src/utcToLocal.ts +30 -0
  293. package/src/validationDataMerge.ts +31 -0
  294. package/src/withIdRefPrefix.ts +49 -0
  295. package/dist/index.d.ts +0 -1911
  296. package/dist/utils.cjs.development.js +0 -3522
  297. package/dist/utils.cjs.development.js.map +0 -1
  298. package/dist/utils.cjs.production.min.js +0 -2
  299. package/dist/utils.cjs.production.min.js.map +0 -1
  300. package/dist/utils.umd.development.js +0 -3504
  301. package/dist/utils.umd.development.js.map +0 -1
  302. package/dist/utils.umd.production.min.js +0 -2
  303. package/dist/utils.umd.production.min.js.map +0 -1
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { ErrorSchema, FormValidation } from './types';
2
+ /** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError()` functions from it
3
+ *
4
+ * @param errorHandler - The `FormValidation` error handling structure
5
+ * @returns - The `ErrorSchema` resulting from the stripping of the `addError()` function
6
+ */
7
+ export default function unwrapErrorHandler<T = any>(errorHandler: FormValidation<T>): ErrorSchema<T>;
@@ -0,0 +1,21 @@
1
+ import isPlainObject from 'lodash/isPlainObject';
2
+ /** Unwraps the `errorHandler` structure into the associated `ErrorSchema`, stripping the `addError()` functions from it
3
+ *
4
+ * @param errorHandler - The `FormValidation` error handling structure
5
+ * @returns - The `ErrorSchema` resulting from the stripping of the `addError()` function
6
+ */
7
+ export default function unwrapErrorHandler(errorHandler) {
8
+ return Object.keys(errorHandler).reduce((acc, key) => {
9
+ if (key === 'addError') {
10
+ return acc;
11
+ }
12
+ else {
13
+ const childSchema = errorHandler[key];
14
+ if (isPlainObject(childSchema)) {
15
+ return Object.assign(Object.assign({}, acc), { [key]: unwrapErrorHandler(childSchema) });
16
+ }
17
+ return Object.assign(Object.assign({}, acc), { [key]: childSchema });
18
+ }
19
+ }, {});
20
+ }
21
+ //# sourceMappingURL=unwrapErrorHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unwrapErrorHandler.js","sourceRoot":"","sources":["../src/unwrapErrorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,sBAAsB,CAAC;AAIjD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAU,YAA+B;IACjF,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACnD,IAAI,GAAG,KAAK,UAAU,EAAE;YACtB,OAAO,GAAG,CAAC;SACZ;aAAM;YACL,MAAM,WAAW,GAAI,YAAkC,CAAC,GAAG,CAAC,CAAC;YAC7D,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE;gBAC9B,uCACK,GAAG,KACN,CAAC,GAAG,CAAC,EAAE,kBAAkB,CAAC,WAAW,CAAC,IACtC;aACH;YACD,uCAAY,GAAG,KAAE,CAAC,GAAG,CAAC,EAAE,WAAW,IAAG;SACvC;IACH,CAAC,EAAE,EAAoB,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** Converts a UTC date string into a local Date format
2
+ *
3
+ * @param jsonDate - A UTC date string
4
+ * @returns - An empty string when `jsonDate` is falsey, otherwise a date string in local format
5
+ */
6
+ export default function utcToLocal(jsonDate: string): string;
@@ -0,0 +1,26 @@
1
+ import pad from './pad';
2
+ /** Converts a UTC date string into a local Date format
3
+ *
4
+ * @param jsonDate - A UTC date string
5
+ * @returns - An empty string when `jsonDate` is falsey, otherwise a date string in local format
6
+ */
7
+ export default function utcToLocal(jsonDate) {
8
+ if (!jsonDate) {
9
+ return '';
10
+ }
11
+ // required format of `'yyyy-MM-ddThh:mm' followed by optional ':ss' or ':ss.SSS'
12
+ // https://html.spec.whatwg.org/multipage/input.html#local-date-and-time-state-(type%3Ddatetime-local)
13
+ // > should be a _valid local date and time string_ (not GMT)
14
+ // Note - date constructor passed local ISO-8601 does not correctly
15
+ // change time to UTC in node pre-8
16
+ const date = new Date(jsonDate);
17
+ const yyyy = pad(date.getFullYear(), 4);
18
+ const MM = pad(date.getMonth() + 1, 2);
19
+ const dd = pad(date.getDate(), 2);
20
+ const hh = pad(date.getHours(), 2);
21
+ const mm = pad(date.getMinutes(), 2);
22
+ const ss = pad(date.getSeconds(), 2);
23
+ const SSS = pad(date.getMilliseconds(), 3);
24
+ return `${yyyy}-${MM}-${dd}T${hh}:${mm}:${ss}.${SSS}`;
25
+ }
26
+ //# sourceMappingURL=utcToLocal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utcToLocal.js","sourceRoot":"","sources":["../src/utcToLocal.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAC;AAExB;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,QAAgB;IACjD,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,EAAE,CAAC;KACX;IAED,iFAAiF;IACjF,sGAAsG;IACtG,6DAA6D;IAE7D,mEAAmE;IACnE,mCAAmC;IACnC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;IAEhC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;IACxC,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACvC,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAClC,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC;IACrC,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,CAAC;IAE3C,OAAO,GAAG,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC;AACxD,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { ErrorSchema, ValidationData } from './types';
2
+ /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
3
+ * two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
4
+ * `toErrorList()` on the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
5
+ * `validationData` is returned.
6
+ *
7
+ * @param validationData - The current `ValidationData` into which to merge the additional errors
8
+ * @param [additionalErrorSchema] - The optional additional set of errors in an `ErrorSchema`
9
+ * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
10
+ */
11
+ export default function validationDataMerge<T = any>(validationData: ValidationData<T>, additionalErrorSchema?: ErrorSchema<T>): ValidationData<T>;
@@ -0,0 +1,26 @@
1
+ import isEmpty from 'lodash/isEmpty';
2
+ import mergeObjects from './mergeObjects';
3
+ import toErrorList from './toErrorList';
4
+ /** Merges the errors in `additionalErrorSchema` into the existing `validationData` by combining the hierarchies in the
5
+ * two `ErrorSchema`s and then appending the error list from the `additionalErrorSchema` obtained by calling
6
+ * `toErrorList()` on the `errors` in the `validationData`. If no `additionalErrorSchema` is passed, then
7
+ * `validationData` is returned.
8
+ *
9
+ * @param validationData - The current `ValidationData` into which to merge the additional errors
10
+ * @param [additionalErrorSchema] - The optional additional set of errors in an `ErrorSchema`
11
+ * @returns - The `validationData` with the additional errors from `additionalErrorSchema` merged into it, if provided.
12
+ */
13
+ export default function validationDataMerge(validationData, additionalErrorSchema) {
14
+ if (!additionalErrorSchema) {
15
+ return validationData;
16
+ }
17
+ const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
18
+ let errors = toErrorList(additionalErrorSchema);
19
+ let errorSchema = additionalErrorSchema;
20
+ if (!isEmpty(oldErrorSchema)) {
21
+ errorSchema = mergeObjects(oldErrorSchema, additionalErrorSchema, true);
22
+ errors = [...oldErrors].concat(errors);
23
+ }
24
+ return { errorSchema, errors };
25
+ }
26
+ //# sourceMappingURL=validationDataMerge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validationDataMerge.js","sourceRoot":"","sources":["../src/validationDataMerge.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,WAAW,MAAM,eAAe,CAAC;AAGxC;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,cAAiC,EACjC,qBAAsC;IAEtC,IAAI,CAAC,qBAAqB,EAAE;QAC1B,OAAO,cAAc,CAAC;KACvB;IACD,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,cAAc,CAAC;IAC1E,IAAI,MAAM,GAAG,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAChD,IAAI,WAAW,GAAG,qBAAqB,CAAC;IACxC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;QAC5B,WAAW,GAAG,YAAY,CAAC,cAAc,EAAE,qBAAqB,EAAE,IAAI,CAAmB,CAAC;QAC1F,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KACxC;IACD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACjC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { RJSFSchema, StrictRJSFSchema } from './types';
2
+ /** Recursively prefixes all `$ref`s in a schema with the value of the `ROOT_SCHEMA_PREFIX` constant.
3
+ * This is used in isValid to make references to the rootSchema
4
+ *
5
+ * @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
6
+ * @returns - A copy of the `schemaNode` with updated `$ref`s
7
+ */
8
+ export default function withIdRefPrefix<S extends StrictRJSFSchema = RJSFSchema>(schemaNode: S): S | S[];
@@ -0,0 +1,47 @@
1
+ import { REF_KEY, ROOT_SCHEMA_PREFIX } from './constants';
2
+ import isObject from 'lodash/isObject';
3
+ /** Takes a `node` object and transforms any contained `$ref` node variables with a prefix, recursively calling
4
+ * `withIdRefPrefix` for any other elements.
5
+ *
6
+ * @param node - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
7
+ */
8
+ function withIdRefPrefixObject(node) {
9
+ for (const key in node) {
10
+ const realObj = node;
11
+ const value = realObj[key];
12
+ if (key === REF_KEY && typeof value === 'string' && value.startsWith('#')) {
13
+ realObj[key] = ROOT_SCHEMA_PREFIX + value;
14
+ }
15
+ else {
16
+ realObj[key] = withIdRefPrefix(value);
17
+ }
18
+ }
19
+ return node;
20
+ }
21
+ /** Takes a `node` object list and transforms any contained `$ref` node variables with a prefix, recursively calling
22
+ * `withIdRefPrefix` for any other elements.
23
+ *
24
+ * @param node - The list of object nodes to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
25
+ */
26
+ function withIdRefPrefixArray(node) {
27
+ for (let i = 0; i < node.length; i++) {
28
+ node[i] = withIdRefPrefix(node[i]);
29
+ }
30
+ return node;
31
+ }
32
+ /** Recursively prefixes all `$ref`s in a schema with the value of the `ROOT_SCHEMA_PREFIX` constant.
33
+ * This is used in isValid to make references to the rootSchema
34
+ *
35
+ * @param schemaNode - The object node to which a ROOT_SCHEMA_PREFIX is added when a REF_KEY is part of it
36
+ * @returns - A copy of the `schemaNode` with updated `$ref`s
37
+ */
38
+ export default function withIdRefPrefix(schemaNode) {
39
+ if (Array.isArray(schemaNode)) {
40
+ return withIdRefPrefixArray([...schemaNode]);
41
+ }
42
+ if (isObject(schemaNode)) {
43
+ return withIdRefPrefixObject(Object.assign({}, schemaNode));
44
+ }
45
+ return schemaNode;
46
+ }
47
+ //# sourceMappingURL=withIdRefPrefix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withIdRefPrefix.js","sourceRoot":"","sources":["../src/withIdRefPrefix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAEvC;;;;GAIG;AACH,SAAS,qBAAqB,CAA0C,IAAO;IAC7E,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;QACtB,MAAM,OAAO,GAAyB,IAAI,CAAC;QAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,GAAG,KAAK,OAAO,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YACzE,OAAO,CAAC,GAAG,CAAC,GAAG,kBAAkB,GAAG,KAAK,CAAC;SAC3C;aAAM;YACL,OAAO,CAAC,GAAG,CAAC,GAAG,eAAe,CAAI,KAAK,CAAC,CAAC;SAC1C;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAA0C,IAAS;IAC9E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACpC,IAAI,CAAC,CAAC,CAAC,GAAG,eAAe,CAAI,IAAI,CAAC,CAAC,CAAC,CAAM,CAAC;KAC5C;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAA0C,UAAa;IAC5F,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QAC7B,OAAO,oBAAoB,CAAI,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;KACjD;IACD,IAAI,QAAQ,CAAC,UAAU,CAAC,EAAE;QACxB,OAAO,qBAAqB,mBAAS,UAAU,EAAG,CAAC;KACpD;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
package/package.json CHANGED
@@ -1,19 +1,25 @@
1
1
  {
2
2
  "name": "@rjsf/utils",
3
- "version": "5.11.2",
3
+ "version": "5.12.0",
4
4
  "main": "dist/index.js",
5
- "module": "dist/utils.esm.js",
6
- "typings": "dist/index.d.ts",
5
+ "module": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
7
  "description": "Utility functions for @rjsf/core",
8
8
  "files": [
9
- "dist"
9
+ "dist",
10
+ "lib",
11
+ "src"
10
12
  ],
11
13
  "engineStrict": false,
12
14
  "engines": {
13
15
  "node": ">=14"
14
16
  },
15
17
  "scripts": {
16
- "build": "rimraf dist && dts build --rollupTypes --format cjs,esm,umd",
18
+ "build:ts": "rimraf lib && tsc",
19
+ "build:cjs": "esbuild ./src/index.ts --bundle --outfile=dist/index.js --sourcemap --packages=external --format=cjs",
20
+ "build:esm": "esbuild ./src/index.ts --bundle --outfile=dist/utils.esm.js --sourcemap --packages=external --format=esm",
21
+ "build:umd": "rollup dist/utils.esm.js --format=umd --file=dist/utils.umd.js --name=@rjsf/utils",
22
+ "build": "rimraf dist && npm run build:ts && npm run build:cjs && npm run build:esm && npm run build:umd",
17
23
  "cs-check": "prettier -l \"{src,test}/**/*.ts?(x)\"",
18
24
  "cs-format": "prettier \"{src,test}/**/*.ts?(x)\" --write",
19
25
  "lint": "eslint src test",
@@ -46,20 +52,21 @@
46
52
  "@babel/preset-typescript": "^7.22.5",
47
53
  "@types/json-schema": "^7.0.12",
48
54
  "@types/json-schema-merge-allof": "^0.6.1",
49
- "@types/lodash": "^4.14.195",
55
+ "@types/lodash": "^4.14.196",
50
56
  "@types/react": "^17.0.62",
51
57
  "@types/react-is": "^17.0.4",
52
58
  "@types/react-test-renderer": "^17.0.2",
53
- "babel-jest": "^29.6.1",
59
+ "babel-jest": "^29.6.2",
54
60
  "deep-freeze-es6": "^1.4.1",
55
- "dts-cli": "^1.6.3",
56
- "eslint": "^8.44.0",
57
- "jest": "^29.6.1",
61
+ "esbuild": "^0.18.19",
62
+ "eslint": "^8.46.0",
63
+ "jest": "^29.6.2",
58
64
  "jest-environment-jsdom": "^29.6.1",
59
- "jest-expect-message": "^1.1.3",
60
65
  "react": "^17.0.2",
61
66
  "react-test-renderer": "^17.0.2",
62
- "rimraf": "^5.0.1"
67
+ "rimraf": "^5.0.1",
68
+ "rollup": "^3.27.2",
69
+ "typescript": "^4.9.5"
63
70
  },
64
71
  "publishConfig": {
65
72
  "access": "public"
@@ -79,5 +86,5 @@
79
86
  "url": "git+https://github.com/rjsf-team/react-jsonschema-form.git"
80
87
  },
81
88
  "license": "Apache-2.0",
82
- "gitHead": "2fafced84e18aa2cd487715d11d2730cd23333f3"
89
+ "gitHead": "bab797c43a34e5ec68a84b2bdabb3c377e46b092"
83
90
  }
@@ -0,0 +1,112 @@
1
+ import cloneDeep from 'lodash/cloneDeep';
2
+ import get from 'lodash/get';
3
+ import set from 'lodash/set';
4
+
5
+ import { ErrorSchema } from './types';
6
+ import { ERRORS_KEY } from './constants';
7
+
8
+ /** The `ErrorSchemaBuilder<T>` is used to build an `ErrorSchema<T>` since the definition of the `ErrorSchema` type is
9
+ * designed for reading information rather than writing it. Use this class to add, replace or clear errors in an error
10
+ * schema by using either dotted path or an array of path names. Once you are done building the `ErrorSchema`, you can
11
+ * get the result and/or reset all the errors back to an initial set and start again.
12
+ */
13
+ export default class ErrorSchemaBuilder<T = any> {
14
+ /** The error schema being built
15
+ *
16
+ * @private
17
+ */
18
+ private errorSchema: ErrorSchema<T> = {};
19
+
20
+ /** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
21
+ *
22
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
23
+ */
24
+ constructor(initialSchema?: ErrorSchema<T>) {
25
+ this.resetAllErrors(initialSchema);
26
+ }
27
+
28
+ /** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
29
+ */
30
+ get ErrorSchema() {
31
+ return this.errorSchema;
32
+ }
33
+
34
+ /** Will get an existing `ErrorSchema` at the specified `pathOfError` or create and return one.
35
+ *
36
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
37
+ * @returns - The error block for the given `pathOfError` or the root if not provided
38
+ * @private
39
+ */
40
+ private getOrCreateErrorBlock(pathOfError?: string | string[]) {
41
+ const hasPath = (Array.isArray(pathOfError) && pathOfError.length > 0) || typeof pathOfError === 'string';
42
+ let errorBlock: ErrorSchema = hasPath ? get(this.errorSchema, pathOfError) : this.errorSchema;
43
+ if (!errorBlock && pathOfError) {
44
+ errorBlock = {};
45
+ set(this.errorSchema, pathOfError, errorBlock);
46
+ }
47
+ return errorBlock;
48
+ }
49
+
50
+ /** Resets all errors in the `ErrorSchemaBuilder` back to the `initialSchema` if provided, otherwise an empty set.
51
+ *
52
+ * @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
53
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
54
+ */
55
+ resetAllErrors(initialSchema?: ErrorSchema<T>) {
56
+ this.errorSchema = initialSchema ? cloneDeep(initialSchema) : {};
57
+ return this;
58
+ }
59
+
60
+ /** Adds the `errorOrList` to the list of errors in the `ErrorSchema` at either the root level or the location within
61
+ * the schema described by the `pathOfError`. For more information about how to specify the path see the
62
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
63
+ *
64
+ * @param errorOrList - The error or list of errors to add into the `ErrorSchema`
65
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
66
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
67
+ */
68
+ addErrors(errorOrList: string | string[], pathOfError?: string | string[]) {
69
+ const errorBlock: ErrorSchema = this.getOrCreateErrorBlock(pathOfError);
70
+ let errorsList = get(errorBlock, ERRORS_KEY);
71
+ if (!Array.isArray(errorsList)) {
72
+ errorsList = [];
73
+ errorBlock[ERRORS_KEY] = errorsList;
74
+ }
75
+
76
+ if (Array.isArray(errorOrList)) {
77
+ errorsList.push(...errorOrList);
78
+ } else {
79
+ errorsList.push(errorOrList);
80
+ }
81
+ return this;
82
+ }
83
+
84
+ /** Sets/replaces the `errorOrList` as the error(s) in the `ErrorSchema` at either the root level or the location
85
+ * within the schema described by the `pathOfError`. For more information about how to specify the path see the
86
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
87
+ *
88
+ * @param errorOrList - The error or list of errors to set into the `ErrorSchema`
89
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
90
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
91
+ */
92
+ setErrors(errorOrList: string | string[], pathOfError?: string | string[]) {
93
+ const errorBlock: ErrorSchema = this.getOrCreateErrorBlock(pathOfError);
94
+ // Effectively clone the array being given to prevent accidental outside manipulation of the given list
95
+ const listToAdd = Array.isArray(errorOrList) ? [...errorOrList] : [errorOrList];
96
+ set(errorBlock, ERRORS_KEY, listToAdd);
97
+ return this;
98
+ }
99
+
100
+ /** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
101
+ * the `pathOfError`. For more information about how to specify the path see the
102
+ * [eslint lodash plugin docs](https://github.com/wix/eslint-plugin-lodash/blob/master/docs/rules/path-style.md).
103
+ *
104
+ * @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
105
+ * @returns - The `ErrorSchemaBuilder` object for chaining purposes
106
+ */
107
+ clearErrors(pathOfError?: string | string[]) {
108
+ const errorBlock: ErrorSchema = this.getOrCreateErrorBlock(pathOfError);
109
+ set(errorBlock, ERRORS_KEY, []);
110
+ return this;
111
+ }
112
+ }
@@ -0,0 +1,15 @@
1
+ import isObject from './isObject';
2
+ import { RJSFSchema, StrictRJSFSchema } from './types';
3
+
4
+ /** Checks the schema to see if it is allowing additional items, by verifying that `schema.additionalItems` is an
5
+ * object. The user is warned in the console if `schema.additionalItems` has the value `true`.
6
+ *
7
+ * @param schema - The schema object to check
8
+ * @returns - True if additional items is allowed, otherwise false
9
+ */
10
+ export default function allowAdditionalItems<S extends StrictRJSFSchema = RJSFSchema>(schema: S) {
11
+ if (schema.additionalItems === true) {
12
+ console.warn('additionalItems=true is currently not supported');
13
+ }
14
+ return isObject(schema.additionalItems);
15
+ }
@@ -0,0 +1,38 @@
1
+ /** Attempts to convert the string into a number. If an empty string is provided, then `undefined` is returned. If a
2
+ * `null` is provided, it is returned. If the string ends in a `.` then the string is returned because the user may be
3
+ * in the middle of typing a float number. If a number ends in a pattern like `.0`, `.20`, `.030`, string is returned
4
+ * because the user may be typing number that will end in a non-zero digit. Otherwise, the string is wrapped by
5
+ * `Number()` and if that result is not `NaN`, that number will be returned, otherwise the string `value` will be.
6
+ *
7
+ * @param value - The string or null value to convert to a number
8
+ * @returns - The `value` converted to a number when appropriate, otherwise the `value`
9
+ */
10
+ export default function asNumber(value: string | null) {
11
+ if (value === '') {
12
+ return undefined;
13
+ }
14
+ if (value === null) {
15
+ return null;
16
+ }
17
+ if (/\.$/.test(value)) {
18
+ // '3.' can't really be considered a number even if it parses in js. The
19
+ // user is most likely entering a float.
20
+ return value;
21
+ }
22
+ if (/\.0$/.test(value)) {
23
+ // we need to return this as a string here, to allow for input like 3.07
24
+ return value;
25
+ }
26
+
27
+ if (/\.\d*0$/.test(value)) {
28
+ // It's a number, that's cool - but we need it as a string so it doesn't screw
29
+ // with the user when entering dollar amounts or other values (such as those with
30
+ // specific precision or number of significant digits)
31
+ return value;
32
+ }
33
+
34
+ const n = Number(value);
35
+ const valid = typeof n === 'number' && !Number.isNaN(n);
36
+
37
+ return valid ? n : value;
38
+ }
@@ -0,0 +1,31 @@
1
+ import { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema } from './types';
2
+ import getUiOptions from './getUiOptions';
3
+
4
+ /** Checks whether the field described by `schema`, having the `uiSchema` and `formData` supports expanding. The UI for
5
+ * the field can expand if it has additional properties, is not forced as non-expandable by the `uiSchema` and the
6
+ * `formData` object doesn't already have `schema.maxProperties` elements.
7
+ *
8
+ * @param schema - The schema for the field that is being checked
9
+ * @param [uiSchema={}] - The uiSchema for the field
10
+ * @param [formData] - The formData for the field
11
+ * @returns - True if the schema element has additionalProperties, is expandable, and not at the maxProperties limit
12
+ */
13
+ export default function canExpand<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
14
+ schema: RJSFSchema,
15
+ uiSchema: UiSchema<T, S, F> = {},
16
+ formData?: T
17
+ ) {
18
+ if (!schema.additionalProperties) {
19
+ return false;
20
+ }
21
+ const { expandable = true } = getUiOptions<T, S, F>(uiSchema);
22
+ if (expandable === false) {
23
+ return expandable;
24
+ }
25
+ // if ui:options.expandable was not explicitly set to false, we can add
26
+ // another property if we have not exceeded maxProperties yet
27
+ if (schema.maxProperties !== undefined && formData) {
28
+ return Object.keys(formData).length < schema.maxProperties;
29
+ }
30
+ return true;
31
+ }
@@ -0,0 +1,31 @@
1
+ /** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various
2
+ * utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG` and
3
+ * `RJSF_ADDITONAL_PROPERTIES_FLAG` flags that is added to a schema under certain conditions by the `retrieveSchema()`
4
+ * utility.
5
+ */
6
+ export const ADDITIONAL_PROPERTY_FLAG = '__additional_property';
7
+ export const ADDITIONAL_PROPERTIES_KEY = 'additionalProperties';
8
+ export const ALL_OF_KEY = 'allOf';
9
+ export const ANY_OF_KEY = 'anyOf';
10
+ export const CONST_KEY = 'const';
11
+ export const DEFAULT_KEY = 'default';
12
+ export const DEFINITIONS_KEY = 'definitions';
13
+ export const DEPENDENCIES_KEY = 'dependencies';
14
+ export const ENUM_KEY = 'enum';
15
+ export const ERRORS_KEY = '__errors';
16
+ export const ID_KEY = '$id';
17
+ export const IF_KEY = 'if';
18
+ export const ITEMS_KEY = 'items';
19
+ export const JUNK_OPTION_ID = '_$junk_option_schema_id$_';
20
+ export const NAME_KEY = '$name';
21
+ export const ONE_OF_KEY = 'oneOf';
22
+ export const PROPERTIES_KEY = 'properties';
23
+ export const REQUIRED_KEY = 'required';
24
+ export const SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions';
25
+ export const REF_KEY = '$ref';
26
+ export const RJSF_ADDITONAL_PROPERTIES_FLAG = '__rjsf_additionalProperties';
27
+ export const ROOT_SCHEMA_PREFIX = '__rjsf_rootSchema';
28
+ export const UI_FIELD_KEY = 'ui:field';
29
+ export const UI_WIDGET_KEY = 'ui:widget';
30
+ export const UI_OPTIONS_KEY = 'ui:options';
31
+ export const UI_GLOBAL_OPTIONS_KEY = 'ui:globalOptions';
@@ -0,0 +1,33 @@
1
+ import isPlainObject from 'lodash/isPlainObject';
2
+
3
+ import { ERRORS_KEY } from './constants';
4
+ import { FieldValidation, FormValidation, GenericObjectType } from './types';
5
+
6
+ /** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it
7
+ *
8
+ * @param formData - The form data around which the error handler is created
9
+ * @returns - A `FormValidation` object based on the `formData` structure
10
+ */
11
+ export default function createErrorHandler<T = any>(formData: T): FormValidation<T> {
12
+ const handler: FieldValidation = {
13
+ // We store the list of errors for this node in a property named __errors
14
+ // to avoid name collision with a possible sub schema field named
15
+ // 'errors' (see `utils.toErrorSchema`).
16
+ [ERRORS_KEY]: [],
17
+ addError(message: string) {
18
+ this[ERRORS_KEY]!.push(message);
19
+ },
20
+ };
21
+ if (Array.isArray(formData)) {
22
+ return formData.reduce((acc, value, key) => {
23
+ return { ...acc, [key]: createErrorHandler(value) };
24
+ }, handler);
25
+ }
26
+ if (isPlainObject(formData)) {
27
+ const formObject: GenericObjectType = formData as GenericObjectType;
28
+ return Object.keys(formObject).reduce((acc, key) => {
29
+ return { ...acc, [key]: createErrorHandler(formObject[key]) };
30
+ }, handler as FormValidation<T>);
31
+ }
32
+ return handler as FormValidation<T>;
33
+ }