@cabloy/zod 4.3.6
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/LICENSE +21 -0
- 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/locales/package.json +7 -0
- package/mini/index.cjs +32 -0
- package/mini/index.d.cts +3 -0
- package/mini/index.d.ts +3 -0
- package/mini/index.js +3 -0
- package/mini/package.json +7 -0
- package/package.json +135 -0
- package/src/index.ts +4 -0
- package/src/locales/index.ts +1 -0
- package/src/mini/index.ts +3 -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 +70 -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 +261 -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 +24 -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 +5138 -0
- package/src/v4/classic/checks.ts +32 -0
- package/src/v4/classic/coerce.ts +27 -0
- package/src/v4/classic/compat.ts +70 -0
- package/src/v4/classic/errors.ts +82 -0
- package/src/v4/classic/external.ts +51 -0
- package/src/v4/classic/from-json-schema.ts +643 -0
- package/src/v4/classic/index.ts +5 -0
- package/src/v4/classic/iso.ts +90 -0
- package/src/v4/classic/parse.ts +82 -0
- package/src/v4/classic/schemas.ts +2409 -0
- package/src/v4/classic/tests/anyunknown.test.ts +26 -0
- package/src/v4/classic/tests/apply.test.ts +59 -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 +106 -0
- package/src/v4/classic/tests/catch.test.ts +276 -0
- package/src/v4/classic/tests/coalesce.test.ts +20 -0
- package/src/v4/classic/tests/codec-examples.test.ts +573 -0
- package/src/v4/classic/tests/codec.test.ts +562 -0
- package/src/v4/classic/tests/coerce.test.ts +160 -0
- package/src/v4/classic/tests/continuability.test.ts +374 -0
- package/src/v4/classic/tests/custom.test.ts +40 -0
- package/src/v4/classic/tests/date.test.ts +62 -0
- package/src/v4/classic/tests/datetime.test.ts +302 -0
- package/src/v4/classic/tests/default.test.ts +365 -0
- package/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
- package/src/v4/classic/tests/description.test.ts +32 -0
- package/src/v4/classic/tests/discriminated-unions.test.ts +661 -0
- package/src/v4/classic/tests/enum.test.ts +285 -0
- package/src/v4/classic/tests/error-utils.test.ts +595 -0
- package/src/v4/classic/tests/error.test.ts +711 -0
- package/src/v4/classic/tests/file.test.ts +96 -0
- package/src/v4/classic/tests/firstparty.test.ts +179 -0
- package/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
- package/src/v4/classic/tests/from-json-schema.test.ts +734 -0
- package/src/v4/classic/tests/function.test.ts +360 -0
- package/src/v4/classic/tests/generics.test.ts +72 -0
- package/src/v4/classic/tests/hash.test.ts +68 -0
- package/src/v4/classic/tests/index.test.ts +939 -0
- package/src/v4/classic/tests/instanceof.test.ts +60 -0
- package/src/v4/classic/tests/intersection.test.ts +198 -0
- package/src/v4/classic/tests/json.test.ts +109 -0
- package/src/v4/classic/tests/lazy.test.ts +227 -0
- package/src/v4/classic/tests/literal.test.ts +117 -0
- package/src/v4/classic/tests/locales_ka.test.ts +29 -0
- package/src/v4/classic/tests/map.test.ts +330 -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 +101 -0
- package/src/v4/classic/tests/nullable.test.ts +22 -0
- package/src/v4/classic/tests/number.test.ts +311 -0
- package/src/v4/classic/tests/object.test.ts +640 -0
- package/src/v4/classic/tests/optional.test.ts +223 -0
- package/src/v4/classic/tests/partial.test.ts +427 -0
- package/src/v4/classic/tests/pickomit.test.ts +211 -0
- package/src/v4/classic/tests/pipe.test.ts +101 -0
- package/src/v4/classic/tests/prefault.test.ts +74 -0
- package/src/v4/classic/tests/preprocess.test.ts +282 -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 +632 -0
- package/src/v4/classic/tests/recursive-types.test.ts +582 -0
- package/src/v4/classic/tests/refine.test.ts +570 -0
- package/src/v4/classic/tests/registries.test.ts +243 -0
- package/src/v4/classic/tests/set.test.ts +181 -0
- package/src/v4/classic/tests/standard-schema.test.ts +134 -0
- package/src/v4/classic/tests/string-formats.test.ts +125 -0
- package/src/v4/classic/tests/string.test.ts +1200 -0
- package/src/v4/classic/tests/stringbool.test.ts +106 -0
- package/src/v4/classic/tests/template-literal.test.ts +771 -0
- package/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
- package/src/v4/classic/tests/to-json-schema.test.ts +2990 -0
- package/src/v4/classic/tests/transform.test.ts +361 -0
- package/src/v4/classic/tests/tuple.test.ts +183 -0
- package/src/v4/classic/tests/union.test.ts +219 -0
- package/src/v4/classic/tests/url.test.ts +13 -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 +1798 -0
- package/src/v4/core/checks.ts +1293 -0
- package/src/v4/core/config.ts +15 -0
- package/src/v4/core/core.ts +138 -0
- package/src/v4/core/doc.ts +44 -0
- package/src/v4/core/errors.ts +448 -0
- package/src/v4/core/index.ts +16 -0
- package/src/v4/core/json-schema-generator.ts +126 -0
- package/src/v4/core/json-schema-processors.ts +667 -0
- package/src/v4/core/json-schema.ts +147 -0
- package/src/v4/core/parse.ts +195 -0
- package/src/v4/core/regexes.ts +185 -0
- package/src/v4/core/registries.ts +105 -0
- package/src/v4/core/schemas.ts +4562 -0
- package/src/v4/core/standard-schema.ts +159 -0
- package/src/v4/core/tests/extend.test.ts +59 -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/es.test.ts +181 -0
- package/src/v4/core/tests/locales/he.test.ts +379 -0
- package/src/v4/core/tests/locales/hr.test.ts +163 -0
- package/src/v4/core/tests/locales/nl.test.ts +46 -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/tests/locales/uz.test.ts +105 -0
- package/src/v4/core/tests/record-constructor.test.ts +67 -0
- package/src/v4/core/tests/recursive-tuples.test.ts +45 -0
- package/src/v4/core/to-json-schema.ts +613 -0
- package/src/v4/core/util.ts +984 -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 +115 -0
- package/src/v4/locales/az.ts +111 -0
- package/src/v4/locales/be.ts +176 -0
- package/src/v4/locales/bg.ts +128 -0
- package/src/v4/locales/ca.ts +116 -0
- package/src/v4/locales/cs.ts +118 -0
- package/src/v4/locales/da.ts +123 -0
- package/src/v4/locales/de.ts +116 -0
- package/src/v4/locales/en.ts +119 -0
- package/src/v4/locales/eo.ts +118 -0
- package/src/v4/locales/es.ts +141 -0
- package/src/v4/locales/fa.ts +126 -0
- package/src/v4/locales/fi.ts +121 -0
- package/src/v4/locales/fr-CA.ts +116 -0
- package/src/v4/locales/fr.ts +116 -0
- package/src/v4/locales/he.ts +246 -0
- package/src/v4/locales/hr.ts +131 -0
- package/src/v4/locales/hu.ts +117 -0
- package/src/v4/locales/hy.ts +164 -0
- package/src/v4/locales/id.ts +115 -0
- package/src/v4/locales/index.ts +50 -0
- package/src/v4/locales/is.ts +119 -0
- package/src/v4/locales/it.ts +116 -0
- package/src/v4/locales/ja.ts +114 -0
- package/src/v4/locales/ka.ts +123 -0
- package/src/v4/locales/kh.ts +7 -0
- package/src/v4/locales/km.ts +119 -0
- package/src/v4/locales/ko.ts +121 -0
- package/src/v4/locales/lt.ts +239 -0
- package/src/v4/locales/mk.ts +118 -0
- package/src/v4/locales/ms.ts +115 -0
- package/src/v4/locales/nl.ts +121 -0
- package/src/v4/locales/no.ts +116 -0
- package/src/v4/locales/ota.ts +117 -0
- package/src/v4/locales/pl.ts +118 -0
- package/src/v4/locales/ps.ts +126 -0
- package/src/v4/locales/pt.ts +116 -0
- package/src/v4/locales/ru.ts +176 -0
- package/src/v4/locales/sl.ts +118 -0
- package/src/v4/locales/sv.ts +119 -0
- package/src/v4/locales/ta.ts +118 -0
- package/src/v4/locales/th.ts +119 -0
- package/src/v4/locales/tr.ts +111 -0
- package/src/v4/locales/ua.ts +7 -0
- package/src/v4/locales/uk.ts +117 -0
- package/src/v4/locales/ur.ts +119 -0
- package/src/v4/locales/uz.ts +117 -0
- package/src/v4/locales/vi.ts +117 -0
- package/src/v4/locales/yo.ts +124 -0
- package/src/v4/locales/zh-CN.ts +116 -0
- package/src/v4/locales/zh-TW.ts +115 -0
- package/src/v4/mini/checks.ts +32 -0
- package/src/v4/mini/coerce.ts +27 -0
- package/src/v4/mini/external.ts +40 -0
- package/src/v4/mini/index.ts +3 -0
- package/src/v4/mini/iso.ts +66 -0
- package/src/v4/mini/parse.ts +14 -0
- package/src/v4/mini/schemas.ts +1916 -0
- package/src/v4/mini/tests/apply.test.ts +24 -0
- package/src/v4/mini/tests/assignability.test.ts +129 -0
- package/src/v4/mini/tests/brand.test.ts +94 -0
- package/src/v4/mini/tests/checks.test.ts +144 -0
- package/src/v4/mini/tests/codec.test.ts +529 -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 +5 -0
- package/src/v4/mini/tests/index.test.ts +963 -0
- package/src/v4/mini/tests/number.test.ts +95 -0
- package/src/v4/mini/tests/object.test.ts +227 -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/standard-schema.test.ts +50 -0
- package/src/v4/mini/tests/string.test.ts +347 -0
- package/src/v4-mini/index.ts +3 -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/v3/index.cjs +33 -0
- package/v3/index.d.cts +4 -0
- package/v3/index.d.ts +4 -0
- package/v3/index.js +4 -0
- package/v3/locales/en.cjs +112 -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/package.json +7 -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 +3777 -0
- package/v3/types.d.cts +1034 -0
- package/v3/types.d.ts +1034 -0
- package/v3/types.js +3695 -0
- package/v4/classic/checks.cjs +33 -0
- package/v4/classic/checks.d.cts +1 -0
- package/v4/classic/checks.d.ts +1 -0
- package/v4/classic/checks.js +1 -0
- package/v4/classic/coerce.cjs +47 -0
- package/v4/classic/coerce.d.cts +17 -0
- package/v4/classic/coerce.d.ts +17 -0
- package/v4/classic/coerce.js +17 -0
- package/v4/classic/compat.cjs +61 -0
- package/v4/classic/compat.d.cts +50 -0
- package/v4/classic/compat.d.ts +50 -0
- package/v4/classic/compat.js +31 -0
- package/v4/classic/errors.cjs +74 -0
- package/v4/classic/errors.d.cts +30 -0
- package/v4/classic/errors.d.ts +30 -0
- package/v4/classic/errors.js +48 -0
- package/v4/classic/external.cjs +73 -0
- package/v4/classic/external.d.cts +15 -0
- package/v4/classic/external.d.ts +15 -0
- package/v4/classic/external.js +20 -0
- package/v4/classic/from-json-schema.cjs +610 -0
- package/v4/classic/from-json-schema.d.cts +12 -0
- package/v4/classic/from-json-schema.d.ts +12 -0
- package/v4/classic/from-json-schema.js +584 -0
- package/v4/classic/index.cjs +33 -0
- package/v4/classic/index.d.cts +4 -0
- package/v4/classic/index.d.ts +4 -0
- package/v4/classic/index.js +4 -0
- package/v4/classic/iso.cjs +60 -0
- package/v4/classic/iso.d.cts +22 -0
- package/v4/classic/iso.d.ts +22 -0
- package/v4/classic/iso.js +30 -0
- package/v4/classic/package.json +7 -0
- package/v4/classic/parse.cjs +41 -0
- package/v4/classic/parse.d.cts +31 -0
- package/v4/classic/parse.d.ts +31 -0
- package/v4/classic/parse.js +15 -0
- package/v4/classic/schemas.cjs +1272 -0
- package/v4/classic/schemas.d.cts +739 -0
- package/v4/classic/schemas.d.ts +739 -0
- package/v4/classic/schemas.js +1157 -0
- package/v4/core/api.cjs +1222 -0
- package/v4/core/api.d.cts +304 -0
- package/v4/core/api.d.ts +304 -0
- package/v4/core/api.js +1082 -0
- package/v4/core/checks.cjs +601 -0
- package/v4/core/checks.d.cts +278 -0
- package/v4/core/checks.d.ts +278 -0
- package/v4/core/checks.js +575 -0
- package/v4/core/core.cjs +83 -0
- package/v4/core/core.d.cts +70 -0
- package/v4/core/core.d.ts +70 -0
- package/v4/core/core.js +76 -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 +213 -0
- package/v4/core/errors.d.cts +220 -0
- package/v4/core/errors.d.ts +220 -0
- package/v4/core/errors.js +182 -0
- package/v4/core/index.cjs +47 -0
- package/v4/core/index.d.cts +16 -0
- package/v4/core/index.d.ts +16 -0
- package/v4/core/index.js +16 -0
- package/v4/core/json-schema-generator.cjs +99 -0
- package/v4/core/json-schema-generator.d.cts +65 -0
- package/v4/core/json-schema-generator.d.ts +65 -0
- package/v4/core/json-schema-generator.js +95 -0
- package/v4/core/json-schema-processors.cjs +648 -0
- package/v4/core/json-schema-processors.d.cts +49 -0
- package/v4/core/json-schema-processors.d.ts +49 -0
- package/v4/core/json-schema-processors.js +605 -0
- package/v4/core/json-schema.cjs +2 -0
- package/v4/core/json-schema.d.cts +88 -0
- package/v4/core/json-schema.d.ts +88 -0
- package/v4/core/json-schema.js +1 -0
- package/v4/core/package.json +7 -0
- package/v4/core/parse.cjs +131 -0
- package/v4/core/parse.d.cts +49 -0
- package/v4/core/parse.d.ts +49 -0
- package/v4/core/parse.js +93 -0
- package/v4/core/regexes.cjs +167 -0
- package/v4/core/regexes.d.cts +80 -0
- package/v4/core/regexes.d.ts +80 -0
- package/v4/core/regexes.js +134 -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 +2147 -0
- package/v4/core/schemas.d.cts +1147 -0
- package/v4/core/schemas.d.ts +1147 -0
- package/v4/core/schemas.js +2115 -0
- package/v4/core/standard-schema.cjs +2 -0
- package/v4/core/standard-schema.d.cts +126 -0
- package/v4/core/standard-schema.d.ts +126 -0
- package/v4/core/standard-schema.js +1 -0
- package/v4/core/to-json-schema.cjs +446 -0
- package/v4/core/to-json-schema.d.cts +114 -0
- package/v4/core/to-json-schema.d.ts +114 -0
- package/v4/core/to-json-schema.js +437 -0
- package/v4/core/util.cjs +729 -0
- package/v4/core/util.d.cts +201 -0
- package/v4/core/util.d.ts +201 -0
- package/v4/core/util.js +668 -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 +133 -0
- package/v4/locales/ar.d.cts +5 -0
- package/v4/locales/ar.d.ts +4 -0
- package/v4/locales/ar.js +106 -0
- package/v4/locales/az.cjs +132 -0
- package/v4/locales/az.d.cts +5 -0
- package/v4/locales/az.d.ts +4 -0
- package/v4/locales/az.js +105 -0
- package/v4/locales/be.cjs +183 -0
- package/v4/locales/be.d.cts +5 -0
- package/v4/locales/be.d.ts +4 -0
- package/v4/locales/be.js +156 -0
- package/v4/locales/bg.cjs +147 -0
- package/v4/locales/bg.d.cts +5 -0
- package/v4/locales/bg.d.ts +4 -0
- package/v4/locales/bg.js +120 -0
- package/v4/locales/ca.cjs +134 -0
- package/v4/locales/ca.d.cts +5 -0
- package/v4/locales/ca.d.ts +4 -0
- package/v4/locales/ca.js +107 -0
- package/v4/locales/cs.cjs +138 -0
- package/v4/locales/cs.d.cts +5 -0
- package/v4/locales/cs.d.ts +4 -0
- package/v4/locales/cs.js +111 -0
- package/v4/locales/da.cjs +142 -0
- package/v4/locales/da.d.cts +5 -0
- package/v4/locales/da.d.ts +4 -0
- package/v4/locales/da.js +115 -0
- package/v4/locales/de.cjs +135 -0
- package/v4/locales/de.d.cts +5 -0
- package/v4/locales/de.d.ts +4 -0
- package/v4/locales/de.js +108 -0
- package/v4/locales/en.cjs +136 -0
- package/v4/locales/en.d.cts +5 -0
- package/v4/locales/en.d.ts +4 -0
- package/v4/locales/en.js +109 -0
- package/v4/locales/eo.cjs +136 -0
- package/v4/locales/eo.d.cts +5 -0
- package/v4/locales/eo.d.ts +4 -0
- package/v4/locales/eo.js +109 -0
- package/v4/locales/es.cjs +159 -0
- package/v4/locales/es.d.cts +5 -0
- package/v4/locales/es.d.ts +4 -0
- package/v4/locales/es.js +132 -0
- package/v4/locales/fa.cjs +141 -0
- package/v4/locales/fa.d.cts +5 -0
- package/v4/locales/fa.d.ts +4 -0
- package/v4/locales/fa.js +114 -0
- package/v4/locales/fi.cjs +139 -0
- package/v4/locales/fi.d.cts +5 -0
- package/v4/locales/fi.d.ts +4 -0
- package/v4/locales/fi.js +112 -0
- package/v4/locales/fr-CA.cjs +134 -0
- package/v4/locales/fr-CA.d.cts +5 -0
- package/v4/locales/fr-CA.d.ts +4 -0
- package/v4/locales/fr-CA.js +107 -0
- package/v4/locales/fr.cjs +135 -0
- package/v4/locales/fr.d.cts +5 -0
- package/v4/locales/fr.d.ts +4 -0
- package/v4/locales/fr.js +108 -0
- package/v4/locales/he.cjs +241 -0
- package/v4/locales/he.d.cts +5 -0
- package/v4/locales/he.d.ts +4 -0
- package/v4/locales/he.js +214 -0
- package/v4/locales/hr.cjs +149 -0
- package/v4/locales/hr.d.cts +5 -0
- package/v4/locales/hr.d.ts +4 -0
- package/v4/locales/hr.js +122 -0
- package/v4/locales/hu.cjs +135 -0
- package/v4/locales/hu.d.cts +5 -0
- package/v4/locales/hu.d.ts +4 -0
- package/v4/locales/hu.js +108 -0
- package/v4/locales/hy.cjs +174 -0
- package/v4/locales/hy.d.cts +5 -0
- package/v4/locales/hy.d.ts +4 -0
- package/v4/locales/hy.js +147 -0
- package/v4/locales/id.cjs +133 -0
- package/v4/locales/id.d.cts +5 -0
- package/v4/locales/id.d.ts +4 -0
- package/v4/locales/id.js +106 -0
- package/v4/locales/index.cjs +106 -0
- package/v4/locales/index.d.cts +50 -0
- package/v4/locales/index.d.ts +50 -0
- package/v4/locales/index.js +50 -0
- package/v4/locales/is.cjs +136 -0
- package/v4/locales/is.d.cts +5 -0
- package/v4/locales/is.d.ts +4 -0
- package/v4/locales/is.js +109 -0
- package/v4/locales/it.cjs +135 -0
- package/v4/locales/it.d.cts +5 -0
- package/v4/locales/it.d.ts +4 -0
- package/v4/locales/it.js +108 -0
- package/v4/locales/ja.cjs +134 -0
- package/v4/locales/ja.d.cts +5 -0
- package/v4/locales/ja.d.ts +4 -0
- package/v4/locales/ja.js +107 -0
- package/v4/locales/ka.cjs +139 -0
- package/v4/locales/ka.d.cts +5 -0
- package/v4/locales/ka.d.ts +4 -0
- package/v4/locales/ka.js +112 -0
- package/v4/locales/kh.cjs +12 -0
- package/v4/locales/kh.d.cts +5 -0
- package/v4/locales/kh.d.ts +5 -0
- package/v4/locales/kh.js +5 -0
- package/v4/locales/km.cjs +137 -0
- package/v4/locales/km.d.cts +5 -0
- package/v4/locales/km.d.ts +4 -0
- package/v4/locales/km.js +110 -0
- package/v4/locales/ko.cjs +138 -0
- package/v4/locales/ko.d.cts +5 -0
- package/v4/locales/ko.d.ts +4 -0
- package/v4/locales/ko.js +111 -0
- package/v4/locales/lt.cjs +230 -0
- package/v4/locales/lt.d.cts +5 -0
- package/v4/locales/lt.d.ts +4 -0
- package/v4/locales/lt.js +203 -0
- package/v4/locales/mk.cjs +136 -0
- package/v4/locales/mk.d.cts +5 -0
- package/v4/locales/mk.d.ts +4 -0
- package/v4/locales/mk.js +109 -0
- package/v4/locales/ms.cjs +134 -0
- package/v4/locales/ms.d.cts +5 -0
- package/v4/locales/ms.d.ts +4 -0
- package/v4/locales/ms.js +107 -0
- package/v4/locales/nl.cjs +137 -0
- package/v4/locales/nl.d.cts +5 -0
- package/v4/locales/nl.d.ts +4 -0
- package/v4/locales/nl.js +110 -0
- package/v4/locales/no.cjs +135 -0
- package/v4/locales/no.d.cts +5 -0
- package/v4/locales/no.d.ts +4 -0
- package/v4/locales/no.js +108 -0
- package/v4/locales/ota.cjs +136 -0
- package/v4/locales/ota.d.cts +5 -0
- package/v4/locales/ota.d.ts +4 -0
- package/v4/locales/ota.js +109 -0
- package/v4/locales/package.json +7 -0
- package/v4/locales/pl.cjs +136 -0
- package/v4/locales/pl.d.cts +5 -0
- package/v4/locales/pl.d.ts +4 -0
- package/v4/locales/pl.js +109 -0
- package/v4/locales/ps.cjs +141 -0
- package/v4/locales/ps.d.cts +5 -0
- package/v4/locales/ps.d.ts +4 -0
- package/v4/locales/ps.js +114 -0
- package/v4/locales/pt.cjs +135 -0
- package/v4/locales/pt.d.cts +5 -0
- package/v4/locales/pt.d.ts +4 -0
- package/v4/locales/pt.js +108 -0
- package/v4/locales/ru.cjs +183 -0
- package/v4/locales/ru.d.cts +5 -0
- package/v4/locales/ru.d.ts +4 -0
- package/v4/locales/ru.js +156 -0
- package/v4/locales/sl.cjs +136 -0
- package/v4/locales/sl.d.cts +5 -0
- package/v4/locales/sl.d.ts +4 -0
- package/v4/locales/sl.js +109 -0
- package/v4/locales/sv.cjs +137 -0
- package/v4/locales/sv.d.cts +5 -0
- package/v4/locales/sv.d.ts +4 -0
- package/v4/locales/sv.js +110 -0
- package/v4/locales/ta.cjs +137 -0
- package/v4/locales/ta.d.cts +5 -0
- package/v4/locales/ta.d.ts +4 -0
- package/v4/locales/ta.js +110 -0
- package/v4/locales/th.cjs +137 -0
- package/v4/locales/th.d.cts +5 -0
- package/v4/locales/th.d.ts +4 -0
- package/v4/locales/th.js +110 -0
- package/v4/locales/tr.cjs +132 -0
- package/v4/locales/tr.d.cts +5 -0
- package/v4/locales/tr.d.ts +4 -0
- package/v4/locales/tr.js +105 -0
- package/v4/locales/ua.cjs +12 -0
- package/v4/locales/ua.d.cts +5 -0
- package/v4/locales/ua.d.ts +5 -0
- package/v4/locales/ua.js +5 -0
- package/v4/locales/uk.cjs +135 -0
- package/v4/locales/uk.d.cts +5 -0
- package/v4/locales/uk.d.ts +4 -0
- package/v4/locales/uk.js +108 -0
- package/v4/locales/ur.cjs +137 -0
- package/v4/locales/ur.d.cts +5 -0
- package/v4/locales/ur.d.ts +4 -0
- package/v4/locales/ur.js +110 -0
- package/v4/locales/uz.cjs +137 -0
- package/v4/locales/uz.d.cts +5 -0
- package/v4/locales/uz.d.ts +4 -0
- package/v4/locales/uz.js +110 -0
- package/v4/locales/vi.cjs +135 -0
- package/v4/locales/vi.d.cts +5 -0
- package/v4/locales/vi.d.ts +4 -0
- package/v4/locales/vi.js +108 -0
- package/v4/locales/yo.cjs +134 -0
- package/v4/locales/yo.d.cts +5 -0
- package/v4/locales/yo.d.ts +4 -0
- package/v4/locales/yo.js +107 -0
- package/v4/locales/zh-CN.cjs +136 -0
- package/v4/locales/zh-CN.d.cts +5 -0
- package/v4/locales/zh-CN.d.ts +4 -0
- package/v4/locales/zh-CN.js +109 -0
- package/v4/locales/zh-TW.cjs +134 -0
- package/v4/locales/zh-TW.d.cts +5 -0
- package/v4/locales/zh-TW.d.ts +4 -0
- package/v4/locales/zh-TW.js +107 -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/v4/mini/coerce.cjs +52 -0
- package/v4/mini/coerce.d.cts +7 -0
- package/v4/mini/coerce.d.ts +7 -0
- package/v4/mini/coerce.js +22 -0
- package/v4/mini/external.cjs +63 -0
- package/v4/mini/external.d.cts +12 -0
- package/v4/mini/external.d.ts +12 -0
- package/v4/mini/external.js +14 -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 +64 -0
- package/v4/mini/iso.d.cts +22 -0
- package/v4/mini/iso.d.ts +22 -0
- package/v4/mini/iso.js +34 -0
- package/v4/mini/package.json +7 -0
- package/v4/mini/parse.cjs +16 -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 +1046 -0
- package/v4/mini/schemas.d.cts +427 -0
- package/v4/mini/schemas.d.ts +427 -0
- package/v4/mini/schemas.js +925 -0
- package/v4/package.json +7 -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/package.json +7 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export type Schema =
|
|
2
|
+
| ObjectSchema
|
|
3
|
+
| ArraySchema
|
|
4
|
+
| StringSchema
|
|
5
|
+
| NumberSchema
|
|
6
|
+
| IntegerSchema
|
|
7
|
+
| BooleanSchema
|
|
8
|
+
| NullSchema;
|
|
9
|
+
|
|
10
|
+
// export type JsonType = "object" | "array" | "string" | "number" | "boolean" | "null" | "integer";
|
|
11
|
+
|
|
12
|
+
// export interface JSONSchema {
|
|
13
|
+
// type?: string ;
|
|
14
|
+
// $id?: string ;
|
|
15
|
+
// id?: string ;
|
|
16
|
+
// $schema?: string ;
|
|
17
|
+
// $ref?: string ;
|
|
18
|
+
// $anchor?: string ;
|
|
19
|
+
// $defs?: { [key: string]: JSONSchema } ;
|
|
20
|
+
// definitions?: { [key: string]: JSONSchema } ;
|
|
21
|
+
// $comment?: string ;
|
|
22
|
+
// title?: string ;
|
|
23
|
+
// description?: string ;
|
|
24
|
+
// default?: unknown ;
|
|
25
|
+
// examples?: unknown[] ;
|
|
26
|
+
// readOnly?: boolean ;
|
|
27
|
+
// writeOnly?: boolean ;
|
|
28
|
+
// deprecated?: boolean ;
|
|
29
|
+
// allOf?: JSONSchema[] ;
|
|
30
|
+
// anyOf?: JSONSchema[] ;
|
|
31
|
+
// oneOf?: JSONSchema[] ;
|
|
32
|
+
// not?: JSONSchema ;
|
|
33
|
+
// if?: JSONSchema ;
|
|
34
|
+
// then?: JSONSchema ;
|
|
35
|
+
// else?: JSONSchema ;
|
|
36
|
+
// enum?: Array<string | number | boolean | null> ;
|
|
37
|
+
// const?: string | number | boolean | null ;
|
|
38
|
+
// [k: string]: unknown;
|
|
39
|
+
|
|
40
|
+
// /** A special key used as an intermediate representation of extends-style relationships. Omitted as a $ref with additional properties. */
|
|
41
|
+
// // _ref?: JSONSchema;
|
|
42
|
+
// _prefault?: unknown ;
|
|
43
|
+
// }
|
|
44
|
+
|
|
45
|
+
export type _JSONSchema = boolean | JSONSchema;
|
|
46
|
+
export type JSONSchema = {
|
|
47
|
+
[k: string]: unknown;
|
|
48
|
+
$schema?:
|
|
49
|
+
| "https://json-schema.org/draft/2020-12/schema"
|
|
50
|
+
| "http://json-schema.org/draft-07/schema#"
|
|
51
|
+
| "http://json-schema.org/draft-04/schema#";
|
|
52
|
+
$id?: string;
|
|
53
|
+
$anchor?: string;
|
|
54
|
+
$ref?: string;
|
|
55
|
+
$dynamicRef?: string;
|
|
56
|
+
$dynamicAnchor?: string;
|
|
57
|
+
$vocabulary?: Record<string, boolean>;
|
|
58
|
+
$comment?: string;
|
|
59
|
+
$defs?: Record<string, JSONSchema>;
|
|
60
|
+
type?: "object" | "array" | "string" | "number" | "boolean" | "null" | "integer";
|
|
61
|
+
additionalItems?: _JSONSchema;
|
|
62
|
+
unevaluatedItems?: _JSONSchema;
|
|
63
|
+
prefixItems?: _JSONSchema[];
|
|
64
|
+
items?: _JSONSchema | _JSONSchema[];
|
|
65
|
+
contains?: _JSONSchema;
|
|
66
|
+
additionalProperties?: _JSONSchema;
|
|
67
|
+
unevaluatedProperties?: _JSONSchema;
|
|
68
|
+
properties?: Record<string, _JSONSchema>;
|
|
69
|
+
patternProperties?: Record<string, _JSONSchema>;
|
|
70
|
+
dependentSchemas?: Record<string, _JSONSchema>;
|
|
71
|
+
propertyNames?: _JSONSchema;
|
|
72
|
+
if?: _JSONSchema;
|
|
73
|
+
then?: _JSONSchema;
|
|
74
|
+
else?: _JSONSchema;
|
|
75
|
+
allOf?: JSONSchema[];
|
|
76
|
+
anyOf?: JSONSchema[];
|
|
77
|
+
oneOf?: JSONSchema[];
|
|
78
|
+
not?: _JSONSchema;
|
|
79
|
+
multipleOf?: number;
|
|
80
|
+
maximum?: number;
|
|
81
|
+
exclusiveMaximum?: number | boolean;
|
|
82
|
+
minimum?: number;
|
|
83
|
+
exclusiveMinimum?: number | boolean;
|
|
84
|
+
maxLength?: number;
|
|
85
|
+
minLength?: number;
|
|
86
|
+
pattern?: string;
|
|
87
|
+
maxItems?: number;
|
|
88
|
+
minItems?: number;
|
|
89
|
+
uniqueItems?: boolean;
|
|
90
|
+
maxContains?: number;
|
|
91
|
+
minContains?: number;
|
|
92
|
+
maxProperties?: number;
|
|
93
|
+
minProperties?: number;
|
|
94
|
+
required?: string[];
|
|
95
|
+
dependentRequired?: Record<string, string[]>;
|
|
96
|
+
enum?: Array<string | number | boolean | null>;
|
|
97
|
+
const?: string | number | boolean | null;
|
|
98
|
+
|
|
99
|
+
// metadata
|
|
100
|
+
id?: string;
|
|
101
|
+
title?: string;
|
|
102
|
+
description?: string;
|
|
103
|
+
default?: unknown;
|
|
104
|
+
deprecated?: boolean;
|
|
105
|
+
readOnly?: boolean;
|
|
106
|
+
writeOnly?: boolean;
|
|
107
|
+
nullable?: boolean;
|
|
108
|
+
examples?: unknown[];
|
|
109
|
+
format?: string;
|
|
110
|
+
contentMediaType?: string;
|
|
111
|
+
contentEncoding?: string;
|
|
112
|
+
contentSchema?: JSONSchema;
|
|
113
|
+
|
|
114
|
+
// internal
|
|
115
|
+
_prefault?: unknown;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// for backwards compatibility
|
|
119
|
+
export type BaseSchema = JSONSchema;
|
|
120
|
+
|
|
121
|
+
export interface ObjectSchema extends JSONSchema {
|
|
122
|
+
type: "object";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface ArraySchema extends JSONSchema {
|
|
126
|
+
type: "array";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface StringSchema extends JSONSchema {
|
|
130
|
+
type: "string";
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface NumberSchema extends JSONSchema {
|
|
134
|
+
type: "number";
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface IntegerSchema extends JSONSchema {
|
|
138
|
+
type: "integer";
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface BooleanSchema extends JSONSchema {
|
|
142
|
+
type: "boolean";
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface NullSchema extends JSONSchema {
|
|
146
|
+
type: "null";
|
|
147
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import * as core from "./core.js";
|
|
2
|
+
import * as errors from "./errors.js";
|
|
3
|
+
import type * as schemas from "./schemas.js";
|
|
4
|
+
import * as util from "./util.js";
|
|
5
|
+
|
|
6
|
+
export type $ZodErrorClass = { new (issues: errors.$ZodIssue[]): errors.$ZodError };
|
|
7
|
+
|
|
8
|
+
/////////// METHODS ///////////
|
|
9
|
+
export type $Parse = <T extends schemas.$ZodType>(
|
|
10
|
+
schema: T,
|
|
11
|
+
value: unknown,
|
|
12
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>,
|
|
13
|
+
_params?: { callee?: util.AnyFunc; Err?: $ZodErrorClass }
|
|
14
|
+
) => core.output<T>;
|
|
15
|
+
|
|
16
|
+
export const _parse: (_Err: $ZodErrorClass) => $Parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
17
|
+
const ctx: schemas.ParseContextInternal = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
|
|
18
|
+
const result = schema._zod.run({ value, issues: [] }, ctx);
|
|
19
|
+
if (result instanceof Promise) {
|
|
20
|
+
throw new core.$ZodAsyncError();
|
|
21
|
+
}
|
|
22
|
+
if (result.issues.length) {
|
|
23
|
+
const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())));
|
|
24
|
+
util.captureStackTrace(e, _params?.callee);
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
return result.value as core.output<typeof schema>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const parse: $Parse = /* @__PURE__*/ _parse(errors.$ZodRealError);
|
|
31
|
+
|
|
32
|
+
export type $ParseAsync = <T extends schemas.$ZodType>(
|
|
33
|
+
schema: T,
|
|
34
|
+
value: unknown,
|
|
35
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>,
|
|
36
|
+
_params?: { callee?: util.AnyFunc; Err?: $ZodErrorClass }
|
|
37
|
+
) => Promise<core.output<T>>;
|
|
38
|
+
|
|
39
|
+
export const _parseAsync: (_Err: $ZodErrorClass) => $ParseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
40
|
+
const ctx: schemas.ParseContextInternal = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
41
|
+
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
42
|
+
if (result instanceof Promise) result = await result;
|
|
43
|
+
if (result.issues.length) {
|
|
44
|
+
const e = new (params?.Err ?? _Err)(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())));
|
|
45
|
+
util.captureStackTrace(e, params?.callee);
|
|
46
|
+
throw e;
|
|
47
|
+
}
|
|
48
|
+
return result.value as core.output<typeof schema>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const parseAsync: $ParseAsync = /* @__PURE__*/ _parseAsync(errors.$ZodRealError);
|
|
52
|
+
|
|
53
|
+
export type $SafeParse = <T extends schemas.$ZodType>(
|
|
54
|
+
schema: T,
|
|
55
|
+
value: unknown,
|
|
56
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>
|
|
57
|
+
) => util.SafeParseResult<core.output<T>>;
|
|
58
|
+
|
|
59
|
+
export const _safeParse: (_Err: $ZodErrorClass) => $SafeParse = (_Err) => (schema, value, _ctx) => {
|
|
60
|
+
const ctx: schemas.ParseContextInternal = _ctx ? { ..._ctx, async: false } : { async: false };
|
|
61
|
+
const result = schema._zod.run({ value, issues: [] }, ctx);
|
|
62
|
+
if (result instanceof Promise) {
|
|
63
|
+
throw new core.$ZodAsyncError();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return result.issues.length
|
|
67
|
+
? {
|
|
68
|
+
success: false,
|
|
69
|
+
error: new (_Err ?? errors.$ZodError)(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
|
|
70
|
+
}
|
|
71
|
+
: ({ success: true, data: result.value } as any);
|
|
72
|
+
};
|
|
73
|
+
export const safeParse: $SafeParse = /* @__PURE__*/ _safeParse(errors.$ZodRealError);
|
|
74
|
+
|
|
75
|
+
export type $SafeParseAsync = <T extends schemas.$ZodType>(
|
|
76
|
+
schema: T,
|
|
77
|
+
value: unknown,
|
|
78
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>
|
|
79
|
+
) => Promise<util.SafeParseResult<core.output<T>>>;
|
|
80
|
+
|
|
81
|
+
export const _safeParseAsync: (_Err: $ZodErrorClass) => $SafeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
82
|
+
const ctx: schemas.ParseContextInternal = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
83
|
+
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
84
|
+
if (result instanceof Promise) result = await result;
|
|
85
|
+
|
|
86
|
+
return result.issues.length
|
|
87
|
+
? {
|
|
88
|
+
success: false,
|
|
89
|
+
error: new _Err(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
|
|
90
|
+
}
|
|
91
|
+
: ({ success: true, data: result.value } as any);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const safeParseAsync: $SafeParseAsync = /* @__PURE__*/ _safeParseAsync(errors.$ZodRealError);
|
|
95
|
+
|
|
96
|
+
// Codec functions
|
|
97
|
+
export type $Encode = <T extends schemas.$ZodType>(
|
|
98
|
+
schema: T,
|
|
99
|
+
value: core.output<T>,
|
|
100
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>
|
|
101
|
+
) => core.input<T>;
|
|
102
|
+
|
|
103
|
+
export const _encode: (_Err: $ZodErrorClass) => $Encode = (_Err) => (schema, value, _ctx) => {
|
|
104
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" as const }) : { direction: "backward" as const };
|
|
105
|
+
return _parse(_Err)(schema, value, ctx as any) as any;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const encode: $Encode = /* @__PURE__*/ _encode(errors.$ZodRealError);
|
|
109
|
+
|
|
110
|
+
export type $Decode = <T extends schemas.$ZodType>(
|
|
111
|
+
schema: T,
|
|
112
|
+
value: core.input<T>,
|
|
113
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>
|
|
114
|
+
) => core.output<T>;
|
|
115
|
+
|
|
116
|
+
export const _decode: (_Err: $ZodErrorClass) => $Decode = (_Err) => (schema, value, _ctx) => {
|
|
117
|
+
return _parse(_Err)(schema, value, _ctx);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const decode: $Decode = /* @__PURE__*/ _decode(errors.$ZodRealError);
|
|
121
|
+
|
|
122
|
+
export type $EncodeAsync = <T extends schemas.$ZodType>(
|
|
123
|
+
schema: T,
|
|
124
|
+
value: core.output<T>,
|
|
125
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>
|
|
126
|
+
) => Promise<core.input<T>>;
|
|
127
|
+
|
|
128
|
+
export const _encodeAsync: (_Err: $ZodErrorClass) => $EncodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
129
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" as const }) : { direction: "backward" as const };
|
|
130
|
+
return _parseAsync(_Err)(schema, value, ctx as any) as any;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const encodeAsync: $EncodeAsync = /* @__PURE__*/ _encodeAsync(errors.$ZodRealError);
|
|
134
|
+
|
|
135
|
+
export type $DecodeAsync = <T extends schemas.$ZodType>(
|
|
136
|
+
schema: T,
|
|
137
|
+
value: core.input<T>,
|
|
138
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>
|
|
139
|
+
) => Promise<core.output<T>>;
|
|
140
|
+
|
|
141
|
+
export const _decodeAsync: (_Err: $ZodErrorClass) => $DecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
142
|
+
return _parseAsync(_Err)(schema, value, _ctx);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export const decodeAsync: $DecodeAsync = /* @__PURE__*/ _decodeAsync(errors.$ZodRealError);
|
|
146
|
+
|
|
147
|
+
export type $SafeEncode = <T extends schemas.$ZodType>(
|
|
148
|
+
schema: T,
|
|
149
|
+
value: core.output<T>,
|
|
150
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>
|
|
151
|
+
) => util.SafeParseResult<core.input<T>>;
|
|
152
|
+
|
|
153
|
+
export const _safeEncode: (_Err: $ZodErrorClass) => $SafeEncode = (_Err) => (schema, value, _ctx) => {
|
|
154
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" as const }) : { direction: "backward" as const };
|
|
155
|
+
return _safeParse(_Err)(schema, value, ctx as any) as any;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export const safeEncode: $SafeEncode = /* @__PURE__*/ _safeEncode(errors.$ZodRealError);
|
|
159
|
+
|
|
160
|
+
export type $SafeDecode = <T extends schemas.$ZodType>(
|
|
161
|
+
schema: T,
|
|
162
|
+
value: core.input<T>,
|
|
163
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>
|
|
164
|
+
) => util.SafeParseResult<core.output<T>>;
|
|
165
|
+
|
|
166
|
+
export const _safeDecode: (_Err: $ZodErrorClass) => $SafeDecode = (_Err) => (schema, value, _ctx) => {
|
|
167
|
+
return _safeParse(_Err)(schema, value, _ctx);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export const safeDecode: $SafeDecode = /* @__PURE__*/ _safeDecode(errors.$ZodRealError);
|
|
171
|
+
|
|
172
|
+
export type $SafeEncodeAsync = <T extends schemas.$ZodType>(
|
|
173
|
+
schema: T,
|
|
174
|
+
value: core.output<T>,
|
|
175
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>
|
|
176
|
+
) => Promise<util.SafeParseResult<core.input<T>>>;
|
|
177
|
+
|
|
178
|
+
export const _safeEncodeAsync: (_Err: $ZodErrorClass) => $SafeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
179
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" as const }) : { direction: "backward" as const };
|
|
180
|
+
return _safeParseAsync(_Err)(schema, value, ctx as any) as any;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const safeEncodeAsync: $SafeEncodeAsync = /* @__PURE__*/ _safeEncodeAsync(errors.$ZodRealError);
|
|
184
|
+
|
|
185
|
+
export type $SafeDecodeAsync = <T extends schemas.$ZodType>(
|
|
186
|
+
schema: T,
|
|
187
|
+
value: core.input<T>,
|
|
188
|
+
_ctx?: schemas.ParseContext<errors.$ZodIssue>
|
|
189
|
+
) => Promise<util.SafeParseResult<core.output<T>>>;
|
|
190
|
+
|
|
191
|
+
export const _safeDecodeAsync: (_Err: $ZodErrorClass) => $SafeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
192
|
+
return _safeParseAsync(_Err)(schema, value, _ctx);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export const safeDecodeAsync: $SafeDecodeAsync = /* @__PURE__*/ _safeDecodeAsync(errors.$ZodRealError);
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import * as util from "./util.js";
|
|
2
|
+
|
|
3
|
+
export const cuid: RegExp = /^[cC][^\s-]{8,}$/;
|
|
4
|
+
export const cuid2: RegExp = /^[0-9a-z]+$/;
|
|
5
|
+
export const ulid: RegExp = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
|
6
|
+
export const xid: RegExp = /^[0-9a-vA-V]{20}$/;
|
|
7
|
+
export const ksuid: RegExp = /^[A-Za-z0-9]{27}$/;
|
|
8
|
+
export const nanoid: RegExp = /^[a-zA-Z0-9_-]{21}$/;
|
|
9
|
+
|
|
10
|
+
/** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
|
|
11
|
+
export const duration: RegExp =
|
|
12
|
+
/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
|
13
|
+
|
|
14
|
+
/** Implements ISO 8601-2 extensions like explicit +- prefixes, mixing weeks with other units, and fractional/negative components. */
|
|
15
|
+
export const extendedDuration: RegExp =
|
|
16
|
+
/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
17
|
+
|
|
18
|
+
/** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
|
|
19
|
+
export const guid: RegExp = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
|
20
|
+
|
|
21
|
+
/** Returns a regex for validating an RFC 9562/4122 UUID.
|
|
22
|
+
*
|
|
23
|
+
* @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
|
|
24
|
+
export const uuid = (version?: number | undefined): RegExp => {
|
|
25
|
+
if (!version)
|
|
26
|
+
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
27
|
+
return new RegExp(
|
|
28
|
+
`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
export const uuid4: RegExp = /*@__PURE__*/ uuid(4);
|
|
32
|
+
export const uuid6: RegExp = /*@__PURE__*/ uuid(6);
|
|
33
|
+
export const uuid7: RegExp = /*@__PURE__*/ uuid(7);
|
|
34
|
+
|
|
35
|
+
/** Practical email validation */
|
|
36
|
+
export const email: RegExp =
|
|
37
|
+
/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
38
|
+
|
|
39
|
+
/** Equivalent to the HTML5 input[type=email] validation implemented by browsers. Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email */
|
|
40
|
+
export const html5Email: RegExp =
|
|
41
|
+
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
42
|
+
|
|
43
|
+
/** The classic emailregex.com regex for RFC 5322-compliant emails */
|
|
44
|
+
export const rfc5322Email =
|
|
45
|
+
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
46
|
+
|
|
47
|
+
/** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
|
|
48
|
+
export const unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
|
|
49
|
+
export const idnEmail = unicodeEmail;
|
|
50
|
+
|
|
51
|
+
export const browserEmail: RegExp =
|
|
52
|
+
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
53
|
+
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
54
|
+
|
|
55
|
+
const _emoji: string = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
56
|
+
export function emoji(): RegExp {
|
|
57
|
+
return new RegExp(_emoji, "u");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const ipv4: RegExp =
|
|
61
|
+
/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
62
|
+
export const ipv6: RegExp =
|
|
63
|
+
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
|
64
|
+
export const mac = (delimiter?: string): RegExp => {
|
|
65
|
+
const escapedDelim = util.escapeRegex(delimiter ?? ":");
|
|
66
|
+
return new RegExp(`^(?:[0-9A-F]{2}${escapedDelim}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${escapedDelim}){5}[0-9a-f]{2}$`);
|
|
67
|
+
};
|
|
68
|
+
export const cidrv4: RegExp =
|
|
69
|
+
/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
|
70
|
+
export const cidrv6: RegExp =
|
|
71
|
+
/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
72
|
+
|
|
73
|
+
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
74
|
+
export const base64: RegExp = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
75
|
+
export const base64url: RegExp = /^[A-Za-z0-9_-]*$/;
|
|
76
|
+
|
|
77
|
+
// based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
|
78
|
+
// export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
|
79
|
+
export const hostname: RegExp =
|
|
80
|
+
/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
|
81
|
+
|
|
82
|
+
export const domain: RegExp = /^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
|
|
83
|
+
|
|
84
|
+
export const httpProtocol: RegExp = /^https?$/;
|
|
85
|
+
|
|
86
|
+
// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
|
|
87
|
+
// E.164: leading digit must be 1-9; total digits (excluding '+') between 7-15
|
|
88
|
+
export const e164: RegExp = /^\+[1-9]\d{6,14}$/;
|
|
89
|
+
|
|
90
|
+
// const dateSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
91
|
+
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
92
|
+
export const date: RegExp = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
|
|
93
|
+
|
|
94
|
+
function timeSource(args: { precision?: number | null | undefined }) {
|
|
95
|
+
const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
|
|
96
|
+
const regex =
|
|
97
|
+
typeof args.precision === "number"
|
|
98
|
+
? args.precision === -1
|
|
99
|
+
? `${hhmm}`
|
|
100
|
+
: args.precision === 0
|
|
101
|
+
? `${hhmm}:[0-5]\\d`
|
|
102
|
+
: `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}`
|
|
103
|
+
: `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
|
|
104
|
+
return regex;
|
|
105
|
+
}
|
|
106
|
+
export function time(args: {
|
|
107
|
+
precision?: number | null;
|
|
108
|
+
// local?: boolean;
|
|
109
|
+
}): RegExp {
|
|
110
|
+
return new RegExp(`^${timeSource(args)}$`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Adapted from https://stackoverflow.com/a/3143231
|
|
114
|
+
export function datetime(args: {
|
|
115
|
+
precision?: number | null;
|
|
116
|
+
offset?: boolean;
|
|
117
|
+
local?: boolean;
|
|
118
|
+
}): RegExp {
|
|
119
|
+
const time = timeSource({ precision: args.precision });
|
|
120
|
+
const opts = ["Z"];
|
|
121
|
+
if (args.local) opts.push("");
|
|
122
|
+
// if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
|
|
123
|
+
if (args.offset) opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
|
|
124
|
+
const timeRegex = `${time}(?:${opts.join("|")})`;
|
|
125
|
+
|
|
126
|
+
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export const string = (params?: { minimum?: number | undefined; maximum?: number | undefined }): RegExp => {
|
|
130
|
+
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
131
|
+
return new RegExp(`^${regex}$`);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const bigint: RegExp = /^-?\d+n?$/;
|
|
135
|
+
export const integer: RegExp = /^-?\d+$/;
|
|
136
|
+
export const number: RegExp = /^-?\d+(?:\.\d+)?$/;
|
|
137
|
+
export const boolean: RegExp = /^(?:true|false)$/i;
|
|
138
|
+
const _null: RegExp = /^null$/i;
|
|
139
|
+
export { _null as null };
|
|
140
|
+
const _undefined: RegExp = /^undefined$/i;
|
|
141
|
+
export { _undefined as undefined };
|
|
142
|
+
|
|
143
|
+
// regex for string with no uppercase letters
|
|
144
|
+
export const lowercase: RegExp = /^[^A-Z]*$/;
|
|
145
|
+
// regex for string with no lowercase letters
|
|
146
|
+
export const uppercase: RegExp = /^[^a-z]*$/;
|
|
147
|
+
|
|
148
|
+
// regex for hexadecimal strings (any length)
|
|
149
|
+
export const hex: RegExp = /^[0-9a-fA-F]*$/;
|
|
150
|
+
|
|
151
|
+
// Hash regexes for different algorithms and encodings
|
|
152
|
+
// Helper function to create base64 regex with exact length and padding
|
|
153
|
+
function fixedBase64(bodyLength: number, padding: "" | "=" | "=="): RegExp {
|
|
154
|
+
return new RegExp(`^[A-Za-z0-9+/]{${bodyLength}}${padding}$`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Helper function to create base64url regex with exact length (no padding)
|
|
158
|
+
function fixedBase64url(length: number): RegExp {
|
|
159
|
+
return new RegExp(`^[A-Za-z0-9_-]{${length}}$`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// MD5 (16 bytes): base64 = 24 chars total (22 + "==")
|
|
163
|
+
export const md5_hex: RegExp = /^[0-9a-fA-F]{32}$/;
|
|
164
|
+
export const md5_base64: RegExp = /*@__PURE__*/ fixedBase64(22, "==");
|
|
165
|
+
export const md5_base64url: RegExp = /*@__PURE__*/ fixedBase64url(22);
|
|
166
|
+
|
|
167
|
+
// SHA1 (20 bytes): base64 = 28 chars total (27 + "=")
|
|
168
|
+
export const sha1_hex: RegExp = /^[0-9a-fA-F]{40}$/;
|
|
169
|
+
export const sha1_base64: RegExp = /*@__PURE__*/ fixedBase64(27, "=");
|
|
170
|
+
export const sha1_base64url: RegExp = /*@__PURE__*/ fixedBase64url(27);
|
|
171
|
+
|
|
172
|
+
// SHA256 (32 bytes): base64 = 44 chars total (43 + "=")
|
|
173
|
+
export const sha256_hex: RegExp = /^[0-9a-fA-F]{64}$/;
|
|
174
|
+
export const sha256_base64: RegExp = /*@__PURE__*/ fixedBase64(43, "=");
|
|
175
|
+
export const sha256_base64url: RegExp = /*@__PURE__*/ fixedBase64url(43);
|
|
176
|
+
|
|
177
|
+
// SHA384 (48 bytes): base64 = 64 chars total (no padding)
|
|
178
|
+
export const sha384_hex: RegExp = /^[0-9a-fA-F]{96}$/;
|
|
179
|
+
export const sha384_base64: RegExp = /*@__PURE__*/ fixedBase64(64, "");
|
|
180
|
+
export const sha384_base64url: RegExp = /*@__PURE__*/ fixedBase64url(64);
|
|
181
|
+
|
|
182
|
+
// SHA512 (64 bytes): base64 = 88 chars total (86 + "==")
|
|
183
|
+
export const sha512_hex: RegExp = /^[0-9a-fA-F]{128}$/;
|
|
184
|
+
export const sha512_base64: RegExp = /*@__PURE__*/ fixedBase64(86, "==");
|
|
185
|
+
export const sha512_base64url: RegExp = /*@__PURE__*/ fixedBase64url(86);
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type * as core from "./core.js";
|
|
2
|
+
import type { $ZodType } from "./schemas.js";
|
|
3
|
+
|
|
4
|
+
export const $output: unique symbol = Symbol("ZodOutput");
|
|
5
|
+
export type $output = typeof $output;
|
|
6
|
+
export const $input: unique symbol = Symbol("ZodInput");
|
|
7
|
+
export type $input = typeof $input;
|
|
8
|
+
|
|
9
|
+
export type $replace<Meta, S extends $ZodType> = Meta extends $output
|
|
10
|
+
? core.output<S>
|
|
11
|
+
: Meta extends $input
|
|
12
|
+
? core.input<S>
|
|
13
|
+
: Meta extends (infer M)[]
|
|
14
|
+
? $replace<M, S>[]
|
|
15
|
+
: Meta extends (...args: infer P) => infer R
|
|
16
|
+
? (
|
|
17
|
+
...args: {
|
|
18
|
+
[K in keyof P]: $replace<P[K], S>; // tuple
|
|
19
|
+
}
|
|
20
|
+
) => $replace<R, S>
|
|
21
|
+
: // handle objects
|
|
22
|
+
Meta extends object
|
|
23
|
+
? { [K in keyof Meta]: $replace<Meta[K], S> }
|
|
24
|
+
: Meta;
|
|
25
|
+
|
|
26
|
+
type MetadataType = object | undefined;
|
|
27
|
+
export class $ZodRegistry<Meta extends MetadataType = MetadataType, Schema extends $ZodType = $ZodType> {
|
|
28
|
+
_meta!: Meta;
|
|
29
|
+
_schema!: Schema;
|
|
30
|
+
_map: WeakMap<Schema, $replace<Meta, Schema>> = new WeakMap();
|
|
31
|
+
_idmap: Map<string, Schema> = new Map();
|
|
32
|
+
|
|
33
|
+
add<S extends Schema>(
|
|
34
|
+
schema: S,
|
|
35
|
+
..._meta: undefined extends Meta ? [$replace<Meta, S>?] : [$replace<Meta, S>]
|
|
36
|
+
): this {
|
|
37
|
+
const meta: any = _meta[0];
|
|
38
|
+
this._map.set(schema, meta!);
|
|
39
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
40
|
+
this._idmap.set(meta.id!, schema);
|
|
41
|
+
}
|
|
42
|
+
return this as any;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
clear(): this {
|
|
46
|
+
this._map = new WeakMap();
|
|
47
|
+
this._idmap = new Map();
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
remove(schema: Schema): this {
|
|
52
|
+
const meta: any = this._map.get(schema);
|
|
53
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
54
|
+
this._idmap.delete(meta.id!);
|
|
55
|
+
}
|
|
56
|
+
this._map.delete(schema);
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get<S extends Schema>(schema: S): $replace<Meta, S> | undefined {
|
|
61
|
+
// return this._map.get(schema) as any;
|
|
62
|
+
|
|
63
|
+
// inherit metadata
|
|
64
|
+
const p = schema._zod.parent as Schema;
|
|
65
|
+
if (p) {
|
|
66
|
+
const pm: any = { ...(this.get(p) ?? {}) };
|
|
67
|
+
delete pm.id; // do not inherit id
|
|
68
|
+
const f = { ...pm, ...this._map.get(schema) } as any;
|
|
69
|
+
return Object.keys(f).length ? f : undefined;
|
|
70
|
+
}
|
|
71
|
+
return this._map.get(schema) as any;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
has(schema: Schema): boolean {
|
|
75
|
+
return this._map.has(schema);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface JSONSchemaMeta {
|
|
80
|
+
id?: string | undefined;
|
|
81
|
+
title?: string | undefined;
|
|
82
|
+
description?: string | undefined;
|
|
83
|
+
deprecated?: boolean | undefined;
|
|
84
|
+
[k: string]: unknown;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface GlobalMeta extends JSONSchemaMeta {}
|
|
88
|
+
|
|
89
|
+
// registries
|
|
90
|
+
export function registry<T extends MetadataType = MetadataType, S extends $ZodType = $ZodType>(): $ZodRegistry<T, S> {
|
|
91
|
+
return new $ZodRegistry<T, S>();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface GlobalThisWithRegistry {
|
|
95
|
+
/**
|
|
96
|
+
* The globalRegistry instance shared across both CommonJS and ESM builds.
|
|
97
|
+
* By attaching the registry to `globalThis`, this property ensures a single, deduplicated instance
|
|
98
|
+
* is used regardless of whether the package is loaded via `require` (CJS) or `import` (ESM).
|
|
99
|
+
* This prevents dual package hazards and keeps registry state consistent.
|
|
100
|
+
*/
|
|
101
|
+
__zod_globalRegistry?: $ZodRegistry<GlobalMeta>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
(globalThis as GlobalThisWithRegistry).__zod_globalRegistry ??= registry<GlobalMeta>();
|
|
105
|
+
export const globalRegistry: $ZodRegistry<GlobalMeta> = (globalThis as GlobalThisWithRegistry).__zod_globalRegistry!;
|