@rjsf/utils 6.7.1 → 6.10.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.cjs +521 -425
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +520 -424
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +579 -333
- package/lib/ErrorSchemaBuilder.d.ts +8 -7
- package/lib/ErrorSchemaBuilder.d.ts.map +1 -0
- package/lib/ErrorSchemaBuilder.js +29 -27
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/SelectedOptionDescription.d.ts +2 -1
- package/lib/SelectedOptionDescription.d.ts.map +1 -0
- package/lib/SelectedOptionDescription.js +6 -7
- package/lib/SelectedOptionDescription.js.map +1 -1
- package/lib/allowAdditionalItems.d.ts +2 -1
- package/lib/allowAdditionalItems.d.ts.map +1 -0
- package/lib/allowAdditionalItems.js +1 -1
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.d.ts +1 -0
- package/lib/asNumber.d.ts.map +1 -0
- package/lib/asNumber.js +1 -1
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +2 -1
- package/lib/canExpand.d.ts.map +1 -0
- package/lib/canExpand.js +1 -1
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.d.ts +2 -1
- package/lib/constIsAjvDataReference.d.ts.map +1 -0
- package/lib/constIsAjvDataReference.js +2 -3
- package/lib/constIsAjvDataReference.js.map +1 -1
- package/lib/constants.d.ts +1 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/createErrorHandler.d.ts +2 -1
- package/lib/createErrorHandler.d.ts.map +1 -0
- package/lib/createErrorHandler.js +3 -4
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +2 -1
- package/lib/createSchemaUtils.d.ts.map +1 -0
- package/lib/createSchemaUtils.js +10 -7
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.d.ts +1 -0
- package/lib/dataURItoBlob.d.ts.map +1 -0
- package/lib/dataURItoBlob.js +1 -2
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +2 -1
- package/lib/dateRangeOptions.d.ts.map +1 -0
- package/lib/dateRangeOptions.js +1 -1
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/deepEquals.d.ts +1 -0
- package/lib/deepEquals.d.ts.map +1 -0
- package/lib/englishStringTranslator.d.ts +2 -1
- package/lib/englishStringTranslator.d.ts.map +1 -0
- package/lib/englishStringTranslator.js +1 -1
- package/lib/englishStringTranslator.js.map +1 -1
- package/lib/enumOptionSelectedValue.d.ts +2 -1
- package/lib/enumOptionSelectedValue.d.ts.map +1 -0
- package/lib/enumOptionSelectedValue.js +1 -1
- package/lib/enumOptionSelectedValue.js.map +1 -1
- package/lib/enumOptionValueDecoder.d.ts +2 -1
- package/lib/enumOptionValueDecoder.d.ts.map +1 -0
- package/lib/enumOptionValueDecoder.js +1 -1
- package/lib/enumOptionValueDecoder.js.map +1 -1
- package/lib/enumOptionValueEncoder.d.ts +2 -1
- package/lib/enumOptionValueEncoder.d.ts.map +1 -0
- package/lib/enumOptionValueEncoder.js +1 -2
- package/lib/enumOptionValueEncoder.js.map +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +2 -1
- package/lib/enumOptionsDeselectValue.d.ts.map +1 -0
- package/lib/enumOptionsDeselectValue.js +2 -2
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +2 -1
- package/lib/enumOptionsIndexForValue.d.ts.map +1 -0
- package/lib/enumOptionsIndexForValue.js +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +2 -1
- package/lib/enumOptionsIsSelected.d.ts.map +1 -0
- package/lib/enumOptionsIsSelected.js +1 -1
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.d.ts +2 -1
- package/lib/enumOptionsSelectValue.d.ts.map +1 -0
- package/lib/enumOptionsSelectValue.js +2 -3
- package/lib/enumOptionsSelectValue.js.map +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +2 -1
- package/lib/enumOptionsValueForIndex.d.ts.map +1 -0
- package/lib/enums.d.ts +1 -0
- package/lib/enums.d.ts.map +1 -0
- package/lib/findSchemaDefinition.d.ts +2 -1
- package/lib/findSchemaDefinition.d.ts.map +1 -0
- package/lib/findSchemaDefinition.js +7 -11
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.d.ts +11 -2
- package/lib/getChangedFields.d.ts.map +1 -0
- package/lib/getChangedFields.js +57 -18
- package/lib/getChangedFields.js.map +1 -1
- package/lib/getDateElementProps.d.ts +2 -1
- package/lib/getDateElementProps.d.ts.map +1 -0
- package/lib/getDecimalSeparator.d.ts +1 -0
- package/lib/getDecimalSeparator.d.ts.map +1 -0
- package/lib/getDecimalSeparator.js +1 -2
- package/lib/getDecimalSeparator.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.d.ts +2 -1
- package/lib/getDiscriminatorFieldFromSchema.d.ts.map +1 -0
- package/lib/getDiscriminatorFieldFromSchema.js +4 -5
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +2 -1
- package/lib/getInputProps.d.ts.map +1 -0
- package/lib/getInputProps.js +4 -1
- package/lib/getInputProps.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +2 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts.map +1 -0
- package/lib/getOptionMatchingSimpleDiscriminator.js +6 -6
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getOptionValueFormat.d.ts +2 -1
- package/lib/getOptionValueFormat.d.ts.map +1 -0
- package/lib/getOptionValueFormat.js +1 -2
- package/lib/getOptionValueFormat.js.map +1 -1
- package/lib/getPropertySchema.d.ts +12 -0
- package/lib/getPropertySchema.d.ts.map +1 -0
- package/lib/getPropertySchema.js +14 -0
- package/lib/getPropertySchema.js.map +1 -0
- package/lib/getSchemaType.d.ts +2 -1
- package/lib/getSchemaType.d.ts.map +1 -0
- package/lib/getSchemaType.js +1 -1
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +2 -1
- package/lib/getSubmitButtonOptions.d.ts.map +1 -0
- package/lib/getSubmitButtonOptions.js +3 -3
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +2 -1
- package/lib/getTemplate.d.ts.map +1 -0
- package/lib/getTestIds.d.ts +2 -1
- package/lib/getTestIds.d.ts.map +1 -0
- package/lib/getTestIds.js +6 -5
- package/lib/getTestIds.js.map +1 -1
- package/lib/getUiOptions.d.ts +2 -1
- package/lib/getUiOptions.d.ts.map +1 -0
- package/lib/getUiOptions.js +2 -2
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +2 -1
- package/lib/getWidget.d.ts.map +1 -0
- package/lib/getWidget.js +6 -7
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.d.ts +2 -1
- package/lib/guessType.d.ts.map +1 -0
- package/lib/hasWidget.d.ts +2 -1
- package/lib/hasWidget.d.ts.map +1 -0
- package/lib/hasWidget.js +1 -1
- package/lib/hasWidget.js.map +1 -1
- package/lib/hashForSchema.d.ts +4 -2
- package/lib/hashForSchema.d.ts.map +1 -0
- package/lib/hashForSchema.js +17 -8
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +2 -1
- package/lib/idGenerators.d.ts.map +1 -0
- package/lib/idGenerators.js +2 -3
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +93 -87
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +85 -81
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +2 -1
- package/lib/isConstant.d.ts.map +1 -0
- package/lib/isConstant.js +1 -1
- package/lib/isConstant.js.map +1 -1
- package/lib/isCustomWidget.d.ts +2 -1
- package/lib/isCustomWidget.d.ts.map +1 -0
- package/lib/isCustomWidget.js +1 -1
- package/lib/isCustomWidget.js.map +1 -1
- package/lib/isFixedItems.d.ts +2 -1
- package/lib/isFixedItems.d.ts.map +1 -0
- package/lib/isFixedItems.js +1 -1
- package/lib/isFixedItems.js.map +1 -1
- package/lib/isFormDataAvailable.d.ts +1 -0
- package/lib/isFormDataAvailable.d.ts.map +1 -0
- package/lib/isFormDataAvailable.js +7 -4
- package/lib/isFormDataAvailable.js.map +1 -1
- package/lib/isObject.d.ts +3 -1
- package/lib/isObject.d.ts.map +1 -0
- package/lib/isObject.js +8 -2
- package/lib/isObject.js.map +1 -1
- package/lib/isPlainObject.d.ts +9 -0
- package/lib/isPlainObject.d.ts.map +1 -0
- package/lib/isPlainObject.js +15 -0
- package/lib/isPlainObject.js.map +1 -0
- package/lib/isRootSchema.d.ts +2 -1
- package/lib/isRootSchema.d.ts.map +1 -0
- package/lib/isRootSchema.js +2 -2
- package/lib/isRootSchema.js.map +1 -1
- package/lib/jsonSchemaAugmentation.d.ts +1 -0
- package/lib/jsonSchemaAugmentation.d.ts.map +1 -0
- package/lib/labelValue.d.ts +1 -0
- package/lib/labelValue.d.ts.map +1 -0
- package/lib/localToUTC.d.ts +1 -0
- package/lib/localToUTC.d.ts.map +1 -0
- package/lib/logUnsupportedDefaultForEnum.d.ts +2 -1
- package/lib/logUnsupportedDefaultForEnum.d.ts.map +1 -0
- package/lib/logUnsupportedDefaultForEnum.js +1 -1
- package/lib/logUnsupportedDefaultForEnum.js.map +1 -1
- package/lib/lookupFromFormContext.d.ts +3 -2
- package/lib/lookupFromFormContext.d.ts.map +1 -0
- package/lib/lookupFromFormContext.js +4 -5
- package/lib/lookupFromFormContext.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.d.ts +1 -0
- package/lib/mergeDefaultsWithFormData.d.ts.map +1 -0
- package/lib/mergeDefaultsWithFormData.js +20 -16
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +2 -1
- package/lib/mergeObjects.d.ts.map +1 -0
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +2 -1
- package/lib/mergeSchemas.d.ts.map +1 -0
- package/lib/mergeSchemas.js +4 -5
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/nameGenerators.d.ts +2 -1
- package/lib/nameGenerators.d.ts.map +1 -0
- package/lib/noop.d.ts +5 -0
- package/lib/noop.d.ts.map +1 -0
- package/lib/noop.js +5 -0
- package/lib/noop.js.map +1 -0
- package/lib/optionsList.d.ts +2 -1
- package/lib/optionsList.d.ts.map +1 -0
- package/lib/optionsList.js +15 -15
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.d.ts +1 -0
- package/lib/orderProperties.d.ts.map +1 -0
- package/lib/pad.d.ts +1 -0
- package/lib/pad.d.ts.map +1 -0
- package/lib/parseDateString.d.ts +2 -1
- package/lib/parseDateString.d.ts.map +1 -0
- package/lib/parser/ParserValidator.d.ts +2 -1
- package/lib/parser/ParserValidator.d.ts.map +1 -0
- package/lib/parser/ParserValidator.js +8 -7
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +3 -2
- package/lib/parser/index.d.ts.map +1 -0
- package/lib/parser/index.js +1 -1
- package/lib/parser/index.js.map +1 -1
- package/lib/parser/schemaParser.d.ts +3 -2
- package/lib/parser/schemaParser.d.ts.map +1 -0
- package/lib/parser/schemaParser.js +6 -7
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/pathUtils.d.ts +77 -0
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +192 -0
- package/lib/pathUtils.js.map +1 -0
- package/lib/rangeSpec.d.ts +2 -1
- package/lib/rangeSpec.d.ts.map +1 -0
- package/lib/removeOptionalEmptyObjects.d.ts +2 -1
- package/lib/removeOptionalEmptyObjects.d.ts.map +1 -0
- package/lib/removeOptionalEmptyObjects.js +2 -2
- package/lib/removeOptionalEmptyObjects.js.map +1 -1
- package/lib/replaceStringParameters.d.ts +1 -0
- package/lib/replaceStringParameters.d.ts.map +1 -0
- package/lib/resolveUiSchema.d.ts +2 -1
- package/lib/resolveUiSchema.d.ts.map +1 -0
- package/lib/resolveUiSchema.js +6 -8
- package/lib/resolveUiSchema.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +2 -1
- package/lib/schema/findFieldInSchema.d.ts.map +1 -0
- package/lib/schema/findFieldInSchema.js +10 -11
- package/lib/schema/findFieldInSchema.js.map +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +2 -1
- package/lib/schema/findSelectedOptionInXxxOf.d.ts.map +1 -0
- package/lib/schema/findSelectedOptionInXxxOf.js +7 -7
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.d.ts +2 -1
- package/lib/schema/getClosestMatchingOption.d.ts.map +1 -0
- package/lib/schema/getClosestMatchingOption.js +18 -23
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +2 -1
- package/lib/schema/getDefaultFormState.d.ts.map +1 -0
- package/lib/schema/getDefaultFormState.js +78 -56
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +2 -1
- package/lib/schema/getDisplayLabel.d.ts.map +1 -0
- package/lib/schema/getDisplayLabel.js +7 -7
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +2 -1
- package/lib/schema/getFirstMatchingOption.d.ts.map +1 -0
- package/lib/schema/getFirstMatchingOption.js +9 -9
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +3 -2
- package/lib/schema/getFromSchema.d.ts.map +1 -0
- package/lib/schema/getFromSchema.js +10 -11
- package/lib/schema/getFromSchema.js.map +1 -1
- package/lib/schema/index.d.ts +15 -14
- package/lib/schema/index.d.ts.map +1 -0
- package/lib/schema/index.js +14 -14
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +2 -1
- package/lib/schema/isFilesArray.d.ts.map +1 -0
- package/lib/schema/isFilesArray.js +2 -2
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.d.ts +2 -1
- package/lib/schema/isMultiSelect.d.ts.map +1 -0
- package/lib/schema/isMultiSelect.js +1 -1
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +2 -1
- package/lib/schema/isSelect.d.ts.map +1 -0
- package/lib/schema/isSelect.js +2 -2
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/omitExtraData.d.ts +2 -1
- package/lib/schema/omitExtraData.d.ts.map +1 -0
- package/lib/schema/omitExtraData.js +100 -64
- package/lib/schema/omitExtraData.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +2 -1
- package/lib/schema/retrieveSchema.d.ts.map +1 -0
- package/lib/schema/retrieveSchema.js +32 -40
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +4 -3
- package/lib/schema/sanitizeDataForNewSchema.d.ts.map +1 -0
- package/lib/schema/sanitizeDataForNewSchema.js +41 -39
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/shallowAllOfMerge.d.ts +1 -0
- package/lib/schema/shallowAllOfMerge.d.ts.map +1 -0
- package/lib/schema/toPathSchema.d.ts +2 -1
- package/lib/schema/toPathSchema.d.ts.map +1 -0
- package/lib/schema/toPathSchema.js +14 -14
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +2 -1
- package/lib/schemaRequiresTrueValue.d.ts.map +1 -0
- package/lib/schemaRequiresTrueValue.js +3 -4
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shallowEquals.d.ts +1 -0
- package/lib/shallowEquals.d.ts.map +1 -0
- package/lib/shouldRender.d.ts +2 -1
- package/lib/shouldRender.d.ts.map +1 -0
- package/lib/shouldRender.js +2 -2
- package/lib/shouldRender.js.map +1 -1
- package/lib/shouldRenderOptionalField.d.ts +2 -1
- package/lib/shouldRenderOptionalField.d.ts.map +1 -0
- package/lib/shouldRenderOptionalField.js +11 -10
- package/lib/shouldRenderOptionalField.js.map +1 -1
- package/lib/toConstant.d.ts +2 -1
- package/lib/toConstant.d.ts.map +1 -0
- package/lib/toConstant.js +1 -1
- package/lib/toConstant.js.map +1 -1
- package/lib/toDateString.d.ts +2 -1
- package/lib/toDateString.d.ts.map +1 -0
- package/lib/toErrorList.d.ts +2 -1
- package/lib/toErrorList.d.ts.map +1 -0
- package/lib/toErrorList.js +20 -21
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +2 -1
- package/lib/toErrorSchema.d.ts.map +1 -0
- package/lib/toErrorSchema.js +4 -9
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/toFieldPathId.d.ts +2 -1
- package/lib/toFieldPathId.d.ts.map +1 -0
- package/lib/toFieldPathId.js +2 -2
- package/lib/toFieldPathId.js.map +1 -1
- package/lib/types.d.ts +15 -5
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +1 -1
- package/lib/types.js.map +1 -1
- package/lib/unwrapErrorHandler.d.ts +2 -1
- package/lib/unwrapErrorHandler.d.ts.map +1 -0
- package/lib/unwrapErrorHandler.js +13 -4
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/useAltDateWidgetProps.d.ts +3 -2
- package/lib/useAltDateWidgetProps.d.ts.map +1 -0
- package/lib/useAltDateWidgetProps.js +5 -5
- package/lib/useAltDateWidgetProps.js.map +1 -1
- package/lib/useDeepCompareMemo.d.ts +1 -0
- package/lib/useDeepCompareMemo.d.ts.map +1 -0
- package/lib/useDeepCompareMemo.js +1 -1
- package/lib/useDeepCompareMemo.js.map +1 -1
- package/lib/useFileWidgetProps.d.ts +1 -0
- package/lib/useFileWidgetProps.d.ts.map +1 -0
- package/lib/useFileWidgetProps.js +3 -4
- package/lib/useFileWidgetProps.js.map +1 -1
- package/lib/utcToLocal.d.ts +1 -0
- package/lib/utcToLocal.d.ts.map +1 -0
- package/lib/utcToLocal.js +1 -1
- package/lib/utcToLocal.js.map +1 -1
- package/lib/validationDataMerge.d.ts +2 -1
- package/lib/validationDataMerge.d.ts.map +1 -0
- package/lib/validationDataMerge.js +3 -4
- package/lib/validationDataMerge.js.map +1 -1
- package/lib/withIdRefPrefix.d.ts +2 -1
- package/lib/withIdRefPrefix.d.ts.map +1 -0
- package/lib/withIdRefPrefix.js +2 -2
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +5 -6
- package/src/ErrorSchemaBuilder.ts +25 -24
- package/src/SelectedOptionDescription.tsx +5 -5
- package/src/allowAdditionalItems.ts +2 -2
- package/src/asNumber.ts +1 -1
- package/src/canExpand.ts +2 -2
- package/src/constIsAjvDataReference.ts +5 -4
- package/src/createErrorHandler.ts +5 -7
- package/src/createSchemaUtils.ts +8 -10
- package/src/dateRangeOptions.ts +2 -2
- package/src/englishStringTranslator.ts +2 -2
- package/src/enumOptionSelectedValue.ts +2 -2
- package/src/enumOptionValueDecoder.ts +2 -2
- package/src/enumOptionValueEncoder.ts +2 -4
- package/src/enumOptionsDeselectValue.ts +3 -3
- package/src/enumOptionsIndexForValue.ts +2 -2
- package/src/enumOptionsIsSelected.ts +2 -2
- package/src/enumOptionsSelectValue.ts +3 -5
- package/src/enumOptionsValueForIndex.ts +1 -1
- package/src/findSchemaDefinition.ts +8 -12
- package/src/getChangedFields.ts +57 -18
- package/src/getDateElementProps.ts +1 -1
- package/src/getDiscriminatorFieldFromSchema.ts +5 -7
- package/src/getInputProps.ts +6 -2
- package/src/getOptionMatchingSimpleDiscriminator.ts +7 -7
- package/src/getOptionValueFormat.ts +1 -1
- package/src/getPropertySchema.ts +18 -0
- package/src/getSchemaType.ts +2 -2
- package/src/getSubmitButtonOptions.ts +3 -3
- package/src/getTemplate.ts +1 -1
- package/src/getTestIds.ts +7 -6
- package/src/getUiOptions.ts +3 -3
- package/src/getWidget.tsx +6 -6
- package/src/hasWidget.ts +2 -2
- package/src/hashForSchema.ts +20 -9
- package/src/idGenerators.ts +3 -5
- package/src/index.ts +99 -85
- package/src/isConstant.ts +2 -2
- package/src/isCustomWidget.ts +2 -2
- package/src/isFixedItems.ts +2 -2
- package/src/isFormDataAvailable.ts +7 -5
- package/src/isObject.ts +15 -3
- package/src/isPlainObject.ts +14 -0
- package/src/isRootSchema.ts +3 -3
- package/src/logUnsupportedDefaultForEnum.ts +2 -2
- package/src/lookupFromFormContext.ts +7 -8
- package/src/mergeDefaultsWithFormData.ts +22 -18
- package/src/mergeObjects.ts +2 -2
- package/src/mergeSchemas.ts +5 -7
- package/src/nameGenerators.ts +1 -1
- package/src/noop.ts +4 -0
- package/src/optionsList.ts +9 -9
- package/src/orderProperties.ts +1 -1
- package/src/parseDateString.ts +1 -1
- package/src/parser/ParserValidator.ts +5 -7
- package/src/parser/index.ts +2 -2
- package/src/parser/schemaParser.ts +8 -10
- package/src/pathUtils.ts +203 -0
- package/src/rangeSpec.ts +1 -1
- package/src/removeOptionalEmptyObjects.ts +3 -3
- package/src/resolveUiSchema.ts +5 -7
- package/src/schema/findFieldInSchema.ts +11 -13
- package/src/schema/findSelectedOptionInXxxOf.ts +9 -10
- package/src/schema/getClosestMatchingOption.ts +73 -83
- package/src/schema/getDefaultFormState.ts +62 -34
- package/src/schema/getDisplayLabel.ts +7 -7
- package/src/schema/getFirstMatchingOption.ts +10 -11
- package/src/schema/getFromSchema.ts +12 -14
- package/src/schema/index.ts +14 -14
- package/src/schema/isFilesArray.ts +3 -3
- package/src/schema/isMultiSelect.ts +2 -2
- package/src/schema/isSelect.ts +3 -3
- package/src/schema/omitExtraData.ts +104 -68
- package/src/schema/retrieveSchema.ts +47 -60
- package/src/schema/sanitizeDataForNewSchema.ts +42 -41
- package/src/schema/toPathSchema.ts +14 -14
- package/src/schemaRequiresTrueValue.ts +1 -1
- package/src/shouldRender.ts +3 -3
- package/src/shouldRenderOptionalField.ts +14 -14
- package/src/toConstant.ts +2 -2
- package/src/toDateString.ts +1 -1
- package/src/toErrorList.ts +22 -25
- package/src/toErrorSchema.ts +5 -11
- package/src/toFieldPathId.ts +2 -2
- package/src/types.ts +14 -5
- package/src/unwrapErrorHandler.ts +15 -6
- package/src/useAltDateWidgetProps.tsx +7 -7
- package/src/useDeepCompareMemo.ts +1 -1
- package/src/useFileWidgetProps.ts +1 -1
- package/src/utcToLocal.ts +1 -1
- package/src/validationDataMerge.ts +4 -6
- package/src/withIdRefPrefix.ts +3 -4
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/src/tsconfig.json +0 -9
package/dist/index.cjs
CHANGED
|
@@ -101,6 +101,7 @@ __export(index_exports, {
|
|
|
101
101
|
findFieldInSchema: () => findFieldInSchema,
|
|
102
102
|
findSchemaDefinition: () => findSchemaDefinition,
|
|
103
103
|
findSelectedOptionInXxxOf: () => findSelectedOptionInXxxOf,
|
|
104
|
+
getByPath: () => getByPath,
|
|
104
105
|
getChangedFields: () => getChangedFields,
|
|
105
106
|
getClosestMatchingOption: () => getClosestMatchingOption,
|
|
106
107
|
getDateElementProps: () => getDateElementProps,
|
|
@@ -114,6 +115,7 @@ __export(index_exports, {
|
|
|
114
115
|
getInputProps: () => getInputProps,
|
|
115
116
|
getOptionMatchingSimpleDiscriminator: () => getOptionMatchingSimpleDiscriminator,
|
|
116
117
|
getOptionValueFormat: () => getOptionValueFormat,
|
|
118
|
+
getPropertySchema: () => getPropertySchema,
|
|
117
119
|
getSchemaType: () => getSchemaType,
|
|
118
120
|
getSubmitButtonOptions: () => getSubmitButtonOptions,
|
|
119
121
|
getTemplate: () => getTemplate,
|
|
@@ -122,6 +124,7 @@ __export(index_exports, {
|
|
|
122
124
|
getUsedFormData: () => getUsedFormData,
|
|
123
125
|
getWidget: () => getWidget,
|
|
124
126
|
guessType: () => guessType,
|
|
127
|
+
hasByPath: () => hasByPath,
|
|
125
128
|
hasWidget: () => hasWidget,
|
|
126
129
|
hashForSchema: () => hashForSchema,
|
|
127
130
|
hashObject: () => hashObject,
|
|
@@ -134,6 +137,7 @@ __export(index_exports, {
|
|
|
134
137
|
isFormDataAvailable: () => isFormDataAvailable,
|
|
135
138
|
isMultiSelect: () => isMultiSelect,
|
|
136
139
|
isObject: () => isObject,
|
|
140
|
+
isPlainObject: () => isPlainObject,
|
|
137
141
|
isRootSchema: () => isRootSchema,
|
|
138
142
|
isSelect: () => isSelect,
|
|
139
143
|
isValueEmpty: () => isValueEmpty,
|
|
@@ -144,6 +148,7 @@ __export(index_exports, {
|
|
|
144
148
|
mergeDefaultsWithFormData: () => mergeDefaultsWithFormData,
|
|
145
149
|
mergeObjects: () => mergeObjects,
|
|
146
150
|
mergeSchemas: () => mergeSchemas,
|
|
151
|
+
noop: () => noop,
|
|
147
152
|
omitExtraData: () => omitExtraData,
|
|
148
153
|
optionId: () => optionId,
|
|
149
154
|
optionalControlsId: () => optionalControlsId,
|
|
@@ -160,6 +165,7 @@ __export(index_exports, {
|
|
|
160
165
|
sanitizeDataForNewSchema: () => sanitizeDataForNewSchema,
|
|
161
166
|
schemaParser: () => schemaParser,
|
|
162
167
|
schemaRequiresTrueValue: () => schemaRequiresTrueValue,
|
|
168
|
+
setByPath: () => setByPath,
|
|
163
169
|
shallowEquals: () => shallowEquals,
|
|
164
170
|
shouldRender: () => shouldRender,
|
|
165
171
|
shouldRenderOptionalField: () => shouldRenderOptionalField,
|
|
@@ -170,7 +176,9 @@ __export(index_exports, {
|
|
|
170
176
|
toErrorList: () => toErrorList,
|
|
171
177
|
toErrorSchema: () => toErrorSchema,
|
|
172
178
|
toFieldPathId: () => toFieldPathId,
|
|
179
|
+
toPath: () => toPath,
|
|
173
180
|
toPathSchema: () => toPathSchema,
|
|
181
|
+
unsetByPath: () => unsetByPath,
|
|
174
182
|
unwrapErrorHandler: () => unwrapErrorHandler,
|
|
175
183
|
useAltDateWidgetProps: () => useAltDateWidgetProps,
|
|
176
184
|
useDeepCompareMemo: () => useDeepCompareMemo,
|
|
@@ -186,10 +194,10 @@ function isObject(thing) {
|
|
|
186
194
|
if (typeof thing !== "object" || thing === null) {
|
|
187
195
|
return false;
|
|
188
196
|
}
|
|
189
|
-
if (typeof thing.lastModified === "number" && typeof File !== "undefined" && thing instanceof File) {
|
|
197
|
+
if ("lastModified" in thing && typeof thing.lastModified === "number" && typeof File !== "undefined" && thing instanceof File) {
|
|
190
198
|
return false;
|
|
191
199
|
}
|
|
192
|
-
if (typeof thing.getMonth === "function" && typeof Date !== "undefined" && thing instanceof Date) {
|
|
200
|
+
if ("getMonth" in thing && typeof thing.getMonth === "function" && typeof Date !== "undefined" && thing instanceof Date) {
|
|
193
201
|
return false;
|
|
194
202
|
}
|
|
195
203
|
return !Array.isArray(thing);
|
|
@@ -319,8 +327,16 @@ function canExpand(schema, uiSchema = {}, formData) {
|
|
|
319
327
|
return true;
|
|
320
328
|
}
|
|
321
329
|
|
|
330
|
+
// src/isPlainObject.ts
|
|
331
|
+
function isPlainObject(thing) {
|
|
332
|
+
if (typeof thing !== "object" || thing === null) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
const proto = Object.getPrototypeOf(thing);
|
|
336
|
+
return proto === null || proto === Object.prototype;
|
|
337
|
+
}
|
|
338
|
+
|
|
322
339
|
// src/createErrorHandler.ts
|
|
323
|
-
var import_isPlainObject = __toESM(require("lodash/isPlainObject"), 1);
|
|
324
340
|
function createErrorHandler(formData) {
|
|
325
341
|
const handler = {
|
|
326
342
|
// We store the list of errors for this node in a property named __errors
|
|
@@ -334,19 +350,15 @@ function createErrorHandler(formData) {
|
|
|
334
350
|
if (Array.isArray(formData)) {
|
|
335
351
|
return formData.reduce((acc, value, key) => ({ ...acc, [key]: createErrorHandler(value) }), handler);
|
|
336
352
|
}
|
|
337
|
-
if ((
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
(acc, key) => ({ ...acc, [key]: createErrorHandler(formObject[key]) }),
|
|
353
|
+
if (isPlainObject(formData)) {
|
|
354
|
+
return Object.keys(formData).reduce(
|
|
355
|
+
(acc, key) => ({ ...acc, [key]: createErrorHandler(formData[key]) }),
|
|
341
356
|
handler
|
|
342
357
|
);
|
|
343
358
|
}
|
|
344
359
|
return handler;
|
|
345
360
|
}
|
|
346
361
|
|
|
347
|
-
// src/createSchemaUtils.ts
|
|
348
|
-
var import_get16 = __toESM(require("lodash/get"), 1);
|
|
349
|
-
|
|
350
362
|
// src/deepEquals.ts
|
|
351
363
|
var import_fast_equals = require("fast-equals");
|
|
352
364
|
var deepEquals = (0, import_fast_equals.createCustomEqual)({
|
|
@@ -362,10 +374,6 @@ var deepEquals_default = deepEquals;
|
|
|
362
374
|
// src/findSchemaDefinition.ts
|
|
363
375
|
var import_fast_uri = __toESM(require("fast-uri"), 1);
|
|
364
376
|
var import_jsonpointer = __toESM(require("jsonpointer"), 1);
|
|
365
|
-
var import_get = __toESM(require("lodash/get"), 1);
|
|
366
|
-
var import_isEmpty = __toESM(require("lodash/isEmpty"), 1);
|
|
367
|
-
var import_isObject3 = __toESM(require("lodash/isObject"), 1);
|
|
368
|
-
var import_omit = __toESM(require("lodash/omit"), 1);
|
|
369
377
|
function findEmbeddedSchemaRecursive(schema, ref) {
|
|
370
378
|
if (ID_KEY in schema && import_fast_uri.default.equal(schema[ID_KEY], ref)) {
|
|
371
379
|
return schema;
|
|
@@ -373,14 +381,14 @@ function findEmbeddedSchemaRecursive(schema, ref) {
|
|
|
373
381
|
for (const subSchema of Object.values(schema)) {
|
|
374
382
|
if (Array.isArray(subSchema)) {
|
|
375
383
|
for (const item of subSchema) {
|
|
376
|
-
if ((
|
|
384
|
+
if (isObject(item)) {
|
|
377
385
|
const result = findEmbeddedSchemaRecursive(item, ref);
|
|
378
386
|
if (result !== void 0) {
|
|
379
387
|
return result;
|
|
380
388
|
}
|
|
381
389
|
}
|
|
382
390
|
}
|
|
383
|
-
} else if ((
|
|
391
|
+
} else if (isObject(subSchema)) {
|
|
384
392
|
const result = findEmbeddedSchemaRecursive(subSchema, ref);
|
|
385
393
|
if (result !== void 0) {
|
|
386
394
|
return result;
|
|
@@ -390,7 +398,7 @@ function findEmbeddedSchemaRecursive(schema, ref) {
|
|
|
390
398
|
return void 0;
|
|
391
399
|
}
|
|
392
400
|
function makeAllReferencesAbsolute(schema, baseURI) {
|
|
393
|
-
const currentURI =
|
|
401
|
+
const currentURI = schema[ID_KEY] ?? baseURI;
|
|
394
402
|
let result = schema;
|
|
395
403
|
if (REF_KEY in result) {
|
|
396
404
|
result = { ...result, [REF_KEY]: import_fast_uri.default.resolve(currentURI, result[REF_KEY]) };
|
|
@@ -399,20 +407,19 @@ function makeAllReferencesAbsolute(schema, baseURI) {
|
|
|
399
407
|
if (Array.isArray(subSchema)) {
|
|
400
408
|
result = {
|
|
401
409
|
...result,
|
|
402
|
-
[key]: subSchema.map((item) => (
|
|
410
|
+
[key]: subSchema.map((item) => isObject(item) ? makeAllReferencesAbsolute(item, currentURI) : item)
|
|
403
411
|
};
|
|
404
|
-
} else if ((
|
|
412
|
+
} else if (isObject(subSchema)) {
|
|
405
413
|
result = { ...result, [key]: makeAllReferencesAbsolute(subSchema, currentURI) };
|
|
406
414
|
}
|
|
407
415
|
}
|
|
408
416
|
return result;
|
|
409
417
|
}
|
|
410
418
|
function splitKeyElementFromObject(key, object) {
|
|
411
|
-
const value = object
|
|
412
|
-
const remaining = (0, import_omit.default)(object, [key]);
|
|
419
|
+
const { [key]: value, ...remaining } = object;
|
|
413
420
|
return [remaining, value];
|
|
414
421
|
}
|
|
415
|
-
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [], baseURI =
|
|
422
|
+
function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [], baseURI = rootSchema[ID_KEY]) {
|
|
416
423
|
const ref = $ref || "";
|
|
417
424
|
let current = void 0;
|
|
418
425
|
let currentBaseURI = baseURI;
|
|
@@ -432,7 +439,7 @@ function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [],
|
|
|
432
439
|
current = findEmbeddedSchemaRecursive(rootSchema, refId.replace(/\/$/, ""));
|
|
433
440
|
if (current !== void 0) {
|
|
434
441
|
currentBaseURI = current[ID_KEY];
|
|
435
|
-
if (
|
|
442
|
+
if (refAnchor.length > 0) {
|
|
436
443
|
current = import_jsonpointer.default.get(current, decodeURIComponent(refAnchor.join("#")));
|
|
437
444
|
}
|
|
438
445
|
}
|
|
@@ -462,25 +469,116 @@ function findSchemaDefinitionRecursive($ref, rootSchema = {}, recurseList = [],
|
|
|
462
469
|
}
|
|
463
470
|
return current;
|
|
464
471
|
}
|
|
465
|
-
function findSchemaDefinition($ref, rootSchema = {}, baseURI =
|
|
472
|
+
function findSchemaDefinition($ref, rootSchema = {}, baseURI = rootSchema[ID_KEY]) {
|
|
466
473
|
const recurseList = [];
|
|
467
474
|
return findSchemaDefinitionRecursive($ref, rootSchema, recurseList, baseURI);
|
|
468
475
|
}
|
|
469
476
|
|
|
470
|
-
// src/
|
|
471
|
-
var
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
477
|
+
// src/pathUtils.ts
|
|
478
|
+
var reIsIndex = /^(?:0|[1-9]\d*)$/;
|
|
479
|
+
function toPath(path) {
|
|
480
|
+
return path.split(/[.[\]]+/).filter(Boolean);
|
|
481
|
+
}
|
|
482
|
+
function normalizePath(path) {
|
|
483
|
+
return Array.isArray(path) ? path : [path];
|
|
484
|
+
}
|
|
485
|
+
function isUnsafeSegment(segment) {
|
|
486
|
+
return segment === "__proto__";
|
|
487
|
+
}
|
|
488
|
+
function isIndex(segment) {
|
|
489
|
+
return typeof segment === "number" ? Number.isInteger(segment) && segment >= 0 : reIsIndex.test(segment);
|
|
490
|
+
}
|
|
491
|
+
function isSettable(value) {
|
|
492
|
+
return value != null && (typeof value === "object" || typeof value === "function");
|
|
493
|
+
}
|
|
494
|
+
function getByPath(obj, path, defaultValue) {
|
|
495
|
+
let current;
|
|
496
|
+
if (!Array.isArray(path)) {
|
|
497
|
+
current = isSettable(obj) && Object.hasOwn(obj, path) ? obj[path] : void 0;
|
|
498
|
+
} else if (path.length === 0) {
|
|
499
|
+
current = void 0;
|
|
500
|
+
} else {
|
|
501
|
+
current = obj;
|
|
502
|
+
for (let i = 0; i < path.length; i++) {
|
|
503
|
+
const segment = path[i];
|
|
504
|
+
if (!isSettable(current) || !Object.hasOwn(current, segment)) {
|
|
505
|
+
current = void 0;
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
current = current[segment];
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return current === void 0 ? defaultValue : current;
|
|
512
|
+
}
|
|
513
|
+
function setByPath(obj, path, value, createIntermediateObjects = false) {
|
|
514
|
+
if (!isSettable(obj)) {
|
|
515
|
+
return obj;
|
|
516
|
+
}
|
|
517
|
+
if (!Array.isArray(path)) {
|
|
518
|
+
if (!isUnsafeSegment(path)) {
|
|
519
|
+
const target = obj;
|
|
520
|
+
target[path] = value;
|
|
521
|
+
}
|
|
522
|
+
return obj;
|
|
523
|
+
}
|
|
524
|
+
const segments = path;
|
|
525
|
+
if (segments.some(isUnsafeSegment)) {
|
|
526
|
+
return obj;
|
|
527
|
+
}
|
|
528
|
+
let current = obj;
|
|
529
|
+
for (let i = 0; i < segments.length; i++) {
|
|
530
|
+
const segment = segments[i];
|
|
531
|
+
if (i === segments.length - 1) {
|
|
532
|
+
current[segment] = value;
|
|
533
|
+
} else {
|
|
534
|
+
const existing = Object.hasOwn(current, segment) ? current[segment] : void 0;
|
|
535
|
+
if (isSettable(existing)) {
|
|
536
|
+
current = existing;
|
|
537
|
+
} else {
|
|
538
|
+
const next = createIntermediateObjects || !isIndex(segments[i + 1]) ? {} : [];
|
|
539
|
+
current[segment] = next;
|
|
540
|
+
if (isSettable(next)) {
|
|
541
|
+
current = next;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return obj;
|
|
547
|
+
}
|
|
548
|
+
function hasByPath(obj, path) {
|
|
549
|
+
if (!Array.isArray(path)) {
|
|
550
|
+
return isSettable(obj) && Object.hasOwn(obj, path);
|
|
551
|
+
}
|
|
552
|
+
let current = obj;
|
|
553
|
+
for (let i = 0; i < path.length; i++) {
|
|
554
|
+
if (!isSettable(current) || !Object.hasOwn(current, path[i])) {
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
current = current[path[i]];
|
|
558
|
+
}
|
|
559
|
+
return path.length > 0;
|
|
560
|
+
}
|
|
561
|
+
function unsetByPath(obj, path) {
|
|
562
|
+
const segments = normalizePath(path);
|
|
563
|
+
if (segments.length === 0) {
|
|
564
|
+
return true;
|
|
565
|
+
}
|
|
566
|
+
const parent = segments.length > 1 ? getByPath(obj, segments.slice(0, -1)) : obj;
|
|
567
|
+
if (parent == null) {
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
try {
|
|
571
|
+
return Reflect.deleteProperty(parent, segments[segments.length - 1]);
|
|
572
|
+
} catch {
|
|
573
|
+
return false;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
476
576
|
|
|
477
577
|
// src/getDiscriminatorFieldFromSchema.ts
|
|
478
|
-
var import_get2 = __toESM(require("lodash/get"), 1);
|
|
479
|
-
var import_isString = __toESM(require("lodash/isString"), 1);
|
|
480
578
|
function getDiscriminatorFieldFromSchema(schema) {
|
|
481
579
|
let discriminator;
|
|
482
|
-
const maybeString = (
|
|
483
|
-
if (
|
|
580
|
+
const maybeString = getByPath(schema, DISCRIMINATOR_PATH);
|
|
581
|
+
if (typeof maybeString === "string") {
|
|
484
582
|
discriminator = maybeString;
|
|
485
583
|
} else if (maybeString !== void 0) {
|
|
486
584
|
console.warn(`Expecting discriminator to be a string, got "${typeof maybeString}" instead`);
|
|
@@ -488,16 +586,6 @@ function getDiscriminatorFieldFromSchema(schema) {
|
|
|
488
586
|
return discriminator;
|
|
489
587
|
}
|
|
490
588
|
|
|
491
|
-
// src/schema/retrieveSchema.ts
|
|
492
|
-
var import_flattenDeep = __toESM(require("lodash/flattenDeep"), 1);
|
|
493
|
-
var import_get5 = __toESM(require("lodash/get"), 1);
|
|
494
|
-
var import_isEmpty2 = __toESM(require("lodash/isEmpty"), 1);
|
|
495
|
-
var import_merge = __toESM(require("lodash/merge"), 1);
|
|
496
|
-
var import_set = __toESM(require("lodash/set"), 1);
|
|
497
|
-
var import_times = __toESM(require("lodash/times"), 1);
|
|
498
|
-
var import_transform = __toESM(require("lodash/transform"), 1);
|
|
499
|
-
var import_uniq = __toESM(require("lodash/uniq"), 1);
|
|
500
|
-
|
|
501
589
|
// src/guessType.ts
|
|
502
590
|
function guessType(value) {
|
|
503
591
|
if (Array.isArray(value)) {
|
|
@@ -521,9 +609,6 @@ function guessType(value) {
|
|
|
521
609
|
return "string";
|
|
522
610
|
}
|
|
523
611
|
|
|
524
|
-
// src/mergeSchemas.ts
|
|
525
|
-
var import_union = __toESM(require("lodash/union"), 1);
|
|
526
|
-
|
|
527
612
|
// src/getSchemaType.ts
|
|
528
613
|
function getSchemaType(schema) {
|
|
529
614
|
let { type } = schema;
|
|
@@ -554,7 +639,7 @@ function mergeSchemas(obj1, obj2) {
|
|
|
554
639
|
if (obj1 && key in obj1 && isObject(right)) {
|
|
555
640
|
accumulator[key] = mergeSchemas(left, right);
|
|
556
641
|
} else if (obj1 && obj2 && (getSchemaType(obj1) === "object" || getSchemaType(obj2) === "object") && key === REQUIRED_KEY && Array.isArray(left) && Array.isArray(right)) {
|
|
557
|
-
accumulator[key] =
|
|
642
|
+
accumulator[key] = [.../* @__PURE__ */ new Set([...left, ...right])];
|
|
558
643
|
} else {
|
|
559
644
|
accumulator[key] = right;
|
|
560
645
|
}
|
|
@@ -566,27 +651,27 @@ function mergeSchemas(obj1, obj2) {
|
|
|
566
651
|
return result;
|
|
567
652
|
}
|
|
568
653
|
|
|
569
|
-
// src/
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
654
|
+
// src/getPropertySchema.ts
|
|
655
|
+
function getPropertySchema(schema, property) {
|
|
656
|
+
return schema?.[PROPERTIES_KEY]?.[property] ?? {};
|
|
657
|
+
}
|
|
573
658
|
|
|
574
659
|
// src/getOptionMatchingSimpleDiscriminator.ts
|
|
575
|
-
var import_get3 = __toESM(require("lodash/get"), 1);
|
|
576
660
|
function getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField) {
|
|
577
661
|
if (formData && discriminatorField) {
|
|
578
|
-
const value = (
|
|
662
|
+
const value = getByPath(formData, discriminatorField);
|
|
579
663
|
if (value === void 0) {
|
|
580
664
|
return void 0;
|
|
581
665
|
}
|
|
582
666
|
for (let i = 0; i < options.length; i += 1) {
|
|
583
667
|
const option = options[i];
|
|
584
|
-
const discriminator = (
|
|
668
|
+
const discriminator = getPropertySchema(option, discriminatorField);
|
|
585
669
|
if (discriminator.type !== "object" && discriminator.type !== "array") {
|
|
586
670
|
if (discriminator.const === value) {
|
|
587
671
|
return i;
|
|
588
672
|
}
|
|
589
|
-
|
|
673
|
+
const enumValues = discriminator.enum;
|
|
674
|
+
if (enumValues?.includes(value)) {
|
|
590
675
|
return i;
|
|
591
676
|
}
|
|
592
677
|
}
|
|
@@ -601,14 +686,14 @@ function getFirstMatchingOption(validator, formData, options, rootSchema, discri
|
|
|
601
686
|
return 0;
|
|
602
687
|
}
|
|
603
688
|
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
604
|
-
if (
|
|
689
|
+
if (typeof simpleDiscriminatorMatch === "number") {
|
|
605
690
|
return simpleDiscriminatorMatch;
|
|
606
691
|
}
|
|
607
692
|
for (let i = 0; i < options.length; i += 1) {
|
|
608
693
|
const option = options[i];
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
const
|
|
694
|
+
const discriminator = discriminatorField ? option[PROPERTIES_KEY]?.[discriminatorField] : void 0;
|
|
695
|
+
if (discriminatorField && discriminator !== void 0) {
|
|
696
|
+
const value = getByPath(formData, discriminatorField);
|
|
612
697
|
if (validator.isValid(discriminator, value, rootSchema)) {
|
|
613
698
|
return i;
|
|
614
699
|
}
|
|
@@ -741,7 +826,7 @@ function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
741
826
|
const allPermutations = listOfLists.reduce(
|
|
742
827
|
(permutations, list) => {
|
|
743
828
|
if (list.length > 1) {
|
|
744
|
-
return list.flatMap((element) =>
|
|
829
|
+
return list.flatMap((element) => permutations.map((permutation) => [...permutation, element]));
|
|
745
830
|
}
|
|
746
831
|
permutations.forEach((permutation) => permutation.push(list[0]));
|
|
747
832
|
return permutations;
|
|
@@ -752,12 +837,9 @@ function getAllPermutationsOfXxxOf(listOfLists) {
|
|
|
752
837
|
return allPermutations;
|
|
753
838
|
}
|
|
754
839
|
function getMatchingPatternProperties(schema, key) {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
return obj;
|
|
759
|
-
},
|
|
760
|
-
{}
|
|
840
|
+
const patternProperties = schema.patternProperties ?? {};
|
|
841
|
+
return Object.fromEntries(
|
|
842
|
+
Object.entries(patternProperties).filter(([pattern]) => RegExp(pattern).test(key))
|
|
761
843
|
);
|
|
762
844
|
}
|
|
763
845
|
function resolveSchema(validator, schema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf, resolveAnyOfOrOneOfRefs) {
|
|
@@ -852,23 +934,24 @@ function resolveAllReferences(schema, rootSchema, recurseList, baseURI, resolveA
|
|
|
852
934
|
}
|
|
853
935
|
if (PROPERTIES_KEY in resolvedSchema) {
|
|
854
936
|
const childrenLists = [];
|
|
855
|
-
const updatedProps =
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
{
|
|
870
|
-
|
|
871
|
-
|
|
937
|
+
const updatedProps = {};
|
|
938
|
+
for (const [key, value] of Object.entries(resolvedSchema[PROPERTIES_KEY] ?? {})) {
|
|
939
|
+
const childList = [...recurseList];
|
|
940
|
+
updatedProps[key] = resolveAllReferences(
|
|
941
|
+
value,
|
|
942
|
+
rootSchema,
|
|
943
|
+
childList,
|
|
944
|
+
currentBaseURI,
|
|
945
|
+
resolveAnyOfOrOneOfRefs,
|
|
946
|
+
!resolveAnyOfOrOneOfRefs
|
|
947
|
+
);
|
|
948
|
+
childrenLists.push(childList);
|
|
949
|
+
}
|
|
950
|
+
for (const ref of new Set(childrenLists.flat())) {
|
|
951
|
+
if (!recurseList.includes(ref)) {
|
|
952
|
+
recurseList.push(ref);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
872
955
|
resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };
|
|
873
956
|
}
|
|
874
957
|
if (ITEMS_KEY in resolvedSchema && !Array.isArray(resolvedSchema.items) && typeof resolvedSchema.items !== "boolean") {
|
|
@@ -917,12 +1000,12 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
917
1000
|
}
|
|
918
1001
|
if (PATTERN_PROPERTIES_KEY in schema) {
|
|
919
1002
|
const matchingProperties = getMatchingPatternProperties(schema, key);
|
|
920
|
-
if (
|
|
1003
|
+
if (Object.keys(matchingProperties).length > 0) {
|
|
921
1004
|
schema.properties[key] = retrieveSchema(
|
|
922
1005
|
validator,
|
|
923
1006
|
{ [ALL_OF_KEY]: Object.values(matchingProperties) },
|
|
924
1007
|
rootSchema,
|
|
925
|
-
|
|
1008
|
+
formData[key],
|
|
926
1009
|
experimental_customMergeAllOf
|
|
927
1010
|
);
|
|
928
1011
|
schema.properties[key][ADDITIONAL_PROPERTY_FLAG] = true;
|
|
@@ -935,9 +1018,9 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
935
1018
|
if (REF_KEY in schema.additionalProperties) {
|
|
936
1019
|
additionalProperties = retrieveSchema(
|
|
937
1020
|
validator,
|
|
938
|
-
{ [REF_KEY]:
|
|
1021
|
+
{ [REF_KEY]: schema.additionalProperties[REF_KEY] },
|
|
939
1022
|
rootSchema,
|
|
940
|
-
|
|
1023
|
+
formData[key],
|
|
941
1024
|
experimental_customMergeAllOf
|
|
942
1025
|
);
|
|
943
1026
|
} else if ("type" in schema.additionalProperties) {
|
|
@@ -948,10 +1031,10 @@ function stubExistingAdditionalProperties(validator, theSchema, rootSchema, aFor
|
|
|
948
1031
|
...schema.additionalProperties
|
|
949
1032
|
};
|
|
950
1033
|
} else {
|
|
951
|
-
additionalProperties = { type: guessType(
|
|
1034
|
+
additionalProperties = { type: guessType(formData[key]) };
|
|
952
1035
|
}
|
|
953
1036
|
} else {
|
|
954
|
-
additionalProperties = { type: guessType(
|
|
1037
|
+
additionalProperties = { type: guessType(formData[key]) };
|
|
955
1038
|
}
|
|
956
1039
|
schema.properties[key] = additionalProperties;
|
|
957
1040
|
schema.properties[key][ADDITIONAL_PROPERTY_FLAG] = true;
|
|
@@ -1033,12 +1116,12 @@ function retrieveSchemaInternal(validator, schema, rootSchema, rawFormData, expa
|
|
|
1033
1116
|
resolvedSchema = Object.keys(resolvedSchema.properties).reduce(
|
|
1034
1117
|
(acc, key) => {
|
|
1035
1118
|
const matchingProperties = getMatchingPatternProperties(acc, key);
|
|
1036
|
-
if (
|
|
1119
|
+
if (Object.keys(matchingProperties).length > 0) {
|
|
1037
1120
|
acc.properties[key] = retrieveSchema(
|
|
1038
1121
|
validator,
|
|
1039
1122
|
{ allOf: [acc.properties[key], ...Object.values(matchingProperties)] },
|
|
1040
1123
|
rootSchema,
|
|
1041
|
-
(
|
|
1124
|
+
getByPath(rawFormData, key),
|
|
1042
1125
|
experimental_customMergeAllOf
|
|
1043
1126
|
);
|
|
1044
1127
|
}
|
|
@@ -1119,7 +1202,7 @@ function resolveDependencies(validator, schema, rootSchema, expandAllBranches, r
|
|
|
1119
1202
|
function processDependencies(validator, dependencies, resolvedSchema, rootSchema, expandAllBranches, recurseList, formData, experimental_customMergeAllOf) {
|
|
1120
1203
|
let schemas = [resolvedSchema];
|
|
1121
1204
|
for (const dependencyKey in dependencies) {
|
|
1122
|
-
if ((expandAllBranches || (
|
|
1205
|
+
if ((expandAllBranches || getByPath(formData, dependencyKey) !== void 0) && (!resolvedSchema.properties || dependencyKey in resolvedSchema.properties)) {
|
|
1123
1206
|
const [remainingDependencies, dependencyValue] = splitKeyElementFromObject(
|
|
1124
1207
|
dependencyKey,
|
|
1125
1208
|
dependencies
|
|
@@ -1246,14 +1329,14 @@ function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField,
|
|
|
1246
1329
|
const xxxOfs = schema[xxx].map(
|
|
1247
1330
|
(xxxOf) => retrieveSchema(validator, xxxOf, rootSchema, formData, experimental_customMergeAllOf)
|
|
1248
1331
|
);
|
|
1249
|
-
const data = (
|
|
1332
|
+
const data = getByPath(formData, selectorField);
|
|
1250
1333
|
if (data !== void 0) {
|
|
1251
1334
|
return xxxOfs.find(
|
|
1252
1335
|
(xxxOfOption) => deepEquals_default(
|
|
1253
|
-
(
|
|
1336
|
+
getByPath(
|
|
1254
1337
|
xxxOfOption,
|
|
1255
1338
|
[PROPERTIES_KEY, selectorField, DEFAULT_KEY],
|
|
1256
|
-
(
|
|
1339
|
+
getByPath(xxxOfOption, [PROPERTIES_KEY, selectorField, CONST_KEY])
|
|
1257
1340
|
),
|
|
1258
1341
|
data
|
|
1259
1342
|
)
|
|
@@ -1264,21 +1347,18 @@ function findSelectedOptionInXxxOf(validator, rootSchema, schema, fallbackField,
|
|
|
1264
1347
|
}
|
|
1265
1348
|
|
|
1266
1349
|
// src/schema/getFromSchema.ts
|
|
1267
|
-
var import_get7 = __toESM(require("lodash/get"), 1);
|
|
1268
|
-
var import_has2 = __toESM(require("lodash/has"), 1);
|
|
1269
|
-
var import_isEmpty3 = __toESM(require("lodash/isEmpty"), 1);
|
|
1270
1350
|
function getFromSchemaInternal(validator, rootSchema, schema, path, experimental_customMergeAllOf) {
|
|
1271
1351
|
let fieldSchema = schema;
|
|
1272
|
-
if ((
|
|
1352
|
+
if (hasByPath(schema, REF_KEY)) {
|
|
1273
1353
|
fieldSchema = retrieveSchema(validator, schema, rootSchema, void 0, experimental_customMergeAllOf);
|
|
1274
1354
|
}
|
|
1275
|
-
if (
|
|
1355
|
+
if (path.length === 0) {
|
|
1276
1356
|
return fieldSchema;
|
|
1277
1357
|
}
|
|
1278
|
-
const pathList = Array.isArray(path) ? [...path] : path
|
|
1358
|
+
const pathList = Array.isArray(path) ? [...path] : toPath(path);
|
|
1279
1359
|
const [part, ...nestedPath] = pathList;
|
|
1280
|
-
if (part !== void 0 && part !== "" && (
|
|
1281
|
-
fieldSchema = (
|
|
1360
|
+
if (part !== void 0 && part !== "" && hasByPath(fieldSchema, part)) {
|
|
1361
|
+
fieldSchema = getByPath(fieldSchema, part);
|
|
1282
1362
|
return getFromSchemaInternal(
|
|
1283
1363
|
validator,
|
|
1284
1364
|
rootSchema,
|
|
@@ -1314,30 +1394,30 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1314
1394
|
{},
|
|
1315
1395
|
experimental_customMergeAllOf
|
|
1316
1396
|
);
|
|
1317
|
-
if ((
|
|
1397
|
+
if (hasByPath(parentField, ONE_OF_KEY)) {
|
|
1318
1398
|
parentField = findSelectedOptionInXxxOf(
|
|
1319
1399
|
validator,
|
|
1320
1400
|
rootSchema,
|
|
1321
1401
|
parentField,
|
|
1322
1402
|
fieldNameKey,
|
|
1323
1403
|
ONE_OF_KEY,
|
|
1324
|
-
(
|
|
1404
|
+
getByPath(formData, subPath),
|
|
1325
1405
|
experimental_customMergeAllOf
|
|
1326
1406
|
);
|
|
1327
|
-
} else if ((
|
|
1407
|
+
} else if (hasByPath(parentField, ANY_OF_KEY)) {
|
|
1328
1408
|
parentField = findSelectedOptionInXxxOf(
|
|
1329
1409
|
validator,
|
|
1330
1410
|
rootSchema,
|
|
1331
1411
|
parentField,
|
|
1332
1412
|
fieldNameKey,
|
|
1333
1413
|
ANY_OF_KEY,
|
|
1334
|
-
(
|
|
1414
|
+
getByPath(formData, subPath),
|
|
1335
1415
|
experimental_customMergeAllOf
|
|
1336
1416
|
);
|
|
1337
1417
|
}
|
|
1338
1418
|
});
|
|
1339
1419
|
}
|
|
1340
|
-
if ((
|
|
1420
|
+
if (hasByPath(parentField, ONE_OF_KEY)) {
|
|
1341
1421
|
parentField = findSelectedOptionInXxxOf(
|
|
1342
1422
|
validator,
|
|
1343
1423
|
rootSchema,
|
|
@@ -1347,7 +1427,7 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1347
1427
|
formData,
|
|
1348
1428
|
experimental_customMergeAllOf
|
|
1349
1429
|
);
|
|
1350
|
-
} else if ((
|
|
1430
|
+
} else if (hasByPath(parentField, ANY_OF_KEY)) {
|
|
1351
1431
|
parentField = findSelectedOptionInXxxOf(
|
|
1352
1432
|
validator,
|
|
1353
1433
|
rootSchema,
|
|
@@ -1385,13 +1465,6 @@ function findFieldInSchema(validator, rootSchema, schema, path, formData = {}, e
|
|
|
1385
1465
|
}
|
|
1386
1466
|
|
|
1387
1467
|
// src/schema/getClosestMatchingOption.ts
|
|
1388
|
-
var import_get9 = __toESM(require("lodash/get"), 1);
|
|
1389
|
-
var import_has4 = __toESM(require("lodash/has"), 1);
|
|
1390
|
-
var import_isNumber2 = __toESM(require("lodash/isNumber"), 1);
|
|
1391
|
-
var import_isObject6 = __toESM(require("lodash/isObject"), 1);
|
|
1392
|
-
var import_isString2 = __toESM(require("lodash/isString"), 1);
|
|
1393
|
-
var import_reduce = __toESM(require("lodash/reduce"), 1);
|
|
1394
|
-
var import_times2 = __toESM(require("lodash/times"), 1);
|
|
1395
1468
|
var JUNK_OPTION = {
|
|
1396
1469
|
type: "object",
|
|
1397
1470
|
$id: JUNK_OPTION_ID,
|
|
@@ -1404,61 +1477,57 @@ var JUNK_OPTION = {
|
|
|
1404
1477
|
function calculateIndexScore(validator, rootSchema, schema, formData, experimental_customMergeAllOf) {
|
|
1405
1478
|
let totalScore = 0;
|
|
1406
1479
|
if (schema) {
|
|
1407
|
-
if ((
|
|
1408
|
-
totalScore += (
|
|
1409
|
-
|
|
1410
|
-
(
|
|
1411
|
-
const formValue = (0, import_get9.default)(formData, key);
|
|
1412
|
-
if (typeof value === "boolean") {
|
|
1413
|
-
return score;
|
|
1414
|
-
}
|
|
1415
|
-
if ((0, import_has4.default)(value, REF_KEY)) {
|
|
1416
|
-
const newSchema = retrieveSchema(
|
|
1417
|
-
validator,
|
|
1418
|
-
value,
|
|
1419
|
-
rootSchema,
|
|
1420
|
-
formValue,
|
|
1421
|
-
experimental_customMergeAllOf
|
|
1422
|
-
);
|
|
1423
|
-
return score + calculateIndexScore(
|
|
1424
|
-
validator,
|
|
1425
|
-
rootSchema,
|
|
1426
|
-
newSchema,
|
|
1427
|
-
formValue || {},
|
|
1428
|
-
experimental_customMergeAllOf
|
|
1429
|
-
);
|
|
1430
|
-
}
|
|
1431
|
-
if (((0, import_has4.default)(value, ONE_OF_KEY) || (0, import_has4.default)(value, ANY_OF_KEY)) && formValue) {
|
|
1432
|
-
const xxxOfKey = (0, import_has4.default)(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
1433
|
-
const discriminator = getDiscriminatorFieldFromSchema(value);
|
|
1434
|
-
return score + getClosestMatchingOption(
|
|
1435
|
-
validator,
|
|
1436
|
-
rootSchema,
|
|
1437
|
-
formValue,
|
|
1438
|
-
(0, import_get9.default)(value, xxxOfKey),
|
|
1439
|
-
-1,
|
|
1440
|
-
discriminator,
|
|
1441
|
-
experimental_customMergeAllOf
|
|
1442
|
-
);
|
|
1443
|
-
}
|
|
1444
|
-
if (value.type === "object") {
|
|
1445
|
-
const structureBoost = (0, import_isObject6.default)(formValue) ? 1 : 0;
|
|
1446
|
-
return score + structureBoost + calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf);
|
|
1447
|
-
}
|
|
1448
|
-
if (value.type === guessType(formValue)) {
|
|
1449
|
-
let newScore = score + 1;
|
|
1450
|
-
if (value.default) {
|
|
1451
|
-
newScore += formValue === value.default ? 1 : -1;
|
|
1452
|
-
} else if (value.const) {
|
|
1453
|
-
newScore += formValue === value.const ? 1 : -1;
|
|
1454
|
-
}
|
|
1455
|
-
return newScore;
|
|
1456
|
-
}
|
|
1480
|
+
if (isObject(schema.properties)) {
|
|
1481
|
+
totalScore += Object.entries(schema.properties).reduce((score, [key, value]) => {
|
|
1482
|
+
const formValue = formData?.[key];
|
|
1483
|
+
if (typeof value === "boolean") {
|
|
1457
1484
|
return score;
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1485
|
+
}
|
|
1486
|
+
if (hasByPath(value, REF_KEY)) {
|
|
1487
|
+
const newSchema = retrieveSchema(
|
|
1488
|
+
validator,
|
|
1489
|
+
value,
|
|
1490
|
+
rootSchema,
|
|
1491
|
+
formValue,
|
|
1492
|
+
experimental_customMergeAllOf
|
|
1493
|
+
);
|
|
1494
|
+
return score + calculateIndexScore(
|
|
1495
|
+
validator,
|
|
1496
|
+
rootSchema,
|
|
1497
|
+
newSchema,
|
|
1498
|
+
formValue || {},
|
|
1499
|
+
experimental_customMergeAllOf
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1502
|
+
if ((hasByPath(value, ONE_OF_KEY) || hasByPath(value, ANY_OF_KEY)) && formValue) {
|
|
1503
|
+
const xxxOfKey = hasByPath(value, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
|
|
1504
|
+
const discriminator = getDiscriminatorFieldFromSchema(value);
|
|
1505
|
+
return score + getClosestMatchingOption(
|
|
1506
|
+
validator,
|
|
1507
|
+
rootSchema,
|
|
1508
|
+
formValue,
|
|
1509
|
+
getByPath(value, xxxOfKey),
|
|
1510
|
+
-1,
|
|
1511
|
+
discriminator,
|
|
1512
|
+
experimental_customMergeAllOf
|
|
1513
|
+
);
|
|
1514
|
+
}
|
|
1515
|
+
if (value.type === "object") {
|
|
1516
|
+
const structureBoost = typeof formValue === "object" && formValue !== null ? 1 : 0;
|
|
1517
|
+
return score + structureBoost + calculateIndexScore(validator, rootSchema, value, formValue, experimental_customMergeAllOf);
|
|
1518
|
+
}
|
|
1519
|
+
if (value.type === guessType(formValue)) {
|
|
1520
|
+
let newScore = score + 1;
|
|
1521
|
+
if (value.default) {
|
|
1522
|
+
newScore += formValue === value.default ? 1 : -1;
|
|
1523
|
+
} else if (value.const) {
|
|
1524
|
+
newScore += formValue === value.const ? 1 : -1;
|
|
1525
|
+
}
|
|
1526
|
+
return newScore;
|
|
1527
|
+
}
|
|
1528
|
+
return score;
|
|
1529
|
+
}, 0);
|
|
1530
|
+
} else if (typeof schema.type === "string" && schema.type === guessType(formData)) {
|
|
1462
1531
|
totalScore += 1;
|
|
1463
1532
|
}
|
|
1464
1533
|
}
|
|
@@ -1467,7 +1536,7 @@ function calculateIndexScore(validator, rootSchema, schema, formData, experiment
|
|
|
1467
1536
|
function getClosestMatchingOption(validator, rootSchema, formData, options, selectedOption = -1, discriminatorField, experimental_customMergeAllOf) {
|
|
1468
1537
|
const resolvedOptions = options.map((option) => resolveAllReferences(option, rootSchema, []));
|
|
1469
1538
|
const simpleDiscriminatorMatch = getOptionMatchingSimpleDiscriminator(formData, options, discriminatorField);
|
|
1470
|
-
if (
|
|
1539
|
+
if (typeof simpleDiscriminatorMatch === "number") {
|
|
1471
1540
|
return simpleDiscriminatorMatch;
|
|
1472
1541
|
}
|
|
1473
1542
|
const allValidIndexes = resolvedOptions.reduce((validList, option, index) => {
|
|
@@ -1482,7 +1551,7 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1482
1551
|
return allValidIndexes[0];
|
|
1483
1552
|
}
|
|
1484
1553
|
if (!allValidIndexes.length) {
|
|
1485
|
-
|
|
1554
|
+
allValidIndexes.push(...resolvedOptions.keys());
|
|
1486
1555
|
}
|
|
1487
1556
|
const scoreCount = /* @__PURE__ */ new Set();
|
|
1488
1557
|
const { bestIndex } = allValidIndexes.reduce(
|
|
@@ -1504,16 +1573,11 @@ function getClosestMatchingOption(validator, rootSchema, formData, options, sele
|
|
|
1504
1573
|
return bestIndex;
|
|
1505
1574
|
}
|
|
1506
1575
|
|
|
1507
|
-
// src/schema/getDefaultFormState.ts
|
|
1508
|
-
var import_get12 = __toESM(require("lodash/get"), 1);
|
|
1509
|
-
var import_isEmpty4 = __toESM(require("lodash/isEmpty"), 1);
|
|
1510
|
-
|
|
1511
1576
|
// src/constIsAjvDataReference.ts
|
|
1512
|
-
var import_isString3 = __toESM(require("lodash/isString"), 1);
|
|
1513
1577
|
function constIsAjvDataReference(schema) {
|
|
1514
1578
|
const schemaConst = schema[CONST_KEY];
|
|
1515
1579
|
const schemaType = getSchemaType(schema);
|
|
1516
|
-
return isObject(schemaConst) &&
|
|
1580
|
+
return isObject(schemaConst) && typeof schemaConst?.$data === "string" && schemaType !== "object" && schemaType !== "array";
|
|
1517
1581
|
}
|
|
1518
1582
|
|
|
1519
1583
|
// src/isConstant.ts
|
|
@@ -1527,8 +1591,6 @@ function isFixedItems(schema) {
|
|
|
1527
1591
|
}
|
|
1528
1592
|
|
|
1529
1593
|
// src/mergeDefaultsWithFormData.ts
|
|
1530
|
-
var import_get10 = __toESM(require("lodash/get"), 1);
|
|
1531
|
-
var import_isNil = __toESM(require("lodash/isNil"), 1);
|
|
1532
1594
|
function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false, overrideFormDataWithDefaults = false) {
|
|
1533
1595
|
if (Array.isArray(formData)) {
|
|
1534
1596
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
@@ -1553,23 +1615,25 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
1553
1615
|
}
|
|
1554
1616
|
if (isObject(formData)) {
|
|
1555
1617
|
const acc = Object.assign({}, defaults);
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
const
|
|
1560
|
-
const
|
|
1561
|
-
const
|
|
1562
|
-
const
|
|
1618
|
+
const formDataObj = formData;
|
|
1619
|
+
const defaultsObj = isObject(defaults) ? defaults : void 0;
|
|
1620
|
+
return Object.keys(formDataObj).reduce((accumulator, key) => {
|
|
1621
|
+
const keyValue = formDataObj[key];
|
|
1622
|
+
const keyExistsInDefaults = defaultsObj !== void 0 && key in defaultsObj;
|
|
1623
|
+
const keyExistsInFormData = key in formDataObj;
|
|
1624
|
+
const keyDefault = defaultsObj?.[key] ?? {};
|
|
1625
|
+
const defaultValueNeedsDeepMerge = keyExistsInDefaults && isObject(keyDefault) && Object.values(keyDefault).some((v) => isObject(v) || Array.isArray(v));
|
|
1626
|
+
const keyDefaultIsObject = keyExistsInDefaults && isObject(defaultsObj?.[key]);
|
|
1563
1627
|
const keyHasFormDataObject = keyExistsInFormData && isObject(keyValue);
|
|
1564
|
-
if (keyDefaultIsObject && keyHasFormDataObject && !
|
|
1628
|
+
if (keyDefaultIsObject && keyHasFormDataObject && !defaultValueNeedsDeepMerge) {
|
|
1565
1629
|
accumulator[key] = {
|
|
1566
|
-
...
|
|
1630
|
+
...defaultsObj?.[key],
|
|
1567
1631
|
...keyValue
|
|
1568
1632
|
};
|
|
1569
1633
|
return accumulator;
|
|
1570
1634
|
}
|
|
1571
1635
|
accumulator[key] = mergeDefaultsWithFormData(
|
|
1572
|
-
|
|
1636
|
+
defaultsObj?.[key],
|
|
1573
1637
|
keyValue,
|
|
1574
1638
|
mergeExtraArrayDefaults,
|
|
1575
1639
|
defaultSupercedesUndefined,
|
|
@@ -1580,7 +1644,7 @@ function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults =
|
|
|
1580
1644
|
return acc;
|
|
1581
1645
|
}, acc);
|
|
1582
1646
|
}
|
|
1583
|
-
if (defaultSupercedesUndefined && (!(defaults === void 0) &&
|
|
1647
|
+
if (defaultSupercedesUndefined && (!(defaults === void 0) && formData == null || typeof formData === "number" && Number.isNaN(formData)) || overrideFormDataWithDefaults && formData != null) {
|
|
1584
1648
|
return defaults;
|
|
1585
1649
|
}
|
|
1586
1650
|
return formData;
|
|
@@ -1613,9 +1677,6 @@ function mergeObjects(obj1, obj2, concatArrays = false) {
|
|
|
1613
1677
|
);
|
|
1614
1678
|
}
|
|
1615
1679
|
|
|
1616
|
-
// src/optionsList.ts
|
|
1617
|
-
var import_get11 = __toESM(require("lodash/get"), 1);
|
|
1618
|
-
|
|
1619
1680
|
// src/toConstant.ts
|
|
1620
1681
|
function toConstant(schema) {
|
|
1621
1682
|
if (ENUM_KEY in schema && Array.isArray(schema.enum) && schema.enum.length === 1) {
|
|
@@ -1678,8 +1739,8 @@ function optionsList(schema, uiSchema) {
|
|
|
1678
1739
|
let value;
|
|
1679
1740
|
let label = title;
|
|
1680
1741
|
if (selectorField) {
|
|
1681
|
-
const innerSchema = (
|
|
1682
|
-
value = (
|
|
1742
|
+
const innerSchema = getPropertySchema(aSchema, selectorField);
|
|
1743
|
+
value = getByPath(innerSchema, DEFAULT_KEY, getByPath(innerSchema, CONST_KEY));
|
|
1683
1744
|
label = label ?? innerSchema?.title ?? aSchema.title ?? String(value);
|
|
1684
1745
|
} else {
|
|
1685
1746
|
value = toConstant(aSchema);
|
|
@@ -1732,9 +1793,18 @@ function getInnerSchemaForArrayItem(schema, additionalItems = 0 /* Ignore */, id
|
|
|
1732
1793
|
}
|
|
1733
1794
|
return {};
|
|
1734
1795
|
}
|
|
1796
|
+
function hasContent(value) {
|
|
1797
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
1798
|
+
return value.length > 0;
|
|
1799
|
+
}
|
|
1800
|
+
if (typeof value === "object" && value !== null) {
|
|
1801
|
+
return Object.keys(value).length > 0;
|
|
1802
|
+
}
|
|
1803
|
+
return false;
|
|
1804
|
+
}
|
|
1735
1805
|
function computeDefaultBasedOnSchemaTypeAndDefaults(schema, computedDefault) {
|
|
1736
1806
|
const { default: schemaDefault, type } = schema;
|
|
1737
|
-
const shouldReturnNullAsDefault = Array.isArray(type) && type.includes("null") && (
|
|
1807
|
+
const shouldReturnNullAsDefault = Array.isArray(type) && type.includes("null") && !hasContent(computedDefault) && schemaDefault === null;
|
|
1738
1808
|
return shouldReturnNullAsDefault ? null : computedDefault;
|
|
1739
1809
|
}
|
|
1740
1810
|
function maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValues, isParentRequired, requiredFields = [], experimental_defaultFormStateBehavior = {}, isConst = false, isNullType = false) {
|
|
@@ -1742,17 +1812,17 @@ function maybeAddDefaultToObject(acc, key, computedDefault, includeUndefinedValu
|
|
|
1742
1812
|
if (includeUndefinedValues === true || isConst) {
|
|
1743
1813
|
acc[key] = computedDefault;
|
|
1744
1814
|
} else if (includeUndefinedValues === "excludeObjectChildren") {
|
|
1745
|
-
if (isNullType && computedDefault !== void 0 || !isObject(computedDefault) ||
|
|
1815
|
+
if (isNullType && computedDefault !== void 0 || !isObject(computedDefault) || Object.keys(computedDefault).length > 0) {
|
|
1746
1816
|
acc[key] = computedDefault;
|
|
1747
1817
|
}
|
|
1748
1818
|
} else if (emptyObjectFields !== "skipDefaults") {
|
|
1749
1819
|
const isSelfOrParentRequired = isParentRequired === void 0 ? requiredFields.includes(key) : isParentRequired;
|
|
1750
1820
|
if (isObject(computedDefault)) {
|
|
1751
1821
|
if (emptyObjectFields === "skipEmptyDefaults") {
|
|
1752
|
-
if (
|
|
1822
|
+
if (Object.keys(computedDefault).length > 0) {
|
|
1753
1823
|
acc[key] = computedDefault;
|
|
1754
1824
|
}
|
|
1755
|
-
} else if ((
|
|
1825
|
+
} else if ((Object.keys(computedDefault).length > 0 || requiredFields.includes(key)) && (isSelfOrParentRequired || emptyObjectFields !== "populateRequiredDefaults")) {
|
|
1756
1826
|
acc[key] = computedDefault;
|
|
1757
1827
|
}
|
|
1758
1828
|
} else if (
|
|
@@ -1802,7 +1872,7 @@ function computeDefaults(validator, rawSchema, computeDefaultsProps = {}) {
|
|
|
1802
1872
|
updatedRecurseList = _recurseList.concat(refName);
|
|
1803
1873
|
schemaToCompute = findSchemaDefinition(refName, rootSchema);
|
|
1804
1874
|
}
|
|
1805
|
-
const hasNoExistingData = rawFormData === void 0 || isObject(rawFormData) &&
|
|
1875
|
+
const hasNoExistingData = rawFormData === void 0 || isObject(rawFormData) && Object.keys(rawFormData).length === 0;
|
|
1806
1876
|
if (schemaToCompute && !defaults && hasNoExistingData) {
|
|
1807
1877
|
defaults = schema.default;
|
|
1808
1878
|
}
|
|
@@ -1935,13 +2005,13 @@ function ensureFormDataMatchingSchema(validator, schema, rootSchema, formData, e
|
|
|
1935
2005
|
} else if (isObject(validFormData) && isObject(schemaToMatch.properties)) {
|
|
1936
2006
|
validFormData = Object.keys(schemaToMatch.properties).reduce(
|
|
1937
2007
|
(acc, key) => {
|
|
1938
|
-
const propertySchema = (
|
|
2008
|
+
const propertySchema = getPropertySchema(schemaToMatch, key);
|
|
1939
2009
|
if (key in acc && (shouldRetrieveAllOf || isObject(propertySchema) && ALL_OF_KEY in propertySchema)) {
|
|
1940
2010
|
acc[key] = ensureFormDataMatchingSchema(
|
|
1941
2011
|
validator,
|
|
1942
2012
|
propertySchema,
|
|
1943
2013
|
rootSchema,
|
|
1944
|
-
|
|
2014
|
+
acc[key],
|
|
1945
2015
|
experimental_defaultFormStateBehavior,
|
|
1946
2016
|
experimental_customMergeAllOf
|
|
1947
2017
|
);
|
|
@@ -1972,7 +2042,7 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1972
2042
|
const parentConst = retrievedSchema[CONST_KEY];
|
|
1973
2043
|
const objectDefaults = Object.keys(retrievedSchema.properties || {}).reduce(
|
|
1974
2044
|
(acc, key) => {
|
|
1975
|
-
const propertySchema = (
|
|
2045
|
+
const propertySchema = getPropertySchema(retrievedSchema, key);
|
|
1976
2046
|
const hasParentConst = isObject(parentConst) && parentConst[key] !== void 0;
|
|
1977
2047
|
const hasConst = (isObject(propertySchema) && CONST_KEY in propertySchema || hasParentConst) && experimental_defaultFormStateBehavior?.constAsDefaults !== "never" && !constIsAjvDataReference(propertySchema);
|
|
1978
2048
|
const computedDefault = computeDefaults(validator, propertySchema, {
|
|
@@ -1981,8 +2051,8 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
1981
2051
|
experimental_defaultFormStateBehavior,
|
|
1982
2052
|
experimental_customMergeAllOf,
|
|
1983
2053
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
1984
|
-
parentDefaults: (
|
|
1985
|
-
rawFormData: (
|
|
2054
|
+
parentDefaults: getByPath(defaults, key),
|
|
2055
|
+
rawFormData: getByPath(formData, key),
|
|
1986
2056
|
required: retrievedSchema.required?.includes(key),
|
|
1987
2057
|
shouldMergeDefaultsIntoFormData,
|
|
1988
2058
|
initialDefaultsGenerated
|
|
@@ -2004,24 +2074,24 @@ function getObjectDefaults(validator, rawSchema, {
|
|
|
2004
2074
|
);
|
|
2005
2075
|
if (retrievedSchema.additionalProperties && !initialDefaultsGenerated) {
|
|
2006
2076
|
const additionalPropertiesSchema = isObject(retrievedSchema.additionalProperties) ? retrievedSchema.additionalProperties : {};
|
|
2007
|
-
const
|
|
2077
|
+
const keys = /* @__PURE__ */ new Set();
|
|
2008
2078
|
const formDataRequired = [];
|
|
2009
2079
|
Object.keys(formData).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => {
|
|
2010
|
-
|
|
2080
|
+
keys.add(key);
|
|
2011
2081
|
formDataRequired.push(key);
|
|
2012
2082
|
});
|
|
2013
2083
|
if (isObject(defaults) && formDataRequired.length === 0) {
|
|
2014
|
-
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) =>
|
|
2084
|
+
Object.keys(defaults).filter((key) => !retrievedSchema.properties || !retrievedSchema.properties[key]).forEach((key) => keys.add(key));
|
|
2015
2085
|
}
|
|
2016
|
-
|
|
2086
|
+
keys.forEach((key) => {
|
|
2017
2087
|
const computedDefault = computeDefaults(validator, additionalPropertiesSchema, {
|
|
2018
2088
|
rootSchema,
|
|
2019
2089
|
_recurseList,
|
|
2020
2090
|
experimental_defaultFormStateBehavior,
|
|
2021
2091
|
experimental_customMergeAllOf,
|
|
2022
2092
|
includeUndefinedValues: includeUndefinedValues === true,
|
|
2023
|
-
parentDefaults: (
|
|
2024
|
-
rawFormData: (
|
|
2093
|
+
parentDefaults: getByPath(defaults, key),
|
|
2094
|
+
rawFormData: getByPath(formData, key),
|
|
2025
2095
|
required: retrievedSchema.required?.includes(key),
|
|
2026
2096
|
shouldMergeDefaultsIntoFormData,
|
|
2027
2097
|
initialDefaultsGenerated
|
|
@@ -2089,7 +2159,7 @@ function getArrayDefaults(validator, rawSchema, {
|
|
|
2089
2159
|
experimental_defaultFormStateBehavior,
|
|
2090
2160
|
experimental_customMergeAllOf,
|
|
2091
2161
|
rawFormData: item,
|
|
2092
|
-
parentDefaults: (
|
|
2162
|
+
parentDefaults: getByPath(defaults, idx),
|
|
2093
2163
|
required,
|
|
2094
2164
|
shouldMergeDefaultsIntoFormData,
|
|
2095
2165
|
initialDefaultsGenerated
|
|
@@ -2141,6 +2211,12 @@ function getDefaultBasedOnSchemaType(validator, rawSchema, computeDefaultsProps
|
|
|
2141
2211
|
case "array": {
|
|
2142
2212
|
return getArrayDefaults(validator, rawSchema, computeDefaultsProps, defaults);
|
|
2143
2213
|
}
|
|
2214
|
+
case "boolean": {
|
|
2215
|
+
if (computeDefaultsProps.required && defaults === void 0) {
|
|
2216
|
+
return false;
|
|
2217
|
+
}
|
|
2218
|
+
return void 0;
|
|
2219
|
+
}
|
|
2144
2220
|
default:
|
|
2145
2221
|
return void 0;
|
|
2146
2222
|
}
|
|
@@ -2243,22 +2319,30 @@ function getDisplayLabel(validator, schema, uiSchema = {}, rootSchema, globalOpt
|
|
|
2243
2319
|
}
|
|
2244
2320
|
|
|
2245
2321
|
// src/schema/omitExtraData.ts
|
|
2246
|
-
var import_get13 = __toESM(require("lodash/get"), 1);
|
|
2247
|
-
var import_isEmpty5 = __toESM(require("lodash/isEmpty"), 1);
|
|
2248
|
-
var import_isNil2 = __toESM(require("lodash/isNil"), 1);
|
|
2249
|
-
var import_pick = __toESM(require("lodash/pick"), 1);
|
|
2250
2322
|
function getUsedFormData(formData, fields) {
|
|
2251
2323
|
if (fields.length === 0 && typeof formData !== "object") {
|
|
2252
2324
|
return formData;
|
|
2253
2325
|
}
|
|
2254
|
-
const data =
|
|
2326
|
+
const data = {};
|
|
2327
|
+
fields.forEach((field) => {
|
|
2328
|
+
const path = Array.isArray(field) ? field : toPath(field);
|
|
2329
|
+
if (hasByPath(formData, path)) {
|
|
2330
|
+
setByPath(data, path, getByPath(formData, path));
|
|
2331
|
+
}
|
|
2332
|
+
});
|
|
2255
2333
|
if (Array.isArray(formData)) {
|
|
2256
2334
|
return Object.keys(data).map((key) => data[key]);
|
|
2257
2335
|
}
|
|
2258
2336
|
return data;
|
|
2259
2337
|
}
|
|
2260
2338
|
function getFieldNames(pathSchema, formData) {
|
|
2261
|
-
const formValueHasData = (value, isLeaf) =>
|
|
2339
|
+
const formValueHasData = (value, isLeaf) => {
|
|
2340
|
+
if (typeof value !== "object" || value === null) {
|
|
2341
|
+
return true;
|
|
2342
|
+
}
|
|
2343
|
+
const isEmptyValue = Array.isArray(value) ? value.length === 0 : Object.keys(value).length === 0;
|
|
2344
|
+
return isEmptyValue || isLeaf;
|
|
2345
|
+
};
|
|
2262
2346
|
const getAllPaths = (_obj, acc = [], paths = [[]]) => {
|
|
2263
2347
|
const objKeys = Object.keys(_obj);
|
|
2264
2348
|
objKeys.forEach((key) => {
|
|
@@ -2272,7 +2356,7 @@ function getFieldNames(pathSchema, formData) {
|
|
|
2272
2356
|
}
|
|
2273
2357
|
} else if (key === NAME_KEY && data !== "") {
|
|
2274
2358
|
paths.forEach((path) => {
|
|
2275
|
-
const formValue = (
|
|
2359
|
+
const formValue = getByPath(formData, path);
|
|
2276
2360
|
const isLeaf = objKeys.length === 1;
|
|
2277
2361
|
if (formValueHasData(formValue, isLeaf) || Array.isArray(formValue) && formValue.every((val) => formValueHasData(val, isLeaf))) {
|
|
2278
2362
|
acc.push(path);
|
|
@@ -2285,7 +2369,7 @@ function getFieldNames(pathSchema, formData) {
|
|
|
2285
2369
|
return getAllPaths(pathSchema);
|
|
2286
2370
|
}
|
|
2287
2371
|
function isValueEmpty(value) {
|
|
2288
|
-
if (
|
|
2372
|
+
if (value == null || value === "") {
|
|
2289
2373
|
return true;
|
|
2290
2374
|
}
|
|
2291
2375
|
if (Array.isArray(value)) {
|
|
@@ -2307,19 +2391,17 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2307
2391
|
return isObject(schemaDef);
|
|
2308
2392
|
}
|
|
2309
2393
|
function handleObject(childSchema, source, target) {
|
|
2310
|
-
const { properties, additionalProperties, patternProperties
|
|
2394
|
+
const { properties, additionalProperties, patternProperties } = childSchema;
|
|
2311
2395
|
const requiredSet = new Set(childSchema.required ?? []);
|
|
2312
2396
|
function setProperty(key, schemaDef, value, required = false) {
|
|
2313
|
-
const v =
|
|
2397
|
+
const v = omit(schemaDef, value, target[key]);
|
|
2314
2398
|
if (!required && isObject(v)) {
|
|
2315
2399
|
let sd = isSchemaObj(schemaDef) ? schemaDef : {};
|
|
2316
2400
|
if (sd.$ref !== void 0) {
|
|
2317
2401
|
sd = findSchemaDefinition(sd.$ref, rootSchema);
|
|
2318
2402
|
}
|
|
2319
2403
|
const innerRequired = new Set(sd.required ?? []);
|
|
2320
|
-
const shouldDrop = Object.entries(v).every(
|
|
2321
|
-
([k, val]) => !innerRequired.has(k) && isValueEmpty(val)
|
|
2322
|
-
);
|
|
2404
|
+
const shouldDrop = Object.entries(v).every(([k, val]) => !innerRequired.has(k) && isValueEmpty(val));
|
|
2323
2405
|
if (shouldDrop) {
|
|
2324
2406
|
return;
|
|
2325
2407
|
}
|
|
@@ -2367,31 +2449,29 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2367
2449
|
}
|
|
2368
2450
|
}
|
|
2369
2451
|
}
|
|
2370
|
-
if (propertyNames !== void 0) {
|
|
2371
|
-
for (const [key, value] of Object.entries(source)) {
|
|
2372
|
-
target[key] = value;
|
|
2373
|
-
}
|
|
2374
|
-
}
|
|
2375
2452
|
return target;
|
|
2376
2453
|
}
|
|
2377
2454
|
function handleArray(childSchema, source, target) {
|
|
2378
2455
|
const { items, additionalItems } = childSchema;
|
|
2379
|
-
if (items
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
} else {
|
|
2385
|
-
for (let i = 0; i < source.length; i += 1) {
|
|
2386
|
-
target.push(omit2(items, source[i]));
|
|
2387
|
-
}
|
|
2456
|
+
if (Array.isArray(items)) {
|
|
2457
|
+
const tupleLength = Math.min(items.length, source.length);
|
|
2458
|
+
let i = 0;
|
|
2459
|
+
for (; i < tupleLength; i += 1) {
|
|
2460
|
+
target[i] = omit(items[i], source[i]);
|
|
2388
2461
|
}
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2462
|
+
if (!additionalItems) {
|
|
2463
|
+
target.length = tupleLength;
|
|
2464
|
+
return target;
|
|
2465
|
+
}
|
|
2466
|
+
for (; i < source.length; i += 1) {
|
|
2467
|
+
target[i] = omit(additionalItems, source[i]);
|
|
2468
|
+
}
|
|
2469
|
+
} else {
|
|
2470
|
+
for (let i = 0; i < source.length; i += 1) {
|
|
2471
|
+
target[i] = omit(items, source[i]);
|
|
2393
2472
|
}
|
|
2394
2473
|
}
|
|
2474
|
+
target.length = source.length;
|
|
2395
2475
|
return target;
|
|
2396
2476
|
}
|
|
2397
2477
|
function handleConditions(childSchema, source, target) {
|
|
@@ -2401,7 +2481,7 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2401
2481
|
}
|
|
2402
2482
|
const isThenBranch = isSchemaObj(condition) ? validator.isValid(condition, source, rootSchema) : condition;
|
|
2403
2483
|
const branch = isThenBranch ? then : otherwise;
|
|
2404
|
-
return branch === void 0 ? target :
|
|
2484
|
+
return branch === void 0 ? target : omit(branch, source, target, false);
|
|
2405
2485
|
}
|
|
2406
2486
|
function handleOneOf(oneOf, childSchema, source, target) {
|
|
2407
2487
|
if (!Array.isArray(oneOf) || isSelect(validator, childSchema, rootSchema, experimental_customMergeAllOf)) {
|
|
@@ -2419,7 +2499,7 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2419
2499
|
);
|
|
2420
2500
|
const winning = oneOf[bestIndex];
|
|
2421
2501
|
const resolved = isObject(winning) ? resolveAllReferences(winning, rootSchema, []) : scoringOptions[bestIndex];
|
|
2422
|
-
return
|
|
2502
|
+
return omit(resolved, source, target, false);
|
|
2423
2503
|
}
|
|
2424
2504
|
function handleAnyOf(childSchema, source, target) {
|
|
2425
2505
|
const { anyOf } = childSchema;
|
|
@@ -2429,7 +2509,7 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2429
2509
|
if (source === void 0 || Array.isArray(source) && source.length === 0 || isObject(source) && Object.keys(source).length === 0) {
|
|
2430
2510
|
let result = target;
|
|
2431
2511
|
for (const branch of anyOf) {
|
|
2432
|
-
result =
|
|
2512
|
+
result = omit(branch, source, result, false);
|
|
2433
2513
|
}
|
|
2434
2514
|
return result;
|
|
2435
2515
|
}
|
|
@@ -2443,29 +2523,29 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2443
2523
|
let result = target;
|
|
2444
2524
|
for (const [key, deps] of Object.entries(dependencies)) {
|
|
2445
2525
|
if (key in source && !Array.isArray(deps)) {
|
|
2446
|
-
result =
|
|
2526
|
+
result = omit(deps, source, result, false);
|
|
2447
2527
|
}
|
|
2448
2528
|
}
|
|
2449
2529
|
return result;
|
|
2450
2530
|
}
|
|
2451
|
-
function
|
|
2531
|
+
function omit(schemaDef, source, target, useSourceAsFallback = true) {
|
|
2452
2532
|
if (source === void 0 || schemaDef === false) {
|
|
2453
2533
|
return void 0;
|
|
2454
2534
|
}
|
|
2455
|
-
if (schemaDef === true ||
|
|
2456
|
-
return source;
|
|
2535
|
+
if (schemaDef === true || !schemaDef || Object.keys(schemaDef).length === 0) {
|
|
2536
|
+
return target ?? (useSourceAsFallback ? source : void 0);
|
|
2457
2537
|
}
|
|
2458
2538
|
let localSchema = schemaDef;
|
|
2459
2539
|
const { $ref: ref, allOf } = localSchema;
|
|
2460
2540
|
if (ref !== void 0) {
|
|
2461
|
-
return
|
|
2541
|
+
return omit(findSchemaDefinition(ref, rootSchema), source, target, useSourceAsFallback);
|
|
2462
2542
|
}
|
|
2463
2543
|
if (allOf) {
|
|
2464
2544
|
localSchema = doMergeAllOf(localSchema, experimental_customMergeAllOf);
|
|
2465
2545
|
const remainingAllOf = localSchema.allOf;
|
|
2466
2546
|
if (remainingAllOf) {
|
|
2467
2547
|
for (let i = 0; i < remainingAllOf.length; i++) {
|
|
2468
|
-
target =
|
|
2548
|
+
target = omit(remainingAllOf[i], source, target, false);
|
|
2469
2549
|
}
|
|
2470
2550
|
}
|
|
2471
2551
|
}
|
|
@@ -2480,18 +2560,27 @@ function omitExtraData(validator, schema, rootSchema = {}, formData, experimenta
|
|
|
2480
2560
|
if (!Array.isArray(source)) {
|
|
2481
2561
|
return void 0;
|
|
2482
2562
|
}
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2563
|
+
if (localSchema.items !== void 0) {
|
|
2564
|
+
filtered = handleArray(localSchema, source, Array.isArray(filtered) ? filtered : []);
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
const afterConditions = handleConditions(localSchema, source, filtered);
|
|
2568
|
+
if (localSchema.additionalProperties === false && isObjectValue(afterConditions)) {
|
|
2569
|
+
const knownKeys = new Set(Object.keys(localSchema.properties ?? {}));
|
|
2570
|
+
const patterns = localSchema.patternProperties ? Object.keys(localSchema.patternProperties).map((p) => new RegExp(p)) : [];
|
|
2571
|
+
for (const key of Object.keys(afterConditions)) {
|
|
2572
|
+
if (!knownKeys.has(key) && !patterns.some((re) => re.test(key))) {
|
|
2573
|
+
delete afterConditions[key];
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2486
2576
|
}
|
|
2487
|
-
|
|
2577
|
+
const result = handleDependencies(localSchema, source, afterConditions);
|
|
2578
|
+
return result ?? (useSourceAsFallback ? source : void 0);
|
|
2488
2579
|
}
|
|
2489
|
-
return
|
|
2580
|
+
return omit(schema, formData);
|
|
2490
2581
|
}
|
|
2491
2582
|
|
|
2492
2583
|
// src/schema/sanitizeDataForNewSchema.ts
|
|
2493
|
-
var import_get14 = __toESM(require("lodash/get"), 1);
|
|
2494
|
-
var import_has5 = __toESM(require("lodash/has"), 1);
|
|
2495
2584
|
var NO_VALUE = /* @__PURE__ */ Symbol("no Value");
|
|
2496
2585
|
function enumValuesForSchema(schema) {
|
|
2497
2586
|
if (Array.isArray(schema.enum)) {
|
|
@@ -2514,7 +2603,7 @@ function replacementForInvalidEnumValue(schema, formValue) {
|
|
|
2514
2603
|
if (!enumValues || enumValues.some((value) => deepEquals_default(value, formValue))) {
|
|
2515
2604
|
return NO_VALUE;
|
|
2516
2605
|
}
|
|
2517
|
-
const defaultValue = (
|
|
2606
|
+
const defaultValue = getByPath(schema, DEFAULT_KEY, NO_VALUE);
|
|
2518
2607
|
if (defaultValue !== NO_VALUE && enumValues.some((value) => deepEquals_default(value, defaultValue))) {
|
|
2519
2608
|
return defaultValue;
|
|
2520
2609
|
}
|
|
@@ -2522,23 +2611,25 @@ function replacementForInvalidEnumValue(schema, formValue) {
|
|
|
2522
2611
|
}
|
|
2523
2612
|
function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}, experimental_customMergeAllOf) {
|
|
2524
2613
|
let newFormData;
|
|
2525
|
-
|
|
2614
|
+
const newProperties = newSchema?.[PROPERTIES_KEY];
|
|
2615
|
+
if (newProperties) {
|
|
2526
2616
|
const removeOldSchemaData = {};
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
Object.keys(
|
|
2530
|
-
if ((
|
|
2617
|
+
const oldProperties = oldSchema?.[PROPERTIES_KEY];
|
|
2618
|
+
if (oldProperties) {
|
|
2619
|
+
Object.keys(oldProperties).forEach((key) => {
|
|
2620
|
+
if (hasByPath(data, key)) {
|
|
2531
2621
|
removeOldSchemaData[key] = void 0;
|
|
2532
2622
|
}
|
|
2533
2623
|
});
|
|
2534
2624
|
}
|
|
2535
|
-
const
|
|
2625
|
+
const keys = Object.keys(newProperties);
|
|
2536
2626
|
const nestedData = {};
|
|
2537
|
-
|
|
2538
|
-
const formValue =
|
|
2539
|
-
|
|
2540
|
-
let
|
|
2541
|
-
|
|
2627
|
+
keys.forEach((key) => {
|
|
2628
|
+
const formValue = data?.[key];
|
|
2629
|
+
const isNewProperty = !hasByPath(oldSchema, [PROPERTIES_KEY, key]);
|
|
2630
|
+
let oldKeyedSchema = getPropertySchema(oldSchema, key);
|
|
2631
|
+
let newKeyedSchema = getPropertySchema(newSchema, key);
|
|
2632
|
+
if (hasByPath(oldKeyedSchema, REF_KEY)) {
|
|
2542
2633
|
oldKeyedSchema = retrieveSchema(
|
|
2543
2634
|
validator,
|
|
2544
2635
|
oldKeyedSchema,
|
|
@@ -2547,7 +2638,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2547
2638
|
experimental_customMergeAllOf
|
|
2548
2639
|
);
|
|
2549
2640
|
}
|
|
2550
|
-
if ((
|
|
2641
|
+
if (hasByPath(newKeyedSchema, REF_KEY)) {
|
|
2551
2642
|
newKeyedSchema = retrieveSchema(
|
|
2552
2643
|
validator,
|
|
2553
2644
|
newKeyedSchema,
|
|
@@ -2556,10 +2647,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2556
2647
|
experimental_customMergeAllOf
|
|
2557
2648
|
);
|
|
2558
2649
|
}
|
|
2559
|
-
const oldSchemaTypeForKey =
|
|
2560
|
-
const newSchemaTypeForKey =
|
|
2650
|
+
const oldSchemaTypeForKey = oldKeyedSchema.type;
|
|
2651
|
+
const newSchemaTypeForKey = newKeyedSchema.type;
|
|
2561
2652
|
if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {
|
|
2562
|
-
if (
|
|
2653
|
+
if (key in removeOldSchemaData) {
|
|
2563
2654
|
delete removeOldSchemaData[key];
|
|
2564
2655
|
}
|
|
2565
2656
|
if (newSchemaTypeForKey === "object" || newSchemaTypeForKey === "array" && Array.isArray(formValue)) {
|
|
@@ -2567,7 +2658,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2567
2658
|
validator,
|
|
2568
2659
|
rootSchema,
|
|
2569
2660
|
newKeyedSchema,
|
|
2570
|
-
oldKeyedSchema,
|
|
2661
|
+
isNewProperty && newSchemaTypeForKey === "array" ? newKeyedSchema : oldKeyedSchema,
|
|
2571
2662
|
formValue,
|
|
2572
2663
|
experimental_customMergeAllOf
|
|
2573
2664
|
);
|
|
@@ -2575,21 +2666,21 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2575
2666
|
nestedData[key] = itemData;
|
|
2576
2667
|
}
|
|
2577
2668
|
} else {
|
|
2578
|
-
const newOptionDefault = (
|
|
2579
|
-
const oldOptionDefault = (
|
|
2669
|
+
const newOptionDefault = getByPath(newKeyedSchema, DEFAULT_KEY, NO_VALUE);
|
|
2670
|
+
const oldOptionDefault = getByPath(oldKeyedSchema, DEFAULT_KEY, NO_VALUE);
|
|
2580
2671
|
if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {
|
|
2581
|
-
if (oldOptionDefault === formValue) {
|
|
2672
|
+
if (isNewProperty && formValue === void 0 || oldOptionDefault === formValue) {
|
|
2582
2673
|
removeOldSchemaData[key] = newOptionDefault;
|
|
2583
|
-
} else if (
|
|
2674
|
+
} else if (newKeyedSchema.readOnly === true) {
|
|
2584
2675
|
removeOldSchemaData[key] = void 0;
|
|
2585
2676
|
}
|
|
2586
2677
|
}
|
|
2587
|
-
const newOptionConst = (
|
|
2588
|
-
const oldOptionConst = (
|
|
2678
|
+
const newOptionConst = getByPath(newKeyedSchema, CONST_KEY, NO_VALUE);
|
|
2679
|
+
const oldOptionConst = getByPath(oldKeyedSchema, CONST_KEY, NO_VALUE);
|
|
2589
2680
|
if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {
|
|
2590
2681
|
removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : void 0;
|
|
2591
2682
|
}
|
|
2592
|
-
if ((
|
|
2683
|
+
if (hasByPath(data, key)) {
|
|
2593
2684
|
const enumReplacement = replacementForInvalidEnumValue(newKeyedSchema, formValue);
|
|
2594
2685
|
if (enumReplacement !== NO_VALUE) {
|
|
2595
2686
|
removeOldSchemaData[key] = enumReplacement;
|
|
@@ -2603,11 +2694,11 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2603
2694
|
...removeOldSchemaData,
|
|
2604
2695
|
...nestedData
|
|
2605
2696
|
};
|
|
2606
|
-
} else if (
|
|
2607
|
-
let oldSchemaItems =
|
|
2608
|
-
let newSchemaItems =
|
|
2697
|
+
} else if (oldSchema?.type === "array" && newSchema?.type === "array" && Array.isArray(data)) {
|
|
2698
|
+
let oldSchemaItems = oldSchema.items;
|
|
2699
|
+
let newSchemaItems = newSchema.items;
|
|
2609
2700
|
if (typeof oldSchemaItems === "object" && typeof newSchemaItems === "object" && !Array.isArray(oldSchemaItems) && !Array.isArray(newSchemaItems)) {
|
|
2610
|
-
if ((
|
|
2701
|
+
if (hasByPath(oldSchemaItems, REF_KEY)) {
|
|
2611
2702
|
oldSchemaItems = retrieveSchema(
|
|
2612
2703
|
validator,
|
|
2613
2704
|
oldSchemaItems,
|
|
@@ -2616,7 +2707,7 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2616
2707
|
experimental_customMergeAllOf
|
|
2617
2708
|
);
|
|
2618
2709
|
}
|
|
2619
|
-
if ((
|
|
2710
|
+
if (hasByPath(newSchemaItems, REF_KEY)) {
|
|
2620
2711
|
newSchemaItems = retrieveSchema(
|
|
2621
2712
|
validator,
|
|
2622
2713
|
newSchemaItems,
|
|
@@ -2625,10 +2716,10 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2625
2716
|
experimental_customMergeAllOf
|
|
2626
2717
|
);
|
|
2627
2718
|
}
|
|
2628
|
-
const oldSchemaType = (
|
|
2629
|
-
const newSchemaType = (
|
|
2719
|
+
const oldSchemaType = getByPath(oldSchemaItems, "type");
|
|
2720
|
+
const newSchemaType = getByPath(newSchemaItems, "type");
|
|
2630
2721
|
if (!oldSchemaType || oldSchemaType === newSchemaType) {
|
|
2631
|
-
const maxItems =
|
|
2722
|
+
const maxItems = newSchema.maxItems ?? -1;
|
|
2632
2723
|
if (newSchemaType === "object") {
|
|
2633
2724
|
newFormData = data.reduce((newValue, aValue) => {
|
|
2634
2725
|
const itemValue = sanitizeDataForNewSchema(
|
|
@@ -2658,9 +2749,6 @@ function sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, d
|
|
|
2658
2749
|
}
|
|
2659
2750
|
|
|
2660
2751
|
// src/schema/toPathSchema.ts
|
|
2661
|
-
var import_get15 = __toESM(require("lodash/get"), 1);
|
|
2662
|
-
var import_isObject12 = __toESM(require("lodash/isObject"), 1);
|
|
2663
|
-
var import_set2 = __toESM(require("lodash/set"), 1);
|
|
2664
2752
|
function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
|
|
2665
2753
|
if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema || IF_KEY in schema) {
|
|
2666
2754
|
const innerSchema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
|
|
@@ -2707,9 +2795,9 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2707
2795
|
};
|
|
2708
2796
|
}
|
|
2709
2797
|
if (ADDITIONAL_PROPERTIES_KEY in schema && schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
|
|
2710
|
-
(
|
|
2711
|
-
const additionalSchema = (
|
|
2712
|
-
const definedProperties =
|
|
2798
|
+
setByPath(pathSchema, RJSF_ADDITIONAL_PROPERTIES_FLAG, true);
|
|
2799
|
+
const additionalSchema = isObject(schema[ADDITIONAL_PROPERTIES_KEY]) ? schema[ADDITIONAL_PROPERTIES_KEY] : {};
|
|
2800
|
+
const definedProperties = schema[PROPERTIES_KEY] ?? {};
|
|
2713
2801
|
for (const key of Object.keys(formData ?? {})) {
|
|
2714
2802
|
if (!(key in definedProperties)) {
|
|
2715
2803
|
pathSchema[key] = toPathSchemaInternal(
|
|
@@ -2717,7 +2805,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2717
2805
|
additionalSchema,
|
|
2718
2806
|
`${name}.${key}`,
|
|
2719
2807
|
rootSchema,
|
|
2720
|
-
(
|
|
2808
|
+
getByPath(formData, key),
|
|
2721
2809
|
_recurseList,
|
|
2722
2810
|
experimental_customMergeAllOf
|
|
2723
2811
|
);
|
|
@@ -2767,7 +2855,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2767
2855
|
}
|
|
2768
2856
|
} else if (PROPERTIES_KEY in schema) {
|
|
2769
2857
|
for (const property in schema.properties) {
|
|
2770
|
-
const field = (
|
|
2858
|
+
const field = getPropertySchema(schema, property);
|
|
2771
2859
|
pathSchema[property] = toPathSchemaInternal(
|
|
2772
2860
|
validator,
|
|
2773
2861
|
field,
|
|
@@ -2775,7 +2863,7 @@ function toPathSchemaInternal(validator, schema, name, rootSchema, formData, _re
|
|
|
2775
2863
|
rootSchema,
|
|
2776
2864
|
// It's possible that formData is not an object -- this can happen if an
|
|
2777
2865
|
// array item has just been added, but not populated with data yet
|
|
2778
|
-
(
|
|
2866
|
+
getByPath(formData, property),
|
|
2779
2867
|
_recurseList,
|
|
2780
2868
|
experimental_customMergeAllOf
|
|
2781
2869
|
);
|
|
@@ -2789,6 +2877,10 @@ function toPathSchema(validator, schema, name = "", rootSchema, formData, experi
|
|
|
2789
2877
|
|
|
2790
2878
|
// src/createSchemaUtils.ts
|
|
2791
2879
|
var SchemaUtils = class {
|
|
2880
|
+
rootSchema;
|
|
2881
|
+
validator;
|
|
2882
|
+
experimental_defaultFormStateBehavior;
|
|
2883
|
+
experimental_customMergeAllOf;
|
|
2792
2884
|
/** Constructs the `SchemaUtils` instance with the given `validator` and `rootSchema` stored as instance variables
|
|
2793
2885
|
*
|
|
2794
2886
|
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
@@ -2798,7 +2890,7 @@ var SchemaUtils = class {
|
|
|
2798
2890
|
*/
|
|
2799
2891
|
constructor(validator, rootSchema, experimental_defaultFormStateBehavior, experimental_customMergeAllOf) {
|
|
2800
2892
|
if (rootSchema?.[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
2801
|
-
this.rootSchema = makeAllReferencesAbsolute(rootSchema,
|
|
2893
|
+
this.rootSchema = makeAllReferencesAbsolute(rootSchema, rootSchema[ID_KEY] ?? "#");
|
|
2802
2894
|
} else {
|
|
2803
2895
|
this.rootSchema = rootSchema;
|
|
2804
2896
|
}
|
|
@@ -3189,8 +3281,8 @@ function enumOptionsIndexForValue(value, allEnumOptions = [], multiple = false)
|
|
|
3189
3281
|
|
|
3190
3282
|
// src/enumOptionSelectedValue.ts
|
|
3191
3283
|
function enumOptionSelectedValue(value, enumOptions, multiple, format = "indexed", emptyValue) {
|
|
3192
|
-
const
|
|
3193
|
-
if (
|
|
3284
|
+
const isEmpty = typeof value === "undefined" || multiple && Array.isArray(value) && value.length < 1 || !multiple && value === emptyValue;
|
|
3285
|
+
if (isEmpty) {
|
|
3194
3286
|
return emptyValue;
|
|
3195
3287
|
}
|
|
3196
3288
|
if (format === "realValue") {
|
|
@@ -3201,10 +3293,9 @@ function enumOptionSelectedValue(value, enumOptions, multiple, format = "indexed
|
|
|
3201
3293
|
}
|
|
3202
3294
|
|
|
3203
3295
|
// src/enumOptionsSelectValue.ts
|
|
3204
|
-
var import_isNil3 = __toESM(require("lodash/isNil"), 1);
|
|
3205
3296
|
function enumOptionsSelectValue(valueIndex, selected, allEnumOptions = []) {
|
|
3206
3297
|
const value = enumOptionsValueForIndex(valueIndex, allEnumOptions);
|
|
3207
|
-
if (
|
|
3298
|
+
if (value != null) {
|
|
3208
3299
|
const index = allEnumOptions.findIndex((opt) => value === opt.value);
|
|
3209
3300
|
const all = allEnumOptions.map(({ value: val }) => val);
|
|
3210
3301
|
const updated = selected.slice(0, index).concat(value, selected.slice(index));
|
|
@@ -3239,12 +3330,11 @@ function enumOptionValueDecoder(value, enumOptions, format = "indexed", emptyVal
|
|
|
3239
3330
|
}
|
|
3240
3331
|
|
|
3241
3332
|
// src/enumOptionValueEncoder.ts
|
|
3242
|
-
var import_isNil4 = __toESM(require("lodash/isNil"), 1);
|
|
3243
3333
|
function enumOptionValueEncoder(value, index, format = "indexed") {
|
|
3244
3334
|
if (format !== "realValue") {
|
|
3245
3335
|
return String(index);
|
|
3246
3336
|
}
|
|
3247
|
-
if (
|
|
3337
|
+
if (value == null) {
|
|
3248
3338
|
return "";
|
|
3249
3339
|
}
|
|
3250
3340
|
if (typeof value === "object") {
|
|
@@ -3254,21 +3344,17 @@ function enumOptionValueEncoder(value, index, format = "indexed") {
|
|
|
3254
3344
|
}
|
|
3255
3345
|
|
|
3256
3346
|
// src/ErrorSchemaBuilder.ts
|
|
3257
|
-
var import_cloneDeep = __toESM(require("lodash/cloneDeep"), 1);
|
|
3258
|
-
var import_get17 = __toESM(require("lodash/get"), 1);
|
|
3259
|
-
var import_set3 = __toESM(require("lodash/set"), 1);
|
|
3260
|
-
var import_setWith = __toESM(require("lodash/setWith"), 1);
|
|
3261
3347
|
var ErrorSchemaBuilder = class {
|
|
3348
|
+
/** The error schema being built
|
|
3349
|
+
*
|
|
3350
|
+
* @private
|
|
3351
|
+
*/
|
|
3352
|
+
errorSchema = {};
|
|
3262
3353
|
/** Construct an `ErrorSchemaBuilder` with an optional initial set of errors in an `ErrorSchema`.
|
|
3263
3354
|
*
|
|
3264
3355
|
* @param [initialSchema] - The optional set of initial errors, that will be cloned into the class
|
|
3265
3356
|
*/
|
|
3266
3357
|
constructor(initialSchema) {
|
|
3267
|
-
/** The error schema being built
|
|
3268
|
-
*
|
|
3269
|
-
* @private
|
|
3270
|
-
*/
|
|
3271
|
-
this.errorSchema = {};
|
|
3272
3358
|
this.resetAllErrors(initialSchema);
|
|
3273
3359
|
}
|
|
3274
3360
|
/** Returns the `ErrorSchema` that has been updated by the methods of the `ErrorSchemaBuilder`
|
|
@@ -3283,11 +3369,14 @@ var ErrorSchemaBuilder = class {
|
|
|
3283
3369
|
* @private
|
|
3284
3370
|
*/
|
|
3285
3371
|
getOrCreateErrorBlock(pathOfError) {
|
|
3286
|
-
const
|
|
3287
|
-
|
|
3288
|
-
|
|
3372
|
+
const path = typeof pathOfError === "string" ? toPath(pathOfError) : pathOfError ?? [];
|
|
3373
|
+
if (path.length === 0) {
|
|
3374
|
+
return this.errorSchema;
|
|
3375
|
+
}
|
|
3376
|
+
let errorBlock = getByPath(this.errorSchema, path);
|
|
3377
|
+
if (!errorBlock) {
|
|
3289
3378
|
errorBlock = {};
|
|
3290
|
-
(
|
|
3379
|
+
setByPath(this.errorSchema, path, errorBlock, true);
|
|
3291
3380
|
}
|
|
3292
3381
|
return errorBlock;
|
|
3293
3382
|
}
|
|
@@ -3297,12 +3386,12 @@ var ErrorSchemaBuilder = class {
|
|
|
3297
3386
|
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
3298
3387
|
*/
|
|
3299
3388
|
resetAllErrors(initialSchema) {
|
|
3300
|
-
this.errorSchema = initialSchema ? (
|
|
3389
|
+
this.errorSchema = initialSchema ? structuredClone(initialSchema) : {};
|
|
3301
3390
|
return this;
|
|
3302
3391
|
}
|
|
3303
3392
|
/** Adds the `errorOrList` to the list of errors in the `ErrorSchema` at either the root level or the location within
|
|
3304
|
-
* the schema described by the `pathOfError`.
|
|
3305
|
-
* [
|
|
3393
|
+
* the schema described by the `pathOfError`. The path is either a dotted string (with optional bracketed array
|
|
3394
|
+
* indexes, e.g. `'a.b[0]'`) or a list of path segments; keys containing dots require the list form.
|
|
3306
3395
|
*
|
|
3307
3396
|
* @param errorOrList - The error or list of errors to add into the `ErrorSchema`
|
|
3308
3397
|
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
|
|
@@ -3310,21 +3399,21 @@ var ErrorSchemaBuilder = class {
|
|
|
3310
3399
|
*/
|
|
3311
3400
|
addErrors(errorOrList, pathOfError) {
|
|
3312
3401
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
3313
|
-
let errorsList =
|
|
3402
|
+
let errorsList = errorBlock[ERRORS_KEY];
|
|
3314
3403
|
if (!Array.isArray(errorsList)) {
|
|
3315
3404
|
errorsList = [];
|
|
3316
3405
|
errorBlock[ERRORS_KEY] = errorsList;
|
|
3317
3406
|
}
|
|
3318
3407
|
if (Array.isArray(errorOrList)) {
|
|
3319
|
-
|
|
3408
|
+
errorBlock[ERRORS_KEY] = [.../* @__PURE__ */ new Set([...errorsList, ...errorOrList])];
|
|
3320
3409
|
} else {
|
|
3321
|
-
|
|
3410
|
+
errorBlock[ERRORS_KEY] = [.../* @__PURE__ */ new Set([...errorsList, errorOrList])];
|
|
3322
3411
|
}
|
|
3323
3412
|
return this;
|
|
3324
3413
|
}
|
|
3325
3414
|
/** Sets/replaces the `errorOrList` as the error(s) in the `ErrorSchema` at either the root level or the location
|
|
3326
|
-
* within the schema described by the `pathOfError`.
|
|
3327
|
-
* [
|
|
3415
|
+
* within the schema described by the `pathOfError`. The path is either a dotted string (with optional bracketed array
|
|
3416
|
+
* indexes, e.g. `'a.b[0]'`) or a list of path segments; keys containing dots require the list form.
|
|
3328
3417
|
*
|
|
3329
3418
|
* @param errorOrList - The error or list of errors to set into the `ErrorSchema`
|
|
3330
3419
|
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
|
|
@@ -3333,43 +3422,59 @@ var ErrorSchemaBuilder = class {
|
|
|
3333
3422
|
setErrors(errorOrList, pathOfError) {
|
|
3334
3423
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
3335
3424
|
const listToAdd = Array.isArray(errorOrList) ? [.../* @__PURE__ */ new Set([...errorOrList])] : [errorOrList];
|
|
3336
|
-
|
|
3425
|
+
errorBlock[ERRORS_KEY] = listToAdd;
|
|
3337
3426
|
return this;
|
|
3338
3427
|
}
|
|
3339
3428
|
/** Clears the error(s) in the `ErrorSchema` at either the root level or the location within the schema described by
|
|
3340
|
-
* the `pathOfError`.
|
|
3341
|
-
* [
|
|
3429
|
+
* the `pathOfError`. The path is either a dotted string (with optional bracketed array
|
|
3430
|
+
* indexes, e.g. `'a.b[0]'`) or a list of path segments; keys containing dots require the list form.
|
|
3342
3431
|
*
|
|
3343
3432
|
* @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
|
|
3344
3433
|
* @returns - The `ErrorSchemaBuilder` object for chaining purposes
|
|
3345
3434
|
*/
|
|
3346
3435
|
clearErrors(pathOfError) {
|
|
3347
3436
|
const errorBlock = this.getOrCreateErrorBlock(pathOfError);
|
|
3348
|
-
|
|
3437
|
+
errorBlock[ERRORS_KEY] = [];
|
|
3349
3438
|
return this;
|
|
3350
3439
|
}
|
|
3351
3440
|
};
|
|
3352
3441
|
|
|
3353
3442
|
// src/getChangedFields.ts
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3443
|
+
function getChangedDescendants(a, b) {
|
|
3444
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
3445
|
+
return getChangedFields(a, b, true);
|
|
3446
|
+
}
|
|
3447
|
+
if (Array.isArray(a) && Array.isArray(b) && a.length === b.length) {
|
|
3448
|
+
return a.flatMap((value, index) => {
|
|
3449
|
+
if (deepEquals_default(value, b[index])) {
|
|
3450
|
+
return [];
|
|
3451
|
+
}
|
|
3452
|
+
const descendants = getChangedDescendants(value, b[index]);
|
|
3453
|
+
return descendants.length ? descendants.map((path) => `${index}.${path}`) : [String(index)];
|
|
3454
|
+
});
|
|
3455
|
+
}
|
|
3456
|
+
return [];
|
|
3457
|
+
}
|
|
3458
|
+
function getChangedFields(a, b, deep = false) {
|
|
3459
|
+
if (a === b) {
|
|
3363
3460
|
return [];
|
|
3364
3461
|
}
|
|
3365
|
-
if (
|
|
3366
|
-
return (
|
|
3462
|
+
if (!isPlainObject(a)) {
|
|
3463
|
+
return isPlainObject(b) ? Object.keys(b) : [];
|
|
3367
3464
|
}
|
|
3368
|
-
if (!
|
|
3369
|
-
return
|
|
3465
|
+
if (!isPlainObject(b)) {
|
|
3466
|
+
return Object.keys(a);
|
|
3370
3467
|
}
|
|
3371
|
-
const
|
|
3372
|
-
const
|
|
3468
|
+
const aKeys = Object.keys(a);
|
|
3469
|
+
const aKeySet = new Set(aKeys);
|
|
3470
|
+
const unequalFields = aKeys.filter((key) => !deepEquals_default(a[key], getByPath(b, key))).flatMap((key) => {
|
|
3471
|
+
if (!deep) {
|
|
3472
|
+
return [key];
|
|
3473
|
+
}
|
|
3474
|
+
const descendants = getChangedDescendants(a[key], getByPath(b, key));
|
|
3475
|
+
return descendants.length ? descendants.map((path) => `${key}.${path}`) : [key];
|
|
3476
|
+
});
|
|
3477
|
+
const diffFields = Object.keys(b).filter((key) => !aKeySet.has(key));
|
|
3373
3478
|
return [...unequalFields, ...diffFields];
|
|
3374
3479
|
}
|
|
3375
3480
|
|
|
@@ -3448,6 +3553,9 @@ function getInputProps(schema, defaultType, options = {}, autoDefaultStepAny = t
|
|
|
3448
3553
|
if (options.autocomplete) {
|
|
3449
3554
|
inputProps.autoComplete = options.autocomplete;
|
|
3450
3555
|
}
|
|
3556
|
+
if (options.autocapitalize) {
|
|
3557
|
+
inputProps.autoCapitalize = options.autocapitalize;
|
|
3558
|
+
}
|
|
3451
3559
|
if (options.accept) {
|
|
3452
3560
|
inputProps.accept = options.accept;
|
|
3453
3561
|
}
|
|
@@ -3494,10 +3602,9 @@ function getTemplate(name, registry, uiOptions = {}) {
|
|
|
3494
3602
|
}
|
|
3495
3603
|
|
|
3496
3604
|
// src/getTestIds.ts
|
|
3497
|
-
var
|
|
3498
|
-
var import_uniqueId = __toESM(require("lodash/uniqueId"), 1);
|
|
3605
|
+
var testIdCounter = 0;
|
|
3499
3606
|
function getTestIds() {
|
|
3500
|
-
if ((
|
|
3607
|
+
if (getByPath(globalThis, ["process", "env", "NODE_ENV"]) !== "test") {
|
|
3501
3608
|
return {};
|
|
3502
3609
|
}
|
|
3503
3610
|
const ids = /* @__PURE__ */ new Map();
|
|
@@ -3506,7 +3613,8 @@ function getTestIds() {
|
|
|
3506
3613
|
{
|
|
3507
3614
|
get(_obj, prop) {
|
|
3508
3615
|
if (!ids.has(prop)) {
|
|
3509
|
-
|
|
3616
|
+
testIdCounter += 1;
|
|
3617
|
+
ids.set(prop, `test-id-${testIdCounter}`);
|
|
3510
3618
|
}
|
|
3511
3619
|
return ids.get(prop);
|
|
3512
3620
|
}
|
|
@@ -3516,8 +3624,6 @@ function getTestIds() {
|
|
|
3516
3624
|
|
|
3517
3625
|
// src/getWidget.tsx
|
|
3518
3626
|
var import_react = require("react");
|
|
3519
|
-
var import_get20 = __toESM(require("lodash/get"), 1);
|
|
3520
|
-
var import_set4 = __toESM(require("lodash/set"), 1);
|
|
3521
3627
|
var import_react_is = __toESM(require("react-is"), 1);
|
|
3522
3628
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
3523
3629
|
var widgetMap = {
|
|
@@ -3573,11 +3679,11 @@ var widgetMap = {
|
|
|
3573
3679
|
}
|
|
3574
3680
|
};
|
|
3575
3681
|
function mergeWidgetOptions(AWidget) {
|
|
3576
|
-
let MergedWidget =
|
|
3682
|
+
let { MergedWidget } = AWidget;
|
|
3577
3683
|
if (!MergedWidget) {
|
|
3578
3684
|
const defaultOptions = AWidget.defaultProps?.options || {};
|
|
3579
3685
|
MergedWidget = ({ options, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AWidget, { options: { ...defaultOptions, ...options }, ...props });
|
|
3580
|
-
|
|
3686
|
+
AWidget.MergedWidget = MergedWidget;
|
|
3581
3687
|
}
|
|
3582
3688
|
return MergedWidget;
|
|
3583
3689
|
}
|
|
@@ -3616,12 +3722,18 @@ function hashString(string) {
|
|
|
3616
3722
|
return hash.toString(16);
|
|
3617
3723
|
}
|
|
3618
3724
|
function sortedJSONStringify(object) {
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3725
|
+
function shouldIncludeValue(value) {
|
|
3726
|
+
return value !== void 0 && typeof value !== "function" && typeof value !== "symbol";
|
|
3727
|
+
}
|
|
3728
|
+
if (Array.isArray(object)) {
|
|
3729
|
+
return `[${object.map((x) => x === void 0 ? "undefined" : sortedJSONStringify(x)).join(",")}]`;
|
|
3730
|
+
}
|
|
3731
|
+
if (object === null || typeof object !== "object") {
|
|
3732
|
+
return JSON.stringify(typeof object === "function" ? null : object);
|
|
3733
|
+
}
|
|
3734
|
+
const record = object;
|
|
3735
|
+
const sortedValues = Object.keys(record).sort().filter((key) => shouldIncludeValue(record[key])).map((key) => `${JSON.stringify(key)}:${sortedJSONStringify(record[key])}`);
|
|
3736
|
+
return `{${sortedValues.join(",")}}`;
|
|
3625
3737
|
}
|
|
3626
3738
|
function hashObject(object) {
|
|
3627
3739
|
return hashString(sortedJSONStringify(object));
|
|
@@ -3645,9 +3757,8 @@ function hasWidget(schema, widget, registeredWidgets = {}) {
|
|
|
3645
3757
|
}
|
|
3646
3758
|
|
|
3647
3759
|
// src/idGenerators.ts
|
|
3648
|
-
var import_isString4 = __toESM(require("lodash/isString"), 1);
|
|
3649
3760
|
function idGenerator(id, suffix) {
|
|
3650
|
-
const theId =
|
|
3761
|
+
const theId = typeof id === "string" ? id : id[ID_KEY];
|
|
3651
3762
|
return `${theId}__${suffix}`;
|
|
3652
3763
|
}
|
|
3653
3764
|
function descriptionId(id) {
|
|
@@ -3680,11 +3791,14 @@ function optionalControlsId(id, element) {
|
|
|
3680
3791
|
}
|
|
3681
3792
|
|
|
3682
3793
|
// src/isFormDataAvailable.ts
|
|
3683
|
-
var import_isEmpty6 = __toESM(require("lodash/isEmpty"), 1);
|
|
3684
|
-
var import_isNil5 = __toESM(require("lodash/isNil"), 1);
|
|
3685
|
-
var import_isObject13 = __toESM(require("lodash/isObject"), 1);
|
|
3686
3794
|
function isFormDataAvailable(formData) {
|
|
3687
|
-
|
|
3795
|
+
if (formData === void 0 || formData === null) {
|
|
3796
|
+
return false;
|
|
3797
|
+
}
|
|
3798
|
+
if (typeof formData !== "object" || Array.isArray(formData)) {
|
|
3799
|
+
return true;
|
|
3800
|
+
}
|
|
3801
|
+
return Object.keys(formData).length > 0;
|
|
3688
3802
|
}
|
|
3689
3803
|
|
|
3690
3804
|
// src/isRootSchema.ts
|
|
@@ -3720,14 +3834,12 @@ function logUnsupportedDefaultForEnum(id, schema, enumOptions, multiple = false)
|
|
|
3720
3834
|
}
|
|
3721
3835
|
|
|
3722
3836
|
// src/lookupFromFormContext.ts
|
|
3723
|
-
var import_get21 = __toESM(require("lodash/get"), 1);
|
|
3724
|
-
var import_has6 = __toESM(require("lodash/has"), 1);
|
|
3725
3837
|
function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
3726
3838
|
const lookupPath = [LOOKUP_MAP_NAME];
|
|
3727
|
-
if ((
|
|
3839
|
+
if (hasByPath(regOrFc, FORM_CONTEXT_NAME)) {
|
|
3728
3840
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
3729
3841
|
}
|
|
3730
|
-
return (
|
|
3842
|
+
return getByPath(regOrFc, [...lookupPath, toLookup], fallback);
|
|
3731
3843
|
}
|
|
3732
3844
|
|
|
3733
3845
|
// src/nameGenerators.ts
|
|
@@ -3750,6 +3862,10 @@ var dotNotationNameGenerator = (path, idPrefix, _isMultiValue) => {
|
|
|
3750
3862
|
return `${idPrefix}.${path.map(String).join(".")}`;
|
|
3751
3863
|
};
|
|
3752
3864
|
|
|
3865
|
+
// src/noop.ts
|
|
3866
|
+
function noop() {
|
|
3867
|
+
}
|
|
3868
|
+
|
|
3753
3869
|
// src/orderProperties.ts
|
|
3754
3870
|
function orderProperties(properties, order) {
|
|
3755
3871
|
if (!Array.isArray(order)) {
|
|
@@ -3864,7 +3980,6 @@ function removeOptionalEmptyObjects(validator, schema, rootSchema, formData) {
|
|
|
3864
3980
|
}
|
|
3865
3981
|
|
|
3866
3982
|
// src/resolveUiSchema.ts
|
|
3867
|
-
var import_isEmpty7 = __toESM(require("lodash/isEmpty"), 1);
|
|
3868
3983
|
function resolveUiSchema(schema, localUiSchema, registry) {
|
|
3869
3984
|
const ref = schema[RJSF_REF_KEY] ?? schema[REF_KEY];
|
|
3870
3985
|
const definitions = registry.uiSchemaDefinitions;
|
|
@@ -3872,7 +3987,7 @@ function resolveUiSchema(schema, localUiSchema, registry) {
|
|
|
3872
3987
|
let result;
|
|
3873
3988
|
if (!definitionUiSchema) {
|
|
3874
3989
|
result = localUiSchema || {};
|
|
3875
|
-
} else if (!localUiSchema ||
|
|
3990
|
+
} else if (!localUiSchema || Object.keys(localUiSchema).length === 0) {
|
|
3876
3991
|
result = { ...definitionUiSchema };
|
|
3877
3992
|
} else {
|
|
3878
3993
|
result = mergeObjects(definitionUiSchema, localUiSchema);
|
|
@@ -4003,12 +4118,12 @@ function shouldRender(component, nextProps, nextState, updateStrategy = "customD
|
|
|
4003
4118
|
}
|
|
4004
4119
|
|
|
4005
4120
|
// src/shouldRenderOptionalField.ts
|
|
4006
|
-
var import_isObject15 = __toESM(require("lodash/isObject"), 1);
|
|
4007
|
-
var import_uniq2 = __toESM(require("lodash/uniq"), 1);
|
|
4008
4121
|
function getSchemaTypesForXxxOf(schemas) {
|
|
4009
|
-
const allTypes =
|
|
4010
|
-
|
|
4011
|
-
|
|
4122
|
+
const allTypes = [
|
|
4123
|
+
...new Set(
|
|
4124
|
+
schemas.map((s) => isObject(s) ? getSchemaType(s) : void 0).flat().filter((t) => t !== void 0)
|
|
4125
|
+
)
|
|
4126
|
+
];
|
|
4012
4127
|
return allTypes.length === 1 ? allTypes[0] : allTypes;
|
|
4013
4128
|
}
|
|
4014
4129
|
function shouldRenderOptionalField(registry, schema, required, uiSchema) {
|
|
@@ -4033,46 +4148,29 @@ function toDateString(dateObject, time = true) {
|
|
|
4033
4148
|
}
|
|
4034
4149
|
|
|
4035
4150
|
// src/toErrorList.ts
|
|
4036
|
-
var import_isPlainObject3 = __toESM(require("lodash/isPlainObject"), 1);
|
|
4037
4151
|
function toErrorList(errorSchema, fieldPath = []) {
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
errorSchema[ERRORS_KEY].map((message) => {
|
|
4045
|
-
const property = `.${fieldPath.join(".")}`;
|
|
4046
|
-
return {
|
|
4047
|
-
property,
|
|
4048
|
-
message,
|
|
4049
|
-
stack: `${property} ${message}`
|
|
4050
|
-
};
|
|
4051
|
-
})
|
|
4052
|
-
);
|
|
4053
|
-
}
|
|
4152
|
+
return errorSchema ? errorsFrom(errorSchema, fieldPath) : [];
|
|
4153
|
+
}
|
|
4154
|
+
function errorsFrom(errorSchema, fieldPath) {
|
|
4155
|
+
const errors = errorSchema[ERRORS_KEY];
|
|
4156
|
+
const property = `.${fieldPath.join(".")}`;
|
|
4157
|
+
const errorList = Array.isArray(errors) ? errors.map((message) => ({ property, message, stack: `${property} ${message}` })) : [];
|
|
4054
4158
|
return Object.keys(errorSchema).reduce((currentList, key) => {
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
return currentList.concat(toErrorList(childSchema, [...fieldPath, key]));
|
|
4059
|
-
}
|
|
4159
|
+
const childSchema = errorSchema[key];
|
|
4160
|
+
if (key !== ERRORS_KEY && isPlainObject(childSchema)) {
|
|
4161
|
+
return currentList.concat(errorsFrom(childSchema, [...fieldPath, key]));
|
|
4060
4162
|
}
|
|
4061
4163
|
return currentList;
|
|
4062
4164
|
}, errorList);
|
|
4063
4165
|
}
|
|
4064
4166
|
|
|
4065
4167
|
// src/toErrorSchema.ts
|
|
4066
|
-
var import_toPath = __toESM(require("lodash/toPath"), 1);
|
|
4067
4168
|
function toErrorSchema(errors) {
|
|
4068
4169
|
const builder = new ErrorSchemaBuilder();
|
|
4069
4170
|
if (errors.length) {
|
|
4070
4171
|
errors.forEach((error) => {
|
|
4071
4172
|
const { property, message } = error;
|
|
4072
|
-
const path = property
|
|
4073
|
-
if (path.length > 0 && path[0] === "") {
|
|
4074
|
-
path.splice(0, 1);
|
|
4075
|
-
}
|
|
4173
|
+
const path = property ? toPath(property) : [];
|
|
4076
4174
|
if (message) {
|
|
4077
4175
|
builder.addErrors(message, path);
|
|
4078
4176
|
}
|
|
@@ -4095,17 +4193,19 @@ function toFieldPathId(fieldPath, globalFormOptions, parentPath, isMultiValue) {
|
|
|
4095
4193
|
}
|
|
4096
4194
|
|
|
4097
4195
|
// src/unwrapErrorHandler.ts
|
|
4098
|
-
var import_isPlainObject4 = __toESM(require("lodash/isPlainObject"), 1);
|
|
4099
4196
|
function unwrapErrorHandler(errorHandler) {
|
|
4100
|
-
return
|
|
4197
|
+
return unwrapErrors(errorHandler);
|
|
4198
|
+
}
|
|
4199
|
+
function unwrapErrors(errors) {
|
|
4200
|
+
return Object.keys(errors).reduce((acc, key) => {
|
|
4101
4201
|
if (key === "addError") {
|
|
4102
4202
|
return acc;
|
|
4103
4203
|
}
|
|
4104
|
-
const childSchema =
|
|
4105
|
-
if ((
|
|
4204
|
+
const childSchema = errors[key];
|
|
4205
|
+
if (isPlainObject(childSchema)) {
|
|
4106
4206
|
return {
|
|
4107
4207
|
...acc,
|
|
4108
|
-
[key]:
|
|
4208
|
+
[key]: unwrapErrors(childSchema)
|
|
4109
4209
|
};
|
|
4110
4210
|
}
|
|
4111
4211
|
return { ...acc, [key]: childSchema };
|
|
@@ -4330,7 +4430,6 @@ function utcToLocal(jsonDate) {
|
|
|
4330
4430
|
}
|
|
4331
4431
|
|
|
4332
4432
|
// src/validationDataMerge.ts
|
|
4333
|
-
var import_isEmpty8 = __toESM(require("lodash/isEmpty"), 1);
|
|
4334
4433
|
function validationDataMerge(validationData, additionalErrorSchema, preventDuplicates = false) {
|
|
4335
4434
|
if (!additionalErrorSchema) {
|
|
4336
4435
|
return validationData;
|
|
@@ -4338,7 +4437,7 @@ function validationDataMerge(validationData, additionalErrorSchema, preventDupli
|
|
|
4338
4437
|
const { errors: oldErrors, errorSchema: oldErrorSchema } = validationData;
|
|
4339
4438
|
let errors = toErrorList(additionalErrorSchema);
|
|
4340
4439
|
let errorSchema = additionalErrorSchema;
|
|
4341
|
-
if (
|
|
4440
|
+
if (oldErrorSchema && Object.keys(oldErrorSchema).length > 0) {
|
|
4342
4441
|
errorSchema = mergeObjects(
|
|
4343
4442
|
oldErrorSchema,
|
|
4344
4443
|
additionalErrorSchema,
|
|
@@ -4350,7 +4449,6 @@ function validationDataMerge(validationData, additionalErrorSchema, preventDupli
|
|
|
4350
4449
|
}
|
|
4351
4450
|
|
|
4352
4451
|
// src/withIdRefPrefix.ts
|
|
4353
|
-
var import_isObject16 = __toESM(require("lodash/isObject"), 1);
|
|
4354
4452
|
function withIdRefPrefixObject(node) {
|
|
4355
4453
|
const realObj = node;
|
|
4356
4454
|
for (const key in realObj) {
|
|
@@ -4372,7 +4470,7 @@ function withIdRefPrefix(schemaNode) {
|
|
|
4372
4470
|
if (Array.isArray(schemaNode)) {
|
|
4373
4471
|
return withIdRefPrefixArray([...schemaNode]);
|
|
4374
4472
|
}
|
|
4375
|
-
if ((
|
|
4473
|
+
if (isObject(schemaNode)) {
|
|
4376
4474
|
return withIdRefPrefixObject({ ...schemaNode });
|
|
4377
4475
|
}
|
|
4378
4476
|
return schemaNode;
|
|
@@ -4422,20 +4520,18 @@ var TranslatableString = /* @__PURE__ */ ((TranslatableString2) => {
|
|
|
4422
4520
|
return TranslatableString2;
|
|
4423
4521
|
})(TranslatableString || {});
|
|
4424
4522
|
|
|
4425
|
-
// src/parser/schemaParser.ts
|
|
4426
|
-
var import_forEach = __toESM(require("lodash/forEach"), 1);
|
|
4427
|
-
|
|
4428
4523
|
// src/parser/ParserValidator.ts
|
|
4429
|
-
var import_get22 = __toESM(require("lodash/get"), 1);
|
|
4430
4524
|
var ParserValidator = class {
|
|
4525
|
+
/** The rootSchema provided during construction of the class */
|
|
4526
|
+
rootSchema;
|
|
4527
|
+
/** The map of schemas encountered by the ParserValidator */
|
|
4528
|
+
schemaMap = {};
|
|
4431
4529
|
/** Construct the ParserValidator for the given `rootSchema`. This `rootSchema` will be stashed in the `schemaMap`
|
|
4432
4530
|
* first.
|
|
4433
4531
|
*
|
|
4434
4532
|
* @param rootSchema - The root schema against which this validator will be executed
|
|
4435
4533
|
*/
|
|
4436
4534
|
constructor(rootSchema) {
|
|
4437
|
-
/** The map of schemas encountered by the ParserValidator */
|
|
4438
|
-
this.schemaMap = {};
|
|
4439
4535
|
this.rootSchema = rootSchema;
|
|
4440
4536
|
this.addSchema(rootSchema, hashForSchema(rootSchema));
|
|
4441
4537
|
}
|
|
@@ -4452,7 +4548,7 @@ var ParserValidator = class {
|
|
|
4452
4548
|
* @param hash - The hash value at which to map the schema
|
|
4453
4549
|
*/
|
|
4454
4550
|
addSchema(schema, hash) {
|
|
4455
|
-
const key =
|
|
4551
|
+
const key = schema[ID_KEY] ?? hash;
|
|
4456
4552
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
4457
4553
|
const existing = this.schemaMap[key];
|
|
4458
4554
|
if (!existing) {
|
|
@@ -4525,9 +4621,9 @@ function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
|
4525
4621
|
const allOptions = resolveAnyOrOneOfSchemas(validator, localSchema, rootSchema, true);
|
|
4526
4622
|
allOptions.forEach((s) => {
|
|
4527
4623
|
if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
|
|
4528
|
-
(
|
|
4624
|
+
for (const value of Object.values(localSchema[PROPERTIES_KEY] ?? {})) {
|
|
4529
4625
|
parseSchema(validator, recurseList, rootSchema, value);
|
|
4530
|
-
}
|
|
4626
|
+
}
|
|
4531
4627
|
}
|
|
4532
4628
|
});
|
|
4533
4629
|
if (ITEMS_KEY in localSchema && !Array.isArray(localSchema.items) && typeof localSchema.items !== "boolean") {
|