@rjsf/utils 5.11.2 → 5.12.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 (303) hide show
  1. package/dist/index.js +2545 -5
  2. package/dist/index.js.map +7 -0
  3. package/dist/utils.esm.js +1230 -2114
  4. package/dist/utils.esm.js.map +7 -1
  5. package/dist/utils.umd.js +2415 -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 +438 -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 +615 -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
@@ -0,0 +1,173 @@
1
+ import get from 'lodash/get';
2
+ import has from 'lodash/has';
3
+ import { PROPERTIES_KEY, REF_KEY } from '../constants';
4
+ import retrieveSchema from './retrieveSchema';
5
+ const NO_VALUE = Symbol('no Value');
6
+ /** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the new
7
+ * schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the nature
8
+ * of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the old schema
9
+ * that are non-existent in the new schema are set to `undefined`. The data sanitization process has the following flow:
10
+ *
11
+ * - If the new schema is an object that contains a `properties` object then:
12
+ * - Create a `removeOldSchemaData` object, setting each key in the `oldSchema.properties` having `data` to undefined
13
+ * - Create an empty `nestedData` object for use in the key filtering below:
14
+ * - Iterate over each key in the `newSchema.properties` as follows:
15
+ * - Get the `formValue` of the key from the `data`
16
+ * - Get the `oldKeySchema` and `newKeyedSchema` for the key, defaulting to `{}` when it doesn't exist
17
+ * - Retrieve the schema for any refs within each `oldKeySchema` and/or `newKeySchema`
18
+ * - Get the types of the old and new keyed schemas and if the old doesn't exist or the old & new are the same then:
19
+ * - If `removeOldSchemaData` has an entry for the key, delete it since the new schema has the same property
20
+ * - If type of the key in the new schema is `object`:
21
+ * - Store the value from the recursive `sanitizeDataForNewSchema` call in `nestedData[key]`
22
+ * - Otherwise, check for default or const values:
23
+ * - Get the old and new `default` values from the schema and check:
24
+ * - If the new `default` value does not match the form value:
25
+ * - If the old `default` value DOES match the form value, then:
26
+ * - Replace `removeOldSchemaData[key]` with the new `default`
27
+ * - Otherwise, if the new schema is `readOnly` then replace `removeOldSchemaData[key]` with undefined
28
+ * - Get the old and new `const` values from the schema and check:
29
+ * - If the new `const` value does not match the form value:
30
+ * - If the old `const` value DOES match the form value, then:
31
+ * - Replace `removeOldSchemaData[key]` with the new `const`
32
+ * - Otherwise, replace `removeOldSchemaData[key]` with undefined
33
+ * - Once all keys have been processed, return an object built as follows:
34
+ * - `{ ...removeOldSchemaData, ...nestedData, ...pick(data, keysToKeep) }`
35
+ * - If the new and old schema types are array and the `data` is an array then:
36
+ * - If the type of the old and new schema `items` are a non-array objects:
37
+ * - Retrieve the schema for any refs within each `oldKeySchema.items` and/or `newKeySchema.items`
38
+ * - If the `type`s of both items are the same (or the old does not have a type):
39
+ * - If the type is "object", then:
40
+ * - For each element in the `data` recursively sanitize the data, stopping at `maxItems` if specified
41
+ * - Otherwise, just return the `data` removing any values after `maxItems` if it is set
42
+ * - If the type of the old and new schema `items` are booleans of the same value, return `data` as is
43
+ * - Otherwise return `undefined`
44
+ *
45
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
46
+ * @param rootSchema - The root JSON schema of the entire form
47
+ * @param [newSchema] - The new schema for which the data is being sanitized
48
+ * @param [oldSchema] - The old schema from which the data originated
49
+ * @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
50
+ * @returns - The new form data, with all the fields uniquely associated with the old schema set
51
+ * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
52
+ */
53
+ export default function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {
54
+ // By default, we will clear the form data
55
+ let newFormData;
56
+ // If the new schema is of type object and that object contains a list of properties
57
+ if (has(newSchema, PROPERTIES_KEY)) {
58
+ // Create an object containing root-level keys in the old schema, setting each key to undefined to remove the data
59
+ const removeOldSchemaData = {};
60
+ if (has(oldSchema, PROPERTIES_KEY)) {
61
+ const properties = get(oldSchema, PROPERTIES_KEY, {});
62
+ Object.keys(properties).forEach((key) => {
63
+ if (has(data, key)) {
64
+ removeOldSchemaData[key] = undefined;
65
+ }
66
+ });
67
+ }
68
+ const keys = Object.keys(get(newSchema, PROPERTIES_KEY, {}));
69
+ // Create a place to store nested data that will be a side-effect of the filter
70
+ const nestedData = {};
71
+ keys.forEach((key) => {
72
+ const formValue = get(data, key);
73
+ let oldKeyedSchema = get(oldSchema, [PROPERTIES_KEY, key], {});
74
+ let newKeyedSchema = get(newSchema, [PROPERTIES_KEY, key], {});
75
+ // Resolve the refs if they exist
76
+ if (has(oldKeyedSchema, REF_KEY)) {
77
+ oldKeyedSchema = retrieveSchema(validator, oldKeyedSchema, rootSchema, formValue);
78
+ }
79
+ if (has(newKeyedSchema, REF_KEY)) {
80
+ newKeyedSchema = retrieveSchema(validator, newKeyedSchema, rootSchema, formValue);
81
+ }
82
+ // Now get types and see if they are the same
83
+ const oldSchemaTypeForKey = get(oldKeyedSchema, 'type');
84
+ const newSchemaTypeForKey = get(newKeyedSchema, 'type');
85
+ // Check if the old option has the same key with the same type
86
+ if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
87
+ if (has(removeOldSchemaData, key)) {
88
+ // SIDE-EFFECT: remove the undefined value for a key that has the same type between the old and new schemas
89
+ delete removeOldSchemaData[key];
90
+ }
91
+ // If it is an object, we'll recurse and store the resulting sanitized data for the key
92
+ if (newSchemaTypeForKey === 'object' || (newSchemaTypeForKey === 'array' && Array.isArray(formValue))) {
93
+ // SIDE-EFFECT: process the new schema type of object recursively to save iterations
94
+ const itemData = sanitizeDataForNewSchema(validator, rootSchema, newKeyedSchema, oldKeyedSchema, formValue);
95
+ if (itemData !== undefined || newSchemaTypeForKey === 'array') {
96
+ // only put undefined values for the array type and not the object type
97
+ nestedData[key] = itemData;
98
+ }
99
+ }
100
+ else {
101
+ // Ok, the non-object types match, let's make sure that a default or a const of a different value is replaced
102
+ // with the new default or const. This allows the case where two schemas differ that only by the default/const
103
+ // value to be properly selected
104
+ const newOptionDefault = get(newKeyedSchema, 'default', NO_VALUE);
105
+ const oldOptionDefault = get(oldKeyedSchema, 'default', NO_VALUE);
106
+ if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
107
+ if (oldOptionDefault === formValue) {
108
+ // If the old default matches the formValue, we'll update the new value to match the new default
109
+ removeOldSchemaData[key] = newOptionDefault;
110
+ }
111
+ else if (get(newKeyedSchema, 'readOnly') === true) {
112
+ // If the new schema has the default set to read-only, treat it like a const and remove the value
113
+ removeOldSchemaData[key] = undefined;
114
+ }
115
+ }
116
+ const newOptionConst = get(newKeyedSchema, 'const', NO_VALUE);
117
+ const oldOptionConst = get(oldKeyedSchema, 'const', NO_VALUE);
118
+ if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
119
+ // Since this is a const, if the old value matches, replace the value with the new const otherwise clear it
120
+ removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : undefined;
121
+ }
122
+ }
123
+ }
124
+ });
125
+ newFormData = Object.assign(Object.assign(Object.assign({}, data), removeOldSchemaData), nestedData);
126
+ // First apply removing the old schema data, then apply the nested data, then apply the old data keys to keep
127
+ }
128
+ else if (get(oldSchema, 'type') === 'array' && get(newSchema, 'type') === 'array' && Array.isArray(data)) {
129
+ let oldSchemaItems = get(oldSchema, 'items');
130
+ let newSchemaItems = get(newSchema, 'items');
131
+ // If any of the array types `items` are arrays (remember arrays are objects) then we'll just drop the data
132
+ // Eventually, we may want to deal with when either of the `items` are arrays since those tuple validations
133
+ if (typeof oldSchemaItems === 'object' &&
134
+ typeof newSchemaItems === 'object' &&
135
+ !Array.isArray(oldSchemaItems) &&
136
+ !Array.isArray(newSchemaItems)) {
137
+ if (has(oldSchemaItems, REF_KEY)) {
138
+ oldSchemaItems = retrieveSchema(validator, oldSchemaItems, rootSchema, data);
139
+ }
140
+ if (has(newSchemaItems, REF_KEY)) {
141
+ newSchemaItems = retrieveSchema(validator, newSchemaItems, rootSchema, data);
142
+ }
143
+ // Now get types and see if they are the same
144
+ const oldSchemaType = get(oldSchemaItems, 'type');
145
+ const newSchemaType = get(newSchemaItems, 'type');
146
+ // Check if the old option has the same key with the same type
147
+ if (!oldSchemaType || oldSchemaType === newSchemaType) {
148
+ const maxItems = get(newSchema, 'maxItems', -1);
149
+ if (newSchemaType === 'object') {
150
+ newFormData = data.reduce((newValue, aValue) => {
151
+ const itemValue = sanitizeDataForNewSchema(validator, rootSchema, newSchemaItems, oldSchemaItems, aValue);
152
+ if (itemValue !== undefined && (maxItems < 0 || newValue.length < maxItems)) {
153
+ newValue.push(itemValue);
154
+ }
155
+ return newValue;
156
+ }, []);
157
+ }
158
+ else {
159
+ newFormData = maxItems > 0 && data.length > maxItems ? data.slice(0, maxItems) : data;
160
+ }
161
+ }
162
+ }
163
+ else if (typeof oldSchemaItems === 'boolean' &&
164
+ typeof newSchemaItems === 'boolean' &&
165
+ oldSchemaItems === newSchemaItems) {
166
+ // If they are both booleans and have the same value just return the data as is otherwise fall-thru to undefined
167
+ newFormData = data;
168
+ }
169
+ // Also probably want to deal with `prefixItems` as tuples with the latest 2020 draft
170
+ }
171
+ return newFormData;
172
+ }
173
+ //# sourceMappingURL=sanitizeDataForNewSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitizeDataForNewSchema.js","sourceRoot":"","sources":["../../src/schema/sanitizeDataForNewSchema.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,GAAG,MAAM,YAAY,CAAC;AAG7B,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAEpC;;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C,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;iBACvF;aACF;SACF;aAAM,IACL,OAAO,cAAc,KAAK,SAAS;YACnC,OAAO,cAAc,KAAK,SAAS;YACnC,cAAc,KAAK,cAAc,EACjC;YACA,gHAAgH;YAChH,WAAW,GAAG,IAAI,CAAC;SACpB;QACD,qFAAqF;KACtF;IACD,OAAO,WAAgB,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { FormContextType, IdSchema, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
2
+ /** Generates an `IdSchema` object for the `schema`, recursively
3
+ *
4
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
5
+ * @param schema - The schema for which the `IdSchema` is desired
6
+ * @param [id] - The base id for the schema
7
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
8
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
9
+ * @param [idPrefix='root'] - The prefix to use for the id
10
+ * @param [idSeparator='_'] - The separator to use for the path segments in the id
11
+ * @returns - The `IdSchema` object for the `schema`
12
+ */
13
+ export default function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, id?: string | null, rootSchema?: S, formData?: T, idPrefix?: string, idSeparator?: string): IdSchema<T>;
@@ -0,0 +1,59 @@
1
+ import get from 'lodash/get';
2
+ import isEqual from 'lodash/isEqual';
3
+ import { ALL_OF_KEY, DEPENDENCIES_KEY, ID_KEY, ITEMS_KEY, PROPERTIES_KEY, REF_KEY } from '../constants';
4
+ import isObject from '../isObject';
5
+ import retrieveSchema from './retrieveSchema';
6
+ import getSchemaType from '../getSchemaType';
7
+ /** An internal helper that generates an `IdSchema` object for the `schema`, recursively with protection against
8
+ * infinite recursion
9
+ *
10
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
11
+ * @param schema - The schema for which the `IdSchema` is desired
12
+ * @param idPrefix - The prefix to use for the id
13
+ * @param idSeparator - The separator to use for the path segments in the id
14
+ * @param [id] - The base id for the schema
15
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
16
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
17
+ * @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
18
+ * @returns - The `IdSchema` object for the `schema`
19
+ */
20
+ function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = []) {
21
+ if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
22
+ const _schema = retrieveSchema(validator, schema, rootSchema, formData);
23
+ const sameSchemaIndex = _recurseList.findIndex((item) => isEqual(item, _schema));
24
+ if (sameSchemaIndex === -1) {
25
+ return toIdSchemaInternal(validator, _schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList.concat(_schema));
26
+ }
27
+ }
28
+ if (ITEMS_KEY in schema && !get(schema, [ITEMS_KEY, REF_KEY])) {
29
+ return toIdSchemaInternal(validator, get(schema, ITEMS_KEY), idPrefix, idSeparator, id, rootSchema, formData, _recurseList);
30
+ }
31
+ const $id = id || idPrefix;
32
+ const idSchema = { $id };
33
+ if (getSchemaType(schema) === 'object' && PROPERTIES_KEY in schema) {
34
+ for (const name in schema.properties) {
35
+ const field = get(schema, [PROPERTIES_KEY, name]);
36
+ const fieldId = idSchema[ID_KEY] + idSeparator + name;
37
+ idSchema[name] = toIdSchemaInternal(validator, isObject(field) ? field : {}, idPrefix, idSeparator, fieldId, rootSchema,
38
+ // It's possible that formData is not an object -- this can happen if an
39
+ // array item has just been added, but not populated with data yet
40
+ get(formData, [name]), _recurseList);
41
+ }
42
+ }
43
+ return idSchema;
44
+ }
45
+ /** Generates an `IdSchema` object for the `schema`, recursively
46
+ *
47
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
48
+ * @param schema - The schema for which the `IdSchema` is desired
49
+ * @param [id] - The base id for the schema
50
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
51
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
52
+ * @param [idPrefix='root'] - The prefix to use for the id
53
+ * @param [idSeparator='_'] - The separator to use for the path segments in the id
54
+ * @returns - The `IdSchema` object for the `schema`
55
+ */
56
+ export default function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = 'root', idSeparator = '_') {
57
+ return toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData);
58
+ }
59
+ //# sourceMappingURL=toIdSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toIdSchema.js","sourceRoot":"","sources":["../../src/schema/toIdSchema.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACxG,OAAO,QAAQ,MAAM,aAAa,CAAC;AAEnC,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACH,SAAS,kBAAkB,CACzB,SAAiC,EACjC,MAAS,EACT,QAAgB,EAChB,WAAmB,EACnB,EAAkB,EAClB,UAAc,EACd,QAAY,EACZ,eAAoB,EAAE;IAEtB,IAAI,OAAO,IAAI,MAAM,IAAI,gBAAgB,IAAI,MAAM,IAAI,UAAU,IAAI,MAAM,EAAE;QAC3E,MAAM,OAAO,GAAG,cAAc,CAAU,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;QACjF,MAAM,eAAe,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QACjF,IAAI,eAAe,KAAK,CAAC,CAAC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,CAChC,SAAiC,EACjC,MAAS,EACT,EAAkB,EAClB,UAAc,EACd,QAAY,EACZ,QAAQ,GAAG,MAAM,EACjB,WAAW,GAAG,GAAG;IAEjB,OAAO,kBAAkB,CAAU,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AACzG,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { FormContextType, PathSchema, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
2
+ /** Generates an `PathSchema` object for the `schema`, recursively
3
+ *
4
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
5
+ * @param schema - The schema for which the `PathSchema` is desired
6
+ * @param [name=''] - The base name for the schema
7
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
8
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
9
+ * @returns - The `PathSchema` object for the `schema`
10
+ */
11
+ export default function toPathSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, name?: string, rootSchema?: S, formData?: T): PathSchema<T>;
@@ -0,0 +1,68 @@
1
+ import get from 'lodash/get';
2
+ import isEqual from 'lodash/isEqual';
3
+ import set from 'lodash/set';
4
+ import { ALL_OF_KEY, ANY_OF_KEY, ADDITIONAL_PROPERTIES_KEY, DEPENDENCIES_KEY, ITEMS_KEY, NAME_KEY, ONE_OF_KEY, PROPERTIES_KEY, REF_KEY, RJSF_ADDITONAL_PROPERTIES_FLAG, } from '../constants';
5
+ import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
6
+ import getClosestMatchingOption from './getClosestMatchingOption';
7
+ import retrieveSchema from './retrieveSchema';
8
+ /** An internal helper that generates an `PathSchema` object for the `schema`, recursively with protection against
9
+ * infinite recursion
10
+ *
11
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
12
+ * @param schema - The schema for which the `PathSchema` is desired
13
+ * @param [name=''] - The base name for the schema
14
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
15
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
16
+ * @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
17
+ * @returns - The `PathSchema` object for the `schema`
18
+ */
19
+ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = []) {
20
+ if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
21
+ const _schema = retrieveSchema(validator, schema, rootSchema, formData);
22
+ const sameSchemaIndex = _recurseList.findIndex((item) => isEqual(item, _schema));
23
+ if (sameSchemaIndex === -1) {
24
+ return toPathSchemaInternal(validator, _schema, name, rootSchema, formData, _recurseList.concat(_schema));
25
+ }
26
+ }
27
+ let pathSchema = {
28
+ [NAME_KEY]: name.replace(/^\./, ''),
29
+ };
30
+ if (ONE_OF_KEY in schema || ANY_OF_KEY in schema) {
31
+ const xxxOf = ONE_OF_KEY in schema ? schema.oneOf : schema.anyOf;
32
+ const discriminator = getDiscriminatorFieldFromSchema(schema);
33
+ const index = getClosestMatchingOption(validator, rootSchema, formData, xxxOf, 0, discriminator);
34
+ const _schema = xxxOf[index];
35
+ pathSchema = Object.assign(Object.assign({}, pathSchema), toPathSchemaInternal(validator, _schema, name, rootSchema, formData, _recurseList));
36
+ }
37
+ if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
38
+ set(pathSchema, RJSF_ADDITONAL_PROPERTIES_FLAG, true);
39
+ }
40
+ if (ITEMS_KEY in schema && Array.isArray(formData)) {
41
+ formData.forEach((element, i) => {
42
+ pathSchema[i] = toPathSchemaInternal(validator, schema.items, `${name}.${i}`, rootSchema, element, _recurseList);
43
+ });
44
+ }
45
+ else if (PROPERTIES_KEY in schema) {
46
+ for (const property in schema.properties) {
47
+ const field = get(schema, [PROPERTIES_KEY, property]);
48
+ pathSchema[property] = toPathSchemaInternal(validator, field, `${name}.${property}`, rootSchema,
49
+ // It's possible that formData is not an object -- this can happen if an
50
+ // array item has just been added, but not populated with data yet
51
+ get(formData, [property]), _recurseList);
52
+ }
53
+ }
54
+ return pathSchema;
55
+ }
56
+ /** Generates an `PathSchema` object for the `schema`, recursively
57
+ *
58
+ * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
59
+ * @param schema - The schema for which the `PathSchema` is desired
60
+ * @param [name=''] - The base name for the schema
61
+ * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
62
+ * @param [formData] - The current formData, if any, to assist retrieving a schema
63
+ * @returns - The `PathSchema` object for the `schema`
64
+ */
65
+ export default function toPathSchema(validator, schema, name = '', rootSchema, formData) {
66
+ return toPathSchemaInternal(validator, schema, name, rootSchema, formData);
67
+ }
68
+ //# sourceMappingURL=toPathSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toPathSchema.js","sourceRoot":"","sources":["../../src/schema/toPathSchema.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EACL,UAAU,EACV,UAAU,EACV,yBAAyB,EACzB,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,cAAc,EACd,OAAO,EACP,8BAA8B,GAC/B,MAAM,cAAc,CAAC;AACtB,OAAO,+BAA+B,MAAM,oCAAoC,CAAC;AAEjF,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,SAAS,oBAAoB,CAC3B,SAAiC,EACjC,MAAS,EACT,IAAY,EACZ,UAAc,EACd,QAAY,EACZ,eAAoB,EAAE;IAEtB,IAAI,OAAO,IAAI,MAAM,IAAI,gBAAgB,IAAI,MAAM,IAAI,UAAU,IAAI,MAAM,EAAE;QAC3E,MAAM,OAAO,GAA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AK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAClD,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAS,EAAE,EAAE;YACtC,UAAU,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAClC,SAAS,EACT,MAAM,CAAC,KAAU,EACjB,GAAG,IAAI,IAAI,CAAC,EAAE,EACd,UAAU,EACV,OAAO,EACP,YAAY,CACb,CAAC;QACJ,CAAC,CAAC,CAAC;KACJ;SAAM,IAAI,cAAc,IAAI,MAAM,EAAE;QACnC,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,UAAU,EAAE;YACxC,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC;YACtD,UAAU,CAAC,QAAQ,CAAC,GAAG,oBAAoB,CACzC,SAAS,EACT,KAAK,EACL,GAAG,IAAI,IAAI,QAAQ,EAAE,EACrB,UAAU;YACV,wEAAwE;YACxE,kEAAkE;YAClE,GAAG,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EACzB,YAAY,CACb,CAAC;SACH;KACF;IACD,OAAO,UAA2B,CAAC;AACrC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,SAAiC,EACjC,MAAS,EACT,IAAI,GAAG,EAAE,EACT,UAAc,EACd,QAAY;IAEZ,OAAO,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { RJSFSchema, StrictRJSFSchema } from './types';
2
+ /** Check to see if a `schema` specifies that a value must be true. This happens when:
3
+ * - `schema.const` is truthy
4
+ * - `schema.enum` == `[true]`
5
+ * - `schema.anyOf` or `schema.oneOf` has a single value which recursively returns true
6
+ * - `schema.allOf` has at least one value which recursively returns true
7
+ *
8
+ * @param schema - The schema to check
9
+ * @returns - True if the schema specifies a value that must be true, false otherwise
10
+ */
11
+ export default function schemaRequiresTrueValue<S extends StrictRJSFSchema = RJSFSchema>(schema: S): boolean;
@@ -0,0 +1,34 @@
1
+ /** Check to see if a `schema` specifies that a value must be true. This happens when:
2
+ * - `schema.const` is truthy
3
+ * - `schema.enum` == `[true]`
4
+ * - `schema.anyOf` or `schema.oneOf` has a single value which recursively returns true
5
+ * - `schema.allOf` has at least one value which recursively returns true
6
+ *
7
+ * @param schema - The schema to check
8
+ * @returns - True if the schema specifies a value that must be true, false otherwise
9
+ */
10
+ export default function schemaRequiresTrueValue(schema) {
11
+ // Check if const is a truthy value
12
+ if (schema.const) {
13
+ return true;
14
+ }
15
+ // Check if an enum has a single value of true
16
+ if (schema.enum && schema.enum.length === 1 && schema.enum[0] === true) {
17
+ return true;
18
+ }
19
+ // If anyOf has a single value, evaluate the subschema
20
+ if (schema.anyOf && schema.anyOf.length === 1) {
21
+ return schemaRequiresTrueValue(schema.anyOf[0]);
22
+ }
23
+ // If oneOf has a single value, evaluate the subschema
24
+ if (schema.oneOf && schema.oneOf.length === 1) {
25
+ return schemaRequiresTrueValue(schema.oneOf[0]);
26
+ }
27
+ // Evaluate each subschema in allOf, to see if one of them requires a true value
28
+ if (schema.allOf) {
29
+ const schemaSome = (subSchema) => schemaRequiresTrueValue(subSchema);
30
+ return schema.allOf.some(schemaSome);
31
+ }
32
+ return false;
33
+ }
34
+ //# sourceMappingURL=schemaRequiresTrueValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaRequiresTrueValue.js","sourceRoot":"","sources":["../src/schemaRequiresTrueValue.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAA0C,MAAS;IAChG,mCAAmC;IACnC,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,OAAO,IAAI,CAAC;KACb;IAED,8CAA8C;IAC9C,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE;QACtE,OAAO,IAAI,CAAC;KACb;IAED,sDAAsD;IACtD,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QAC7C,OAAO,uBAAuB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAM,CAAC,CAAC;KACtD;IAED,sDAAsD;IACtD,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QAC7C,OAAO,uBAAuB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAM,CAAC,CAAC;KACtD;IAED,gFAAgF;IAChF,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,MAAM,UAAU,GAAG,CAAC,SAAoC,EAAE,EAAE,CAAC,uBAAuB,CAAC,SAAc,CAAC,CAAC;QACrG,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KACtC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ /** Determines whether the given `component` should be rerendered by comparing its current set of props and state
3
+ * against the next set. If either of those two sets are not the same, then the component should be rerendered.
4
+ *
5
+ * @param component - A React component being checked
6
+ * @param nextProps - The next set of props against which to check
7
+ * @param nextState - The next set of state against which to check
8
+ * @returns - True if the component should be re-rendered, false otherwise
9
+ */
10
+ export default function shouldRender(component: React.Component, nextProps: any, nextState: any): boolean;
@@ -0,0 +1,14 @@
1
+ import deepEquals from './deepEquals';
2
+ /** Determines whether the given `component` should be rerendered by comparing its current set of props and state
3
+ * against the next set. If either of those two sets are not the same, then the component should be rerendered.
4
+ *
5
+ * @param component - A React component being checked
6
+ * @param nextProps - The next set of props against which to check
7
+ * @param nextState - The next set of state against which to check
8
+ * @returns - True if the component should be re-rendered, false otherwise
9
+ */
10
+ export default function shouldRender(component, nextProps, nextState) {
11
+ const { props, state } = component;
12
+ return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
13
+ }
14
+ //# sourceMappingURL=shouldRender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shouldRender.js","sourceRoot":"","sources":["../src/shouldRender.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,SAA0B,EAAE,SAAc,EAAE,SAAc;IAC7F,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC;IACnC,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { RJSFSchema, StrictRJSFSchema } from './types';
2
+ /** Returns the constant value from the schema when it is either a single value enum or has a const key. Otherwise
3
+ * throws an error.
4
+ *
5
+ * @param schema - The schema from which to obtain the constant value
6
+ * @returns - The constant value for the schema
7
+ * @throws - Error when the schema does not have a constant value
8
+ */
9
+ export default function toConstant<S extends StrictRJSFSchema = RJSFSchema>(schema: S): import("json-schema").JSONSchema7Type | undefined;
@@ -0,0 +1,18 @@
1
+ import { CONST_KEY, ENUM_KEY } from './constants';
2
+ /** Returns the constant value from the schema when it is either a single value enum or has a const key. Otherwise
3
+ * throws an error.
4
+ *
5
+ * @param schema - The schema from which to obtain the constant value
6
+ * @returns - The constant value for the schema
7
+ * @throws - Error when the schema does not have a constant value
8
+ */
9
+ export default function toConstant(schema) {
10
+ if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
11
+ return schema.enum[0];
12
+ }
13
+ if (CONST_KEY in schema) {
14
+ return schema.const;
15
+ }
16
+ throw new Error('schema cannot be inferred as a constant');
17
+ }
18
+ //# sourceMappingURL=toConstant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toConstant.js","sourceRoot":"","sources":["../src/toConstant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGlD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAA0C,MAAS;IACnF,IAAI,QAAQ,IAAI,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QAChF,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACvB;IACD,IAAI,SAAS,IAAI,MAAM,EAAE;QACvB,OAAO,MAAM,CAAC,KAAK,CAAC;KACrB;IACD,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { DateObject } from './types';
2
+ /** Returns a UTC date string for the given `dateObject`. If `time` is false, then the time portion of the string is
3
+ * removed.
4
+ *
5
+ * @param dateObject - The `DateObject` to convert to a date string
6
+ * @param [time=true] - Optional flag used to remove the time portion of the date string if false
7
+ * @returns - The UTC date string
8
+ */
9
+ export default function toDateString(dateObject: DateObject, time?: boolean): string;
@@ -0,0 +1,14 @@
1
+ /** Returns a UTC date string for the given `dateObject`. If `time` is false, then the time portion of the string is
2
+ * removed.
3
+ *
4
+ * @param dateObject - The `DateObject` to convert to a date string
5
+ * @param [time=true] - Optional flag used to remove the time portion of the date string if false
6
+ * @returns - The UTC date string
7
+ */
8
+ export default function toDateString(dateObject, time = true) {
9
+ const { year, month, day, hour = 0, minute = 0, second = 0 } = dateObject;
10
+ const utcTime = Date.UTC(year, month - 1, day, hour, minute, second);
11
+ const datetime = new Date(utcTime).toJSON();
12
+ return time ? datetime : datetime.slice(0, 10);
13
+ }
14
+ //# sourceMappingURL=toDateString.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toDateString.js","sourceRoot":"","sources":["../src/toDateString.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,UAAsB,EAAE,IAAI,GAAG,IAAI;IACtE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,UAAU,CAAC;IAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;IAC5C,OAAO,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { ErrorSchema, RJSFValidationError } from './types';
2
+ /** Converts an `errorSchema` into a list of `RJSFValidationErrors`
3
+ *
4
+ * @param errorSchema - The `ErrorSchema` instance to convert
5
+ * @param [fieldPath=[]] - The current field path, defaults to [] if not specified
6
+ * @returns - The list of `RJSFValidationErrors` extracted from the `errorSchema`
7
+ */
8
+ export default function toErrorList<T = any>(errorSchema?: ErrorSchema<T>, fieldPath?: string[]): RJSFValidationError[];
@@ -0,0 +1,34 @@
1
+ import isPlainObject from 'lodash/isPlainObject';
2
+ import { ERRORS_KEY } from './constants';
3
+ /** Converts an `errorSchema` into a list of `RJSFValidationErrors`
4
+ *
5
+ * @param errorSchema - The `ErrorSchema` instance to convert
6
+ * @param [fieldPath=[]] - The current field path, defaults to [] if not specified
7
+ * @returns - The list of `RJSFValidationErrors` extracted from the `errorSchema`
8
+ */
9
+ export default function toErrorList(errorSchema, fieldPath = []) {
10
+ if (!errorSchema) {
11
+ return [];
12
+ }
13
+ let errorList = [];
14
+ if (ERRORS_KEY in errorSchema) {
15
+ errorList = errorList.concat(errorSchema[ERRORS_KEY].map((message) => {
16
+ const property = `.${fieldPath.join('.')}`;
17
+ return {
18
+ property,
19
+ message,
20
+ stack: `${property} ${message}`,
21
+ };
22
+ }));
23
+ }
24
+ return Object.keys(errorSchema).reduce((acc, key) => {
25
+ if (key !== ERRORS_KEY) {
26
+ const childSchema = errorSchema[key];
27
+ if (isPlainObject(childSchema)) {
28
+ acc = acc.concat(toErrorList(childSchema, [...fieldPath, key]));
29
+ }
30
+ }
31
+ return acc;
32
+ }, errorList);
33
+ }
34
+ //# sourceMappingURL=toErrorList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toErrorList.js","sourceRoot":"","sources":["../src/toErrorList.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,WAA4B,EAC5B,YAAsB,EAAE;IAExB,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,EAAE,CAAC;KACX;IACD,IAAI,SAAS,GAA0B,EAAE,CAAC;IAC1C,IAAI,UAAU,IAAI,WAAW,EAAE;QAC7B,SAAS,GAAG,SAAS,CAAC,MAAM,CAC1B,WAAW,CAAC,UAAU,CAAE,CAAC,GAAG,CAAC,CAAC,OAAe,EAAE,EAAE;YAC/C,MAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3C,OAAO;gBACL,QAAQ;gBACR,OAAO;gBACP,KAAK,EAAE,GAAG,QAAQ,IAAI,OAAO,EAAE;aAChC,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;KACH;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAClD,IAAI,GAAG,KAAK,UAAU,EAAE;YACtB,MAAM,WAAW,GAAI,WAAiC,CAAC,GAAG,CAAC,CAAC;YAC5D,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE;gBAC9B,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;aACjE;SACF;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,SAAS,CAAC,CAAC;AAChB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { ErrorSchema, RJSFValidationError } from './types';
2
+ /** Transforms a rjsf validation errors list:
3
+ * [
4
+ * {property: '.level1.level2[2].level3', message: 'err a'},
5
+ * {property: '.level1.level2[2].level3', message: 'err b'},
6
+ * {property: '.level1.level2[4].level3', message: 'err b'},
7
+ * ]
8
+ * Into an error tree:
9
+ * {
10
+ * level1: {
11
+ * level2: {
12
+ * 2: {level3: {errors: ['err a', 'err b']}},
13
+ * 4: {level3: {errors: ['err b']}},
14
+ * }
15
+ * }
16
+ * };
17
+ *
18
+ * @param errors - The list of RJSFValidationError objects
19
+ * @returns - The `ErrorSchema` built from the list of `RJSFValidationErrors`
20
+ */
21
+ export default function toErrorSchema<T = any>(errors: RJSFValidationError[]): ErrorSchema<T>;
@@ -0,0 +1,41 @@
1
+ import toPath from 'lodash/toPath';
2
+ import ErrorSchemaBuilder from './ErrorSchemaBuilder';
3
+ /** Transforms a rjsf validation errors list:
4
+ * [
5
+ * {property: '.level1.level2[2].level3', message: 'err a'},
6
+ * {property: '.level1.level2[2].level3', message: 'err b'},
7
+ * {property: '.level1.level2[4].level3', message: 'err b'},
8
+ * ]
9
+ * Into an error tree:
10
+ * {
11
+ * level1: {
12
+ * level2: {
13
+ * 2: {level3: {errors: ['err a', 'err b']}},
14
+ * 4: {level3: {errors: ['err b']}},
15
+ * }
16
+ * }
17
+ * };
18
+ *
19
+ * @param errors - The list of RJSFValidationError objects
20
+ * @returns - The `ErrorSchema` built from the list of `RJSFValidationErrors`
21
+ */
22
+ export default function toErrorSchema(errors) {
23
+ const builder = new ErrorSchemaBuilder();
24
+ if (errors.length) {
25
+ errors.forEach((error) => {
26
+ const { property, message } = error;
27
+ // When the property is the root element, just use an empty array for the path
28
+ const path = property === '.' ? [] : toPath(property);
29
+ // If the property is at the root (.level1) then toPath creates
30
+ // an empty array element at the first index. Remove it.
31
+ if (path.length > 0 && path[0] === '') {
32
+ path.splice(0, 1);
33
+ }
34
+ if (message) {
35
+ builder.addErrors(message, path);
36
+ }
37
+ });
38
+ }
39
+ return builder.ErrorSchema;
40
+ }
41
+ //# sourceMappingURL=toErrorSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toErrorSchema.js","sourceRoot":"","sources":["../src/toErrorSchema.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,eAAe,CAAC;AAGnC,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAU,MAA6B;IAC1E,MAAM,OAAO,GAAG,IAAI,kBAAkB,EAAK,CAAC;IAC5C,IAAI,MAAM,CAAC,MAAM,EAAE;QACjB,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACvB,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;YACpC,8EAA8E;YAC9E,MAAM,IAAI,GAAG,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YACtD,+DAA+D;YAC/D,wDAAwD;YACxD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE;gBACrC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACnB;YACD,IAAI,OAAO,EAAE;gBACX,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;aAClC;QACH,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,OAAO,CAAC,WAAW,CAAC;AAC7B,CAAC"}