zod 4.0.0-beta.20250505T195954 → 4.0.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/README.md +208 -0
- package/index.cjs +33 -0
- package/index.d.cts +4 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/locales/index.cjs +17 -0
- package/locales/index.d.cts +1 -0
- package/locales/index.d.ts +1 -0
- package/locales/index.js +1 -0
- package/mini/index.cjs +17 -0
- package/mini/index.d.cts +1 -0
- package/mini/index.d.ts +1 -0
- package/mini/index.js +1 -0
- package/package.json +87 -40
- package/src/index.ts +2 -3
- package/src/locales/index.ts +1 -0
- package/src/mini/index.ts +1 -0
- package/src/v3/ZodError.ts +330 -0
- package/src/v3/benchmarks/datetime.ts +58 -0
- package/src/v3/benchmarks/discriminatedUnion.ts +80 -0
- package/src/v3/benchmarks/index.ts +59 -0
- package/src/v3/benchmarks/ipv4.ts +57 -0
- package/src/v3/benchmarks/object.ts +69 -0
- package/src/v3/benchmarks/primitives.ts +162 -0
- package/src/v3/benchmarks/realworld.ts +63 -0
- package/src/v3/benchmarks/string.ts +55 -0
- package/src/v3/benchmarks/union.ts +80 -0
- package/src/v3/errors.ts +13 -0
- package/src/v3/external.ts +6 -0
- package/src/v3/helpers/enumUtil.ts +17 -0
- package/src/v3/helpers/errorUtil.ts +8 -0
- package/src/v3/helpers/parseUtil.ts +176 -0
- package/src/v3/helpers/partialUtil.ts +34 -0
- package/src/v3/helpers/typeAliases.ts +2 -0
- package/src/v3/helpers/util.ts +224 -0
- package/src/v3/index.ts +4 -0
- package/src/v3/locales/en.ts +124 -0
- package/src/v3/standard-schema.ts +113 -0
- package/src/v3/tests/Mocker.ts +54 -0
- package/src/v3/tests/all-errors.test.ts +157 -0
- package/src/v3/tests/anyunknown.test.ts +28 -0
- package/src/v3/tests/array.test.ts +71 -0
- package/src/v3/tests/async-parsing.test.ts +388 -0
- package/src/v3/tests/async-refinements.test.ts +46 -0
- package/src/v3/tests/base.test.ts +29 -0
- package/src/v3/tests/bigint.test.ts +55 -0
- package/src/v3/tests/branded.test.ts +53 -0
- package/src/v3/tests/catch.test.ts +220 -0
- package/src/v3/tests/coerce.test.ts +133 -0
- package/src/v3/tests/complex.test.ts +56 -0
- package/src/v3/tests/custom.test.ts +31 -0
- package/src/v3/tests/date.test.ts +32 -0
- package/src/v3/tests/deepmasking.test.ts +186 -0
- package/src/v3/tests/default.test.ts +112 -0
- package/src/v3/tests/description.test.ts +33 -0
- package/src/v3/tests/discriminated-unions.test.ts +315 -0
- package/src/v3/tests/enum.test.ts +80 -0
- package/src/v3/tests/error.test.ts +551 -0
- package/src/v3/tests/firstparty.test.ts +87 -0
- package/src/v3/tests/firstpartyschematypes.test.ts +21 -0
- package/src/v3/tests/function.test.ts +257 -0
- package/src/v3/tests/generics.test.ts +48 -0
- package/src/v3/tests/instanceof.test.ts +37 -0
- package/src/v3/tests/intersection.test.ts +110 -0
- package/src/v3/tests/language-server.source.ts +76 -0
- package/src/v3/tests/language-server.test.ts +207 -0
- package/src/v3/tests/literal.test.ts +36 -0
- package/src/v3/tests/map.test.ts +110 -0
- package/src/v3/tests/masking.test.ts +4 -0
- package/src/v3/tests/mocker.test.ts +19 -0
- package/src/v3/tests/nan.test.ts +21 -0
- package/src/v3/tests/nativeEnum.test.ts +87 -0
- package/src/v3/tests/nullable.test.ts +42 -0
- package/src/v3/tests/number.test.ts +176 -0
- package/src/v3/tests/object-augmentation.test.ts +29 -0
- package/src/v3/tests/object-in-es5-env.test.ts +29 -0
- package/src/v3/tests/object.test.ts +434 -0
- package/src/v3/tests/optional.test.ts +42 -0
- package/src/v3/tests/parseUtil.test.ts +23 -0
- package/src/v3/tests/parser.test.ts +41 -0
- package/src/v3/tests/partials.test.ts +243 -0
- package/src/v3/tests/pickomit.test.ts +111 -0
- package/src/v3/tests/pipeline.test.ts +29 -0
- package/src/v3/tests/preprocess.test.ts +186 -0
- package/src/v3/tests/primitive.test.ts +440 -0
- package/src/v3/tests/promise.test.ts +90 -0
- package/src/v3/tests/readonly.test.ts +194 -0
- package/src/v3/tests/record.test.ts +171 -0
- package/src/v3/tests/recursive.test.ts +197 -0
- package/src/v3/tests/refine.test.ts +313 -0
- package/src/v3/tests/safeparse.test.ts +27 -0
- package/src/v3/tests/set.test.ts +142 -0
- package/src/v3/tests/standard-schema.test.ts +83 -0
- package/src/v3/tests/string.test.ts +916 -0
- package/src/v3/tests/transformer.test.ts +233 -0
- package/src/v3/tests/tuple.test.ts +90 -0
- package/src/v3/tests/unions.test.ts +57 -0
- package/src/v3/tests/validations.test.ts +133 -0
- package/src/v3/tests/void.test.ts +15 -0
- package/src/v3/types.ts +5136 -0
- package/src/{checks.ts → v4/classic/checks.ts} +1 -1
- package/src/v4/classic/coerce.ts +27 -0
- package/src/{compat.ts → v4/classic/compat.ts} +3 -13
- package/src/v4/classic/errors.ts +75 -0
- package/src/v4/classic/external.ts +50 -0
- package/src/v4/classic/index.ts +5 -0
- package/src/{iso.ts → v4/classic/iso.ts} +1 -1
- package/src/{parse.ts → v4/classic/parse.ts} +13 -12
- package/src/{schemas.ts → v4/classic/schemas.ts} +430 -417
- package/src/v4/classic/tests/anyunknown.test.ts +26 -0
- package/src/v4/classic/tests/array.test.ts +264 -0
- package/src/v4/classic/tests/assignability.test.ts +210 -0
- package/src/v4/classic/tests/async-parsing.test.ts +381 -0
- package/src/v4/classic/tests/async-refinements.test.ts +68 -0
- package/src/v4/classic/tests/base.test.ts +7 -0
- package/src/v4/classic/tests/bigint.test.ts +54 -0
- package/src/v4/classic/tests/brand.test.ts +63 -0
- package/src/v4/classic/tests/catch.test.ts +252 -0
- package/src/v4/classic/tests/coalesce.test.ts +20 -0
- package/src/v4/classic/tests/coerce.test.ts +160 -0
- package/src/v4/classic/tests/continuability.test.ts +352 -0
- package/src/v4/classic/tests/custom.test.ts +40 -0
- package/src/v4/classic/tests/date.test.ts +31 -0
- package/src/v4/classic/tests/datetime.test.ts +296 -0
- package/src/v4/classic/tests/default.test.ts +313 -0
- package/src/v4/classic/tests/description.test.ts +32 -0
- package/src/v4/classic/tests/discriminated-unions.test.ts +619 -0
- package/src/v4/classic/tests/enum.test.ts +285 -0
- package/src/v4/classic/tests/error-utils.test.ts +552 -0
- package/src/v4/classic/tests/error.test.ts +711 -0
- package/src/v4/classic/tests/file.test.ts +91 -0
- package/src/v4/classic/tests/firstparty.test.ts +175 -0
- package/src/v4/classic/tests/function.test.ts +268 -0
- package/src/v4/classic/tests/generics.test.ts +72 -0
- package/src/v4/classic/tests/index.test.ts +829 -0
- package/src/v4/classic/tests/instanceof.test.ts +34 -0
- package/src/v4/classic/tests/intersection.test.ts +171 -0
- package/src/v4/classic/tests/json.test.ts +108 -0
- package/src/v4/classic/tests/lazy.test.ts +227 -0
- package/src/v4/classic/tests/literal.test.ts +92 -0
- package/src/v4/classic/tests/map.test.ts +196 -0
- package/src/v4/classic/tests/nan.test.ts +21 -0
- package/src/v4/classic/tests/nested-refine.test.ts +168 -0
- package/src/v4/classic/tests/nonoptional.test.ts +86 -0
- package/src/v4/classic/tests/nullable.test.ts +22 -0
- package/src/v4/classic/tests/number.test.ts +247 -0
- package/src/v4/classic/tests/object.test.ts +563 -0
- package/src/v4/classic/tests/optional.test.ts +123 -0
- package/src/v4/classic/tests/partial.test.ts +147 -0
- package/src/v4/classic/tests/pickomit.test.ts +127 -0
- package/src/v4/classic/tests/pipe.test.ts +81 -0
- package/src/v4/classic/tests/prefault.test.ts +37 -0
- package/src/v4/classic/tests/preprocess.test.ts +298 -0
- package/src/v4/classic/tests/primitive.test.ts +175 -0
- package/src/v4/classic/tests/promise.test.ts +81 -0
- package/src/v4/classic/tests/prototypes.test.ts +23 -0
- package/src/v4/classic/tests/readonly.test.ts +252 -0
- package/src/v4/classic/tests/record.test.ts +342 -0
- package/src/v4/classic/tests/recursive-types.test.ts +356 -0
- package/src/v4/classic/tests/refine.test.ts +532 -0
- package/src/v4/classic/tests/registries.test.ts +204 -0
- package/src/v4/classic/tests/set.test.ts +179 -0
- package/src/v4/classic/tests/standard-schema.test.ts +57 -0
- package/src/v4/classic/tests/string-formats.test.ts +109 -0
- package/src/v4/classic/tests/string.test.ts +881 -0
- package/src/v4/classic/tests/stringbool.test.ts +66 -0
- package/src/v4/classic/tests/template-literal.test.ts +758 -0
- package/src/v4/classic/tests/to-json-schema.test.ts +2314 -0
- package/src/v4/classic/tests/transform.test.ts +250 -0
- package/src/v4/classic/tests/tuple.test.ts +163 -0
- package/src/v4/classic/tests/union.test.ts +94 -0
- package/src/v4/classic/tests/validations.test.ts +283 -0
- package/src/v4/classic/tests/void.test.ts +12 -0
- package/src/v4/core/api.ts +1594 -0
- package/src/v4/core/checks.ts +1283 -0
- package/src/v4/core/config.ts +15 -0
- package/src/v4/core/core.ts +134 -0
- package/src/v4/core/doc.ts +44 -0
- package/src/v4/core/errors.ts +426 -0
- package/src/v4/core/function.ts +176 -0
- package/src/v4/core/index.ts +15 -0
- package/src/v4/core/json-schema.ts +143 -0
- package/src/v4/core/parse.ts +94 -0
- package/src/v4/core/regexes.ts +135 -0
- package/src/v4/core/registries.ts +96 -0
- package/src/v4/core/schemas.ts +3842 -0
- package/src/v4/core/standard-schema.ts +64 -0
- package/src/v4/core/tests/index.test.ts +46 -0
- package/src/v4/core/tests/locales/be.test.ts +124 -0
- package/src/v4/core/tests/locales/en.test.ts +22 -0
- package/src/v4/core/tests/locales/ru.test.ts +128 -0
- package/src/v4/core/tests/locales/tr.test.ts +69 -0
- package/src/v4/core/to-json-schema.ts +977 -0
- package/src/v4/core/util.ts +775 -0
- package/src/v4/core/versions.ts +5 -0
- package/src/v4/core/zsf.ts +323 -0
- package/src/v4/index.ts +4 -0
- package/src/v4/locales/ar.ts +125 -0
- package/src/v4/locales/az.ts +121 -0
- package/src/v4/locales/be.ts +184 -0
- package/src/v4/locales/ca.ts +127 -0
- package/src/v4/locales/cs.ts +142 -0
- package/src/v4/locales/de.ts +124 -0
- package/src/v4/locales/en.ts +127 -0
- package/src/v4/locales/eo.ts +125 -0
- package/src/v4/locales/es.ts +125 -0
- package/src/v4/locales/fa.ts +134 -0
- package/src/v4/locales/fi.ts +131 -0
- package/src/v4/locales/fr-CA.ts +126 -0
- package/src/v4/locales/fr.ts +124 -0
- package/src/v4/locales/he.ts +125 -0
- package/src/v4/locales/hu.ts +126 -0
- package/src/v4/locales/id.ts +125 -0
- package/src/v4/locales/index.ts +39 -0
- package/src/v4/locales/it.ts +125 -0
- package/src/v4/locales/ja.ts +122 -0
- package/src/v4/locales/kh.ts +126 -0
- package/src/v4/locales/ko.ts +131 -0
- package/src/v4/locales/mk.ts +127 -0
- package/src/v4/locales/ms.ts +124 -0
- package/src/v4/locales/nl.ts +126 -0
- package/src/v4/locales/no.ts +124 -0
- package/src/v4/locales/ota.ts +125 -0
- package/src/v4/locales/pl.ts +126 -0
- package/src/v4/locales/ps.ts +133 -0
- package/src/v4/locales/pt.ts +123 -0
- package/src/v4/locales/ru.ts +184 -0
- package/src/v4/locales/sl.ts +126 -0
- package/src/v4/locales/sv.ts +127 -0
- package/src/v4/locales/ta.ts +125 -0
- package/src/v4/locales/th.ts +126 -0
- package/src/v4/locales/tr.ts +121 -0
- package/src/v4/locales/ua.ts +126 -0
- package/src/v4/locales/ur.ts +126 -0
- package/src/v4/locales/vi.ts +125 -0
- package/src/v4/locales/zh-CN.ts +123 -0
- package/src/v4/locales/zh-TW.ts +125 -0
- package/src/v4/mini/checks.ts +32 -0
- package/src/v4/mini/coerce.ts +22 -0
- package/src/v4/mini/external.ts +40 -0
- package/src/v4/mini/index.ts +3 -0
- package/src/v4/mini/iso.ts +62 -0
- package/src/v4/mini/parse.ts +1 -0
- package/src/v4/mini/schemas.ts +1579 -0
- package/src/v4/mini/tests/assignability.test.ts +129 -0
- package/src/v4/mini/tests/brand.test.ts +51 -0
- package/src/v4/mini/tests/checks.test.ts +144 -0
- package/src/v4/mini/tests/computed.test.ts +36 -0
- package/src/v4/mini/tests/error.test.ts +22 -0
- package/src/v4/mini/tests/functions.test.ts +43 -0
- package/src/v4/mini/tests/index.test.ts +871 -0
- package/src/v4/mini/tests/number.test.ts +95 -0
- package/src/v4/mini/tests/object.test.ts +185 -0
- package/src/v4/mini/tests/prototypes.test.ts +43 -0
- package/src/v4/mini/tests/recursive-types.test.ts +275 -0
- package/src/v4/mini/tests/string.test.ts +299 -0
- package/src/v4-mini/index.ts +1 -0
- package/v3/ZodError.cjs +138 -0
- package/v3/ZodError.d.cts +164 -0
- package/v3/ZodError.d.ts +164 -0
- package/v3/ZodError.js +133 -0
- package/v3/errors.cjs +17 -0
- package/v3/errors.d.cts +5 -0
- package/v3/errors.d.ts +5 -0
- package/v3/errors.js +9 -0
- package/v3/external.cjs +22 -0
- package/v3/external.d.cts +6 -0
- package/v3/external.d.ts +6 -0
- package/v3/external.js +6 -0
- package/v3/helpers/enumUtil.cjs +2 -0
- package/v3/helpers/enumUtil.d.cts +8 -0
- package/v3/helpers/enumUtil.d.ts +8 -0
- package/v3/helpers/enumUtil.js +1 -0
- package/v3/helpers/errorUtil.cjs +9 -0
- package/v3/helpers/errorUtil.d.cts +9 -0
- package/v3/helpers/errorUtil.d.ts +9 -0
- package/v3/helpers/errorUtil.js +6 -0
- package/v3/helpers/parseUtil.cjs +124 -0
- package/v3/helpers/parseUtil.d.cts +78 -0
- package/v3/helpers/parseUtil.d.ts +78 -0
- package/v3/helpers/parseUtil.js +109 -0
- package/v3/helpers/partialUtil.cjs +2 -0
- package/v3/helpers/partialUtil.d.cts +8 -0
- package/v3/helpers/partialUtil.d.ts +8 -0
- package/v3/helpers/partialUtil.js +1 -0
- package/v3/helpers/typeAliases.cjs +2 -0
- package/v3/helpers/typeAliases.d.cts +2 -0
- package/v3/helpers/typeAliases.d.ts +2 -0
- package/v3/helpers/typeAliases.js +1 -0
- package/v3/helpers/util.cjs +137 -0
- package/v3/helpers/util.d.cts +85 -0
- package/v3/helpers/util.d.ts +85 -0
- package/v3/helpers/util.js +133 -0
- package/{dist/commonjs/index.js → v3/index.cjs} +2 -2
- package/v3/index.d.cts +4 -0
- package/v3/index.js +4 -0
- package/v3/locales/en.cjs +111 -0
- package/v3/locales/en.d.cts +3 -0
- package/v3/locales/en.d.ts +3 -0
- package/v3/locales/en.js +109 -0
- package/v3/standard-schema.cjs +2 -0
- package/v3/standard-schema.d.cts +102 -0
- package/v3/standard-schema.d.ts +102 -0
- package/v3/standard-schema.js +1 -0
- package/v3/types.cjs +3775 -0
- package/v3/types.d.cts +1031 -0
- package/v3/types.d.ts +1031 -0
- package/v3/types.js +3693 -0
- package/{dist/commonjs/checks.js → v4/classic/checks.cjs} +29 -29
- package/{dist/esm/checks.d.ts → v4/classic/checks.d.cts} +1 -1
- package/{dist/commonjs → v4/classic}/checks.d.ts +1 -1
- package/{dist/esm → v4/classic}/checks.js +1 -1
- package/{dist/commonjs/coerce.js → v4/classic/coerce.cjs} +2 -2
- package/v4/classic/coerce.d.cts +17 -0
- package/v4/classic/coerce.d.ts +17 -0
- package/{dist/esm → v4/classic}/coerce.js +1 -1
- package/{dist/commonjs/compat.js → v4/classic/compat.cjs} +5 -11
- package/{dist/esm/compat.d.ts → v4/classic/compat.d.cts} +4 -6
- package/{dist/commonjs → v4/classic}/compat.d.ts +3 -5
- package/{dist/esm → v4/classic}/compat.js +2 -8
- package/v4/classic/errors.cjs +67 -0
- package/{dist/commonjs/errors.d.ts → v4/classic/errors.d.cts} +8 -7
- package/{dist/esm → v4/classic}/errors.d.ts +8 -7
- package/v4/classic/errors.js +41 -0
- package/v4/classic/external.cjs +70 -0
- package/v4/classic/external.d.cts +13 -0
- package/v4/classic/external.d.ts +13 -0
- package/v4/classic/external.js +18 -0
- package/v4/classic/index.cjs +33 -0
- package/v4/classic/index.d.cts +4 -0
- package/{dist/commonjs/iso.js → v4/classic/iso.cjs} +2 -2
- package/{dist/esm/iso.d.ts → v4/classic/iso.d.cts} +2 -2
- package/{dist/commonjs → v4/classic}/iso.d.ts +1 -1
- package/{dist/esm → v4/classic}/iso.js +1 -1
- package/{dist/commonjs/parse.js → v4/classic/parse.cjs} +7 -9
- package/{dist/commonjs/parse.d.ts → v4/classic/parse.d.cts} +10 -4
- package/{dist/esm → v4/classic}/parse.d.ts +10 -4
- package/v4/classic/parse.js +6 -0
- package/{dist/commonjs/schemas.js → v4/classic/schemas.cjs} +167 -138
- package/{dist/esm/schemas.d.ts → v4/classic/schemas.d.cts} +176 -196
- package/{dist/commonjs → v4/classic}/schemas.d.ts +175 -195
- package/{dist/esm → v4/classic}/schemas.js +128 -102
- package/v4/core/api.cjs +1039 -0
- package/v4/core/api.d.cts +284 -0
- package/v4/core/api.d.ts +284 -0
- package/v4/core/api.js +906 -0
- package/v4/core/checks.cjs +591 -0
- package/v4/core/checks.d.cts +278 -0
- package/v4/core/checks.d.ts +278 -0
- package/v4/core/checks.js +565 -0
- package/v4/core/core.cjs +67 -0
- package/v4/core/core.d.cts +49 -0
- package/v4/core/core.d.ts +49 -0
- package/v4/core/core.js +61 -0
- package/v4/core/doc.cjs +39 -0
- package/v4/core/doc.d.cts +14 -0
- package/v4/core/doc.d.ts +14 -0
- package/v4/core/doc.js +35 -0
- package/v4/core/errors.cjs +226 -0
- package/v4/core/errors.d.cts +210 -0
- package/v4/core/errors.d.ts +210 -0
- package/v4/core/errors.js +195 -0
- package/v4/core/function.cjs +102 -0
- package/v4/core/function.d.cts +52 -0
- package/v4/core/function.d.ts +52 -0
- package/v4/core/function.js +75 -0
- package/v4/core/index.cjs +44 -0
- package/v4/core/index.d.cts +15 -0
- package/v4/core/index.d.ts +15 -0
- package/v4/core/index.js +15 -0
- package/v4/core/json-schema.cjs +2 -0
- package/v4/core/json-schema.d.cts +87 -0
- package/v4/core/json-schema.d.ts +87 -0
- package/v4/core/json-schema.js +1 -0
- package/v4/core/parse.cjs +87 -0
- package/v4/core/parse.d.cts +25 -0
- package/v4/core/parse.d.ts +25 -0
- package/v4/core/parse.js +57 -0
- package/v4/core/regexes.cjs +103 -0
- package/v4/core/regexes.d.cts +61 -0
- package/v4/core/regexes.d.ts +61 -0
- package/v4/core/regexes.js +95 -0
- package/v4/core/registries.cjs +56 -0
- package/v4/core/registries.d.cts +35 -0
- package/v4/core/registries.d.ts +35 -0
- package/v4/core/registries.js +51 -0
- package/v4/core/schemas.cjs +1748 -0
- package/v4/core/schemas.d.cts +1041 -0
- package/v4/core/schemas.d.ts +1041 -0
- package/v4/core/schemas.js +1717 -0
- package/v4/core/standard-schema.cjs +2 -0
- package/v4/core/standard-schema.d.cts +55 -0
- package/v4/core/standard-schema.d.ts +55 -0
- package/v4/core/standard-schema.js +1 -0
- package/v4/core/to-json-schema.cjs +854 -0
- package/v4/core/to-json-schema.d.cts +88 -0
- package/v4/core/to-json-schema.d.ts +88 -0
- package/v4/core/to-json-schema.js +849 -0
- package/v4/core/util.cjs +539 -0
- package/v4/core/util.d.cts +183 -0
- package/v4/core/util.d.ts +183 -0
- package/v4/core/util.js +493 -0
- package/v4/core/versions.cjs +8 -0
- package/v4/core/versions.d.cts +5 -0
- package/v4/core/versions.d.ts +5 -0
- package/v4/core/versions.js +5 -0
- package/v4/index.cjs +22 -0
- package/v4/index.d.cts +3 -0
- package/v4/index.d.ts +3 -0
- package/v4/index.js +3 -0
- package/v4/locales/ar.cjs +142 -0
- package/v4/locales/ar.d.cts +4 -0
- package/v4/locales/ar.d.ts +4 -0
- package/v4/locales/ar.js +116 -0
- package/v4/locales/az.cjs +141 -0
- package/v4/locales/az.d.cts +4 -0
- package/v4/locales/az.d.ts +4 -0
- package/v4/locales/az.js +115 -0
- package/v4/locales/be.cjs +190 -0
- package/v4/locales/be.d.cts +4 -0
- package/v4/locales/be.d.ts +4 -0
- package/v4/locales/be.js +164 -0
- package/v4/locales/ca.cjs +144 -0
- package/v4/locales/ca.d.cts +4 -0
- package/v4/locales/ca.d.ts +4 -0
- package/v4/locales/ca.js +118 -0
- package/v4/locales/cs.cjs +161 -0
- package/v4/locales/cs.d.cts +4 -0
- package/v4/locales/cs.d.ts +4 -0
- package/v4/locales/cs.js +135 -0
- package/v4/locales/de.cjs +142 -0
- package/v4/locales/de.d.cts +4 -0
- package/v4/locales/de.d.ts +4 -0
- package/v4/locales/de.js +116 -0
- package/v4/locales/en.cjs +145 -0
- package/v4/locales/en.d.cts +5 -0
- package/v4/locales/en.d.ts +5 -0
- package/v4/locales/en.js +117 -0
- package/v4/locales/eo.cjs +144 -0
- package/v4/locales/eo.d.cts +5 -0
- package/v4/locales/eo.d.ts +5 -0
- package/v4/locales/eo.js +116 -0
- package/v4/locales/es.cjs +143 -0
- package/v4/locales/es.d.cts +4 -0
- package/v4/locales/es.d.ts +4 -0
- package/v4/locales/es.js +117 -0
- package/v4/locales/fa.cjs +148 -0
- package/v4/locales/fa.d.cts +4 -0
- package/v4/locales/fa.d.ts +4 -0
- package/v4/locales/fa.js +122 -0
- package/v4/locales/fi.cjs +148 -0
- package/v4/locales/fi.d.cts +4 -0
- package/v4/locales/fi.d.ts +4 -0
- package/v4/locales/fi.js +122 -0
- package/v4/locales/fr-CA.cjs +143 -0
- package/v4/locales/fr-CA.d.cts +4 -0
- package/v4/locales/fr-CA.d.ts +4 -0
- package/v4/locales/fr-CA.js +117 -0
- package/v4/locales/fr.cjs +142 -0
- package/v4/locales/fr.d.cts +4 -0
- package/v4/locales/fr.d.ts +4 -0
- package/v4/locales/fr.js +116 -0
- package/v4/locales/he.cjs +143 -0
- package/v4/locales/he.d.cts +4 -0
- package/v4/locales/he.d.ts +4 -0
- package/v4/locales/he.js +117 -0
- package/v4/locales/hu.cjs +143 -0
- package/v4/locales/hu.d.cts +4 -0
- package/v4/locales/hu.d.ts +4 -0
- package/v4/locales/hu.js +117 -0
- package/v4/locales/id.cjs +142 -0
- package/v4/locales/id.d.cts +4 -0
- package/v4/locales/id.d.ts +4 -0
- package/v4/locales/id.js +116 -0
- package/v4/locales/index.cjs +84 -0
- package/v4/locales/index.d.cts +39 -0
- package/v4/locales/index.d.ts +39 -0
- package/v4/locales/index.js +39 -0
- package/v4/locales/it.cjs +143 -0
- package/v4/locales/it.d.cts +4 -0
- package/v4/locales/it.d.ts +4 -0
- package/v4/locales/it.js +117 -0
- package/v4/locales/ja.cjs +141 -0
- package/v4/locales/ja.d.cts +4 -0
- package/v4/locales/ja.d.ts +4 -0
- package/v4/locales/ja.js +115 -0
- package/v4/locales/kh.cjs +143 -0
- package/v4/locales/kh.d.cts +4 -0
- package/v4/locales/kh.d.ts +4 -0
- package/v4/locales/kh.js +117 -0
- package/v4/locales/ko.cjs +147 -0
- package/v4/locales/ko.d.cts +4 -0
- package/v4/locales/ko.d.ts +4 -0
- package/v4/locales/ko.js +121 -0
- package/v4/locales/mk.cjs +144 -0
- package/v4/locales/mk.d.cts +4 -0
- package/v4/locales/mk.d.ts +4 -0
- package/v4/locales/mk.js +118 -0
- package/v4/locales/ms.cjs +142 -0
- package/v4/locales/ms.d.cts +4 -0
- package/v4/locales/ms.d.ts +4 -0
- package/v4/locales/ms.js +116 -0
- package/v4/locales/nl.cjs +143 -0
- package/v4/locales/nl.d.cts +4 -0
- package/v4/locales/nl.d.ts +4 -0
- package/v4/locales/nl.js +117 -0
- package/v4/locales/no.cjs +142 -0
- package/v4/locales/no.d.cts +4 -0
- package/v4/locales/no.d.ts +4 -0
- package/v4/locales/no.js +116 -0
- package/v4/locales/ota.cjs +143 -0
- package/v4/locales/ota.d.cts +4 -0
- package/v4/locales/ota.d.ts +4 -0
- package/v4/locales/ota.js +117 -0
- package/v4/locales/pl.cjs +143 -0
- package/v4/locales/pl.d.cts +4 -0
- package/v4/locales/pl.d.ts +4 -0
- package/v4/locales/pl.js +117 -0
- package/v4/locales/ps.cjs +148 -0
- package/v4/locales/ps.d.cts +4 -0
- package/v4/locales/ps.d.ts +4 -0
- package/v4/locales/ps.js +122 -0
- package/v4/locales/pt.cjs +142 -0
- package/v4/locales/pt.d.cts +4 -0
- package/v4/locales/pt.d.ts +4 -0
- package/v4/locales/pt.js +116 -0
- package/v4/locales/ru.cjs +190 -0
- package/v4/locales/ru.d.cts +4 -0
- package/v4/locales/ru.d.ts +4 -0
- package/v4/locales/ru.js +164 -0
- package/v4/locales/sl.cjs +143 -0
- package/v4/locales/sl.d.cts +4 -0
- package/v4/locales/sl.d.ts +4 -0
- package/v4/locales/sl.js +117 -0
- package/v4/locales/sv.cjs +144 -0
- package/v4/locales/sv.d.cts +4 -0
- package/v4/locales/sv.d.ts +4 -0
- package/v4/locales/sv.js +118 -0
- package/v4/locales/ta.cjs +143 -0
- package/v4/locales/ta.d.cts +4 -0
- package/v4/locales/ta.d.ts +4 -0
- package/v4/locales/ta.js +117 -0
- package/v4/locales/th.cjs +143 -0
- package/v4/locales/th.d.cts +4 -0
- package/v4/locales/th.d.ts +4 -0
- package/v4/locales/th.js +117 -0
- package/v4/locales/tr.cjs +143 -0
- package/v4/locales/tr.d.cts +5 -0
- package/v4/locales/tr.d.ts +5 -0
- package/v4/locales/tr.js +115 -0
- package/v4/locales/ua.cjs +143 -0
- package/v4/locales/ua.d.cts +4 -0
- package/v4/locales/ua.d.ts +4 -0
- package/v4/locales/ua.js +117 -0
- package/v4/locales/ur.cjs +143 -0
- package/v4/locales/ur.d.cts +4 -0
- package/v4/locales/ur.d.ts +4 -0
- package/v4/locales/ur.js +117 -0
- package/v4/locales/vi.cjs +142 -0
- package/v4/locales/vi.d.cts +4 -0
- package/v4/locales/vi.d.ts +4 -0
- package/v4/locales/vi.js +116 -0
- package/v4/locales/zh-CN.cjs +142 -0
- package/v4/locales/zh-CN.d.cts +4 -0
- package/v4/locales/zh-CN.d.ts +4 -0
- package/v4/locales/zh-CN.js +116 -0
- package/v4/locales/zh-TW.cjs +143 -0
- package/v4/locales/zh-TW.d.cts +4 -0
- package/v4/locales/zh-TW.d.ts +4 -0
- package/v4/locales/zh-TW.js +117 -0
- package/v4/mini/checks.cjs +34 -0
- package/v4/mini/checks.d.cts +1 -0
- package/v4/mini/checks.d.ts +1 -0
- package/v4/mini/checks.js +1 -0
- package/{dist/commonjs/errors.js → v4/mini/coerce.cjs} +21 -25
- package/v4/mini/coerce.d.cts +7 -0
- package/v4/mini/coerce.d.ts +7 -0
- package/v4/mini/coerce.js +17 -0
- package/v4/mini/external.cjs +62 -0
- package/v4/mini/external.d.cts +11 -0
- package/v4/mini/external.d.ts +11 -0
- package/v4/mini/external.js +13 -0
- package/v4/mini/index.cjs +32 -0
- package/v4/mini/index.d.cts +3 -0
- package/v4/mini/index.d.ts +3 -0
- package/v4/mini/index.js +3 -0
- package/v4/mini/iso.cjs +60 -0
- package/v4/mini/iso.d.cts +22 -0
- package/v4/mini/iso.d.ts +22 -0
- package/v4/mini/iso.js +30 -0
- package/v4/mini/parse.cjs +8 -0
- package/v4/mini/parse.d.cts +1 -0
- package/v4/mini/parse.d.ts +1 -0
- package/v4/mini/parse.js +1 -0
- package/v4/mini/schemas.cjs +839 -0
- package/v4/mini/schemas.d.cts +356 -0
- package/v4/mini/schemas.d.ts +356 -0
- package/v4/mini/schemas.js +732 -0
- package/v4-mini/index.cjs +17 -0
- package/v4-mini/index.d.cts +1 -0
- package/v4-mini/index.d.ts +1 -0
- package/v4-mini/index.js +1 -0
- package/dist/commonjs/coerce.d.ts +0 -17
- package/dist/commonjs/external.d.ts +0 -8
- package/dist/commonjs/external.js +0 -58
- package/dist/commonjs/package.json +0 -3
- package/dist/esm/coerce.d.ts +0 -17
- package/dist/esm/errors.js +0 -24
- package/dist/esm/external.d.ts +0 -8
- package/dist/esm/external.js +0 -14
- package/dist/esm/package.json +0 -3
- package/dist/esm/parse.js +0 -8
- package/src/coerce.ts +0 -27
- package/src/errors.ts +0 -50
- package/src/external.ts +0 -30
- package/{dist/esm → v3}/index.d.ts +1 -1
- /package/{dist/commonjs → v4/classic}/index.d.ts +0 -0
- /package/{dist/esm → v4/classic}/index.js +0 -0
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import * as core from "
|
|
2
|
-
import { util } from "
|
|
1
|
+
import * as core from "../core/index.js";
|
|
2
|
+
import { util } from "../core/index.js";
|
|
3
3
|
|
|
4
4
|
import * as checks from "./checks.js";
|
|
5
5
|
import * as iso from "./iso.js";
|
|
6
6
|
import * as parse from "./parse.js";
|
|
7
7
|
|
|
8
|
-
export * as iso from "./iso.js";
|
|
9
|
-
export * as coerce from "./coerce.js";
|
|
10
|
-
|
|
11
8
|
///////////////////////////////////////////
|
|
12
9
|
///////////////////////////////////////////
|
|
13
10
|
//////////// ////////////
|
|
@@ -20,29 +17,34 @@ export interface RefinementCtx<T = unknown> extends core.ParsePayload<T> {
|
|
|
20
17
|
addIssue(arg: string | core.$ZodRawIssue | Partial<core.$ZodIssueCustom>): void;
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
export interface ZodType<
|
|
24
|
-
|
|
20
|
+
export interface ZodType<
|
|
21
|
+
out Output = unknown,
|
|
22
|
+
out Input = unknown,
|
|
23
|
+
out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>,
|
|
24
|
+
> extends core.$ZodType<Output, Input, Internals> {
|
|
25
|
+
def: Internals["def"];
|
|
26
|
+
type: Internals["def"]["type"];
|
|
27
|
+
|
|
25
28
|
/** @deprecated Use `.def` instead. */
|
|
26
|
-
_def:
|
|
27
|
-
|
|
28
|
-
_output:
|
|
29
|
-
|
|
30
|
-
_input:
|
|
29
|
+
_def: Internals["def"];
|
|
30
|
+
/** @deprecated Use `z.output<typeof schema>` instead. */
|
|
31
|
+
_output: Internals["output"];
|
|
32
|
+
/** @deprecated Use `z.input<typeof schema>` instead. */
|
|
33
|
+
_input: Internals["input"];
|
|
34
|
+
|
|
31
35
|
// base methods
|
|
32
36
|
check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
|
|
33
|
-
clone(def?:
|
|
37
|
+
clone(def?: Internals["def"], params?: { parent: boolean }): this;
|
|
34
38
|
register<R extends core.$ZodRegistry>(
|
|
35
39
|
registry: R,
|
|
36
40
|
...meta: this extends R["_schema"]
|
|
37
41
|
? undefined extends R["_meta"]
|
|
38
|
-
? [core.$
|
|
39
|
-
: [core.$
|
|
42
|
+
? [core.$replace<R["_meta"], this>?]
|
|
43
|
+
: [core.$replace<R["_meta"], this>]
|
|
40
44
|
: ["Incompatible schema"]
|
|
41
45
|
): this;
|
|
42
46
|
|
|
43
|
-
brand<T extends PropertyKey = PropertyKey>(
|
|
44
|
-
value?: T
|
|
45
|
-
): PropertyKey extends T ? this : this & Record<"_zod", Record<"~output", core.output<this> & core.$brand<T>>>;
|
|
47
|
+
brand<T extends PropertyKey = PropertyKey>(value?: T): PropertyKey extends T ? this : core.$ZodBranded<this, T>;
|
|
46
48
|
|
|
47
49
|
// parsing
|
|
48
50
|
parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
|
|
@@ -61,27 +63,29 @@ export interface ZodType<out Output = unknown, out Input = unknown> extends core
|
|
|
61
63
|
refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
|
|
62
64
|
/** @deprecated Use `.check()` instead. */
|
|
63
65
|
superRefine(
|
|
64
|
-
refinement: (arg: core.output<this>, ctx: RefinementCtx<this
|
|
66
|
+
refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>
|
|
65
67
|
): this;
|
|
66
68
|
overwrite(fn: (x: core.output<this>) => core.output<this>): this;
|
|
67
69
|
|
|
68
70
|
// wrappers
|
|
69
|
-
optional(
|
|
71
|
+
optional(): ZodOptional<this>;
|
|
70
72
|
nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>;
|
|
71
|
-
nullable(
|
|
73
|
+
nullable(): ZodNullable<this>;
|
|
72
74
|
nullish(): ZodOptional<ZodNullable<this>>;
|
|
73
|
-
default(def:
|
|
74
|
-
default(def: () => util.NoUndefined<core.output<this
|
|
75
|
+
default(def: core.output<this>): ZodDefault<this>;
|
|
76
|
+
default(def: () => util.NoUndefined<core.output<this>>): ZodDefault<this>;
|
|
77
|
+
prefault(def: () => core.input<this>): ZodPrefault<this>;
|
|
78
|
+
prefault(def: core.input<this>): ZodPrefault<this>;
|
|
75
79
|
array(): ZodArray<this>;
|
|
76
|
-
or<T extends core
|
|
77
|
-
and<T extends core
|
|
80
|
+
or<T extends core.SomeType>(option: T): ZodUnion<[this, T]>;
|
|
81
|
+
and<T extends core.SomeType>(incoming: T): ZodIntersection<this, T>;
|
|
78
82
|
transform<NewOut>(
|
|
79
83
|
transform: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>
|
|
80
84
|
): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
|
|
81
85
|
catch(def: core.output<this>): ZodCatch<this>;
|
|
82
86
|
catch(def: (ctx: core.$ZodCatchCtx) => core.output<this>): ZodCatch<this>;
|
|
83
|
-
pipe<T extends core.$ZodType<any, this
|
|
84
|
-
target: T | core.$ZodType<any, this
|
|
87
|
+
pipe<T extends core.$ZodType<any, core.output<this>>>(
|
|
88
|
+
target: T | core.$ZodType<any, core.output<this>>
|
|
85
89
|
): ZodPipe<this, T>;
|
|
86
90
|
readonly(): ZodReadonly<this>;
|
|
87
91
|
|
|
@@ -94,28 +98,49 @@ export interface ZodType<out Output = unknown, out Input = unknown> extends core
|
|
|
94
98
|
meta(data: core.$replace<core.GlobalMeta, this>): this;
|
|
95
99
|
|
|
96
100
|
// helpers
|
|
101
|
+
/** @deprecated Try safe-parsing `undefined` (this is what `isOptional` does internally):
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* const schema = z.string().optional();
|
|
105
|
+
* const isOptional = schema.safeParse(undefined).success; // true
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
97
108
|
isOptional(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated Try safe-parsing `null` (this is what `isNullable` does internally):
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
113
|
+
* const schema = z.string().nullable();
|
|
114
|
+
* const isNullable = schema.safeParse(null).success; // true
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
98
117
|
isNullable(): boolean;
|
|
99
118
|
}
|
|
100
119
|
|
|
120
|
+
export interface _ZodType<out Internals extends core.$ZodTypeInternals = core.$ZodTypeInternals>
|
|
121
|
+
extends ZodType<any, any, Internals> {}
|
|
122
|
+
|
|
101
123
|
export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => {
|
|
102
124
|
core.$ZodType.init(inst, def);
|
|
103
125
|
inst.def = def;
|
|
104
|
-
inst
|
|
126
|
+
Object.defineProperty(inst, "_def", { value: def });
|
|
105
127
|
|
|
106
128
|
// base methods
|
|
107
129
|
inst.check = (...checks) => {
|
|
108
|
-
return inst.clone(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
130
|
+
return inst.clone(
|
|
131
|
+
{
|
|
132
|
+
...def,
|
|
133
|
+
checks: [
|
|
134
|
+
...(def.checks ?? []),
|
|
135
|
+
...checks.map((ch) =>
|
|
136
|
+
typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch
|
|
137
|
+
),
|
|
138
|
+
],
|
|
139
|
+
}
|
|
140
|
+
// { parent: true }
|
|
141
|
+
);
|
|
117
142
|
};
|
|
118
|
-
inst.clone = (
|
|
143
|
+
inst.clone = (def, params) => core.clone(inst, def, params);
|
|
119
144
|
inst.brand = () => inst as any;
|
|
120
145
|
inst.register = ((reg: any, meta: any) => {
|
|
121
146
|
reg.add(inst, meta);
|
|
@@ -123,9 +148,9 @@ export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$construct
|
|
|
123
148
|
}) as any;
|
|
124
149
|
|
|
125
150
|
// parsing
|
|
126
|
-
inst.parse = (data, params) => parse.parse(inst, data, params);
|
|
151
|
+
inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
|
|
127
152
|
inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
|
|
128
|
-
inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params);
|
|
153
|
+
inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
129
154
|
inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params);
|
|
130
155
|
inst.spa = inst.safeParseAsync;
|
|
131
156
|
|
|
@@ -135,15 +160,16 @@ export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$construct
|
|
|
135
160
|
inst.overwrite = (fn) => inst.check(checks.overwrite(fn));
|
|
136
161
|
|
|
137
162
|
// wrappers
|
|
138
|
-
inst.optional = (
|
|
139
|
-
inst.nullable = (
|
|
163
|
+
inst.optional = () => optional(inst);
|
|
164
|
+
inst.nullable = () => nullable(inst);
|
|
140
165
|
inst.nullish = () => optional(nullable(inst));
|
|
141
166
|
inst.nonoptional = (params) => nonoptional(inst, params);
|
|
142
167
|
inst.array = () => array(inst);
|
|
143
168
|
inst.or = (arg) => union([inst, arg]);
|
|
144
169
|
inst.and = (arg) => intersection(inst, arg);
|
|
145
170
|
inst.transform = (tx) => pipe(inst, transform(tx as any)) as never;
|
|
146
|
-
inst.default = (def
|
|
171
|
+
inst.default = (def) => _default(inst, def);
|
|
172
|
+
inst.prefault = (def) => prefault(inst, def);
|
|
147
173
|
// inst.coalesce = (def, params) => coalesce(inst, def, params);
|
|
148
174
|
inst.catch = (params) => _catch(inst, params);
|
|
149
175
|
inst.pipe = (target) => pipe(inst, target);
|
|
@@ -152,9 +178,7 @@ export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$construct
|
|
|
152
178
|
// meta
|
|
153
179
|
inst.describe = (description) => {
|
|
154
180
|
const cl = inst.clone();
|
|
155
|
-
|
|
156
|
-
delete meta.id; // do not inherit
|
|
157
|
-
core.globalRegistry.add(cl, meta);
|
|
181
|
+
core.globalRegistry.add(cl, { description });
|
|
158
182
|
return cl;
|
|
159
183
|
};
|
|
160
184
|
Object.defineProperty(inst, "description", {
|
|
@@ -164,7 +188,9 @@ export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$construct
|
|
|
164
188
|
configurable: true,
|
|
165
189
|
});
|
|
166
190
|
inst.meta = (...args: any) => {
|
|
167
|
-
if (args.length === 0)
|
|
191
|
+
if (args.length === 0) {
|
|
192
|
+
return core.globalRegistry.get(inst);
|
|
193
|
+
}
|
|
168
194
|
const cl = inst.clone();
|
|
169
195
|
core.globalRegistry.add(cl, args[0]);
|
|
170
196
|
return cl as any;
|
|
@@ -177,19 +203,15 @@ export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$construct
|
|
|
177
203
|
});
|
|
178
204
|
|
|
179
205
|
// ZodString
|
|
180
|
-
export interface _ZodString<
|
|
181
|
-
|
|
182
|
-
|
|
206
|
+
export interface _ZodString<T extends core.$ZodStringInternals<unknown> = core.$ZodStringInternals<unknown>>
|
|
207
|
+
extends _ZodType<T> {
|
|
183
208
|
format: string | null;
|
|
184
209
|
minLength: number | null;
|
|
185
210
|
maxLength: number | null;
|
|
186
211
|
|
|
187
|
-
// /** @deprecated Use `z.jsonString()` instead. */
|
|
188
|
-
// json(params?: string | core.$ZodCheckJSONStringParams): this;
|
|
189
|
-
|
|
190
212
|
// miscellaneous checks
|
|
191
213
|
regex(regex: RegExp, params?: string | core.$ZodCheckRegexParams): this;
|
|
192
|
-
includes(value: string, params?:
|
|
214
|
+
includes(value: string, params?: core.$ZodCheckIncludesParams): this;
|
|
193
215
|
startsWith(value: string, params?: string | core.$ZodCheckStartsWithParams): this;
|
|
194
216
|
endsWith(value: string, params?: string | core.$ZodCheckEndsWithParams): this;
|
|
195
217
|
min(minLength: number, params?: string | core.$ZodCheckMinLengthParams): this;
|
|
@@ -206,19 +228,21 @@ export interface _ZodString<Input = unknown> extends ZodType {
|
|
|
206
228
|
toUpperCase(): this;
|
|
207
229
|
}
|
|
208
230
|
|
|
231
|
+
/** @internal */
|
|
209
232
|
export const _ZodString: core.$constructor<_ZodString> = /*@__PURE__*/ core.$constructor("_ZodString", (inst, def) => {
|
|
210
233
|
core.$ZodString.init(inst, def);
|
|
211
234
|
ZodType.init(inst, def);
|
|
212
235
|
|
|
213
|
-
|
|
214
|
-
inst.
|
|
215
|
-
inst.
|
|
236
|
+
const bag = inst._zod.bag;
|
|
237
|
+
inst.format = bag.format ?? null;
|
|
238
|
+
inst.minLength = bag.minimum ?? null;
|
|
239
|
+
inst.maxLength = bag.maximum ?? null;
|
|
216
240
|
|
|
217
241
|
// validations
|
|
218
242
|
inst.regex = (...args) => inst.check(checks.regex(...args));
|
|
219
243
|
inst.includes = (...args) => inst.check(checks.includes(...args));
|
|
220
|
-
inst.startsWith = (
|
|
221
|
-
inst.endsWith = (
|
|
244
|
+
inst.startsWith = (...args) => inst.check(checks.startsWith(...args));
|
|
245
|
+
inst.endsWith = (...args) => inst.check(checks.endsWith(...args));
|
|
222
246
|
inst.min = (...args) => inst.check(checks.minLength(...args));
|
|
223
247
|
inst.max = (...args) => inst.check(checks.maxLength(...args));
|
|
224
248
|
inst.length = (...args) => inst.check(checks.length(...args));
|
|
@@ -233,11 +257,9 @@ export const _ZodString: core.$constructor<_ZodString> = /*@__PURE__*/ core.$con
|
|
|
233
257
|
inst.toUpperCase = () => inst.check(checks.toUpperCase());
|
|
234
258
|
});
|
|
235
259
|
|
|
236
|
-
export interface ZodString extends _ZodString<string
|
|
260
|
+
export interface ZodString extends _ZodString<core.$ZodStringInternals<string>> {
|
|
237
261
|
// string format checks
|
|
238
|
-
|
|
239
|
-
// email(params?: string): ZodString;
|
|
240
|
-
// email(params?: StringFormatParams): ZodString;
|
|
262
|
+
|
|
241
263
|
/** @deprecated Use `z.email()` instead. */
|
|
242
264
|
email(params?: string | core.$ZodCheckEmailParams): this;
|
|
243
265
|
/** @deprecated Use `z.url()` instead. */
|
|
@@ -343,14 +365,15 @@ export const ZodString: core.$constructor<ZodString> = /*@__PURE__*/ core.$const
|
|
|
343
365
|
inst.duration = (params) => inst.check(iso.duration(params as any));
|
|
344
366
|
});
|
|
345
367
|
|
|
368
|
+
export function string(params?: string | core.$ZodStringParams): ZodString;
|
|
369
|
+
export function string<T extends string>(params?: string | core.$ZodStringParams): core.$ZodType<T, T>;
|
|
346
370
|
export function string(params?: string | core.$ZodStringParams): ZodString {
|
|
347
371
|
return core._string(ZodString, params) as any;
|
|
348
372
|
}
|
|
349
373
|
|
|
350
374
|
// ZodStringFormat
|
|
351
|
-
export interface ZodStringFormat<Format extends
|
|
352
|
-
|
|
353
|
-
}
|
|
375
|
+
export interface ZodStringFormat<Format extends string = string>
|
|
376
|
+
extends _ZodString<core.$ZodStringFormatInternals<Format>> {}
|
|
354
377
|
export const ZodStringFormat: core.$constructor<ZodStringFormat> = /*@__PURE__*/ core.$constructor(
|
|
355
378
|
"ZodStringFormat",
|
|
356
379
|
(inst, def) => {
|
|
@@ -653,10 +676,31 @@ export function jwt(params?: string | core.$ZodJWTParams): ZodJWT {
|
|
|
653
676
|
return core._jwt(ZodJWT, params);
|
|
654
677
|
}
|
|
655
678
|
|
|
656
|
-
//
|
|
657
|
-
export interface
|
|
658
|
-
|
|
679
|
+
// ZodCustomStringFormat
|
|
680
|
+
export interface ZodCustomStringFormat<Format extends string = string>
|
|
681
|
+
extends ZodStringFormat<Format>,
|
|
682
|
+
core.$ZodCustomStringFormat<Format> {
|
|
683
|
+
_zod: core.$ZodCustomStringFormatInternals<Format>;
|
|
684
|
+
}
|
|
685
|
+
export const ZodCustomStringFormat: core.$constructor<ZodCustomStringFormat> = /*@__PURE__*/ core.$constructor(
|
|
686
|
+
"ZodCustomStringFormat",
|
|
687
|
+
(inst, def) => {
|
|
688
|
+
// ZodStringFormat.init(inst, def);
|
|
689
|
+
core.$ZodCustomStringFormat.init(inst, def);
|
|
690
|
+
ZodStringFormat.init(inst, def);
|
|
691
|
+
}
|
|
692
|
+
);
|
|
693
|
+
export function stringFormat<Format extends string>(
|
|
694
|
+
format: Format,
|
|
695
|
+
fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp,
|
|
696
|
+
_params: string | core.$ZodStringFormatParams = {}
|
|
697
|
+
): ZodCustomStringFormat<Format> {
|
|
698
|
+
return core._stringFormat(ZodCustomStringFormat, format, fnOrRegex, _params) as any;
|
|
699
|
+
}
|
|
659
700
|
|
|
701
|
+
// ZodNumber
|
|
702
|
+
export interface _ZodNumber<Internals extends core.$ZodNumberInternals = core.$ZodNumberInternals>
|
|
703
|
+
extends _ZodType<Internals> {
|
|
660
704
|
gt(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
|
|
661
705
|
/** Identical to .min() */
|
|
662
706
|
gte(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
|
|
@@ -678,7 +722,7 @@ export interface _ZodNumber<Input = unknown> extends ZodType {
|
|
|
678
722
|
step(value: number, params?: string | core.$ZodCheckMultipleOfParams): this;
|
|
679
723
|
|
|
680
724
|
/** @deprecated In v4 and later, z.number() does not allow infinite values by default. This is a no-op. */
|
|
681
|
-
finite(params?:
|
|
725
|
+
finite(params?: unknown): this;
|
|
682
726
|
|
|
683
727
|
minValue: number | null;
|
|
684
728
|
maxValue: number | null;
|
|
@@ -689,7 +733,7 @@ export interface _ZodNumber<Input = unknown> extends ZodType {
|
|
|
689
733
|
format: string | null;
|
|
690
734
|
}
|
|
691
735
|
|
|
692
|
-
export interface ZodNumber extends _ZodNumber<number
|
|
736
|
+
export interface ZodNumber extends _ZodNumber<core.$ZodNumberInternals<number>> {}
|
|
693
737
|
|
|
694
738
|
export const ZodNumber: core.$constructor<ZodNumber> = /*@__PURE__*/ core.$constructor("ZodNumber", (inst, def) => {
|
|
695
739
|
core.$ZodNumber.init(inst, def);
|
|
@@ -713,12 +757,14 @@ export const ZodNumber: core.$constructor<ZodNumber> = /*@__PURE__*/ core.$const
|
|
|
713
757
|
// inst.finite = (params) => inst.check(core.finite(params));
|
|
714
758
|
inst.finite = () => inst;
|
|
715
759
|
|
|
716
|
-
|
|
717
|
-
inst.
|
|
718
|
-
|
|
719
|
-
|
|
760
|
+
const bag = inst._zod.bag;
|
|
761
|
+
inst.minValue =
|
|
762
|
+
Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
|
|
763
|
+
inst.maxValue =
|
|
764
|
+
Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
|
|
765
|
+
inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
|
|
720
766
|
inst.isFinite = true;
|
|
721
|
-
inst.format =
|
|
767
|
+
inst.format = bag.format ?? null;
|
|
722
768
|
});
|
|
723
769
|
|
|
724
770
|
export function number(params?: string | core.$ZodNumberParams): ZodNumber {
|
|
@@ -768,10 +814,8 @@ export function uint32(params?: string | core.$ZodCheckNumberFormatParams): ZodU
|
|
|
768
814
|
}
|
|
769
815
|
|
|
770
816
|
// boolean
|
|
771
|
-
export interface _ZodBoolean<T =
|
|
772
|
-
|
|
773
|
-
}
|
|
774
|
-
export interface ZodBoolean extends _ZodBoolean<boolean> {}
|
|
817
|
+
export interface _ZodBoolean<T extends core.$ZodBooleanInternals = core.$ZodBooleanInternals> extends _ZodType<T> {}
|
|
818
|
+
export interface ZodBoolean extends _ZodBoolean<core.$ZodBooleanInternals<boolean>> {}
|
|
775
819
|
export const ZodBoolean: core.$constructor<ZodBoolean> = /*@__PURE__*/ core.$constructor("ZodBoolean", (inst, def) => {
|
|
776
820
|
core.$ZodBoolean.init(inst, def);
|
|
777
821
|
ZodType.init(inst, def);
|
|
@@ -782,9 +826,7 @@ export function boolean(params?: string | core.$ZodBooleanParams): ZodBoolean {
|
|
|
782
826
|
}
|
|
783
827
|
|
|
784
828
|
// bigint
|
|
785
|
-
export interface _ZodBigInt<T =
|
|
786
|
-
_zod: core.$ZodBigIntInternals<T>;
|
|
787
|
-
|
|
829
|
+
export interface _ZodBigInt<T extends core.$ZodBigIntInternals = core.$ZodBigIntInternals> extends _ZodType<T> {
|
|
788
830
|
gte(value: bigint, params?: string | core.$ZodCheckGreaterThanParams): this;
|
|
789
831
|
/** Alias of `.gte()` */
|
|
790
832
|
min(value: bigint, params?: string | core.$ZodCheckGreaterThanParams): this;
|
|
@@ -804,7 +846,7 @@ export interface _ZodBigInt<T = unknown> extends ZodType {
|
|
|
804
846
|
format: string | null;
|
|
805
847
|
}
|
|
806
848
|
|
|
807
|
-
export interface ZodBigInt extends _ZodBigInt<bigint
|
|
849
|
+
export interface ZodBigInt extends _ZodBigInt<core.$ZodBigIntInternals<bigint>> {}
|
|
808
850
|
export const ZodBigInt: core.$constructor<ZodBigInt> = /*@__PURE__*/ core.$constructor("ZodBigInt", (inst, def) => {
|
|
809
851
|
core.$ZodBigInt.init(inst, def);
|
|
810
852
|
ZodType.init(inst, def);
|
|
@@ -823,9 +865,10 @@ export const ZodBigInt: core.$constructor<ZodBigInt> = /*@__PURE__*/ core.$const
|
|
|
823
865
|
inst.nonnegative = (params) => inst.check(checks.gte(BigInt(0), params));
|
|
824
866
|
inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params));
|
|
825
867
|
|
|
826
|
-
|
|
827
|
-
inst.
|
|
828
|
-
inst.
|
|
868
|
+
const bag = inst._zod.bag;
|
|
869
|
+
inst.minValue = bag.minimum ?? null;
|
|
870
|
+
inst.maxValue = bag.maximum ?? null;
|
|
871
|
+
inst.format = bag.format ?? null;
|
|
829
872
|
});
|
|
830
873
|
|
|
831
874
|
export function bigint(params?: string | core.$ZodBigIntParams): ZodBigInt {
|
|
@@ -856,9 +899,7 @@ export function uint64(params?: string | core.$ZodBigIntFormatParams): ZodBigInt
|
|
|
856
899
|
}
|
|
857
900
|
|
|
858
901
|
// symbol
|
|
859
|
-
export interface ZodSymbol extends
|
|
860
|
-
_zod: core.$ZodSymbolInternals;
|
|
861
|
-
}
|
|
902
|
+
export interface ZodSymbol extends _ZodType<core.$ZodSymbolInternals> {}
|
|
862
903
|
export const ZodSymbol: core.$constructor<ZodSymbol> = /*@__PURE__*/ core.$constructor("ZodSymbol", (inst, def) => {
|
|
863
904
|
core.$ZodSymbol.init(inst, def);
|
|
864
905
|
ZodType.init(inst, def);
|
|
@@ -869,9 +910,7 @@ export function symbol(params?: string | core.$ZodSymbolParams): ZodSymbol {
|
|
|
869
910
|
}
|
|
870
911
|
|
|
871
912
|
// ZodUndefined
|
|
872
|
-
export interface ZodUndefined extends
|
|
873
|
-
_zod: core.$ZodUndefinedInternals;
|
|
874
|
-
}
|
|
913
|
+
export interface ZodUndefined extends _ZodType<core.$ZodUndefinedInternals> {}
|
|
875
914
|
export const ZodUndefined: core.$constructor<ZodUndefined> = /*@__PURE__*/ core.$constructor(
|
|
876
915
|
"ZodUndefined",
|
|
877
916
|
(inst, def) => {
|
|
@@ -886,9 +925,7 @@ function _undefined(params?: string | core.$ZodUndefinedParams): ZodUndefined {
|
|
|
886
925
|
export { _undefined as undefined };
|
|
887
926
|
|
|
888
927
|
// ZodNull
|
|
889
|
-
export interface ZodNull extends
|
|
890
|
-
_zod: core.$ZodNullInternals;
|
|
891
|
-
}
|
|
928
|
+
export interface ZodNull extends _ZodType<core.$ZodNullInternals> {}
|
|
892
929
|
export const ZodNull: core.$constructor<ZodNull> = /*@__PURE__*/ core.$constructor("ZodNull", (inst, def) => {
|
|
893
930
|
core.$ZodNull.init(inst, def);
|
|
894
931
|
ZodType.init(inst, def);
|
|
@@ -900,35 +937,29 @@ function _null(params?: string | core.$ZodNullParams): ZodNull {
|
|
|
900
937
|
export { _null as null };
|
|
901
938
|
|
|
902
939
|
// ZodAny
|
|
903
|
-
export interface ZodAny extends
|
|
904
|
-
_zod: core.$ZodAnyInternals;
|
|
905
|
-
}
|
|
940
|
+
export interface ZodAny extends _ZodType<core.$ZodAnyInternals> {}
|
|
906
941
|
export const ZodAny: core.$constructor<ZodAny> = /*@__PURE__*/ core.$constructor("ZodAny", (inst, def) => {
|
|
907
942
|
core.$ZodAny.init(inst, def);
|
|
908
943
|
ZodType.init(inst, def);
|
|
909
944
|
});
|
|
910
945
|
|
|
911
|
-
export function any(
|
|
912
|
-
return core._any(ZodAny
|
|
946
|
+
export function any(): ZodAny {
|
|
947
|
+
return core._any(ZodAny);
|
|
913
948
|
}
|
|
914
949
|
|
|
915
950
|
// ZodUnknown
|
|
916
|
-
export interface ZodUnknown extends
|
|
917
|
-
_zod: core.$ZodUnknownInternals;
|
|
918
|
-
}
|
|
951
|
+
export interface ZodUnknown extends _ZodType<core.$ZodUnknownInternals> {}
|
|
919
952
|
export const ZodUnknown: core.$constructor<ZodUnknown> = /*@__PURE__*/ core.$constructor("ZodUnknown", (inst, def) => {
|
|
920
953
|
core.$ZodUnknown.init(inst, def);
|
|
921
954
|
ZodType.init(inst, def);
|
|
922
955
|
});
|
|
923
956
|
|
|
924
|
-
export function unknown(
|
|
925
|
-
return core._unknown(ZodUnknown
|
|
957
|
+
export function unknown(): ZodUnknown {
|
|
958
|
+
return core._unknown(ZodUnknown);
|
|
926
959
|
}
|
|
927
960
|
|
|
928
961
|
// ZodNever
|
|
929
|
-
export interface ZodNever extends
|
|
930
|
-
_zod: core.$ZodNeverInternals;
|
|
931
|
-
}
|
|
962
|
+
export interface ZodNever extends _ZodType<core.$ZodNeverInternals> {}
|
|
932
963
|
export const ZodNever: core.$constructor<ZodNever> = /*@__PURE__*/ core.$constructor("ZodNever", (inst, def) => {
|
|
933
964
|
core.$ZodNever.init(inst, def);
|
|
934
965
|
ZodType.init(inst, def);
|
|
@@ -939,9 +970,7 @@ export function never(params?: string | core.$ZodNeverParams): ZodNever {
|
|
|
939
970
|
}
|
|
940
971
|
|
|
941
972
|
// ZodVoid
|
|
942
|
-
export interface ZodVoid extends
|
|
943
|
-
_zod: core.$ZodVoidInternals;
|
|
944
|
-
}
|
|
973
|
+
export interface ZodVoid extends _ZodType<core.$ZodVoidInternals> {}
|
|
945
974
|
export const ZodVoid: core.$constructor<ZodVoid> = /*@__PURE__*/ core.$constructor("ZodVoid", (inst, def) => {
|
|
946
975
|
core.$ZodVoid.init(inst, def);
|
|
947
976
|
ZodType.init(inst, def);
|
|
@@ -953,9 +982,7 @@ function _void(params?: string | core.$ZodVoidParams): ZodVoid {
|
|
|
953
982
|
export { _void as void };
|
|
954
983
|
|
|
955
984
|
// ZodDate
|
|
956
|
-
export interface _ZodDate<T =
|
|
957
|
-
_zod: core.$ZodDateInternals<T>;
|
|
958
|
-
|
|
985
|
+
export interface _ZodDate<T extends core.$ZodDateInternals = core.$ZodDateInternals> extends _ZodType<T> {
|
|
959
986
|
min(value: number | Date, params?: string | core.$ZodCheckGreaterThanParams): this;
|
|
960
987
|
max(value: number | Date, params?: string | core.$ZodCheckLessThanParams): this;
|
|
961
988
|
|
|
@@ -965,7 +992,7 @@ export interface _ZodDate<T = unknown> extends ZodType {
|
|
|
965
992
|
maxDate: Date | null;
|
|
966
993
|
}
|
|
967
994
|
|
|
968
|
-
export interface ZodDate extends _ZodDate<Date
|
|
995
|
+
export interface ZodDate extends _ZodDate<core.$ZodDateInternals<Date>> {}
|
|
969
996
|
export const ZodDate: core.$constructor<ZodDate> = /*@__PURE__*/ core.$constructor("ZodDate", (inst, def) => {
|
|
970
997
|
core.$ZodDate.init(inst, def);
|
|
971
998
|
ZodType.init(inst, def);
|
|
@@ -973,7 +1000,7 @@ export const ZodDate: core.$constructor<ZodDate> = /*@__PURE__*/ core.$construct
|
|
|
973
1000
|
inst.min = (value, params) => inst.check(checks.gte(value, params));
|
|
974
1001
|
inst.max = (value, params) => inst.check(checks.lte(value, params));
|
|
975
1002
|
|
|
976
|
-
const c = inst._zod.
|
|
1003
|
+
const c = inst._zod.bag;
|
|
977
1004
|
inst.minDate = c.minimum ? new Date(c.minimum) : null;
|
|
978
1005
|
inst.maxDate = c.maximum ? new Date(c.maximum) : null;
|
|
979
1006
|
});
|
|
@@ -983,14 +1010,16 @@ export function date(params?: string | core.$ZodDateParams): ZodDate {
|
|
|
983
1010
|
}
|
|
984
1011
|
|
|
985
1012
|
// ZodArray
|
|
986
|
-
export interface ZodArray<T extends core
|
|
987
|
-
|
|
988
|
-
|
|
1013
|
+
export interface ZodArray<T extends core.SomeType = core.$ZodType>
|
|
1014
|
+
extends _ZodType<core.$ZodArrayInternals<T>>,
|
|
1015
|
+
core.$ZodArray<T> {
|
|
989
1016
|
element: T;
|
|
990
1017
|
min(minLength: number, params?: string | core.$ZodCheckMinLengthParams): this;
|
|
991
1018
|
nonempty(params?: string | core.$ZodCheckMinLengthParams): this;
|
|
992
1019
|
max(maxLength: number, params?: string | core.$ZodCheckMaxLengthParams): this;
|
|
993
1020
|
length(len: number, params?: string | core.$ZodCheckLengthEqualsParams): this;
|
|
1021
|
+
|
|
1022
|
+
unwrap(): T;
|
|
994
1023
|
}
|
|
995
1024
|
export const ZodArray: core.$constructor<ZodArray> = /*@__PURE__*/ core.$constructor("ZodArray", (inst, def) => {
|
|
996
1025
|
core.$ZodArray.init(inst, def);
|
|
@@ -1001,99 +1030,90 @@ export const ZodArray: core.$constructor<ZodArray> = /*@__PURE__*/ core.$constru
|
|
|
1001
1030
|
inst.nonempty = (params) => inst.check(checks.minLength(1, params));
|
|
1002
1031
|
inst.max = (maxLength, params) => inst.check(checks.maxLength(maxLength, params));
|
|
1003
1032
|
inst.length = (len, params) => inst.check(checks.length(len, params));
|
|
1033
|
+
|
|
1034
|
+
inst.unwrap = () => inst.element;
|
|
1004
1035
|
});
|
|
1005
1036
|
|
|
1006
|
-
export function array<T extends core
|
|
1007
|
-
|
|
1008
|
-
return core._array(ZodArray, element, params) as any;
|
|
1037
|
+
export function array<T extends core.SomeType>(element: T, params?: string | core.$ZodArrayParams): ZodArray<T> {
|
|
1038
|
+
return core._array(ZodArray, element as any, params) as any;
|
|
1009
1039
|
}
|
|
1010
1040
|
|
|
1011
1041
|
// .keyof
|
|
1012
|
-
export function keyof<T extends ZodObject>(schema: T): ZodLiteral<keyof T["_zod"]["output"]
|
|
1042
|
+
export function keyof<T extends ZodObject>(schema: T): ZodLiteral<Exclude<keyof T["_zod"]["output"], symbol>> {
|
|
1013
1043
|
const shape = schema._zod.def.shape;
|
|
1014
1044
|
return literal(Object.keys(shape)) as any;
|
|
1015
1045
|
}
|
|
1016
1046
|
|
|
1017
1047
|
// ZodObject
|
|
1048
|
+
|
|
1018
1049
|
export interface ZodObject<
|
|
1019
|
-
|
|
1050
|
+
/** @ts-ignore Cast variance */
|
|
1020
1051
|
out Shape extends core.$ZodShape = core.$ZodLooseShape,
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
>
|
|
1024
|
-
_zod: core.$ZodObjectInternals<Shape, OutExtra, InExtra>;
|
|
1052
|
+
out Config extends core.$ZodObjectConfig = core.$strip,
|
|
1053
|
+
> extends _ZodType<core.$ZodObjectInternals<Shape, Config>>,
|
|
1054
|
+
core.$ZodObject<Shape, Config> {
|
|
1025
1055
|
shape: Shape;
|
|
1026
1056
|
|
|
1027
1057
|
keyof(): ZodEnum<util.ToEnum<keyof Shape & string>>;
|
|
1028
1058
|
/** Define a schema to validate all unrecognized keys. This overrides the existing strict/loose behavior. */
|
|
1029
|
-
catchall<T extends core
|
|
1059
|
+
catchall<T extends core.SomeType>(schema: T): ZodObject<Shape, core.$catchall<T>>;
|
|
1030
1060
|
|
|
1031
1061
|
/** @deprecated Use `z.looseObject()` or `.loose()` instead. */
|
|
1032
|
-
passthrough(): ZodObject<Shape,
|
|
1062
|
+
passthrough(): ZodObject<Shape, core.$loose>;
|
|
1033
1063
|
/** Consider `z.looseObject(A.shape)` instead */
|
|
1034
|
-
loose(): ZodObject<Shape,
|
|
1064
|
+
loose(): ZodObject<Shape, core.$loose>;
|
|
1035
1065
|
|
|
1036
1066
|
/** Consider `z.strictObject(A.shape)` instead */
|
|
1037
|
-
strict(): ZodObject<Shape,
|
|
1067
|
+
strict(): ZodObject<Shape, core.$strict>;
|
|
1038
1068
|
|
|
1039
1069
|
/** This is the default behavior. This method call is likely unnecessary. */
|
|
1040
|
-
strip(): ZodObject<Shape,
|
|
1070
|
+
strip(): ZodObject<Shape, core.$strip>;
|
|
1041
1071
|
|
|
1042
|
-
extend<U extends core.$ZodLooseShape
|
|
1072
|
+
extend<U extends core.$ZodLooseShape & Partial<Record<keyof Shape, core.SomeType>>>(
|
|
1043
1073
|
shape: U
|
|
1044
|
-
): ZodObject<
|
|
1045
|
-
util.Extend<Shape, U>,
|
|
1046
|
-
OutExtra,
|
|
1047
|
-
InExtra // & B['_zod']["extra"]
|
|
1048
|
-
>;
|
|
1074
|
+
): ZodObject<util.Extend<Shape, U>, Config>;
|
|
1049
1075
|
|
|
1050
1076
|
/**
|
|
1051
|
-
* @deprecated Use
|
|
1077
|
+
* @deprecated Use spread syntax and the `.shape` property to combine two object schemas:
|
|
1052
1078
|
*
|
|
1053
1079
|
* ```ts
|
|
1054
|
-
* z.object({
|
|
1055
|
-
*
|
|
1056
|
-
* ...B.shape
|
|
1057
|
-
* });
|
|
1058
|
-
* ```
|
|
1059
|
-
*/
|
|
1060
|
-
merge<U extends ZodObject>(
|
|
1061
|
-
other: U
|
|
1062
|
-
): ZodObject<util.Extend<Shape, U["shape"]>, U["_zod"]["outextra"], U["_zod"]["inextra"]>;
|
|
1063
|
-
/**
|
|
1064
|
-
* @deprecated Use destructuring to merge the shapes:
|
|
1080
|
+
* const A = z.object({ a: z.string() });
|
|
1081
|
+
* const B = z.object({ b: z.number() });
|
|
1065
1082
|
*
|
|
1066
|
-
*
|
|
1067
|
-
* z.object({
|
|
1083
|
+
* const C = z.object({
|
|
1068
1084
|
* ...A.shape,
|
|
1069
1085
|
* ...B.shape
|
|
1070
1086
|
* });
|
|
1071
1087
|
* ```
|
|
1072
1088
|
*/
|
|
1089
|
+
merge<U extends ZodObject>(other: U): ZodObject<util.Extend<Shape, U["shape"]>, U["_zod"]["config"]>;
|
|
1073
1090
|
|
|
1074
|
-
pick<M extends util.
|
|
1091
|
+
pick<M extends util.Mask<keyof Shape>>(
|
|
1075
1092
|
mask: M
|
|
1076
|
-
): ZodObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>,
|
|
1093
|
+
): ZodObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, Config>;
|
|
1077
1094
|
|
|
1078
|
-
omit<M extends util.
|
|
1095
|
+
omit<M extends util.Mask<keyof Shape>>(
|
|
1079
1096
|
mask: M
|
|
1080
|
-
): ZodObject<util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>,
|
|
1097
|
+
): ZodObject<util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>, Config>;
|
|
1081
1098
|
|
|
1082
1099
|
partial(): ZodObject<
|
|
1083
1100
|
{
|
|
1084
1101
|
[k in keyof Shape]: ZodOptional<Shape[k]>;
|
|
1085
1102
|
},
|
|
1086
|
-
|
|
1087
|
-
InExtra
|
|
1103
|
+
Config
|
|
1088
1104
|
>;
|
|
1089
|
-
partial<M extends util.
|
|
1105
|
+
partial<M extends util.Mask<keyof Shape>>(
|
|
1090
1106
|
mask: M
|
|
1091
1107
|
): ZodObject<
|
|
1092
1108
|
{
|
|
1093
|
-
[k in keyof Shape]: k extends keyof M
|
|
1109
|
+
[k in keyof Shape]: k extends keyof M
|
|
1110
|
+
? // Shape[k] extends OptionalInSchema
|
|
1111
|
+
// ? Shape[k]
|
|
1112
|
+
// :
|
|
1113
|
+
ZodOptional<Shape[k]>
|
|
1114
|
+
: Shape[k];
|
|
1094
1115
|
},
|
|
1095
|
-
|
|
1096
|
-
InExtra
|
|
1116
|
+
Config
|
|
1097
1117
|
>;
|
|
1098
1118
|
|
|
1099
1119
|
// required
|
|
@@ -1101,17 +1121,15 @@ export interface ZodObject<
|
|
|
1101
1121
|
{
|
|
1102
1122
|
[k in keyof Shape]: ZodNonOptional<Shape[k]>;
|
|
1103
1123
|
},
|
|
1104
|
-
|
|
1105
|
-
InExtra
|
|
1124
|
+
Config
|
|
1106
1125
|
>;
|
|
1107
|
-
required<M extends util.
|
|
1126
|
+
required<M extends util.Mask<keyof Shape>>(
|
|
1108
1127
|
mask: M
|
|
1109
1128
|
): ZodObject<
|
|
1110
1129
|
{
|
|
1111
1130
|
[k in keyof Shape]: k extends keyof M ? ZodNonOptional<Shape[k]> : Shape[k];
|
|
1112
1131
|
},
|
|
1113
|
-
|
|
1114
|
-
InExtra
|
|
1132
|
+
Config
|
|
1115
1133
|
>;
|
|
1116
1134
|
}
|
|
1117
1135
|
|
|
@@ -1119,11 +1137,9 @@ export const ZodObject: core.$constructor<ZodObject> = /*@__PURE__*/ core.$const
|
|
|
1119
1137
|
core.$ZodObject.init(inst, def);
|
|
1120
1138
|
ZodType.init(inst, def);
|
|
1121
1139
|
|
|
1122
|
-
util.defineLazy(inst, "shape", () =>
|
|
1123
|
-
return Object.fromEntries(Object.entries(inst._zod.def.shape));
|
|
1124
|
-
});
|
|
1140
|
+
util.defineLazy(inst, "shape", () => def.shape);
|
|
1125
1141
|
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape)) as any;
|
|
1126
|
-
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
|
|
1142
|
+
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall as any as core.$ZodType }) as any;
|
|
1127
1143
|
inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
1128
1144
|
// inst.nonstrict = () => inst.clone({ ...inst._zod.def, catchall: api.unknown() });
|
|
1129
1145
|
inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
@@ -1140,18 +1156,16 @@ export const ZodObject: core.$constructor<ZodObject> = /*@__PURE__*/ core.$const
|
|
|
1140
1156
|
inst.required = (...args: any[]) => util.required(ZodNonOptional, inst, args[0] as object);
|
|
1141
1157
|
});
|
|
1142
1158
|
|
|
1143
|
-
export function object<T extends core.$ZodLooseShape = Record<never, core
|
|
1159
|
+
export function object<T extends core.$ZodLooseShape = Partial<Record<never, core.SomeType>>>(
|
|
1144
1160
|
shape?: T,
|
|
1145
1161
|
params?: string | core.$ZodObjectParams
|
|
1146
|
-
): ZodObject<util.Writeable<T
|
|
1162
|
+
): ZodObject<util.Writeable<T>, core.$strip> {
|
|
1147
1163
|
const def: core.$ZodObjectDef = {
|
|
1148
1164
|
type: "object",
|
|
1149
|
-
|
|
1150
1165
|
get shape() {
|
|
1151
1166
|
util.assignProp(this, "shape", { ...shape });
|
|
1152
1167
|
return this.shape;
|
|
1153
1168
|
},
|
|
1154
|
-
|
|
1155
1169
|
...util.normalizeParams(params),
|
|
1156
1170
|
};
|
|
1157
1171
|
return new ZodObject(def) as any;
|
|
@@ -1162,41 +1176,39 @@ export function object<T extends core.$ZodLooseShape = Record<never, core.$ZodTy
|
|
|
1162
1176
|
export function strictObject<T extends core.$ZodLooseShape>(
|
|
1163
1177
|
shape: T,
|
|
1164
1178
|
params?: string | core.$ZodObjectParams
|
|
1165
|
-
): ZodObject<T,
|
|
1179
|
+
): ZodObject<T, core.$strict> {
|
|
1166
1180
|
return new ZodObject({
|
|
1167
1181
|
type: "object",
|
|
1168
|
-
|
|
1169
1182
|
get shape() {
|
|
1170
1183
|
util.assignProp(this, "shape", { ...shape });
|
|
1171
1184
|
return this.shape;
|
|
1172
1185
|
},
|
|
1173
|
-
|
|
1174
1186
|
catchall: never(),
|
|
1175
1187
|
...util.normalizeParams(params),
|
|
1176
1188
|
}) as any;
|
|
1177
1189
|
}
|
|
1178
1190
|
|
|
1179
1191
|
// looseObject
|
|
1192
|
+
|
|
1180
1193
|
export function looseObject<T extends core.$ZodLooseShape>(
|
|
1181
1194
|
shape: T,
|
|
1182
1195
|
params?: string | core.$ZodObjectParams
|
|
1183
|
-
): ZodObject<T,
|
|
1196
|
+
): ZodObject<T, core.$loose> {
|
|
1184
1197
|
return new ZodObject({
|
|
1185
1198
|
type: "object",
|
|
1186
|
-
|
|
1187
1199
|
get shape() {
|
|
1188
1200
|
util.assignProp(this, "shape", { ...shape });
|
|
1189
1201
|
return this.shape;
|
|
1190
1202
|
},
|
|
1191
|
-
|
|
1192
1203
|
catchall: unknown(),
|
|
1193
1204
|
...util.normalizeParams(params),
|
|
1194
1205
|
}) as any;
|
|
1195
1206
|
}
|
|
1196
1207
|
|
|
1197
1208
|
// ZodUnion
|
|
1198
|
-
export interface ZodUnion<T extends readonly core
|
|
1199
|
-
|
|
1209
|
+
export interface ZodUnion<T extends readonly core.SomeType[] = readonly core.$ZodType[]>
|
|
1210
|
+
extends _ZodType<core.$ZodUnionInternals<T>>,
|
|
1211
|
+
core.$ZodUnion<T> {
|
|
1200
1212
|
options: T;
|
|
1201
1213
|
}
|
|
1202
1214
|
export const ZodUnion: core.$constructor<ZodUnion> = /*@__PURE__*/ core.$constructor("ZodUnion", (inst, def) => {
|
|
@@ -1205,62 +1217,51 @@ export const ZodUnion: core.$constructor<ZodUnion> = /*@__PURE__*/ core.$constru
|
|
|
1205
1217
|
inst.options = def.options;
|
|
1206
1218
|
});
|
|
1207
1219
|
|
|
1208
|
-
export function union<const T extends readonly core
|
|
1220
|
+
export function union<const T extends readonly core.SomeType[]>(
|
|
1209
1221
|
options: T,
|
|
1210
1222
|
params?: string | core.$ZodUnionParams
|
|
1211
1223
|
): ZodUnion<T> {
|
|
1212
1224
|
return new ZodUnion({
|
|
1213
1225
|
type: "union",
|
|
1214
|
-
options,
|
|
1226
|
+
options: options as any as core.$ZodType[],
|
|
1215
1227
|
...util.normalizeParams(params),
|
|
1216
|
-
}) as
|
|
1228
|
+
}) as any;
|
|
1217
1229
|
}
|
|
1218
1230
|
|
|
1219
1231
|
// ZodDiscriminatedUnion
|
|
1220
|
-
export interface ZodDiscriminatedUnion<Options extends readonly core
|
|
1221
|
-
extends ZodUnion<Options
|
|
1232
|
+
export interface ZodDiscriminatedUnion<Options extends readonly core.SomeType[] = readonly core.$ZodType[]>
|
|
1233
|
+
extends ZodUnion<Options>,
|
|
1234
|
+
core.$ZodDiscriminatedUnion<Options> {
|
|
1222
1235
|
_zod: core.$ZodDiscriminatedUnionInternals<Options>;
|
|
1223
1236
|
}
|
|
1224
1237
|
export const ZodDiscriminatedUnion: core.$constructor<ZodDiscriminatedUnion> = /*@__PURE__*/ core.$constructor(
|
|
1225
1238
|
"ZodDiscriminatedUnion",
|
|
1226
1239
|
(inst, def) => {
|
|
1240
|
+
ZodUnion.init(inst, def);
|
|
1227
1241
|
core.$ZodDiscriminatedUnion.init(inst, def);
|
|
1228
|
-
ZodType.init(inst, def);
|
|
1229
1242
|
}
|
|
1230
1243
|
);
|
|
1231
1244
|
|
|
1232
|
-
export
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
export interface $ZodTypeDiscriminable extends ZodType {
|
|
1237
|
-
_zod: $ZodTypeDiscriminableInternals;
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
export function discriminatedUnion<Types extends [$ZodTypeDiscriminable, ...$ZodTypeDiscriminable[]]>(
|
|
1241
|
-
disc: string,
|
|
1242
|
-
options: Types,
|
|
1243
|
-
params?: string | core.$ZodDiscriminatedUnionParams
|
|
1244
|
-
): ZodDiscriminatedUnion<Types>;
|
|
1245
|
-
export function discriminatedUnion<Types extends [$ZodTypeDiscriminable, ...$ZodTypeDiscriminable[]]>(
|
|
1245
|
+
export function discriminatedUnion<
|
|
1246
|
+
Types extends readonly [core.$ZodTypeDiscriminable, ...core.$ZodTypeDiscriminable[]],
|
|
1247
|
+
>(
|
|
1248
|
+
discriminator: string,
|
|
1246
1249
|
options: Types,
|
|
1247
1250
|
params?: string | core.$ZodDiscriminatedUnionParams
|
|
1248
|
-
): ZodDiscriminatedUnion<Types
|
|
1249
|
-
|
|
1250
|
-
if (typeof args[0] === "string") args = args.slice(1);
|
|
1251
|
-
const [options, params] = args;
|
|
1251
|
+
): ZodDiscriminatedUnion<Types> {
|
|
1252
|
+
// const [options, params] = args;
|
|
1252
1253
|
return new ZodDiscriminatedUnion({
|
|
1253
1254
|
type: "union",
|
|
1254
1255
|
options,
|
|
1256
|
+
discriminator,
|
|
1255
1257
|
...util.normalizeParams(params),
|
|
1256
|
-
});
|
|
1258
|
+
}) as any;
|
|
1257
1259
|
}
|
|
1258
1260
|
|
|
1259
1261
|
// ZodIntersection
|
|
1260
|
-
export interface ZodIntersection<A extends core
|
|
1261
|
-
extends
|
|
1262
|
-
|
|
1263
|
-
}
|
|
1262
|
+
export interface ZodIntersection<A extends core.SomeType = core.$ZodType, B extends core.SomeType = core.$ZodType>
|
|
1263
|
+
extends _ZodType<core.$ZodIntersectionInternals<A, B>>,
|
|
1264
|
+
core.$ZodIntersection<A, B> {}
|
|
1264
1265
|
export const ZodIntersection: core.$constructor<ZodIntersection> = /*@__PURE__*/ core.$constructor(
|
|
1265
1266
|
"ZodIntersection",
|
|
1266
1267
|
(inst, def) => {
|
|
@@ -1269,26 +1270,24 @@ export const ZodIntersection: core.$constructor<ZodIntersection> = /*@__PURE__*/
|
|
|
1269
1270
|
}
|
|
1270
1271
|
);
|
|
1271
1272
|
|
|
1272
|
-
export function intersection<T extends core
|
|
1273
|
+
export function intersection<T extends core.SomeType, U extends core.SomeType>(
|
|
1273
1274
|
left: T,
|
|
1274
|
-
right: U
|
|
1275
|
-
params?: string | core.$ZodIntersectionParams
|
|
1275
|
+
right: U
|
|
1276
1276
|
): ZodIntersection<T, U> {
|
|
1277
1277
|
return new ZodIntersection({
|
|
1278
1278
|
type: "intersection",
|
|
1279
|
-
left,
|
|
1280
|
-
right,
|
|
1281
|
-
|
|
1282
|
-
}) as ZodIntersection<T, U>;
|
|
1279
|
+
left: left as any as core.$ZodType,
|
|
1280
|
+
right: right as any as core.$ZodType,
|
|
1281
|
+
}) as any;
|
|
1283
1282
|
}
|
|
1284
1283
|
|
|
1285
1284
|
// ZodTuple
|
|
1286
1285
|
export interface ZodTuple<
|
|
1287
|
-
T extends util.TupleItems =
|
|
1288
|
-
Rest extends core
|
|
1289
|
-
> extends
|
|
1290
|
-
|
|
1291
|
-
rest<Rest extends core.$ZodType>(rest: Rest): ZodTuple<T, Rest>;
|
|
1286
|
+
T extends util.TupleItems = readonly core.$ZodType[],
|
|
1287
|
+
Rest extends core.SomeType | null = core.$ZodType | null,
|
|
1288
|
+
> extends _ZodType<core.$ZodTupleInternals<T, Rest>>,
|
|
1289
|
+
core.$ZodTuple<T, Rest> {
|
|
1290
|
+
rest<Rest extends core.SomeType = core.$ZodType>(rest: Rest): ZodTuple<T, Rest>;
|
|
1292
1291
|
}
|
|
1293
1292
|
export const ZodTuple: core.$constructor<ZodTuple> = /*@__PURE__*/ core.$constructor("ZodTuple", (inst, def) => {
|
|
1294
1293
|
core.$ZodTuple.init(inst, def);
|
|
@@ -1296,23 +1295,23 @@ export const ZodTuple: core.$constructor<ZodTuple> = /*@__PURE__*/ core.$constru
|
|
|
1296
1295
|
inst.rest = (rest) =>
|
|
1297
1296
|
inst.clone({
|
|
1298
1297
|
...inst._zod.def,
|
|
1299
|
-
rest,
|
|
1298
|
+
rest: rest as any as core.$ZodType,
|
|
1300
1299
|
}) as any;
|
|
1301
1300
|
});
|
|
1302
1301
|
|
|
1303
|
-
export function tuple<T extends readonly [core
|
|
1302
|
+
export function tuple<T extends readonly [core.SomeType, ...core.SomeType[]]>(
|
|
1304
1303
|
items: T,
|
|
1305
1304
|
params?: string | core.$ZodTupleParams
|
|
1306
1305
|
): ZodTuple<T, null>;
|
|
1307
|
-
export function tuple<T extends readonly [core
|
|
1306
|
+
export function tuple<T extends readonly [core.SomeType, ...core.SomeType[]], Rest extends core.SomeType>(
|
|
1308
1307
|
items: T,
|
|
1309
1308
|
rest: Rest,
|
|
1310
1309
|
params?: string | core.$ZodTupleParams
|
|
1311
1310
|
): ZodTuple<T, Rest>;
|
|
1312
1311
|
export function tuple(items: [], params?: string | core.$ZodTupleParams): ZodTuple<[], null>;
|
|
1313
1312
|
export function tuple(
|
|
1314
|
-
items: core
|
|
1315
|
-
_paramsOrRest?: string | core.$ZodTupleParams | core
|
|
1313
|
+
items: core.SomeType[],
|
|
1314
|
+
_paramsOrRest?: string | core.$ZodTupleParams | core.SomeType,
|
|
1316
1315
|
_params?: string | core.$ZodTupleParams
|
|
1317
1316
|
) {
|
|
1318
1317
|
const hasRest = _paramsOrRest instanceof core.$ZodType;
|
|
@@ -1320,7 +1319,7 @@ export function tuple(
|
|
|
1320
1319
|
const rest = hasRest ? _paramsOrRest : null;
|
|
1321
1320
|
return new ZodTuple({
|
|
1322
1321
|
type: "tuple",
|
|
1323
|
-
items,
|
|
1322
|
+
items: items as any as core.$ZodType[],
|
|
1324
1323
|
rest,
|
|
1325
1324
|
...util.normalizeParams(params),
|
|
1326
1325
|
});
|
|
@@ -1329,9 +1328,9 @@ export function tuple(
|
|
|
1329
1328
|
// ZodRecord
|
|
1330
1329
|
export interface ZodRecord<
|
|
1331
1330
|
Key extends core.$ZodRecordKey = core.$ZodRecordKey,
|
|
1332
|
-
Value extends core
|
|
1333
|
-
> extends
|
|
1334
|
-
|
|
1331
|
+
Value extends core.SomeType = core.$ZodType,
|
|
1332
|
+
> extends _ZodType<core.$ZodRecordInternals<Key, Value>>,
|
|
1333
|
+
core.$ZodRecord<Key, Value> {
|
|
1335
1334
|
keyType: Key;
|
|
1336
1335
|
valueType: Value;
|
|
1337
1336
|
}
|
|
@@ -1343,7 +1342,7 @@ export const ZodRecord: core.$constructor<ZodRecord> = /*@__PURE__*/ core.$const
|
|
|
1343
1342
|
inst.valueType = def.valueType;
|
|
1344
1343
|
});
|
|
1345
1344
|
|
|
1346
|
-
export function record<Key extends core.$ZodRecordKey, Value extends core
|
|
1345
|
+
export function record<Key extends core.$ZodRecordKey, Value extends core.SomeType>(
|
|
1347
1346
|
keyType: Key,
|
|
1348
1347
|
valueType: Value,
|
|
1349
1348
|
params?: string | core.$ZodRecordParams
|
|
@@ -1351,29 +1350,28 @@ export function record<Key extends core.$ZodRecordKey, Value extends core.$ZodTy
|
|
|
1351
1350
|
return new ZodRecord({
|
|
1352
1351
|
type: "record",
|
|
1353
1352
|
keyType,
|
|
1354
|
-
valueType,
|
|
1353
|
+
valueType: valueType as any as core.$ZodType,
|
|
1355
1354
|
...util.normalizeParams(params),
|
|
1356
|
-
}) as
|
|
1355
|
+
}) as any;
|
|
1357
1356
|
}
|
|
1358
|
-
|
|
1359
|
-
export function partialRecord<Key extends core.$ZodRecordKey, Value extends core
|
|
1357
|
+
// type alksjf = core.output<core.$ZodRecordKey>;
|
|
1358
|
+
export function partialRecord<Key extends core.$ZodRecordKey, Value extends core.SomeType>(
|
|
1360
1359
|
keyType: Key,
|
|
1361
1360
|
valueType: Value,
|
|
1362
1361
|
params?: string | core.$ZodRecordParams
|
|
1363
|
-
): ZodRecord<
|
|
1362
|
+
): ZodRecord<Key & core.$partial, Value> {
|
|
1364
1363
|
return new ZodRecord({
|
|
1365
1364
|
type: "record",
|
|
1366
1365
|
keyType: union([keyType, never()]),
|
|
1367
|
-
valueType,
|
|
1366
|
+
valueType: valueType as any,
|
|
1368
1367
|
...util.normalizeParams(params),
|
|
1369
|
-
}) as
|
|
1368
|
+
}) as any;
|
|
1370
1369
|
}
|
|
1371
1370
|
|
|
1372
1371
|
// ZodMap
|
|
1373
|
-
export interface ZodMap<Key extends core
|
|
1374
|
-
extends
|
|
1375
|
-
|
|
1376
|
-
|
|
1372
|
+
export interface ZodMap<Key extends core.SomeType = core.$ZodType, Value extends core.SomeType = core.$ZodType>
|
|
1373
|
+
extends _ZodType<core.$ZodMapInternals<Key, Value>>,
|
|
1374
|
+
core.$ZodMap<Key, Value> {
|
|
1377
1375
|
keyType: Key;
|
|
1378
1376
|
valueType: Value;
|
|
1379
1377
|
}
|
|
@@ -1384,22 +1382,23 @@ export const ZodMap: core.$constructor<ZodMap> = /*@__PURE__*/ core.$constructor
|
|
|
1384
1382
|
inst.valueType = def.valueType;
|
|
1385
1383
|
});
|
|
1386
1384
|
|
|
1387
|
-
export function map<Key extends core
|
|
1385
|
+
export function map<Key extends core.SomeType, Value extends core.SomeType>(
|
|
1388
1386
|
keyType: Key,
|
|
1389
1387
|
valueType: Value,
|
|
1390
1388
|
params?: string | core.$ZodMapParams
|
|
1391
1389
|
): ZodMap<Key, Value> {
|
|
1392
1390
|
return new ZodMap({
|
|
1393
1391
|
type: "map",
|
|
1394
|
-
keyType,
|
|
1395
|
-
valueType,
|
|
1392
|
+
keyType: keyType as any as core.$ZodType,
|
|
1393
|
+
valueType: valueType as any as core.$ZodType,
|
|
1396
1394
|
...util.normalizeParams(params),
|
|
1397
|
-
}) as
|
|
1395
|
+
}) as any;
|
|
1398
1396
|
}
|
|
1399
1397
|
|
|
1400
1398
|
// ZodSet
|
|
1401
|
-
export interface ZodSet<T extends core
|
|
1402
|
-
|
|
1399
|
+
export interface ZodSet<T extends core.SomeType = core.$ZodType>
|
|
1400
|
+
extends _ZodType<core.$ZodSetInternals<T>>,
|
|
1401
|
+
core.$ZodSet<T> {
|
|
1403
1402
|
min(minSize: number, params?: string | core.$ZodCheckMinSizeParams): this;
|
|
1404
1403
|
/** */
|
|
1405
1404
|
nonempty(params?: string | core.$ZodCheckMinSizeParams): this;
|
|
@@ -1416,22 +1415,23 @@ export const ZodSet: core.$constructor<ZodSet> = /*@__PURE__*/ core.$constructor
|
|
|
1416
1415
|
inst.size = (...args) => inst.check(core._size(...args));
|
|
1417
1416
|
});
|
|
1418
1417
|
|
|
1419
|
-
export function set<Value extends core
|
|
1418
|
+
export function set<Value extends core.SomeType>(
|
|
1420
1419
|
valueType: Value,
|
|
1421
1420
|
params?: string | core.$ZodSetParams
|
|
1422
1421
|
): ZodSet<Value> {
|
|
1423
1422
|
return new ZodSet({
|
|
1424
1423
|
type: "set",
|
|
1425
|
-
valueType,
|
|
1424
|
+
valueType: valueType as any as core.$ZodType,
|
|
1426
1425
|
...util.normalizeParams(params),
|
|
1427
|
-
}) as
|
|
1426
|
+
}) as any;
|
|
1428
1427
|
}
|
|
1429
1428
|
|
|
1430
1429
|
// ZodEnum
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1430
|
+
export interface ZodEnum<
|
|
1431
|
+
/** @ts-ignore Cast variance */
|
|
1432
|
+
out T extends util.EnumLike = util.EnumLike,
|
|
1433
|
+
> extends _ZodType<core.$ZodEnumInternals<T>>,
|
|
1434
|
+
core.$ZodEnum<T> {
|
|
1435
1435
|
enum: T;
|
|
1436
1436
|
options: Array<T[keyof T]>;
|
|
1437
1437
|
|
|
@@ -1516,17 +1516,28 @@ export function nativeEnum<T extends util.EnumLike>(entries: T, params?: string
|
|
|
1516
1516
|
}
|
|
1517
1517
|
|
|
1518
1518
|
// ZodLiteral
|
|
1519
|
-
export interface ZodLiteral<T extends util.
|
|
1520
|
-
|
|
1519
|
+
export interface ZodLiteral<T extends util.Literal = util.Literal>
|
|
1520
|
+
extends _ZodType<core.$ZodLiteralInternals<T>>,
|
|
1521
|
+
core.$ZodLiteral<T> {
|
|
1521
1522
|
values: Set<T>;
|
|
1523
|
+
/** @legacy Use `.values` instead. Accessing this property will throw an error if the literal accepts multiple values. */
|
|
1524
|
+
value: T;
|
|
1522
1525
|
}
|
|
1523
1526
|
export const ZodLiteral: core.$constructor<ZodLiteral> = /*@__PURE__*/ core.$constructor("ZodLiteral", (inst, def) => {
|
|
1524
1527
|
core.$ZodLiteral.init(inst, def);
|
|
1525
1528
|
ZodType.init(inst, def);
|
|
1526
1529
|
inst.values = new Set(def.values);
|
|
1530
|
+
Object.defineProperty(inst, "value", {
|
|
1531
|
+
get() {
|
|
1532
|
+
if (def.values.length > 1) {
|
|
1533
|
+
throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
|
|
1534
|
+
}
|
|
1535
|
+
return def.values[0];
|
|
1536
|
+
},
|
|
1537
|
+
});
|
|
1527
1538
|
});
|
|
1528
1539
|
|
|
1529
|
-
export function literal<const T extends
|
|
1540
|
+
export function literal<const T extends ReadonlyArray<util.Literal>>(
|
|
1530
1541
|
value: T,
|
|
1531
1542
|
params?: string | core.$ZodLiteralParams
|
|
1532
1543
|
): ZodLiteral<T[number]>;
|
|
@@ -1543,12 +1554,10 @@ export function literal(value: any, params: any) {
|
|
|
1543
1554
|
}
|
|
1544
1555
|
|
|
1545
1556
|
// ZodFile
|
|
1546
|
-
export interface ZodFile extends
|
|
1547
|
-
_zod: core.$ZodFileInternals;
|
|
1548
|
-
|
|
1557
|
+
export interface ZodFile extends _ZodType<core.$ZodFileInternals>, core.$ZodFile {
|
|
1549
1558
|
min(size: number, params?: string | core.$ZodCheckMinSizeParams): this;
|
|
1550
1559
|
max(size: number, params?: string | core.$ZodCheckMaxSizeParams): this;
|
|
1551
|
-
mime(types: Array<util.MimeTypes>, params?: string | core.$ZodCheckMimeTypeParams): this;
|
|
1560
|
+
mime(types: util.MimeTypes | Array<util.MimeTypes>, params?: string | core.$ZodCheckMimeTypeParams): this;
|
|
1552
1561
|
}
|
|
1553
1562
|
export const ZodFile: core.$constructor<ZodFile> = /*@__PURE__*/ core.$constructor("ZodFile", (inst, def) => {
|
|
1554
1563
|
core.$ZodFile.init(inst, def);
|
|
@@ -1556,7 +1565,7 @@ export const ZodFile: core.$constructor<ZodFile> = /*@__PURE__*/ core.$construct
|
|
|
1556
1565
|
|
|
1557
1566
|
inst.min = (size, params) => inst.check(core._minSize(size, params));
|
|
1558
1567
|
inst.max = (size, params) => inst.check(core._maxSize(size, params));
|
|
1559
|
-
inst.mime = (types, params) => inst.check(core._mime(types, params));
|
|
1568
|
+
inst.mime = (types, params) => inst.check(core._mime(Array.isArray(types) ? types : [types], params));
|
|
1560
1569
|
});
|
|
1561
1570
|
|
|
1562
1571
|
export function file(params?: string | core.$ZodFileParams): ZodFile {
|
|
@@ -1564,9 +1573,9 @@ export function file(params?: string | core.$ZodFileParams): ZodFile {
|
|
|
1564
1573
|
}
|
|
1565
1574
|
|
|
1566
1575
|
// ZodTransform
|
|
1567
|
-
export interface ZodTransform<O = unknown, I = unknown>
|
|
1568
|
-
|
|
1569
|
-
}
|
|
1576
|
+
export interface ZodTransform<O = unknown, I = unknown>
|
|
1577
|
+
extends _ZodType<core.$ZodTransformInternals<O, I>>,
|
|
1578
|
+
core.$ZodTransform<O, I> {}
|
|
1570
1579
|
export const ZodTransform: core.$constructor<ZodTransform> = /*@__PURE__*/ core.$constructor(
|
|
1571
1580
|
"ZodTransform",
|
|
1572
1581
|
(inst, def) => {
|
|
@@ -1585,7 +1594,7 @@ export const ZodTransform: core.$constructor<ZodTransform> = /*@__PURE__*/ core.
|
|
|
1585
1594
|
_issue.code ??= "custom";
|
|
1586
1595
|
_issue.input ??= payload.value;
|
|
1587
1596
|
_issue.inst ??= inst;
|
|
1588
|
-
_issue.continue ??=
|
|
1597
|
+
_issue.continue ??= true;
|
|
1589
1598
|
payload.issues.push(util.issue(_issue));
|
|
1590
1599
|
}
|
|
1591
1600
|
};
|
|
@@ -1604,20 +1613,18 @@ export const ZodTransform: core.$constructor<ZodTransform> = /*@__PURE__*/ core.
|
|
|
1604
1613
|
);
|
|
1605
1614
|
|
|
1606
1615
|
export function transform<I = unknown, O = I>(
|
|
1607
|
-
fn: (input: I, ctx: core.ParsePayload) => O
|
|
1608
|
-
params?: string | core.$ZodTransformParams
|
|
1616
|
+
fn: (input: I, ctx: core.ParsePayload) => O
|
|
1609
1617
|
): ZodTransform<Awaited<O>, I> {
|
|
1610
1618
|
return new ZodTransform({
|
|
1611
1619
|
type: "transform",
|
|
1612
1620
|
transform: fn as any,
|
|
1613
|
-
...util.normalizeParams(params),
|
|
1614
1621
|
}) as any;
|
|
1615
1622
|
}
|
|
1616
1623
|
|
|
1617
1624
|
// ZodOptional
|
|
1618
|
-
export interface ZodOptional<T extends core
|
|
1619
|
-
|
|
1620
|
-
|
|
1625
|
+
export interface ZodOptional<T extends core.SomeType = core.$ZodType>
|
|
1626
|
+
extends _ZodType<core.$ZodOptionalInternals<T>>,
|
|
1627
|
+
core.$ZodOptional<T> {
|
|
1621
1628
|
unwrap(): T;
|
|
1622
1629
|
}
|
|
1623
1630
|
export const ZodOptional: core.$constructor<ZodOptional> = /*@__PURE__*/ core.$constructor(
|
|
@@ -1630,21 +1637,17 @@ export const ZodOptional: core.$constructor<ZodOptional> = /*@__PURE__*/ core.$c
|
|
|
1630
1637
|
}
|
|
1631
1638
|
);
|
|
1632
1639
|
|
|
1633
|
-
export function optional<T extends core
|
|
1634
|
-
innerType: T,
|
|
1635
|
-
params?: string | core.$ZodOptionalParams
|
|
1636
|
-
): ZodOptional<T> {
|
|
1640
|
+
export function optional<T extends core.SomeType>(innerType: T): ZodOptional<T> {
|
|
1637
1641
|
return new ZodOptional({
|
|
1638
1642
|
type: "optional",
|
|
1639
|
-
innerType,
|
|
1640
|
-
|
|
1641
|
-
}) as ZodOptional<T>;
|
|
1643
|
+
innerType: innerType as any as core.$ZodType,
|
|
1644
|
+
}) as any;
|
|
1642
1645
|
}
|
|
1643
1646
|
|
|
1644
1647
|
// ZodNullable
|
|
1645
|
-
export interface ZodNullable<T extends core
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
+
export interface ZodNullable<T extends core.SomeType = core.$ZodType>
|
|
1649
|
+
extends _ZodType<core.$ZodNullableInternals<T>>,
|
|
1650
|
+
core.$ZodNullable<T> {
|
|
1648
1651
|
unwrap(): T;
|
|
1649
1652
|
}
|
|
1650
1653
|
export const ZodNullable: core.$constructor<ZodNullable> = /*@__PURE__*/ core.$constructor(
|
|
@@ -1657,26 +1660,22 @@ export const ZodNullable: core.$constructor<ZodNullable> = /*@__PURE__*/ core.$c
|
|
|
1657
1660
|
}
|
|
1658
1661
|
);
|
|
1659
1662
|
|
|
1660
|
-
export function nullable<T extends core
|
|
1661
|
-
innerType: T,
|
|
1662
|
-
params?: string | core.$ZodNullableParams
|
|
1663
|
-
): ZodNullable<T> {
|
|
1663
|
+
export function nullable<T extends core.SomeType>(innerType: T): ZodNullable<T> {
|
|
1664
1664
|
return new ZodNullable({
|
|
1665
1665
|
type: "nullable",
|
|
1666
|
-
innerType,
|
|
1667
|
-
|
|
1668
|
-
}) as ZodNullable<T>;
|
|
1666
|
+
innerType: innerType as any as core.$ZodType,
|
|
1667
|
+
}) as any;
|
|
1669
1668
|
}
|
|
1670
1669
|
|
|
1671
1670
|
// nullish
|
|
1672
|
-
export function nullish<T extends core
|
|
1671
|
+
export function nullish<T extends core.SomeType>(innerType: T): ZodOptional<ZodNullable<T>> {
|
|
1673
1672
|
return optional(nullable(innerType));
|
|
1674
1673
|
}
|
|
1675
1674
|
|
|
1676
1675
|
// ZodDefault
|
|
1677
|
-
export interface ZodDefault<T extends core
|
|
1678
|
-
|
|
1679
|
-
|
|
1676
|
+
export interface ZodDefault<T extends core.SomeType = core.$ZodType>
|
|
1677
|
+
extends _ZodType<core.$ZodDefaultInternals<T>>,
|
|
1678
|
+
core.$ZodDefault<T> {
|
|
1680
1679
|
unwrap(): T;
|
|
1681
1680
|
/** @deprecated Use `.unwrap()` instead. */
|
|
1682
1681
|
removeDefault(): T;
|
|
@@ -1689,23 +1688,51 @@ export const ZodDefault: core.$constructor<ZodDefault> = /*@__PURE__*/ core.$con
|
|
|
1689
1688
|
inst.removeDefault = inst.unwrap;
|
|
1690
1689
|
});
|
|
1691
1690
|
|
|
1692
|
-
export function _default<T extends core
|
|
1691
|
+
export function _default<T extends core.SomeType>(
|
|
1693
1692
|
innerType: T,
|
|
1694
|
-
defaultValue: util.NoUndefined<core.output<T>> | (() => util.NoUndefined<core.output<T>>)
|
|
1695
|
-
params?: string | core.$ZodDefaultParams
|
|
1693
|
+
defaultValue: util.NoUndefined<core.output<T>> | (() => util.NoUndefined<core.output<T>>)
|
|
1696
1694
|
): ZodDefault<T> {
|
|
1697
1695
|
return new ZodDefault({
|
|
1698
1696
|
type: "default",
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1697
|
+
innerType: innerType as any as core.$ZodType,
|
|
1698
|
+
get defaultValue() {
|
|
1699
|
+
return typeof defaultValue === "function" ? (defaultValue as Function)() : defaultValue;
|
|
1700
|
+
},
|
|
1701
|
+
}) as any;
|
|
1703
1702
|
}
|
|
1704
1703
|
|
|
1705
|
-
//
|
|
1706
|
-
export interface
|
|
1707
|
-
|
|
1704
|
+
// ZodPrefault
|
|
1705
|
+
export interface ZodPrefault<T extends core.SomeType = core.$ZodType>
|
|
1706
|
+
extends _ZodType<core.$ZodPrefaultInternals<T>>,
|
|
1707
|
+
core.$ZodPrefault<T> {
|
|
1708
|
+
unwrap(): T;
|
|
1709
|
+
}
|
|
1710
|
+
export const ZodPrefault: core.$constructor<ZodPrefault> = /*@__PURE__*/ core.$constructor(
|
|
1711
|
+
"ZodPrefault",
|
|
1712
|
+
(inst, def) => {
|
|
1713
|
+
core.$ZodPrefault.init(inst, def);
|
|
1714
|
+
ZodType.init(inst, def);
|
|
1715
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
1716
|
+
}
|
|
1717
|
+
);
|
|
1718
|
+
|
|
1719
|
+
export function prefault<T extends core.SomeType>(
|
|
1720
|
+
innerType: T,
|
|
1721
|
+
defaultValue: core.input<T> | (() => core.input<T>)
|
|
1722
|
+
): ZodPrefault<T> {
|
|
1723
|
+
return new ZodPrefault({
|
|
1724
|
+
type: "prefault",
|
|
1725
|
+
innerType: innerType as any as core.$ZodType,
|
|
1726
|
+
get defaultValue() {
|
|
1727
|
+
return typeof defaultValue === "function" ? (defaultValue as Function)() : defaultValue;
|
|
1728
|
+
},
|
|
1729
|
+
}) as any;
|
|
1730
|
+
}
|
|
1708
1731
|
|
|
1732
|
+
// ZodNonOptional
|
|
1733
|
+
export interface ZodNonOptional<T extends core.SomeType = core.$ZodType>
|
|
1734
|
+
extends _ZodType<core.$ZodNonOptionalInternals<T>>,
|
|
1735
|
+
core.$ZodNonOptional<T> {
|
|
1709
1736
|
unwrap(): T;
|
|
1710
1737
|
}
|
|
1711
1738
|
export const ZodNonOptional: core.$constructor<ZodNonOptional> = /*@__PURE__*/ core.$constructor(
|
|
@@ -1718,21 +1745,21 @@ export const ZodNonOptional: core.$constructor<ZodNonOptional> = /*@__PURE__*/ c
|
|
|
1718
1745
|
}
|
|
1719
1746
|
);
|
|
1720
1747
|
|
|
1721
|
-
export function nonoptional<T extends core
|
|
1748
|
+
export function nonoptional<T extends core.SomeType>(
|
|
1722
1749
|
innerType: T,
|
|
1723
1750
|
params?: string | core.$ZodNonOptionalParams
|
|
1724
1751
|
): ZodNonOptional<T> {
|
|
1725
1752
|
return new ZodNonOptional({
|
|
1726
1753
|
type: "nonoptional",
|
|
1727
|
-
innerType,
|
|
1754
|
+
innerType: innerType as any as core.$ZodType,
|
|
1728
1755
|
...util.normalizeParams(params),
|
|
1729
|
-
}) as
|
|
1756
|
+
}) as any;
|
|
1730
1757
|
}
|
|
1731
1758
|
|
|
1732
1759
|
// ZodSuccess
|
|
1733
|
-
export interface ZodSuccess<T extends core
|
|
1734
|
-
|
|
1735
|
-
|
|
1760
|
+
export interface ZodSuccess<T extends core.SomeType = core.$ZodType>
|
|
1761
|
+
extends _ZodType<core.$ZodSuccessInternals<T>>,
|
|
1762
|
+
core.$ZodSuccess<T> {
|
|
1736
1763
|
unwrap(): T;
|
|
1737
1764
|
}
|
|
1738
1765
|
export const ZodSuccess: core.$constructor<ZodSuccess> = /*@__PURE__*/ core.$constructor("ZodSuccess", (inst, def) => {
|
|
@@ -1742,21 +1769,17 @@ export const ZodSuccess: core.$constructor<ZodSuccess> = /*@__PURE__*/ core.$con
|
|
|
1742
1769
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
1743
1770
|
});
|
|
1744
1771
|
|
|
1745
|
-
export function success<T extends core
|
|
1746
|
-
innerType: T,
|
|
1747
|
-
params?: string | core.$ZodSuccessParams
|
|
1748
|
-
): ZodSuccess<T> {
|
|
1772
|
+
export function success<T extends core.SomeType>(innerType: T): ZodSuccess<T> {
|
|
1749
1773
|
return new ZodSuccess({
|
|
1750
1774
|
type: "success",
|
|
1751
|
-
innerType,
|
|
1752
|
-
|
|
1753
|
-
}) as ZodSuccess<T>;
|
|
1775
|
+
innerType: innerType as any as core.$ZodType,
|
|
1776
|
+
}) as any;
|
|
1754
1777
|
}
|
|
1755
1778
|
|
|
1756
1779
|
// ZodCatch
|
|
1757
|
-
export interface ZodCatch<T extends core
|
|
1758
|
-
|
|
1759
|
-
|
|
1780
|
+
export interface ZodCatch<T extends core.SomeType = core.$ZodType>
|
|
1781
|
+
extends _ZodType<core.$ZodCatchInternals<T>>,
|
|
1782
|
+
core.$ZodCatch<T> {
|
|
1760
1783
|
unwrap(): T;
|
|
1761
1784
|
/** @deprecated Use `.unwrap()` instead. */
|
|
1762
1785
|
removeCatch(): T;
|
|
@@ -1769,26 +1792,22 @@ export const ZodCatch: core.$constructor<ZodCatch> = /*@__PURE__*/ core.$constru
|
|
|
1769
1792
|
inst.removeCatch = inst.unwrap;
|
|
1770
1793
|
});
|
|
1771
1794
|
|
|
1772
|
-
function _catch<T extends core
|
|
1795
|
+
function _catch<T extends core.SomeType>(
|
|
1773
1796
|
innerType: T,
|
|
1774
|
-
catchValue: core.output<T> | ((ctx: core.$ZodCatchCtx) => core.output<T>)
|
|
1775
|
-
params?: string | core.$ZodCatchParams
|
|
1797
|
+
catchValue: core.output<T> | ((ctx: core.$ZodCatchCtx) => core.output<T>)
|
|
1776
1798
|
): ZodCatch<T> {
|
|
1777
1799
|
return new ZodCatch({
|
|
1778
1800
|
type: "catch",
|
|
1779
|
-
innerType,
|
|
1801
|
+
innerType: innerType as any as core.$ZodType,
|
|
1780
1802
|
catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue) as (
|
|
1781
1803
|
ctx: core.$ZodCatchCtx
|
|
1782
1804
|
) => core.output<T>,
|
|
1783
|
-
|
|
1784
|
-
}) as ZodCatch<T>;
|
|
1805
|
+
}) as any;
|
|
1785
1806
|
}
|
|
1786
1807
|
export { _catch as catch };
|
|
1787
1808
|
|
|
1788
1809
|
// ZodNaN
|
|
1789
|
-
export interface ZodNaN extends
|
|
1790
|
-
_zod: core.$ZodNaNInternals;
|
|
1791
|
-
}
|
|
1810
|
+
export interface ZodNaN extends _ZodType<core.$ZodNaNInternals>, core.$ZodNaN {}
|
|
1792
1811
|
export const ZodNaN: core.$constructor<ZodNaN> = /*@__PURE__*/ core.$constructor("ZodNaN", (inst, def) => {
|
|
1793
1812
|
core.$ZodNaN.init(inst, def);
|
|
1794
1813
|
ZodType.init(inst, def);
|
|
@@ -1799,10 +1818,9 @@ export function nan(params?: string | core.$ZodNaNParams): ZodNaN {
|
|
|
1799
1818
|
}
|
|
1800
1819
|
|
|
1801
1820
|
// ZodPipe
|
|
1802
|
-
export interface ZodPipe<A extends core
|
|
1803
|
-
extends
|
|
1804
|
-
|
|
1805
|
-
|
|
1821
|
+
export interface ZodPipe<A extends core.SomeType = core.$ZodType, B extends core.SomeType = core.$ZodType>
|
|
1822
|
+
extends _ZodType<core.$ZodPipeInternals<A, B>>,
|
|
1823
|
+
core.$ZodPipe<A, B> {
|
|
1806
1824
|
in: A;
|
|
1807
1825
|
out: B;
|
|
1808
1826
|
}
|
|
@@ -1815,22 +1833,22 @@ export const ZodPipe: core.$constructor<ZodPipe> = /*@__PURE__*/ core.$construct
|
|
|
1815
1833
|
});
|
|
1816
1834
|
|
|
1817
1835
|
export function pipe<
|
|
1818
|
-
const A extends core
|
|
1836
|
+
const A extends core.SomeType,
|
|
1819
1837
|
B extends core.$ZodType<unknown, core.output<A>> = core.$ZodType<unknown, core.output<A>>,
|
|
1820
|
-
>(in_: A, out: B | core.$ZodType<unknown, core.output<A
|
|
1821
|
-
export function pipe(in_: core
|
|
1838
|
+
>(in_: A, out: B | core.$ZodType<unknown, core.output<A>>): ZodPipe<A, B>;
|
|
1839
|
+
export function pipe(in_: core.SomeType, out: core.SomeType) {
|
|
1822
1840
|
return new ZodPipe({
|
|
1823
1841
|
type: "pipe",
|
|
1824
|
-
in: in_,
|
|
1825
|
-
out,
|
|
1826
|
-
...util.normalizeParams(params),
|
|
1842
|
+
in: in_ as unknown as core.$ZodType,
|
|
1843
|
+
out: out as unknown as core.$ZodType,
|
|
1844
|
+
// ...util.normalizeParams(params),
|
|
1827
1845
|
});
|
|
1828
1846
|
}
|
|
1829
1847
|
|
|
1830
1848
|
// ZodReadonly
|
|
1831
|
-
export interface ZodReadonly<T extends core
|
|
1832
|
-
|
|
1833
|
-
}
|
|
1849
|
+
export interface ZodReadonly<T extends core.SomeType = core.$ZodType>
|
|
1850
|
+
extends _ZodType<core.$ZodReadonlyInternals<T>>,
|
|
1851
|
+
core.$ZodReadonly<T> {}
|
|
1834
1852
|
export const ZodReadonly: core.$constructor<ZodReadonly> = /*@__PURE__*/ core.$constructor(
|
|
1835
1853
|
"ZodReadonly",
|
|
1836
1854
|
(inst, def) => {
|
|
@@ -1839,21 +1857,17 @@ export const ZodReadonly: core.$constructor<ZodReadonly> = /*@__PURE__*/ core.$c
|
|
|
1839
1857
|
}
|
|
1840
1858
|
);
|
|
1841
1859
|
|
|
1842
|
-
export function readonly<T extends core
|
|
1843
|
-
innerType: T,
|
|
1844
|
-
params?: string | core.$ZodReadonlyParams
|
|
1845
|
-
): ZodReadonly<T> {
|
|
1860
|
+
export function readonly<T extends core.SomeType>(innerType: T): ZodReadonly<T> {
|
|
1846
1861
|
return new ZodReadonly({
|
|
1847
1862
|
type: "readonly",
|
|
1848
|
-
innerType,
|
|
1849
|
-
|
|
1850
|
-
}) as ZodReadonly<T>;
|
|
1863
|
+
innerType: innerType as any as core.$ZodType,
|
|
1864
|
+
}) as any;
|
|
1851
1865
|
}
|
|
1852
1866
|
|
|
1853
1867
|
// ZodTemplateLiteral
|
|
1854
|
-
export interface ZodTemplateLiteral<Template extends string = string>
|
|
1855
|
-
|
|
1856
|
-
}
|
|
1868
|
+
export interface ZodTemplateLiteral<Template extends string = string>
|
|
1869
|
+
extends _ZodType<core.$ZodTemplateLiteralInternals<Template>>,
|
|
1870
|
+
core.$ZodTemplateLiteral<Template> {}
|
|
1857
1871
|
export const ZodTemplateLiteral: core.$constructor<ZodTemplateLiteral> = /*@__PURE__*/ core.$constructor(
|
|
1858
1872
|
"ZodTemplateLiteral",
|
|
1859
1873
|
(inst, def) => {
|
|
@@ -1862,7 +1876,7 @@ export const ZodTemplateLiteral: core.$constructor<ZodTemplateLiteral> = /*@__PU
|
|
|
1862
1876
|
}
|
|
1863
1877
|
);
|
|
1864
1878
|
|
|
1865
|
-
export function templateLiteral<const Parts extends core.$
|
|
1879
|
+
export function templateLiteral<const Parts extends core.$ZodTemplateLiteralPart[]>(
|
|
1866
1880
|
parts: Parts,
|
|
1867
1881
|
params?: string | core.$ZodTemplateLiteralParams
|
|
1868
1882
|
): ZodTemplateLiteral<core.$PartsToTemplateLiteral<Parts>> {
|
|
@@ -1874,9 +1888,9 @@ export function templateLiteral<const Parts extends core.$TemplateLiteralPart[]>
|
|
|
1874
1888
|
}
|
|
1875
1889
|
|
|
1876
1890
|
// ZodLazy
|
|
1877
|
-
export interface ZodLazy<T extends core
|
|
1878
|
-
|
|
1879
|
-
|
|
1891
|
+
export interface ZodLazy<T extends core.SomeType = core.$ZodType>
|
|
1892
|
+
extends _ZodType<core.$ZodLazyInternals<T>>,
|
|
1893
|
+
core.$ZodLazy<T> {
|
|
1880
1894
|
unwrap(): T;
|
|
1881
1895
|
}
|
|
1882
1896
|
export const ZodLazy: core.$constructor<ZodLazy> = /*@__PURE__*/ core.$constructor("ZodLazy", (inst, def) => {
|
|
@@ -1886,17 +1900,17 @@ export const ZodLazy: core.$constructor<ZodLazy> = /*@__PURE__*/ core.$construct
|
|
|
1886
1900
|
inst.unwrap = () => inst._zod.def.getter();
|
|
1887
1901
|
});
|
|
1888
1902
|
|
|
1889
|
-
export function lazy<T extends core
|
|
1903
|
+
export function lazy<T extends core.SomeType>(getter: () => T): ZodLazy<T> {
|
|
1890
1904
|
return new ZodLazy({
|
|
1891
1905
|
type: "lazy",
|
|
1892
|
-
getter,
|
|
1893
|
-
}) as
|
|
1906
|
+
getter: getter as any,
|
|
1907
|
+
}) as any;
|
|
1894
1908
|
}
|
|
1895
1909
|
|
|
1896
1910
|
// ZodPromise
|
|
1897
|
-
export interface ZodPromise<T extends core
|
|
1898
|
-
|
|
1899
|
-
|
|
1911
|
+
export interface ZodPromise<T extends core.SomeType = core.$ZodType>
|
|
1912
|
+
extends _ZodType<core.$ZodPromiseInternals<T>>,
|
|
1913
|
+
core.$ZodPromise<T> {
|
|
1900
1914
|
unwrap(): T;
|
|
1901
1915
|
}
|
|
1902
1916
|
export const ZodPromise: core.$constructor<ZodPromise> = /*@__PURE__*/ core.$constructor("ZodPromise", (inst, def) => {
|
|
@@ -1906,41 +1920,37 @@ export const ZodPromise: core.$constructor<ZodPromise> = /*@__PURE__*/ core.$con
|
|
|
1906
1920
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
1907
1921
|
});
|
|
1908
1922
|
|
|
1909
|
-
export function promise<T extends core
|
|
1910
|
-
innerType: T,
|
|
1911
|
-
params?: string | core.$ZodPromiseParams
|
|
1912
|
-
): ZodPromise<T> {
|
|
1923
|
+
export function promise<T extends core.SomeType>(innerType: T): ZodPromise<T> {
|
|
1913
1924
|
return new ZodPromise({
|
|
1914
1925
|
type: "promise",
|
|
1915
|
-
innerType,
|
|
1916
|
-
|
|
1917
|
-
}) as ZodPromise<T>;
|
|
1926
|
+
innerType: innerType as any as core.$ZodType,
|
|
1927
|
+
}) as any;
|
|
1918
1928
|
}
|
|
1919
1929
|
|
|
1920
1930
|
// ZodCustom
|
|
1921
|
-
export interface ZodCustom<O = unknown, I = unknown>
|
|
1922
|
-
|
|
1923
|
-
}
|
|
1931
|
+
export interface ZodCustom<O = unknown, I = unknown>
|
|
1932
|
+
extends _ZodType<core.$ZodCustomInternals<O, I>>,
|
|
1933
|
+
core.$ZodCustom<O, I> {}
|
|
1924
1934
|
export const ZodCustom: core.$constructor<ZodCustom> = /*@__PURE__*/ core.$constructor("ZodCustom", (inst, def) => {
|
|
1925
1935
|
core.$ZodCustom.init(inst, def);
|
|
1926
1936
|
ZodType.init(inst, def);
|
|
1927
1937
|
});
|
|
1928
1938
|
|
|
1929
1939
|
// custom checks
|
|
1930
|
-
export function check<O = unknown>(fn: core.CheckFn<O
|
|
1940
|
+
export function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<O> {
|
|
1931
1941
|
const ch = new core.$ZodCheck({
|
|
1932
1942
|
check: "custom",
|
|
1933
|
-
...util.normalizeParams(params),
|
|
1943
|
+
// ...util.normalizeParams(params),
|
|
1934
1944
|
});
|
|
1935
1945
|
|
|
1936
1946
|
ch._zod.check = fn;
|
|
1937
1947
|
return ch;
|
|
1938
1948
|
}
|
|
1939
1949
|
|
|
1940
|
-
export function custom<O
|
|
1941
|
-
fn?: (data:
|
|
1950
|
+
export function custom<O>(
|
|
1951
|
+
fn?: (data: unknown) => unknown,
|
|
1942
1952
|
_params?: string | core.$ZodCustomParams | undefined
|
|
1943
|
-
): ZodCustom<O,
|
|
1953
|
+
): ZodCustom<O, O> {
|
|
1944
1954
|
return core._custom(ZodCustom, fn ?? (() => true), _params) as any;
|
|
1945
1955
|
}
|
|
1946
1956
|
|
|
@@ -1948,14 +1958,11 @@ export function refine<T>(
|
|
|
1948
1958
|
fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>,
|
|
1949
1959
|
_params: string | core.$ZodCustomParams = {}
|
|
1950
1960
|
): core.$ZodCheck<T> {
|
|
1951
|
-
return core.
|
|
1961
|
+
return core._refine(ZodCustom, fn, _params);
|
|
1952
1962
|
}
|
|
1953
1963
|
|
|
1954
1964
|
// superRefine
|
|
1955
|
-
export function superRefine<T>(
|
|
1956
|
-
fn: (arg: T, payload: RefinementCtx<T>) => void | Promise<void>,
|
|
1957
|
-
params?: string | core.$ZodCustomParams
|
|
1958
|
-
): core.$ZodCheck<T> {
|
|
1965
|
+
export function superRefine<T>(fn: (arg: T, payload: RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T> {
|
|
1959
1966
|
const ch = check<T>((payload) => {
|
|
1960
1967
|
(payload as RefinementCtx).addIssue = (issue) => {
|
|
1961
1968
|
if (typeof issue === "string") {
|
|
@@ -1973,52 +1980,60 @@ export function superRefine<T>(
|
|
|
1973
1980
|
};
|
|
1974
1981
|
|
|
1975
1982
|
return fn(payload.value, payload as RefinementCtx<T>);
|
|
1976
|
-
}
|
|
1983
|
+
});
|
|
1977
1984
|
return ch;
|
|
1978
1985
|
}
|
|
1979
1986
|
|
|
1980
|
-
|
|
1981
|
-
abstract class Class {
|
|
1982
|
-
constructor(..._args: any[]) {}
|
|
1983
|
-
}
|
|
1984
|
-
type ZodInstanceOfParams = util.Params<
|
|
1987
|
+
type ZodInstanceOfParams = core.Params<
|
|
1985
1988
|
ZodCustom,
|
|
1986
1989
|
core.$ZodIssueCustom,
|
|
1987
1990
|
"type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path"
|
|
1988
1991
|
>;
|
|
1989
|
-
function _instanceof<T extends typeof Class>(
|
|
1992
|
+
function _instanceof<T extends typeof util.Class>(
|
|
1990
1993
|
cls: T,
|
|
1991
1994
|
params: ZodInstanceOfParams = {
|
|
1992
1995
|
error: `Input not instance of ${cls.name}`,
|
|
1993
1996
|
}
|
|
1994
|
-
): ZodCustom<InstanceType<T>> {
|
|
1995
|
-
|
|
1997
|
+
): ZodCustom<InstanceType<T>, InstanceType<T>> {
|
|
1998
|
+
const inst = new ZodCustom({
|
|
1996
1999
|
type: "custom",
|
|
1997
2000
|
check: "custom",
|
|
1998
2001
|
fn: (data) => data instanceof cls,
|
|
1999
2002
|
abort: true,
|
|
2000
2003
|
...(util.normalizeParams(params) as any),
|
|
2001
|
-
})
|
|
2004
|
+
});
|
|
2005
|
+
inst._zod.bag.Class = cls;
|
|
2006
|
+
return inst as any;
|
|
2002
2007
|
}
|
|
2003
2008
|
export { _instanceof as instanceof };
|
|
2004
2009
|
|
|
2005
2010
|
// stringbool
|
|
2006
|
-
export const stringbool: (
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2011
|
+
export const stringbool: (
|
|
2012
|
+
_params?: string | core.$ZodStringBoolParams
|
|
2013
|
+
) => ZodPipe<ZodPipe<ZodString, ZodTransform<boolean, string>>, ZodBoolean> = (...args) =>
|
|
2014
|
+
core._stringbool(
|
|
2015
|
+
{
|
|
2016
|
+
Pipe: ZodPipe,
|
|
2017
|
+
Boolean: ZodBoolean,
|
|
2018
|
+
String: ZodString,
|
|
2019
|
+
Transform: ZodTransform,
|
|
2020
|
+
},
|
|
2021
|
+
...args
|
|
2022
|
+
) as any;
|
|
2012
2023
|
|
|
2013
2024
|
// json
|
|
2014
|
-
|
|
2025
|
+
type _ZodJSONSchema = ZodUnion<
|
|
2015
2026
|
[ZodString, ZodNumber, ZodBoolean, ZodNull, ZodArray<ZodJSONSchema>, ZodRecord<ZodString, ZodJSONSchema>]
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2027
|
+
>;
|
|
2028
|
+
type _ZodJSONSchemaInternals = _ZodJSONSchema["_zod"];
|
|
2029
|
+
|
|
2030
|
+
export interface ZodJSONSchemaInternals extends _ZodJSONSchemaInternals {
|
|
2031
|
+
output: util.JSONType;
|
|
2032
|
+
input: util.JSONType;
|
|
2033
|
+
}
|
|
2034
|
+
export interface ZodJSONSchema extends _ZodJSONSchema {
|
|
2035
|
+
_zod: ZodJSONSchemaInternals;
|
|
2036
|
+
}
|
|
2022
2037
|
|
|
2023
2038
|
export function json(params?: string | core.$ZodCustomParams): ZodJSONSchema {
|
|
2024
2039
|
const jsonSchema: any = lazy(() => {
|
|
@@ -2029,13 +2044,11 @@ export function json(params?: string | core.$ZodCustomParams): ZodJSONSchema {
|
|
|
2029
2044
|
}
|
|
2030
2045
|
|
|
2031
2046
|
// preprocess
|
|
2032
|
-
export interface ZodPreprocessParams extends core.$ZodTransformParams, core.$ZodPipeParams {}
|
|
2033
2047
|
|
|
2034
2048
|
// /** @deprecated Use `z.pipe()` and `z.transform()` instead. */
|
|
2035
|
-
export function preprocess<A, U extends core
|
|
2036
|
-
fn: (arg:
|
|
2037
|
-
schema: U
|
|
2038
|
-
|
|
2039
|
-
)
|
|
2040
|
-
return pipe(transform(fn as any, params), schema as any, params);
|
|
2049
|
+
export function preprocess<A, U extends core.SomeType, B = unknown>(
|
|
2050
|
+
fn: (arg: B, ctx: RefinementCtx) => A,
|
|
2051
|
+
schema: U
|
|
2052
|
+
): ZodPipe<ZodTransform<A, B>, U> {
|
|
2053
|
+
return pipe(transform(fn as any), schema as any) as any;
|
|
2041
2054
|
}
|