@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.
- package/dist/index.js +2544 -5
- package/dist/index.js.map +7 -0
- package/dist/utils.esm.js +1228 -2113
- package/dist/utils.esm.js.map +7 -1
- package/dist/utils.umd.js +2414 -0
- package/lib/ErrorSchemaBuilder.d.ts +60 -0
- package/lib/ErrorSchemaBuilder.js +103 -0
- package/lib/ErrorSchemaBuilder.js.map +1 -0
- package/lib/allowAdditionalItems.d.ts +8 -0
- package/lib/allowAdditionalItems.js +14 -0
- package/lib/allowAdditionalItems.js.map +1 -0
- package/lib/asNumber.d.ts +10 -0
- package/lib/asNumber.js +36 -0
- package/lib/asNumber.js.map +1 -0
- package/lib/canExpand.d.ts +11 -0
- package/lib/canExpand.js +26 -0
- package/lib/canExpand.js.map +1 -0
- package/lib/constants.d.ts +31 -0
- package/lib/constants.js +32 -0
- package/lib/constants.js.map +1 -0
- package/lib/createErrorHandler.d.ts +7 -0
- package/lib/createErrorHandler.js +31 -0
- package/lib/createErrorHandler.js.map +1 -0
- package/lib/createSchemaUtils.d.ts +10 -0
- package/lib/createSchemaUtils.js +207 -0
- package/lib/createSchemaUtils.js.map +1 -0
- package/lib/dataURItoBlob.d.ts +16 -0
- package/lib/dataURItoBlob.js +43 -0
- package/lib/dataURItoBlob.js.map +1 -0
- package/lib/deepEquals.d.ts +8 -0
- package/lib/deepEquals.js +19 -0
- package/lib/deepEquals.js.map +1 -0
- package/lib/englishStringTranslator.d.ts +10 -0
- package/lib/englishStringTranslator.js +13 -0
- package/lib/englishStringTranslator.js.map +1 -0
- package/lib/enumOptionsDeselectValue.d.ts +14 -0
- package/lib/enumOptionsDeselectValue.js +22 -0
- package/lib/enumOptionsDeselectValue.js.map +1 -0
- package/lib/enumOptionsIndexForValue.d.ts +13 -0
- package/lib/enumOptionsIndexForValue.js +22 -0
- package/lib/enumOptionsIndexForValue.js.map +1 -0
- package/lib/enumOptionsIsSelected.d.ts +8 -0
- package/lib/enumOptionsIsSelected.js +14 -0
- package/lib/enumOptionsIsSelected.js.map +1 -0
- package/lib/enumOptionsSelectValue.d.ts +10 -0
- package/lib/enumOptionsSelectValue.js +23 -0
- package/lib/enumOptionsSelectValue.js.map +1 -0
- package/lib/enumOptionsValueForIndex.d.ts +13 -0
- package/lib/enumOptionsValueForIndex.js +21 -0
- package/lib/enumOptionsValueForIndex.js.map +1 -0
- package/lib/enums.d.ts +72 -0
- package/lib/enums.js +76 -0
- package/lib/enums.js.map +1 -0
- package/lib/findSchemaDefinition.d.ts +20 -0
- package/lib/findSchemaDefinition.js +49 -0
- package/lib/findSchemaDefinition.js.map +1 -0
- package/lib/getDiscriminatorFieldFromSchema.d.ts +8 -0
- package/lib/getDiscriminatorFieldFromSchema.js +20 -0
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -0
- package/lib/getInputProps.d.ts +10 -0
- package/lib/getInputProps.js +41 -0
- package/lib/getInputProps.js.map +1 -0
- package/lib/getSchemaType.d.ts +13 -0
- package/lib/getSchemaType.js +29 -0
- package/lib/getSchemaType.js.map +1 -0
- package/lib/getSubmitButtonOptions.d.ts +10 -0
- package/lib/getSubmitButtonOptions.js +25 -0
- package/lib/getSubmitButtonOptions.js.map +1 -0
- package/lib/getTemplate.d.ts +10 -0
- package/lib/getTemplate.js +19 -0
- package/lib/getTemplate.js.map +1 -0
- package/lib/getUiOptions.d.ts +9 -0
- package/lib/getUiOptions.js +25 -0
- package/lib/getUiOptions.js.map +1 -0
- package/lib/getWidget.d.ts +13 -0
- package/lib/getWidget.js +118 -0
- package/lib/getWidget.js.map +1 -0
- package/lib/guessType.d.ts +7 -0
- package/lib/guessType.js +29 -0
- package/lib/guessType.js.map +1 -0
- package/lib/hasWidget.d.ts +10 -0
- package/lib/hasWidget.js +23 -0
- package/lib/hasWidget.js.map +1 -0
- package/lib/hashForSchema.d.ts +8 -0
- package/lib/hashForSchema.js +29 -0
- package/lib/hashForSchema.js.map +1 -0
- package/lib/idGenerators.d.ts +47 -0
- package/lib/idGenerators.js +73 -0
- package/lib/idGenerators.js.map +1 -0
- package/lib/index.d.ts +57 -0
- package/lib/index.js +58 -0
- package/lib/index.js.map +1 -0
- package/lib/isConstant.d.ts +8 -0
- package/lib/isConstant.js +11 -0
- package/lib/isConstant.js.map +1 -0
- package/lib/isCustomWidget.d.ts +7 -0
- package/lib/isCustomWidget.js +13 -0
- package/lib/isCustomWidget.js.map +1 -0
- package/lib/isFixedItems.d.ts +8 -0
- package/lib/isFixedItems.js +11 -0
- package/lib/isFixedItems.js.map +1 -0
- package/lib/isObject.d.ts +7 -0
- package/lib/isObject.js +16 -0
- package/lib/isObject.js.map +1 -0
- package/lib/labelValue.d.ts +13 -0
- package/lib/labelValue.js +4 -0
- package/lib/labelValue.js.map +1 -0
- package/lib/localToUTC.d.ts +6 -0
- package/lib/localToUTC.js +9 -0
- package/lib/localToUTC.js.map +1 -0
- package/lib/mergeDefaultsWithFormData.d.ts +17 -0
- package/lib/mergeDefaultsWithFormData.js +43 -0
- package/lib/mergeDefaultsWithFormData.js.map +1 -0
- package/lib/mergeObjects.d.ts +11 -0
- package/lib/mergeObjects.js +35 -0
- package/lib/mergeObjects.js.map +1 -0
- package/lib/mergeSchemas.d.ts +10 -0
- package/lib/mergeSchemas.js +35 -0
- package/lib/mergeSchemas.js.map +1 -0
- package/lib/optionsList.d.ts +10 -0
- package/lib/optionsList.js +36 -0
- package/lib/optionsList.js.map +1 -0
- package/lib/orderProperties.d.ts +11 -0
- package/lib/orderProperties.js +38 -0
- package/lib/orderProperties.js.map +1 -0
- package/lib/pad.d.ts +7 -0
- package/lib/pad.js +14 -0
- package/lib/pad.js.map +1 -0
- package/lib/parseDateString.d.ts +9 -0
- package/lib/parseDateString.js +32 -0
- package/lib/parseDateString.js.map +1 -0
- package/lib/parser/ParserValidator.d.ts +70 -0
- package/lib/parser/ParserValidator.js +93 -0
- package/lib/parser/ParserValidator.js.map +1 -0
- package/lib/parser/index.d.ts +4 -0
- package/lib/parser/index.js +3 -0
- package/lib/parser/index.js.map +1 -0
- package/lib/parser/schemaParser.d.ts +9 -0
- package/lib/parser/schemaParser.js +48 -0
- package/lib/parser/schemaParser.js.map +1 -0
- package/lib/rangeSpec.d.ts +9 -0
- package/lib/rangeSpec.js +20 -0
- package/lib/rangeSpec.js.map +1 -0
- package/lib/replaceStringParameters.d.ts +9 -0
- package/lib/replaceStringParameters.js +23 -0
- package/lib/replaceStringParameters.js.map +1 -0
- package/lib/schema/getClosestMatchingOption.d.ts +49 -0
- package/lib/schema/getClosestMatchingOption.js +154 -0
- package/lib/schema/getClosestMatchingOption.js.map +1 -0
- package/lib/schema/getDefaultFormState.d.ts +66 -0
- package/lib/schema/getDefaultFormState.js +351 -0
- package/lib/schema/getDefaultFormState.js.map +1 -0
- package/lib/schema/getDisplayLabel.d.ts +12 -0
- package/lib/schema/getDisplayLabel.js +39 -0
- package/lib/schema/getDisplayLabel.js.map +1 -0
- package/lib/schema/getFirstMatchingOption.d.ts +13 -0
- package/lib/schema/getFirstMatchingOption.js +16 -0
- package/lib/schema/getFirstMatchingOption.js.map +1 -0
- package/lib/schema/getMatchingOption.d.ts +14 -0
- package/lib/schema/getMatchingOption.js +80 -0
- package/lib/schema/getMatchingOption.js.map +1 -0
- package/lib/schema/index.d.ts +14 -0
- package/lib/schema/index.js +15 -0
- package/lib/schema/index.js.map +1 -0
- package/lib/schema/isFilesArray.d.ts +10 -0
- package/lib/schema/isFilesArray.js +21 -0
- package/lib/schema/isFilesArray.js.map +1 -0
- package/lib/schema/isMultiSelect.d.ts +9 -0
- package/lib/schema/isMultiSelect.js +15 -0
- package/lib/schema/isMultiSelect.js.map +1 -0
- package/lib/schema/isSelect.d.ts +9 -0
- package/lib/schema/isSelect.js +21 -0
- package/lib/schema/isSelect.js.map +1 -0
- package/lib/schema/mergeValidationData.d.ts +14 -0
- package/lib/schema/mergeValidationData.js +28 -0
- package/lib/schema/mergeValidationData.js.map +1 -0
- package/lib/schema/retrieveSchema.d.ts +170 -0
- package/lib/schema/retrieveSchema.js +437 -0
- package/lib/schema/retrieveSchema.js.map +1 -0
- package/lib/schema/sanitizeDataForNewSchema.d.ts +49 -0
- package/lib/schema/sanitizeDataForNewSchema.js +173 -0
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -0
- package/lib/schema/toIdSchema.d.ts +13 -0
- package/lib/schema/toIdSchema.js +59 -0
- package/lib/schema/toIdSchema.js.map +1 -0
- package/lib/schema/toPathSchema.d.ts +11 -0
- package/lib/schema/toPathSchema.js +68 -0
- package/lib/schema/toPathSchema.js.map +1 -0
- package/lib/schemaRequiresTrueValue.d.ts +11 -0
- package/lib/schemaRequiresTrueValue.js +34 -0
- package/lib/schemaRequiresTrueValue.js.map +1 -0
- package/lib/shouldRender.d.ts +10 -0
- package/lib/shouldRender.js +14 -0
- package/lib/shouldRender.js.map +1 -0
- package/lib/toConstant.d.ts +9 -0
- package/lib/toConstant.js +18 -0
- package/lib/toConstant.js.map +1 -0
- package/lib/toDateString.d.ts +9 -0
- package/lib/toDateString.js +14 -0
- package/lib/toDateString.js.map +1 -0
- package/lib/toErrorList.d.ts +8 -0
- package/lib/toErrorList.js +34 -0
- package/lib/toErrorList.js.map +1 -0
- package/lib/toErrorSchema.d.ts +21 -0
- package/lib/toErrorSchema.js +41 -0
- package/lib/toErrorSchema.js.map +1 -0
- package/lib/types.d.ts +982 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/unwrapErrorHandler.d.ts +7 -0
- package/lib/unwrapErrorHandler.js +21 -0
- package/lib/unwrapErrorHandler.js.map +1 -0
- package/lib/utcToLocal.d.ts +6 -0
- package/lib/utcToLocal.js +26 -0
- package/lib/utcToLocal.js.map +1 -0
- package/lib/validationDataMerge.d.ts +11 -0
- package/lib/validationDataMerge.js +26 -0
- package/lib/validationDataMerge.js.map +1 -0
- package/lib/withIdRefPrefix.d.ts +8 -0
- package/lib/withIdRefPrefix.js +47 -0
- package/lib/withIdRefPrefix.js.map +1 -0
- package/package.json +20 -13
- package/src/ErrorSchemaBuilder.ts +112 -0
- package/src/allowAdditionalItems.ts +15 -0
- package/src/asNumber.ts +38 -0
- package/src/canExpand.ts +31 -0
- package/src/constants.ts +31 -0
- package/src/createErrorHandler.ts +33 -0
- package/src/createSchemaUtils.ts +298 -0
- package/src/dataURItoBlob.ts +42 -0
- package/src/deepEquals.ts +19 -0
- package/src/englishStringTranslator.ts +14 -0
- package/src/enumOptionsDeselectValue.ts +28 -0
- package/src/enumOptionsIndexForValue.ts +27 -0
- package/src/enumOptionsIsSelected.ts +19 -0
- package/src/enumOptionsSelectValue.ts +28 -0
- package/src/enumOptionsValueForIndex.ts +26 -0
- package/src/enums.ts +74 -0
- package/src/findSchemaDefinition.ts +54 -0
- package/src/getDiscriminatorFieldFromSchema.ts +21 -0
- package/src/getInputProps.ts +55 -0
- package/src/getSchemaType.ts +37 -0
- package/src/getSubmitButtonOptions.ts +32 -0
- package/src/getTemplate.ts +26 -0
- package/src/getUiOptions.ts +32 -0
- package/src/getWidget.tsx +133 -0
- package/src/guessType.ts +28 -0
- package/src/hasWidget.ts +27 -0
- package/src/hashForSchema.ts +31 -0
- package/src/idGenerators.ts +81 -0
- package/src/index.ts +118 -0
- package/src/isConstant.ts +12 -0
- package/src/isCustomWidget.ts +19 -0
- package/src/isFixedItems.ts +12 -0
- package/src/isObject.ts +15 -0
- package/src/labelValue.ts +16 -0
- package/src/localToUTC.ts +8 -0
- package/src/mergeDefaultsWithFormData.ts +53 -0
- package/src/mergeObjects.ts +39 -0
- package/src/mergeSchemas.ts +38 -0
- package/src/optionsList.ts +41 -0
- package/src/orderProperties.ts +44 -0
- package/src/pad.ts +13 -0
- package/src/parseDateString.ts +33 -0
- package/src/parser/ParserValidator.ts +132 -0
- package/src/parser/index.ts +6 -0
- package/src/parser/schemaParser.ts +60 -0
- package/src/rangeSpec.ts +22 -0
- package/src/replaceStringParameters.ts +22 -0
- package/src/schema/getClosestMatchingOption.ts +191 -0
- package/src/schema/getDefaultFormState.ts +447 -0
- package/src/schema/getDisplayLabel.ts +59 -0
- package/src/schema/getFirstMatchingOption.ts +27 -0
- package/src/schema/getMatchingOption.ts +95 -0
- package/src/schema/index.ts +29 -0
- package/src/schema/isFilesArray.ts +27 -0
- package/src/schema/isMultiSelect.ts +21 -0
- package/src/schema/isSelect.ts +26 -0
- package/src/schema/mergeValidationData.ts +38 -0
- package/src/schema/retrieveSchema.ts +614 -0
- package/src/schema/sanitizeDataForNewSchema.ts +197 -0
- package/src/schema/toIdSchema.ts +105 -0
- package/src/schema/toPathSchema.ts +121 -0
- package/src/schemaRequiresTrueValue.ts +40 -0
- package/src/shouldRender.ts +16 -0
- package/src/toConstant.ts +19 -0
- package/src/toDateString.ts +15 -0
- package/src/toErrorList.ts +41 -0
- package/src/toErrorSchema.ts +43 -0
- package/src/types.ts +1139 -0
- package/src/unwrapErrorHandler.ts +25 -0
- package/src/utcToLocal.ts +30 -0
- package/src/validationDataMerge.ts +31 -0
- package/src/withIdRefPrefix.ts +49 -0
- package/dist/index.d.ts +0 -1911
- package/dist/utils.cjs.development.js +0 -3522
- package/dist/utils.cjs.development.js.map +0 -1
- package/dist/utils.cjs.production.min.js +0 -2
- package/dist/utils.cjs.production.min.js.map +0 -1
- package/dist/utils.umd.development.js +0 -3504
- package/dist/utils.umd.development.js.map +0 -1
- package/dist/utils.umd.production.min.js +0 -2
- package/dist/utils.umd.production.min.js.map +0 -1
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import get from 'lodash/get';
|
|
3
|
+
import set from 'lodash/set';
|
|
4
|
+
import times from 'lodash/times';
|
|
5
|
+
import transform from 'lodash/transform';
|
|
6
|
+
import mergeAllOf from 'json-schema-merge-allof';
|
|
7
|
+
import { ADDITIONAL_PROPERTIES_KEY, ADDITIONAL_PROPERTY_FLAG, ALL_OF_KEY, ANY_OF_KEY, DEPENDENCIES_KEY, IF_KEY, ONE_OF_KEY, REF_KEY, PROPERTIES_KEY, ITEMS_KEY, } from '../constants';
|
|
8
|
+
import findSchemaDefinition, { splitKeyElementFromObject } from '../findSchemaDefinition';
|
|
9
|
+
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema';
|
|
10
|
+
import guessType from '../guessType';
|
|
11
|
+
import isObject from '../isObject';
|
|
12
|
+
import mergeSchemas from '../mergeSchemas';
|
|
13
|
+
import getFirstMatchingOption from './getFirstMatchingOption';
|
|
14
|
+
/** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies
|
|
15
|
+
* resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the
|
|
16
|
+
* potentially recursive resolution.
|
|
17
|
+
*
|
|
18
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
19
|
+
* @param schema - The schema for which retrieving a schema is desired
|
|
20
|
+
* @param [rootSchema={}] - The root schema that will be forwarded to all the APIs
|
|
21
|
+
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema
|
|
22
|
+
* @returns - The schema having its conditions, additional properties, references and dependencies resolved
|
|
23
|
+
*/
|
|
24
|
+
export default function retrieveSchema(validator, schema, rootSchema = {}, rawFormData) {
|
|
25
|
+
return retrieveSchemaInternal(validator, schema, rootSchema, rawFormData)[0];
|
|
26
|
+
}
|
|
27
|
+
/** Resolves a conditional block (if/else/then) by removing the condition and merging the appropriate conditional branch
|
|
28
|
+
* with the rest of the schema. If `expandAllBranches` is true, then the `retrieveSchemaInteral()` results for both
|
|
29
|
+
* conditions will be returned.
|
|
30
|
+
*
|
|
31
|
+
* @param validator - An implementation of the `ValidatorType` interface that is used to detect valid schema conditions
|
|
32
|
+
* @param schema - The schema for which resolving a condition is desired
|
|
33
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
34
|
+
* @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and
|
|
35
|
+
* dependencies as a list of schemas
|
|
36
|
+
* @param [formData] - The current formData to assist retrieving a schema
|
|
37
|
+
* @returns - A list of schemas with the appropriate conditions resolved, possibly with all branches expanded
|
|
38
|
+
*/
|
|
39
|
+
export function resolveCondition(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
40
|
+
const { if: expression, then, else: otherwise } = schema, resolvedSchemaLessConditional = __rest(schema, ["if", "then", "else"]);
|
|
41
|
+
const conditionValue = validator.isValid(expression, formData || {}, rootSchema);
|
|
42
|
+
let resolvedSchemas = [resolvedSchemaLessConditional];
|
|
43
|
+
let schemas = [];
|
|
44
|
+
if (expandAllBranches) {
|
|
45
|
+
if (then && typeof then !== 'boolean') {
|
|
46
|
+
schemas = schemas.concat(retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches));
|
|
47
|
+
}
|
|
48
|
+
if (otherwise && typeof otherwise !== 'boolean') {
|
|
49
|
+
schemas = schemas.concat(retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const conditionalSchema = conditionValue ? then : otherwise;
|
|
54
|
+
if (conditionalSchema && typeof conditionalSchema !== 'boolean') {
|
|
55
|
+
schemas = schemas.concat(retrieveSchemaInternal(validator, conditionalSchema, rootSchema, formData, expandAllBranches));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (schemas.length) {
|
|
59
|
+
resolvedSchemas = schemas.map((s) => mergeSchemas(resolvedSchemaLessConditional, s));
|
|
60
|
+
}
|
|
61
|
+
return resolvedSchemas.flatMap((s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches));
|
|
62
|
+
}
|
|
63
|
+
/** Given a list of lists of allOf, anyOf or oneOf values, create a list of lists of all permutations of the values. The
|
|
64
|
+
* `listOfLists` is expected to be all resolved values of the 1st...nth schemas within an `allOf`, `anyOf` or `oneOf`.
|
|
65
|
+
* From those lists, build a matrix for each `xxxOf` where there is more than one schema for a row in the list of lists.
|
|
66
|
+
*
|
|
67
|
+
* For example:
|
|
68
|
+
* - If there are three xxxOf rows (A, B, C) and they have been resolved such that there is only one A, two B and three
|
|
69
|
+
* C schemas then:
|
|
70
|
+
* - The permutation for the first row is `[[A]]`
|
|
71
|
+
* - The permutations for the second row are `[[A,B1], [A,B2]]`
|
|
72
|
+
* - The permutations for the third row are `[[A,B1,C1], [A,B1,C2], [A,B1,C3], [A,B2,C1], [A,B2,C2], [A,B2,C3]]`
|
|
73
|
+
*
|
|
74
|
+
* @param listOfLists - The list of lists of elements that represent the allOf, anyOf or oneOf resolved values in order
|
|
75
|
+
* @returns - The list of all permutations of schemas for a set of `xxxOf`s
|
|
76
|
+
*/
|
|
77
|
+
export function getAllPermutationsOfXxxOf(listOfLists) {
|
|
78
|
+
const allPermutations = listOfLists.reduce((permutations, list) => {
|
|
79
|
+
// When there are more than one set of schemas for a row, duplicate the set of permutations and add in the values
|
|
80
|
+
if (list.length > 1) {
|
|
81
|
+
return list.flatMap((element) => times(permutations.length, (i) => [...permutations[i]].concat(element)));
|
|
82
|
+
}
|
|
83
|
+
// Otherwise just push in the single value into the current set of permutations
|
|
84
|
+
permutations.forEach((permutation) => permutation.push(list[0]));
|
|
85
|
+
return permutations;
|
|
86
|
+
}, [[]] // Start with an empty list
|
|
87
|
+
);
|
|
88
|
+
return allPermutations;
|
|
89
|
+
}
|
|
90
|
+
/** Resolves references and dependencies within a schema and its 'allOf' children. Passes the `expandAllBranches` flag
|
|
91
|
+
* down to the `retrieveSchemaInternal()`, `resolveReference()` and `resolveDependencies()` helper calls. If
|
|
92
|
+
* `expandAllBranches` is true, then all possible dependencies and/or allOf branches are returned.
|
|
93
|
+
*
|
|
94
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
95
|
+
* @param schema - The schema for which resolving a schema is desired
|
|
96
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
97
|
+
* @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
|
|
98
|
+
* as a list of schemas
|
|
99
|
+
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
100
|
+
* @returns - The list of schemas having its references, dependencies and allOf schemas resolved
|
|
101
|
+
*/
|
|
102
|
+
export function resolveSchema(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
103
|
+
if (REF_KEY in schema) {
|
|
104
|
+
return resolveReference(validator, schema, rootSchema, expandAllBranches, formData);
|
|
105
|
+
}
|
|
106
|
+
if (DEPENDENCIES_KEY in schema) {
|
|
107
|
+
const resolvedSchemas = resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData);
|
|
108
|
+
return resolvedSchemas.flatMap((s) => {
|
|
109
|
+
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) {
|
|
113
|
+
const allOfSchemaElements = schema.allOf.map((allOfSubschema) => retrieveSchemaInternal(validator, allOfSubschema, rootSchema, formData, expandAllBranches));
|
|
114
|
+
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements);
|
|
115
|
+
return allPermutations.map((permutation) => (Object.assign(Object.assign({}, schema), { allOf: permutation })));
|
|
116
|
+
}
|
|
117
|
+
// No $ref or dependencies or allOf attribute was found, returning the original schema.
|
|
118
|
+
return [schema];
|
|
119
|
+
}
|
|
120
|
+
/** Resolves references within a schema and then returns the `retrieveSchemaInternal()` of the resolved schema. Passes
|
|
121
|
+
* the `expandAllBranches` flag down to the `retrieveSchemaInternal()` helper call.
|
|
122
|
+
*
|
|
123
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
124
|
+
* @param schema - The schema for which resolving a reference is desired
|
|
125
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
126
|
+
* @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
|
|
127
|
+
* as a list of schemas
|
|
128
|
+
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
129
|
+
* @returns - The list schemas retrieved after having all references resolved
|
|
130
|
+
*/
|
|
131
|
+
export function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
132
|
+
// Drop the $ref property of the source schema.
|
|
133
|
+
const { $ref } = schema, localSchema = __rest(schema, ["$ref"]);
|
|
134
|
+
// Retrieve the referenced schema definition.
|
|
135
|
+
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
136
|
+
// Update referenced schema definition with local schema properties.
|
|
137
|
+
return retrieveSchemaInternal(validator, Object.assign(Object.assign({}, refSchema), localSchema), rootSchema, formData, expandAllBranches);
|
|
138
|
+
}
|
|
139
|
+
/** Resolves all references within a schema's properties and array items.
|
|
140
|
+
*
|
|
141
|
+
* @param schema - The schema for which resolving all references is desired
|
|
142
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
143
|
+
* @returns - given schema will all references resolved
|
|
144
|
+
*/
|
|
145
|
+
export function resolveAllReferences(schema, rootSchema) {
|
|
146
|
+
let resolvedSchema = schema;
|
|
147
|
+
// resolve top level ref
|
|
148
|
+
if (REF_KEY in resolvedSchema) {
|
|
149
|
+
const { $ref } = resolvedSchema, localSchema = __rest(resolvedSchema, ["$ref"]);
|
|
150
|
+
// Retrieve the referenced schema definition.
|
|
151
|
+
const refSchema = findSchemaDefinition($ref, rootSchema);
|
|
152
|
+
resolvedSchema = Object.assign(Object.assign({}, refSchema), localSchema);
|
|
153
|
+
}
|
|
154
|
+
if (PROPERTIES_KEY in resolvedSchema) {
|
|
155
|
+
const updatedProps = transform(resolvedSchema[PROPERTIES_KEY], (result, value, key) => {
|
|
156
|
+
result[key] = resolveAllReferences(value, rootSchema);
|
|
157
|
+
}, {});
|
|
158
|
+
resolvedSchema = Object.assign(Object.assign({}, resolvedSchema), { [PROPERTIES_KEY]: updatedProps });
|
|
159
|
+
}
|
|
160
|
+
if (ITEMS_KEY in resolvedSchema &&
|
|
161
|
+
!Array.isArray(resolvedSchema.items) &&
|
|
162
|
+
typeof resolvedSchema.items !== 'boolean') {
|
|
163
|
+
resolvedSchema = Object.assign(Object.assign({}, resolvedSchema), { items: resolveAllReferences(resolvedSchema.items, rootSchema) });
|
|
164
|
+
}
|
|
165
|
+
return resolvedSchema;
|
|
166
|
+
}
|
|
167
|
+
/** Creates new 'properties' items for each key in the `formData`
|
|
168
|
+
*
|
|
169
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
170
|
+
* @param theSchema - The schema for which the existing additional properties is desired
|
|
171
|
+
* @param [rootSchema] - The root schema, used to primarily to look up `$ref`s * @param validator
|
|
172
|
+
* @param [aFormData] - The current formData, if any, to assist retrieving a schema
|
|
173
|
+
* @returns - The updated schema with additional properties stubbed
|
|
174
|
+
*/
|
|
175
|
+
export function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFormData) {
|
|
176
|
+
// Clone the schema so that we don't ruin the consumer's original
|
|
177
|
+
const schema = Object.assign(Object.assign({}, theSchema), { properties: Object.assign({}, theSchema.properties) });
|
|
178
|
+
// make sure formData is an object
|
|
179
|
+
const formData = aFormData && isObject(aFormData) ? aFormData : {};
|
|
180
|
+
Object.keys(formData).forEach((key) => {
|
|
181
|
+
if (key in schema.properties) {
|
|
182
|
+
// No need to stub, our schema already has the property
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
let additionalProperties = {};
|
|
186
|
+
if (typeof schema.additionalProperties !== 'boolean') {
|
|
187
|
+
if (REF_KEY in schema.additionalProperties) {
|
|
188
|
+
additionalProperties = retrieveSchema(validator, { $ref: get(schema.additionalProperties, [REF_KEY]) }, rootSchema, formData);
|
|
189
|
+
}
|
|
190
|
+
else if ('type' in schema.additionalProperties) {
|
|
191
|
+
additionalProperties = Object.assign({}, schema.additionalProperties);
|
|
192
|
+
}
|
|
193
|
+
else if (ANY_OF_KEY in schema.additionalProperties || ONE_OF_KEY in schema.additionalProperties) {
|
|
194
|
+
additionalProperties = Object.assign({ type: 'object' }, schema.additionalProperties);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
additionalProperties = { type: guessType(get(formData, [key])) };
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
additionalProperties = { type: guessType(get(formData, [key])) };
|
|
202
|
+
}
|
|
203
|
+
// The type of our new key should match the additionalProperties value;
|
|
204
|
+
schema.properties[key] = additionalProperties;
|
|
205
|
+
// Set our additional property flag so we know it was dynamically added
|
|
206
|
+
set(schema.properties, [key, ADDITIONAL_PROPERTY_FLAG], true);
|
|
207
|
+
});
|
|
208
|
+
return schema;
|
|
209
|
+
}
|
|
210
|
+
/** Internal handler that retrieves an expanded schema that has had all of its conditions, additional properties,
|
|
211
|
+
* references and dependencies resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData`
|
|
212
|
+
* that is used to do the potentially recursive resolution. If `expandAllBranches` is true, then all possible branches
|
|
213
|
+
* of the schema and its references, conditions and dependencies are returned.
|
|
214
|
+
*
|
|
215
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
216
|
+
* @param schema - The schema for which retrieving a schema is desired
|
|
217
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
218
|
+
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema
|
|
219
|
+
* @param [expandAllBranches=false] - Flag, if true, will return all possible branches of conditions, any/oneOf and
|
|
220
|
+
* dependencies as a list of schemas
|
|
221
|
+
* @returns - The schema(s) resulting from having its conditions, additional properties, references and dependencies
|
|
222
|
+
* resolved. Multiple schemas may be returned if `expandAllBranches` is true.
|
|
223
|
+
*/
|
|
224
|
+
export function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false) {
|
|
225
|
+
if (!isObject(schema)) {
|
|
226
|
+
return [{}];
|
|
227
|
+
}
|
|
228
|
+
const resolvedSchemas = resolveSchema(validator, schema, rootSchema, expandAllBranches, rawFormData);
|
|
229
|
+
return resolvedSchemas.flatMap((s) => {
|
|
230
|
+
let resolvedSchema = s;
|
|
231
|
+
if (IF_KEY in resolvedSchema) {
|
|
232
|
+
return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, rawFormData);
|
|
233
|
+
}
|
|
234
|
+
if (ALL_OF_KEY in resolvedSchema) {
|
|
235
|
+
// resolve allOf schemas
|
|
236
|
+
if (expandAllBranches) {
|
|
237
|
+
return [...resolvedSchema.allOf];
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
resolvedSchema = mergeAllOf(resolvedSchema, {
|
|
241
|
+
deep: false,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
catch (e) {
|
|
245
|
+
console.warn('could not merge subschemas in allOf:\n', e);
|
|
246
|
+
const { allOf } = resolvedSchema, resolvedSchemaWithoutAllOf = __rest(resolvedSchema, ["allOf"]);
|
|
247
|
+
return resolvedSchemaWithoutAllOf;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const hasAdditionalProperties = ADDITIONAL_PROPERTIES_KEY in resolvedSchema && resolvedSchema.additionalProperties !== false;
|
|
251
|
+
if (hasAdditionalProperties) {
|
|
252
|
+
return stubExistingAdditionalProperties(validator, resolvedSchema, rootSchema, rawFormData);
|
|
253
|
+
}
|
|
254
|
+
return resolvedSchema;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
/** Resolves an `anyOf` or `oneOf` within a schema (if present) to the list of schemas returned from
|
|
258
|
+
* `retrieveSchemaInternal()` for the best matching option. If `expandAllBranches` is true, then a list of schemas for ALL
|
|
259
|
+
* options are retrieved and returned.
|
|
260
|
+
*
|
|
261
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
262
|
+
* @param schema - The schema for which retrieving a schema is desired
|
|
263
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
264
|
+
* @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
|
|
265
|
+
* as a list of schemas
|
|
266
|
+
* @param [rawFormData] - The current formData, if any, to assist retrieving a schema, defaults to an empty object
|
|
267
|
+
* @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
|
|
268
|
+
*/
|
|
269
|
+
export function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) {
|
|
270
|
+
let anyOrOneOf;
|
|
271
|
+
const { oneOf, anyOf } = schema, remaining = __rest(schema, ["oneOf", "anyOf"]);
|
|
272
|
+
if (Array.isArray(oneOf)) {
|
|
273
|
+
anyOrOneOf = oneOf;
|
|
274
|
+
}
|
|
275
|
+
else if (Array.isArray(anyOf)) {
|
|
276
|
+
anyOrOneOf = anyOf;
|
|
277
|
+
}
|
|
278
|
+
if (anyOrOneOf) {
|
|
279
|
+
// Ensure that during expand all branches we pass an object rather than undefined so that all options are interrogated
|
|
280
|
+
const formData = rawFormData === undefined && expandAllBranches ? {} : rawFormData;
|
|
281
|
+
const discriminator = getDiscriminatorFieldFromSchema(schema);
|
|
282
|
+
anyOrOneOf = anyOrOneOf.map((s) => {
|
|
283
|
+
return resolveAllReferences(s, rootSchema);
|
|
284
|
+
});
|
|
285
|
+
// Call this to trigger the set of isValid() calls that the schema parser will need
|
|
286
|
+
const option = getFirstMatchingOption(validator, formData, anyOrOneOf, rootSchema, discriminator);
|
|
287
|
+
if (expandAllBranches) {
|
|
288
|
+
return anyOrOneOf.map((item) => mergeSchemas(remaining, item));
|
|
289
|
+
}
|
|
290
|
+
schema = mergeSchemas(remaining, anyOrOneOf[option]);
|
|
291
|
+
}
|
|
292
|
+
return [schema];
|
|
293
|
+
}
|
|
294
|
+
/** Resolves dependencies within a schema and its 'anyOf/oneOf' children. Passes the `expandAllBranches` flag down to
|
|
295
|
+
* the `resolveAnyOrOneOfSchema()` and `processDependencies()` helper calls.
|
|
296
|
+
*
|
|
297
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
298
|
+
* @param schema - The schema for which resolving a dependency is desired
|
|
299
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
300
|
+
* @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
|
|
301
|
+
* as a list of schemas
|
|
302
|
+
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
303
|
+
* @returns - The list of schemas with their dependencies resolved
|
|
304
|
+
*/
|
|
305
|
+
export function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) {
|
|
306
|
+
// Drop the dependencies from the source schema.
|
|
307
|
+
const { dependencies } = schema, remainingSchema = __rest(schema, ["dependencies"]);
|
|
308
|
+
const resolvedSchemas = resolveAnyOrOneOfSchemas(validator, remainingSchema, rootSchema, expandAllBranches, formData);
|
|
309
|
+
return resolvedSchemas.flatMap((resolvedSchema) => processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData));
|
|
310
|
+
}
|
|
311
|
+
/** Processes all the `dependencies` recursively into the list of `resolvedSchema`s as needed. Passes the
|
|
312
|
+
* `expandAllBranches` flag down to the `withDependentSchema()` and the recursive `processDependencies()` helper calls.
|
|
313
|
+
*
|
|
314
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
315
|
+
* @param dependencies - The set of dependencies that needs to be processed
|
|
316
|
+
* @param resolvedSchema - The schema for which processing dependencies is desired
|
|
317
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
318
|
+
* @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
|
|
319
|
+
* as a list of schemas
|
|
320
|
+
* @param [formData] - The current formData, if any, to assist retrieving a schema
|
|
321
|
+
* @returns - The schema with the `dependencies` resolved into it
|
|
322
|
+
*/
|
|
323
|
+
export function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) {
|
|
324
|
+
let schemas = [resolvedSchema];
|
|
325
|
+
// Process dependencies updating the local schema properties as appropriate.
|
|
326
|
+
for (const dependencyKey in dependencies) {
|
|
327
|
+
// Skip this dependency if its trigger property is not present.
|
|
328
|
+
if (!expandAllBranches && get(formData, [dependencyKey]) === undefined) {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
// Skip this dependency if it is not included in the schema (such as when dependencyKey is itself a hidden dependency.)
|
|
332
|
+
if (resolvedSchema.properties && !(dependencyKey in resolvedSchema.properties)) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(dependencyKey, dependencies);
|
|
336
|
+
if (Array.isArray(dependencyValue)) {
|
|
337
|
+
schemas[0] = withDependentProperties(resolvedSchema, dependencyValue);
|
|
338
|
+
}
|
|
339
|
+
else if (isObject(dependencyValue)) {
|
|
340
|
+
schemas = withDependentSchema(validator, resolvedSchema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData);
|
|
341
|
+
}
|
|
342
|
+
return schemas.flatMap((schema) => processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, formData));
|
|
343
|
+
}
|
|
344
|
+
return schemas;
|
|
345
|
+
}
|
|
346
|
+
/** Updates a schema with additionally required properties added
|
|
347
|
+
*
|
|
348
|
+
* @param schema - The schema for which resolving a dependent properties is desired
|
|
349
|
+
* @param [additionallyRequired] - An optional array of additionally required names
|
|
350
|
+
* @returns - The schema with the additional required values merged in
|
|
351
|
+
*/
|
|
352
|
+
export function withDependentProperties(schema, additionallyRequired) {
|
|
353
|
+
if (!additionallyRequired) {
|
|
354
|
+
return schema;
|
|
355
|
+
}
|
|
356
|
+
const required = Array.isArray(schema.required)
|
|
357
|
+
? Array.from(new Set([...schema.required, ...additionallyRequired]))
|
|
358
|
+
: additionallyRequired;
|
|
359
|
+
return Object.assign(Object.assign({}, schema), { required: required });
|
|
360
|
+
}
|
|
361
|
+
/** Merges a dependent schema into the `schema` dealing with oneOfs and references. Passes the `expandAllBranches` flag
|
|
362
|
+
* down to the `retrieveSchemaInternal()`, `resolveReference()` and `withExactlyOneSubschema()` helper calls.
|
|
363
|
+
*
|
|
364
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
365
|
+
* @param schema - The schema for which resolving a dependent schema is desired
|
|
366
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
367
|
+
* @param dependencyKey - The key name of the dependency
|
|
368
|
+
* @param dependencyValue - The potentially dependent schema
|
|
369
|
+
* @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
|
|
370
|
+
* as a list of schemas
|
|
371
|
+
* @param [formData]- The current formData to assist retrieving a schema
|
|
372
|
+
* @returns - The list of schemas with the dependent schema resolved into them
|
|
373
|
+
*/
|
|
374
|
+
export function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) {
|
|
375
|
+
const dependentSchemas = retrieveSchemaInternal(validator, dependencyValue, rootSchema, formData, expandAllBranches);
|
|
376
|
+
return dependentSchemas.flatMap((dependent) => {
|
|
377
|
+
const { oneOf } = dependent, dependentSchema = __rest(dependent, ["oneOf"]);
|
|
378
|
+
schema = mergeSchemas(schema, dependentSchema);
|
|
379
|
+
// Since it does not contain oneOf, we return the original schema.
|
|
380
|
+
if (oneOf === undefined) {
|
|
381
|
+
return schema;
|
|
382
|
+
}
|
|
383
|
+
// Resolve $refs inside oneOf.
|
|
384
|
+
const resolvedOneOfs = oneOf.map((subschema) => {
|
|
385
|
+
if (typeof subschema === 'boolean' || !(REF_KEY in subschema)) {
|
|
386
|
+
return [subschema];
|
|
387
|
+
}
|
|
388
|
+
return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData);
|
|
389
|
+
});
|
|
390
|
+
const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs);
|
|
391
|
+
return allPermutations.flatMap((resolvedOneOf) => withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, expandAllBranches, formData));
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/** Returns a list of `schema`s with the best choice from the `oneOf` options merged into it. If `expandAllBranches` is
|
|
395
|
+
* true, then a list of schemas for ALL options are retrieved and returned. Passes the `expandAllBranches` flag down to
|
|
396
|
+
* the `retrieveSchemaInternal()` helper call.
|
|
397
|
+
*
|
|
398
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used to validate oneOf options
|
|
399
|
+
* @param schema - The schema for which resolving a oneOf subschema is desired
|
|
400
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
401
|
+
* @param dependencyKey - The key name of the oneOf dependency
|
|
402
|
+
* @param oneOf - The list of schemas representing the oneOf options
|
|
403
|
+
* @param expandAllBranches - Flag, if true, will return all possible branches of conditions, any/oneOf and dependencies
|
|
404
|
+
* as a list of schemas
|
|
405
|
+
* @param [formData] - The current formData to assist retrieving a schema
|
|
406
|
+
* @returns - Either an array containing the best matching option or all options if `expandAllBranches` is true
|
|
407
|
+
*/
|
|
408
|
+
export function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) {
|
|
409
|
+
const validSubschemas = oneOf.filter((subschema) => {
|
|
410
|
+
if (typeof subschema === 'boolean' || !subschema || !subschema.properties) {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
const { [dependencyKey]: conditionPropertySchema } = subschema.properties;
|
|
414
|
+
if (conditionPropertySchema) {
|
|
415
|
+
const conditionSchema = {
|
|
416
|
+
type: 'object',
|
|
417
|
+
properties: {
|
|
418
|
+
[dependencyKey]: conditionPropertySchema,
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
return validator.isValid(conditionSchema, formData, rootSchema) || expandAllBranches;
|
|
422
|
+
}
|
|
423
|
+
return false;
|
|
424
|
+
});
|
|
425
|
+
if (!expandAllBranches && validSubschemas.length !== 1) {
|
|
426
|
+
console.warn("ignoring oneOf in dependencies because there isn't exactly one subschema that is valid");
|
|
427
|
+
return [schema];
|
|
428
|
+
}
|
|
429
|
+
return validSubschemas.flatMap((s) => {
|
|
430
|
+
const subschema = s;
|
|
431
|
+
const [dependentSubschema] = splitKeyElementFromObject(dependencyKey, subschema.properties);
|
|
432
|
+
const dependentSchema = Object.assign(Object.assign({}, subschema), { properties: dependentSubschema });
|
|
433
|
+
const schemas = retrieveSchemaInternal(validator, dependentSchema, rootSchema, formData, expandAllBranches);
|
|
434
|
+
return schemas.map((s) => mergeSchemas(schema, s));
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
//# sourceMappingURL=retrieveSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieveSchema.js","sourceRoot":"","sources":["../../src/schema/retrieveSchema.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,UAAuB,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,MAAM,EACN,UAAU,EACV,OAAO,EACP,cAAc,EACd,SAAS,GACV,MAAM,cAAc,CAAC;AACtB,OAAO,oBAAoB,EAAE,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,+BAA+B,MAAM,oCAAoC,CAAC;AACjF,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAE3C,OAAO,sBAAsB,MAAM,0BAA0B,CAAC;AAE9D;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAIpC,SAAiC,EAAE,MAAS,EAAE,aAAgB,EAAO,EAAE,WAAe;IACtF,OAAO,sBAAsB,CAAU,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACxF,CAAC;AAED;;;;;;;;;;;GAW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CAAC;SACd;QACD,MAAM,EAAE,CAAC,aAAa,CAAC,EAAE,uBAAuB,EAAE,GAAG,SAAS,CAAC,UAAU,CAAC;QAC1E,IAAI,uBAAuB,EAAE;YAC3B,MAAM,eAAe,GAAM;gBACzB,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,CAAC,aAAa,CAAC,EAAE,uBAAuB;iBACzC;aACG,CAAC;YACP,OAAO,SAAS,CAAC,OAAO,CAAC,eAAe,EAAE,QAAQ,EAAE,UAAU,CAAC,IAAI,iBAAiB,CAAC;SACtF;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,iBAAiB,IAAI,eAAgB,CAAC,MAAM,KAAK,CAAC,EAAE;QACvD,OAAO,CAAC,IAAI,CAAC,wFAAwF,CAAC,CAAC;QACvG,OAAO,CAAC,MAAM,CAAC,CAAC;KACjB;IACD,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QACnC,MAAM,SAAS,GAAM,CAAM,CAAC;QAC5B,MAAM,CAAC,kBAAkB,CAAC,GAAG,yBAAyB,CAAC,aAAa,EAAE,SAAS,CAAC,UAA+B,CAAC,CAAC;QACjH,MAAM,eAAe,mCAAQ,SAAS,KAAE,UAAU,EAAE,kBAAkB,GAAE,CAAC;QACzE,MAAM,OAAO,GAAG,sBAAsB,CACpC,SAAS,EACT,eAAe,EACf,UAAU,EACV,QAAQ,EACR,iBAAiB,CAClB,CAAC;QACF,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAM,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types';
|
|
2
|
+
/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the new
|
|
3
|
+
* schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the nature
|
|
4
|
+
* of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the old schema
|
|
5
|
+
* that are non-existent in the new schema are set to `undefined`. The data sanitization process has the following flow:
|
|
6
|
+
*
|
|
7
|
+
* - If the new schema is an object that contains a `properties` object then:
|
|
8
|
+
* - Create a `removeOldSchemaData` object, setting each key in the `oldSchema.properties` having `data` to undefined
|
|
9
|
+
* - Create an empty `nestedData` object for use in the key filtering below:
|
|
10
|
+
* - Iterate over each key in the `newSchema.properties` as follows:
|
|
11
|
+
* - Get the `formValue` of the key from the `data`
|
|
12
|
+
* - Get the `oldKeySchema` and `newKeyedSchema` for the key, defaulting to `{}` when it doesn't exist
|
|
13
|
+
* - Retrieve the schema for any refs within each `oldKeySchema` and/or `newKeySchema`
|
|
14
|
+
* - 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:
|
|
15
|
+
* - If `removeOldSchemaData` has an entry for the key, delete it since the new schema has the same property
|
|
16
|
+
* - If type of the key in the new schema is `object`:
|
|
17
|
+
* - Store the value from the recursive `sanitizeDataForNewSchema` call in `nestedData[key]`
|
|
18
|
+
* - Otherwise, check for default or const values:
|
|
19
|
+
* - Get the old and new `default` values from the schema and check:
|
|
20
|
+
* - If the new `default` value does not match the form value:
|
|
21
|
+
* - If the old `default` value DOES match the form value, then:
|
|
22
|
+
* - Replace `removeOldSchemaData[key]` with the new `default`
|
|
23
|
+
* - Otherwise, if the new schema is `readOnly` then replace `removeOldSchemaData[key]` with undefined
|
|
24
|
+
* - Get the old and new `const` values from the schema and check:
|
|
25
|
+
* - If the new `const` value does not match the form value:
|
|
26
|
+
* - If the old `const` value DOES match the form value, then:
|
|
27
|
+
* - Replace `removeOldSchemaData[key]` with the new `const`
|
|
28
|
+
* - Otherwise, replace `removeOldSchemaData[key]` with undefined
|
|
29
|
+
* - Once all keys have been processed, return an object built as follows:
|
|
30
|
+
* - `{ ...removeOldSchemaData, ...nestedData, ...pick(data, keysToKeep) }`
|
|
31
|
+
* - If the new and old schema types are array and the `data` is an array then:
|
|
32
|
+
* - If the type of the old and new schema `items` are a non-array objects:
|
|
33
|
+
* - Retrieve the schema for any refs within each `oldKeySchema.items` and/or `newKeySchema.items`
|
|
34
|
+
* - If the `type`s of both items are the same (or the old does not have a type):
|
|
35
|
+
* - If the type is "object", then:
|
|
36
|
+
* - For each element in the `data` recursively sanitize the data, stopping at `maxItems` if specified
|
|
37
|
+
* - Otherwise, just return the `data` removing any values after `maxItems` if it is set
|
|
38
|
+
* - If the type of the old and new schema `items` are booleans of the same value, return `data` as is
|
|
39
|
+
* - Otherwise return `undefined`
|
|
40
|
+
*
|
|
41
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
|
|
42
|
+
* @param rootSchema - The root JSON schema of the entire form
|
|
43
|
+
* @param [newSchema] - The new schema for which the data is being sanitized
|
|
44
|
+
* @param [oldSchema] - The old schema from which the data originated
|
|
45
|
+
* @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined
|
|
46
|
+
* @returns - The new form data, with all the fields uniquely associated with the old schema set
|
|
47
|
+
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
48
|
+
*/
|
|
49
|
+
export default function sanitizeDataForNewSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, newSchema?: S, oldSchema?: S, data?: any): T;
|