@es-joy/jsoe 0.24.3 → 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 +47 -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.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 -79
- 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
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
import * as regexes from "./regexes.js";
|
|
2
|
+
import { extractDefs, finalize, handleUnrepresentable, initializeContext, process, } from "./to-json-schema.js";
|
|
3
|
+
import { assignProp, getEnumValues } from "./util.js";
|
|
4
|
+
const formatMap = {
|
|
5
|
+
guid: "uuid",
|
|
6
|
+
url: "uri",
|
|
7
|
+
datetime: "date-time",
|
|
8
|
+
json_string: "json-string",
|
|
9
|
+
regex: "", // do not set
|
|
10
|
+
};
|
|
11
|
+
// ==================== SIMPLE TYPE PROCESSORS ====================
|
|
12
|
+
export const stringProcessor = (schema, ctx, _json, _params) => {
|
|
13
|
+
const json = _json;
|
|
14
|
+
json.type = "string";
|
|
15
|
+
const { minimum, maximum, format, patterns, contentEncoding, laxFormat } = schema._zod
|
|
16
|
+
.bag;
|
|
17
|
+
if (typeof minimum === "number")
|
|
18
|
+
json.minLength = minimum;
|
|
19
|
+
if (typeof maximum === "number")
|
|
20
|
+
json.maxLength = maximum;
|
|
21
|
+
// custom pattern overrides format
|
|
22
|
+
if (format) {
|
|
23
|
+
json.format = formatMap[format] ?? format;
|
|
24
|
+
if (json.format === "")
|
|
25
|
+
delete json.format; // empty format is not valid
|
|
26
|
+
// `z.iso.time()` is never full-time, and `laxFormat` carries the datetime shapes that also accept what their keyword forbids
|
|
27
|
+
if (format === "time" || laxFormat) {
|
|
28
|
+
delete json.format;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (contentEncoding)
|
|
32
|
+
json.contentEncoding = contentEncoding;
|
|
33
|
+
if (patterns && patterns.size > 0) {
|
|
34
|
+
const patternList = [...patterns];
|
|
35
|
+
if (patternList.length === 1)
|
|
36
|
+
json.pattern = patternList[0].source;
|
|
37
|
+
else if (patternList.length > 1) {
|
|
38
|
+
json.allOf = [
|
|
39
|
+
...patternList.map((regex) => ({
|
|
40
|
+
...(ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0"
|
|
41
|
+
? { type: "string" }
|
|
42
|
+
: {}),
|
|
43
|
+
pattern: regex.source,
|
|
44
|
+
})),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export const numberProcessor = (schema, ctx, _json, params) => {
|
|
50
|
+
const json = _json;
|
|
51
|
+
const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
|
|
52
|
+
if (typeof format === "string" && format.includes("int"))
|
|
53
|
+
json.type = "integer";
|
|
54
|
+
else
|
|
55
|
+
json.type = "number";
|
|
56
|
+
// when both minimum and exclusiveMinimum exist, pick the more restrictive one
|
|
57
|
+
const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
|
|
58
|
+
const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
|
|
59
|
+
const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
|
|
60
|
+
if (exMin) {
|
|
61
|
+
if (legacy) {
|
|
62
|
+
json.minimum = exclusiveMinimum;
|
|
63
|
+
json.exclusiveMinimum = true;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
json.exclusiveMinimum = exclusiveMinimum;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (typeof minimum === "number") {
|
|
70
|
+
json.minimum = minimum;
|
|
71
|
+
}
|
|
72
|
+
if (exMax) {
|
|
73
|
+
if (legacy) {
|
|
74
|
+
json.maximum = exclusiveMaximum;
|
|
75
|
+
json.exclusiveMaximum = true;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
json.exclusiveMaximum = exclusiveMaximum;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (typeof maximum === "number") {
|
|
82
|
+
json.maximum = maximum;
|
|
83
|
+
}
|
|
84
|
+
if (typeof multipleOf === "number") {
|
|
85
|
+
// JSON Schema requires a divisor strictly greater than zero, and a non-finite one does not survive JSON at all. A negative divisor accepts exactly what its absolute value accepts, so it still maps; zero, NaN and Infinity have no keyword form.
|
|
86
|
+
if (Number.isFinite(multipleOf) && multipleOf !== 0)
|
|
87
|
+
json.multipleOf = Math.abs(multipleOf);
|
|
88
|
+
else
|
|
89
|
+
handleUnrepresentable(schema, ctx, json, params, `A multipleOf divisor of ${multipleOf} cannot be represented in JSON Schema`);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export const booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
93
|
+
json.type = "boolean";
|
|
94
|
+
};
|
|
95
|
+
export const bigintProcessor = (schema, ctx, json, params) => {
|
|
96
|
+
handleUnrepresentable(schema, ctx, json, params, "BigInt cannot be represented in JSON Schema");
|
|
97
|
+
};
|
|
98
|
+
export const symbolProcessor = (schema, ctx, json, params) => {
|
|
99
|
+
handleUnrepresentable(schema, ctx, json, params, "Symbols cannot be represented in JSON Schema");
|
|
100
|
+
};
|
|
101
|
+
export const nullProcessor = (_schema, ctx, json, _params) => {
|
|
102
|
+
if (ctx.target === "openapi-3.0") {
|
|
103
|
+
json.type = "string";
|
|
104
|
+
json.nullable = true;
|
|
105
|
+
json.enum = [null];
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
json.type = "null";
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
export const undefinedProcessor = (schema, ctx, json, params) => {
|
|
112
|
+
handleUnrepresentable(schema, ctx, json, params, "Undefined cannot be represented in JSON Schema");
|
|
113
|
+
};
|
|
114
|
+
export const voidProcessor = (schema, ctx, json, params) => {
|
|
115
|
+
handleUnrepresentable(schema, ctx, json, params, "Void cannot be represented in JSON Schema");
|
|
116
|
+
};
|
|
117
|
+
export const neverProcessor = (_schema, _ctx, json, _params) => {
|
|
118
|
+
json.not = {};
|
|
119
|
+
};
|
|
120
|
+
export const anyProcessor = (_schema, _ctx, _json, _params) => {
|
|
121
|
+
// empty schema accepts anything
|
|
122
|
+
};
|
|
123
|
+
export const unknownProcessor = (_schema, _ctx, _json, _params) => {
|
|
124
|
+
// empty schema accepts anything
|
|
125
|
+
};
|
|
126
|
+
export const dateProcessor = (schema, ctx, json, params) => {
|
|
127
|
+
handleUnrepresentable(schema, ctx, json, params, "Date cannot be represented in JSON Schema");
|
|
128
|
+
};
|
|
129
|
+
export const enumProcessor = (schema, _ctx, json, _params) => {
|
|
130
|
+
const def = schema._zod.def;
|
|
131
|
+
const values = getEnumValues(def.entries);
|
|
132
|
+
// an empty enum accepts nothing, same as z.never()
|
|
133
|
+
if (values.length === 0) {
|
|
134
|
+
json.not = {};
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
// Number enums can have both string and number values
|
|
138
|
+
if (values.every((v) => typeof v === "number"))
|
|
139
|
+
json.type = "number";
|
|
140
|
+
if (values.every((v) => typeof v === "string"))
|
|
141
|
+
json.type = "string";
|
|
142
|
+
json.enum = values;
|
|
143
|
+
};
|
|
144
|
+
export const literalProcessor = (schema, ctx, json, params) => {
|
|
145
|
+
const def = schema._zod.def;
|
|
146
|
+
// a literal with no values accepts nothing, same as z.never()
|
|
147
|
+
if (def.values.length === 0) {
|
|
148
|
+
json.not = {};
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const vals = [];
|
|
152
|
+
for (const val of def.values) {
|
|
153
|
+
if (val === undefined) {
|
|
154
|
+
// a custom schema replaces the whole literal, so there is nothing left to accumulate
|
|
155
|
+
if (handleUnrepresentable(schema, ctx, json, params, "Literal `undefined` cannot be represented in JSON Schema"))
|
|
156
|
+
return;
|
|
157
|
+
// otherwise do not add to vals
|
|
158
|
+
}
|
|
159
|
+
else if (typeof val === "bigint") {
|
|
160
|
+
if (handleUnrepresentable(schema, ctx, json, params, "BigInt literals cannot be represented in JSON Schema"))
|
|
161
|
+
return;
|
|
162
|
+
vals.push(Number(val));
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
vals.push(val);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (vals.length === 0) {
|
|
169
|
+
// do nothing (an undefined literal was stripped)
|
|
170
|
+
}
|
|
171
|
+
else if (vals.length === 1) {
|
|
172
|
+
const val = vals[0];
|
|
173
|
+
json.type = val === null ? "null" : typeof val;
|
|
174
|
+
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
175
|
+
json.enum = [val];
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
json.const = val;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
if (vals.every((v) => typeof v === "number"))
|
|
183
|
+
json.type = "number";
|
|
184
|
+
if (vals.every((v) => typeof v === "string"))
|
|
185
|
+
json.type = "string";
|
|
186
|
+
if (vals.every((v) => typeof v === "boolean"))
|
|
187
|
+
json.type = "boolean";
|
|
188
|
+
if (vals.every((v) => v === null))
|
|
189
|
+
json.type = "null";
|
|
190
|
+
json.enum = vals;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
export const nanProcessor = (schema, ctx, json, params) => {
|
|
194
|
+
handleUnrepresentable(schema, ctx, json, params, "NaN cannot be represented in JSON Schema");
|
|
195
|
+
};
|
|
196
|
+
export const templateLiteralProcessor = (schema, _ctx, json, _params) => {
|
|
197
|
+
const _json = json;
|
|
198
|
+
const pattern = schema._zod.pattern;
|
|
199
|
+
if (!pattern)
|
|
200
|
+
throw new Error("Pattern not found in template literal");
|
|
201
|
+
_json.type = "string";
|
|
202
|
+
_json.pattern = pattern.source;
|
|
203
|
+
};
|
|
204
|
+
export const fileProcessor = (schema, _ctx, json, _params) => {
|
|
205
|
+
const _json = json;
|
|
206
|
+
const file = {
|
|
207
|
+
type: "string",
|
|
208
|
+
format: "binary",
|
|
209
|
+
contentEncoding: "binary",
|
|
210
|
+
};
|
|
211
|
+
const { minimum, maximum, mime } = schema._zod.bag;
|
|
212
|
+
if (minimum !== undefined)
|
|
213
|
+
file.minLength = minimum;
|
|
214
|
+
if (maximum !== undefined)
|
|
215
|
+
file.maxLength = maximum;
|
|
216
|
+
if (mime) {
|
|
217
|
+
if (mime.length === 1) {
|
|
218
|
+
file.contentMediaType = mime[0];
|
|
219
|
+
Object.assign(_json, file);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
Object.assign(_json, file); // shared props at root
|
|
223
|
+
_json.anyOf = mime.map((m) => ({ contentMediaType: m })); // only contentMediaType differs
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
Object.assign(_json, file);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
export const successProcessor = (_schema, _ctx, json, _params) => {
|
|
231
|
+
json.type = "boolean";
|
|
232
|
+
};
|
|
233
|
+
export const customProcessor = (schema, ctx, json, params) => {
|
|
234
|
+
handleUnrepresentable(schema, ctx, json, params, "Custom types cannot be represented in JSON Schema");
|
|
235
|
+
};
|
|
236
|
+
export const functionProcessor = (schema, ctx, json, params) => {
|
|
237
|
+
handleUnrepresentable(schema, ctx, json, params, "Function types cannot be represented in JSON Schema");
|
|
238
|
+
};
|
|
239
|
+
export const transformProcessor = (schema, ctx, json, params) => {
|
|
240
|
+
handleUnrepresentable(schema, ctx, json, params, "Transforms cannot be represented in JSON Schema");
|
|
241
|
+
};
|
|
242
|
+
export const mapProcessor = (schema, ctx, json, params) => {
|
|
243
|
+
handleUnrepresentable(schema, ctx, json, params, "Map cannot be represented in JSON Schema");
|
|
244
|
+
};
|
|
245
|
+
export const setProcessor = (schema, ctx, json, params) => {
|
|
246
|
+
handleUnrepresentable(schema, ctx, json, params, "Set cannot be represented in JSON Schema");
|
|
247
|
+
};
|
|
248
|
+
// ==================== COMPOSITE TYPE PROCESSORS ====================
|
|
249
|
+
export const arrayProcessor = (schema, ctx, _json, params) => {
|
|
250
|
+
const json = _json;
|
|
251
|
+
const def = schema._zod.def;
|
|
252
|
+
const { minimum, maximum } = schema._zod.bag;
|
|
253
|
+
if (typeof minimum === "number")
|
|
254
|
+
json.minItems = minimum;
|
|
255
|
+
if (typeof maximum === "number")
|
|
256
|
+
json.maxItems = maximum;
|
|
257
|
+
json.type = "array";
|
|
258
|
+
json.items = process(def.element, ctx, {
|
|
259
|
+
...params,
|
|
260
|
+
path: [...params.path, "items"],
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
// Transform and catch set `optin = "optional"` at runtime so the parser lets them observe an
|
|
264
|
+
// absent key, but their declared input type stays required. An input JSON Schema describes the
|
|
265
|
+
// declared type, so resolve past them to the schema that actually carries the optionality.
|
|
266
|
+
// Used by both `objectProcessor` (for `required`) and `tupleProcessor` (for `minItems`); see
|
|
267
|
+
// wiki/optionality.md, "The JSON Schema emitter reads the *static* value".
|
|
268
|
+
function inputOptin(schema) {
|
|
269
|
+
const def = schema._zod.def;
|
|
270
|
+
if (def.type === "pipe" && def.in._zod.traits.has("$ZodTransform")) {
|
|
271
|
+
return inputOptin(def.out);
|
|
272
|
+
}
|
|
273
|
+
if (def.type === "catch") {
|
|
274
|
+
return inputOptin(def.innerType);
|
|
275
|
+
}
|
|
276
|
+
return schema._zod.optin;
|
|
277
|
+
}
|
|
278
|
+
export const objectProcessor = (schema, ctx, _json, params) => {
|
|
279
|
+
const json = _json;
|
|
280
|
+
const def = schema._zod.def;
|
|
281
|
+
const shape = def.shape;
|
|
282
|
+
// dropping it while still emitting `additionalProperties: false` would emit a schema that rejects data this one requires
|
|
283
|
+
const symbolKeys = Object.getOwnPropertySymbols(shape);
|
|
284
|
+
if (symbolKeys.length &&
|
|
285
|
+
handleUnrepresentable(schema, ctx, json, params, "Symbol keys cannot be represented in JSON Schema")) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
json.type = "object";
|
|
289
|
+
json.properties = {};
|
|
290
|
+
for (const key in shape) {
|
|
291
|
+
// assignProp so a __proto__ key becomes an own property instead of hitting the inherited setter on the plain {} we build into
|
|
292
|
+
assignProp(json.properties, key, process(shape[key], ctx, {
|
|
293
|
+
...params,
|
|
294
|
+
path: [...params.path, "properties", key],
|
|
295
|
+
}));
|
|
296
|
+
}
|
|
297
|
+
// required keys
|
|
298
|
+
const allKeys = new Set(Object.keys(shape));
|
|
299
|
+
const requiredKeys = new Set([...allKeys].filter((key) => {
|
|
300
|
+
const field = def.shape[key];
|
|
301
|
+
if (ctx.io === "input") {
|
|
302
|
+
return inputOptin(field) === undefined;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
return field._zod.optout === undefined;
|
|
306
|
+
}
|
|
307
|
+
}));
|
|
308
|
+
if (requiredKeys.size > 0) {
|
|
309
|
+
json.required = Array.from(requiredKeys);
|
|
310
|
+
}
|
|
311
|
+
// catchall
|
|
312
|
+
if (def.catchall?._zod.def.type === "never") {
|
|
313
|
+
// strict
|
|
314
|
+
json.additionalProperties = false;
|
|
315
|
+
}
|
|
316
|
+
else if (!def.catchall) {
|
|
317
|
+
// regular
|
|
318
|
+
if (ctx.io === "output")
|
|
319
|
+
json.additionalProperties = false;
|
|
320
|
+
}
|
|
321
|
+
else if (def.catchall) {
|
|
322
|
+
json.additionalProperties = process(def.catchall, ctx, {
|
|
323
|
+
...params,
|
|
324
|
+
path: [...params.path, "additionalProperties"],
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
export const unionProcessor = (schema, ctx, json, params) => {
|
|
329
|
+
const def = schema._zod.def;
|
|
330
|
+
// Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches). This includes both z.xor() and discriminated unions
|
|
331
|
+
const isExclusive = def.inclusive === false;
|
|
332
|
+
const options = def.options.map((x, i) => process(x, ctx, {
|
|
333
|
+
...params,
|
|
334
|
+
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
|
|
335
|
+
}));
|
|
336
|
+
if (isExclusive) {
|
|
337
|
+
json.oneOf = options;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
json.anyOf = options;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
export const intersectionProcessor = (schema, ctx, json, params) => {
|
|
344
|
+
const def = schema._zod.def;
|
|
345
|
+
const a = process(def.left, ctx, {
|
|
346
|
+
...params,
|
|
347
|
+
path: [...params.path, "allOf", 0],
|
|
348
|
+
});
|
|
349
|
+
const b = process(def.right, ctx, {
|
|
350
|
+
...params,
|
|
351
|
+
path: [...params.path, "allOf", 1],
|
|
352
|
+
});
|
|
353
|
+
const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
|
|
354
|
+
const allOf = [
|
|
355
|
+
...(isSimpleIntersection(a) ? a.allOf : [a]),
|
|
356
|
+
...(isSimpleIntersection(b) ? b.allOf : [b]),
|
|
357
|
+
];
|
|
358
|
+
json.allOf = allOf;
|
|
359
|
+
// Recorded innermost first, so a nested intersection has already folded by the time this one is considered. The array is the handle rather than the schema, because a wrapper that inherits this schema shares the same array; `finalize` folds every object holding it. See `foldIntersection`.
|
|
360
|
+
ctx.intersections.push(allOf);
|
|
361
|
+
};
|
|
362
|
+
export const tupleProcessor = (schema, ctx, _json, params) => {
|
|
363
|
+
const json = _json;
|
|
364
|
+
const def = schema._zod.def;
|
|
365
|
+
json.type = "array";
|
|
366
|
+
const prefixPath = ctx.target === "draft-2020-12" ? "prefixItems" : "items";
|
|
367
|
+
const restPath = ctx.target === "draft-2020-12" ? "items" : ctx.target === "openapi-3.0" ? "items" : "additionalItems";
|
|
368
|
+
const prefixItems = def.items.map((x, i) => process(x, ctx, {
|
|
369
|
+
...params,
|
|
370
|
+
path: [...params.path, prefixPath, i],
|
|
371
|
+
}));
|
|
372
|
+
const rest = def.rest
|
|
373
|
+
? process(def.rest, ctx, {
|
|
374
|
+
...params,
|
|
375
|
+
path: [...params.path, restPath, ...(ctx.target === "openapi-3.0" ? [def.items.length] : [])],
|
|
376
|
+
})
|
|
377
|
+
: null;
|
|
378
|
+
let minItems = def.items.length;
|
|
379
|
+
while (minItems > 0) {
|
|
380
|
+
const item = def.items[minItems - 1];
|
|
381
|
+
const optional = ctx.io === "input" ? inputOptin(item) !== undefined : item._zod.optout === "optional";
|
|
382
|
+
if (!optional)
|
|
383
|
+
break;
|
|
384
|
+
minItems--;
|
|
385
|
+
}
|
|
386
|
+
const maxItems = def.items.length;
|
|
387
|
+
const isClosed = !def.rest;
|
|
388
|
+
if (ctx.target === "draft-2020-12") {
|
|
389
|
+
json.prefixItems = prefixItems;
|
|
390
|
+
if (isClosed) {
|
|
391
|
+
json.items = false;
|
|
392
|
+
}
|
|
393
|
+
else if (rest) {
|
|
394
|
+
json.items = rest;
|
|
395
|
+
}
|
|
396
|
+
if (minItems > 0)
|
|
397
|
+
json.minItems = minItems;
|
|
398
|
+
if (isClosed)
|
|
399
|
+
json.maxItems = maxItems;
|
|
400
|
+
}
|
|
401
|
+
else if (ctx.target === "openapi-3.0") {
|
|
402
|
+
json.items = {
|
|
403
|
+
anyOf: prefixItems,
|
|
404
|
+
};
|
|
405
|
+
if (rest) {
|
|
406
|
+
json.items.anyOf.push(rest);
|
|
407
|
+
}
|
|
408
|
+
if (minItems > 0)
|
|
409
|
+
json.minItems = minItems;
|
|
410
|
+
if (isClosed)
|
|
411
|
+
json.maxItems = maxItems;
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
json.items = prefixItems;
|
|
415
|
+
if (isClosed) {
|
|
416
|
+
json.additionalItems = false;
|
|
417
|
+
}
|
|
418
|
+
else if (rest) {
|
|
419
|
+
json.additionalItems = rest;
|
|
420
|
+
}
|
|
421
|
+
if (minItems > 0)
|
|
422
|
+
json.minItems = minItems;
|
|
423
|
+
if (isClosed)
|
|
424
|
+
json.maxItems = maxItems;
|
|
425
|
+
}
|
|
426
|
+
// explicit user-defined length checks take precedence
|
|
427
|
+
const { minimum, maximum } = schema._zod.bag;
|
|
428
|
+
if (typeof minimum === "number")
|
|
429
|
+
json.minItems = minimum;
|
|
430
|
+
if (typeof maximum === "number")
|
|
431
|
+
json.maxItems = maximum;
|
|
432
|
+
};
|
|
433
|
+
/** JSON object keys are always strings, so a numeric record key schema is re-expressed over the
|
|
434
|
+
* numeric-string form the record parser matches. Deferred to `finalize`, after the flatten: a key
|
|
435
|
+
* behind a wrapper only carries its own `type` before then, and a union key only has its branches.
|
|
436
|
+
*
|
|
437
|
+
* A numeric bound cannot apply to a property name, so `minimum` and its siblings are dropped rather
|
|
438
|
+
* than carried over: keeping them beside `type: "string"` reproduces the match-nothing schema this
|
|
439
|
+
* exists to fix. A key that carries one therefore emits wider than the record parses — `z.record(z.number().min(5), V)`
|
|
440
|
+
* accepts `"3"` — which is the deliberate trade, since throwing on it would reject an ordinary schema
|
|
441
|
+
* outright. */
|
|
442
|
+
function stringifyKeyNames(bySchema, json, visited) {
|
|
443
|
+
// an extracted key that rewrites cannot go on sharing its definition — the string form a key position needs is not the number form every other reference wants — so it inlines. One that does not rewrite keeps the `$ref`.
|
|
444
|
+
if (json.$ref) {
|
|
445
|
+
// a recursive key holds its own reference inside its definition, so a node already on the path is left alone rather than resolved again
|
|
446
|
+
if (visited.has(json))
|
|
447
|
+
return json;
|
|
448
|
+
visited.add(json);
|
|
449
|
+
const def = bySchema.get(json)?.def;
|
|
450
|
+
if (!def)
|
|
451
|
+
return json;
|
|
452
|
+
const inlined = stringifyKeyNames(bySchema, def, visited);
|
|
453
|
+
return inlined === def ? json : inlined;
|
|
454
|
+
}
|
|
455
|
+
for (const keyword of ["anyOf", "oneOf"]) {
|
|
456
|
+
const branches = json[keyword];
|
|
457
|
+
if (!Array.isArray(branches))
|
|
458
|
+
continue;
|
|
459
|
+
const mapped = branches.map((branch) => stringifyKeyNames(bySchema, branch, visited));
|
|
460
|
+
// rebuilding regardless would detach a key that had nothing to re-express, dropping its `$ref` and leaking the internal `id`
|
|
461
|
+
if (mapped.some((branch, i) => branch !== branches[i]))
|
|
462
|
+
json = { ...json, [keyword]: mapped };
|
|
463
|
+
}
|
|
464
|
+
// a member that already admits a string leaves the key unconstrained, so the node's own type re-expresses only when every member is numeric
|
|
465
|
+
const types = Array.isArray(json.type) ? json.type : [json.type];
|
|
466
|
+
const numericType = !types.includes("string") && types.some((t) => t === "number" || t === "integer");
|
|
467
|
+
// a heterogeneous key carries no type at all, so its numeric members are caught here instead
|
|
468
|
+
const values = json.enum ?? (json.const !== undefined ? [json.const] : undefined);
|
|
469
|
+
if (!numericType && !values?.some((v) => typeof v === "number"))
|
|
470
|
+
return json;
|
|
471
|
+
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id, ...rest } = json;
|
|
472
|
+
if (rest.enum)
|
|
473
|
+
rest.enum = rest.enum.map((v) => (typeof v === "number" ? String(v) : v));
|
|
474
|
+
else if (typeof rest.const === "number")
|
|
475
|
+
rest.const = String(rest.const);
|
|
476
|
+
// a heterogeneous key keeps its absent type: the stringified members already say what a key may be
|
|
477
|
+
if (!numericType)
|
|
478
|
+
return rest;
|
|
479
|
+
rest.type = "string";
|
|
480
|
+
if (!values)
|
|
481
|
+
rest.pattern = (types.includes("number") ? regexes.number : regexes.integer).source;
|
|
482
|
+
return rest;
|
|
483
|
+
}
|
|
484
|
+
/** Every record of one conversion, so the carriers are found in a single pass rather than once per record. */
|
|
485
|
+
const pendingRecords = new WeakMap();
|
|
486
|
+
function rewriteKeyNames(ctx) {
|
|
487
|
+
// an extracted key is resolved by the object `extractToDef` left in its place, so the map is built once rather than searched per reference. `_zod.toJSONSchema` can hand the same object to two schemas, so the first entry carrying a body wins, as a search would have found it.
|
|
488
|
+
const bySchema = new Map();
|
|
489
|
+
for (const entry of ctx.seen.values()) {
|
|
490
|
+
if (entry.def && !bySchema.has(entry.schema))
|
|
491
|
+
bySchema.set(entry.schema, entry);
|
|
492
|
+
}
|
|
493
|
+
const rewrites = new Map();
|
|
494
|
+
for (const record of pendingRecords.get(ctx) ?? []) {
|
|
495
|
+
const seen = ctx.seen.get(record);
|
|
496
|
+
const names = (seen?.def ?? seen?.schema)?.propertyNames;
|
|
497
|
+
if (!names || names === true || rewrites.has(names))
|
|
498
|
+
continue;
|
|
499
|
+
const rewritten = stringifyKeyNames(bySchema, names, new Set());
|
|
500
|
+
if (rewritten !== names)
|
|
501
|
+
rewrites.set(names, rewritten);
|
|
502
|
+
}
|
|
503
|
+
if (!rewrites.size)
|
|
504
|
+
return;
|
|
505
|
+
// the flatten has already copied each record's own properties onto every wrapper by reference, and an extracted body is another such copy, so every carrier holding a rewritten key is updated together
|
|
506
|
+
for (const entry of ctx.seen.values()) {
|
|
507
|
+
for (const carrier of [entry.schema, entry.def]) {
|
|
508
|
+
const rewritten = carrier && rewrites.get(carrier.propertyNames);
|
|
509
|
+
if (rewritten)
|
|
510
|
+
carrier.propertyNames = rewritten;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
export const recordProcessor = (schema, ctx, _json, params) => {
|
|
515
|
+
const json = _json;
|
|
516
|
+
const def = schema._zod.def;
|
|
517
|
+
json.type = "object";
|
|
518
|
+
// For looseRecord with regex patterns, use patternProperties. This correctly represents "only validate keys matching the pattern" semantics and composes well with allOf (intersections)
|
|
519
|
+
const keyType = def.keyType;
|
|
520
|
+
const keyBag = keyType._zod.bag;
|
|
521
|
+
const patterns = keyBag?.patterns;
|
|
522
|
+
if (def.mode === "loose" && patterns && patterns.size > 0) {
|
|
523
|
+
// Use patternProperties for looseRecord with regex patterns
|
|
524
|
+
const valueSchema = process(def.valueType, ctx, {
|
|
525
|
+
...params,
|
|
526
|
+
path: [...params.path, "patternProperties", "*"],
|
|
527
|
+
});
|
|
528
|
+
json.patternProperties = {};
|
|
529
|
+
for (const pattern of patterns) {
|
|
530
|
+
assignProp(json.patternProperties, pattern.source, valueSchema);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
// Default behavior: use propertyNames + additionalProperties
|
|
535
|
+
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
|
|
536
|
+
json.propertyNames = process(def.keyType, ctx, {
|
|
537
|
+
...params,
|
|
538
|
+
path: [...params.path, "propertyNames"],
|
|
539
|
+
});
|
|
540
|
+
let pending = pendingRecords.get(ctx);
|
|
541
|
+
if (!pending) {
|
|
542
|
+
pending = [];
|
|
543
|
+
pendingRecords.set(ctx, pending);
|
|
544
|
+
ctx.deferred.push(() => rewriteKeyNames(ctx));
|
|
545
|
+
}
|
|
546
|
+
pending.push(schema);
|
|
547
|
+
}
|
|
548
|
+
json.additionalProperties = process(def.valueType, ctx, {
|
|
549
|
+
...params,
|
|
550
|
+
path: [...params.path, "additionalProperties"],
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
// Add required for keys with discrete values (enum, literal, etc.)
|
|
554
|
+
const keyValues = keyType._zod.values;
|
|
555
|
+
// Every key shares one value schema, so an optional-in value makes the whole key set omittable on input. Output keeps them: the exhaustive branch assigns every key, even one whose value came back undefined.
|
|
556
|
+
const omittableOnInput = ctx.io === "input" && inputOptin(def.valueType) !== undefined;
|
|
557
|
+
if (keyValues && !def.partial && !omittableOnInput) {
|
|
558
|
+
const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
|
|
559
|
+
if (validKeyValues.length > 0) {
|
|
560
|
+
json.required = validKeyValues.map(String);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
export const nullableProcessor = (schema, ctx, json, params) => {
|
|
565
|
+
const def = schema._zod.def;
|
|
566
|
+
const inner = process(def.innerType, ctx, params);
|
|
567
|
+
const seen = ctx.seen.get(schema);
|
|
568
|
+
if (ctx.target === "openapi-3.0") {
|
|
569
|
+
seen.ref = def.innerType;
|
|
570
|
+
json.nullable = true;
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
json.anyOf = [inner, { type: "null" }];
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
export const nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
577
|
+
const def = schema._zod.def;
|
|
578
|
+
process(def.innerType, ctx, params);
|
|
579
|
+
const seen = ctx.seen.get(schema);
|
|
580
|
+
seen.ref = def.innerType;
|
|
581
|
+
};
|
|
582
|
+
/** Round-trips a default value through JSON so the emitted schema is guaranteed to be valid JSON.
|
|
583
|
+
* A BigInt has no reliable encoding, so it goes through `unrepresentable` like any other
|
|
584
|
+
* unrepresentable value. Returns a sentinel when the caller must not write a default of its own. */
|
|
585
|
+
const UNREPRESENTABLE_DEFAULT = Symbol();
|
|
586
|
+
function serializeDefaultValue(value, schema, ctx, json, params) {
|
|
587
|
+
let unrepresentable = false;
|
|
588
|
+
const serialized = JSON.stringify(value, (_, val) => {
|
|
589
|
+
if (typeof val !== "bigint")
|
|
590
|
+
return val;
|
|
591
|
+
unrepresentable = true;
|
|
592
|
+
return null;
|
|
593
|
+
});
|
|
594
|
+
if (!unrepresentable)
|
|
595
|
+
return JSON.parse(serialized);
|
|
596
|
+
handleUnrepresentable(schema, ctx, json, params, "BigInt defaults cannot be represented in JSON Schema");
|
|
597
|
+
return UNREPRESENTABLE_DEFAULT;
|
|
598
|
+
}
|
|
599
|
+
export const defaultProcessor = (schema, ctx, json, params) => {
|
|
600
|
+
const def = schema._zod.def;
|
|
601
|
+
process(def.innerType, ctx, params);
|
|
602
|
+
const seen = ctx.seen.get(schema);
|
|
603
|
+
seen.ref = def.innerType;
|
|
604
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json, params);
|
|
605
|
+
if (value !== UNREPRESENTABLE_DEFAULT)
|
|
606
|
+
json.default = value;
|
|
607
|
+
};
|
|
608
|
+
export const prefaultProcessor = (schema, ctx, json, params) => {
|
|
609
|
+
const def = schema._zod.def;
|
|
610
|
+
process(def.innerType, ctx, params);
|
|
611
|
+
const seen = ctx.seen.get(schema);
|
|
612
|
+
seen.ref = def.innerType;
|
|
613
|
+
if (ctx.io !== "input")
|
|
614
|
+
return;
|
|
615
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json, params);
|
|
616
|
+
if (value !== UNREPRESENTABLE_DEFAULT)
|
|
617
|
+
json._prefault = value;
|
|
618
|
+
};
|
|
619
|
+
export const catchProcessor = (schema, ctx, json, params) => {
|
|
620
|
+
const def = schema._zod.def;
|
|
621
|
+
process(def.innerType, ctx, params);
|
|
622
|
+
const seen = ctx.seen.get(schema);
|
|
623
|
+
seen.ref = def.innerType;
|
|
624
|
+
let catchValue;
|
|
625
|
+
try {
|
|
626
|
+
catchValue = def.catchValue(undefined);
|
|
627
|
+
}
|
|
628
|
+
catch {
|
|
629
|
+
handleUnrepresentable(schema, ctx, json, params, "Dynamic catch values are not supported in JSON Schema");
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
json.default = catchValue;
|
|
633
|
+
};
|
|
634
|
+
export const pipeProcessor = (schema, ctx, _json, params) => {
|
|
635
|
+
const def = schema._zod.def;
|
|
636
|
+
const inIsTransform = def.in._zod.traits.has("$ZodTransform");
|
|
637
|
+
const innerType = ctx.io === "input" ? (inIsTransform ? def.out : def.in) : def.out;
|
|
638
|
+
process(innerType, ctx, params);
|
|
639
|
+
const seen = ctx.seen.get(schema);
|
|
640
|
+
seen.ref = innerType;
|
|
641
|
+
};
|
|
642
|
+
export const readonlyProcessor = (schema, ctx, json, params) => {
|
|
643
|
+
const def = schema._zod.def;
|
|
644
|
+
process(def.innerType, ctx, params);
|
|
645
|
+
const seen = ctx.seen.get(schema);
|
|
646
|
+
seen.ref = def.innerType;
|
|
647
|
+
json.readOnly = true;
|
|
648
|
+
};
|
|
649
|
+
export const promiseProcessor = (schema, ctx, _json, params) => {
|
|
650
|
+
const def = schema._zod.def;
|
|
651
|
+
process(def.innerType, ctx, params);
|
|
652
|
+
const seen = ctx.seen.get(schema);
|
|
653
|
+
seen.ref = def.innerType;
|
|
654
|
+
};
|
|
655
|
+
export const optionalProcessor = (schema, ctx, _json, params) => {
|
|
656
|
+
const def = schema._zod.def;
|
|
657
|
+
process(def.innerType, ctx, params);
|
|
658
|
+
const seen = ctx.seen.get(schema);
|
|
659
|
+
seen.ref = def.innerType;
|
|
660
|
+
};
|
|
661
|
+
export const lazyProcessor = (schema, ctx, _json, params) => {
|
|
662
|
+
const innerType = schema._zod.innerType;
|
|
663
|
+
process(innerType, ctx, params);
|
|
664
|
+
const seen = ctx.seen.get(schema);
|
|
665
|
+
seen.ref = innerType;
|
|
666
|
+
};
|
|
667
|
+
// ==================== ALL PROCESSORS ====================
|
|
668
|
+
export const allProcessors = {
|
|
669
|
+
string: stringProcessor,
|
|
670
|
+
number: numberProcessor,
|
|
671
|
+
boolean: booleanProcessor,
|
|
672
|
+
bigint: bigintProcessor,
|
|
673
|
+
symbol: symbolProcessor,
|
|
674
|
+
null: nullProcessor,
|
|
675
|
+
undefined: undefinedProcessor,
|
|
676
|
+
void: voidProcessor,
|
|
677
|
+
never: neverProcessor,
|
|
678
|
+
any: anyProcessor,
|
|
679
|
+
unknown: unknownProcessor,
|
|
680
|
+
date: dateProcessor,
|
|
681
|
+
enum: enumProcessor,
|
|
682
|
+
literal: literalProcessor,
|
|
683
|
+
nan: nanProcessor,
|
|
684
|
+
template_literal: templateLiteralProcessor,
|
|
685
|
+
file: fileProcessor,
|
|
686
|
+
success: successProcessor,
|
|
687
|
+
custom: customProcessor,
|
|
688
|
+
function: functionProcessor,
|
|
689
|
+
transform: transformProcessor,
|
|
690
|
+
map: mapProcessor,
|
|
691
|
+
set: setProcessor,
|
|
692
|
+
array: arrayProcessor,
|
|
693
|
+
object: objectProcessor,
|
|
694
|
+
union: unionProcessor,
|
|
695
|
+
intersection: intersectionProcessor,
|
|
696
|
+
tuple: tupleProcessor,
|
|
697
|
+
record: recordProcessor,
|
|
698
|
+
nullable: nullableProcessor,
|
|
699
|
+
nonoptional: nonoptionalProcessor,
|
|
700
|
+
default: defaultProcessor,
|
|
701
|
+
prefault: prefaultProcessor,
|
|
702
|
+
catch: catchProcessor,
|
|
703
|
+
pipe: pipeProcessor,
|
|
704
|
+
readonly: readonlyProcessor,
|
|
705
|
+
promise: promiseProcessor,
|
|
706
|
+
optional: optionalProcessor,
|
|
707
|
+
lazy: lazyProcessor,
|
|
708
|
+
};
|
|
709
|
+
export function toJSONSchema(input, params) {
|
|
710
|
+
if ("_idmap" in input) {
|
|
711
|
+
// Registry case
|
|
712
|
+
const registry = input;
|
|
713
|
+
const ctx = initializeContext({ ...params, processors: allProcessors });
|
|
714
|
+
const defs = {};
|
|
715
|
+
// First pass: process all schemas to build the seen map
|
|
716
|
+
for (const entry of registry._idmap.entries()) {
|
|
717
|
+
const [_, schema] = entry;
|
|
718
|
+
process(schema, ctx);
|
|
719
|
+
}
|
|
720
|
+
const schemas = {};
|
|
721
|
+
const external = {
|
|
722
|
+
registry,
|
|
723
|
+
uri: params?.uri,
|
|
724
|
+
defs,
|
|
725
|
+
};
|
|
726
|
+
// Update the context with external configuration
|
|
727
|
+
ctx.external = external;
|
|
728
|
+
// Second pass: emit each schema
|
|
729
|
+
for (const entry of registry._idmap.entries()) {
|
|
730
|
+
const [key, schema] = entry;
|
|
731
|
+
extractDefs(ctx, schema);
|
|
732
|
+
assignProp(schemas, key, finalize(ctx, schema));
|
|
733
|
+
}
|
|
734
|
+
if (Object.keys(defs).length > 0) {
|
|
735
|
+
const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
736
|
+
schemas.__shared = {
|
|
737
|
+
[defsSegment]: defs,
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
return { schemas };
|
|
741
|
+
}
|
|
742
|
+
// Single schema case
|
|
743
|
+
const ctx = initializeContext({ ...params, processors: allProcessors });
|
|
744
|
+
process(input, ctx);
|
|
745
|
+
extractDefs(ctx, input);
|
|
746
|
+
return finalize(ctx, input);
|
|
747
|
+
}
|