@rjsf/utils
Advanced tools
Comparing version 5.13.0 to 5.13.1
@@ -24,4 +24,9 @@ import guessType from './guessType'; | ||
} | ||
if (Array.isArray(type) && type.length === 2 && type.includes('null')) { | ||
type = type.find((type) => type !== 'null'); | ||
if (Array.isArray(type)) { | ||
if (type.length === 2 && type.includes('null')) { | ||
type = type.find((type) => type !== 'null'); | ||
} | ||
else { | ||
type = type[0]; | ||
} | ||
} | ||
@@ -28,0 +33,0 @@ return type; |
@@ -52,2 +52,3 @@ import allowAdditionalItems from './allowAdditionalItems'; | ||
import withIdRefPrefix from './withIdRefPrefix'; | ||
import getOptionMatchingSimpleDiscriminator from './getOptionMatchingSimpleDiscriminator'; | ||
export * from './types'; | ||
@@ -58,2 +59,2 @@ export * from './enums'; | ||
export * from './schema'; | ||
export { allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createErrorHandler, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, ErrorSchemaBuilder, findSchemaDefinition, getDiscriminatorFieldFromSchema, getInputProps, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, hashForSchema, helpId, isConstant, isCustomWidget, isFixedItems, isObject, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toErrorList, toErrorSchema, unwrapErrorHandler, utcToLocal, validationDataMerge, withIdRefPrefix, }; | ||
export { allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createErrorHandler, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, ErrorSchemaBuilder, findSchemaDefinition, getDiscriminatorFieldFromSchema, getInputProps, getOptionMatchingSimpleDiscriminator, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, hashForSchema, helpId, isConstant, isCustomWidget, isFixedItems, isObject, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toErrorList, toErrorSchema, unwrapErrorHandler, utcToLocal, validationDataMerge, withIdRefPrefix, }; |
@@ -52,2 +52,3 @@ import allowAdditionalItems from './allowAdditionalItems'; | ||
import withIdRefPrefix from './withIdRefPrefix'; | ||
import getOptionMatchingSimpleDiscriminator from './getOptionMatchingSimpleDiscriminator'; | ||
export * from './types'; | ||
@@ -58,3 +59,3 @@ export * from './enums'; | ||
export * from './schema'; | ||
export { allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createErrorHandler, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, ErrorSchemaBuilder, findSchemaDefinition, getDiscriminatorFieldFromSchema, getInputProps, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, hashForSchema, helpId, isConstant, isCustomWidget, isFixedItems, isObject, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toErrorList, toErrorSchema, unwrapErrorHandler, utcToLocal, validationDataMerge, withIdRefPrefix, }; | ||
export { allowAdditionalItems, ariaDescribedByIds, asNumber, canExpand, createErrorHandler, createSchemaUtils, dataURItoBlob, deepEquals, descriptionId, englishStringTranslator, enumOptionsDeselectValue, enumOptionsIndexForValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, errorId, examplesId, ErrorSchemaBuilder, findSchemaDefinition, getDiscriminatorFieldFromSchema, getInputProps, getOptionMatchingSimpleDiscriminator, getSchemaType, getSubmitButtonOptions, getTemplate, getUiOptions, getWidget, guessType, hasWidget, hashForSchema, helpId, isConstant, isCustomWidget, isFixedItems, isObject, labelValue, localToUTC, mergeDefaultsWithFormData, mergeObjects, mergeSchemas, optionId, optionsList, orderProperties, pad, parseDateString, rangeSpec, replaceStringParameters, schemaRequiresTrueValue, shouldRender, titleId, toConstant, toDateString, toErrorList, toErrorSchema, unwrapErrorHandler, utcToLocal, validationDataMerge, withIdRefPrefix, }; | ||
//# sourceMappingURL=index.js.map |
@@ -17,3 +17,4 @@ import forEach from 'lodash/forEach'; | ||
function parseSchema(validator, recurseList, rootSchema, schema) { | ||
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, undefined, true); | ||
const recurseRefs = []; | ||
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, undefined, true, recurseRefs); | ||
schemas.forEach((schema) => { | ||
@@ -23,3 +24,3 @@ const sameSchemaIndex = recurseList.findIndex((item) => isEqual(item, schema)); | ||
recurseList.push(schema); | ||
const allOptions = resolveAnyOrOneOfSchemas(validator, schema, rootSchema, true); | ||
const allOptions = resolveAnyOrOneOfSchemas(validator, schema, rootSchema, true, recurseRefs); | ||
allOptions.forEach((s) => { | ||
@@ -26,0 +27,0 @@ if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) { |
import get from 'lodash/get'; | ||
import has from 'lodash/has'; | ||
import isNumber from 'lodash/isNumber'; | ||
import isObject from 'lodash/isObject'; | ||
@@ -12,2 +13,3 @@ import isString from 'lodash/isString'; | ||
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema'; | ||
import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator'; | ||
/** A junk option used to determine when the getFirstMatchingOption call really matches an option rather than returning | ||
@@ -117,4 +119,8 @@ * the first item | ||
const resolvedOptions = options.map((option) => { | ||
return resolveAllReferences(option, rootSchema); | ||
return resolveAllReferences(option, rootSchema, []); | ||
}); | ||
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField); | ||
if (isNumber(simpleDiscriminatorMatch)) { | ||
return simpleDiscriminatorMatch; | ||
} | ||
// Reduce the array of options down to a list of the indexes that are considered matching options | ||
@@ -121,0 +127,0 @@ const allValidIndexes = resolvedOptions.reduce((validList, option, index) => { |
@@ -146,3 +146,3 @@ import { __rest } from "tslib"; | ||
else if (DEPENDENCIES_KEY in schema) { | ||
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, formData); | ||
const resolvedSchema = resolveDependencies(validator, schema, rootSchema, false, [], formData); | ||
schemaToCompute = resolvedSchema[0]; // pick the first element from resolve dependencies | ||
@@ -222,12 +222,9 @@ } | ||
} | ||
let formDataRequired; | ||
if (isObject(formData)) { | ||
formDataRequired = []; | ||
Object.keys(formData) | ||
.filter((key) => !schema.properties || !schema.properties[key]) | ||
.forEach((key) => { | ||
keys.add(key); | ||
formDataRequired.push(key); | ||
}); | ||
} | ||
const formDataRequired = []; | ||
Object.keys(formData) | ||
.filter((key) => !schema.properties || !schema.properties[key]) | ||
.forEach((key) => { | ||
keys.add(key); | ||
formDataRequired.push(key); | ||
}); | ||
keys.forEach((key) => { | ||
@@ -244,3 +241,3 @@ var _a; | ||
}); | ||
// Since these are additional properties we don’t need to add the `experimental_defaultFormStateBehavior` prop | ||
// Since these are additional properties we don't need to add the `experimental_defaultFormStateBehavior` prop | ||
maybeAddDefaultToObject(objectDefaults, key, computedDefault, includeUndefinedValues, required, formDataRequired); | ||
@@ -247,0 +244,0 @@ }); |
import { __rest } from "tslib"; | ||
import get from 'lodash/get'; | ||
import has from 'lodash/has'; | ||
import isNumber from 'lodash/isNumber'; | ||
import { PROPERTIES_KEY } from '../constants'; | ||
import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator'; | ||
/** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data. | ||
@@ -23,2 +25,6 @@ * Deprecated, use `getFirstMatchingOption()` instead. | ||
} | ||
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField); | ||
if (isNumber(simpleDiscriminatorMatch)) { | ||
return simpleDiscriminatorMatch; | ||
} | ||
for (let i = 0; i < options.length; i++) { | ||
@@ -25,0 +31,0 @@ const option = options[i]; |
@@ -25,3 +25,3 @@ import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types'; | ||
*/ | ||
export declare function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, formData?: T): S[]; | ||
export declare function resolveCondition<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[]; | ||
/** Given a list of lists of allOf, anyOf or oneOf values, create a list of lists of all permutations of the values. The | ||
@@ -54,5 +54,6 @@ * `listOfLists` is expected to be all resolved values of the 1st...nth schemas within an `allOf`, `anyOf` or `oneOf`. | ||
*/ | ||
export declare function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, formData?: T): S[]; | ||
/** Resolves references within a schema and then returns the `retrieveSchemaInternal()` of the resolved schema. Passes | ||
* the `expandAllBranches` flag down to the `retrieveSchemaInternal()` helper call. | ||
export declare function resolveSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[]; | ||
/** Resolves all references within a schema and then returns the `retrieveSchemaInternal()` if the resolved schema is | ||
* actually different than the original. Passes the `expandAllBranches` flag down to the `retrieveSchemaInternal()` | ||
* helper call. | ||
* | ||
@@ -67,10 +68,11 @@ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs | ||
*/ | ||
export declare function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, formData?: T): S[]; | ||
/** Resolves all references within a schema's properties and array items. | ||
export declare function resolveReference<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[]; | ||
/** Resolves all references within the schema itself as well as any of its properties and array items. | ||
* | ||
* @param schema - The schema for which resolving all references is desired | ||
* @param rootSchema - The root schema that will be forwarded to all the APIs | ||
* @returns - given schema will all references resolved | ||
* @param recurseList - List of $refs already resolved to prevent recursion | ||
* @returns - given schema will all references resolved or the original schema if no internal `$refs` were resolved | ||
*/ | ||
export declare function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(schema: S, rootSchema: S): S; | ||
export declare function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(schema: S, rootSchema: S, recurseList: string[]): S; | ||
/** Creates new 'properties' items for each key in the `formData` | ||
@@ -99,3 +101,3 @@ * | ||
*/ | ||
export declare function retrieveSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, rawFormData?: T, expandAllBranches?: boolean): S[]; | ||
export declare function retrieveSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, rawFormData?: T, expandAllBranches?: boolean, recurseList?: string[]): S[]; | ||
/** Resolves an `anyOf` or `oneOf` within a schema (if present) to the list of schemas returned from | ||
@@ -113,3 +115,3 @@ * `retrieveSchemaInternal()` for the best matching option. If `expandAllBranches` is true, then a list of schemas for ALL | ||
*/ | ||
export declare function resolveAnyOrOneOfSchemas<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, rawFormData?: T): S[]; | ||
export declare function resolveAnyOrOneOfSchemas<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], rawFormData?: T): S[]; | ||
/** Resolves dependencies within a schema and its 'anyOf/oneOf' children. Passes the `expandAllBranches` flag down to | ||
@@ -126,3 +128,3 @@ * the `resolveAnyOrOneOfSchema()` and `processDependencies()` helper calls. | ||
*/ | ||
export declare function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, formData?: T): S[]; | ||
export declare function resolveDependencies<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[]; | ||
/** Processes all the `dependencies` recursively into the list of `resolvedSchema`s as needed. Passes the | ||
@@ -140,3 +142,3 @@ * `expandAllBranches` flag down to the `withDependentSchema()` and the recursive `processDependencies()` helper calls. | ||
*/ | ||
export declare function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, dependencies: S['dependencies'], resolvedSchema: S, rootSchema: S, expandAllBranches: boolean, formData?: T): S[]; | ||
export declare function processDependencies<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, dependencies: S['dependencies'], resolvedSchema: S, rootSchema: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[]; | ||
/** Updates a schema with additionally required properties added | ||
@@ -162,3 +164,3 @@ * | ||
*/ | ||
export declare function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, dependencyKey: string, dependencyValue: S, expandAllBranches: boolean, formData?: T): S[]; | ||
export declare function withDependentSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, dependencyKey: string, dependencyValue: S, expandAllBranches: boolean, recurseList: string[], formData?: T): S[]; | ||
/** Returns a list of `schema`s with the best choice from the `oneOf` options merged into it. If `expandAllBranches` is | ||
@@ -178,2 +180,2 @@ * true, then a list of schemas for ALL options are retrieved and returned. Passes the `expandAllBranches` flag down to | ||
*/ | ||
export declare function withExactlyOneSubschema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, dependencyKey: string, oneOf: S['oneOf'], expandAllBranches: boolean, formData?: T): S[]; | ||
export declare function withExactlyOneSubschema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, dependencyKey: string, oneOf: S['oneOf'], expandAllBranches: boolean, recurseList: string[], formData?: T): S[]; |
import { __rest } from "tslib"; | ||
import get from 'lodash/get'; | ||
import isEqual from 'lodash/isEqual'; | ||
import set from 'lodash/set'; | ||
@@ -39,3 +40,3 @@ import times from 'lodash/times'; | ||
*/ | ||
export function resolveCondition(validator, schema, rootSchema, expandAllBranches, formData) { | ||
export function resolveCondition(validator, schema, rootSchema, expandAllBranches, recurseList, formData) { | ||
const { if: expression, then, else: otherwise } = schema, resolvedSchemaLessConditional = __rest(schema, ["if", "then", "else"]); | ||
@@ -47,6 +48,6 @@ const conditionValue = validator.isValid(expression, formData || {}, rootSchema); | ||
if (then && typeof then !== 'boolean') { | ||
schemas = schemas.concat(retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches)); | ||
schemas = schemas.concat(retrieveSchemaInternal(validator, then, rootSchema, formData, expandAllBranches, recurseList)); | ||
} | ||
if (otherwise && typeof otherwise !== 'boolean') { | ||
schemas = schemas.concat(retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches)); | ||
schemas = schemas.concat(retrieveSchemaInternal(validator, otherwise, rootSchema, formData, expandAllBranches, recurseList)); | ||
} | ||
@@ -57,3 +58,3 @@ } | ||
if (conditionalSchema && typeof conditionalSchema !== 'boolean') { | ||
schemas = schemas.concat(retrieveSchemaInternal(validator, conditionalSchema, rootSchema, formData, expandAllBranches)); | ||
schemas = schemas.concat(retrieveSchemaInternal(validator, conditionalSchema, rootSchema, formData, expandAllBranches, recurseList)); | ||
} | ||
@@ -64,3 +65,3 @@ } | ||
} | ||
return resolvedSchemas.flatMap((s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches)); | ||
return resolvedSchemas.flatMap((s) => retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList)); | ||
} | ||
@@ -106,14 +107,17 @@ /** Given a list of lists of allOf, anyOf or oneOf values, create a list of lists of all permutations of the values. The | ||
*/ | ||
export function resolveSchema(validator, schema, rootSchema, expandAllBranches, formData) { | ||
if (REF_KEY in schema) { | ||
return resolveReference(validator, schema, rootSchema, expandAllBranches, formData); | ||
export function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData) { | ||
const updatedSchemas = resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData); | ||
if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) { | ||
// return the updatedSchemas array if it has either multiple schemas within it | ||
// OR the first schema is not the same as the original schema | ||
return updatedSchemas; | ||
} | ||
if (DEPENDENCIES_KEY in schema) { | ||
const resolvedSchemas = resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData); | ||
const resolvedSchemas = resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData); | ||
return resolvedSchemas.flatMap((s) => { | ||
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches); | ||
return retrieveSchemaInternal(validator, s, rootSchema, formData, expandAllBranches, recurseList); | ||
}); | ||
} | ||
if (ALL_OF_KEY in schema && Array.isArray(schema.allOf)) { | ||
const allOfSchemaElements = schema.allOf.map((allOfSubschema) => retrieveSchemaInternal(validator, allOfSubschema, rootSchema, formData, expandAllBranches)); | ||
const allOfSchemaElements = schema.allOf.map((allOfSubschema) => retrieveSchemaInternal(validator, allOfSubschema, rootSchema, formData, expandAllBranches, recurseList)); | ||
const allPermutations = getAllPermutationsOfXxxOf(allOfSchemaElements); | ||
@@ -125,4 +129,5 @@ return allPermutations.map((permutation) => (Object.assign(Object.assign({}, schema), { allOf: permutation }))); | ||
} | ||
/** Resolves references within a schema and then returns the `retrieveSchemaInternal()` of the resolved schema. Passes | ||
* the `expandAllBranches` flag down to the `retrieveSchemaInternal()` helper call. | ||
/** Resolves all references within a schema and then returns the `retrieveSchemaInternal()` if the resolved schema is | ||
* actually different than the original. Passes the `expandAllBranches` flag down to the `retrieveSchemaInternal()` | ||
* helper call. | ||
* | ||
@@ -137,17 +142,21 @@ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs | ||
*/ | ||
export function resolveReference(validator, schema, rootSchema, expandAllBranches, formData) { | ||
// Drop the $ref property of the source schema. | ||
const { $ref } = schema, localSchema = __rest(schema, ["$ref"]); | ||
// Retrieve the referenced schema definition. | ||
const refSchema = findSchemaDefinition($ref, rootSchema); | ||
// Update referenced schema definition with local schema properties. | ||
return retrieveSchemaInternal(validator, Object.assign(Object.assign({}, refSchema), localSchema), rootSchema, formData, expandAllBranches); | ||
export function resolveReference(validator, schema, rootSchema, expandAllBranches, recurseList, formData) { | ||
const updatedSchema = resolveAllReferences(schema, rootSchema, recurseList); | ||
if (updatedSchema !== schema) { | ||
// Only call this if the schema was actually changed by the `resolveAllReferences()` function | ||
return retrieveSchemaInternal(validator, updatedSchema, rootSchema, formData, expandAllBranches, recurseList); | ||
} | ||
return [schema]; | ||
} | ||
/** Resolves all references within a schema's properties and array items. | ||
/** Resolves all references within the schema itself as well as any of its properties and array items. | ||
* | ||
* @param schema - The schema for which resolving all references is desired | ||
* @param rootSchema - The root schema that will be forwarded to all the APIs | ||
* @returns - given schema will all references resolved | ||
* @param recurseList - List of $refs already resolved to prevent recursion | ||
* @returns - given schema will all references resolved or the original schema if no internal `$refs` were resolved | ||
*/ | ||
export function resolveAllReferences(schema, rootSchema) { | ||
export function resolveAllReferences(schema, rootSchema, recurseList) { | ||
if (!isObject(schema)) { | ||
return schema; | ||
} | ||
let resolvedSchema = schema; | ||
@@ -157,2 +166,7 @@ // resolve top level ref | ||
const { $ref } = resolvedSchema, localSchema = __rest(resolvedSchema, ["$ref"]); | ||
// Check for a recursive reference and stop the loop | ||
if (recurseList.includes($ref)) { | ||
return resolvedSchema; | ||
} | ||
recurseList.push($ref); | ||
// Retrieve the referenced schema definition. | ||
@@ -164,3 +178,3 @@ const refSchema = findSchemaDefinition($ref, rootSchema); | ||
const updatedProps = transform(resolvedSchema[PROPERTIES_KEY], (result, value, key) => { | ||
result[key] = resolveAllReferences(value, rootSchema); | ||
result[key] = resolveAllReferences(value, rootSchema, recurseList); | ||
}, {}); | ||
@@ -172,5 +186,5 @@ resolvedSchema = Object.assign(Object.assign({}, resolvedSchema), { [PROPERTIES_KEY]: updatedProps }); | ||
typeof resolvedSchema.items !== 'boolean') { | ||
resolvedSchema = Object.assign(Object.assign({}, resolvedSchema), { items: resolveAllReferences(resolvedSchema.items, rootSchema) }); | ||
resolvedSchema = Object.assign(Object.assign({}, resolvedSchema), { items: resolveAllReferences(resolvedSchema.items, rootSchema, recurseList) }); | ||
} | ||
return resolvedSchema; | ||
return isEqual(schema, resolvedSchema) ? schema : resolvedSchema; | ||
} | ||
@@ -234,11 +248,11 @@ /** Creates new 'properties' items for each key in the `formData` | ||
*/ | ||
export function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false) { | ||
export function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expandAllBranches = false, recurseList = []) { | ||
if (!isObject(schema)) { | ||
return [{}]; | ||
} | ||
const resolvedSchemas = resolveSchema(validator, schema, rootSchema, expandAllBranches, rawFormData); | ||
const resolvedSchemas = resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, rawFormData); | ||
return resolvedSchemas.flatMap((s) => { | ||
let resolvedSchema = s; | ||
if (IF_KEY in resolvedSchema) { | ||
return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, rawFormData); | ||
return resolveCondition(validator, resolvedSchema, rootSchema, expandAllBranches, recurseList, rawFormData); | ||
} | ||
@@ -281,3 +295,3 @@ if (ALL_OF_KEY in resolvedSchema) { | ||
*/ | ||
export function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, rawFormData) { | ||
export function resolveAnyOrOneOfSchemas(validator, schema, rootSchema, expandAllBranches, recurseList, rawFormData) { | ||
let anyOrOneOf; | ||
@@ -296,3 +310,3 @@ const { oneOf, anyOf } = schema, remaining = __rest(schema, ["oneOf", "anyOf"]); | ||
anyOrOneOf = anyOrOneOf.map((s) => { | ||
return resolveAllReferences(s, rootSchema); | ||
return resolveAllReferences(s, rootSchema, recurseList); | ||
}); | ||
@@ -319,7 +333,7 @@ // Call this to trigger the set of isValid() calls that the schema parser will need | ||
*/ | ||
export function resolveDependencies(validator, schema, rootSchema, expandAllBranches, formData) { | ||
export function resolveDependencies(validator, schema, rootSchema, expandAllBranches, recurseList, formData) { | ||
// Drop the dependencies from the source schema. | ||
const { dependencies } = schema, remainingSchema = __rest(schema, ["dependencies"]); | ||
const resolvedSchemas = resolveAnyOrOneOfSchemas(validator, remainingSchema, rootSchema, expandAllBranches, formData); | ||
return resolvedSchemas.flatMap((resolvedSchema) => processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData)); | ||
const resolvedSchemas = resolveAnyOrOneOfSchemas(validator, remainingSchema, rootSchema, expandAllBranches, recurseList, formData); | ||
return resolvedSchemas.flatMap((resolvedSchema) => processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData)); | ||
} | ||
@@ -338,3 +352,3 @@ /** Processes all the `dependencies` recursively into the list of `resolvedSchema`s as needed. Passes the | ||
*/ | ||
export function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) { | ||
export function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData) { | ||
let schemas = [resolvedSchema]; | ||
@@ -356,5 +370,5 @@ // Process dependencies updating the local schema properties as appropriate. | ||
else if (isObject(dependencyValue)) { | ||
schemas = withDependentSchema(validator, resolvedSchema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData); | ||
schemas = withDependentSchema(validator, resolvedSchema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData); | ||
} | ||
return schemas.flatMap((schema) => processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, formData)); | ||
return schemas.flatMap((schema) => processDependencies(validator, remainingDependencies, schema, rootSchema, expandAllBranches, recurseList, formData)); | ||
} | ||
@@ -391,4 +405,4 @@ return schemas; | ||
*/ | ||
export function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, formData) { | ||
const dependentSchemas = retrieveSchemaInternal(validator, dependencyValue, rootSchema, formData, expandAllBranches); | ||
export function withDependentSchema(validator, schema, rootSchema, dependencyKey, dependencyValue, expandAllBranches, recurseList, formData) { | ||
const dependentSchemas = retrieveSchemaInternal(validator, dependencyValue, rootSchema, formData, expandAllBranches, recurseList); | ||
return dependentSchemas.flatMap((dependent) => { | ||
@@ -406,6 +420,6 @@ const { oneOf } = dependent, dependentSchema = __rest(dependent, ["oneOf"]); | ||
} | ||
return resolveReference(validator, subschema, rootSchema, expandAllBranches, formData); | ||
return resolveReference(validator, subschema, rootSchema, expandAllBranches, recurseList, formData); | ||
}); | ||
const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs); | ||
return allPermutations.flatMap((resolvedOneOf) => withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, expandAllBranches, formData)); | ||
return allPermutations.flatMap((resolvedOneOf) => withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, resolvedOneOf, expandAllBranches, recurseList, formData)); | ||
}); | ||
@@ -427,3 +441,3 @@ } | ||
*/ | ||
export function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, formData) { | ||
export function withExactlyOneSubschema(validator, schema, rootSchema, dependencyKey, oneOf, expandAllBranches, recurseList, formData) { | ||
const validSubschemas = oneOf.filter((subschema) => { | ||
@@ -453,3 +467,3 @@ if (typeof subschema === 'boolean' || !subschema || !subschema.properties) { | ||
const dependentSchema = Object.assign(Object.assign({}, subschema), { properties: dependentSubschema }); | ||
const schemas = retrieveSchemaInternal(validator, dependentSchema, rootSchema, formData, expandAllBranches); | ||
const schemas = retrieveSchemaInternal(validator, dependentSchema, rootSchema, formData, expandAllBranches, recurseList); | ||
return schemas.map((s) => mergeSchemas(schema, s)); | ||
@@ -456,0 +470,0 @@ }); |
@@ -396,3 +396,3 @@ import type { ButtonHTMLAttributes, ChangeEvent, ComponentType, HTMLAttributes, ReactElement, ReactNode, StyleHTMLAttributes } from 'react'; | ||
/** The value change event handler; Can be called with a new value to change the value for this field */ | ||
onChange: FieldProps['onChange']; | ||
onChange: FieldProps<T, S, F>['onChange']; | ||
/** The key change event handler; Called when the key associated with a field is changed for an additionalProperty */ | ||
@@ -399,0 +399,0 @@ onKeyChange: (value: string) => () => void; |
{ | ||
"name": "@rjsf/utils", | ||
"version": "5.13.0", | ||
"version": "5.13.1", | ||
"main": "dist/index.js", | ||
@@ -47,24 +47,24 @@ "module": "lib/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.22.9", | ||
"@babel/core": "^7.22.17", | ||
"@babel/plugin-proposal-class-properties": "^7.18.6", | ||
"@babel/plugin-proposal-optional-chaining": "^7.21.0", | ||
"@babel/preset-env": "^7.22.9", | ||
"@babel/preset-react": "^7.22.5", | ||
"@babel/preset-typescript": "^7.22.5", | ||
"@babel/preset-env": "^7.22.15", | ||
"@babel/preset-react": "^7.22.15", | ||
"@babel/preset-typescript": "^7.22.15", | ||
"@types/json-schema": "^7.0.12", | ||
"@types/json-schema-merge-allof": "^0.6.1", | ||
"@types/lodash": "^4.14.196", | ||
"@types/react": "^17.0.62", | ||
"@types/lodash": "^4.14.198", | ||
"@types/react": "^17.0.65", | ||
"@types/react-is": "^17.0.4", | ||
"@types/react-test-renderer": "^17.0.2", | ||
"babel-jest": "^29.6.2", | ||
"@types/react-test-renderer": "^17.0.3", | ||
"babel-jest": "^29.6.4", | ||
"deep-freeze-es6": "^1.4.1", | ||
"esbuild": "^0.18.19", | ||
"eslint": "^8.46.0", | ||
"jest": "^29.6.2", | ||
"jest-environment-jsdom": "^29.6.1", | ||
"esbuild": "^0.18.20", | ||
"eslint": "^8.48.0", | ||
"jest": "^29.6.4", | ||
"jest-environment-jsdom": "^29.6.4", | ||
"react": "^17.0.2", | ||
"react-test-renderer": "^17.0.2", | ||
"rimraf": "^5.0.1", | ||
"rollup": "^3.27.2", | ||
"rollup": "^3.29.0", | ||
"typescript": "^4.9.5" | ||
@@ -90,3 +90,3 @@ }, | ||
"license": "Apache-2.0", | ||
"gitHead": "588b1c063095f75278585838cbca9b20252e13c9" | ||
"gitHead": "a8039b4b7b872606a14e28885ba4e7faea9e2bfa" | ||
} |
@@ -32,4 +32,8 @@ import guessType from './guessType'; | ||
if (Array.isArray(type) && type.length === 2 && type.includes('null')) { | ||
type = type.find((type) => type !== 'null'); | ||
if (Array.isArray(type)) { | ||
if (type.length === 2 && type.includes('null')) { | ||
type = type.find((type) => type !== 'null'); | ||
} else { | ||
type = type[0]; | ||
} | ||
} | ||
@@ -36,0 +40,0 @@ |
@@ -52,2 +52,3 @@ import allowAdditionalItems from './allowAdditionalItems'; | ||
import withIdRefPrefix from './withIdRefPrefix'; | ||
import getOptionMatchingSimpleDiscriminator from './getOptionMatchingSimpleDiscriminator'; | ||
@@ -83,2 +84,3 @@ export * from './types'; | ||
getInputProps, | ||
getOptionMatchingSimpleDiscriminator, | ||
getSchemaType, | ||
@@ -85,0 +87,0 @@ getSubmitButtonOptions, |
@@ -25,3 +25,4 @@ import forEach from 'lodash/forEach'; | ||
) { | ||
const schemas = retrieveSchemaInternal<T, S, F>(validator, schema, rootSchema, undefined, true); | ||
const recurseRefs: string[] = []; | ||
const schemas = retrieveSchemaInternal<T, S, F>(validator, schema, rootSchema, undefined, true, recurseRefs); | ||
schemas.forEach((schema) => { | ||
@@ -31,3 +32,3 @@ const sameSchemaIndex = recurseList.findIndex((item) => isEqual(item, schema)); | ||
recurseList.push(schema); | ||
const allOptions = resolveAnyOrOneOfSchemas<T, S, F>(validator, schema, rootSchema, true); | ||
const allOptions = resolveAnyOrOneOfSchemas<T, S, F>(validator, schema, rootSchema, true, recurseRefs); | ||
allOptions.forEach((s) => { | ||
@@ -34,0 +35,0 @@ if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) { |
import get from 'lodash/get'; | ||
import has from 'lodash/has'; | ||
import isNumber from 'lodash/isNumber'; | ||
import isObject from 'lodash/isObject'; | ||
@@ -14,2 +15,3 @@ import isString from 'lodash/isString'; | ||
import getDiscriminatorFieldFromSchema from '../getDiscriminatorFieldFromSchema'; | ||
import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator'; | ||
@@ -149,4 +151,10 @@ /** A junk option used to determine when the getFirstMatchingOption call really matches an option rather than returning | ||
const resolvedOptions = options.map((option) => { | ||
return resolveAllReferences(option, rootSchema); | ||
return resolveAllReferences<S>(option, rootSchema, []); | ||
}); | ||
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField); | ||
if (isNumber(simpleDiscriminatorMatch)) { | ||
return simpleDiscriminatorMatch; | ||
} | ||
// Reduce the array of options down to a list of the indexes that are considered matching options | ||
@@ -153,0 +161,0 @@ const allValidIndexes = resolvedOptions.reduce((validList: number[], option, index: number) => { |
@@ -188,3 +188,3 @@ import get from 'lodash/get'; | ||
} else if (DEPENDENCIES_KEY in schema) { | ||
const resolvedSchema = resolveDependencies<T, S, F>(validator, schema, rootSchema, false, formData); | ||
const resolvedSchema = resolveDependencies<T, S, F>(validator, schema, rootSchema, false, [], formData); | ||
schemaToCompute = resolvedSchema[0]; // pick the first element from resolve dependencies | ||
@@ -291,12 +291,9 @@ } else if (isFixedItems(schema)) { | ||
} | ||
let formDataRequired: string[]; | ||
if (isObject(formData)) { | ||
formDataRequired = []; | ||
Object.keys(formData as GenericObjectType) | ||
.filter((key) => !schema.properties || !schema.properties[key]) | ||
.forEach((key) => { | ||
keys.add(key); | ||
formDataRequired.push(key); | ||
}); | ||
} | ||
const formDataRequired: string[] = []; | ||
Object.keys(formData as GenericObjectType) | ||
.filter((key) => !schema.properties || !schema.properties[key]) | ||
.forEach((key) => { | ||
keys.add(key); | ||
formDataRequired.push(key); | ||
}); | ||
keys.forEach((key) => { | ||
@@ -312,3 +309,3 @@ const computedDefault = computeDefaults(validator, additionalPropertiesSchema as S, { | ||
}); | ||
// Since these are additional properties we don’t need to add the `experimental_defaultFormStateBehavior` prop | ||
// Since these are additional properties we don't need to add the `experimental_defaultFormStateBehavior` prop | ||
maybeAddDefaultToObject<T>( | ||
@@ -315,0 +312,0 @@ objectDefaults as GenericObjectType, |
import get from 'lodash/get'; | ||
import has from 'lodash/has'; | ||
import isNumber from 'lodash/isNumber'; | ||
import { PROPERTIES_KEY } from '../constants'; | ||
import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types'; | ||
import getOptionMatchingSimpleDiscriminator from '../getOptionMatchingSimpleDiscriminator'; | ||
@@ -35,2 +37,8 @@ /** Given the `formData` and list of `options`, attempts to find the index of the option that best matches the data. | ||
} | ||
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField); | ||
if (isNumber(simpleDiscriminatorMatch)) { | ||
return simpleDiscriminatorMatch; | ||
} | ||
for (let i = 0; i < options.length; i++) { | ||
@@ -37,0 +45,0 @@ const option = options[i]; |
import get from 'lodash/get'; | ||
import isEqual from 'lodash/isEqual'; | ||
import set from 'lodash/set'; | ||
@@ -62,2 +63,3 @@ import times from 'lodash/times'; | ||
expandAllBranches: boolean, | ||
recurseList: string[], | ||
formData?: T | ||
@@ -73,3 +75,3 @@ ): S[] { | ||
schemas = schemas.concat( | ||
retrieveSchemaInternal<T, S, F>(validator, then as S, rootSchema, formData, expandAllBranches) | ||
retrieveSchemaInternal<T, S, F>(validator, then as S, rootSchema, formData, expandAllBranches, recurseList) | ||
); | ||
@@ -79,3 +81,3 @@ } | ||
schemas = schemas.concat( | ||
retrieveSchemaInternal<T, S, F>(validator, otherwise as S, rootSchema, formData, expandAllBranches) | ||
retrieveSchemaInternal<T, S, F>(validator, otherwise as S, rootSchema, formData, expandAllBranches, recurseList) | ||
); | ||
@@ -87,3 +89,10 @@ } | ||
schemas = schemas.concat( | ||
retrieveSchemaInternal<T, S, F>(validator, conditionalSchema as S, rootSchema, formData, expandAllBranches) | ||
retrieveSchemaInternal<T, S, F>( | ||
validator, | ||
conditionalSchema as S, | ||
rootSchema, | ||
formData, | ||
expandAllBranches, | ||
recurseList | ||
) | ||
); | ||
@@ -96,3 +105,3 @@ } | ||
return resolvedSchemas.flatMap((s) => | ||
retrieveSchemaInternal<T, S, F>(validator, s, rootSchema, formData, expandAllBranches) | ||
retrieveSchemaInternal<T, S, F>(validator, s, rootSchema, formData, expandAllBranches, recurseList) | ||
); | ||
@@ -149,11 +158,29 @@ } | ||
expandAllBranches: boolean, | ||
recurseList: string[], | ||
formData?: T | ||
): S[] { | ||
if (REF_KEY in schema) { | ||
return resolveReference<T, S, F>(validator, schema, rootSchema, expandAllBranches, formData); | ||
const updatedSchemas = resolveReference<T, S, F>( | ||
validator, | ||
schema, | ||
rootSchema, | ||
expandAllBranches, | ||
recurseList, | ||
formData | ||
); | ||
if (updatedSchemas.length > 1 || updatedSchemas[0] !== schema) { | ||
// return the updatedSchemas array if it has either multiple schemas within it | ||
// OR the first schema is not the same as the original schema | ||
return updatedSchemas; | ||
} | ||
if (DEPENDENCIES_KEY in schema) { | ||
const resolvedSchemas = resolveDependencies<T, S, F>(validator, schema, rootSchema, expandAllBranches, formData); | ||
const resolvedSchemas = resolveDependencies<T, S, F>( | ||
validator, | ||
schema, | ||
rootSchema, | ||
expandAllBranches, | ||
recurseList, | ||
formData | ||
); | ||
return resolvedSchemas.flatMap((s) => { | ||
return retrieveSchemaInternal<T, S, F>(validator, s, rootSchema, formData, expandAllBranches); | ||
return retrieveSchemaInternal<T, S, F>(validator, s, rootSchema, formData, expandAllBranches, recurseList); | ||
}); | ||
@@ -163,3 +190,10 @@ } | ||
const allOfSchemaElements: S[][] = schema.allOf.map((allOfSubschema) => | ||
retrieveSchemaInternal<T, S, F>(validator, allOfSubschema as S, rootSchema, formData, expandAllBranches) | ||
retrieveSchemaInternal<T, S, F>( | ||
validator, | ||
allOfSubschema as S, | ||
rootSchema, | ||
formData, | ||
expandAllBranches, | ||
recurseList | ||
) | ||
); | ||
@@ -173,4 +207,5 @@ const allPermutations = getAllPermutationsOfXxxOf<S>(allOfSchemaElements); | ||
/** Resolves references within a schema and then returns the `retrieveSchemaInternal()` of the resolved schema. Passes | ||
* the `expandAllBranches` flag down to the `retrieveSchemaInternal()` helper call. | ||
/** Resolves all references within a schema and then returns the `retrieveSchemaInternal()` if the resolved schema is | ||
* actually different than the original. Passes the `expandAllBranches` flag down to the `retrieveSchemaInternal()` | ||
* helper call. | ||
* | ||
@@ -190,25 +225,35 @@ * @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs | ||
expandAllBranches: boolean, | ||
recurseList: string[], | ||
formData?: T | ||
): S[] { | ||
// Drop the $ref property of the source schema. | ||
const { $ref, ...localSchema } = schema; | ||
// Retrieve the referenced schema definition. | ||
const refSchema = findSchemaDefinition<S>($ref, rootSchema); | ||
// Update referenced schema definition with local schema properties. | ||
return retrieveSchemaInternal<T, S, F>( | ||
validator, | ||
{ ...refSchema, ...localSchema }, | ||
rootSchema, | ||
formData, | ||
expandAllBranches | ||
); | ||
const updatedSchema = resolveAllReferences<S>(schema, rootSchema, recurseList); | ||
if (updatedSchema !== schema) { | ||
// Only call this if the schema was actually changed by the `resolveAllReferences()` function | ||
return retrieveSchemaInternal<T, S, F>( | ||
validator, | ||
updatedSchema, | ||
rootSchema, | ||
formData, | ||
expandAllBranches, | ||
recurseList | ||
); | ||
} | ||
return [schema]; | ||
} | ||
/** Resolves all references within a schema's properties and array items. | ||
/** Resolves all references within the schema itself as well as any of its properties and array items. | ||
* | ||
* @param schema - The schema for which resolving all references is desired | ||
* @param rootSchema - The root schema that will be forwarded to all the APIs | ||
* @returns - given schema will all references resolved | ||
* @param recurseList - List of $refs already resolved to prevent recursion | ||
* @returns - given schema will all references resolved or the original schema if no internal `$refs` were resolved | ||
*/ | ||
export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(schema: S, rootSchema: S): S { | ||
export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>( | ||
schema: S, | ||
rootSchema: S, | ||
recurseList: string[] | ||
): S { | ||
if (!isObject(schema)) { | ||
return schema; | ||
} | ||
let resolvedSchema: S = schema; | ||
@@ -218,2 +263,7 @@ // resolve top level ref | ||
const { $ref, ...localSchema } = resolvedSchema; | ||
// Check for a recursive reference and stop the loop | ||
if (recurseList.includes($ref!)) { | ||
return resolvedSchema; | ||
} | ||
recurseList.push($ref!); | ||
// Retrieve the referenced schema definition. | ||
@@ -228,3 +278,3 @@ const refSchema = findSchemaDefinition<S>($ref, rootSchema); | ||
(result, value, key: string) => { | ||
result[key] = resolveAllReferences(value as S, rootSchema); | ||
result[key] = resolveAllReferences(value as S, rootSchema, recurseList); | ||
}, | ||
@@ -241,6 +291,9 @@ {} as RJSFSchema | ||
) { | ||
resolvedSchema = { ...resolvedSchema, items: resolveAllReferences(resolvedSchema.items as S, rootSchema) }; | ||
resolvedSchema = { | ||
...resolvedSchema, | ||
items: resolveAllReferences(resolvedSchema.items as S, rootSchema, recurseList), | ||
}; | ||
} | ||
return resolvedSchema; | ||
return isEqual(schema, resolvedSchema) ? schema : resolvedSchema; | ||
} | ||
@@ -325,11 +378,32 @@ | ||
F extends FormContextType = any | ||
>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, rawFormData?: T, expandAllBranches = false): S[] { | ||
>( | ||
validator: ValidatorType<T, S, F>, | ||
schema: S, | ||
rootSchema: S, | ||
rawFormData?: T, | ||
expandAllBranches = false, | ||
recurseList: string[] = [] | ||
): S[] { | ||
if (!isObject(schema)) { | ||
return [{} as S]; | ||
} | ||
const resolvedSchemas = resolveSchema<T, S, F>(validator, schema, rootSchema, expandAllBranches, rawFormData); | ||
const resolvedSchemas = resolveSchema<T, S, F>( | ||
validator, | ||
schema, | ||
rootSchema, | ||
expandAllBranches, | ||
recurseList, | ||
rawFormData | ||
); | ||
return resolvedSchemas.flatMap((s: S) => { | ||
let resolvedSchema = s; | ||
if (IF_KEY in resolvedSchema) { | ||
return resolveCondition<T, S, F>(validator, resolvedSchema, rootSchema, expandAllBranches, rawFormData as T); | ||
return resolveCondition<T, S, F>( | ||
validator, | ||
resolvedSchema, | ||
rootSchema, | ||
expandAllBranches, | ||
recurseList, | ||
rawFormData as T | ||
); | ||
} | ||
@@ -378,3 +452,10 @@ if (ALL_OF_KEY in resolvedSchema) { | ||
F extends FormContextType = any | ||
>(validator: ValidatorType<T, S, F>, schema: S, rootSchema: S, expandAllBranches: boolean, rawFormData?: T) { | ||
>( | ||
validator: ValidatorType<T, S, F>, | ||
schema: S, | ||
rootSchema: S, | ||
expandAllBranches: boolean, | ||
recurseList: string[], | ||
rawFormData?: T | ||
) { | ||
let anyOrOneOf: S[] | undefined; | ||
@@ -392,3 +473,3 @@ const { oneOf, anyOf, ...remaining } = schema; | ||
anyOrOneOf = anyOrOneOf.map((s) => { | ||
return resolveAllReferences(s, rootSchema); | ||
return resolveAllReferences(s, rootSchema, recurseList); | ||
}); | ||
@@ -421,2 +502,3 @@ // Call this to trigger the set of isValid() calls that the schema parser will need | ||
expandAllBranches: boolean, | ||
recurseList: string[], | ||
formData?: T | ||
@@ -431,6 +513,15 @@ ): S[] { | ||
expandAllBranches, | ||
recurseList, | ||
formData | ||
); | ||
return resolvedSchemas.flatMap((resolvedSchema) => | ||
processDependencies<T, S, F>(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, formData) | ||
processDependencies<T, S, F>( | ||
validator, | ||
dependencies, | ||
resolvedSchema, | ||
rootSchema, | ||
expandAllBranches, | ||
recurseList, | ||
formData | ||
) | ||
); | ||
@@ -457,2 +548,3 @@ } | ||
expandAllBranches: boolean, | ||
recurseList: string[], | ||
formData?: T | ||
@@ -485,2 +577,3 @@ ): S[] { | ||
expandAllBranches, | ||
recurseList, | ||
formData | ||
@@ -490,3 +583,11 @@ ); | ||
return schemas.flatMap((schema) => | ||
processDependencies<T, S, F>(validator, remainingDependencies, schema, rootSchema, expandAllBranches, formData) | ||
processDependencies<T, S, F>( | ||
validator, | ||
remainingDependencies, | ||
schema, | ||
rootSchema, | ||
expandAllBranches, | ||
recurseList, | ||
formData | ||
) | ||
); | ||
@@ -536,2 +637,3 @@ } | ||
expandAllBranches: boolean, | ||
recurseList: string[], | ||
formData?: T | ||
@@ -544,3 +646,4 @@ ): S[] { | ||
formData, | ||
expandAllBranches | ||
expandAllBranches, | ||
recurseList | ||
); | ||
@@ -559,3 +662,3 @@ return dependentSchemas.flatMap((dependent) => { | ||
} | ||
return resolveReference<T, S, F>(validator, subschema as S, rootSchema, expandAllBranches, formData); | ||
return resolveReference<T, S, F>(validator, subschema as S, rootSchema, expandAllBranches, recurseList, formData); | ||
}); | ||
@@ -571,2 +674,3 @@ const allPermutations = getAllPermutationsOfXxxOf(resolvedOneOfs); | ||
expandAllBranches, | ||
recurseList, | ||
formData | ||
@@ -603,2 +707,3 @@ ) | ||
expandAllBranches: boolean, | ||
recurseList: string[], | ||
formData?: T | ||
@@ -636,3 +741,4 @@ ): S[] { | ||
formData, | ||
expandAllBranches | ||
expandAllBranches, | ||
recurseList | ||
); | ||
@@ -639,0 +745,0 @@ return schemas.map((s) => mergeSchemas(schema, s) as S); |
@@ -443,3 +443,3 @@ import type { | ||
/** The value change event handler; Can be called with a new value to change the value for this field */ | ||
onChange: FieldProps['onChange']; | ||
onChange: FieldProps<T, S, F>['onChange']; | ||
/** The key change event handler; Called when the key associated with a field is changed for an additionalProperty */ | ||
@@ -446,0 +446,0 @@ onKeyChange: (value: string) => () => void; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1498496
300
18819