@es-joy/jsoe 0.24.3 → 0.25.1
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.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 +399 -54
- 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,846 @@
|
|
|
1
|
+
import { globalConfig } from "./core.js";
|
|
2
|
+
// functions
|
|
3
|
+
export function assertEqual(val) {
|
|
4
|
+
return val;
|
|
5
|
+
}
|
|
6
|
+
export function assertNotEqual(val) {
|
|
7
|
+
return val;
|
|
8
|
+
}
|
|
9
|
+
export function toZod() {
|
|
10
|
+
return (schema) => schema;
|
|
11
|
+
}
|
|
12
|
+
export function assertIs(_arg) { }
|
|
13
|
+
export function assertNever(_x) {
|
|
14
|
+
throw new Error("Unexpected value in exhaustive check");
|
|
15
|
+
}
|
|
16
|
+
export function assert(_) { }
|
|
17
|
+
export function getEnumValues(entries) {
|
|
18
|
+
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
19
|
+
const values = Object.entries(entries)
|
|
20
|
+
.filter(([k, _]) => numericValues.indexOf(+k) === -1)
|
|
21
|
+
.map(([_, v]) => v);
|
|
22
|
+
return values;
|
|
23
|
+
}
|
|
24
|
+
export function joinValues(array, separator = "|") {
|
|
25
|
+
return array.map((val) => stringifyPrimitive(val)).join(separator);
|
|
26
|
+
}
|
|
27
|
+
export function jsonStringifyReplacer(_, value) {
|
|
28
|
+
if (typeof value === "bigint")
|
|
29
|
+
return value.toString();
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
export function cached(getter) {
|
|
33
|
+
const set = false;
|
|
34
|
+
return {
|
|
35
|
+
get value() {
|
|
36
|
+
if (!set) {
|
|
37
|
+
const value = getter();
|
|
38
|
+
Object.defineProperty(this, "value", { value });
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
throw new Error("cached value already set");
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function nullish(input) {
|
|
46
|
+
return input === null || input === undefined;
|
|
47
|
+
}
|
|
48
|
+
export function cleanRegex(source) {
|
|
49
|
+
const start = source.startsWith("^") ? 1 : 0;
|
|
50
|
+
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
51
|
+
return source.slice(start, end);
|
|
52
|
+
}
|
|
53
|
+
export function floatSafeRemainder(val, step) {
|
|
54
|
+
const ratio = val / step;
|
|
55
|
+
const roundedRatio = Math.round(ratio);
|
|
56
|
+
// `val` and `step` each round to a double before the division rounds again, so a true decimal multiple's quotient can sit up to 1.5 of these scaled epsilons from the integer. A 1x tolerance therefore rejected 2.03 as a multiple of 0.07; 4x covers the worst case with margin.
|
|
57
|
+
const tolerance = 4 * Number.EPSILON * Math.max(Math.abs(ratio), 1);
|
|
58
|
+
if (Math.abs(ratio - roundedRatio) < tolerance)
|
|
59
|
+
return 0;
|
|
60
|
+
return ratio - roundedRatio;
|
|
61
|
+
}
|
|
62
|
+
const EVALUATING = /* @__PURE__*/ Symbol("evaluating");
|
|
63
|
+
export function defineLazy(object, key, getter) {
|
|
64
|
+
let value = undefined;
|
|
65
|
+
Object.defineProperty(object, key, {
|
|
66
|
+
get() {
|
|
67
|
+
if (value === EVALUATING) {
|
|
68
|
+
// Circular reference detected, return undefined to break the cycle
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
if (value === undefined) {
|
|
72
|
+
value = EVALUATING;
|
|
73
|
+
value = getter();
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
},
|
|
77
|
+
set(v) {
|
|
78
|
+
Object.defineProperty(object, key, {
|
|
79
|
+
value: v,
|
|
80
|
+
// configurable: true,
|
|
81
|
+
});
|
|
82
|
+
// object[key] = v;
|
|
83
|
+
},
|
|
84
|
+
configurable: true,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export function objectClone(obj) {
|
|
88
|
+
return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
|
|
89
|
+
}
|
|
90
|
+
export function assignProp(target, prop, value) {
|
|
91
|
+
Object.defineProperty(target, prop, {
|
|
92
|
+
value,
|
|
93
|
+
writable: true,
|
|
94
|
+
enumerable: true,
|
|
95
|
+
configurable: true,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
export function mergeDefs(...defs) {
|
|
99
|
+
const mergedDescriptors = {};
|
|
100
|
+
for (const def of defs) {
|
|
101
|
+
const descriptors = Object.getOwnPropertyDescriptors(def);
|
|
102
|
+
Object.assign(mergedDescriptors, descriptors);
|
|
103
|
+
}
|
|
104
|
+
return Object.defineProperties({}, mergedDescriptors);
|
|
105
|
+
}
|
|
106
|
+
export function cloneDef(schema) {
|
|
107
|
+
return mergeDefs(schema._zod.def);
|
|
108
|
+
}
|
|
109
|
+
export function getElementAtPath(obj, path) {
|
|
110
|
+
if (!path)
|
|
111
|
+
return obj;
|
|
112
|
+
return path.reduce((acc, key) => acc?.[key], obj);
|
|
113
|
+
}
|
|
114
|
+
export function promiseAllObject(promisesObj) {
|
|
115
|
+
const keys = Object.keys(promisesObj);
|
|
116
|
+
const promises = keys.map((key) => promisesObj[key]);
|
|
117
|
+
return Promise.all(promises).then((results) => {
|
|
118
|
+
const resolvedObj = {};
|
|
119
|
+
for (let i = 0; i < keys.length; i++) {
|
|
120
|
+
resolvedObj[keys[i]] = results[i];
|
|
121
|
+
}
|
|
122
|
+
return resolvedObj;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
export function randomString(length = 10) {
|
|
126
|
+
const chars = "abcdefghijklmnopqrstuvwxyz";
|
|
127
|
+
let str = "";
|
|
128
|
+
for (let i = 0; i < length; i++) {
|
|
129
|
+
str += chars[Math.floor(Math.random() * chars.length)];
|
|
130
|
+
}
|
|
131
|
+
return str;
|
|
132
|
+
}
|
|
133
|
+
export function esc(str) {
|
|
134
|
+
return JSON.stringify(str);
|
|
135
|
+
}
|
|
136
|
+
export function slugify(input) {
|
|
137
|
+
return input
|
|
138
|
+
.toLowerCase()
|
|
139
|
+
.trim()
|
|
140
|
+
.replace(/[^\w\s-]/g, "")
|
|
141
|
+
.replace(/[\s_-]+/g, "-")
|
|
142
|
+
.replace(/^-+|-+$/g, "");
|
|
143
|
+
}
|
|
144
|
+
export const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
|
|
145
|
+
export function isObject(data) {
|
|
146
|
+
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
147
|
+
}
|
|
148
|
+
export const allowsEval = /* @__PURE__*/ cached(() => {
|
|
149
|
+
// Skip the probe under `jitless`: strict CSPs report the caught `new Function` as a `securitypolicyviolation` even though the throw is swallowed.
|
|
150
|
+
if (globalConfig.jitless) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const F = Function;
|
|
159
|
+
new F("");
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
catch (_) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
export function isPlainObject(o) {
|
|
167
|
+
if (isObject(o) === false)
|
|
168
|
+
return false;
|
|
169
|
+
// modified constructor
|
|
170
|
+
const ctor = o.constructor;
|
|
171
|
+
if (ctor === undefined)
|
|
172
|
+
return true;
|
|
173
|
+
if (typeof ctor !== "function")
|
|
174
|
+
return true;
|
|
175
|
+
// modified prototype
|
|
176
|
+
const prot = ctor.prototype;
|
|
177
|
+
if (isObject(prot) === false)
|
|
178
|
+
return false;
|
|
179
|
+
// ctor doesn't have static `isPrototypeOf`
|
|
180
|
+
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
export function shallowClone(o) {
|
|
186
|
+
if (isPlainObject(o))
|
|
187
|
+
return { ...o };
|
|
188
|
+
if (Array.isArray(o))
|
|
189
|
+
return [...o];
|
|
190
|
+
if (o instanceof Map)
|
|
191
|
+
return new Map(o);
|
|
192
|
+
if (o instanceof Set)
|
|
193
|
+
return new Set(o);
|
|
194
|
+
return o;
|
|
195
|
+
}
|
|
196
|
+
export function numKeys(data) {
|
|
197
|
+
let keyCount = 0;
|
|
198
|
+
for (const key in data) {
|
|
199
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
200
|
+
keyCount++;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return keyCount;
|
|
204
|
+
}
|
|
205
|
+
export const getParsedType = (data) => {
|
|
206
|
+
const t = typeof data;
|
|
207
|
+
switch (t) {
|
|
208
|
+
case "undefined":
|
|
209
|
+
return "undefined";
|
|
210
|
+
case "string":
|
|
211
|
+
return "string";
|
|
212
|
+
case "number":
|
|
213
|
+
return Number.isNaN(data) ? "nan" : "number";
|
|
214
|
+
case "boolean":
|
|
215
|
+
return "boolean";
|
|
216
|
+
case "function":
|
|
217
|
+
return "function";
|
|
218
|
+
case "bigint":
|
|
219
|
+
return "bigint";
|
|
220
|
+
case "symbol":
|
|
221
|
+
return "symbol";
|
|
222
|
+
case "object":
|
|
223
|
+
if (Array.isArray(data)) {
|
|
224
|
+
return "array";
|
|
225
|
+
}
|
|
226
|
+
if (data === null) {
|
|
227
|
+
return "null";
|
|
228
|
+
}
|
|
229
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
230
|
+
return "promise";
|
|
231
|
+
}
|
|
232
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
233
|
+
return "map";
|
|
234
|
+
}
|
|
235
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
236
|
+
return "set";
|
|
237
|
+
}
|
|
238
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
239
|
+
return "date";
|
|
240
|
+
}
|
|
241
|
+
// @ts-ignore
|
|
242
|
+
if (typeof File !== "undefined" && data instanceof File) {
|
|
243
|
+
return "file";
|
|
244
|
+
}
|
|
245
|
+
return "object";
|
|
246
|
+
default:
|
|
247
|
+
throw new Error(`Unknown data type: ${t}`);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
export const propertyKeyTypes = /* @__PURE__*/ new Set(["string", "number", "symbol"]);
|
|
251
|
+
export const primitiveTypes = /* @__PURE__*/ new Set([
|
|
252
|
+
"string",
|
|
253
|
+
"number",
|
|
254
|
+
"bigint",
|
|
255
|
+
"boolean",
|
|
256
|
+
"symbol",
|
|
257
|
+
"undefined",
|
|
258
|
+
]);
|
|
259
|
+
export function escapeRegex(str) {
|
|
260
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
261
|
+
}
|
|
262
|
+
// zod-specific utils
|
|
263
|
+
export function clone(inst, def, params) {
|
|
264
|
+
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
265
|
+
if (!def || params?.parent)
|
|
266
|
+
cl._zod.parent = inst;
|
|
267
|
+
return cl;
|
|
268
|
+
}
|
|
269
|
+
export function normalizeParams(_params) {
|
|
270
|
+
const params = _params;
|
|
271
|
+
if (!params)
|
|
272
|
+
return {};
|
|
273
|
+
if (typeof params === "string")
|
|
274
|
+
return { error: () => params };
|
|
275
|
+
if (params?.message !== undefined) {
|
|
276
|
+
if (params?.error !== undefined)
|
|
277
|
+
throw new Error("Cannot specify both `message` and `error` params");
|
|
278
|
+
params.error = params.message;
|
|
279
|
+
}
|
|
280
|
+
delete params.message;
|
|
281
|
+
if (typeof params.error === "string")
|
|
282
|
+
return { ...params, error: () => params.error };
|
|
283
|
+
return params;
|
|
284
|
+
}
|
|
285
|
+
export function createTransparentProxy(getter) {
|
|
286
|
+
let target;
|
|
287
|
+
return new Proxy({}, {
|
|
288
|
+
get(_, prop, receiver) {
|
|
289
|
+
target ?? (target = getter());
|
|
290
|
+
return Reflect.get(target, prop, receiver);
|
|
291
|
+
},
|
|
292
|
+
set(_, prop, value, receiver) {
|
|
293
|
+
target ?? (target = getter());
|
|
294
|
+
return Reflect.set(target, prop, value, receiver);
|
|
295
|
+
},
|
|
296
|
+
has(_, prop) {
|
|
297
|
+
target ?? (target = getter());
|
|
298
|
+
return Reflect.has(target, prop);
|
|
299
|
+
},
|
|
300
|
+
deleteProperty(_, prop) {
|
|
301
|
+
target ?? (target = getter());
|
|
302
|
+
return Reflect.deleteProperty(target, prop);
|
|
303
|
+
},
|
|
304
|
+
ownKeys(_) {
|
|
305
|
+
target ?? (target = getter());
|
|
306
|
+
return Reflect.ownKeys(target);
|
|
307
|
+
},
|
|
308
|
+
getOwnPropertyDescriptor(_, prop) {
|
|
309
|
+
target ?? (target = getter());
|
|
310
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
311
|
+
},
|
|
312
|
+
defineProperty(_, prop, descriptor) {
|
|
313
|
+
target ?? (target = getter());
|
|
314
|
+
return Reflect.defineProperty(target, prop, descriptor);
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
export function stringifyPrimitive(value) {
|
|
319
|
+
if (typeof value === "bigint")
|
|
320
|
+
return value.toString() + "n";
|
|
321
|
+
if (typeof value === "string")
|
|
322
|
+
return `"${value}"`;
|
|
323
|
+
return `${value}`;
|
|
324
|
+
}
|
|
325
|
+
export function optionalKeys(shape) {
|
|
326
|
+
return Object.keys(shape).filter((k) => {
|
|
327
|
+
return shape[k]._zod.optin !== undefined && shape[k]._zod.optout === "optional";
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
// Wrapped in a `@__PURE__` IIFE: esbuild never tree-shakes a top-level initializer that contains a member access on `Number`, so the bare object literal survived into every bundle.
|
|
331
|
+
export const NUMBER_FORMAT_RANGES = /*@__PURE__*/ (() => ({
|
|
332
|
+
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
|
|
333
|
+
int32: [-2147483648, 2147483647],
|
|
334
|
+
uint32: [0, 4294967295],
|
|
335
|
+
float32: [-3.4028234663852886e38, 3.4028234663852886e38],
|
|
336
|
+
float64: [-Number.MAX_VALUE, Number.MAX_VALUE],
|
|
337
|
+
}))();
|
|
338
|
+
export const BIGINT_FORMAT_RANGES = {
|
|
339
|
+
int64: [/* @__PURE__*/ BigInt("-9223372036854775808"), /* @__PURE__*/ BigInt("9223372036854775807")],
|
|
340
|
+
uint64: [/* @__PURE__*/ BigInt(0), /* @__PURE__*/ BigInt("18446744073709551615")],
|
|
341
|
+
};
|
|
342
|
+
export function pick(schema, mask) {
|
|
343
|
+
const currDef = schema._zod.def;
|
|
344
|
+
const checks = currDef.checks;
|
|
345
|
+
const hasChecks = checks && checks.length > 0;
|
|
346
|
+
if (hasChecks) {
|
|
347
|
+
throw new Error(".pick() cannot be used on object schemas containing refinements");
|
|
348
|
+
}
|
|
349
|
+
const def = mergeDefs(schema._zod.def, {
|
|
350
|
+
get shape() {
|
|
351
|
+
const newShape = {};
|
|
352
|
+
// `for...in` skips symbols, so a symbol in the mask would select nothing
|
|
353
|
+
for (const key of Reflect.ownKeys(mask)) {
|
|
354
|
+
if (!Object.prototype.hasOwnProperty.call(currDef.shape, key)) {
|
|
355
|
+
throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
356
|
+
}
|
|
357
|
+
if (!mask[key])
|
|
358
|
+
continue;
|
|
359
|
+
assignProp(newShape, key, currDef.shape[key]);
|
|
360
|
+
}
|
|
361
|
+
assignProp(this, "shape", newShape); // self-caching
|
|
362
|
+
return newShape;
|
|
363
|
+
},
|
|
364
|
+
checks: [],
|
|
365
|
+
});
|
|
366
|
+
return clone(schema, def);
|
|
367
|
+
}
|
|
368
|
+
export function omit(schema, mask) {
|
|
369
|
+
const currDef = schema._zod.def;
|
|
370
|
+
const checks = currDef.checks;
|
|
371
|
+
const hasChecks = checks && checks.length > 0;
|
|
372
|
+
if (hasChecks) {
|
|
373
|
+
throw new Error(".omit() cannot be used on object schemas containing refinements");
|
|
374
|
+
}
|
|
375
|
+
const def = mergeDefs(schema._zod.def, {
|
|
376
|
+
get shape() {
|
|
377
|
+
const newShape = { ...schema._zod.def.shape };
|
|
378
|
+
for (const key of Reflect.ownKeys(mask)) {
|
|
379
|
+
if (!Object.prototype.hasOwnProperty.call(currDef.shape, key)) {
|
|
380
|
+
throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
381
|
+
}
|
|
382
|
+
if (!mask[key])
|
|
383
|
+
continue;
|
|
384
|
+
delete newShape[key];
|
|
385
|
+
}
|
|
386
|
+
assignProp(this, "shape", newShape); // self-caching
|
|
387
|
+
return newShape;
|
|
388
|
+
},
|
|
389
|
+
checks: [],
|
|
390
|
+
});
|
|
391
|
+
return clone(schema, def);
|
|
392
|
+
}
|
|
393
|
+
export function extend(schema, shape) {
|
|
394
|
+
if (!isPlainObject(shape)) {
|
|
395
|
+
throw new Error("Invalid input to extend: expected a plain object");
|
|
396
|
+
}
|
|
397
|
+
const checks = schema._zod.def.checks;
|
|
398
|
+
const hasChecks = checks && checks.length > 0;
|
|
399
|
+
if (hasChecks) {
|
|
400
|
+
// Only throw if new shape overlaps with existing shape. Use getOwnPropertyDescriptor to check key existence without accessing values
|
|
401
|
+
const existingShape = schema._zod.def.shape;
|
|
402
|
+
for (const key of Reflect.ownKeys(shape)) {
|
|
403
|
+
if (Object.getOwnPropertyDescriptor(existingShape, key) !== undefined) {
|
|
404
|
+
throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const def = mergeDefs(schema._zod.def, {
|
|
409
|
+
get shape() {
|
|
410
|
+
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
411
|
+
assignProp(this, "shape", _shape); // self-caching
|
|
412
|
+
return _shape;
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
return clone(schema, def);
|
|
416
|
+
}
|
|
417
|
+
export function safeExtend(schema, shape) {
|
|
418
|
+
if (!isPlainObject(shape)) {
|
|
419
|
+
throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
420
|
+
}
|
|
421
|
+
const def = mergeDefs(schema._zod.def, {
|
|
422
|
+
get shape() {
|
|
423
|
+
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
424
|
+
assignProp(this, "shape", _shape); // self-caching
|
|
425
|
+
return _shape;
|
|
426
|
+
},
|
|
427
|
+
});
|
|
428
|
+
return clone(schema, def);
|
|
429
|
+
}
|
|
430
|
+
export function merge(a, b) {
|
|
431
|
+
if (!b?._zod?.def) {
|
|
432
|
+
throw new Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");
|
|
433
|
+
}
|
|
434
|
+
if (a._zod.def.checks?.length) {
|
|
435
|
+
throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");
|
|
436
|
+
}
|
|
437
|
+
const def = mergeDefs(a._zod.def, {
|
|
438
|
+
get shape() {
|
|
439
|
+
const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
|
|
440
|
+
assignProp(this, "shape", _shape); // self-caching
|
|
441
|
+
return _shape;
|
|
442
|
+
},
|
|
443
|
+
get catchall() {
|
|
444
|
+
return b._zod.def.catchall;
|
|
445
|
+
},
|
|
446
|
+
checks: b._zod.def.checks ?? [],
|
|
447
|
+
});
|
|
448
|
+
return clone(a, def);
|
|
449
|
+
}
|
|
450
|
+
export function partial(Class, schema, mask, name = "partial") {
|
|
451
|
+
const currDef = schema._zod.def;
|
|
452
|
+
const checks = currDef.checks;
|
|
453
|
+
const hasChecks = checks && checks.length > 0;
|
|
454
|
+
if (hasChecks) {
|
|
455
|
+
throw new Error(`.${name}() cannot be used on object schemas containing refinements`);
|
|
456
|
+
}
|
|
457
|
+
const def = mergeDefs(schema._zod.def, {
|
|
458
|
+
get shape() {
|
|
459
|
+
const oldShape = schema._zod.def.shape;
|
|
460
|
+
const shape = { ...oldShape };
|
|
461
|
+
if (mask) {
|
|
462
|
+
for (const key of Reflect.ownKeys(mask)) {
|
|
463
|
+
if (!Object.prototype.hasOwnProperty.call(oldShape, key)) {
|
|
464
|
+
throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
465
|
+
}
|
|
466
|
+
if (!mask[key])
|
|
467
|
+
continue;
|
|
468
|
+
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
469
|
+
shape[key] = Class
|
|
470
|
+
? new Class({
|
|
471
|
+
type: "optional",
|
|
472
|
+
innerType: oldShape[key],
|
|
473
|
+
})
|
|
474
|
+
: oldShape[key];
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
// the spread copies symbol keys; `for...in` would not reach them
|
|
479
|
+
for (const key of Reflect.ownKeys(oldShape)) {
|
|
480
|
+
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
481
|
+
shape[key] = Class
|
|
482
|
+
? new Class({
|
|
483
|
+
type: "optional",
|
|
484
|
+
innerType: oldShape[key],
|
|
485
|
+
})
|
|
486
|
+
: oldShape[key];
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
assignProp(this, "shape", shape); // self-caching
|
|
490
|
+
return shape;
|
|
491
|
+
},
|
|
492
|
+
checks: [],
|
|
493
|
+
});
|
|
494
|
+
return clone(schema, def);
|
|
495
|
+
}
|
|
496
|
+
export function required(Class, schema, mask) {
|
|
497
|
+
const def = mergeDefs(schema._zod.def, {
|
|
498
|
+
get shape() {
|
|
499
|
+
const oldShape = schema._zod.def.shape;
|
|
500
|
+
const shape = { ...oldShape };
|
|
501
|
+
if (mask) {
|
|
502
|
+
for (const key of Reflect.ownKeys(mask)) {
|
|
503
|
+
if (!Object.prototype.hasOwnProperty.call(shape, key)) {
|
|
504
|
+
throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
505
|
+
}
|
|
506
|
+
if (!mask[key])
|
|
507
|
+
continue;
|
|
508
|
+
// overwrite with non-optional
|
|
509
|
+
shape[key] = new Class({
|
|
510
|
+
type: "nonoptional",
|
|
511
|
+
innerType: oldShape[key],
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
for (const key of Reflect.ownKeys(oldShape)) {
|
|
517
|
+
// overwrite with non-optional
|
|
518
|
+
shape[key] = new Class({
|
|
519
|
+
type: "nonoptional",
|
|
520
|
+
innerType: oldShape[key],
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
assignProp(this, "shape", shape); // self-caching
|
|
525
|
+
return shape;
|
|
526
|
+
},
|
|
527
|
+
});
|
|
528
|
+
return clone(schema, def);
|
|
529
|
+
}
|
|
530
|
+
// invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
|
|
531
|
+
export function aborted(x, startIndex = 0) {
|
|
532
|
+
if (x.aborted === true)
|
|
533
|
+
return true;
|
|
534
|
+
for (let i = startIndex; i < x.issues.length; i++) {
|
|
535
|
+
if (x.issues[i]?.continue !== true) {
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
// Checks for explicit abort (continue === false), as opposed to implicit abort (continue === undefined). Used to respect `abort: true` in .refine() even for checks that have a `when` function.
|
|
542
|
+
export function explicitlyAborted(x, startIndex = 0) {
|
|
543
|
+
if (x.aborted === true)
|
|
544
|
+
return true;
|
|
545
|
+
for (let i = startIndex; i < x.issues.length; i++) {
|
|
546
|
+
if (x.issues[i]?.continue === false) {
|
|
547
|
+
return true;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
export function prefixIssues(path, issues) {
|
|
553
|
+
return issues.map((iss) => {
|
|
554
|
+
var _a;
|
|
555
|
+
(_a = iss).path ?? (_a.path = []);
|
|
556
|
+
iss.path.unshift(path);
|
|
557
|
+
return iss;
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
export function unwrapMessage(message) {
|
|
561
|
+
return typeof message === "string" ? message : message?.message;
|
|
562
|
+
}
|
|
563
|
+
/* A check holds no link back to the schema it is attached to — the same check instance is shared by every clone of that schema — so the owner is stamped onto the issues a check just raised, at the only point where both are in scope. Runs on the failure path only; `start` is the issue count from before the check ran. */
|
|
564
|
+
export function attachSchema(issues, start, inst) {
|
|
565
|
+
var _a;
|
|
566
|
+
for (let i = start; i < issues.length; i++) {
|
|
567
|
+
(_a = issues[i]).schema ?? (_a.schema = inst);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
export function finalizeIssue(iss, ctx, config) {
|
|
571
|
+
var _a;
|
|
572
|
+
// A schema that raised an issue itself owns it outright, and outranks any stamp an enclosing check left in `attachSchema`. String formats and z.custom() are schema and check at once, so when they act as a check they defer to that stamp instead.
|
|
573
|
+
const traits = iss.inst?._zod?.traits;
|
|
574
|
+
if (traits?.has("$ZodType")) {
|
|
575
|
+
if (traits.has("$ZodCheck"))
|
|
576
|
+
(_a = iss).schema ?? (_a.schema = iss.inst);
|
|
577
|
+
else
|
|
578
|
+
iss.schema = iss.inst;
|
|
579
|
+
}
|
|
580
|
+
// Decreasing specificity, first map to return a message wins. `inst` is whatever raised the issue, so a check's own map outranks the owning schema's.
|
|
581
|
+
const schemaError = iss.schema !== iss.inst ? iss.schema?._zod.def?.error : undefined;
|
|
582
|
+
const message = iss.message
|
|
583
|
+
? iss.message
|
|
584
|
+
: (unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ??
|
|
585
|
+
unwrapMessage(schemaError?.(iss)) ??
|
|
586
|
+
unwrapMessage(ctx?.error?.(iss)) ??
|
|
587
|
+
unwrapMessage(config.customError?.(iss)) ??
|
|
588
|
+
unwrapMessage(config.localeError?.(iss)) ??
|
|
589
|
+
"Invalid input");
|
|
590
|
+
const { inst: _inst, schema: _schema, continue: _continue, input: _input, ...rest } = iss;
|
|
591
|
+
rest.path ?? (rest.path = []);
|
|
592
|
+
rest.message = message;
|
|
593
|
+
if (ctx?.reportInput) {
|
|
594
|
+
rest.input = _input;
|
|
595
|
+
}
|
|
596
|
+
return rest;
|
|
597
|
+
}
|
|
598
|
+
export function getSizableOrigin(input) {
|
|
599
|
+
if (input instanceof Set)
|
|
600
|
+
return "set";
|
|
601
|
+
if (input instanceof Map)
|
|
602
|
+
return "map";
|
|
603
|
+
// @ts-ignore
|
|
604
|
+
if (input instanceof File)
|
|
605
|
+
return "file";
|
|
606
|
+
return "unknown";
|
|
607
|
+
}
|
|
608
|
+
const highSurrogate = /[\uD800-\uDBFF]/;
|
|
609
|
+
// Code points in `str`: a surrogate pair counts once, a lone surrogate as itself. Hand-rolled because the string iterator allocates and runs ~250x slower on this path; the regex probe exits ~50x quicker for a string with no astral characters.
|
|
610
|
+
export function codePointLength(str) {
|
|
611
|
+
const units = str.length;
|
|
612
|
+
if (!highSurrogate.test(str))
|
|
613
|
+
return units;
|
|
614
|
+
let count = units;
|
|
615
|
+
for (let i = 0; i < units - 1; i++) {
|
|
616
|
+
if ((str.charCodeAt(i) & 0xfc00) === 0xd800 && (str.charCodeAt(i + 1) & 0xfc00) === 0xdc00) {
|
|
617
|
+
count--;
|
|
618
|
+
i++;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return count;
|
|
622
|
+
}
|
|
623
|
+
export function getLengthableOrigin(input) {
|
|
624
|
+
if (Array.isArray(input))
|
|
625
|
+
return "array";
|
|
626
|
+
if (typeof input === "string")
|
|
627
|
+
return "string";
|
|
628
|
+
return "unknown";
|
|
629
|
+
}
|
|
630
|
+
export function parsedType(data) {
|
|
631
|
+
const t = typeof data;
|
|
632
|
+
switch (t) {
|
|
633
|
+
case "number": {
|
|
634
|
+
return Number.isNaN(data) ? "nan" : "number";
|
|
635
|
+
}
|
|
636
|
+
case "object": {
|
|
637
|
+
if (data === null) {
|
|
638
|
+
return "null";
|
|
639
|
+
}
|
|
640
|
+
if (Array.isArray(data)) {
|
|
641
|
+
return "array";
|
|
642
|
+
}
|
|
643
|
+
const obj = data;
|
|
644
|
+
if (obj && Object.getPrototypeOf(obj) !== Object.prototype && "constructor" in obj && obj.constructor) {
|
|
645
|
+
return obj.constructor.name;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
return t;
|
|
650
|
+
}
|
|
651
|
+
export function issue(...args) {
|
|
652
|
+
const [iss, input, inst] = args;
|
|
653
|
+
if (typeof iss === "string") {
|
|
654
|
+
return {
|
|
655
|
+
message: iss,
|
|
656
|
+
code: "custom",
|
|
657
|
+
input,
|
|
658
|
+
inst,
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
return { ...iss };
|
|
662
|
+
}
|
|
663
|
+
export function cleanEnum(obj) {
|
|
664
|
+
return Object.entries(obj)
|
|
665
|
+
.filter(([k, _]) => {
|
|
666
|
+
// return true if NaN, meaning it's not a number, thus a string key
|
|
667
|
+
return Number.isNaN(Number.parseInt(k, 10));
|
|
668
|
+
})
|
|
669
|
+
.map((el) => el[1]);
|
|
670
|
+
}
|
|
671
|
+
// Codec utility functions
|
|
672
|
+
export function base64ToUint8Array(base64) {
|
|
673
|
+
const binaryString = atob(base64);
|
|
674
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
675
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
676
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
677
|
+
}
|
|
678
|
+
return bytes;
|
|
679
|
+
}
|
|
680
|
+
export function uint8ArrayToBase64(bytes) {
|
|
681
|
+
let binaryString = "";
|
|
682
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
683
|
+
binaryString += String.fromCharCode(bytes[i]);
|
|
684
|
+
}
|
|
685
|
+
return btoa(binaryString);
|
|
686
|
+
}
|
|
687
|
+
export function base64urlToUint8Array(base64url) {
|
|
688
|
+
const base64 = base64url.replace(/-/g, "+").replace(/_/g, "/");
|
|
689
|
+
const padding = "=".repeat((4 - (base64.length % 4)) % 4);
|
|
690
|
+
return base64ToUint8Array(base64 + padding);
|
|
691
|
+
}
|
|
692
|
+
export function uint8ArrayToBase64url(bytes) {
|
|
693
|
+
return uint8ArrayToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
694
|
+
}
|
|
695
|
+
export function hexToUint8Array(hex) {
|
|
696
|
+
const cleanHex = hex.replace(/^0x/, "");
|
|
697
|
+
if (cleanHex.length % 2 !== 0) {
|
|
698
|
+
throw new Error("Invalid hex string length");
|
|
699
|
+
}
|
|
700
|
+
const bytes = new Uint8Array(cleanHex.length / 2);
|
|
701
|
+
for (let i = 0; i < cleanHex.length; i += 2) {
|
|
702
|
+
bytes[i / 2] = Number.parseInt(cleanHex.slice(i, i + 2), 16);
|
|
703
|
+
}
|
|
704
|
+
return bytes;
|
|
705
|
+
}
|
|
706
|
+
export function uint8ArrayToHex(bytes) {
|
|
707
|
+
return Array.from(bytes)
|
|
708
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
709
|
+
.join("");
|
|
710
|
+
}
|
|
711
|
+
// instanceof
|
|
712
|
+
export class Class {
|
|
713
|
+
constructor(..._args) { }
|
|
714
|
+
}
|
|
715
|
+
////////// PROTOTYPE INSTALLERS //////////
|
|
716
|
+
//
|
|
717
|
+
// Members live on the prototype and materialize per instance on first read, which keeps own-property count under the step where V8 stops using inline slots. Changing anything here means re-measuring runtime, memory and bundle size together — see "The three axes" in AGENTS.md.
|
|
718
|
+
/**
|
|
719
|
+
* Installs a trait's members on its prototype. Each value builds that member for the instance on first read; the built value shadows the accessor as an own property, so a detached `const { parse } = schema` keeps working.
|
|
720
|
+
*
|
|
721
|
+
* Call this from a `proto` initializer, which runs once per prototype — never per instance.
|
|
722
|
+
*/
|
|
723
|
+
export function members(proto, table) {
|
|
724
|
+
for (const key in table) {
|
|
725
|
+
const desc = Object.getOwnPropertyDescriptor(table, key);
|
|
726
|
+
// a getter installs as written, so it stays live: `description` reads through to the registry on every access. not enumerable: an object literal's is, and a prototype member never was
|
|
727
|
+
if (desc.get)
|
|
728
|
+
Object.defineProperty(proto, key, { ...desc, enumerable: false });
|
|
729
|
+
// a method materializes bound on first read, which is what keeps a detached member working: `const opt = schema.optional; opt()`
|
|
730
|
+
else
|
|
731
|
+
defineBound(proto, key, desc.value);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
/** Shadows a prototype member with an own value, so a getter that builds from the instance runs once. */
|
|
735
|
+
export function own(inst, key, value, enumerable = true) {
|
|
736
|
+
Object.defineProperty(inst, key, { configurable: true, writable: true, enumerable, value });
|
|
737
|
+
return value;
|
|
738
|
+
}
|
|
739
|
+
/** Like {@link own}, for a member that was never an own data property and has to stay out of `Object.keys`. */
|
|
740
|
+
export function hide(inst, key, value) {
|
|
741
|
+
return own(inst, key, value, false);
|
|
742
|
+
}
|
|
743
|
+
function defineBound(proto, key, fn) {
|
|
744
|
+
Object.defineProperty(proto, key, {
|
|
745
|
+
configurable: true,
|
|
746
|
+
get() {
|
|
747
|
+
// vitest's spyOn calls a prototype getter bare to find the function it wraps, so a nullish receiver answers the raw method
|
|
748
|
+
return this == null ? fn : own(this, key, fn.bind(this));
|
|
749
|
+
},
|
|
750
|
+
set(value) {
|
|
751
|
+
own(this, key, value);
|
|
752
|
+
},
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
/** Returns the prototype to install on, or `undefined` if this group is already installed on it. */
|
|
756
|
+
function claim(inst, sentinel) {
|
|
757
|
+
const proto = Object.getPrototypeOf(inst);
|
|
758
|
+
// Runs on every construction, so `in` rather than the costlier `hasOwnProperty.call`. Sentinels are keys the group itself defines.
|
|
759
|
+
return sentinel in proto ? undefined : proto;
|
|
760
|
+
}
|
|
761
|
+
// The internals whose init chain is installing. A second call for the same one is a derived constructor overriding its base, so it must not construct another schema in between or the override is dropped.
|
|
762
|
+
let installing;
|
|
763
|
+
// Set while a getter is running, so a value that resolved through a recursion break is not memoized. One shared descriptor shadows the key for the duration, which costs no per-key allocation.
|
|
764
|
+
let broke = false;
|
|
765
|
+
const breaker = {
|
|
766
|
+
configurable: true,
|
|
767
|
+
get() {
|
|
768
|
+
broke = true;
|
|
769
|
+
return undefined;
|
|
770
|
+
},
|
|
771
|
+
};
|
|
772
|
+
/**
|
|
773
|
+
* Installs a lazily-derived internal on the `_zod` prototype of `inst`'s
|
|
774
|
+
* constructor, computed from the internals object itself and cached there on
|
|
775
|
+
* first read. One accessor per constructor rather than one per instance.
|
|
776
|
+
*/
|
|
777
|
+
export function defineLazyInternal(inst, key, compute) {
|
|
778
|
+
const proto = Object.getPrototypeOf(inst._zod);
|
|
779
|
+
if (key in proto && installing !== inst._zod) {
|
|
780
|
+
// A repeat construction: everything is installed already. Cleared here so the reference is not held past the first construction of every type.
|
|
781
|
+
installing = undefined;
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
installing = inst._zod;
|
|
785
|
+
Object.defineProperty(proto, key, {
|
|
786
|
+
configurable: true,
|
|
787
|
+
get() {
|
|
788
|
+
// Shadowed before computing so a re-entrant read from a recursive schema resolves to undefined instead of running the getter again.
|
|
789
|
+
Object.defineProperty(this, key, breaker);
|
|
790
|
+
const outer = broke;
|
|
791
|
+
broke = false;
|
|
792
|
+
try {
|
|
793
|
+
const value = compute(this);
|
|
794
|
+
// A result that resolved through a recursion break is recomputed once the graph is complete; everything else memoizes, undefined included.
|
|
795
|
+
if (broke)
|
|
796
|
+
delete this[key];
|
|
797
|
+
else
|
|
798
|
+
Object.defineProperty(this, key, { configurable: true, writable: true, value });
|
|
799
|
+
broke = broke || outer;
|
|
800
|
+
return value;
|
|
801
|
+
}
|
|
802
|
+
catch (err) {
|
|
803
|
+
// A compute that threw memoizes nothing, so a later read runs it again and fails the same way. The shadow goes with it, since leaving it installed would answer undefined for every later read.
|
|
804
|
+
delete this[key];
|
|
805
|
+
broke = broke || outer;
|
|
806
|
+
throw err;
|
|
807
|
+
}
|
|
808
|
+
},
|
|
809
|
+
set(value) {
|
|
810
|
+
Object.defineProperty(this, key, { configurable: true, writable: true, value });
|
|
811
|
+
},
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Installs `key` on `inst`'s prototype, computed by `make` on first read and cached there as an own
|
|
816
|
+
* data property. One accessor per constructor rather than one per instance, because an own accessor
|
|
817
|
+
* puts every instance after the first into v8 dictionary mode. The key doubles as the sentinel.
|
|
818
|
+
*/
|
|
819
|
+
export function installLazyProp(inst, key, make, enumerable) {
|
|
820
|
+
const proto = claim(inst, key);
|
|
821
|
+
if (!proto)
|
|
822
|
+
return;
|
|
823
|
+
Object.defineProperty(proto, key, {
|
|
824
|
+
configurable: true,
|
|
825
|
+
get() {
|
|
826
|
+
// Shadowed before computing, so a re-entrant read from a self-referential shape resolves to undefined instead of running the getter again. A data property rather than an accessor: an own accessor is the dictionary-mode transition this exists to avoid.
|
|
827
|
+
const desc = { configurable: true, writable: true, enumerable, value: undefined };
|
|
828
|
+
Object.defineProperty(this, key, desc);
|
|
829
|
+
// a compute that throws leaves the shadow behind, so later reads answer undefined instead of re-throwing; `defineLazy` did the same, and `defineLazyInternal`'s delete-on-catch would cost bytes in every bundle for a case only a throwing user getter reaches
|
|
830
|
+
desc.value = make(this);
|
|
831
|
+
Object.defineProperty(this, key, desc);
|
|
832
|
+
return desc.value;
|
|
833
|
+
},
|
|
834
|
+
set(value) {
|
|
835
|
+
Object.defineProperty(this, key, { configurable: true, writable: true, enumerable, value });
|
|
836
|
+
},
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
/** Marks the thunk `_catch` synthesises for a constant catch value. `Function.length` cannot tell that thunk from a user callback — rest and defaulted parameters both report arity 0 — and a user callback reads `ctx.error`, whose issues only finalize correctly against the caller's per-parse error map. Provenance can say what arity cannot. A plain string key rather than `Symbol.for`, whose call at module scope no bundler can prove pure — the same shape that anchored `urlCanParse` into every build. */
|
|
840
|
+
export const CONSTANT_CATCH = "~constantCatch";
|
|
841
|
+
/** Wraps a constant catch value in a thunk tagged with {@link CONSTANT_CATCH}. */
|
|
842
|
+
export function constantCatch(value) {
|
|
843
|
+
const fn = () => value;
|
|
844
|
+
fn[CONSTANT_CATCH] = true;
|
|
845
|
+
return fn;
|
|
846
|
+
}
|