@es-joy/jsoe 0.24.2 → 0.25.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/.claude/settings.local.json +9 -0
- package/.ncurc.cjs +2 -2
- package/CHANGES.md +51 -0
- package/README.md +23 -13
- package/badges/coverage-badge.svg +1 -1
- package/dist/eslint.config.d.ts +3 -0
- package/dist/eslint.config.d.ts.map +1 -0
- package/dist/formatAndTypeChoices.d.ts +28 -30
- package/dist/formatAndTypeChoices.d.ts.map +1 -1
- package/dist/formats/indexedDBKey.d.ts.map +1 -1
- package/dist/formats/schema.d.ts +46 -3
- package/dist/formats/schema.d.ts.map +1 -1
- package/dist/formats/structuredCloning.d.ts +3 -0
- package/dist/formats/structuredCloning.d.ts.map +1 -1
- package/dist/formats.d.ts +24 -6
- package/dist/formats.d.ts.map +1 -1
- package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/arrayReferenceType.d.ts.map +1 -1
- package/dist/fundamentalTypes/arrayType.d.ts +7 -0
- package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
- package/dist/fundamentalTypes/bigintObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/bigintType.d.ts +10 -0
- package/dist/fundamentalTypes/bigintType.d.ts.map +1 -1
- package/dist/fundamentalTypes/blobType.d.ts.map +1 -1
- package/dist/fundamentalTypes/booleanType.d.ts.map +1 -1
- package/dist/fundamentalTypes/catchType.d.ts +2 -2
- package/dist/fundamentalTypes/catchType.d.ts.map +1 -1
- package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
- package/dist/fundamentalTypes/domexceptionType.d.ts.map +1 -1
- package/dist/fundamentalTypes/enumType.d.ts +2 -2
- package/dist/fundamentalTypes/enumType.d.ts.map +1 -1
- package/dist/fundamentalTypes/errorType.d.ts.map +1 -1
- package/dist/fundamentalTypes/fileType.d.ts +6 -0
- package/dist/fundamentalTypes/fileType.d.ts.map +1 -1
- package/dist/fundamentalTypes/functionType.d.ts.map +1 -1
- package/dist/fundamentalTypes/literalType.d.ts +3 -2
- package/dist/fundamentalTypes/literalType.d.ts.map +1 -1
- package/dist/fundamentalTypes/looseRecordType.d.ts +6 -0
- package/dist/fundamentalTypes/looseRecordType.d.ts.map +1 -0
- package/dist/fundamentalTypes/nanType.d.ts.map +1 -1
- package/dist/fundamentalTypes/neverType.d.ts +2 -2
- package/dist/fundamentalTypes/neverType.d.ts.map +1 -1
- package/dist/fundamentalTypes/noneditableType.d.ts.map +1 -1
- package/dist/fundamentalTypes/nullType.d.ts.map +1 -1
- package/dist/fundamentalTypes/numberType.d.ts.map +1 -1
- package/dist/fundamentalTypes/promiseType.d.ts.map +1 -1
- package/dist/fundamentalTypes/regexpType.d.ts.map +1 -1
- package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
- package/dist/fundamentalTypes/symbolType.d.ts.map +1 -1
- package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
- package/dist/fundamentalTypes/voidType.d.ts +2 -2
- package/dist/fundamentalTypes/voidType.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/rollup.config.d.ts +30 -0
- package/dist/rollup.config.d.ts.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/src/formatAndTypeChoices.d.ts +108 -0
- package/dist/src/formatAndTypeChoices.d.ts.map +1 -0
- package/dist/src/formats/arbitraryJS.d.ts +4 -0
- package/dist/src/formats/arbitraryJS.d.ts.map +1 -0
- package/dist/src/formats/indexedDBKey.d.ts +4 -0
- package/dist/src/formats/indexedDBKey.d.ts.map +1 -0
- package/dist/src/formats/json.d.ts +4 -0
- package/dist/src/formats/json.d.ts.map +1 -0
- package/dist/src/formats/schema.d.ts +17 -0
- package/dist/src/formats/schema.d.ts.map +1 -0
- package/dist/src/formats/structuredCloning.d.ts +19 -0
- package/dist/src/formats/structuredCloning.d.ts.map +1 -0
- package/dist/src/formats.d.ts +135 -0
- package/dist/src/formats.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/BooleanObjectType.d.ts +8 -0
- package/dist/src/fundamentalTypes/BooleanObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/NumberObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/NumberObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/StringObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/StringObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/arrayReferenceType.d.ts +8 -0
- package/dist/src/fundamentalTypes/arrayReferenceType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/arrayType.d.ts +29 -0
- package/dist/src/fundamentalTypes/arrayType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/bigintObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/bigintObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/bigintType.d.ts +6 -0
- package/dist/src/fundamentalTypes/bigintType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/blobType.d.ts +11 -0
- package/dist/src/fundamentalTypes/blobType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/booleanType.d.ts +8 -0
- package/dist/src/fundamentalTypes/booleanType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/catchType.d.ts +6 -0
- package/dist/src/fundamentalTypes/catchType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/dateType.d.ts +26 -0
- package/dist/src/fundamentalTypes/dateType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/domexceptionType.d.ts +6 -0
- package/dist/src/fundamentalTypes/domexceptionType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/enumType.d.ts +6 -0
- package/dist/src/fundamentalTypes/enumType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/errorType.d.ts +6 -0
- package/dist/src/fundamentalTypes/errorType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/fileType.d.ts +13 -0
- package/dist/src/fundamentalTypes/fileType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/filelistType.d.ts +6 -0
- package/dist/src/fundamentalTypes/filelistType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/functionType.d.ts +7 -0
- package/dist/src/fundamentalTypes/functionType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/literalType.d.ts +6 -0
- package/dist/src/fundamentalTypes/literalType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/mapType.d.ts +6 -0
- package/dist/src/fundamentalTypes/mapType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/nanType.d.ts +6 -0
- package/dist/src/fundamentalTypes/nanType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/neverType.d.ts +6 -0
- package/dist/src/fundamentalTypes/neverType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/noneditableType.d.ts +6 -0
- package/dist/src/fundamentalTypes/noneditableType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/nullType.d.ts +6 -0
- package/dist/src/fundamentalTypes/nullType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/numberType.d.ts +6 -0
- package/dist/src/fundamentalTypes/numberType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/objectReferenceType.d.ts +8 -0
- package/dist/src/fundamentalTypes/objectReferenceType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/objectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/objectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/promiseType.d.ts +6 -0
- package/dist/src/fundamentalTypes/promiseType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/recordType.d.ts +6 -0
- package/dist/src/fundamentalTypes/recordType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/regexpType.d.ts +8 -0
- package/dist/src/fundamentalTypes/regexpType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/setType.d.ts +6 -0
- package/dist/src/fundamentalTypes/setType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts +6 -0
- package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/stringType.d.ts +6 -0
- package/dist/src/fundamentalTypes/stringType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/symbolType.d.ts +8 -0
- package/dist/src/fundamentalTypes/symbolType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/tupleType.d.ts +6 -0
- package/dist/src/fundamentalTypes/tupleType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/undefinedType.d.ts +6 -0
- package/dist/src/fundamentalTypes/undefinedType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/voidType.d.ts +6 -0
- package/dist/src/fundamentalTypes/voidType.d.ts.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/subTypes/blobHTMLType.d.ts +20 -0
- package/dist/src/subTypes/blobHTMLType.d.ts.map +1 -0
- package/dist/src/subTypes/falseType.d.ts +8 -0
- package/dist/src/subTypes/falseType.d.ts.map +1 -0
- package/dist/src/subTypes/trueType.d.ts +8 -0
- package/dist/src/subTypes/trueType.d.ts.map +1 -0
- package/dist/src/superTypes/SpecialNumberType.d.ts +6 -0
- package/dist/src/superTypes/SpecialNumberType.d.ts.map +1 -0
- package/dist/src/superTypes/SpecialRealNumberType.d.ts +6 -0
- package/dist/src/superTypes/SpecialRealNumberType.d.ts.map +1 -0
- package/dist/src/superTypes/buffersourceType.d.ts +8 -0
- package/dist/src/superTypes/buffersourceType.d.ts.map +1 -0
- package/dist/src/superTypes/dommatrixType.d.ts +6 -0
- package/dist/src/superTypes/dommatrixType.d.ts.map +1 -0
- package/dist/src/superTypes/dompointType.d.ts +6 -0
- package/dist/src/superTypes/dompointType.d.ts.map +1 -0
- package/dist/src/superTypes/domrectType.d.ts +6 -0
- package/dist/src/superTypes/domrectType.d.ts.map +1 -0
- package/dist/src/superTypes/errorsSpecialType.d.ts +8 -0
- package/dist/src/superTypes/errorsSpecialType.d.ts.map +1 -0
- package/dist/src/typeChoices.d.ts +140 -0
- package/dist/src/typeChoices.d.ts.map +1 -0
- package/dist/src/types.d.ts +758 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils/FileList.d.ts +26 -0
- package/dist/src/utils/FileList.d.ts.map +1 -0
- package/dist/src/utils/dialogs.d.ts +111 -0
- package/dist/src/utils/dialogs.d.ts.map +1 -0
- package/dist/src/utils/jsonPointer.d.ts +46 -0
- package/dist/src/utils/jsonPointer.d.ts.map +1 -0
- package/dist/src/utils/media.d.ts +18 -0
- package/dist/src/utils/media.d.ts.map +1 -0
- package/dist/src/utils/objects.d.ts +16 -0
- package/dist/src/utils/objects.d.ts.map +1 -0
- package/dist/src/utils/templateUtils.d.ts +59 -0
- package/dist/src/utils/templateUtils.d.ts.map +1 -0
- package/dist/src/utils/types.d.ts +2 -0
- package/dist/src/utils/types.d.ts.map +1 -0
- package/dist/src/vendor-imports.d.ts +4 -0
- package/dist/src/vendor-imports.d.ts.map +1 -0
- package/dist/subTypes/blobHTMLType.d.ts.map +1 -1
- package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -1
- package/dist/superTypes/buffersourceType.d.ts.map +1 -1
- package/dist/superTypes/dommatrixType.d.ts.map +1 -1
- package/dist/superTypes/dompointType.d.ts.map +1 -1
- package/dist/superTypes/domrectType.d.ts.map +1 -1
- package/dist/superTypes/errorsSpecialType.d.ts.map +1 -1
- package/dist/typeChoices.d.ts +21 -87
- package/dist/typeChoices.d.ts.map +1 -1
- package/dist/types.d.ts +90 -64
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/FileList.d.ts +4 -3
- package/dist/utils/FileList.d.ts.map +1 -1
- package/dist/utils/dialogs.d.ts +4 -4
- package/dist/utils/dialogs.d.ts.map +1 -1
- package/dist/utils/media.d.ts.map +1 -1
- package/dist/utils/schemaMeta.d.ts +92 -0
- package/dist/utils/schemaMeta.d.ts.map +1 -0
- package/dist/utils/templateUtils.d.ts +3 -3
- package/dist/utils/templateUtils.d.ts.map +1 -1
- package/dist/utils/timing.d.ts +2 -0
- package/dist/utils/timing.d.ts.map +1 -0
- package/dist/utils/types.d.ts +1 -0
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/vendor-imports.d.ts +3 -1
- package/docs/proposals/schema-meta.md +233 -0
- package/eslint.config.js +51 -4
- package/licenseInfo.json +1 -1
- package/package.json +52 -42
- package/pnpm-workspace.yaml +57 -0
- package/rollup.config.js +20 -18
- package/server.js +3 -3
- package/src/deepEqual.js +77 -66
- package/src/deepEqual.js.map +1 -1
- package/src/formatAndTypeChoices.js +62 -58
- package/src/formats/indexedDBKey.js +3 -4
- package/src/formats/schema.js +824 -475
- package/src/formats/structuredCloning.js +189 -80
- package/src/formats.js +17 -5
- package/src/fundamentalTypes/BooleanObjectType.js +4 -5
- package/src/fundamentalTypes/NumberObjectType.js +4 -4
- package/src/fundamentalTypes/StringObjectType.js +3 -4
- package/src/fundamentalTypes/arrayReferenceType.js +0 -2
- package/src/fundamentalTypes/arrayType.js +624 -389
- package/src/fundamentalTypes/bigintObjectType.js +3 -2
- package/src/fundamentalTypes/bigintType.js +79 -17
- package/src/fundamentalTypes/blobType.js +35 -35
- package/src/fundamentalTypes/booleanType.js +16 -8
- package/src/fundamentalTypes/dateType.js +6 -8
- package/src/fundamentalTypes/domexceptionType.js +5 -4
- package/src/fundamentalTypes/errorType.js +39 -32
- package/src/fundamentalTypes/fileType.js +238 -52
- package/src/fundamentalTypes/functionType.js +61 -41
- package/src/fundamentalTypes/nanType.js +5 -4
- package/src/fundamentalTypes/noneditableType.js +4 -3
- package/src/fundamentalTypes/nullType.js +3 -2
- package/src/fundamentalTypes/numberType.js +72 -20
- package/src/fundamentalTypes/promiseType.js +16 -40
- package/src/fundamentalTypes/regexpType.js +7 -13
- package/src/fundamentalTypes/stringType.js +176 -110
- package/src/fundamentalTypes/symbolType.js +3 -2
- package/src/fundamentalTypes/undefinedType.js +3 -2
- package/src/index.js +6 -5
- package/src/jsoe.css +107 -8
- package/src/subTypes/blobHTMLType.js +23 -10
- package/src/superTypes/SpecialNumberType.js +6 -6
- package/src/superTypes/SpecialRealNumberType.js +10 -9
- package/src/superTypes/buffersourceType.js +86 -75
- package/src/superTypes/dommatrixType.js +6 -5
- package/src/superTypes/dompointType.js +6 -5
- package/src/superTypes/domrectType.js +6 -5
- package/src/superTypes/errorsSpecialType.js +54 -35
- package/src/typeChoices.js +373 -53
- package/src/types.js +157 -97
- package/src/utils/FileList.js +3 -3
- package/src/utils/dialogs.js +5 -7
- package/src/utils/jsonPointer.js +1 -1
- package/src/utils/media.js +1 -0
- package/src/utils/schemaMeta.js +257 -0
- package/src/utils/templateUtils.js +3 -3
- package/src/utils/timing.js +12 -0
- package/src/utils/types.js +19 -0
- package/src/vendor-imports.js +10 -2
- package/tsconfig.json +2 -0
- package/vendor/acorn/dist/acorn.d.mts +46 -5
- package/vendor/acorn/dist/acorn.d.ts +46 -5
- package/vendor/acorn/dist/acorn.js +394 -117
- package/vendor/acorn/dist/acorn.mjs +394 -117
- package/vendor/acorn/dist/bin.js +1 -1
- package/vendor/jamilih/dist/{jml-es.js → jml.mjs} +590 -312
- package/vendor/jamilih/package.json +1 -1
- package/vendor/mime/dist/types/other.js +719 -0
- package/vendor/mime/dist/types/standard.js +366 -0
- package/vendor/typeson-registry/dist/index.js +519 -99
- package/vendor/zod/classic/checks.d.ts +1 -0
- package/vendor/zod/classic/checks.js +1 -0
- package/vendor/zod/classic/coerce.d.ts +17 -0
- package/vendor/zod/classic/coerce.js +17 -0
- package/vendor/zod/classic/compat.d.ts +48 -0
- package/vendor/zod/classic/compat.js +31 -0
- package/vendor/zod/classic/deep-partial.d.ts +14 -0
- package/vendor/zod/classic/deep-partial.js +13 -0
- package/vendor/zod/classic/errors.d.ts +29 -0
- package/vendor/zod/classic/errors.js +57 -0
- package/vendor/zod/classic/external.d.ts +19 -0
- package/vendor/zod/classic/external.js +17 -0
- package/vendor/zod/classic/from-json-schema.d.ts +12 -0
- package/vendor/zod/classic/from-json-schema.js +660 -0
- package/vendor/zod/classic/in-out.d.ts +8 -0
- package/vendor/zod/classic/in-out.js +36 -0
- package/vendor/zod/classic/index.d.ts +3 -0
- package/vendor/zod/classic/index.js +4 -0
- package/vendor/zod/classic/iso.d.ts +7 -0
- package/vendor/zod/classic/iso.js +15 -0
- package/vendor/zod/classic/package.json +7 -0
- package/vendor/zod/classic/parse.d.ts +44 -0
- package/vendor/zod/classic/parse.js +16 -0
- package/vendor/zod/classic/schemas.d.ts +802 -0
- package/vendor/zod/classic/schemas.js +1491 -0
- package/vendor/zod/core/api.d.ts +329 -0
- package/vendor/zod/core/api.js +1104 -0
- package/vendor/zod/core/checks.d.ts +278 -0
- package/vendor/zod/core/checks.js +581 -0
- package/vendor/zod/core/compile.d.ts +51 -0
- package/vendor/zod/core/compile.js +1783 -0
- package/vendor/zod/core/core.d.ts +82 -0
- package/vendor/zod/core/core.js +141 -0
- package/vendor/zod/core/doc.d.ts +16 -0
- package/vendor/zod/core/doc.js +33 -0
- package/vendor/zod/core/errors.d.ts +225 -0
- package/vendor/zod/core/errors.js +270 -0
- package/vendor/zod/core/index.d.ts +19 -0
- package/vendor/zod/core/index.js +19 -0
- package/vendor/zod/core/json-schema-generator.d.ts +65 -0
- package/vendor/zod/core/json-schema-generator.js +99 -0
- package/vendor/zod/core/json-schema-processors.d.ts +49 -0
- package/vendor/zod/core/json-schema-processors.js +747 -0
- package/vendor/zod/core/json-schema.d.ts +89 -0
- package/vendor/zod/core/memoizer.d.ts +15 -0
- package/vendor/zod/core/memoizer.js +265 -0
- package/vendor/zod/core/package.json +7 -0
- package/vendor/zod/core/parse.d.ts +52 -0
- package/vendor/zod/core/parse.js +154 -0
- package/vendor/zod/core/regexes.d.ts +87 -0
- package/vendor/zod/core/regexes.js +150 -0
- package/vendor/zod/core/registries.d.ts +35 -0
- package/vendor/zod/core/registries.js +51 -0
- package/vendor/zod/core/schemas.d.ts +1253 -0
- package/vendor/zod/core/schemas.js +2440 -0
- package/vendor/zod/core/standard-schema.d.ts +126 -0
- package/vendor/zod/core/to-json-schema.d.ts +153 -0
- package/vendor/zod/core/to-json-schema.js +650 -0
- package/vendor/zod/core/util.d.ts +257 -0
- package/vendor/zod/core/util.js +846 -0
- package/vendor/zod/core/versions.d.ts +5 -0
- package/vendor/zod/core/versions.js +5 -0
- package/vendor/zod/core/visit.d.ts +30 -0
- package/vendor/zod/core/visit.js +169 -0
- package/vendor/zod/index.d.ts +3 -0
- package/vendor/zod/index.js +4 -0
- package/vendor/zod/locales/ar.d.ts +4 -0
- package/vendor/zod/locales/ar.js +109 -0
- package/vendor/zod/locales/az.d.ts +4 -0
- package/vendor/zod/locales/az.js +108 -0
- package/vendor/zod/locales/be.d.ts +4 -0
- package/vendor/zod/locales/be.js +166 -0
- package/vendor/zod/locales/bg.d.ts +4 -0
- package/vendor/zod/locales/bg.js +123 -0
- package/vendor/zod/locales/bn.d.ts +4 -0
- package/vendor/zod/locales/bn.js +111 -0
- package/vendor/zod/locales/ca.d.ts +4 -0
- package/vendor/zod/locales/ca.js +110 -0
- package/vendor/zod/locales/ckb.d.ts +4 -0
- package/vendor/zod/locales/ckb.js +131 -0
- package/vendor/zod/locales/cs.d.ts +4 -0
- package/vendor/zod/locales/cs.js +114 -0
- package/vendor/zod/locales/da.d.ts +4 -0
- package/vendor/zod/locales/da.js +118 -0
- package/vendor/zod/locales/de.d.ts +4 -0
- package/vendor/zod/locales/de.js +111 -0
- package/vendor/zod/locales/el.d.ts +4 -0
- package/vendor/zod/locales/el.js +110 -0
- package/vendor/zod/locales/en.d.ts +4 -0
- package/vendor/zod/locales/en.js +123 -0
- package/vendor/zod/locales/eo.d.ts +4 -0
- package/vendor/zod/locales/eo.js +112 -0
- package/vendor/zod/locales/es.d.ts +4 -0
- package/vendor/zod/locales/es.js +134 -0
- package/vendor/zod/locales/fa.d.ts +4 -0
- package/vendor/zod/locales/fa.js +117 -0
- package/vendor/zod/locales/fi.d.ts +4 -0
- package/vendor/zod/locales/fi.js +115 -0
- package/vendor/zod/locales/fr-CA.d.ts +4 -0
- package/vendor/zod/locales/fr-CA.js +110 -0
- package/vendor/zod/locales/fr.d.ts +4 -0
- package/vendor/zod/locales/fr.js +127 -0
- package/vendor/zod/locales/gu.d.ts +4 -0
- package/vendor/zod/locales/gu.js +111 -0
- package/vendor/zod/locales/he.d.ts +4 -0
- package/vendor/zod/locales/he.js +219 -0
- package/vendor/zod/locales/hi.d.ts +4 -0
- package/vendor/zod/locales/hi.js +109 -0
- package/vendor/zod/locales/hr.d.ts +4 -0
- package/vendor/zod/locales/hr.js +124 -0
- package/vendor/zod/locales/hu.d.ts +4 -0
- package/vendor/zod/locales/hu.js +111 -0
- package/vendor/zod/locales/hy.d.ts +4 -0
- package/vendor/zod/locales/hy.js +156 -0
- package/vendor/zod/locales/id.d.ts +4 -0
- package/vendor/zod/locales/id.js +109 -0
- package/vendor/zod/locales/index.d.ts +62 -0
- package/vendor/zod/locales/index.js +62 -0
- package/vendor/zod/locales/is.d.ts +4 -0
- package/vendor/zod/locales/is.js +112 -0
- package/vendor/zod/locales/it.d.ts +4 -0
- package/vendor/zod/locales/it.js +111 -0
- package/vendor/zod/locales/ja.d.ts +4 -0
- package/vendor/zod/locales/ja.js +110 -0
- package/vendor/zod/locales/ka.d.ts +4 -0
- package/vendor/zod/locales/ka.js +115 -0
- package/vendor/zod/locales/kh.d.ts +5 -0
- package/vendor/zod/locales/kh.js +5 -0
- package/vendor/zod/locales/km.d.ts +4 -0
- package/vendor/zod/locales/km.js +113 -0
- package/vendor/zod/locales/kn.d.ts +4 -0
- package/vendor/zod/locales/kn.js +114 -0
- package/vendor/zod/locales/ko.d.ts +4 -0
- package/vendor/zod/locales/ko.js +114 -0
- package/vendor/zod/locales/lt.d.ts +4 -0
- package/vendor/zod/locales/lt.js +205 -0
- package/vendor/zod/locales/mk.d.ts +4 -0
- package/vendor/zod/locales/mk.js +112 -0
- package/vendor/zod/locales/ms.d.ts +4 -0
- package/vendor/zod/locales/ms.js +110 -0
- package/vendor/zod/locales/ne.d.ts +4 -0
- package/vendor/zod/locales/ne.js +109 -0
- package/vendor/zod/locales/nl.d.ts +4 -0
- package/vendor/zod/locales/nl.js +113 -0
- package/vendor/zod/locales/nn.d.ts +4 -0
- package/vendor/zod/locales/nn.js +111 -0
- package/vendor/zod/locales/no.d.ts +4 -0
- package/vendor/zod/locales/no.js +111 -0
- package/vendor/zod/locales/ota.d.ts +4 -0
- package/vendor/zod/locales/ota.js +112 -0
- package/vendor/zod/locales/package.json +7 -0
- package/vendor/zod/locales/pl.d.ts +4 -0
- package/vendor/zod/locales/pl.js +112 -0
- package/vendor/zod/locales/ps.d.ts +4 -0
- package/vendor/zod/locales/ps.js +117 -0
- package/vendor/zod/locales/pt-BR.d.ts +4 -0
- package/vendor/zod/locales/pt-BR.js +141 -0
- package/vendor/zod/locales/pt.d.ts +4 -0
- package/vendor/zod/locales/pt.js +140 -0
- package/vendor/zod/locales/ro.d.ts +4 -0
- package/vendor/zod/locales/ro.js +120 -0
- package/vendor/zod/locales/ru.d.ts +4 -0
- package/vendor/zod/locales/ru.js +166 -0
- package/vendor/zod/locales/sk.d.ts +4 -0
- package/vendor/zod/locales/sk.js +114 -0
- package/vendor/zod/locales/sl.d.ts +4 -0
- package/vendor/zod/locales/sl.js +112 -0
- package/vendor/zod/locales/sv.d.ts +4 -0
- package/vendor/zod/locales/sv.js +113 -0
- package/vendor/zod/locales/ta.d.ts +4 -0
- package/vendor/zod/locales/ta.js +113 -0
- package/vendor/zod/locales/th.d.ts +4 -0
- package/vendor/zod/locales/th.js +113 -0
- package/vendor/zod/locales/tk.d.ts +4 -0
- package/vendor/zod/locales/tk.js +105 -0
- package/vendor/zod/locales/tr.d.ts +4 -0
- package/vendor/zod/locales/tr.js +108 -0
- package/vendor/zod/locales/ua.d.ts +5 -0
- package/vendor/zod/locales/ua.js +5 -0
- package/vendor/zod/locales/uk.d.ts +4 -0
- package/vendor/zod/locales/uk.js +111 -0
- package/vendor/zod/locales/ur.d.ts +4 -0
- package/vendor/zod/locales/ur.js +113 -0
- package/vendor/zod/locales/uz.d.ts +4 -0
- package/vendor/zod/locales/uz.js +111 -0
- package/vendor/zod/locales/vi.d.ts +4 -0
- package/vendor/zod/locales/vi.js +111 -0
- package/vendor/zod/locales/yo.d.ts +4 -0
- package/vendor/zod/locales/yo.js +110 -0
- package/vendor/zod/locales/zh-CN.d.ts +4 -0
- package/vendor/zod/locales/zh-CN.js +112 -0
- package/vendor/zod/locales/zh-TW.d.ts +4 -0
- package/vendor/zod/locales/zh-TW.js +110 -0
- package/vendor/zod/mini/checks.d.ts +1 -0
- package/vendor/zod/mini/checks.js +1 -0
- package/vendor/zod/mini/coerce.d.ts +7 -0
- package/vendor/zod/mini/coerce.js +22 -0
- package/vendor/zod/mini/deep-partial.d.ts +14 -0
- package/vendor/zod/mini/deep-partial.js +13 -0
- package/vendor/zod/mini/external.d.ts +16 -0
- package/vendor/zod/mini/external.js +16 -0
- package/vendor/zod/mini/in-out.d.ts +8 -0
- package/vendor/zod/mini/in-out.js +36 -0
- package/vendor/zod/mini/index.d.ts +3 -0
- package/vendor/zod/mini/index.js +3 -0
- package/vendor/zod/mini/iso.d.ts +22 -0
- package/vendor/zod/mini/iso.js +34 -0
- package/vendor/zod/mini/package.json +7 -0
- package/vendor/zod/mini/parse.d.ts +1 -0
- package/vendor/zod/mini/parse.js +1 -0
- package/vendor/zod/mini/schemas.d.ts +475 -0
- package/vendor/zod/mini/schemas.js +987 -0
- package/vendor/zod/package.json +7 -0
- package/vendor/zodexy/dist/esm/index.js +1274 -0
- package/vendor/zodexy/dist/index.js +1088 -0
- package/vendor/zodexy/dist/schema.zodexy.json +1036 -0
- package/dist/fundamentalTypes/nativeEnumType.d.ts +0 -6
- package/dist/fundamentalTypes/nativeEnumType.d.ts.map +0 -1
- package/src/fundamentalTypes/catchType.js +0 -140
- package/src/fundamentalTypes/enumType.js +0 -52
- package/src/fundamentalTypes/literalType.js +0 -81
- package/src/fundamentalTypes/nativeEnumType.js +0 -157
- package/src/fundamentalTypes/neverType.js +0 -49
- package/src/fundamentalTypes/recordType.js +0 -42
- package/src/fundamentalTypes/tupleType.js +0 -39
- package/src/fundamentalTypes/voidType.js +0 -48
- package/vendor/zod/lib/index.mjs +0 -4236
- package/vendor/zodex/dist/esm/dezerialize.d.ts +0 -26
- package/vendor/zodex/dist/esm/dezerialize.js +0 -393
- package/vendor/zodex/dist/esm/index.d.ts +0 -9
- package/vendor/zodex/dist/esm/index.js +0 -4
- package/vendor/zodex/dist/esm/infer.d.ts +0 -29
- package/vendor/zodex/dist/esm/package.json +0 -1
- package/vendor/zodex/dist/esm/types.d.ts +0 -201
- package/vendor/zodex/dist/esm/types.js +0 -13
- package/vendor/zodex/dist/esm/ui.d.ts +0 -23
- package/vendor/zodex/dist/esm/ui.js +0 -10
- package/vendor/zodex/dist/esm/zerialize.d.ts +0 -50
- package/vendor/zodex/dist/esm/zerialize.js +0 -417
- package/vendor/zodex/dist/esm/zod-types.d.ts +0 -11
- /package/vendor/{zodex/dist/esm/infer.js → zod/core/json-schema.js} +0 -0
- /package/vendor/{zodex/dist/esm/zod-types.js → zod/core/standard-schema.js} +0 -0
package/src/formats/schema.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
// import {z} from 'zod';
|
|
2
|
-
import {dezerialize} from '
|
|
2
|
+
import {dezerialize} from 'zodexy';
|
|
3
|
+
import deepEqual from 'fast-deep-equal/es6/index.js';
|
|
3
4
|
|
|
4
5
|
import structuredCloning from './structuredCloning.js';
|
|
5
6
|
|
|
6
7
|
import {resolveJSONPointer} from '../utils/jsonPointer.js';
|
|
7
8
|
import {copyObject} from '../utils/objects.js';
|
|
9
|
+
import {isUnionLike} from '../utils/types.js';
|
|
10
|
+
import FileList from '../utils/FileList.js';
|
|
8
11
|
|
|
9
|
-
/* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/147 */
|
|
10
12
|
/**
|
|
11
13
|
* @typedef {T[keyof T]} ValueOf<T>
|
|
12
14
|
* @template T
|
|
13
15
|
*/
|
|
14
|
-
/* eslint-enable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/147 */
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* @typedef {ValueOf<
|
|
18
|
-
* Pick<import('
|
|
19
|
-
* >} AvailableZodexType
|
|
20
|
-
*/
|
|
19
|
+
* Pick<import('zodexy').SzType, "type">
|
|
20
|
+
* >} AvailableZodexType
|
|
21
|
+
*/
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* @type {Map<
|
|
@@ -33,40 +34,338 @@ const zodexToStructuredCloningTypeMap = new Map([
|
|
|
33
34
|
['bigInt', 'bigint'],
|
|
34
35
|
['string', 'string'],
|
|
35
36
|
['date', 'date'],
|
|
37
|
+
['file', 'file'],
|
|
36
38
|
['undefined', 'undef'],
|
|
37
|
-
['void', '
|
|
39
|
+
['void', 'undef'],
|
|
38
40
|
['null', 'null'],
|
|
39
41
|
|
|
40
42
|
// ['array', 'array'],
|
|
41
43
|
['array', 'arrayNonindexKeys'],
|
|
42
44
|
|
|
43
45
|
['object', 'object'],
|
|
44
|
-
['enum', 'enum'],
|
|
45
|
-
['literal', 'literal'],
|
|
46
46
|
|
|
47
|
-
['tuple', '
|
|
48
|
-
['record', '
|
|
47
|
+
['tuple', 'array'],
|
|
48
|
+
['record', 'object'],
|
|
49
|
+
['looseRecord', 'object'],
|
|
49
50
|
['map', 'map'],
|
|
50
51
|
['set', 'set'],
|
|
51
52
|
|
|
52
|
-
['never', 'never'],
|
|
53
|
-
|
|
54
53
|
// Todo: Filter out for cloning-only
|
|
55
|
-
['symbol', 'symbol'],
|
|
56
54
|
['promise', 'promise'],
|
|
57
|
-
['function', 'function']
|
|
58
|
-
|
|
59
|
-
['catch', 'catch'],
|
|
60
|
-
['nativeEnum', 'nativeEnum']
|
|
55
|
+
['function', 'function']
|
|
61
56
|
]);
|
|
62
57
|
|
|
63
58
|
/**
|
|
64
|
-
* @
|
|
59
|
+
* @param {unknown} value
|
|
60
|
+
* @returns {import('../types.js').AvailableArbitraryType|undefined}
|
|
61
|
+
*/
|
|
62
|
+
function getValueType (value) {
|
|
63
|
+
if (value === null) {
|
|
64
|
+
return 'null';
|
|
65
|
+
}
|
|
66
|
+
switch (typeof value) {
|
|
67
|
+
case 'undefined':
|
|
68
|
+
return 'undef';
|
|
69
|
+
case 'bigint':
|
|
70
|
+
return 'bigint';
|
|
71
|
+
case 'boolean':
|
|
72
|
+
return 'boolean';
|
|
73
|
+
case 'number':
|
|
74
|
+
return 'number';
|
|
75
|
+
case 'string':
|
|
76
|
+
return 'string';
|
|
77
|
+
default:
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {import('zodexy').SzLiteral<any>|import('zodexy').SzEnum<any>} schema
|
|
84
|
+
* @returns {Set<ZodexSchema>}
|
|
85
|
+
*/
|
|
86
|
+
function splitConstrainedSchema (schema) {
|
|
87
|
+
const values = /** @type {unknown[]} */ (schema.type === 'literal'
|
|
88
|
+
? schema.values
|
|
89
|
+
: Object.values(schema.values));
|
|
90
|
+
const valueTypes = new Set(values.map((value) => getValueType(value)));
|
|
91
|
+
return new Set([...valueTypes].flatMap((type) => {
|
|
92
|
+
if (!type) {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
const typeValues = values.filter((value) => {
|
|
96
|
+
return getValueType(value) === type;
|
|
97
|
+
});
|
|
98
|
+
const {defaultValue} = schema;
|
|
99
|
+
return [{
|
|
100
|
+
...schema,
|
|
101
|
+
values: schema.type === 'literal'
|
|
102
|
+
? typeValues
|
|
103
|
+
: Object.fromEntries(Object.entries(schema.values).filter(([, value]) => {
|
|
104
|
+
return getValueType(value) === type;
|
|
105
|
+
})),
|
|
106
|
+
defaultValue: typeValues.includes(defaultValue)
|
|
107
|
+
? defaultValue
|
|
108
|
+
: typeValues[0]
|
|
109
|
+
}];
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @param {ZodexSchema} schemaObject
|
|
115
|
+
* @returns {import('../types.js').AvailableType|undefined}
|
|
116
|
+
*/
|
|
117
|
+
function getCheckedType (schemaObject) {
|
|
118
|
+
return /** @type {import('../types.js').AvailableType|undefined} */ (
|
|
119
|
+
schemaObject.checks?.[0]?.name
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* `z.stringbool()` serializes as a `pipe` (a string -> boolean codec) whose
|
|
125
|
+
* `inner` is a plain string, `outer` is a boolean, and which carries the
|
|
126
|
+
* `truthy`/`falsy`/`case` options on the pipe itself. jsoe edits the encoded
|
|
127
|
+
* (string) side, so this is treated as a refinement of the String type -
|
|
128
|
+
* a `kind` of string - rather than its own type or a boolean.
|
|
129
|
+
* @param {ZodexSchema} schemaObject
|
|
130
|
+
* @returns {boolean}
|
|
131
|
+
*/
|
|
132
|
+
function isStringboolSchema (schemaObject) {
|
|
133
|
+
return schemaObject.type === 'pipe' &&
|
|
134
|
+
schemaObject.inner?.type === 'string' &&
|
|
135
|
+
schemaObject.outer?.type === 'boolean' &&
|
|
136
|
+
'case' in schemaObject &&
|
|
137
|
+
'falsy' in schemaObject &&
|
|
138
|
+
'truthy' in schemaObject;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @param {ZodexSchema} schemaObject
|
|
143
|
+
* @returns {import('../types.js').AvailableArbitraryType|undefined}
|
|
144
|
+
*/
|
|
145
|
+
function getSchemaType (schemaObject) {
|
|
146
|
+
if (isStringboolSchema(schemaObject)) {
|
|
147
|
+
return 'string';
|
|
148
|
+
}
|
|
149
|
+
if (schemaObject.type === 'codec' && schemaObject.name === 'filelist') {
|
|
150
|
+
return 'filelist';
|
|
151
|
+
}
|
|
152
|
+
if (schemaObject.type === 'instanceof') {
|
|
153
|
+
return /** @type {import('../types.js').AvailableArbitraryType} */ (
|
|
154
|
+
schemaObject.name
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if (schemaObject.type === 'literal') {
|
|
158
|
+
return getValueType(schemaObject.values[0]);
|
|
159
|
+
}
|
|
160
|
+
if (schemaObject.type === 'enum') {
|
|
161
|
+
return getValueType(Object.values(schemaObject.values)[0]);
|
|
162
|
+
}
|
|
163
|
+
if (schemaObject.type === 'templateLiteral') {
|
|
164
|
+
return 'string';
|
|
165
|
+
}
|
|
166
|
+
return (
|
|
167
|
+
getCheckedType(schemaObject) ??
|
|
168
|
+
zodexToStructuredCloningTypeMap.get(schemaObject.type)
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const dezerializerInstances = {filelist: FileList};
|
|
173
|
+
const dezerializerCodecs = {
|
|
174
|
+
filelist: {
|
|
175
|
+
/**
|
|
176
|
+
* @param {FileList} value
|
|
177
|
+
* @returns {File[]}
|
|
178
|
+
*/
|
|
179
|
+
decode (value) {
|
|
180
|
+
return Array.from({length: value.length}, (_, idx) => value.item(idx));
|
|
181
|
+
},
|
|
182
|
+
/**
|
|
183
|
+
* @param {File[]} value
|
|
184
|
+
* @returns {FileList}
|
|
185
|
+
*/
|
|
186
|
+
encode (value) {
|
|
187
|
+
return new FileList(value);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* @param {InstanceType<typeof import('../types.js').default>} types
|
|
194
|
+
* @param {ZodexSchema} schemaObject
|
|
195
|
+
* @param {ZodexSchema} originalShape
|
|
196
|
+
* @param {unknown} value
|
|
197
|
+
* @returns {ReturnType<ReturnType<typeof dezerialize>['safeParse']>}
|
|
198
|
+
*/
|
|
199
|
+
function parseValue (types, schemaObject, originalShape, value) {
|
|
200
|
+
return dezerialize(schemaObject, {
|
|
201
|
+
checks: getChecks(types),
|
|
202
|
+
codecs: dezerializerCodecs,
|
|
203
|
+
instances: dezerializerInstances,
|
|
204
|
+
originalShape
|
|
205
|
+
}).safeParse(value);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @param {InstanceType<typeof import('../types.js').default>} types
|
|
210
|
+
* @param {ZodexSchema} schemaObject
|
|
211
|
+
* @param {ZodexSchema} originalShape
|
|
212
|
+
* @param {unknown} value
|
|
213
|
+
* @returns {ZodexSchema|undefined}
|
|
214
|
+
*/
|
|
215
|
+
function getInvalidIntersectionBranch (
|
|
216
|
+
types, schemaObject, originalShape, value
|
|
217
|
+
) {
|
|
218
|
+
if (schemaObject.type === 'intersection') {
|
|
219
|
+
return getInvalidIntersectionBranch(
|
|
220
|
+
types, schemaObject.left, originalShape, value
|
|
221
|
+
) ?? getInvalidIntersectionBranch(
|
|
222
|
+
types, schemaObject.right, originalShape, value
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
return parseValue(types, schemaObject, originalShape, value).success
|
|
226
|
+
? undefined
|
|
227
|
+
: schemaObject;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Checks whether a record property name satisfies the record's `key` schema.
|
|
232
|
+
*
|
|
233
|
+
* For a strict `record` every key must conform, so the distinction is
|
|
234
|
+
* irrelevant. For a `looseRecord`, Zod validates the `value` schema only
|
|
235
|
+
* against entries whose key conforms; entries with a non-conforming key are
|
|
236
|
+
* passed through untyped. Both the child-schema resolver in `arrayType.js` and
|
|
237
|
+
* `convertFromTypeson` below use this to avoid imposing the `value` schema on
|
|
238
|
+
* those pass-through entries.
|
|
239
|
+
* @param {InstanceType<typeof import('../types.js').default>} types
|
|
240
|
+
* @param {ZodexSchema|undefined} keySchema
|
|
241
|
+
* @param {string|number|undefined} key
|
|
242
|
+
* @returns {boolean}
|
|
243
|
+
*/
|
|
244
|
+
export function recordKeyConforms (types, keySchema, key) {
|
|
245
|
+
if (!keySchema || key === undefined) {
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
if (parseValue(types, keySchema, keySchema, key).success) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
// Mirror Zod's numeric-string key fallback: an object property name is always
|
|
252
|
+
// a string, so a `number`/`bigInt`/`nan` key schema is retried against the
|
|
253
|
+
// coerced value.
|
|
254
|
+
return typeof key === 'string' && key.trim() !== '' &&
|
|
255
|
+
Number.isFinite(Number(key)) &&
|
|
256
|
+
parseValue(types, keySchema, keySchema, Number(key)).success;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Count how many branches of an `xor` (exclusive union) the value satisfies.
|
|
261
|
+
* `xor` is valid only when exactly one matches; the count drives the editor's
|
|
262
|
+
* live match indicator so an ambiguous value reads as a rule, not a glitch.
|
|
263
|
+
* @param {InstanceType<typeof import('../types.js').default>} types
|
|
264
|
+
* @param {import('zodexy').SzUnion} xorSchema
|
|
265
|
+
* @param {unknown} value
|
|
266
|
+
* @returns {{matched: number, total: number}}
|
|
267
|
+
*/
|
|
268
|
+
export function getXorBranchMatchInfo (types, xorSchema, value) {
|
|
269
|
+
const options = /** @type {ZodexSchema[]} */ (xorSchema.options ?? []);
|
|
270
|
+
let matched = 0;
|
|
271
|
+
for (const option of options) {
|
|
272
|
+
if (parseValue(types, option, xorSchema, value).success) {
|
|
273
|
+
matched++;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return {matched, total: options.length};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Whether a value satisfies a single (already-flattened) schema branch. Used
|
|
281
|
+
* to check the value against the specific `xor` branch the user chose, not
|
|
282
|
+
* merely against some branch.
|
|
283
|
+
* @param {InstanceType<typeof import('../types.js').default>} types
|
|
284
|
+
* @param {ZodexSchema} schema
|
|
285
|
+
* @param {unknown} value
|
|
286
|
+
* @returns {boolean}
|
|
287
|
+
*/
|
|
288
|
+
export function valueMatchesSchema (types, schema, value) {
|
|
289
|
+
return parseValue(types, schema, schema, value).success;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @param {InstanceType<typeof import('../types.js').default>} types
|
|
294
|
+
* @returns {NonNullable<
|
|
295
|
+
* import('zodexy').DezerializerOptions['checks']
|
|
296
|
+
* >}
|
|
297
|
+
*/
|
|
298
|
+
function getChecks (types) {
|
|
299
|
+
return Object.fromEntries(Object.entries(types.availableTypes).map(([
|
|
300
|
+
name, typeObject
|
|
301
|
+
]) => {
|
|
302
|
+
return [name, (payload) => {
|
|
303
|
+
if (!Array.isArray(typeObject) && typeObject.valueMatch &&
|
|
304
|
+
!typeObject.valueMatch(payload.value)) {
|
|
305
|
+
payload.issues.push({
|
|
306
|
+
code: 'custom',
|
|
307
|
+
input: payload.value,
|
|
308
|
+
message: `Value does not match ${name}`
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
}];
|
|
312
|
+
}));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* @typedef {import('zodexy').SzType} ZodexSchema
|
|
65
317
|
*/
|
|
66
318
|
/**
|
|
67
319
|
* @typedef {import('../utils/objects.js').NestedObject} NestedObject
|
|
68
320
|
*/
|
|
69
321
|
|
|
322
|
+
/** @type {WeakMap<ZodexSchema, ZodexSchema>} */
|
|
323
|
+
const intersectionSchemas = new WeakMap();
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* @param {ZodexSchema} schemaObject
|
|
327
|
+
* @returns {ZodexSchema}
|
|
328
|
+
*/
|
|
329
|
+
export function getValidationSchema (schemaObject) {
|
|
330
|
+
return intersectionSchemas.get(schemaObject) ?? schemaObject;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* @param {ZodexSchema['type']} type
|
|
335
|
+
* @param {any} value
|
|
336
|
+
* @returns {any}
|
|
337
|
+
*/
|
|
338
|
+
function getComparableConstraint (type, value) {
|
|
339
|
+
return type === 'bigInt' ? BigInt(value) : value;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Merge a serialized schema's `meta` bag from a wrapping or intersecting
|
|
344
|
+
* schema into an inner one. `title`/`description` concatenate with `" and "`
|
|
345
|
+
* (mirroring how a bare `description` is merged), skipping Zodexy's
|
|
346
|
+
* `"Modifiers"` sentinel; any other key is taken from the source only when the
|
|
347
|
+
* target lacks it.
|
|
348
|
+
* @param {{[key: string]: any}|undefined} target
|
|
349
|
+
* @param {{[key: string]: any}} source
|
|
350
|
+
* @returns {{[key: string]: any}}
|
|
351
|
+
*/
|
|
352
|
+
function mergeMeta (target, source) {
|
|
353
|
+
const merged = {...target};
|
|
354
|
+
for (const [key, val] of Object.entries(source)) {
|
|
355
|
+
if (key === 'title' || key === 'description') {
|
|
356
|
+
if (typeof val === 'string' && val !== 'Modifiers') {
|
|
357
|
+
merged[key] = typeof merged[key] === 'string' &&
|
|
358
|
+
merged[key] !== 'Modifiers'
|
|
359
|
+
? merged[key] + ' and ' + val
|
|
360
|
+
: val;
|
|
361
|
+
}
|
|
362
|
+
} else if (!Object.hasOwn(merged, key)) {
|
|
363
|
+
merged[key] = val && typeof val === 'object' ? copyObject(val) : val;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return merged;
|
|
367
|
+
}
|
|
368
|
+
|
|
70
369
|
/**
|
|
71
370
|
* @param {ZodexSchema} leftItem
|
|
72
371
|
* @param {ZodexSchema} rightItem
|
|
@@ -74,36 +373,61 @@ const zodexToStructuredCloningTypeMap = new Map([
|
|
|
74
373
|
* @returns {ZodexSchema}
|
|
75
374
|
*/
|
|
76
375
|
function mergeSchema (leftItem, rightItem) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/* istanbul ignore if -- Guard */
|
|
83
|
-
if (rightItem.type !== 'object') {
|
|
84
|
-
console.log('rightItem', rightItem);
|
|
85
|
-
throw new Error('Unexpected rightItem of type ' + rightItem.type);
|
|
376
|
+
if (leftItem.type !== rightItem.type) {
|
|
377
|
+
throw new Error(
|
|
378
|
+
'Cannot merge intersection types ' + leftItem.type + ' and ' +
|
|
379
|
+
rightItem.type
|
|
380
|
+
);
|
|
86
381
|
}
|
|
87
382
|
|
|
88
383
|
const newLeftObj = copyObject(leftItem);
|
|
89
384
|
|
|
90
385
|
for (const [prop, val] of Object.entries(rightItem)) {
|
|
91
|
-
if (prop !== 'type' && prop !== 'properties') {
|
|
386
|
+
if (prop !== 'type' && prop !== 'properties' && prop !== 'error') {
|
|
92
387
|
if (prop === 'description') {
|
|
93
388
|
if (val !== 'Modifiers') { // A bit cleaner
|
|
94
|
-
|
|
95
|
-
|
|
389
|
+
const existingDescription = newLeftObj[prop];
|
|
390
|
+
newLeftObj[prop] = existingDescription
|
|
391
|
+
? existingDescription + ' and ' + val
|
|
96
392
|
: val;
|
|
97
393
|
}
|
|
98
|
-
} else
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
394
|
+
} else if (prop === 'meta') {
|
|
395
|
+
newLeftObj.meta = mergeMeta(
|
|
396
|
+
/** @type {{[key: string]: any}} */ (newLeftObj.meta),
|
|
397
|
+
/** @type {{[key: string]: any}} */ (val)
|
|
398
|
+
);
|
|
399
|
+
} else if (Object.hasOwn(newLeftObj, prop)) {
|
|
400
|
+
if (newLeftObj[prop] !== val && !deepEqual(newLeftObj[prop], val)) {
|
|
401
|
+
if (leftItem.type === 'object') {
|
|
402
|
+
throw new Error(
|
|
403
|
+
'Duplicate property ' + prop + ' of value ' +
|
|
404
|
+
JSON.stringify(val) + ' and ' +
|
|
405
|
+
JSON.stringify(newLeftObj[prop])
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
if (prop === 'min' || prop === 'minLength') {
|
|
409
|
+
const existingConstraint = getComparableConstraint(
|
|
410
|
+
leftItem.type, newLeftObj[prop]
|
|
411
|
+
);
|
|
412
|
+
const rightConstraint = getComparableConstraint(
|
|
413
|
+
rightItem.type, val
|
|
414
|
+
);
|
|
415
|
+
newLeftObj[prop] = existingConstraint > rightConstraint
|
|
416
|
+
? newLeftObj[prop]
|
|
417
|
+
: val;
|
|
418
|
+
} else if (prop === 'max' || prop === 'maxLength') {
|
|
419
|
+
const existingConstraint = getComparableConstraint(
|
|
420
|
+
leftItem.type, newLeftObj[prop]
|
|
421
|
+
);
|
|
422
|
+
const rightConstraint = getComparableConstraint(
|
|
423
|
+
rightItem.type, val
|
|
424
|
+
);
|
|
425
|
+
newLeftObj[prop] = existingConstraint < rightConstraint
|
|
426
|
+
? newLeftObj[prop]
|
|
427
|
+
: val;
|
|
428
|
+
}
|
|
105
429
|
}
|
|
106
|
-
|
|
430
|
+
} else {
|
|
107
431
|
newLeftObj[prop] = val && typeof val === 'object'
|
|
108
432
|
? copyObject(val)
|
|
109
433
|
/* istanbul ignore next -- Guard */
|
|
@@ -112,9 +436,19 @@ function mergeSchema (leftItem, rightItem) {
|
|
|
112
436
|
}
|
|
113
437
|
}
|
|
114
438
|
|
|
439
|
+
if (leftItem.type !== 'object' || rightItem.type !== 'object') {
|
|
440
|
+
delete newLeftObj.error;
|
|
441
|
+
return newLeftObj;
|
|
442
|
+
}
|
|
443
|
+
|
|
115
444
|
for (const [prop, val] of Object.entries(rightItem.properties)) {
|
|
116
445
|
if (typeof newLeftObj.properties !== 'string' &&
|
|
117
|
-
|
|
446
|
+
Object.hasOwn(newLeftObj.properties, prop)) {
|
|
447
|
+
if (deepEqual(newLeftObj.properties[prop], val)) {
|
|
448
|
+
// Identical property schemas from both intersection branches merge to
|
|
449
|
+
// themselves; nothing to reconcile
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
118
452
|
throw new Error(
|
|
119
453
|
'Duplicate property ' + prop + ' of value ' +
|
|
120
454
|
JSON.stringify(val) + ' and ' +
|
|
@@ -200,6 +534,15 @@ function addModifiers (schemaObject, set) {
|
|
|
200
534
|
: schemaObject.description;
|
|
201
535
|
}
|
|
202
536
|
}
|
|
537
|
+
|
|
538
|
+
if (schemaObject.meta && typeof schemaObject.meta === 'object') {
|
|
539
|
+
for (const obj of set) {
|
|
540
|
+
obj.meta = mergeMeta(
|
|
541
|
+
/** @type {{[key: string]: any}} */ (obj.meta),
|
|
542
|
+
/** @type {{[key: string]: any}} */ (schemaObject.meta)
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
203
546
|
}
|
|
204
547
|
|
|
205
548
|
/**
|
|
@@ -208,376 +551,314 @@ function addModifiers (schemaObject, set) {
|
|
|
208
551
|
* @returns {Set<ZodexSchema>}
|
|
209
552
|
*/
|
|
210
553
|
export function getTypesForSchema (schemaObject, originalJSON) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
case 'object': {
|
|
215
|
-
const set = new Set();
|
|
216
|
-
// const {properties} = schemaObject;
|
|
217
|
-
// if (
|
|
218
|
-
// 'type' in properties && properties.type.type === 'enum' &&
|
|
219
|
-
// properties.type.values.length === 1
|
|
220
|
-
// ) {
|
|
221
|
-
// set.add(schemaObject);
|
|
222
|
-
// set.add(properties.type.defaultValue);
|
|
223
|
-
// }
|
|
224
|
-
set.add(schemaObject);
|
|
225
|
-
return set;
|
|
226
|
-
}
|
|
227
|
-
case 'discriminatedUnion':
|
|
228
|
-
case 'union': {
|
|
229
|
-
/** @type {(ZodexSchema & {$discriminator?: string})[]} */
|
|
230
|
-
let set = [];
|
|
231
|
-
for (const option of schemaObject.options) {
|
|
232
|
-
set = [...set, ...getTypesForSchema(option, originalJSON)];
|
|
554
|
+
for (;;) {
|
|
555
|
+
if (getCheckedType(schemaObject)) {
|
|
556
|
+
return new Set([schemaObject]);
|
|
233
557
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
558
|
+
switch (schemaObject.type) {
|
|
559
|
+
case 'never':
|
|
560
|
+
return new Set();
|
|
561
|
+
case 'literal':
|
|
562
|
+
case 'enum':
|
|
563
|
+
return splitConstrainedSchema(schemaObject);
|
|
564
|
+
case 'catch': {
|
|
565
|
+
const catchSchema = schemaObject;
|
|
566
|
+
const innerSchemas = [...getTypesForSchema(
|
|
567
|
+
catchSchema.innerType, originalJSON
|
|
568
|
+
)].map((innerSchema) => ({...innerSchema}));
|
|
569
|
+
addModifiers(schemaObject, innerSchemas);
|
|
570
|
+
const fallbackSchemas = [...getTypesForSchema({
|
|
571
|
+
type: 'literal',
|
|
572
|
+
values: [catchSchema.value]
|
|
573
|
+
}, originalJSON)];
|
|
574
|
+
addModifiers(schemaObject, fallbackSchemas);
|
|
575
|
+
return new Set([...innerSchemas, ...fallbackSchemas]);
|
|
576
|
+
}
|
|
577
|
+
case 'object': {
|
|
578
|
+
const set = new Set();
|
|
579
|
+
// const {properties} = schemaObject;
|
|
580
|
+
// if (
|
|
581
|
+
// 'type' in properties && properties.type.type === 'enum' &&
|
|
582
|
+
// properties.type.values.length === 1
|
|
583
|
+
// ) {
|
|
584
|
+
// set.add(schemaObject);
|
|
585
|
+
// set.add(properties.type.defaultValue);
|
|
586
|
+
// }
|
|
587
|
+
// eslint-disable-next-line unicorn/no-immediate-mutation -- May add above
|
|
588
|
+
set.add(schemaObject);
|
|
589
|
+
return set;
|
|
240
590
|
}
|
|
591
|
+
case 'discriminatedUnion':
|
|
592
|
+
case 'xor':
|
|
593
|
+
case 'union': {
|
|
594
|
+
/** @type {(ZodexSchema & {$discriminator?: string})[]} */
|
|
595
|
+
let set = [];
|
|
596
|
+
for (const option of schemaObject.options) {
|
|
597
|
+
set = [...set, ...getTypesForSchema(option, originalJSON)];
|
|
598
|
+
}
|
|
241
599
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const right = getTypesForSchema(schemaObject.right, originalJSON);
|
|
247
|
-
|
|
248
|
-
const set = flattenIntersection(left, right);
|
|
249
|
-
addModifiers(schemaObject, set);
|
|
250
|
-
return new Set(set);
|
|
251
|
-
} case 'any': case 'unknown':
|
|
252
|
-
return new Set([
|
|
253
|
-
{
|
|
254
|
-
type: 'boolean'
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
type: 'number'
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
type: 'nan'
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
type: 'bigInt'
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
type: 'string'
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
description: 'Email',
|
|
270
|
-
type: 'string',
|
|
271
|
-
kind: 'email'
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
description: 'URL',
|
|
275
|
-
type: 'string',
|
|
276
|
-
kind: 'url'
|
|
277
|
-
},
|
|
278
|
-
{
|
|
279
|
-
description: 'Date',
|
|
280
|
-
type: 'string',
|
|
281
|
-
kind: 'date'
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
type: 'date'
|
|
285
|
-
},
|
|
286
|
-
// {
|
|
287
|
-
// type: 'void'
|
|
288
|
-
// },
|
|
289
|
-
{
|
|
290
|
-
type: 'undefined'
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
type: 'null'
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
type: 'object',
|
|
297
|
-
properties: {},
|
|
298
|
-
unknownKeys: 'passthrough'
|
|
299
|
-
},
|
|
300
|
-
|
|
301
|
-
// Todo: support these types separately
|
|
302
|
-
// {
|
|
303
|
-
// type: 'symbol'
|
|
304
|
-
// },
|
|
305
|
-
// {
|
|
306
|
-
// type: 'promise',
|
|
307
|
-
// value: {
|
|
308
|
-
// type: 'any'
|
|
309
|
-
// }
|
|
310
|
-
// },
|
|
311
|
-
// {
|
|
312
|
-
// type: 'function',
|
|
313
|
-
// args: {
|
|
314
|
-
// type: 'tuple',
|
|
315
|
-
// items: [],
|
|
316
|
-
// rest: {
|
|
317
|
-
// type: 'any'
|
|
318
|
-
// }
|
|
319
|
-
// },
|
|
320
|
-
// returns: {
|
|
321
|
-
// type: 'any'
|
|
322
|
-
// }
|
|
323
|
-
// },
|
|
324
|
-
{
|
|
325
|
-
type: 'nativeEnum',
|
|
326
|
-
values: {
|
|
327
|
-
type: 'union',
|
|
328
|
-
options: [
|
|
329
|
-
{
|
|
330
|
-
description: 'Numeric',
|
|
331
|
-
type: 'record',
|
|
332
|
-
key: {
|
|
333
|
-
type: 'number'
|
|
334
|
-
},
|
|
335
|
-
value: {
|
|
336
|
-
type: 'string'
|
|
337
|
-
}
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
description: 'String',
|
|
341
|
-
type: 'record',
|
|
342
|
-
key: {
|
|
343
|
-
type: 'string'
|
|
344
|
-
},
|
|
345
|
-
value: {
|
|
346
|
-
type: 'union',
|
|
347
|
-
options: [
|
|
348
|
-
{
|
|
349
|
-
type: 'string'
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
type: 'number'
|
|
353
|
-
}
|
|
354
|
-
]
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
]
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
type: 'array',
|
|
362
|
-
element: {
|
|
363
|
-
type: 'any'
|
|
364
|
-
}
|
|
365
|
-
},
|
|
366
|
-
{
|
|
367
|
-
type: 'set',
|
|
368
|
-
value: {
|
|
369
|
-
type: 'any'
|
|
600
|
+
if (schemaObject.type === 'discriminatedUnion') {
|
|
601
|
+
for (const obj of set) {
|
|
602
|
+
// Todo: Use to confirm the object has the discriminator
|
|
603
|
+
obj.$discriminator = schemaObject.discriminator;
|
|
370
604
|
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
],
|
|
452
|
-
inner: {type: 'any'}
|
|
453
|
-
},
|
|
454
|
-
{
|
|
455
|
-
type: 'effect',
|
|
456
|
-
effects: [
|
|
457
|
-
{
|
|
458
|
-
name: 'error',
|
|
459
|
-
type: 'refinement'
|
|
460
|
-
}
|
|
461
|
-
],
|
|
462
|
-
inner: {type: 'any'}
|
|
463
|
-
},
|
|
464
|
-
{
|
|
465
|
-
type: 'effect',
|
|
466
|
-
effects: [
|
|
467
|
-
{
|
|
468
|
-
name: 'filelist',
|
|
469
|
-
type: 'refinement'
|
|
470
|
-
}
|
|
471
|
-
],
|
|
472
|
-
inner: {type: 'any'}
|
|
473
|
-
},
|
|
474
|
-
{
|
|
475
|
-
type: 'effect',
|
|
476
|
-
effects: [
|
|
477
|
-
{
|
|
478
|
-
name: 'file',
|
|
479
|
-
type: 'refinement'
|
|
480
|
-
}
|
|
481
|
-
],
|
|
482
|
-
inner: {type: 'any'}
|
|
483
|
-
},
|
|
484
|
-
{
|
|
485
|
-
type: 'effect',
|
|
486
|
-
effects: [
|
|
487
|
-
{
|
|
488
|
-
name: 'resurrectable', // noneditable
|
|
489
|
-
type: 'refinement'
|
|
490
|
-
}
|
|
491
|
-
],
|
|
492
|
-
inner: {type: 'any'}
|
|
493
|
-
},
|
|
494
|
-
{
|
|
495
|
-
type: 'effect',
|
|
496
|
-
effects: [
|
|
497
|
-
{
|
|
498
|
-
name: 'blobHTML',
|
|
499
|
-
type: 'refinement'
|
|
500
|
-
}
|
|
501
|
-
],
|
|
502
|
-
inner: {type: 'any'}
|
|
503
|
-
},
|
|
504
|
-
{
|
|
505
|
-
type: 'effect',
|
|
506
|
-
effects: [
|
|
507
|
-
{
|
|
508
|
-
name: 'buffersource',
|
|
509
|
-
type: 'refinement'
|
|
510
|
-
}
|
|
511
|
-
],
|
|
512
|
-
inner: {type: 'any'}
|
|
513
|
-
},
|
|
514
|
-
{
|
|
515
|
-
type: 'effect',
|
|
516
|
-
effects: [
|
|
517
|
-
{
|
|
518
|
-
name: 'dommatrix',
|
|
519
|
-
type: 'refinement'
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
addModifiers(schemaObject, set);
|
|
608
|
+
return new Set(set);
|
|
609
|
+
} case 'intersection': {
|
|
610
|
+
const left = getTypesForSchema(schemaObject.left, originalJSON);
|
|
611
|
+
const right = getTypesForSchema(schemaObject.right, originalJSON);
|
|
612
|
+
|
|
613
|
+
const set = flattenIntersection(left, right);
|
|
614
|
+
for (const item of set) {
|
|
615
|
+
intersectionSchemas.set(item, schemaObject);
|
|
616
|
+
}
|
|
617
|
+
addModifiers(schemaObject, set);
|
|
618
|
+
return new Set(set);
|
|
619
|
+
} case 'pipe': {
|
|
620
|
+
if (isStringboolSchema(schemaObject)) {
|
|
621
|
+
// Keep the whole `pipe` as the schema object: `getSchemaType` reports it
|
|
622
|
+
// as a String, `stringType` reads its `truthy`/`falsy`/`case` to
|
|
623
|
+
// validate the value, and `dezerialize` still rebuilds
|
|
624
|
+
// `z.stringbool({truthy, falsy})` for value parsing. Drop the
|
|
625
|
+
// `description` first so `addModifiers` re-adds it once rather than
|
|
626
|
+
// concatenating it with itself.
|
|
627
|
+
const stringboolSchema = {...schemaObject};
|
|
628
|
+
delete stringboolSchema.description;
|
|
629
|
+
const set = [stringboolSchema];
|
|
630
|
+
addModifiers(schemaObject, set);
|
|
631
|
+
return new Set(set);
|
|
632
|
+
}
|
|
633
|
+
const set = [...getTypesForSchema(schemaObject.inner, originalJSON)];
|
|
634
|
+
addModifiers(schemaObject, set);
|
|
635
|
+
return new Set(set);
|
|
636
|
+
} case 'any': case 'unknown':
|
|
637
|
+
return new Set([
|
|
638
|
+
{
|
|
639
|
+
type: 'boolean'
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
type: 'number'
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
type: 'nan'
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
type: 'bigInt'
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
type: 'string'
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
description: 'Email',
|
|
655
|
+
type: 'string',
|
|
656
|
+
kind: 'email'
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
description: 'URL',
|
|
660
|
+
type: 'string',
|
|
661
|
+
kind: 'url'
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
description: 'Date',
|
|
665
|
+
type: 'string',
|
|
666
|
+
kind: 'date'
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
type: 'date'
|
|
670
|
+
},
|
|
671
|
+
// {
|
|
672
|
+
// type: 'void'
|
|
673
|
+
// },
|
|
674
|
+
{
|
|
675
|
+
type: 'undefined'
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
type: 'null'
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
type: 'object',
|
|
682
|
+
properties: {},
|
|
683
|
+
catchall: {
|
|
684
|
+
type: 'unknown'
|
|
520
685
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
type: '
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
686
|
+
},
|
|
687
|
+
|
|
688
|
+
// Todo: support these types separately
|
|
689
|
+
// {
|
|
690
|
+
// type: 'symbol'
|
|
691
|
+
// },
|
|
692
|
+
// {
|
|
693
|
+
// type: 'promise',
|
|
694
|
+
// value: {
|
|
695
|
+
// type: 'any'
|
|
696
|
+
// }
|
|
697
|
+
// },
|
|
698
|
+
// {
|
|
699
|
+
// type: 'function',
|
|
700
|
+
// args: {
|
|
701
|
+
// type: 'tuple',
|
|
702
|
+
// items: [],
|
|
703
|
+
// rest: {
|
|
704
|
+
// type: 'any'
|
|
705
|
+
// }
|
|
706
|
+
// },
|
|
707
|
+
// returns: {
|
|
708
|
+
// type: 'any'
|
|
709
|
+
// }
|
|
710
|
+
// },
|
|
711
|
+
{
|
|
712
|
+
type: 'array',
|
|
713
|
+
element: {
|
|
714
|
+
type: 'any'
|
|
530
715
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
effects: [
|
|
537
|
-
{
|
|
538
|
-
name: 'domrect',
|
|
539
|
-
type: 'refinement'
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
type: 'set',
|
|
719
|
+
value: {
|
|
720
|
+
type: 'any'
|
|
540
721
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
{
|
|
548
|
-
|
|
549
|
-
type: 'refinement'
|
|
722
|
+
},
|
|
723
|
+
{
|
|
724
|
+
type: 'map',
|
|
725
|
+
key: {
|
|
726
|
+
type: 'any'
|
|
727
|
+
},
|
|
728
|
+
value: {
|
|
729
|
+
type: 'any'
|
|
550
730
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
731
|
+
},
|
|
732
|
+
|
|
733
|
+
{
|
|
734
|
+
type: 'any',
|
|
735
|
+
checks: [{name: 'regexp'}]
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
type: 'any',
|
|
739
|
+
checks: [{name: 'blob'}]
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
type: 'any',
|
|
743
|
+
checks: [{name: 'BooleanObject'}]
|
|
744
|
+
},
|
|
745
|
+
{
|
|
746
|
+
type: 'any',
|
|
747
|
+
checks: [{name: 'NumberObject'}]
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
type: 'any',
|
|
751
|
+
checks: [{name: 'StringObject'}]
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
type: 'any',
|
|
755
|
+
checks: [{name: 'SpecialRealNumber'}]
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
type: 'any',
|
|
759
|
+
checks: [{name: 'domexception'}]
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
type: 'any',
|
|
763
|
+
checks: [{name: 'error'}]
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
type: 'any',
|
|
767
|
+
checks: [{name: 'filelist'}]
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
type: 'any',
|
|
771
|
+
checks: [{name: 'file'}]
|
|
772
|
+
},
|
|
773
|
+
{
|
|
774
|
+
type: 'any',
|
|
775
|
+
checks: [{name: 'resurrectable'}] // noneditable
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
type: 'any',
|
|
779
|
+
checks: [{name: 'blobHTML'}]
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
type: 'any',
|
|
783
|
+
checks: [{name: 'buffersource'}]
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
type: 'any',
|
|
787
|
+
checks: [{name: 'dommatrix'}]
|
|
788
|
+
},
|
|
789
|
+
{
|
|
790
|
+
type: 'any',
|
|
791
|
+
checks: [{name: 'dompoint'}]
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
type: 'any',
|
|
795
|
+
checks: [{name: 'domrect'}]
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
type: 'any',
|
|
799
|
+
checks: [{name: 'errors'}]
|
|
800
|
+
},
|
|
801
|
+
|
|
802
|
+
// Todo: Adapt into a widget to drag to point back to another object
|
|
803
|
+
{
|
|
804
|
+
description: 'JSON Reference',
|
|
805
|
+
type: 'object',
|
|
806
|
+
properties: {
|
|
807
|
+
$ref: {
|
|
808
|
+
type: 'string'
|
|
809
|
+
}
|
|
561
810
|
}
|
|
562
811
|
}
|
|
812
|
+
]);
|
|
813
|
+
default: {
|
|
814
|
+
if ('$ref' in schemaObject) {
|
|
815
|
+
// console.log('originalJSON', originalJSON, schemaObject.$ref);
|
|
816
|
+
const refObj = resolveJSONPointer({
|
|
817
|
+
obj: originalJSON,
|
|
818
|
+
path: /** @type {import('zodexy').SzRef} */ (
|
|
819
|
+
schemaObject
|
|
820
|
+
).$ref
|
|
821
|
+
});
|
|
822
|
+
schemaObject = refObj;
|
|
823
|
+
// eslint-disable-next-line unicorn/no-break-in-nested-loop -- Intentional, continues the `for` loop
|
|
824
|
+
continue;
|
|
563
825
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
if ('$ref' in schemaObject) {
|
|
567
|
-
// console.log('originalJSON', originalJSON, schemaObject.$ref);
|
|
568
|
-
const refObj = resolveJSONPointer({
|
|
569
|
-
obj: originalJSON,
|
|
570
|
-
path: /** @type {import('zodex').SzRef} */ (schemaObject).$ref
|
|
571
|
-
});
|
|
572
|
-
return getTypesForSchema(refObj, originalJSON);
|
|
826
|
+
return new Set([schemaObject]);
|
|
827
|
+
}
|
|
573
828
|
}
|
|
574
|
-
return new Set([schemaObject]);
|
|
575
|
-
}
|
|
576
829
|
}
|
|
577
830
|
}
|
|
578
831
|
|
|
579
832
|
/** @type {import('../formats.js').Format} */
|
|
580
833
|
const schema = {
|
|
834
|
+
isValueValidationRequired (schemaObject) {
|
|
835
|
+
// `record`/`tuple` refine the `object`/`array` UI, whose structure does not
|
|
836
|
+
// by itself enforce the key schema, positional item schemas, or `rest`;
|
|
837
|
+
// so the assembled value must be parsed to surface those failures on the
|
|
838
|
+
// form control.
|
|
839
|
+
if (['record', 'looseRecord', 'tuple'].includes(schemaObject.type)) {
|
|
840
|
+
return true;
|
|
841
|
+
}
|
|
842
|
+
return schemaObject.type !== 'object' &&
|
|
843
|
+
intersectionSchemas.has(schemaObject);
|
|
844
|
+
},
|
|
845
|
+
validateValue (types, schemaObject, value) {
|
|
846
|
+
const validationSchema = getValidationSchema(schemaObject);
|
|
847
|
+
const parsed = parseValue(
|
|
848
|
+
types, validationSchema, validationSchema, value
|
|
849
|
+
);
|
|
850
|
+
return parsed.success
|
|
851
|
+
? {valid: true}
|
|
852
|
+
: {
|
|
853
|
+
valid: false,
|
|
854
|
+
message: parsed.error.issues[0]?.message,
|
|
855
|
+
schema: validationSchema.type === 'intersection'
|
|
856
|
+
? getInvalidIntersectionBranch(
|
|
857
|
+
types, validationSchema, validationSchema, value
|
|
858
|
+
)
|
|
859
|
+
: validationSchema
|
|
860
|
+
};
|
|
861
|
+
},
|
|
581
862
|
iterate (records, stateObj) {
|
|
582
863
|
// console.log('records', records, stateObj);
|
|
583
864
|
stateObj.format = 'schema';
|
|
@@ -603,131 +884,207 @@ const schema = {
|
|
|
603
884
|
|
|
604
885
|
// We shouldn't have to reprocess intersections, etc., as this is our own
|
|
605
886
|
// union
|
|
606
|
-
if (typeof parentSchemaIdx === 'number' && parentSchema?.type
|
|
607
|
-
parentSchema =
|
|
887
|
+
if (typeof parentSchemaIdx === 'number' && isUnionLike(parentSchema?.type)) {
|
|
888
|
+
parentSchema = /** @type {import('zodexy').SzUnion} */ (
|
|
889
|
+
parentSchema
|
|
890
|
+
).options[parentSchemaIdx];
|
|
608
891
|
}
|
|
609
892
|
|
|
610
893
|
switch (parentSchema?.type) {
|
|
611
894
|
case 'object':
|
|
612
|
-
currentSchema = /** @type {import('
|
|
895
|
+
currentSchema = /** @type {import('zodexy').SzObject} */ (
|
|
613
896
|
parentSchema
|
|
614
897
|
).properties[
|
|
615
898
|
/** @type {string} */ (arrayOrObjectPropertyName)
|
|
616
899
|
];
|
|
617
900
|
if (!currentSchema) {
|
|
618
|
-
currentSchema = /** @type {import('
|
|
901
|
+
currentSchema = /** @type {import('zodexy').SzObject} */ (
|
|
619
902
|
parentSchema
|
|
620
903
|
).catchall;
|
|
621
904
|
mustBeOptional = true;
|
|
622
905
|
}
|
|
623
906
|
break;
|
|
624
907
|
case 'array':
|
|
625
|
-
currentSchema = /** @type {import('
|
|
908
|
+
currentSchema = /** @type {import('zodexy').SzArray} */ (
|
|
626
909
|
parentSchema
|
|
627
910
|
).element;
|
|
628
911
|
break;
|
|
629
912
|
case 'set':
|
|
630
|
-
currentSchema = /** @type {import('
|
|
913
|
+
currentSchema = /** @type {import('zodexy').SzSet} */ (
|
|
631
914
|
parentSchema
|
|
632
915
|
).value;
|
|
633
916
|
break;
|
|
634
|
-
case '
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
917
|
+
case 'codec':
|
|
918
|
+
if (parentSchema.name === 'filelist' &&
|
|
919
|
+
parentSchema.output.type === 'array') {
|
|
920
|
+
currentSchema = typesonType === 'file'
|
|
921
|
+
? parentSchema.output.element
|
|
922
|
+
: parentSchema;
|
|
923
|
+
}
|
|
638
924
|
break;
|
|
925
|
+
// No need to handle differently?
|
|
926
|
+
// case 'instanceof':
|
|
927
|
+
// currentSchema = /** @type {import('zodexy').SzInstanceOf} */ (
|
|
928
|
+
// parentSchema
|
|
929
|
+
// );
|
|
930
|
+
// break;
|
|
639
931
|
// eslint-disable-next-line sonarjs/no-duplicated-branches -- Maintenance
|
|
640
932
|
case 'promise':
|
|
641
|
-
currentSchema = /** @type {import('
|
|
933
|
+
currentSchema = /** @type {import('zodexy').SzPromise} */ (
|
|
642
934
|
parentSchema
|
|
643
935
|
).value;
|
|
644
936
|
break;
|
|
645
937
|
case 'tuple':
|
|
646
|
-
currentSchema = /** @type {import('
|
|
938
|
+
currentSchema = /** @type {import('zodexy').SzTuple} */ (
|
|
647
939
|
parentSchema
|
|
648
940
|
).items[Number(arrayOrObjectPropertyName)] ??
|
|
649
|
-
/** @type {import('
|
|
941
|
+
/** @type {import('zodexy').SzTuple} */ (
|
|
650
942
|
parentSchema
|
|
651
943
|
).rest;
|
|
652
944
|
break;
|
|
945
|
+
case 'record':
|
|
946
|
+
// Every own property of a record shares the single `value` schema; the
|
|
947
|
+
// `key` schema constrains the property name and is enforced by
|
|
948
|
+
// value-level validation (`isValueValidationRequired`). Record keys are
|
|
949
|
+
// dynamic, so no individual property is required.
|
|
950
|
+
currentSchema = /** @type {import('zodexy').SzRecord<any, any>} */ (
|
|
951
|
+
parentSchema
|
|
952
|
+
).value;
|
|
953
|
+
mustBeOptional = true;
|
|
954
|
+
break;
|
|
955
|
+
case 'looseRecord':
|
|
956
|
+
// As `record`, but only for keys that satisfy the `key` schema. Zod's
|
|
957
|
+
// loose mode passes non-conforming keys through untyped, so the `value`
|
|
958
|
+
// schema must not be imposed on them; leaving `currentSchema` unset
|
|
959
|
+
// falls back to the value's own runtime type (`{type: typesonType}`).
|
|
960
|
+
mustBeOptional = true;
|
|
961
|
+
currentSchema = recordKeyConforms(
|
|
962
|
+
types,
|
|
963
|
+
/** @type {import('zodexy').SzLooseRecord<any, any>} */ (
|
|
964
|
+
parentSchema
|
|
965
|
+
).key,
|
|
966
|
+
arrayOrObjectPropertyName
|
|
967
|
+
)
|
|
968
|
+
? /** @type {import('zodexy').SzLooseRecord<any, any>} */ (
|
|
969
|
+
parentSchema
|
|
970
|
+
).value
|
|
971
|
+
: undefined;
|
|
972
|
+
break;
|
|
653
973
|
// Todo:
|
|
654
|
-
// 'record': key, value
|
|
655
974
|
// 'map': key, value
|
|
656
975
|
// 'function': args, returns
|
|
657
976
|
default:
|
|
658
977
|
break;
|
|
659
978
|
}
|
|
660
979
|
|
|
661
|
-
|
|
980
|
+
// Reached when there is no governing schema for this child: an unschema'd
|
|
981
|
+
// parent, or a `looseRecord` entry whose key does not satisfy the `key`
|
|
982
|
+
// schema (Zod's loose mode passes such entries through untyped). Fall back
|
|
983
|
+
// to the value's own runtime type.
|
|
662
984
|
if (!currentSchema) {
|
|
663
985
|
return {type: typesonType};
|
|
664
986
|
}
|
|
665
987
|
const schemaObjects = [...getTypesForSchema(
|
|
666
|
-
|
|
667
|
-
/** @type {import('
|
|
988
|
+
currentSchema,
|
|
989
|
+
/** @type {import('zodexy').SzType} */ (
|
|
990
|
+
stateObj.schemaContent
|
|
991
|
+
)
|
|
668
992
|
)];
|
|
669
993
|
// console.log(
|
|
670
994
|
// 'vvv', v, currentSchema,
|
|
671
995
|
// arrayOrObjectPropertyName, parentSchema, schemaObjects
|
|
672
996
|
// );
|
|
673
997
|
// console.log('schemaObjects', schemaObjects);
|
|
998
|
+
|
|
999
|
+
// When several union options accept the value, the first structural match
|
|
1000
|
+
// is not necessarily the best one: a bare `{type: 'object', properties:
|
|
1001
|
+
// {}}` option strips unrecognized keys, so it parses successfully (with
|
|
1002
|
+
// data loss) even when a sibling option describes the value's actual
|
|
1003
|
+
// shape. Prefer an option that round-trips the value losslessly, then one
|
|
1004
|
+
// that at least parses, and only then one that merely matches the value's
|
|
1005
|
+
// kind. Preserving that last tier matters for a preloaded value that is
|
|
1006
|
+
// the right type but violates a refinement (a `File` whose MIME type is
|
|
1007
|
+
// outside the schema's `mime`, an array shorter than `min`, …): the
|
|
1008
|
+
// control should still carry its schema (and description), with the
|
|
1009
|
+
// violation surfaced by value-level validation, rather than degrading to
|
|
1010
|
+
// an untyped control.
|
|
1011
|
+
let fallbackMatch;
|
|
1012
|
+
let structuralMatch;
|
|
674
1013
|
for (const [schemaIdx, schema] of schemaObjects.entries()) {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
1014
|
+
const type = getSchemaType(schema);
|
|
1015
|
+
|
|
1016
|
+
const typeObject =
|
|
1017
|
+
/** @type {Required<import('../types.js').TypeObject>} */ (
|
|
1018
|
+
types.getTypeObject(
|
|
1019
|
+
/** @type {import('../types.js').AvailableType} */ (type)
|
|
1020
|
+
)
|
|
1021
|
+
);
|
|
1022
|
+
|
|
1023
|
+
if (!typeObject.valueMatch?.(v)) {
|
|
1024
|
+
continue;
|
|
682
1025
|
}
|
|
1026
|
+
|
|
683
1027
|
const dezSchema = dezerialize(schema, {
|
|
1028
|
+
checks: getChecks(types),
|
|
1029
|
+
codecs: dezerializerCodecs,
|
|
1030
|
+
instances: dezerializerInstances,
|
|
684
1031
|
originalShape: stateObj.schemaContent
|
|
685
1032
|
});
|
|
686
|
-
const parsed =
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
schema.unknownKeys = unknownKeys;
|
|
690
|
-
}
|
|
1033
|
+
const parsed = type === 'promise'
|
|
1034
|
+
? {success: true}
|
|
1035
|
+
: dezSchema.safeParse(v);
|
|
691
1036
|
// console.log('parsed', parsed.success, v, schema);
|
|
692
|
-
if (parsed.success) {
|
|
693
|
-
let type = zodexToStructuredCloningTypeMap.get(schema.type);
|
|
694
|
-
if (!type && schema.type === 'effect') {
|
|
695
|
-
type = /** @type {import('../types.js').AvailableType} */ (
|
|
696
|
-
schema.effects[0].name
|
|
697
|
-
);
|
|
698
|
-
}
|
|
699
1037
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
1038
|
+
/**
|
|
1039
|
+
* @type {{
|
|
1040
|
+
* type: import('../types.js').AvailableArbitraryType|undefined,
|
|
1041
|
+
* schema?: import('zodexy').SzType,
|
|
1042
|
+
* mustBeOptional?: boolean,
|
|
1043
|
+
* schemaIdx?: number
|
|
1044
|
+
* }}
|
|
1045
|
+
*/
|
|
1046
|
+
const match = {
|
|
1047
|
+
type,
|
|
1048
|
+
schemaIdx,
|
|
1049
|
+
// For `readonly`, we just want to show the current type (no
|
|
1050
|
+
// pull-down)
|
|
1051
|
+
schema: !stateObj.rootUI ||
|
|
1052
|
+
(stateObj.readonly || schemaObjects.length === 1)
|
|
1053
|
+
? schema
|
|
1054
|
+
// This synthesized schema only drives the type-choices pull-down;
|
|
1055
|
+
// it is deliberately a plain `union` of the flattened leaf
|
|
1056
|
+
// candidates. Exclusive (`xor`) / keyed (`discriminatedUnion`)
|
|
1057
|
+
// enforcement stays with the original schema node, which
|
|
1058
|
+
// `getValidationSchema` passes through untouched to
|
|
1059
|
+
// `validateValue`.
|
|
1060
|
+
: {
|
|
1061
|
+
type: 'union',
|
|
1062
|
+
options: schemaObjects
|
|
1063
|
+
},
|
|
1064
|
+
mustBeOptional
|
|
1065
|
+
};
|
|
1066
|
+
|
|
1067
|
+
if (parsed.success) {
|
|
1068
|
+
// console.log(
|
|
1069
|
+
// 'matched', v, v?.length, type, schema, schemaIdx, schemaObjects
|
|
1070
|
+
// );
|
|
1071
|
+
if (
|
|
1072
|
+
type === 'promise' ||
|
|
1073
|
+
('data' in parsed && deepEqual(parsed.data, v))
|
|
1074
|
+
) {
|
|
1075
|
+
return match;
|
|
728
1076
|
}
|
|
1077
|
+
fallbackMatch ??= match;
|
|
1078
|
+
} else {
|
|
1079
|
+
structuralMatch ??= match;
|
|
729
1080
|
}
|
|
730
1081
|
}
|
|
1082
|
+
if (fallbackMatch) {
|
|
1083
|
+
return fallbackMatch;
|
|
1084
|
+
}
|
|
1085
|
+
if (structuralMatch) {
|
|
1086
|
+
return structuralMatch;
|
|
1087
|
+
}
|
|
731
1088
|
return {type: typesonType};
|
|
732
1089
|
},
|
|
733
1090
|
|
|
@@ -749,34 +1106,26 @@ const schema = {
|
|
|
749
1106
|
);
|
|
750
1107
|
}
|
|
751
1108
|
|
|
752
|
-
//
|
|
1109
|
+
// console.log(JSON.stringify(schemaObject));
|
|
753
1110
|
const schemaObjects = [...getTypesForSchema(
|
|
754
1111
|
schemaObject,
|
|
755
|
-
/** @type {import('
|
|
1112
|
+
/** @type {import('zodexy').SzType} */ (
|
|
1113
|
+
schemaOriginal
|
|
1114
|
+
) ?? schemaObject
|
|
756
1115
|
)];
|
|
757
1116
|
|
|
758
1117
|
// Note: Zod does not support array/object references
|
|
759
1118
|
|
|
760
|
-
//
|
|
1119
|
+
// `tuple`/`record` restrictions on `array`/`object` are applied via
|
|
1120
|
+
// `getSchemaType` (type mapping) plus `arrayType.js` reading
|
|
1121
|
+
// `specificSchemaObject.type`, and enforced by `isValueValidationRequired`.
|
|
761
1122
|
// Todo: Fix `iterate` for schemas (e.g., inject a value method in demo)
|
|
762
1123
|
|
|
763
|
-
/** @type {AvailableZodexType[]} */
|
|
764
|
-
const typeArray = schemaObjects.map(({type}) => {
|
|
765
|
-
return type;
|
|
766
|
-
});
|
|
767
|
-
|
|
768
1124
|
return {
|
|
769
1125
|
schemaObjects,
|
|
770
|
-
types:
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
/** @type {import('zodex').SzEffect} */ (
|
|
774
|
-
schemaObjects[idx]
|
|
775
|
-
).effects[0].name
|
|
776
|
-
);
|
|
777
|
-
}
|
|
778
|
-
return /** @type {import('../types.js').AvailableType} */ (
|
|
779
|
-
zodexToStructuredCloningTypeMap.get(item)
|
|
1126
|
+
types: schemaObjects.map((schemaItem) => {
|
|
1127
|
+
return /** @type {import('../types.js').AvailableArbitraryType} */ (
|
|
1128
|
+
getSchemaType(schemaItem)
|
|
780
1129
|
);
|
|
781
1130
|
})
|
|
782
1131
|
};
|