@suveren/gateway 0.39.0 → 0.40.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/dist/mcp-server/http.mjs +1 -1
- package/dist/ui/assets/index-C-lA_7Lt.js +123 -0
- package/dist/ui/assets/index-DM9WXky8.css +1 -0
- package/dist/ui/index.html +2 -2
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.js +10 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/transport.d.ts +8 -8
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/transport.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js +10 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/transport.d.ts +8 -8
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/transport.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/package.json +1 -1
- package/node_modules/follow-redirects/README.md +27 -1
- package/node_modules/follow-redirects/index.js +1 -5
- package/node_modules/follow-redirects/package.json +1 -1
- package/node_modules/hono/README.md +2 -3
- package/node_modules/hono/dist/cjs/helper/css/common.js +8 -3
- package/node_modules/hono/dist/cjs/helper/css/index.js +1 -1
- package/node_modules/hono/dist/cjs/helper/route/index.js +3 -1
- package/node_modules/hono/dist/cjs/jsx/base.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/bearer-auth/index.js +8 -0
- package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +3 -1
- package/node_modules/hono/dist/cjs/router/trie-router/node.js +2 -2
- package/node_modules/hono/dist/cjs/utils/url.js +11 -6
- package/node_modules/hono/dist/helper/css/common.js +8 -3
- package/node_modules/hono/dist/helper/css/index.js +1 -1
- package/node_modules/hono/dist/helper/route/index.js +3 -1
- package/node_modules/hono/dist/jsx/base.js +1 -1
- package/node_modules/hono/dist/middleware/bearer-auth/index.js +8 -0
- package/node_modules/hono/dist/middleware/serve-static/index.js +3 -1
- package/node_modules/hono/dist/router/trie-router/node.js +2 -2
- package/node_modules/hono/dist/types/adapter/aws-lambda/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-pages/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-workers/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/lambda-edge/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/netlify/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/vercel/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/testing/index.d.ts +2 -1
- package/node_modules/hono/dist/types/hono-base.d.ts +21 -9
- package/node_modules/hono/dist/types/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/context.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/css.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/streaming.d.ts +4 -3
- package/node_modules/hono/dist/types/middleware/bearer-auth/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/ip-restriction/index.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +3 -3
- package/node_modules/hono/dist/types/utils/ipaddr.d.ts +1 -1
- package/node_modules/hono/dist/utils/url.js +11 -6
- package/node_modules/hono/package.json +1 -1
- package/node_modules/http-proxy-middleware/dist/handlers/fix-request-body.js +2 -2
- package/node_modules/http-proxy-middleware/package.json +1 -1
- package/node_modules/ip-address/dist/common.js +2 -2
- package/node_modules/ip-address/dist/common.js.map +1 -1
- package/node_modules/ip-address/package.json +2 -2
- package/node_modules/postcss/lib/input.js +1 -1
- package/node_modules/postcss/lib/lazy-result.js +1 -1
- package/node_modules/postcss/lib/no-work-result.js +1 -1
- package/node_modules/postcss/lib/node.js +2 -2
- package/node_modules/postcss/lib/processor.js +1 -1
- package/node_modules/postcss/lib/warning.js +1 -0
- package/node_modules/postcss/package.json +1 -1
- package/node_modules/zod/README.md +34 -24
- package/node_modules/zod/compile.cjs +96 -0
- package/node_modules/zod/compile.d.cts +1 -0
- package/node_modules/zod/compile.d.ts +1 -0
- package/node_modules/zod/compile.js +52 -0
- package/node_modules/zod/index.cjs +22 -3
- package/node_modules/zod/index.d.cts +3 -4
- package/node_modules/zod/index.d.ts +3 -4
- package/node_modules/zod/index.js +7 -4
- package/node_modules/zod/locales/index.cjs +36 -0
- package/node_modules/zod/locales/index.d.cts +1 -0
- package/node_modules/zod/locales/index.d.ts +1 -0
- package/node_modules/zod/locales/index.js +1 -0
- package/node_modules/zod/locales/package.json +7 -0
- package/node_modules/zod/mini/index.cjs +51 -0
- package/node_modules/zod/mini/index.d.cts +3 -0
- package/node_modules/zod/mini/index.d.ts +3 -0
- package/node_modules/zod/mini/index.js +3 -0
- package/node_modules/zod/mini/package.json +7 -0
- package/node_modules/zod/package.json +44 -15
- package/node_modules/zod/src/compile.ts +56 -0
- package/node_modules/zod/src/index.ts +7 -4
- package/node_modules/zod/src/locales/index.ts +1 -0
- package/node_modules/zod/src/mini/index.ts +3 -0
- package/node_modules/zod/src/v3/ZodError.ts +23 -13
- package/node_modules/zod/src/v3/helpers/errorUtil.ts +1 -1
- package/node_modules/zod/src/v3/tests/all-errors.test.ts +3 -3
- package/node_modules/zod/src/v3/tests/complex.test.ts +17 -3
- package/node_modules/zod/src/v3/tests/error.test.ts +35 -0
- package/node_modules/zod/src/v3/tests/function.test.ts +7 -3
- package/node_modules/zod/src/v3/tests/intersection.test.ts +18 -0
- package/node_modules/zod/src/v3/tests/language-server.test.ts +1 -2
- package/node_modules/zod/src/v3/tests/nan.test.ts +5 -2
- package/node_modules/zod/src/v3/tests/object.test.ts +10 -13
- package/node_modules/zod/src/v3/tests/partials.test.ts +3 -3
- package/node_modules/zod/src/v3/tests/readonly.test.ts +0 -80
- package/node_modules/zod/src/v3/tests/string.test.ts +8 -2
- package/node_modules/zod/src/v3/types.ts +8 -6
- package/node_modules/zod/src/v4/classic/checks.ts +3 -0
- package/node_modules/zod/src/v4/classic/compat.ts +30 -18
- package/node_modules/zod/src/v4/classic/deep-partial.ts +76 -0
- package/node_modules/zod/src/v4/classic/errors.ts +61 -39
- package/node_modules/zod/src/v4/classic/external.ts +18 -11
- package/node_modules/zod/src/v4/classic/from-json-schema.ts +944 -0
- package/node_modules/zod/src/v4/classic/in-out.ts +45 -0
- package/node_modules/zod/src/v4/classic/index.ts +2 -2
- package/node_modules/zod/src/v4/classic/iso.ts +2 -72
- package/node_modules/zod/src/v4/classic/parse.ts +57 -2
- package/node_modules/zod/src/v4/classic/schemas.ts +1258 -375
- package/node_modules/zod/src/v4/classic/tests/apply.test.ts +86 -0
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +35 -8
- package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +192 -0
- package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +36 -1
- package/node_modules/zod/src/v4/classic/tests/brand.test.ts +43 -0
- package/node_modules/zod/src/v4/classic/tests/catch.test.ts +357 -5
- package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +572 -0
- package/node_modules/zod/src/v4/classic/tests/codec.test.ts +704 -0
- package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +27 -5
- package/node_modules/zod/src/v4/classic/tests/credit-card.test.ts +76 -0
- package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +985 -0
- package/node_modules/zod/src/v4/classic/tests/date.test.ts +67 -6
- package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +37 -17
- package/node_modules/zod/src/v4/classic/tests/deep-partial.test.ts +380 -0
- package/node_modules/zod/src/v4/classic/tests/default-locale.test.ts +32 -0
- package/node_modules/zod/src/v4/classic/tests/default.test.ts +142 -0
- package/node_modules/zod/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
- package/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +221 -0
- package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +333 -10
- package/node_modules/zod/src/v4/classic/tests/enum.test.ts +20 -0
- package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +394 -4
- package/node_modules/zod/src/v4/classic/tests/error.test.ts +403 -6
- package/node_modules/zod/src/v4/classic/tests/file.test.ts +9 -4
- package/node_modules/zod/src/v4/classic/tests/firstparty.test.ts +4 -0
- package/node_modules/zod/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
- package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +1467 -0
- package/node_modules/zod/src/v4/classic/tests/function.test.ts +160 -37
- package/node_modules/zod/src/v4/classic/tests/global-config.test.ts +32 -0
- package/node_modules/zod/src/v4/classic/tests/hash.test.ts +67 -0
- package/node_modules/zod/src/v4/classic/tests/iban.test.ts +81 -0
- package/node_modules/zod/src/v4/classic/tests/in-out.test.ts +159 -0
- package/node_modules/zod/src/v4/classic/tests/index.test.ts +134 -5
- package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +319 -0
- package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +93 -0
- package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +168 -5
- package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +215 -0
- package/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +39 -0
- package/node_modules/zod/src/v4/classic/tests/json.test.ts +4 -3
- package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +36 -1
- package/node_modules/zod/src/v4/classic/tests/literal.test.ts +37 -1
- package/node_modules/zod/src/v4/classic/tests/locales_ka.test.ts +29 -0
- package/node_modules/zod/src/v4/classic/tests/locales_ro.test.ts +24 -0
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +153 -0
- package/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts +15 -0
- package/node_modules/zod/src/v4/classic/tests/number.test.ts +161 -7
- package/node_modules/zod/src/v4/classic/tests/object.test.ts +457 -14
- package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +235 -0
- package/node_modules/zod/src/v4/classic/tests/optional.test.ts +255 -12
- package/node_modules/zod/src/v4/classic/tests/partial.test.ts +350 -0
- package/node_modules/zod/src/v4/classic/tests/pickomit.test.ts +89 -5
- package/node_modules/zod/src/v4/classic/tests/pipe.test.ts +25 -5
- package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +107 -0
- package/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +44 -0
- package/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +74 -21
- package/node_modules/zod/src/v4/classic/tests/promise.test.ts +1 -1
- package/node_modules/zod/src/v4/classic/tests/properties.test.ts +141 -0
- package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +1 -69
- package/node_modules/zod/src/v4/classic/tests/record.test.ts +553 -10
- package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +352 -1
- package/node_modules/zod/src/v4/classic/tests/redos.test.ts +68 -0
- package/node_modules/zod/src/v4/classic/tests/refine.test.ts +229 -68
- package/node_modules/zod/src/v4/classic/tests/registries.test.ts +40 -1
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +20 -3
- package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +96 -0
- package/node_modules/zod/src/v4/classic/tests/string-formats.test.ts +16 -0
- package/node_modules/zod/src/v4/classic/tests/string.test.ts +568 -9
- package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +58 -0
- package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +70 -16
- package/node_modules/zod/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
- package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +3409 -990
- package/node_modules/zod/src/v4/classic/tests/transform.test.ts +128 -0
- package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +353 -5
- package/node_modules/zod/src/v4/classic/tests/union.test.ts +219 -3
- package/node_modules/zod/src/v4/classic/tests/url.test.ts +13 -0
- package/node_modules/zod/src/v4/classic/tests/validate.test.ts +645 -0
- package/node_modules/zod/src/v4/classic/tests/validations.test.ts +2 -2
- package/node_modules/zod/src/v4/core/api.ts +442 -161
- package/node_modules/zod/src/v4/core/checks.ts +134 -151
- package/node_modules/zod/src/v4/core/compile.ts +2322 -0
- package/node_modules/zod/src/v4/core/core.ts +146 -50
- package/node_modules/zod/src/v4/core/doc.ts +18 -10
- package/node_modules/zod/src/v4/core/errors.ts +221 -102
- package/node_modules/zod/src/v4/core/index.ts +5 -1
- package/node_modules/zod/src/v4/core/json-schema-generator.ts +131 -0
- package/node_modules/zod/src/v4/core/json-schema-processors.ts +934 -0
- package/node_modules/zod/src/v4/core/json-schema.ts +9 -4
- package/node_modules/zod/src/v4/core/memoizer.ts +331 -0
- package/node_modules/zod/src/v4/core/parse.ts +252 -37
- package/node_modules/zod/src/v4/core/regexes.ts +112 -30
- package/node_modules/zod/src/v4/core/registries.ts +19 -10
- package/node_modules/zod/src/v4/core/schemas.ts +1972 -588
- package/node_modules/zod/src/v4/core/standard-schema.ts +114 -19
- package/node_modules/zod/src/v4/core/tests/cached.test.ts +54 -0
- package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +1004 -0
- package/node_modules/zod/src/v4/core/tests/compile-generative.test.ts +445 -0
- package/node_modules/zod/src/v4/core/tests/compile-global.test.ts +89 -0
- package/node_modules/zod/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
- package/node_modules/zod/src/v4/core/tests/compile-stats.test.ts +34 -0
- package/node_modules/zod/src/v4/core/tests/compile.test.ts +2036 -0
- package/node_modules/zod/src/v4/core/tests/email-regex.test.ts +140 -0
- package/node_modules/zod/src/v4/core/tests/extend.test.ts +59 -0
- package/node_modules/zod/src/v4/core/tests/locales/el.test.ts +214 -0
- package/node_modules/zod/src/v4/core/tests/locales/en.test.ts +1 -1
- package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +180 -0
- package/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +72 -0
- package/node_modules/zod/src/v4/core/tests/locales/he.test.ts +379 -0
- package/node_modules/zod/src/v4/core/tests/locales/hr.test.ts +163 -0
- package/node_modules/zod/src/v4/core/tests/locales/nl.test.ts +46 -0
- package/node_modules/zod/src/v4/core/tests/locales/parity.test.ts +42 -0
- package/node_modules/zod/src/v4/core/tests/locales/tg.test.ts +85 -0
- package/node_modules/zod/src/v4/core/tests/locales/tk.test.ts +69 -0
- package/node_modules/zod/src/v4/core/tests/locales/tr.test.ts +2 -2
- package/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +105 -0
- package/node_modules/zod/src/v4/core/tests/polyfill-collision.test.ts +46 -0
- package/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +125 -0
- package/node_modules/zod/src/v4/core/tests/recursive-tuples.test.ts +45 -0
- package/node_modules/zod/src/v4/core/tests/treeshake.test.ts +51 -0
- package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +133 -0
- package/node_modules/zod/src/v4/core/to-json-schema.ts +706 -826
- package/node_modules/zod/src/v4/core/util.ts +675 -157
- package/node_modules/zod/src/v4/core/versions.ts +2 -2
- package/node_modules/zod/src/v4/core/visit.ts +193 -0
- package/node_modules/zod/src/v4/index.ts +3 -3
- package/node_modules/zod/src/v4/locales/ar.ts +22 -27
- package/node_modules/zod/src/v4/locales/az.ts +22 -27
- package/node_modules/zod/src/v4/locales/be.ts +31 -27
- package/node_modules/zod/src/v4/locales/bg.ts +133 -0
- package/node_modules/zod/src/v4/locales/bn.ts +123 -0
- package/node_modules/zod/src/v4/locales/ca.ts +22 -28
- package/node_modules/zod/src/v4/locales/ckb.ts +140 -0
- package/node_modules/zod/src/v4/locales/cs.ts +26 -45
- package/node_modules/zod/src/v4/locales/da.ts +128 -0
- package/node_modules/zod/src/v4/locales/de.ts +24 -27
- package/node_modules/zod/src/v4/locales/el.ts +124 -0
- package/node_modules/zod/src/v4/locales/en.ts +38 -29
- package/node_modules/zod/src/v4/locales/eo.ts +25 -27
- package/node_modules/zod/src/v4/locales/es.ts +53 -33
- package/node_modules/zod/src/v4/locales/fa.ts +24 -27
- package/node_modules/zod/src/v4/locales/fi.ts +22 -27
- package/node_modules/zod/src/v4/locales/fr-CA.ts +22 -27
- package/node_modules/zod/src/v4/locales/fr.ts +58 -43
- package/node_modules/zod/src/v4/locales/gu.ts +123 -0
- package/node_modules/zod/src/v4/locales/he.ts +208 -80
- package/node_modules/zod/src/v4/locales/hi.ts +126 -0
- package/node_modules/zod/src/v4/locales/hr.ts +135 -0
- package/node_modules/zod/src/v4/locales/hu.ts +24 -28
- package/node_modules/zod/src/v4/locales/hy.ts +175 -0
- package/node_modules/zod/src/v4/locales/id.ts +22 -27
- package/node_modules/zod/src/v4/locales/index.ts +24 -0
- package/node_modules/zod/src/v4/locales/is.ts +124 -0
- package/node_modules/zod/src/v4/locales/it.ts +24 -28
- package/node_modules/zod/src/v4/locales/ja.ts +24 -27
- package/node_modules/zod/src/v4/locales/ka.ts +128 -0
- package/node_modules/zod/src/v4/locales/kh.ts +3 -122
- package/node_modules/zod/src/v4/locales/km.ts +124 -0
- package/node_modules/zod/src/v4/locales/kn.ts +126 -0
- package/node_modules/zod/src/v4/locales/ko.ts +22 -27
- package/node_modules/zod/src/v4/locales/lt.ts +243 -0
- package/node_modules/zod/src/v4/locales/mk.ts +24 -28
- package/node_modules/zod/src/v4/locales/ms.ts +23 -27
- package/node_modules/zod/src/v4/locales/ne.ts +128 -0
- package/node_modules/zod/src/v4/locales/nl.ts +37 -37
- package/node_modules/zod/src/v4/locales/nn.ts +121 -0
- package/node_modules/zod/src/v4/locales/no.ts +26 -29
- package/node_modules/zod/src/v4/locales/ota.ts +25 -28
- package/node_modules/zod/src/v4/locales/pl.ts +24 -27
- package/node_modules/zod/src/v4/locales/ps.ts +24 -26
- package/node_modules/zod/src/v4/locales/pt-BR.ts +161 -0
- package/node_modules/zod/src/v4/locales/pt.ts +107 -71
- package/node_modules/zod/src/v4/locales/ro.ts +132 -0
- package/node_modules/zod/src/v4/locales/ru.ts +31 -27
- package/node_modules/zod/src/v4/locales/sk.ts +123 -0
- package/node_modules/zod/src/v4/locales/sl.ts +24 -27
- package/node_modules/zod/src/v4/locales/sv.ts +26 -29
- package/node_modules/zod/src/v4/locales/ta.ts +25 -27
- package/node_modules/zod/src/v4/locales/tg.ts +135 -0
- package/node_modules/zod/src/v4/locales/th.ts +25 -27
- package/node_modules/zod/src/v4/locales/tk.ts +113 -0
- package/node_modules/zod/src/v4/locales/tr.ts +22 -27
- package/node_modules/zod/src/v4/locales/ua.ts +3 -122
- package/node_modules/zod/src/v4/locales/uk.ts +122 -0
- package/node_modules/zod/src/v4/locales/ur.ts +25 -27
- package/node_modules/zod/src/v4/locales/uz.ts +120 -0
- package/node_modules/zod/src/v4/locales/vi.ts +24 -27
- package/node_modules/zod/src/v4/locales/yo.ts +129 -0
- package/node_modules/zod/src/v4/locales/zh-CN.ts +25 -27
- package/node_modules/zod/src/v4/locales/zh-TW.ts +22 -27
- package/node_modules/zod/src/v4/mini/checks.ts +1 -0
- package/node_modules/zod/src/v4/mini/coerce.ts +5 -0
- package/node_modules/zod/src/v4/mini/deep-partial.ts +73 -0
- package/node_modules/zod/src/v4/mini/external.ts +15 -3
- package/node_modules/zod/src/v4/mini/in-out.ts +45 -0
- package/node_modules/zod/src/v4/mini/iso.ts +8 -4
- package/node_modules/zod/src/v4/mini/parse.ts +16 -1
- package/node_modules/zod/src/v4/mini/schemas.ts +586 -114
- package/node_modules/zod/src/v4/mini/tests/apply.test.ts +57 -0
- package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +63 -2
- package/node_modules/zod/src/v4/mini/tests/brand.test.ts +43 -0
- package/node_modules/zod/src/v4/mini/tests/checks.test.ts +14 -0
- package/node_modules/zod/src/v4/mini/tests/codec.test.ts +582 -0
- package/node_modules/zod/src/v4/mini/tests/computed.test.ts +12 -18
- package/node_modules/zod/src/v4/mini/tests/cyclic-data.test.ts +84 -0
- package/node_modules/zod/src/v4/mini/tests/deep-partial.test.ts +54 -0
- package/node_modules/zod/src/v4/mini/tests/error.test.ts +24 -5
- package/node_modules/zod/src/v4/mini/tests/functions.test.ts +7 -36
- package/node_modules/zod/src/v4/mini/tests/index.test.ts +281 -6
- package/node_modules/zod/src/v4/mini/tests/number.test.ts +15 -1
- package/node_modules/zod/src/v4/mini/tests/object.test.ts +116 -9
- package/node_modules/zod/src/v4/mini/tests/prototypes.test.ts +1 -1
- package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +68 -2
- package/node_modules/zod/src/v4/mini/tests/standard-schema.test.ts +50 -0
- package/node_modules/zod/src/v4/mini/tests/string.test.ts +98 -1
- package/node_modules/zod/src/v4-mini/index.ts +3 -1
- package/node_modules/zod/v3/ZodError.cjs +42 -13
- package/node_modules/zod/v3/ZodError.d.cts +6 -6
- package/node_modules/zod/v3/ZodError.d.ts +6 -6
- package/node_modules/zod/v3/ZodError.js +23 -13
- package/node_modules/zod/v3/errors.cjs +19 -0
- package/node_modules/zod/v3/external.cjs +19 -0
- package/node_modules/zod/v3/helpers/enumUtil.cjs +19 -0
- package/node_modules/zod/v3/helpers/errorUtil.cjs +20 -1
- package/node_modules/zod/v3/helpers/errorUtil.js +1 -1
- package/node_modules/zod/v3/helpers/parseUtil.cjs +19 -0
- package/node_modules/zod/v3/helpers/partialUtil.cjs +19 -0
- package/node_modules/zod/v3/helpers/typeAliases.cjs +19 -0
- package/node_modules/zod/v3/helpers/util.cjs +19 -0
- package/node_modules/zod/v3/index.cjs +19 -0
- package/node_modules/zod/v3/locales/en.cjs +1 -0
- package/node_modules/zod/v3/locales/en.d.cts +1 -1
- package/node_modules/zod/v3/package.json +7 -0
- package/node_modules/zod/v3/standard-schema.cjs +19 -0
- package/node_modules/zod/v3/types.cjs +28 -5
- package/node_modules/zod/v3/types.d.cts +4 -1
- package/node_modules/zod/v3/types.d.ts +4 -1
- package/node_modules/zod/v3/types.js +9 -5
- package/node_modules/zod/v4/classic/checks.cjs +22 -1
- package/node_modules/zod/v4/classic/checks.d.cts +1 -1
- package/node_modules/zod/v4/classic/checks.d.ts +1 -1
- package/node_modules/zod/v4/classic/checks.js +1 -1
- package/node_modules/zod/v4/classic/coerce.cjs +19 -0
- package/node_modules/zod/v4/classic/compat.cjs +24 -1
- package/node_modules/zod/v4/classic/compat.d.cts +13 -11
- package/node_modules/zod/v4/classic/compat.d.ts +13 -11
- package/node_modules/zod/v4/classic/compat.js +4 -0
- package/node_modules/zod/v4/classic/deep-partial.cjs +58 -0
- package/node_modules/zod/v4/classic/deep-partial.d.cts +14 -0
- package/node_modules/zod/v4/classic/deep-partial.d.ts +14 -0
- package/node_modules/zod/v4/classic/deep-partial.js +13 -0
- package/node_modules/zod/v4/classic/errors.cjs +63 -28
- package/node_modules/zod/v4/classic/errors.d.cts +3 -4
- package/node_modules/zod/v4/classic/errors.d.ts +3 -4
- package/node_modules/zod/v4/classic/errors.js +45 -29
- package/node_modules/zod/v4/classic/external.cjs +55 -28
- package/node_modules/zod/v4/classic/external.d.cts +8 -2
- package/node_modules/zod/v4/classic/external.d.ts +8 -2
- package/node_modules/zod/v4/classic/external.js +7 -8
- package/node_modules/zod/v4/classic/from-json-schema.cjs +926 -0
- package/node_modules/zod/v4/classic/from-json-schema.d.cts +12 -0
- package/node_modules/zod/v4/classic/from-json-schema.d.ts +12 -0
- package/node_modules/zod/v4/classic/from-json-schema.js +881 -0
- package/node_modules/zod/v4/classic/in-out.cjs +82 -0
- package/node_modules/zod/v4/classic/in-out.d.cts +8 -0
- package/node_modules/zod/v4/classic/in-out.d.ts +8 -0
- package/node_modules/zod/v4/classic/in-out.js +36 -0
- package/node_modules/zod/v4/classic/index.cjs +21 -2
- package/node_modules/zod/v4/classic/index.d.cts +1 -2
- package/node_modules/zod/v4/classic/index.d.ts +1 -2
- package/node_modules/zod/v4/classic/index.js +2 -2
- package/node_modules/zod/v4/classic/iso.cjs +30 -22
- package/node_modules/zod/v4/classic/iso.d.cts +2 -17
- package/node_modules/zod/v4/classic/iso.d.ts +2 -17
- package/node_modules/zod/v4/classic/iso.js +2 -17
- package/node_modules/zod/v4/classic/package.json +7 -0
- package/node_modules/zod/v4/classic/parse.cjs +32 -1
- package/node_modules/zod/v4/classic/parse.d.cts +21 -0
- package/node_modules/zod/v4/classic/parse.d.ts +21 -0
- package/node_modules/zod/v4/classic/parse.js +10 -0
- package/node_modules/zod/v4/classic/schemas.cjs +805 -238
- package/node_modules/zod/v4/classic/schemas.d.cts +241 -55
- package/node_modules/zod/v4/classic/schemas.d.ts +241 -55
- package/node_modules/zod/v4/classic/schemas.js +766 -237
- package/node_modules/zod/v4/core/api.cjs +284 -54
- package/node_modules/zod/v4/core/api.d.cts +133 -82
- package/node_modules/zod/v4/core/api.d.ts +133 -82
- package/node_modules/zod/v4/core/api.js +255 -54
- package/node_modules/zod/v4/core/checks.cjs +100 -130
- package/node_modules/zod/v4/core/checks.d.cts +32 -16
- package/node_modules/zod/v4/core/checks.d.ts +32 -16
- package/node_modules/zod/v4/core/checks.js +80 -129
- package/node_modules/zod/v4/core/compile.cjs +1916 -0
- package/node_modules/zod/v4/core/compile.d.cts +65 -0
- package/node_modules/zod/v4/core/compile.d.ts +65 -0
- package/node_modules/zod/v4/core/compile.js +1866 -0
- package/node_modules/zod/v4/core/core.cjs +120 -20
- package/node_modules/zod/v4/core/core.d.cts +40 -7
- package/node_modules/zod/v4/core/core.d.ts +40 -7
- package/node_modules/zod/v4/core/core.js +101 -21
- package/node_modules/zod/v4/core/doc.cjs +31 -9
- package/node_modules/zod/v4/core/doc.d.cts +4 -2
- package/node_modules/zod/v4/core/doc.d.ts +4 -2
- package/node_modules/zod/v4/core/doc.js +12 -9
- package/node_modules/zod/v4/core/errors.cjs +151 -60
- package/node_modules/zod/v4/core/errors.d.cts +41 -24
- package/node_modules/zod/v4/core/errors.d.ts +41 -24
- package/node_modules/zod/v4/core/errors.js +132 -60
- package/node_modules/zod/v4/core/index.cjs +28 -2
- package/node_modules/zod/v4/core/index.d.cts +5 -1
- package/node_modules/zod/v4/core/index.d.ts +5 -1
- package/node_modules/zod/v4/core/index.js +5 -1
- package/node_modules/zod/v4/core/json-schema-generator.cjs +122 -0
- package/node_modules/zod/v4/core/json-schema-generator.d.cts +65 -0
- package/node_modules/zod/v4/core/json-schema-generator.d.ts +65 -0
- package/node_modules/zod/v4/core/json-schema-generator.js +99 -0
- package/node_modules/zod/v4/core/json-schema-processors.cjs +929 -0
- package/node_modules/zod/v4/core/json-schema-processors.d.cts +65 -0
- package/node_modules/zod/v4/core/json-schema-processors.d.ts +65 -0
- package/node_modules/zod/v4/core/json-schema-processors.js +843 -0
- package/node_modules/zod/v4/core/json-schema.cjs +19 -0
- package/node_modules/zod/v4/core/json-schema.d.cts +6 -4
- package/node_modules/zod/v4/core/json-schema.d.ts +6 -4
- package/node_modules/zod/v4/core/memoizer.cjs +360 -0
- package/node_modules/zod/v4/core/memoizer.d.cts +15 -0
- package/node_modules/zod/v4/core/memoizer.d.ts +15 -0
- package/node_modules/zod/v4/core/memoizer.js +311 -0
- package/node_modules/zod/v4/core/package.json +7 -0
- package/node_modules/zod/v4/core/parse.cjs +183 -37
- package/node_modules/zod/v4/core/parse.d.cts +34 -7
- package/node_modules/zod/v4/core/parse.d.ts +34 -7
- package/node_modules/zod/v4/core/parse.js +154 -36
- package/node_modules/zod/v4/core/regexes.cjs +137 -31
- package/node_modules/zod/v4/core/regexes.d.cts +30 -2
- package/node_modules/zod/v4/core/regexes.d.ts +30 -2
- package/node_modules/zod/v4/core/regexes.js +90 -29
- package/node_modules/zod/v4/core/registries.cjs +26 -7
- package/node_modules/zod/v4/core/registries.d.cts +2 -2
- package/node_modules/zod/v4/core/registries.d.ts +2 -2
- package/node_modules/zod/v4/core/registries.js +9 -9
- package/node_modules/zod/v4/core/schemas.cjs +1373 -422
- package/node_modules/zod/v4/core/schemas.d.cts +276 -42
- package/node_modules/zod/v4/core/schemas.d.ts +276 -42
- package/node_modules/zod/v4/core/schemas.js +1341 -422
- package/node_modules/zod/v4/core/standard-schema.cjs +19 -0
- package/node_modules/zod/v4/core/standard-schema.d.cts +90 -19
- package/node_modules/zod/v4/core/standard-schema.d.ts +90 -19
- package/node_modules/zod/v4/core/to-json-schema.cjs +628 -801
- package/node_modules/zod/v4/core/to-json-schema.d.cts +103 -37
- package/node_modules/zod/v4/core/to-json-schema.d.ts +103 -37
- package/node_modules/zod/v4/core/to-json-schema.js +602 -800
- package/node_modules/zod/v4/core/util.cjs +580 -155
- package/node_modules/zod/v4/core/util.d.cts +98 -1
- package/node_modules/zod/v4/core/util.d.ts +98 -1
- package/node_modules/zod/v4/core/util.js +536 -156
- package/node_modules/zod/v4/core/versions.cjs +21 -2
- package/node_modules/zod/v4/core/versions.d.cts +1 -1
- package/node_modules/zod/v4/core/versions.d.ts +1 -1
- package/node_modules/zod/v4/core/versions.js +2 -2
- package/node_modules/zod/v4/core/visit.cjs +214 -0
- package/node_modules/zod/v4/core/visit.d.cts +30 -0
- package/node_modules/zod/v4/core/visit.d.ts +30 -0
- package/node_modules/zod/v4/core/visit.js +169 -0
- package/node_modules/zod/v4/index.cjs +34 -5
- package/node_modules/zod/v4/index.d.cts +2 -2
- package/node_modules/zod/v4/index.d.ts +2 -2
- package/node_modules/zod/v4/index.js +3 -2
- package/node_modules/zod/v4/locales/ar.cjs +20 -24
- package/node_modules/zod/v4/locales/ar.d.cts +2 -1
- package/node_modules/zod/v4/locales/ar.js +19 -24
- package/node_modules/zod/v4/locales/az.cjs +20 -24
- package/node_modules/zod/v4/locales/az.d.cts +2 -1
- package/node_modules/zod/v4/locales/az.js +19 -24
- package/node_modules/zod/v4/locales/be.cjs +29 -24
- package/node_modules/zod/v4/locales/be.d.cts +2 -1
- package/node_modules/zod/v4/locales/be.js +28 -24
- package/node_modules/zod/v4/locales/bg.cjs +152 -0
- package/node_modules/zod/v4/locales/bg.d.cts +5 -0
- package/node_modules/zod/v4/locales/bg.d.ts +4 -0
- package/node_modules/zod/v4/locales/bg.js +125 -0
- package/node_modules/zod/v4/locales/bn.cjs +140 -0
- package/node_modules/zod/v4/locales/bn.d.cts +5 -0
- package/node_modules/zod/v4/locales/bn.d.ts +4 -0
- package/node_modules/zod/v4/locales/bn.js +113 -0
- package/node_modules/zod/v4/locales/ca.cjs +20 -25
- package/node_modules/zod/v4/locales/ca.d.cts +2 -1
- package/node_modules/zod/v4/locales/ca.js +19 -25
- package/node_modules/zod/v4/locales/ckb.cjs +160 -0
- package/node_modules/zod/v4/locales/ckb.d.cts +5 -0
- package/node_modules/zod/v4/locales/ckb.d.ts +4 -0
- package/node_modules/zod/v4/locales/ckb.js +133 -0
- package/node_modules/zod/v4/locales/cs.cjs +24 -42
- package/node_modules/zod/v4/locales/cs.d.cts +2 -1
- package/node_modules/zod/v4/locales/cs.js +23 -42
- package/node_modules/zod/v4/locales/da.cjs +147 -0
- package/node_modules/zod/v4/locales/da.d.cts +5 -0
- package/node_modules/zod/v4/locales/da.d.ts +4 -0
- package/node_modules/zod/v4/locales/da.js +120 -0
- package/node_modules/zod/v4/locales/de.cjs +22 -24
- package/node_modules/zod/v4/locales/de.d.cts +2 -1
- package/node_modules/zod/v4/locales/de.js +21 -24
- package/node_modules/zod/v4/locales/el.cjs +139 -0
- package/node_modules/zod/v4/locales/el.d.cts +5 -0
- package/node_modules/zod/v4/locales/el.d.ts +4 -0
- package/node_modules/zod/v4/locales/el.js +112 -0
- package/node_modules/zod/v4/locales/en.cjs +35 -28
- package/node_modules/zod/v4/locales/en.d.cts +2 -2
- package/node_modules/zod/v4/locales/en.d.ts +0 -1
- package/node_modules/zod/v4/locales/en.js +34 -26
- package/node_modules/zod/v4/locales/eo.cjs +23 -26
- package/node_modules/zod/v4/locales/eo.d.cts +2 -2
- package/node_modules/zod/v4/locales/eo.d.ts +0 -1
- package/node_modules/zod/v4/locales/eo.js +22 -24
- package/node_modules/zod/v4/locales/es.cjs +51 -31
- package/node_modules/zod/v4/locales/es.d.cts +2 -1
- package/node_modules/zod/v4/locales/es.js +50 -31
- package/node_modules/zod/v4/locales/fa.cjs +22 -24
- package/node_modules/zod/v4/locales/fa.d.cts +2 -1
- package/node_modules/zod/v4/locales/fa.js +21 -24
- package/node_modules/zod/v4/locales/fi.cjs +20 -24
- package/node_modules/zod/v4/locales/fi.d.cts +2 -1
- package/node_modules/zod/v4/locales/fi.js +19 -24
- package/node_modules/zod/v4/locales/fr-CA.cjs +20 -24
- package/node_modules/zod/v4/locales/fr-CA.d.cts +2 -1
- package/node_modules/zod/v4/locales/fr-CA.js +19 -24
- package/node_modules/zod/v4/locales/fr.cjs +53 -39
- package/node_modules/zod/v4/locales/fr.d.cts +2 -1
- package/node_modules/zod/v4/locales/fr.js +52 -39
- package/node_modules/zod/v4/locales/gu.cjs +140 -0
- package/node_modules/zod/v4/locales/gu.d.cts +5 -0
- package/node_modules/zod/v4/locales/gu.d.ts +4 -0
- package/node_modules/zod/v4/locales/gu.js +113 -0
- package/node_modules/zod/v4/locales/he.cjs +183 -78
- package/node_modules/zod/v4/locales/he.d.cts +2 -1
- package/node_modules/zod/v4/locales/he.js +182 -78
- package/node_modules/zod/v4/locales/hi.cjs +138 -0
- package/node_modules/zod/v4/locales/hi.d.cts +5 -0
- package/node_modules/zod/v4/locales/hi.d.ts +4 -0
- package/node_modules/zod/v4/locales/hi.js +111 -0
- package/node_modules/zod/v4/locales/hr.cjs +153 -0
- package/node_modules/zod/v4/locales/hr.d.cts +5 -0
- package/node_modules/zod/v4/locales/hr.d.ts +4 -0
- package/node_modules/zod/v4/locales/hr.js +126 -0
- package/node_modules/zod/v4/locales/hu.cjs +22 -25
- package/node_modules/zod/v4/locales/hu.d.cts +2 -1
- package/node_modules/zod/v4/locales/hu.js +21 -25
- package/node_modules/zod/v4/locales/hy.cjs +185 -0
- package/node_modules/zod/v4/locales/hy.d.cts +5 -0
- package/node_modules/zod/v4/locales/hy.d.ts +4 -0
- package/node_modules/zod/v4/locales/hy.js +158 -0
- package/node_modules/zod/v4/locales/id.cjs +20 -24
- package/node_modules/zod/v4/locales/id.d.cts +2 -1
- package/node_modules/zod/v4/locales/id.js +19 -24
- package/node_modules/zod/v4/locales/index.cjs +69 -1
- package/node_modules/zod/v4/locales/index.d.cts +24 -0
- package/node_modules/zod/v4/locales/index.d.ts +24 -0
- package/node_modules/zod/v4/locales/index.js +24 -0
- package/node_modules/zod/v4/locales/is.cjs +141 -0
- package/node_modules/zod/v4/locales/is.d.cts +5 -0
- package/node_modules/zod/v4/locales/is.d.ts +4 -0
- package/node_modules/zod/v4/locales/is.js +114 -0
- package/node_modules/zod/v4/locales/it.cjs +22 -25
- package/node_modules/zod/v4/locales/it.d.cts +2 -1
- package/node_modules/zod/v4/locales/it.js +21 -25
- package/node_modules/zod/v4/locales/ja.cjs +22 -24
- package/node_modules/zod/v4/locales/ja.d.cts +2 -1
- package/node_modules/zod/v4/locales/ja.js +21 -24
- package/node_modules/zod/v4/locales/ka.cjs +144 -0
- package/node_modules/zod/v4/locales/ka.d.cts +5 -0
- package/node_modules/zod/v4/locales/ka.d.ts +4 -0
- package/node_modules/zod/v4/locales/ka.js +117 -0
- package/node_modules/zod/v4/locales/kh.cjs +6 -137
- package/node_modules/zod/v4/locales/kh.d.cts +2 -1
- package/node_modules/zod/v4/locales/kh.d.ts +1 -0
- package/node_modules/zod/v4/locales/kh.js +3 -115
- package/node_modules/zod/v4/locales/km.cjs +142 -0
- package/node_modules/zod/v4/locales/km.d.cts +5 -0
- package/node_modules/zod/v4/locales/km.d.ts +4 -0
- package/node_modules/zod/v4/locales/km.js +115 -0
- package/node_modules/zod/v4/locales/kn.cjs +143 -0
- package/node_modules/zod/v4/locales/kn.d.cts +5 -0
- package/node_modules/zod/v4/locales/kn.d.ts +4 -0
- package/node_modules/zod/v4/locales/kn.js +116 -0
- package/node_modules/zod/v4/locales/ko.cjs +20 -24
- package/node_modules/zod/v4/locales/ko.d.cts +2 -1
- package/node_modules/zod/v4/locales/ko.js +19 -24
- package/node_modules/zod/v4/locales/lt.cjs +234 -0
- package/node_modules/zod/v4/locales/lt.d.cts +5 -0
- package/node_modules/zod/v4/locales/lt.d.ts +4 -0
- package/node_modules/zod/v4/locales/lt.js +207 -0
- package/node_modules/zod/v4/locales/mk.cjs +22 -25
- package/node_modules/zod/v4/locales/mk.d.cts +2 -1
- package/node_modules/zod/v4/locales/mk.js +21 -25
- package/node_modules/zod/v4/locales/ms.cjs +21 -24
- package/node_modules/zod/v4/locales/ms.d.cts +2 -1
- package/node_modules/zod/v4/locales/ms.js +20 -24
- package/node_modules/zod/v4/locales/ne.cjs +138 -0
- package/node_modules/zod/v4/locales/ne.d.cts +5 -0
- package/node_modules/zod/v4/locales/ne.d.ts +4 -0
- package/node_modules/zod/v4/locales/ne.js +111 -0
- package/node_modules/zod/v4/locales/nl.cjs +31 -32
- package/node_modules/zod/v4/locales/nl.d.cts +2 -1
- package/node_modules/zod/v4/locales/nl.js +30 -32
- package/node_modules/zod/v4/locales/nn.cjs +140 -0
- package/node_modules/zod/v4/locales/nn.d.cts +5 -0
- package/node_modules/zod/v4/locales/nn.d.ts +4 -0
- package/node_modules/zod/v4/locales/nn.js +113 -0
- package/node_modules/zod/v4/locales/no.cjs +24 -26
- package/node_modules/zod/v4/locales/no.d.cts +2 -1
- package/node_modules/zod/v4/locales/no.js +23 -26
- package/node_modules/zod/v4/locales/ota.cjs +23 -25
- package/node_modules/zod/v4/locales/ota.d.cts +2 -1
- package/node_modules/zod/v4/locales/ota.js +22 -25
- package/node_modules/zod/v4/locales/package.json +7 -0
- package/node_modules/zod/v4/locales/pl.cjs +22 -24
- package/node_modules/zod/v4/locales/pl.d.cts +2 -1
- package/node_modules/zod/v4/locales/pl.js +21 -24
- package/node_modules/zod/v4/locales/ps.cjs +22 -24
- package/node_modules/zod/v4/locales/ps.d.cts +2 -1
- package/node_modules/zod/v4/locales/ps.js +21 -24
- package/node_modules/zod/v4/locales/pt-BR.cjs +170 -0
- package/node_modules/zod/v4/locales/pt-BR.d.cts +5 -0
- package/node_modules/zod/v4/locales/pt-BR.d.ts +4 -0
- package/node_modules/zod/v4/locales/pt-BR.js +143 -0
- package/node_modules/zod/v4/locales/pt.cjs +95 -68
- package/node_modules/zod/v4/locales/pt.d.cts +2 -1
- package/node_modules/zod/v4/locales/pt.js +94 -68
- package/node_modules/zod/v4/locales/ro.cjs +149 -0
- package/node_modules/zod/v4/locales/ro.d.cts +5 -0
- package/node_modules/zod/v4/locales/ro.d.ts +4 -0
- package/node_modules/zod/v4/locales/ro.js +122 -0
- package/node_modules/zod/v4/locales/ru.cjs +29 -24
- package/node_modules/zod/v4/locales/ru.d.cts +2 -1
- package/node_modules/zod/v4/locales/ru.js +28 -24
- package/node_modules/zod/v4/locales/sk.cjs +143 -0
- package/node_modules/zod/v4/locales/sk.d.cts +5 -0
- package/node_modules/zod/v4/locales/sk.d.ts +4 -0
- package/node_modules/zod/v4/locales/sk.js +116 -0
- package/node_modules/zod/v4/locales/sl.cjs +22 -24
- package/node_modules/zod/v4/locales/sl.d.cts +2 -1
- package/node_modules/zod/v4/locales/sl.js +21 -24
- package/node_modules/zod/v4/locales/sv.cjs +24 -26
- package/node_modules/zod/v4/locales/sv.d.cts +2 -1
- package/node_modules/zod/v4/locales/sv.js +23 -26
- package/node_modules/zod/v4/locales/ta.cjs +23 -24
- package/node_modules/zod/v4/locales/ta.d.cts +2 -1
- package/node_modules/zod/v4/locales/ta.js +22 -24
- package/node_modules/zod/v4/locales/tg.cjs +144 -0
- package/node_modules/zod/v4/locales/tg.d.cts +5 -0
- package/node_modules/zod/v4/locales/tg.d.ts +4 -0
- package/node_modules/zod/v4/locales/tg.js +117 -0
- package/node_modules/zod/v4/locales/th.cjs +23 -24
- package/node_modules/zod/v4/locales/th.d.cts +2 -1
- package/node_modules/zod/v4/locales/th.js +22 -24
- package/node_modules/zod/v4/locales/tk.cjs +134 -0
- package/node_modules/zod/v4/locales/tk.d.cts +5 -0
- package/node_modules/zod/v4/locales/tk.d.ts +4 -0
- package/node_modules/zod/v4/locales/tk.js +107 -0
- package/node_modules/zod/v4/locales/tr.cjs +20 -26
- package/node_modules/zod/v4/locales/tr.d.cts +2 -2
- package/node_modules/zod/v4/locales/tr.d.ts +0 -1
- package/node_modules/zod/v4/locales/tr.js +19 -24
- package/node_modules/zod/v4/locales/ua.cjs +6 -137
- package/node_modules/zod/v4/locales/ua.d.cts +2 -1
- package/node_modules/zod/v4/locales/ua.d.ts +1 -0
- package/node_modules/zod/v4/locales/ua.js +3 -115
- package/node_modules/zod/v4/locales/uk.cjs +140 -0
- package/node_modules/zod/v4/locales/uk.d.cts +5 -0
- package/node_modules/zod/v4/locales/uk.d.ts +4 -0
- package/node_modules/zod/v4/locales/uk.js +113 -0
- package/node_modules/zod/v4/locales/ur.cjs +23 -24
- package/node_modules/zod/v4/locales/ur.d.cts +2 -1
- package/node_modules/zod/v4/locales/ur.js +22 -24
- package/node_modules/zod/v4/locales/uz.cjs +140 -0
- package/node_modules/zod/v4/locales/uz.d.cts +5 -0
- package/node_modules/zod/v4/locales/uz.d.ts +4 -0
- package/node_modules/zod/v4/locales/uz.js +113 -0
- package/node_modules/zod/v4/locales/vi.cjs +22 -24
- package/node_modules/zod/v4/locales/vi.d.cts +2 -1
- package/node_modules/zod/v4/locales/vi.js +21 -24
- package/node_modules/zod/v4/locales/yo.cjs +139 -0
- package/node_modules/zod/v4/locales/yo.d.cts +5 -0
- package/node_modules/zod/v4/locales/yo.d.ts +4 -0
- package/node_modules/zod/v4/locales/yo.js +112 -0
- package/node_modules/zod/v4/locales/zh-CN.cjs +23 -24
- package/node_modules/zod/v4/locales/zh-CN.d.cts +2 -1
- package/node_modules/zod/v4/locales/zh-CN.js +22 -24
- package/node_modules/zod/v4/locales/zh-TW.cjs +20 -24
- package/node_modules/zod/v4/locales/zh-TW.d.cts +2 -1
- package/node_modules/zod/v4/locales/zh-TW.js +19 -24
- package/node_modules/zod/v4/mini/checks.cjs +21 -1
- package/node_modules/zod/v4/mini/checks.d.cts +1 -1
- package/node_modules/zod/v4/mini/checks.d.ts +1 -1
- package/node_modules/zod/v4/mini/checks.js +1 -1
- package/node_modules/zod/v4/mini/coerce.cjs +24 -0
- package/node_modules/zod/v4/mini/coerce.js +5 -0
- package/node_modules/zod/v4/mini/deep-partial.cjs +58 -0
- package/node_modules/zod/v4/mini/deep-partial.d.cts +14 -0
- package/node_modules/zod/v4/mini/deep-partial.d.ts +14 -0
- package/node_modules/zod/v4/mini/deep-partial.js +13 -0
- package/node_modules/zod/v4/mini/external.cjs +36 -3
- package/node_modules/zod/v4/mini/external.d.cts +7 -2
- package/node_modules/zod/v4/mini/external.d.ts +7 -2
- package/node_modules/zod/v4/mini/external.js +4 -1
- package/node_modules/zod/v4/mini/in-out.cjs +82 -0
- package/node_modules/zod/v4/mini/in-out.d.cts +8 -0
- package/node_modules/zod/v4/mini/in-out.d.ts +8 -0
- package/node_modules/zod/v4/mini/in-out.js +36 -0
- package/node_modules/zod/v4/mini/index.cjs +19 -0
- package/node_modules/zod/v4/mini/iso.cjs +27 -4
- package/node_modules/zod/v4/mini/iso.js +8 -4
- package/node_modules/zod/v4/mini/package.json +7 -0
- package/node_modules/zod/v4/mini/parse.cjs +30 -1
- package/node_modules/zod/v4/mini/parse.d.cts +1 -1
- package/node_modules/zod/v4/mini/parse.d.ts +1 -1
- package/node_modules/zod/v4/mini/parse.js +1 -1
- package/node_modules/zod/v4/mini/schemas.cjs +390 -82
- package/node_modules/zod/v4/mini/schemas.d.cts +156 -32
- package/node_modules/zod/v4/mini/schemas.d.ts +156 -32
- package/node_modules/zod/v4/mini/schemas.js +329 -59
- package/node_modules/zod/v4/package.json +7 -0
- package/node_modules/zod/v4-mini/index.cjs +35 -1
- package/node_modules/zod/v4-mini/index.d.cts +3 -1
- package/node_modules/zod/v4-mini/index.d.ts +3 -1
- package/node_modules/zod/v4-mini/index.js +3 -1
- package/node_modules/zod/v4-mini/package.json +7 -0
- package/package.json +3 -3
- package/dist/ui/assets/index-DNNXeRpZ.js +0 -123
- package/dist/ui/assets/index-Osk4E49r.css +0 -1
- package/node_modules/zod/src/v4/core/config.ts +0 -15
- package/node_modules/zod/src/v4/core/function.ts +0 -176
- package/node_modules/zod/v4/core/function.cjs +0 -102
- package/node_modules/zod/v4/core/function.d.cts +0 -52
- package/node_modules/zod/v4/core/function.d.ts +0 -52
- package/node_modules/zod/v4/core/function.js +0 -75
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type { $ZodTypeDiscriminable } from "./api.js";
|
|
2
1
|
import * as checks from "./checks.js";
|
|
2
|
+
import type { $ZodNumberFormats } from "./checks.js";
|
|
3
|
+
import type { $ZodBigIntFormats } from "./checks.js";
|
|
3
4
|
import * as core from "./core.js";
|
|
4
5
|
import { Doc } from "./doc.js";
|
|
5
6
|
import type * as errors from "./errors.js";
|
|
6
|
-
import
|
|
7
|
+
import type * as JSONSchema from "./json-schema.js";
|
|
8
|
+
import { parse, parseAsync } from "./parse.js";
|
|
7
9
|
import * as regexes from "./regexes.js";
|
|
8
10
|
import type { StandardSchemaV1 } from "./standard-schema.js";
|
|
11
|
+
import type { ProcessParams, ToJSONSchemaContext } from "./to-json-schema.js";
|
|
9
12
|
import * as util from "./util.js";
|
|
10
13
|
import { version } from "./versions.js";
|
|
11
14
|
|
|
@@ -25,11 +28,27 @@ export interface ParseContext<T extends errors.$ZodIssueBase = never> {
|
|
|
25
28
|
/** @internal */
|
|
26
29
|
export interface ParseContextInternal<T extends errors.$ZodIssueBase = never> extends ParseContext<T> {
|
|
27
30
|
readonly async?: boolean | undefined;
|
|
31
|
+
readonly direction?: "forward" | "backward";
|
|
32
|
+
readonly skipChecks?: boolean;
|
|
33
|
+
/** Set only by `validate`/`validateAsync`. A container may stop before its next child, never inside one, so a map entry and a tuple's fixed items parse whole. */
|
|
34
|
+
readonly abortEarly?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Gives a container cycle support: `attach` wraps its parse, and `alloc` registers the object it builds into before any child is parsed so a reference back to the same input resolves to it. */
|
|
38
|
+
export interface $ZodMemoizer {
|
|
39
|
+
attach(inst: $ZodType): void;
|
|
40
|
+
guard(inst: $ZodType): void;
|
|
41
|
+
alloc<T extends object>(inst: $ZodType, payload: ParsePayload, empty: T, ctx: ParseContextInternal): T;
|
|
28
42
|
}
|
|
29
43
|
|
|
30
44
|
export interface ParsePayload<T = unknown> {
|
|
31
45
|
value: T;
|
|
32
46
|
issues: errors.$ZodRawIssue[];
|
|
47
|
+
/** A way to mark a whole payload as aborted. Used in codecs/pipes. */
|
|
48
|
+
aborted?: boolean;
|
|
49
|
+
/** @internal Set when the value came from a repeat visit to a node still being
|
|
50
|
+
* parsed. Its checks run on the node itself, against the finished value. */
|
|
51
|
+
memo?: boolean | undefined;
|
|
33
52
|
}
|
|
34
53
|
|
|
35
54
|
export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>;
|
|
@@ -76,6 +95,7 @@ export interface $ZodTypeDef {
|
|
|
76
95
|
| "template_literal"
|
|
77
96
|
| "promise"
|
|
78
97
|
| "lazy"
|
|
98
|
+
| "function"
|
|
79
99
|
| "custom";
|
|
80
100
|
error?: errors.$ZodErrorMap<never> | undefined;
|
|
81
101
|
checks?: checks.$ZodCheck<never>[];
|
|
@@ -108,8 +128,13 @@ export interface _$ZodTypeInternals {
|
|
|
108
128
|
* @default Required
|
|
109
129
|
*/
|
|
110
130
|
|
|
111
|
-
/** @internal
|
|
112
|
-
|
|
131
|
+
/** @internal Three rungs, each strictly stronger than the last:
|
|
132
|
+
* undefined — required; the container may not omit this slot
|
|
133
|
+
* "optional" — the container may omit it; nothing is supplied in its place
|
|
134
|
+
* "defaulted" — the container may omit it AND this schema substitutes a value
|
|
135
|
+
* Consumers asking "may the slot be absent?" test `!== undefined`.
|
|
136
|
+
* $ZodOptional asks the stronger question and tests `=== "defaulted"`. */
|
|
137
|
+
optin?: "optional" | "defaulted" | undefined;
|
|
113
138
|
/** @internal */
|
|
114
139
|
optout?: "optional" | undefined;
|
|
115
140
|
|
|
@@ -121,6 +146,9 @@ export interface _$ZodTypeInternals {
|
|
|
121
146
|
*/
|
|
122
147
|
values?: util.PrimitiveSet | undefined;
|
|
123
148
|
|
|
149
|
+
/** Default value bubbled up from */
|
|
150
|
+
// default?: unknown | undefined;
|
|
151
|
+
|
|
124
152
|
/** @internal A set of literal discriminators used for the fast path in discriminated unions. */
|
|
125
153
|
propValues?: util.PropValues | undefined;
|
|
126
154
|
|
|
@@ -138,6 +166,11 @@ export interface _$ZodTypeInternals {
|
|
|
138
166
|
/** @internal The set of issues this schema might throw during type checking. */
|
|
139
167
|
isst: errors.$ZodIssueBase;
|
|
140
168
|
|
|
169
|
+
/** @internal Subject to change, not a public API. */
|
|
170
|
+
processJSONSchema?:
|
|
171
|
+
| ((ctx: ToJSONSchemaContext, json: JSONSchema.BaseSchema, params: ProcessParams) => void)
|
|
172
|
+
| undefined;
|
|
173
|
+
|
|
141
174
|
/** An optional method used to override `toJSONSchema` logic. */
|
|
142
175
|
toJSONSchema?: () => unknown;
|
|
143
176
|
|
|
@@ -165,107 +198,166 @@ export interface $ZodType<
|
|
|
165
198
|
"~standard": $ZodStandardSchema<this>;
|
|
166
199
|
}
|
|
167
200
|
export interface _$ZodType<T extends $ZodTypeInternals = $ZodTypeInternals>
|
|
168
|
-
extends $ZodType<T["output"], T["input"], T> {
|
|
169
|
-
// _zod: T;
|
|
170
|
-
}
|
|
201
|
+
extends $ZodType<T["output"], T["input"], T> {}
|
|
171
202
|
|
|
172
|
-
export const $ZodType: core.$constructor<$ZodType> = /*@__PURE__*/ core.$constructor
|
|
173
|
-
|
|
203
|
+
export const $ZodType: core.$constructor<$ZodType> = /*@__PURE__*/ core.$constructor<$ZodType>(
|
|
204
|
+
"$ZodType",
|
|
205
|
+
(inst, def) => {
|
|
206
|
+
inst ??= {} as any;
|
|
207
|
+
|
|
208
|
+
inst._zod.def = def; // set _def property
|
|
209
|
+
inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
|
|
210
|
+
inst._zod.version = version;
|
|
211
|
+
|
|
212
|
+
const defChecks = inst._zod.def.checks;
|
|
213
|
+
// if inst is itself a checks.$ZodCheck, run it as a check
|
|
214
|
+
const checks: checks.$ZodCheck<never>[] = inst._zod.traits.has("$ZodCheck")
|
|
215
|
+
? [inst as any, ...(defChecks ?? [])]
|
|
216
|
+
: defChecks?.length
|
|
217
|
+
? [...defChecks]
|
|
218
|
+
: [];
|
|
219
|
+
|
|
220
|
+
for (const ch of checks) {
|
|
221
|
+
for (const fn of ch._zod.onattach) {
|
|
222
|
+
fn(inst);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
174
225
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
226
|
+
if (checks.length === 0) {
|
|
227
|
+
// deferred initializer inst._zod.parse is not yet defined
|
|
228
|
+
inst._zod.deferred ??= [];
|
|
229
|
+
inst._zod.deferred?.push(() => {
|
|
230
|
+
inst._zod.run = inst._zod.parse;
|
|
231
|
+
});
|
|
232
|
+
} else {
|
|
233
|
+
const runChecks = (
|
|
234
|
+
payload: ParsePayload,
|
|
235
|
+
checks: checks.$ZodCheck<never>[],
|
|
236
|
+
ctx?: ParseContextInternal | undefined
|
|
237
|
+
): util.MaybeAsync<ParsePayload> => {
|
|
238
|
+
if (payload.memo) return payload;
|
|
239
|
+
|
|
240
|
+
let isAborted = util.aborted(payload);
|
|
241
|
+
|
|
242
|
+
let asyncResult!: Promise<unknown> | undefined;
|
|
243
|
+
for (const ch of checks) {
|
|
244
|
+
if (ch._zod.def.when) {
|
|
245
|
+
if (util.explicitlyAborted(payload)) continue;
|
|
246
|
+
const shouldRun = ch._zod.def.when(payload);
|
|
247
|
+
if (!shouldRun) continue;
|
|
248
|
+
} else if (isAborted) {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
const currLen = payload.issues.length;
|
|
252
|
+
const _ = ch._zod.check(payload as any) as any as ParsePayload;
|
|
178
253
|
|
|
179
|
-
|
|
254
|
+
if (_ instanceof Promise && ctx?.async === false) {
|
|
255
|
+
throw new core.$ZodAsyncError();
|
|
256
|
+
}
|
|
257
|
+
if (asyncResult || _ instanceof Promise) {
|
|
258
|
+
asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
|
|
259
|
+
await _;
|
|
260
|
+
const nextLen = payload.issues.length;
|
|
261
|
+
if (nextLen === currLen) return;
|
|
262
|
+
util.attachSchema(payload.issues, currLen, inst);
|
|
263
|
+
if (!isAborted) isAborted = util.aborted(payload, currLen);
|
|
264
|
+
});
|
|
265
|
+
} else {
|
|
266
|
+
const nextLen = payload.issues.length;
|
|
267
|
+
if (nextLen === currLen) continue;
|
|
268
|
+
util.attachSchema(payload.issues, currLen, inst);
|
|
269
|
+
if (!isAborted) isAborted = util.aborted(payload, currLen);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
180
272
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
273
|
+
if (asyncResult) {
|
|
274
|
+
return asyncResult.then(() => {
|
|
275
|
+
return payload;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return payload;
|
|
279
|
+
};
|
|
186
280
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
281
|
+
const handleCanaryResult = (canary: ParsePayload, payload: ParsePayload, ctx: ParseContextInternal) => {
|
|
282
|
+
// abort if the canary is aborted
|
|
283
|
+
if (util.aborted(canary)) {
|
|
284
|
+
canary.aborted = true;
|
|
285
|
+
return canary;
|
|
286
|
+
}
|
|
192
287
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
inst._zod.run = inst._zod.parse;
|
|
199
|
-
});
|
|
200
|
-
} else {
|
|
201
|
-
const runChecks = (
|
|
202
|
-
payload: ParsePayload,
|
|
203
|
-
checks: checks.$ZodCheck<never>[],
|
|
204
|
-
ctx?: ParseContextInternal | undefined
|
|
205
|
-
): util.MaybeAsync<ParsePayload> => {
|
|
206
|
-
let isAborted = util.aborted(payload);
|
|
207
|
-
|
|
208
|
-
let asyncResult!: Promise<unknown> | undefined;
|
|
209
|
-
for (const ch of checks) {
|
|
210
|
-
if (ch._zod.def.when) {
|
|
211
|
-
const shouldRun = ch._zod.def.when(payload);
|
|
212
|
-
if (!shouldRun) continue;
|
|
213
|
-
} else if (isAborted) {
|
|
214
|
-
continue;
|
|
288
|
+
// run checks first, then
|
|
289
|
+
const checkResult = runChecks(payload, checks, ctx);
|
|
290
|
+
if (checkResult instanceof Promise) {
|
|
291
|
+
if (ctx.async === false) throw new core.$ZodAsyncError();
|
|
292
|
+
return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
|
|
215
293
|
}
|
|
216
|
-
|
|
217
|
-
|
|
294
|
+
return inst._zod.parse(checkResult, ctx);
|
|
295
|
+
};
|
|
218
296
|
|
|
219
|
-
|
|
220
|
-
|
|
297
|
+
inst._zod.run = (payload, ctx) => {
|
|
298
|
+
if (ctx.skipChecks) {
|
|
299
|
+
return inst._zod.parse(payload, ctx);
|
|
221
300
|
}
|
|
222
|
-
if (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
301
|
+
if (ctx.direction === "backward") {
|
|
302
|
+
// run canary initial pass (no checks)
|
|
303
|
+
const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
|
|
304
|
+
|
|
305
|
+
if (canary instanceof Promise) {
|
|
306
|
+
return canary.then((canary) => {
|
|
307
|
+
return handleCanaryResult(canary, payload, ctx);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return handleCanaryResult(canary, payload, ctx);
|
|
233
312
|
}
|
|
234
|
-
}
|
|
235
313
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
};
|
|
314
|
+
// forward
|
|
315
|
+
const result = inst._zod.parse(payload, ctx);
|
|
316
|
+
if (result instanceof Promise) {
|
|
317
|
+
if (ctx.async === false) throw new core.$ZodAsyncError();
|
|
318
|
+
return result.then((result) => runChecks(result, checks, ctx));
|
|
319
|
+
}
|
|
243
320
|
|
|
244
|
-
|
|
245
|
-
|
|
321
|
+
return runChecks(result, checks, ctx);
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
// Wrappers extend this by installing a richer factory over it; reading it eagerly would defeat the laziness.
|
|
327
|
+
get "~standard"(): StandardSchemaV1.Props<any, any> {
|
|
328
|
+
return util.hide(this, "~standard", standardProps(this));
|
|
329
|
+
},
|
|
330
|
+
set "~standard"(value: StandardSchemaV1.Props<any, any>) {
|
|
331
|
+
util.own(this, "~standard", value);
|
|
332
|
+
},
|
|
333
|
+
}
|
|
334
|
+
);
|
|
246
335
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
336
|
+
/** The Standard Schema surface for `inst`. Shared so wrappers can extend it without forcing it. */
|
|
337
|
+
// a Standard Schema result only reports issues, so a failure finalizes them straight off the raw payload: no ZodError, and no lazy result to read through
|
|
338
|
+
const toStandardResult = (r: ParsePayload, ctx: ParseContextInternal) =>
|
|
339
|
+
r.issues.length ? { issues: r.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())) } : { value: r.value };
|
|
251
340
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
341
|
+
async function validateAsync(inst: $ZodType, value: unknown) {
|
|
342
|
+
const ctx: ParseContextInternal = { async: true };
|
|
343
|
+
return toStandardResult((await inst._zod.run({ value, issues: [] }, ctx)) as ParsePayload, ctx);
|
|
344
|
+
}
|
|
255
345
|
|
|
256
|
-
|
|
346
|
+
export function standardProps(inst: $ZodType): StandardSchemaV1.Props<any, any> {
|
|
347
|
+
return {
|
|
257
348
|
validate: (value: unknown) => {
|
|
349
|
+
const ctx: ParseContextInternal = { async: false };
|
|
258
350
|
try {
|
|
259
|
-
const r =
|
|
260
|
-
|
|
261
|
-
} catch (_) {
|
|
262
|
-
|
|
263
|
-
|
|
351
|
+
const r = inst._zod.run({ value, issues: [] }, ctx);
|
|
352
|
+
if (!(r instanceof Promise)) return toStandardResult(r, ctx);
|
|
353
|
+
} catch (_) {}
|
|
354
|
+
// async function so a synchronously throwing check rejects instead of escaping validate
|
|
355
|
+
return validateAsync(inst, value);
|
|
264
356
|
},
|
|
265
357
|
vendor: "zod",
|
|
266
358
|
version: 1 as const,
|
|
267
359
|
};
|
|
268
|
-
}
|
|
360
|
+
}
|
|
269
361
|
|
|
270
362
|
export { clone } from "./util.js";
|
|
271
363
|
|
|
@@ -295,6 +387,8 @@ export interface $ZodStringInternals<Input> extends $ZodTypeInternals<string, In
|
|
|
295
387
|
patterns: Set<RegExp>;
|
|
296
388
|
format: string;
|
|
297
389
|
contentEncoding: string;
|
|
390
|
+
/** the pattern admits strings its `format` keyword forbids, so `toJSONSchema` must not emit it */
|
|
391
|
+
laxFormat: boolean;
|
|
298
392
|
}>;
|
|
299
393
|
}
|
|
300
394
|
|
|
@@ -304,7 +398,8 @@ export interface $ZodString<Input = unknown> extends _$ZodType<$ZodStringInterna
|
|
|
304
398
|
|
|
305
399
|
export const $ZodString: core.$constructor<$ZodString> = /*@__PURE__*/ core.$constructor("$ZodString", (inst, def) => {
|
|
306
400
|
$ZodType.init(inst, def);
|
|
307
|
-
|
|
401
|
+
// a format's own pattern, else unbounded; a template literal derives the check-aware form itself
|
|
402
|
+
inst._zod.pattern = (def as $ZodStringFormatDef).pattern ?? regexes.anyString;
|
|
308
403
|
inst._zod.parse = (payload, _) => {
|
|
309
404
|
if (def.coerce)
|
|
310
405
|
try {
|
|
@@ -316,6 +411,7 @@ export const $ZodString: core.$constructor<$ZodString> = /*@__PURE__*/ core.$con
|
|
|
316
411
|
payload.issues.push({
|
|
317
412
|
expected: "string",
|
|
318
413
|
code: "invalid_type",
|
|
414
|
+
|
|
319
415
|
input: payload.value,
|
|
320
416
|
inst,
|
|
321
417
|
});
|
|
@@ -414,6 +510,7 @@ export const $ZodEmail: core.$constructor<$ZodEmail> = /*@__PURE__*/ core.$const
|
|
|
414
510
|
export interface $ZodURLDef extends $ZodStringFormatDef<"url"> {
|
|
415
511
|
hostname?: RegExp | undefined;
|
|
416
512
|
protocol?: RegExp | undefined;
|
|
513
|
+
normalize?: boolean | undefined;
|
|
417
514
|
}
|
|
418
515
|
export interface $ZodURLInternals extends $ZodStringFormatInternals<"url"> {
|
|
419
516
|
def: $ZodURLDef;
|
|
@@ -423,51 +520,133 @@ export interface $ZodURL extends $ZodType {
|
|
|
423
520
|
_zod: $ZodURLInternals;
|
|
424
521
|
}
|
|
425
522
|
|
|
523
|
+
/** The `://` guard rejected the input before the URL constructor saw it. */
|
|
524
|
+
export const URL_BAD_FORMAT = 1;
|
|
525
|
+
/** The URL parser rejected the input. */
|
|
526
|
+
export const URL_UNPARSEABLE = 2;
|
|
527
|
+
|
|
528
|
+
export function canParseURL(input: string): boolean {
|
|
529
|
+
try {
|
|
530
|
+
if (typeof URL !== "undefined" && typeof URL.canParse === "function") return URL.canParse(input);
|
|
531
|
+
new URL(input);
|
|
532
|
+
return true;
|
|
533
|
+
} catch {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export function validateURL(
|
|
539
|
+
trimmed: string,
|
|
540
|
+
def: Pick<$ZodURLDef, "protocol" | "hostname" | "normalize">
|
|
541
|
+
): URL | true | typeof URL_BAD_FORMAT | typeof URL_UNPARSEABLE {
|
|
542
|
+
if (!("normalize" in def) && !("hostname" in def) && !("protocol" in def)) {
|
|
543
|
+
return canParseURL(trimmed) || URL_UNPARSEABLE;
|
|
544
|
+
}
|
|
545
|
+
return parseURLObject(trimmed, def);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/** Parses a URL while preserving the non-normalizing HTTP guard. */
|
|
549
|
+
export function parseURLObject(
|
|
550
|
+
trimmed: string,
|
|
551
|
+
def: Pick<$ZodURLDef, "protocol" | "normalize">
|
|
552
|
+
): URL | typeof URL_BAD_FORMAT | typeof URL_UNPARSEABLE {
|
|
553
|
+
// When normalize is off, require :// for http/https URLs. This prevents strings like "http:example.com" or "https:/path" from being silently accepted
|
|
554
|
+
if (!def.normalize && def.protocol?.source === regexes.httpProtocol.source && !/^https?:\/\//i.test(trimmed)) {
|
|
555
|
+
return URL_BAD_FORMAT;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
try {
|
|
559
|
+
if (typeof URL !== "undefined") {
|
|
560
|
+
const URLStatic = URL as typeof URL & { parse?: (input: string) => URL | null };
|
|
561
|
+
if (typeof URLStatic.parse === "function") return URLStatic.parse(trimmed) ?? URL_UNPARSEABLE;
|
|
562
|
+
}
|
|
563
|
+
// @ts-ignore
|
|
564
|
+
return new URL(trimmed);
|
|
565
|
+
} catch {
|
|
566
|
+
return URL_UNPARSEABLE;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const asciiTabOrNewline = /[\t\n\r]/g;
|
|
571
|
+
|
|
572
|
+
/** The URL parser deletes every ASCII tab, LF and CR from its input before it parses, so `new URL("https://exa\nmple.com")` reports on `example.com`. Applying the same deletion to the returned value closes the half of that divergence which can move the host; the parser's other rewrite, stripping C0 controls at the edges, cannot. */
|
|
573
|
+
export function stripTabAndNewline(value: string): string {
|
|
574
|
+
return value.replace(asciiTabOrNewline, "");
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export function urlHostnameOk(url: URL, hostname: RegExp): boolean {
|
|
578
|
+
hostname.lastIndex = 0;
|
|
579
|
+
return hostname.test(url.hostname);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
export function urlProtocolOk(url: URL, protocol: RegExp): boolean {
|
|
583
|
+
protocol.lastIndex = 0;
|
|
584
|
+
return protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol);
|
|
585
|
+
}
|
|
586
|
+
|
|
426
587
|
export const $ZodURL: core.$constructor<$ZodURL> = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) => {
|
|
427
588
|
$ZodStringFormat.init(inst, def);
|
|
428
589
|
inst._zod.check = (payload) => {
|
|
429
590
|
try {
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
const
|
|
591
|
+
// Trim whitespace from input
|
|
592
|
+
const trimmed = payload.value.trim();
|
|
593
|
+
const url = validateURL(trimmed, def);
|
|
433
594
|
|
|
434
|
-
if (
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
continue: !def.abort,
|
|
445
|
-
});
|
|
446
|
-
}
|
|
595
|
+
if (url === URL_BAD_FORMAT) {
|
|
596
|
+
payload.issues.push({
|
|
597
|
+
code: "invalid_format",
|
|
598
|
+
format: "url",
|
|
599
|
+
note: "Invalid URL format",
|
|
600
|
+
input: payload.value,
|
|
601
|
+
inst,
|
|
602
|
+
continue: !def.abort,
|
|
603
|
+
});
|
|
604
|
+
return;
|
|
447
605
|
}
|
|
448
606
|
|
|
449
|
-
if (
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
inst,
|
|
459
|
-
continue: !def.abort,
|
|
460
|
-
});
|
|
461
|
-
}
|
|
607
|
+
if (url === URL_UNPARSEABLE) {
|
|
608
|
+
payload.issues.push({
|
|
609
|
+
code: "invalid_format",
|
|
610
|
+
format: "url",
|
|
611
|
+
input: payload.value,
|
|
612
|
+
inst,
|
|
613
|
+
continue: !def.abort,
|
|
614
|
+
});
|
|
615
|
+
return;
|
|
462
616
|
}
|
|
463
617
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
}
|
|
468
|
-
|
|
618
|
+
if (url === true) {
|
|
619
|
+
payload.value = stripTabAndNewline(trimmed);
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (def.hostname && !urlHostnameOk(url, def.hostname)) {
|
|
624
|
+
payload.issues.push({
|
|
625
|
+
code: "invalid_format",
|
|
626
|
+
format: "url",
|
|
627
|
+
note: "Invalid hostname",
|
|
628
|
+
pattern: def.hostname.source,
|
|
629
|
+
input: payload.value,
|
|
630
|
+
inst,
|
|
631
|
+
continue: !def.abort,
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
if (def.protocol && !urlProtocolOk(url, def.protocol)) {
|
|
636
|
+
payload.issues.push({
|
|
637
|
+
code: "invalid_format",
|
|
638
|
+
format: "url",
|
|
639
|
+
note: "Invalid protocol",
|
|
640
|
+
pattern: def.protocol.source,
|
|
641
|
+
input: payload.value,
|
|
642
|
+
inst,
|
|
643
|
+
continue: !def.abort,
|
|
644
|
+
});
|
|
469
645
|
}
|
|
470
646
|
|
|
647
|
+
// Set the output value based on normalize flag
|
|
648
|
+
payload.value = def.normalize ? url.href : stripTabAndNewline(trimmed);
|
|
649
|
+
|
|
471
650
|
return;
|
|
472
651
|
} catch (_) {
|
|
473
652
|
payload.issues.push({
|
|
@@ -500,8 +679,12 @@ export const $ZodEmoji: core.$constructor<$ZodEmoji> = /*@__PURE__*/ core.$const
|
|
|
500
679
|
|
|
501
680
|
////////////////////////////// ZodNanoID //////////////////////////////
|
|
502
681
|
|
|
503
|
-
export interface $ZodNanoIDDef extends $ZodStringFormatDef<"nanoid"> {
|
|
504
|
-
|
|
682
|
+
export interface $ZodNanoIDDef extends $ZodStringFormatDef<"nanoid"> {
|
|
683
|
+
length?: number | undefined;
|
|
684
|
+
}
|
|
685
|
+
export interface $ZodNanoIDInternals extends $ZodStringFormatInternals<"nanoid"> {
|
|
686
|
+
def: $ZodNanoIDDef;
|
|
687
|
+
}
|
|
505
688
|
|
|
506
689
|
export interface $ZodNanoID extends $ZodType {
|
|
507
690
|
_zod: $ZodNanoIDInternals;
|
|
@@ -510,20 +693,42 @@ export interface $ZodNanoID extends $ZodType {
|
|
|
510
693
|
export const $ZodNanoID: core.$constructor<$ZodNanoID> = /*@__PURE__*/ core.$constructor(
|
|
511
694
|
"$ZodNanoID",
|
|
512
695
|
(inst, def): void => {
|
|
513
|
-
def.
|
|
696
|
+
if (def.length !== undefined && (!Number.isInteger(def.length) || def.length < 1))
|
|
697
|
+
throw new Error(`Invalid nanoid length: ${def.length}`);
|
|
698
|
+
def.pattern ??= def.length === undefined ? regexes.nanoid : regexes.nanoidOfLength(def.length);
|
|
514
699
|
$ZodStringFormat.init(inst, def);
|
|
515
700
|
}
|
|
516
701
|
);
|
|
517
702
|
|
|
518
703
|
////////////////////////////// ZodCUID //////////////////////////////
|
|
519
704
|
|
|
705
|
+
/**
|
|
706
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
707
|
+
* (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
|
|
708
|
+
* See https://github.com/paralleldrive/cuid.
|
|
709
|
+
*/
|
|
520
710
|
export interface $ZodCUIDDef extends $ZodStringFormatDef<"cuid"> {}
|
|
711
|
+
/**
|
|
712
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
713
|
+
* (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
|
|
714
|
+
* See https://github.com/paralleldrive/cuid.
|
|
715
|
+
*/
|
|
521
716
|
export interface $ZodCUIDInternals extends $ZodStringFormatInternals<"cuid"> {}
|
|
522
717
|
|
|
718
|
+
/**
|
|
719
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
720
|
+
* (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
|
|
721
|
+
* See https://github.com/paralleldrive/cuid.
|
|
722
|
+
*/
|
|
523
723
|
export interface $ZodCUID extends $ZodType {
|
|
524
724
|
_zod: $ZodCUIDInternals;
|
|
525
725
|
}
|
|
526
726
|
|
|
727
|
+
/**
|
|
728
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
729
|
+
* (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
|
|
730
|
+
* See https://github.com/paralleldrive/cuid.
|
|
731
|
+
*/
|
|
527
732
|
export const $ZodCUID: core.$constructor<$ZodCUID> = /*@__PURE__*/ core.$constructor("$ZodCUID", (inst, def): void => {
|
|
528
733
|
def.pattern ??= regexes.cuid;
|
|
529
734
|
$ZodStringFormat.init(inst, def);
|
|
@@ -688,10 +893,6 @@ export interface $ZodIPv4 extends $ZodType {
|
|
|
688
893
|
export const $ZodIPv4: core.$constructor<$ZodIPv4> = /*@__PURE__*/ core.$constructor("$ZodIPv4", (inst, def): void => {
|
|
689
894
|
def.pattern ??= regexes.ipv4;
|
|
690
895
|
$ZodStringFormat.init(inst, def);
|
|
691
|
-
inst._zod.onattach.push((inst) => {
|
|
692
|
-
const bag = inst._zod.bag as $ZodStringInternals<unknown>["bag"];
|
|
693
|
-
bag.format = `ipv4`;
|
|
694
|
-
});
|
|
695
896
|
});
|
|
696
897
|
|
|
697
898
|
////////////////////////////// ZodIPv6 //////////////////////////////
|
|
@@ -708,20 +909,20 @@ export interface $ZodIPv6 extends $ZodType {
|
|
|
708
909
|
_zod: $ZodIPv6Internals;
|
|
709
910
|
}
|
|
710
911
|
|
|
912
|
+
/** An IPv6 address is written with hex digits, colons and dots, and nothing else. The guard is what makes the check below an IPv6 check: `new URL("http://[...]")` parses an authority, not an address, so `@` and `\` re-delimit it and `"::@1\\"` validates against the host `0.0.0.1`. The URL parser also deletes ASCII tab, LF and CR rather than failing, which is how `"::1\n"` validated as `::1`. */
|
|
913
|
+
const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
|
|
914
|
+
|
|
915
|
+
export function isValidIPv6(value: string): boolean {
|
|
916
|
+
if (!ipv6Alphabet.test(value)) return false;
|
|
917
|
+
return canParseURL(`http://[${value}]`);
|
|
918
|
+
}
|
|
919
|
+
|
|
711
920
|
export const $ZodIPv6: core.$constructor<$ZodIPv6> = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def): void => {
|
|
712
921
|
def.pattern ??= regexes.ipv6;
|
|
713
922
|
$ZodStringFormat.init(inst, def);
|
|
714
923
|
|
|
715
|
-
inst._zod.onattach.push((inst) => {
|
|
716
|
-
const bag = inst._zod.bag as $ZodStringInternals<unknown>["bag"];
|
|
717
|
-
bag.format = `ipv6`;
|
|
718
|
-
});
|
|
719
|
-
|
|
720
924
|
inst._zod.check = (payload) => {
|
|
721
|
-
|
|
722
|
-
new URL(`http://[${payload.value}]`);
|
|
723
|
-
// return;
|
|
724
|
-
} catch {
|
|
925
|
+
if (!isValidIPv6(payload.value)) {
|
|
725
926
|
payload.issues.push({
|
|
726
927
|
code: "invalid_format",
|
|
727
928
|
format: "ipv6",
|
|
@@ -733,6 +934,24 @@ export const $ZodIPv6: core.$constructor<$ZodIPv6> = /*@__PURE__*/ core.$constru
|
|
|
733
934
|
};
|
|
734
935
|
});
|
|
735
936
|
|
|
937
|
+
////////////////////////////// ZodMAC //////////////////////////////
|
|
938
|
+
export interface $ZodMACDef extends $ZodStringFormatDef<"mac"> {
|
|
939
|
+
delimiter?: string;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
export interface $ZodMACInternals extends $ZodStringFormatInternals<"mac"> {
|
|
943
|
+
def: $ZodMACDef;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
export interface $ZodMAC extends $ZodType {
|
|
947
|
+
_zod: $ZodMACInternals;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
export const $ZodMAC: core.$constructor<$ZodMAC> = /*@__PURE__*/ core.$constructor("$ZodMAC", (inst, def): void => {
|
|
951
|
+
def.pattern ??= regexes.mac(def.delimiter);
|
|
952
|
+
$ZodStringFormat.init(inst, def);
|
|
953
|
+
});
|
|
954
|
+
|
|
736
955
|
////////////////////////////// ZodCIDRv4 //////////////////////////////
|
|
737
956
|
|
|
738
957
|
export interface $ZodCIDRv4Def extends $ZodStringFormatDef<"cidrv4"> {
|
|
@@ -769,6 +988,17 @@ export interface $ZodCIDRv6 extends $ZodType {
|
|
|
769
988
|
_zod: $ZodCIDRv6Internals;
|
|
770
989
|
}
|
|
771
990
|
|
|
991
|
+
export function isValidCIDRv6(value: string): boolean {
|
|
992
|
+
const parts = value.split("/");
|
|
993
|
+
if (parts.length !== 2) return false;
|
|
994
|
+
const [address, prefix] = parts;
|
|
995
|
+
if (!prefix) return false;
|
|
996
|
+
const prefixNum = Number(prefix);
|
|
997
|
+
if (`${prefixNum}` !== prefix) return false;
|
|
998
|
+
if (prefixNum < 0 || prefixNum > 128) return false;
|
|
999
|
+
return isValidIPv6(address);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
772
1002
|
export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$constructor(
|
|
773
1003
|
"$ZodCIDRv6",
|
|
774
1004
|
(inst, def): void => {
|
|
@@ -776,14 +1006,7 @@ export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$con
|
|
|
776
1006
|
$ZodStringFormat.init(inst, def);
|
|
777
1007
|
|
|
778
1008
|
inst._zod.check = (payload) => {
|
|
779
|
-
|
|
780
|
-
try {
|
|
781
|
-
if (!prefix) throw new Error();
|
|
782
|
-
const prefixNum = Number(prefix);
|
|
783
|
-
if (`${prefixNum}` !== prefix) throw new Error();
|
|
784
|
-
if (prefixNum < 0 || prefixNum > 128) throw new Error();
|
|
785
|
-
new URL(`http://[${address}]`);
|
|
786
|
-
} catch {
|
|
1009
|
+
if (!isValidCIDRv6(payload.value)) {
|
|
787
1010
|
payload.issues.push({
|
|
788
1011
|
code: "invalid_format",
|
|
789
1012
|
format: "cidrv6",
|
|
@@ -799,8 +1022,11 @@ export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$con
|
|
|
799
1022
|
////////////////////////////// ZodBase64 //////////////////////////////
|
|
800
1023
|
export function isValidBase64(data: string): boolean {
|
|
801
1024
|
if (data === "") return true;
|
|
1025
|
+
// atob ignores whitespace, so reject it up front.
|
|
1026
|
+
if (/\s/.test(data)) return false;
|
|
802
1027
|
if (data.length % 4 !== 0) return false;
|
|
803
1028
|
try {
|
|
1029
|
+
// @ts-ignore
|
|
804
1030
|
atob(data);
|
|
805
1031
|
return true;
|
|
806
1032
|
} catch {
|
|
@@ -815,16 +1041,15 @@ export interface $ZodBase64 extends $ZodType {
|
|
|
815
1041
|
_zod: $ZodBase64Internals;
|
|
816
1042
|
}
|
|
817
1043
|
|
|
1044
|
+
// lax on purpose: the quantified regexes.base64 overflows the regex stack on multi-MB input and its leading ^$| alternation leaks through template-literal composition; isValidBase64 enforces length and padding
|
|
1045
|
+
export const base64Charset: RegExp = /^[0-9a-zA-Z+/]*={0,2}$/;
|
|
1046
|
+
|
|
818
1047
|
export const $ZodBase64: core.$constructor<$ZodBase64> = /*@__PURE__*/ core.$constructor(
|
|
819
1048
|
"$ZodBase64",
|
|
820
1049
|
(inst, def): void => {
|
|
821
|
-
def.pattern ??=
|
|
1050
|
+
def.pattern ??= base64Charset;
|
|
822
1051
|
$ZodStringFormat.init(inst, def);
|
|
823
1052
|
|
|
824
|
-
inst._zod.onattach.push((inst) => {
|
|
825
|
-
inst._zod.bag.contentEncoding = "base64";
|
|
826
|
-
});
|
|
827
|
-
|
|
828
1053
|
inst._zod.check = (payload) => {
|
|
829
1054
|
if (isValidBase64(payload.value)) return;
|
|
830
1055
|
|
|
@@ -839,9 +1064,12 @@ export const $ZodBase64: core.$constructor<$ZodBase64> = /*@__PURE__*/ core.$con
|
|
|
839
1064
|
}
|
|
840
1065
|
);
|
|
841
1066
|
|
|
842
|
-
//////////////////////////////
|
|
1067
|
+
////////////////////////////// ZodBase64URL //////////////////////////////
|
|
1068
|
+
// lax on purpose: the quantified regexes.base64url overflows the regex stack on multi-MB input; isValidBase64 enforces length on the padded string
|
|
1069
|
+
export const base64urlCharset: RegExp = /^[A-Za-z0-9_-]*$/;
|
|
1070
|
+
|
|
843
1071
|
export function isValidBase64URL(data: string): boolean {
|
|
844
|
-
if (!
|
|
1072
|
+
if (!base64urlCharset.test(data)) return false;
|
|
845
1073
|
const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
|
|
846
1074
|
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
|
|
847
1075
|
return isValidBase64(padded);
|
|
@@ -857,13 +1085,9 @@ export interface $ZodBase64URL extends $ZodType {
|
|
|
857
1085
|
export const $ZodBase64URL: core.$constructor<$ZodBase64URL> = /*@__PURE__*/ core.$constructor(
|
|
858
1086
|
"$ZodBase64URL",
|
|
859
1087
|
(inst, def): void => {
|
|
860
|
-
def.pattern ??=
|
|
1088
|
+
def.pattern ??= base64urlCharset;
|
|
861
1089
|
$ZodStringFormat.init(inst, def);
|
|
862
1090
|
|
|
863
|
-
inst._zod.onattach.push((inst) => {
|
|
864
|
-
inst._zod.bag.contentEncoding = "base64url";
|
|
865
|
-
});
|
|
866
|
-
|
|
867
1091
|
inst._zod.check = (payload) => {
|
|
868
1092
|
if (isValidBase64URL(payload.value)) return;
|
|
869
1093
|
|
|
@@ -892,6 +1116,103 @@ export const $ZodE164: core.$constructor<$ZodE164> = /*@__PURE__*/ core.$constru
|
|
|
892
1116
|
$ZodStringFormat.init(inst, def);
|
|
893
1117
|
});
|
|
894
1118
|
|
|
1119
|
+
////////////////////////////// ZodCreditCard //////////////////////////////
|
|
1120
|
+
|
|
1121
|
+
const CC_SANITIZE = /[- ]/g;
|
|
1122
|
+
|
|
1123
|
+
/** Luhn checksum on a digit-only string. Adapted from valibot (MIT). */
|
|
1124
|
+
function isLuhnAlgo(digits: string): boolean {
|
|
1125
|
+
let length = digits.length;
|
|
1126
|
+
let bit = 1;
|
|
1127
|
+
let sum = 0;
|
|
1128
|
+
while (length) {
|
|
1129
|
+
const value = digits.charCodeAt(--length) - 48;
|
|
1130
|
+
bit ^= 1;
|
|
1131
|
+
sum += bit ? [0, 2, 4, 6, 8, 1, 3, 5, 7, 9][value]! : value;
|
|
1132
|
+
}
|
|
1133
|
+
return sum % 10 === 0;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
export function isValidCreditCard(input: string): boolean {
|
|
1137
|
+
if (!regexes.creditCard.test(input)) return false;
|
|
1138
|
+
return isLuhnAlgo(input.replace(CC_SANITIZE, ""));
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
export interface $ZodCreditCardDef extends $ZodStringFormatDef<"credit_card"> {}
|
|
1142
|
+
export interface $ZodCreditCardInternals extends $ZodStringFormatInternals<"credit_card"> {
|
|
1143
|
+
def: $ZodCreditCardDef;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
export interface $ZodCreditCard extends $ZodType {
|
|
1147
|
+
_zod: $ZodCreditCardInternals;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
export const $ZodCreditCard: core.$constructor<$ZodCreditCard> = /*@__PURE__*/ core.$constructor(
|
|
1151
|
+
"$ZodCreditCard",
|
|
1152
|
+
(inst, def): void => {
|
|
1153
|
+
// Shape only — the Luhn check below is not expressible as a pattern, so consumers of `pattern` (JSON Schema, template literals) get the length and separator rules alone.
|
|
1154
|
+
def.pattern ??= regexes.creditCard;
|
|
1155
|
+
$ZodStringFormat.init(inst, def);
|
|
1156
|
+
inst._zod.check = (payload) => {
|
|
1157
|
+
if (isValidCreditCard(payload.value)) return;
|
|
1158
|
+
payload.issues.push({
|
|
1159
|
+
code: "invalid_format",
|
|
1160
|
+
format: "credit_card",
|
|
1161
|
+
input: payload.value,
|
|
1162
|
+
inst,
|
|
1163
|
+
continue: !def.abort,
|
|
1164
|
+
});
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
);
|
|
1168
|
+
|
|
1169
|
+
////////////////////////////// ZodIBAN //////////////////////////////
|
|
1170
|
+
|
|
1171
|
+
// iso 7064 mod 97-10 checksum without BigInt
|
|
1172
|
+
function isIso7064Mod97(iban: string): boolean {
|
|
1173
|
+
let remainder = 0;
|
|
1174
|
+
const len = iban.length;
|
|
1175
|
+
for (let i = 4; i < len; i++) {
|
|
1176
|
+
const code = iban.charCodeAt(i);
|
|
1177
|
+
remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
|
|
1178
|
+
}
|
|
1179
|
+
for (let i = 0; i < 4; i++) {
|
|
1180
|
+
const code = iban.charCodeAt(i);
|
|
1181
|
+
remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
|
|
1182
|
+
}
|
|
1183
|
+
return remainder === 1;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
export function isValidIBAN(input: string): boolean {
|
|
1187
|
+
if (!regexes.iban.test(input)) return false;
|
|
1188
|
+
return isIso7064Mod97(input);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
export interface $ZodIBANDef extends $ZodStringFormatDef<"iban"> {}
|
|
1192
|
+
export interface $ZodIBANInternals extends $ZodStringFormatInternals<"iban"> {
|
|
1193
|
+
def: $ZodIBANDef;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
export interface $ZodIBAN extends $ZodType {
|
|
1197
|
+
_zod: $ZodIBANInternals;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
export const $ZodIBAN: core.$constructor<$ZodIBAN> = /*@__PURE__*/ core.$constructor("$ZodIBAN", (inst, def): void => {
|
|
1201
|
+
// shape only — checksum is not expressible as a pattern
|
|
1202
|
+
def.pattern ??= regexes.iban;
|
|
1203
|
+
$ZodStringFormat.init(inst, def);
|
|
1204
|
+
inst._zod.check = (payload) => {
|
|
1205
|
+
if (isValidIBAN(payload.value)) return;
|
|
1206
|
+
payload.issues.push({
|
|
1207
|
+
code: "invalid_format",
|
|
1208
|
+
format: "iban",
|
|
1209
|
+
input: payload.value,
|
|
1210
|
+
inst,
|
|
1211
|
+
continue: !def.abort,
|
|
1212
|
+
});
|
|
1213
|
+
};
|
|
1214
|
+
});
|
|
1215
|
+
|
|
895
1216
|
////////////////////////////// ZodJWT //////////////////////////////
|
|
896
1217
|
|
|
897
1218
|
export function isValidJWT(token: string, algorithm: util.JWTAlgorithm | null = null): boolean {
|
|
@@ -900,6 +1221,7 @@ export function isValidJWT(token: string, algorithm: util.JWTAlgorithm | null =
|
|
|
900
1221
|
if (tokensParts.length !== 3) return false;
|
|
901
1222
|
const [header] = tokensParts;
|
|
902
1223
|
if (!header) return false;
|
|
1224
|
+
// @ts-ignore
|
|
903
1225
|
const parsedHeader = JSON.parse(atob(header));
|
|
904
1226
|
if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
|
|
905
1227
|
if (!parsedHeader.alg) return false;
|
|
@@ -1006,8 +1328,8 @@ export interface $ZodNumber<Input = unknown> extends $ZodType {
|
|
|
1006
1328
|
|
|
1007
1329
|
export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, def) => {
|
|
1008
1330
|
$ZodType.init(inst, def);
|
|
1009
|
-
inst._zod.pattern = inst._zod.bag.pattern ?? regexes.number;
|
|
1010
1331
|
|
|
1332
|
+
inst._zod.pattern = regexes.number;
|
|
1011
1333
|
inst._zod.parse = (payload, _ctx) => {
|
|
1012
1334
|
if (def.coerce)
|
|
1013
1335
|
try {
|
|
@@ -1023,13 +1345,14 @@ export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$con
|
|
|
1023
1345
|
? Number.isNaN(input)
|
|
1024
1346
|
? "NaN"
|
|
1025
1347
|
: !Number.isFinite(input)
|
|
1026
|
-
?
|
|
1348
|
+
? String(input)
|
|
1027
1349
|
: undefined
|
|
1028
1350
|
: undefined;
|
|
1029
1351
|
|
|
1030
1352
|
payload.issues.push({
|
|
1031
1353
|
expected: "number",
|
|
1032
1354
|
code: "invalid_type",
|
|
1355
|
+
|
|
1033
1356
|
input,
|
|
1034
1357
|
inst,
|
|
1035
1358
|
...(received ? { received } : {}),
|
|
@@ -1041,22 +1364,26 @@ export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$con
|
|
|
1041
1364
|
///////////////////////////////////////////////
|
|
1042
1365
|
////////// ZodNumberFormat //////////
|
|
1043
1366
|
///////////////////////////////////////////////
|
|
1044
|
-
export interface $ZodNumberFormatDef extends $
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1367
|
+
export interface $ZodNumberFormatDef<Format extends $ZodNumberFormats = $ZodNumberFormats>
|
|
1368
|
+
extends $ZodNumberDef,
|
|
1369
|
+
checks.$ZodCheckNumberFormatDef<Format> {}
|
|
1370
|
+
|
|
1371
|
+
export interface $ZodNumberFormatInternals<Format extends $ZodNumberFormats = $ZodNumberFormats>
|
|
1372
|
+
extends $ZodNumberInternals<number>,
|
|
1373
|
+
checks.$ZodCheckNumberFormatInternals<Format> {
|
|
1374
|
+
def: $ZodNumberFormatDef<Format>;
|
|
1048
1375
|
isst: errors.$ZodIssueInvalidType;
|
|
1049
1376
|
}
|
|
1050
1377
|
|
|
1051
|
-
export interface $ZodNumberFormat extends $ZodType {
|
|
1052
|
-
_zod: $ZodNumberFormatInternals
|
|
1378
|
+
export interface $ZodNumberFormat<Format extends $ZodNumberFormats = $ZodNumberFormats> extends $ZodType {
|
|
1379
|
+
_zod: $ZodNumberFormatInternals<Format>;
|
|
1053
1380
|
}
|
|
1054
1381
|
|
|
1055
1382
|
export const $ZodNumberFormat: core.$constructor<$ZodNumberFormat> = /*@__PURE__*/ core.$constructor(
|
|
1056
|
-
"$
|
|
1383
|
+
"$ZodNumberFormat",
|
|
1057
1384
|
(inst, def) => {
|
|
1058
1385
|
checks.$ZodCheckNumberFormat.init(inst, def);
|
|
1059
|
-
$ZodNumber.init(inst, def); // no format
|
|
1386
|
+
$ZodNumber.init(inst, def); // no format checks
|
|
1060
1387
|
}
|
|
1061
1388
|
);
|
|
1062
1389
|
|
|
@@ -1100,6 +1427,7 @@ export const $ZodBoolean: core.$constructor<$ZodBoolean> = /*@__PURE__*/ core.$c
|
|
|
1100
1427
|
payload.issues.push({
|
|
1101
1428
|
expected: "boolean",
|
|
1102
1429
|
code: "invalid_type",
|
|
1430
|
+
|
|
1103
1431
|
input,
|
|
1104
1432
|
inst,
|
|
1105
1433
|
});
|
|
@@ -1152,6 +1480,7 @@ export const $ZodBigInt: core.$constructor<$ZodBigInt> = /*@__PURE__*/ core.$con
|
|
|
1152
1480
|
payload.issues.push({
|
|
1153
1481
|
expected: "bigint",
|
|
1154
1482
|
code: "invalid_type",
|
|
1483
|
+
|
|
1155
1484
|
input: payload.value,
|
|
1156
1485
|
inst,
|
|
1157
1486
|
});
|
|
@@ -1162,20 +1491,24 @@ export const $ZodBigInt: core.$constructor<$ZodBigInt> = /*@__PURE__*/ core.$con
|
|
|
1162
1491
|
///////////////////////////////////////////////
|
|
1163
1492
|
////////// ZodBigIntFormat //////////
|
|
1164
1493
|
///////////////////////////////////////////////
|
|
1165
|
-
export interface $ZodBigIntFormatDef extends $
|
|
1494
|
+
export interface $ZodBigIntFormatDef<Format extends $ZodBigIntFormats = $ZodBigIntFormats>
|
|
1495
|
+
extends $ZodBigIntDef,
|
|
1496
|
+
checks.$ZodCheckBigIntFormatDef<Format> {
|
|
1166
1497
|
check: "bigint_format";
|
|
1167
1498
|
}
|
|
1168
1499
|
|
|
1169
|
-
export interface $ZodBigIntFormatInternals extends $
|
|
1170
|
-
|
|
1500
|
+
export interface $ZodBigIntFormatInternals<Format extends $ZodBigIntFormats = $ZodBigIntFormats>
|
|
1501
|
+
extends $ZodBigIntInternals<bigint>,
|
|
1502
|
+
checks.$ZodCheckBigIntFormatInternals<Format> {
|
|
1503
|
+
def: $ZodBigIntFormatDef<Format>;
|
|
1171
1504
|
}
|
|
1172
1505
|
|
|
1173
|
-
export interface $ZodBigIntFormat extends $ZodType {
|
|
1174
|
-
_zod: $ZodBigIntFormatInternals
|
|
1506
|
+
export interface $ZodBigIntFormat<Format extends $ZodBigIntFormats = $ZodBigIntFormats> extends $ZodType {
|
|
1507
|
+
_zod: $ZodBigIntFormatInternals<Format>;
|
|
1175
1508
|
}
|
|
1176
1509
|
|
|
1177
1510
|
export const $ZodBigIntFormat: core.$constructor<$ZodBigIntFormat> = /*@__PURE__*/ core.$constructor(
|
|
1178
|
-
"$
|
|
1511
|
+
"$ZodBigIntFormat",
|
|
1179
1512
|
(inst, def) => {
|
|
1180
1513
|
checks.$ZodCheckBigIntFormat.init(inst, def);
|
|
1181
1514
|
$ZodBigInt.init(inst, def); // no format checks
|
|
@@ -1211,6 +1544,7 @@ export const $ZodSymbol: core.$constructor<$ZodSymbol> = /*@__PURE__*/ core.$con
|
|
|
1211
1544
|
payload.issues.push({
|
|
1212
1545
|
expected: "symbol",
|
|
1213
1546
|
code: "invalid_type",
|
|
1547
|
+
|
|
1214
1548
|
input,
|
|
1215
1549
|
inst,
|
|
1216
1550
|
});
|
|
@@ -1246,8 +1580,6 @@ export const $ZodUndefined: core.$constructor<$ZodUndefined> = /*@__PURE__*/ cor
|
|
|
1246
1580
|
$ZodType.init(inst, def);
|
|
1247
1581
|
inst._zod.pattern = regexes.undefined;
|
|
1248
1582
|
inst._zod.values = new Set([undefined]);
|
|
1249
|
-
inst._zod.optin = "optional";
|
|
1250
|
-
inst._zod.optout = "optional";
|
|
1251
1583
|
|
|
1252
1584
|
inst._zod.parse = (payload, _ctx) => {
|
|
1253
1585
|
const input = payload.value;
|
|
@@ -1255,6 +1587,7 @@ export const $ZodUndefined: core.$constructor<$ZodUndefined> = /*@__PURE__*/ cor
|
|
|
1255
1587
|
payload.issues.push({
|
|
1256
1588
|
expected: "undefined",
|
|
1257
1589
|
code: "invalid_type",
|
|
1590
|
+
|
|
1258
1591
|
input,
|
|
1259
1592
|
inst,
|
|
1260
1593
|
});
|
|
@@ -1297,6 +1630,7 @@ export const $ZodNull: core.$constructor<$ZodNull> = /*@__PURE__*/ core.$constru
|
|
|
1297
1630
|
payload.issues.push({
|
|
1298
1631
|
expected: "null",
|
|
1299
1632
|
code: "invalid_type",
|
|
1633
|
+
|
|
1300
1634
|
input,
|
|
1301
1635
|
inst,
|
|
1302
1636
|
});
|
|
@@ -1388,6 +1722,7 @@ export const $ZodNever: core.$constructor<$ZodNever> = /*@__PURE__*/ core.$const
|
|
|
1388
1722
|
payload.issues.push({
|
|
1389
1723
|
expected: "never",
|
|
1390
1724
|
code: "invalid_type",
|
|
1725
|
+
|
|
1391
1726
|
input: payload.value,
|
|
1392
1727
|
inst,
|
|
1393
1728
|
});
|
|
@@ -1425,6 +1760,7 @@ export const $ZodVoid: core.$constructor<$ZodVoid> = /*@__PURE__*/ core.$constru
|
|
|
1425
1760
|
payload.issues.push({
|
|
1426
1761
|
expected: "void",
|
|
1427
1762
|
code: "invalid_type",
|
|
1763
|
+
|
|
1428
1764
|
input,
|
|
1429
1765
|
inst,
|
|
1430
1766
|
});
|
|
@@ -1475,6 +1811,7 @@ export const $ZodDate: core.$constructor<$ZodDate> = /*@__PURE__*/ core.$constru
|
|
|
1475
1811
|
payload.issues.push({
|
|
1476
1812
|
expected: "date",
|
|
1477
1813
|
code: "invalid_type",
|
|
1814
|
+
|
|
1478
1815
|
input,
|
|
1479
1816
|
...(isDate ? { received: "Invalid Date" } : {}),
|
|
1480
1817
|
inst,
|
|
@@ -1507,6 +1844,34 @@ export interface $ZodArrayInternals<T extends SomeType = $ZodType> extends _$Zod
|
|
|
1507
1844
|
|
|
1508
1845
|
export interface $ZodArray<T extends SomeType = $ZodType> extends $ZodType<any, any, $ZodArrayInternals<T>> {}
|
|
1509
1846
|
|
|
1847
|
+
// an oversized container fails its leading size checks before any element is parsed
|
|
1848
|
+
function capSize(inst: $ZodType, size: (input: any) => number): void {
|
|
1849
|
+
const caps = util.sizeCaps(inst._zod.def.checks);
|
|
1850
|
+
if (!caps.length) return;
|
|
1851
|
+
const cap = Math.min(...caps.map((c) => c[0]));
|
|
1852
|
+
const parse = inst._zod.parse;
|
|
1853
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1854
|
+
const n = size(payload.value);
|
|
1855
|
+
if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
|
|
1856
|
+
for (const [max, ch] of util.sizeCaps(inst._zod.def.checks)) {
|
|
1857
|
+
if (n > max && ch._zod.def.when!(payload)) {
|
|
1858
|
+
const start = payload.issues.length;
|
|
1859
|
+
ch._zod.check(payload as ParsePayload<never>);
|
|
1860
|
+
// the value is still the raw input, so no later check may read it
|
|
1861
|
+
(payload.issues[start] as { continue?: boolean }).continue = false;
|
|
1862
|
+
util.attachSchema(payload.issues, start, inst);
|
|
1863
|
+
return payload;
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
return parse(payload, ctx);
|
|
1868
|
+
};
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1871
|
+
const arraySize = (input: unknown): number => (Array.isArray(input) ? input.length : -1);
|
|
1872
|
+
const mapSize = (input: unknown): number => (input instanceof Map ? input.size : -1);
|
|
1873
|
+
const setSize = (input: unknown): number => (input instanceof Set ? input.size : -1);
|
|
1874
|
+
|
|
1510
1875
|
function handleArrayResult(result: ParsePayload<any>, final: ParsePayload<any[]>, index: number) {
|
|
1511
1876
|
if (result.issues.length) {
|
|
1512
1877
|
final.issues.push(...util.prefixIssues(index, result.issues));
|
|
@@ -1517,6 +1882,9 @@ function handleArrayResult(result: ParsePayload<any>, final: ParsePayload<any[]>
|
|
|
1517
1882
|
export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def) => {
|
|
1518
1883
|
$ZodType.init(inst, def);
|
|
1519
1884
|
|
|
1885
|
+
const memo = core.globalConfig.memoizer;
|
|
1886
|
+
memo?.attach(inst);
|
|
1887
|
+
|
|
1520
1888
|
inst._zod.parse = (payload, ctx) => {
|
|
1521
1889
|
const input = payload.value;
|
|
1522
1890
|
|
|
@@ -1524,14 +1892,16 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
|
|
|
1524
1892
|
payload.issues.push({
|
|
1525
1893
|
expected: "array",
|
|
1526
1894
|
code: "invalid_type",
|
|
1895
|
+
|
|
1527
1896
|
input,
|
|
1528
1897
|
inst,
|
|
1529
1898
|
});
|
|
1530
1899
|
return payload;
|
|
1531
1900
|
}
|
|
1532
1901
|
|
|
1533
|
-
payload.value = Array(input.length);
|
|
1902
|
+
payload.value = memo ? memo.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
|
|
1534
1903
|
const proms: Promise<any>[] = [];
|
|
1904
|
+
const abortEarly = ctx?.abortEarly;
|
|
1535
1905
|
for (let i = 0; i < input.length; i++) {
|
|
1536
1906
|
const item = input[i];
|
|
1537
1907
|
const result = def.element._zod.run(
|
|
@@ -1546,6 +1916,8 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
|
|
|
1546
1916
|
proms.push(result.then((result) => handleArrayResult(result, payload, i)));
|
|
1547
1917
|
} else {
|
|
1548
1918
|
handleArrayResult(result, payload, i);
|
|
1919
|
+
// the element's payload is authoritative here, since handleArrayResult forwards every issue; an object's is not, because it drops a failed absent optional
|
|
1920
|
+
if (abortEarly && result.issues.length !== 0 && util.aborted(result)) break;
|
|
1549
1921
|
}
|
|
1550
1922
|
}
|
|
1551
1923
|
|
|
@@ -1555,6 +1927,7 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
|
|
|
1555
1927
|
|
|
1556
1928
|
return payload; //handleArrayResultsAsync(parseResults, final);
|
|
1557
1929
|
};
|
|
1930
|
+
capSize(inst, arraySize);
|
|
1558
1931
|
});
|
|
1559
1932
|
|
|
1560
1933
|
//////////////////////////////////////////
|
|
@@ -1566,12 +1939,12 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
|
|
|
1566
1939
|
//////////////////////////////////////////
|
|
1567
1940
|
|
|
1568
1941
|
type OptionalOutSchema = { _zod: { optout: "optional" } };
|
|
1569
|
-
type OptionalInSchema = { _zod: { optin: "optional" } };
|
|
1942
|
+
type OptionalInSchema = { _zod: { optin: "optional" | "defaulted" } };
|
|
1570
1943
|
|
|
1571
1944
|
export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T
|
|
1572
1945
|
? util.IsAny<T[keyof T]> extends true
|
|
1573
1946
|
? Record<string, unknown>
|
|
1574
|
-
:
|
|
1947
|
+
: { [k in string]: core.output<T[keyof T]> }
|
|
1575
1948
|
: keyof (T & Extra) extends never
|
|
1576
1949
|
? Record<string, never>
|
|
1577
1950
|
: util.Prettify<
|
|
@@ -1582,10 +1955,40 @@ export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<st
|
|
|
1582
1955
|
} & Extra
|
|
1583
1956
|
>;
|
|
1584
1957
|
|
|
1958
|
+
// experimental
|
|
1959
|
+
// export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = keyof (T &
|
|
1960
|
+
// Extra) extends never
|
|
1961
|
+
// ? Record<string, never>
|
|
1962
|
+
// : string extends keyof T
|
|
1963
|
+
// ? util.Prettify<
|
|
1964
|
+
// {
|
|
1965
|
+
// [k: string]: util.IsAny<T[string]["_zod"]["output"]> extends true ? unknown : T[string]["_zod"]["output"];
|
|
1966
|
+
// } & $InferObjectOutputNoIndex<util.OmitIndexSignature<T>, Extra>
|
|
1967
|
+
// >
|
|
1968
|
+
// : util.Prettify<$InferObjectOutputNoIndex<T, Extra>>;
|
|
1969
|
+
|
|
1970
|
+
// export type $InferObjectOutputNoIndex<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = {
|
|
1971
|
+
// [k in keyof T as string extends k
|
|
1972
|
+
// ? never
|
|
1973
|
+
// : k extends string
|
|
1974
|
+
// ? T[k] extends OptionalOutSchema
|
|
1975
|
+
// ? never
|
|
1976
|
+
// : k
|
|
1977
|
+
// : never]: T[k]["_zod"]["output"];
|
|
1978
|
+
// } & {
|
|
1979
|
+
// [k in keyof T as string extends k
|
|
1980
|
+
// ? never
|
|
1981
|
+
// : k extends string
|
|
1982
|
+
// ? T[k] extends OptionalOutSchema
|
|
1983
|
+
// ? k
|
|
1984
|
+
// : never
|
|
1985
|
+
// : never]?: T[k]["_zod"]["output"];
|
|
1986
|
+
// } & Extra;
|
|
1987
|
+
|
|
1585
1988
|
export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T
|
|
1586
1989
|
? util.IsAny<T[keyof T]> extends true
|
|
1587
1990
|
? Record<string, unknown>
|
|
1588
|
-
:
|
|
1991
|
+
: { [k in string]: core.input<T[keyof T]> }
|
|
1589
1992
|
: keyof (T & Extra) extends never
|
|
1590
1993
|
? Record<string, never>
|
|
1591
1994
|
: util.Prettify<
|
|
@@ -1596,33 +1999,45 @@ export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<str
|
|
|
1596
1999
|
} & Extra
|
|
1597
2000
|
>;
|
|
1598
2001
|
|
|
1599
|
-
function
|
|
1600
|
-
|
|
2002
|
+
function handlePropertyResult(
|
|
2003
|
+
result: ParsePayload,
|
|
2004
|
+
final: ParsePayload,
|
|
2005
|
+
key: PropertyKey,
|
|
2006
|
+
input: any,
|
|
2007
|
+
optin: "optional" | "defaulted" | undefined,
|
|
2008
|
+
optout: "optional" | undefined
|
|
2009
|
+
) {
|
|
2010
|
+
const isPresent = key in input;
|
|
2011
|
+
const isOptionalOut = optout === "optional";
|
|
2012
|
+
// The middle rung means "absence permitted, nothing supplied in its place", so an absent key contributes nothing — whatever the schema made of `undefined` is invented, not substituted. Only `optional` reaches this with a value: `defaulted` substitutes, and a schema that isn't optional-out has to keep the key.
|
|
2013
|
+
if (!isPresent && isOptionalOut && optin === "optional") {
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
1601
2016
|
if (result.issues.length) {
|
|
2017
|
+
// For optional-in/out schemas, ignore errors on absent keys.
|
|
2018
|
+
if (optin !== undefined && isOptionalOut && !isPresent) {
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
1602
2021
|
final.issues.push(...util.prefixIssues(key, result.issues));
|
|
1603
2022
|
}
|
|
1604
2023
|
|
|
1605
|
-
(
|
|
1606
|
-
|
|
2024
|
+
if (!isPresent && optin === undefined) {
|
|
2025
|
+
if (!result.issues.length) {
|
|
2026
|
+
final.issues.push({
|
|
2027
|
+
code: "invalid_type",
|
|
2028
|
+
expected: "nonoptional",
|
|
2029
|
+
input: undefined,
|
|
2030
|
+
path: [key],
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
return;
|
|
2034
|
+
}
|
|
1607
2035
|
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
if (input[key] === undefined) {
|
|
1612
|
-
// if input was undefined, ignore the error
|
|
1613
|
-
if (key in input) {
|
|
1614
|
-
(final.value as any)[key] = undefined;
|
|
1615
|
-
} else {
|
|
1616
|
-
(final.value as any)[key] = result.value;
|
|
1617
|
-
}
|
|
1618
|
-
} else {
|
|
1619
|
-
final.issues.push(...util.prefixIssues(key, result.issues));
|
|
2036
|
+
if (result.value === undefined) {
|
|
2037
|
+
if (isPresent || (optin === "defaulted" && !isOptionalOut)) {
|
|
2038
|
+
(final.value as any)[key] = undefined;
|
|
1620
2039
|
}
|
|
1621
|
-
} else if (result.value === undefined) {
|
|
1622
|
-
// validation returned `undefined`
|
|
1623
|
-
if (key in input) (final.value as any)[key] = undefined;
|
|
1624
2040
|
} else {
|
|
1625
|
-
// non-undefined value
|
|
1626
2041
|
(final.value as any)[key] = result.value;
|
|
1627
2042
|
}
|
|
1628
2043
|
}
|
|
@@ -1657,7 +2072,7 @@ export interface $ZodObjectDef<Shape extends $ZodShape = $ZodShape> extends $Zod
|
|
|
1657
2072
|
|
|
1658
2073
|
export interface $ZodObjectInternals<
|
|
1659
2074
|
/** @ts-ignore Cast variance */
|
|
1660
|
-
out Shape extends
|
|
2075
|
+
out Shape extends $ZodShape = $ZodShape,
|
|
1661
2076
|
out Config extends $ZodObjectConfig = $ZodObjectConfig,
|
|
1662
2077
|
> extends _$ZodTypeInternals {
|
|
1663
2078
|
def: $ZodObjectDef<Shape>;
|
|
@@ -1666,6 +2081,8 @@ export interface $ZodObjectInternals<
|
|
|
1666
2081
|
propValues: util.PropValues;
|
|
1667
2082
|
output: $InferObjectOutput<Shape, Config["out"]>;
|
|
1668
2083
|
input: $InferObjectInput<Shape, Config["in"]>;
|
|
2084
|
+
optin?: "optional" | undefined;
|
|
2085
|
+
optout?: "optional" | undefined;
|
|
1669
2086
|
}
|
|
1670
2087
|
export type $ZodLooseShape = Record<string, any>;
|
|
1671
2088
|
|
|
@@ -1673,118 +2090,137 @@ export interface $ZodObject<
|
|
|
1673
2090
|
/** @ts-ignore Cast variance */
|
|
1674
2091
|
out Shape extends Readonly<$ZodShape> = Readonly<$ZodShape>,
|
|
1675
2092
|
out Params extends $ZodObjectConfig = $ZodObjectConfig,
|
|
1676
|
-
> extends $ZodType<any, any, $ZodObjectInternals<Shape, Params>> {
|
|
1677
|
-
|
|
2093
|
+
> extends $ZodType<any, any, $ZodObjectInternals<Shape, Params>> {}
|
|
2094
|
+
|
|
2095
|
+
// one shared instance; a fresh [] per schema cost 56 bytes retained
|
|
2096
|
+
const NO_SYMBOL_KEYS: symbol[] = [];
|
|
2097
|
+
|
|
2098
|
+
function normalizeDef(def: $ZodObjectDef) {
|
|
2099
|
+
const keys = Object.keys(def.shape);
|
|
2100
|
+
const ownSymbols = Object.getOwnPropertySymbols(def.shape);
|
|
2101
|
+
const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
|
|
2102
|
+
// aliases `keys` when there are no symbols, so a string-only shape keeps one array
|
|
2103
|
+
const allKeys: (string | symbol)[] = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
|
|
2104
|
+
for (const k of allKeys) {
|
|
2105
|
+
if (!(def.shape as any)?.[k]?._zod?.traits?.has("$ZodType")) {
|
|
2106
|
+
throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
const okeys = util.optionalKeys(def.shape);
|
|
2110
|
+
|
|
2111
|
+
return {
|
|
2112
|
+
...def,
|
|
2113
|
+
allKeys,
|
|
2114
|
+
symbolKeys,
|
|
2115
|
+
// string-only: handleCatchall matches it against `for...in`, which never yields a symbol
|
|
2116
|
+
keySet: new Set(keys),
|
|
2117
|
+
numKeys: keys.length,
|
|
2118
|
+
optionalKeys: new Set(okeys),
|
|
2119
|
+
};
|
|
1678
2120
|
}
|
|
1679
2121
|
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
2122
|
+
function handleCatchall(
|
|
2123
|
+
proms: Promise<any>[],
|
|
2124
|
+
input: any,
|
|
2125
|
+
payload: ParsePayload,
|
|
2126
|
+
ctx: ParseContextInternal,
|
|
2127
|
+
def: ReturnType<typeof normalizeDef>,
|
|
2128
|
+
inst: $ZodObject,
|
|
2129
|
+
abortEarly: boolean
|
|
2130
|
+
) {
|
|
2131
|
+
const unrecognized: string[] = [];
|
|
2132
|
+
const keySet = def.keySet;
|
|
2133
|
+
const _catchall = def.catchall!._zod;
|
|
2134
|
+
const t = _catchall.def.type;
|
|
2135
|
+
const optin = _catchall.optin;
|
|
2136
|
+
const optout = _catchall.optout;
|
|
2137
|
+
// starts at 0, not the current length: the shape phase already ran and may have aborted
|
|
2138
|
+
let seen = 0;
|
|
2139
|
+
for (const key in input) {
|
|
2140
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
2141
|
+
if (util.aborted(payload, seen)) break;
|
|
2142
|
+
seen = payload.issues.length;
|
|
2143
|
+
}
|
|
2144
|
+
// Must precede the __proto__ branch: a declared key is not unrecognized, even though the shape loop deliberately strips __proto__ from the parsed output.
|
|
2145
|
+
if (keySet.has(key)) continue;
|
|
2146
|
+
// Don't copy an undeclared __proto__ into the result; assignment to a plain {} would replace the result prototype. But in strict mode it is still an unknown key, so report it before skipping.
|
|
2147
|
+
if (key === "__proto__") {
|
|
2148
|
+
if (t === "never") unrecognized.push(key);
|
|
2149
|
+
continue;
|
|
2150
|
+
}
|
|
2151
|
+
if (t === "never") {
|
|
2152
|
+
unrecognized.push(key);
|
|
2153
|
+
continue;
|
|
1690
2154
|
}
|
|
1691
|
-
const
|
|
2155
|
+
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
|
1692
2156
|
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
};
|
|
1700
|
-
});
|
|
2157
|
+
if (r instanceof Promise) {
|
|
2158
|
+
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
|
|
2159
|
+
} else {
|
|
2160
|
+
handlePropertyResult(r, payload, key, input, optin, optout);
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
1701
2163
|
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
return propValues;
|
|
1713
|
-
});
|
|
2164
|
+
if (unrecognized.length) {
|
|
2165
|
+
payload.issues.push({
|
|
2166
|
+
code: "unrecognized_keys",
|
|
2167
|
+
keys: unrecognized,
|
|
2168
|
+
input,
|
|
2169
|
+
inst,
|
|
2170
|
+
// Describes the shape of the input, not the validity of the parsed value, so it never aborts. The parse still fails; the schema's own checks just get to run first, and an enclosing intersection can reconcile the key against a sibling operand.
|
|
2171
|
+
continue: true,
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
1714
2174
|
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
2175
|
+
if (!proms.length) return payload;
|
|
2176
|
+
return Promise.all(proms).then(() => {
|
|
2177
|
+
return payload;
|
|
2178
|
+
});
|
|
2179
|
+
}
|
|
1718
2180
|
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
2181
|
+
export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
|
|
2182
|
+
// requires cast because technically $ZodObject doesn't extend
|
|
2183
|
+
$ZodType.init(inst, def);
|
|
2184
|
+
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
|
2185
|
+
// a cloned def carries its source's accessor, which knows the shape it answers from; adopting that keeps the clone's keys readable without running it
|
|
2186
|
+
const sh = desc?.get ? (desc.get as util.ShapeGetter).raw : (def.shape ?? {});
|
|
2187
|
+
if (sh) {
|
|
2188
|
+
// Freezes the shape on first read, so its getters resolve once and every later read sees the same schemas.
|
|
2189
|
+
const get: util.ShapeGetter = () => {
|
|
2190
|
+
const newSh = { ...sh };
|
|
2191
|
+
Object.defineProperty(def, "shape", { value: newSh });
|
|
2192
|
+
get.raw = newSh;
|
|
2193
|
+
return newSh;
|
|
1722
2194
|
};
|
|
2195
|
+
get.raw = sh;
|
|
2196
|
+
Object.defineProperty(def, "shape", { get });
|
|
2197
|
+
}
|
|
1723
2198
|
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
const ids: any = Object.create(null);
|
|
1727
|
-
let counter = 0;
|
|
1728
|
-
for (const key of normalized.keys) {
|
|
1729
|
-
ids[key] = `key_${counter++}`;
|
|
1730
|
-
}
|
|
2199
|
+
const _normalized = util.cached(() => normalizeDef(def));
|
|
1731
2200
|
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
if (${id}.issues.length) {
|
|
1741
|
-
if (input[${k}] === undefined) {
|
|
1742
|
-
if (${k} in input) {
|
|
1743
|
-
newResult[${k}] = undefined;
|
|
1744
|
-
}
|
|
1745
|
-
} else {
|
|
1746
|
-
payload.issues = payload.issues.concat(
|
|
1747
|
-
${id}.issues.map((iss) => ({
|
|
1748
|
-
...iss,
|
|
1749
|
-
path: iss.path ? [${k}, ...iss.path] : [${k}],
|
|
1750
|
-
}))
|
|
1751
|
-
);
|
|
1752
|
-
}
|
|
1753
|
-
} else if (${id}.value === undefined) {
|
|
1754
|
-
if (${k} in input) newResult[${k}] = undefined;
|
|
1755
|
-
} else {
|
|
1756
|
-
newResult[${k}] = ${id}.value;
|
|
2201
|
+
util.defineLazyInternal(inst, "propValues", (zod) => {
|
|
2202
|
+
const shape = zod.def.shape;
|
|
2203
|
+
const propValues: util.PropValues = {};
|
|
2204
|
+
for (const key in shape) {
|
|
2205
|
+
const field = shape[key]!._zod;
|
|
2206
|
+
if (field.values) {
|
|
2207
|
+
if (!Object.prototype.hasOwnProperty.call(propValues, key)) {
|
|
2208
|
+
util.assignProp(propValues, key, new Set());
|
|
1757
2209
|
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
// const id = ids[key];
|
|
1762
|
-
doc.write(`const ${id} = ${parseStr(key)};`);
|
|
1763
|
-
doc.write(`
|
|
1764
|
-
if (${id}.issues.length) payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
1765
|
-
...iss,
|
|
1766
|
-
path: iss.path ? [${util.esc(key)}, ...iss.path] : [${util.esc(key)}]
|
|
1767
|
-
})));`);
|
|
1768
|
-
doc.write(`newResult[${util.esc(key)}] = ${id}.value`);
|
|
2210
|
+
for (const v of field.values) propValues[key].add(v);
|
|
2211
|
+
// An omittable slot reads back as undefined at a discriminator lookup, so it has to claim undefined: two options that can both omit the key are not discriminable on it.
|
|
2212
|
+
if (field.optin !== undefined) propValues[key].add(undefined);
|
|
1769
2213
|
}
|
|
1770
2214
|
}
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
doc.write(`return payload;`);
|
|
1774
|
-
const fn = doc.compile();
|
|
1775
|
-
return (payload: any, ctx: any) => fn(shape, payload, ctx);
|
|
1776
|
-
};
|
|
1777
|
-
|
|
1778
|
-
let fastpass!: ReturnType<typeof generateFastpass>;
|
|
2215
|
+
return propValues;
|
|
2216
|
+
});
|
|
1779
2217
|
|
|
1780
2218
|
const isObject = util.isObject;
|
|
1781
|
-
const jit = !core.globalConfig.jitless;
|
|
1782
|
-
const allowsEval = util.allowsEval;
|
|
1783
|
-
|
|
1784
|
-
const fastEnabled = jit && allowsEval.value; // && !def.catchall;
|
|
1785
2219
|
const catchall = def.catchall;
|
|
1786
2220
|
|
|
1787
2221
|
let value!: typeof _normalized.value;
|
|
2222
|
+
const memo = core.globalConfig.memoizer;
|
|
2223
|
+
memo?.attach(inst);
|
|
1788
2224
|
|
|
1789
2225
|
inst._zod.parse = (payload, ctx) => {
|
|
1790
2226
|
value ??= _normalized.value;
|
|
@@ -1799,88 +2235,192 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
|
|
|
1799
2235
|
return payload;
|
|
1800
2236
|
}
|
|
1801
2237
|
|
|
2238
|
+
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
|
|
2239
|
+
|
|
1802
2240
|
const proms: Promise<any>[] = [];
|
|
2241
|
+
const shape = value.shape;
|
|
2242
|
+
const abortEarly = ctx?.abortEarly;
|
|
2243
|
+
let seen = payload.issues.length;
|
|
2244
|
+
|
|
2245
|
+
for (const key of value.allKeys) {
|
|
2246
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
2247
|
+
if (util.aborted(payload, seen)) break;
|
|
2248
|
+
seen = payload.issues.length;
|
|
2249
|
+
}
|
|
2250
|
+
if (key === "__proto__") continue;
|
|
2251
|
+
const el = (shape as any)[key]!;
|
|
2252
|
+
const optin = el._zod.optin;
|
|
2253
|
+
const optout = el._zod.optout;
|
|
1803
2254
|
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
payload.value = {};
|
|
1810
|
-
|
|
1811
|
-
const shape = value.shape;
|
|
1812
|
-
for (const key of value.keys) {
|
|
1813
|
-
const el = shape[key]!;
|
|
1814
|
-
|
|
1815
|
-
// do not add omitted optional keys
|
|
1816
|
-
// if (!(key in input)) {
|
|
1817
|
-
// if (optionalKeys.has(key)) continue;
|
|
1818
|
-
// payload.issues.push({
|
|
1819
|
-
// code: "invalid_type",
|
|
1820
|
-
// path: [key],
|
|
1821
|
-
// expected: "nonoptional",
|
|
1822
|
-
// note: `Missing required key: "${key}"`,
|
|
1823
|
-
// input,
|
|
1824
|
-
// inst,
|
|
1825
|
-
// });
|
|
1826
|
-
// }
|
|
1827
|
-
|
|
1828
|
-
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
|
|
1829
|
-
const isOptional = el._zod.optin === "optional" && el._zod.optout === "optional";
|
|
1830
|
-
|
|
1831
|
-
if (r instanceof Promise) {
|
|
1832
|
-
proms.push(
|
|
1833
|
-
r.then((r) =>
|
|
1834
|
-
isOptional ? handleOptionalObjectResult(r, payload, key, input) : handleObjectResult(r, payload, key)
|
|
1835
|
-
)
|
|
1836
|
-
);
|
|
1837
|
-
} else if (isOptional) {
|
|
1838
|
-
handleOptionalObjectResult(r, payload, key, input);
|
|
1839
|
-
} else {
|
|
1840
|
-
handleObjectResult(r, payload, key);
|
|
1841
|
-
}
|
|
2255
|
+
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
|
|
2256
|
+
if (r instanceof Promise) {
|
|
2257
|
+
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
|
|
2258
|
+
} else {
|
|
2259
|
+
handlePropertyResult(r, payload, key, input, optin, optout);
|
|
1842
2260
|
}
|
|
1843
2261
|
}
|
|
1844
2262
|
|
|
1845
2263
|
if (!catchall) {
|
|
1846
|
-
// return payload;
|
|
1847
2264
|
return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
1848
2265
|
}
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
2266
|
+
|
|
2267
|
+
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst, abortEarly === true);
|
|
2268
|
+
};
|
|
2269
|
+
});
|
|
2270
|
+
|
|
2271
|
+
export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$constructor(
|
|
2272
|
+
"$ZodObjectJIT",
|
|
2273
|
+
(inst, def) => {
|
|
2274
|
+
// requires cast because technically $ZodObject doesn't extend
|
|
2275
|
+
$ZodObject.init(inst, def);
|
|
2276
|
+
|
|
2277
|
+
const superParse = inst._zod.parse;
|
|
2278
|
+
const _normalized = util.cached(() => normalizeDef(def));
|
|
2279
|
+
|
|
2280
|
+
const memo = core.globalConfig.memoizer;
|
|
2281
|
+
|
|
2282
|
+
const generateFastpass = (shape: any) => {
|
|
2283
|
+
const normalized = _normalized.value;
|
|
2284
|
+
const syms = normalized.symbolKeys;
|
|
2285
|
+
// a symbol has no source literal, so it is read as `syms[i]` off the closed-over scope
|
|
2286
|
+
const doc = new Doc(["payload", "ctx"], { shape, inst, memo, syms });
|
|
2287
|
+
|
|
2288
|
+
const parseStr = (k: string) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
|
|
2289
|
+
|
|
2290
|
+
// prefixes in place, like util.prefixIssues. newResult must land before the early return: a catchall runs after this and would otherwise write onto the caller's input
|
|
2291
|
+
const prefixStr = (id: string, k: string) => `
|
|
2292
|
+
let ${id}_ab = false;
|
|
2293
|
+
for (let i = 0; i < ${id}.issues.length; i++) {
|
|
2294
|
+
const iss = ${id}.issues[i];
|
|
2295
|
+
iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
|
|
2296
|
+
payload.issues.push(iss);
|
|
2297
|
+
if (iss.continue !== true) ${id}_ab = true;
|
|
2298
|
+
}
|
|
2299
|
+
if (${id}_ab && ctx && ctx.abortEarly) {
|
|
2300
|
+
payload.value = newResult;
|
|
2301
|
+
return payload;
|
|
2302
|
+
}`;
|
|
2303
|
+
|
|
2304
|
+
doc.write(`const input = payload.value;`);
|
|
2305
|
+
|
|
2306
|
+
const ids: any = Object.create(null);
|
|
2307
|
+
let counter = 0;
|
|
2308
|
+
for (const key of normalized.allKeys) {
|
|
2309
|
+
ids[key] = `key_${counter++}`;
|
|
1859
2310
|
}
|
|
1860
|
-
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
|
1861
2311
|
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
2312
|
+
// A: preserve key order {
|
|
2313
|
+
doc.write(memo ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
|
|
2314
|
+
for (const key of normalized.allKeys) {
|
|
2315
|
+
if (key === "__proto__") continue;
|
|
2316
|
+
const id = ids[key];
|
|
2317
|
+
const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : util.esc(key);
|
|
2318
|
+
const isPresent = `${k} in input`;
|
|
2319
|
+
const schema = shape[key];
|
|
2320
|
+
const optin = schema?._zod?.optin;
|
|
2321
|
+
const isOptionalIn = optin !== undefined;
|
|
2322
|
+
const isOptionalOut = schema?._zod?.optout === "optional";
|
|
2323
|
+
|
|
2324
|
+
doc.write(`const ${id} = ${parseStr(k)};`);
|
|
2325
|
+
|
|
2326
|
+
if (isOptionalIn && isOptionalOut) {
|
|
2327
|
+
// For optional-in/out schemas, ignore errors on absent keys — and, like the interpreted path, drop the value produced alongside them. The middle rung goes further: it permits absence without supplying anything in its place, so an absent key contributes nothing at all.
|
|
2328
|
+
const assign = optin === "optional" ? `${id}_present` : `${id}.value !== undefined || ${id}_present`;
|
|
2329
|
+
doc.write(`
|
|
2330
|
+
const ${id}_present = ${isPresent};
|
|
2331
|
+
if (!${id}.issues.length || ${id}_present) {
|
|
2332
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
if (${assign}) {
|
|
2336
|
+
newResult[${k}] = ${id}.value;
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2340
|
+
`);
|
|
2341
|
+
} else if (!isOptionalIn) {
|
|
2342
|
+
doc.write(`
|
|
2343
|
+
const ${id}_present = ${isPresent};
|
|
2344
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
2345
|
+
}
|
|
2346
|
+
if (!${id}_present && !${id}.issues.length) {
|
|
2347
|
+
payload.issues.push({
|
|
2348
|
+
code: "invalid_type",
|
|
2349
|
+
expected: "nonoptional",
|
|
2350
|
+
input: undefined,
|
|
2351
|
+
path: [${k}]
|
|
2352
|
+
});
|
|
2353
|
+
if (ctx && ctx.abortEarly) {
|
|
2354
|
+
payload.value = newResult;
|
|
2355
|
+
return payload;
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
if (${id}_present) {
|
|
2360
|
+
newResult[${k}] = ${id}.value;
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
`);
|
|
2364
|
+
} else {
|
|
2365
|
+
doc.write(`
|
|
2366
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
2367
|
+
}
|
|
2368
|
+
`);
|
|
2369
|
+
if (optin === "defaulted") {
|
|
2370
|
+
doc.write(`newResult[${k}] = ${id}.value;`);
|
|
2371
|
+
} else {
|
|
2372
|
+
doc.write(`
|
|
2373
|
+
if (${id}.value !== undefined || ${isPresent}) {
|
|
2374
|
+
newResult[${k}] = ${id}.value;
|
|
2375
|
+
}
|
|
2376
|
+
`);
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
1866
2379
|
}
|
|
1867
|
-
}
|
|
1868
2380
|
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
inst,
|
|
1875
|
-
});
|
|
1876
|
-
}
|
|
2381
|
+
doc.write(`payload.value = newResult;`);
|
|
2382
|
+
doc.write(`return payload;`);
|
|
2383
|
+
// closing `shape` in is what pays: turbofan specializes the parser against that one shape object, so every `shape[k]._zod.run` folds to a known callee. as a parameter it stays a generic load and measures 13% slower even with the forwarding frame gone
|
|
2384
|
+
return doc.compile() as (payload: any, ctx: any) => any;
|
|
2385
|
+
};
|
|
1877
2386
|
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
2387
|
+
let fastpass!: ReturnType<typeof generateFastpass>;
|
|
2388
|
+
|
|
2389
|
+
const isObject = util.isObject;
|
|
2390
|
+
const jit = !core.globalConfig.jitless;
|
|
2391
|
+
const allowsEval = util.allowsEval;
|
|
2392
|
+
|
|
2393
|
+
const fastEnabled = jit && allowsEval.value; // && !def.catchall;
|
|
2394
|
+
const catchall = def.catchall;
|
|
2395
|
+
|
|
2396
|
+
let value!: typeof _normalized.value;
|
|
2397
|
+
|
|
2398
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2399
|
+
value ??= _normalized.value;
|
|
2400
|
+
const input = payload.value;
|
|
2401
|
+
if (!isObject(input)) {
|
|
2402
|
+
payload.issues.push({
|
|
2403
|
+
expected: "object",
|
|
2404
|
+
code: "invalid_type",
|
|
2405
|
+
input,
|
|
2406
|
+
inst,
|
|
2407
|
+
});
|
|
2408
|
+
return payload;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
|
|
2412
|
+
// always synchronous
|
|
2413
|
+
if (!fastpass) fastpass = generateFastpass(def.shape);
|
|
2414
|
+
payload = fastpass(payload, ctx);
|
|
2415
|
+
|
|
2416
|
+
if (!catchall) return payload;
|
|
2417
|
+
return handleCatchall([], input, payload, ctx, value, inst, ctx?.abortEarly === true);
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
return superParse(payload, ctx);
|
|
2421
|
+
};
|
|
2422
|
+
}
|
|
2423
|
+
);
|
|
1884
2424
|
|
|
1885
2425
|
/////////////////////////////////////////
|
|
1886
2426
|
/////////////////////////////////////////
|
|
@@ -1895,6 +2435,7 @@ export type $InferUnionInput<T extends SomeType> = T extends any ? core.input<T>
|
|
|
1895
2435
|
export interface $ZodUnionDef<Options extends readonly SomeType[] = readonly $ZodType[]> extends $ZodTypeDef {
|
|
1896
2436
|
type: "union";
|
|
1897
2437
|
options: Options;
|
|
2438
|
+
inclusive?: boolean;
|
|
1898
2439
|
}
|
|
1899
2440
|
|
|
1900
2441
|
type IsOptionalIn<T extends SomeType> = T extends OptionalInSchema ? true : false;
|
|
@@ -1908,7 +2449,7 @@ export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $Zo
|
|
|
1908
2449
|
output: $InferUnionOutput<T[number]>;
|
|
1909
2450
|
input: $InferUnionInput<T[number]>;
|
|
1910
2451
|
// if any element in the union is optional, then the union is optional
|
|
1911
|
-
optin: IsOptionalIn<T[number]> extends false ? "optional" | undefined : "optional";
|
|
2452
|
+
optin: IsOptionalIn<T[number]> extends false ? "optional" | "defaulted" | undefined : "optional" | "defaulted";
|
|
1912
2453
|
optout: IsOptionalOut<T[number]> extends false ? "optional" | undefined : "optional";
|
|
1913
2454
|
}
|
|
1914
2455
|
|
|
@@ -1925,8 +2466,15 @@ function handleUnionResults(results: ParsePayload[], final: ParsePayload, inst:
|
|
|
1925
2466
|
}
|
|
1926
2467
|
}
|
|
1927
2468
|
|
|
2469
|
+
const nonaborted = results.filter((r) => !util.aborted(r));
|
|
2470
|
+
if (nonaborted.length === 1) {
|
|
2471
|
+
final.value = nonaborted[0].value;
|
|
2472
|
+
return nonaborted[0];
|
|
2473
|
+
}
|
|
2474
|
+
|
|
1928
2475
|
final.issues.push({
|
|
1929
2476
|
code: "invalid_union",
|
|
2477
|
+
|
|
1930
2478
|
input: final.value,
|
|
1931
2479
|
inst,
|
|
1932
2480
|
errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
|
|
@@ -1938,30 +2486,39 @@ function handleUnionResults(results: ParsePayload[], final: ParsePayload, inst:
|
|
|
1938
2486
|
export const $ZodUnion: core.$constructor<$ZodUnion> = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def) => {
|
|
1939
2487
|
$ZodType.init(inst, def);
|
|
1940
2488
|
|
|
1941
|
-
util.
|
|
1942
|
-
def.options.some((o) => o._zod.optin === "
|
|
2489
|
+
util.defineLazyInternal(inst, "optin", (zod) =>
|
|
2490
|
+
zod.def.options.some((o) => o._zod.optin === "defaulted")
|
|
2491
|
+
? "defaulted"
|
|
2492
|
+
: zod.def.options.some((o) => o._zod.optin !== undefined)
|
|
2493
|
+
? "optional"
|
|
2494
|
+
: undefined
|
|
1943
2495
|
);
|
|
1944
2496
|
|
|
1945
|
-
util.
|
|
1946
|
-
def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined
|
|
2497
|
+
util.defineLazyInternal(inst, "optout", (zod) =>
|
|
2498
|
+
zod.def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined
|
|
1947
2499
|
);
|
|
1948
2500
|
|
|
1949
|
-
util.
|
|
1950
|
-
if (def.options.every((o) => o._zod.values)) {
|
|
1951
|
-
return new Set<util.Primitive>(def.options.flatMap((option) => Array.from(option._zod.values!)));
|
|
2501
|
+
util.defineLazyInternal(inst, "values", (zod) => {
|
|
2502
|
+
if (zod.def.options.every((o) => o._zod.values)) {
|
|
2503
|
+
return new Set<util.Primitive>(zod.def.options.flatMap((option) => Array.from(option._zod.values!)));
|
|
1952
2504
|
}
|
|
1953
2505
|
return undefined;
|
|
1954
2506
|
});
|
|
1955
2507
|
|
|
1956
|
-
util.
|
|
1957
|
-
if (def.options.every((o) => o._zod.pattern)) {
|
|
1958
|
-
const patterns = def.options.map((o) => o._zod.pattern);
|
|
2508
|
+
util.defineLazyInternal(inst, "pattern", (zod) => {
|
|
2509
|
+
if (zod.def.options.every((o) => o._zod.pattern)) {
|
|
2510
|
+
const patterns = zod.def.options.map((o) => o._zod.pattern);
|
|
1959
2511
|
return new RegExp(`^(${patterns.map((p) => util.cleanRegex(p!.source)).join("|")})$`);
|
|
1960
2512
|
}
|
|
1961
2513
|
return undefined;
|
|
1962
2514
|
});
|
|
1963
2515
|
|
|
2516
|
+
const first = def.options.length === 1 ? def.options[0]._zod.run : null;
|
|
2517
|
+
|
|
1964
2518
|
inst._zod.parse = (payload, ctx) => {
|
|
2519
|
+
if (first) {
|
|
2520
|
+
return first(payload, ctx);
|
|
2521
|
+
}
|
|
1965
2522
|
let async = false;
|
|
1966
2523
|
|
|
1967
2524
|
const results: util.MaybeAsync<ParsePayload>[] = [];
|
|
@@ -1989,6 +2546,88 @@ export const $ZodUnion: core.$constructor<$ZodUnion> = /*@__PURE__*/ core.$const
|
|
|
1989
2546
|
};
|
|
1990
2547
|
});
|
|
1991
2548
|
|
|
2549
|
+
function handleExclusiveUnionResults(
|
|
2550
|
+
results: ParsePayload[],
|
|
2551
|
+
final: ParsePayload,
|
|
2552
|
+
inst: $ZodUnion,
|
|
2553
|
+
ctx?: ParseContext
|
|
2554
|
+
) {
|
|
2555
|
+
const matches: number[] = [];
|
|
2556
|
+
for (let i = 0; i < results.length; i++) {
|
|
2557
|
+
if (results[i].issues.length === 0) matches.push(i);
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2560
|
+
if (matches.length === 1) {
|
|
2561
|
+
final.value = results[matches[0]].value;
|
|
2562
|
+
return final;
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
if (matches.length === 0) {
|
|
2566
|
+
// No matches - same as regular union
|
|
2567
|
+
final.issues.push({
|
|
2568
|
+
code: "invalid_union",
|
|
2569
|
+
input: final.value,
|
|
2570
|
+
inst,
|
|
2571
|
+
errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
|
|
2572
|
+
});
|
|
2573
|
+
} else {
|
|
2574
|
+
// Multiple matches - exclusive union failure
|
|
2575
|
+
final.issues.push({
|
|
2576
|
+
code: "invalid_union",
|
|
2577
|
+
input: final.value,
|
|
2578
|
+
inst,
|
|
2579
|
+
errors: [],
|
|
2580
|
+
inclusive: false,
|
|
2581
|
+
matches,
|
|
2582
|
+
});
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
return final;
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
export interface $ZodXorInternals<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodUnionInternals<T> {}
|
|
2589
|
+
|
|
2590
|
+
export interface $ZodXor<T extends readonly SomeType[] = readonly $ZodType[]>
|
|
2591
|
+
extends $ZodType<any, any, $ZodXorInternals<T>> {
|
|
2592
|
+
_zod: $ZodXorInternals<T>;
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2595
|
+
export const $ZodXor: core.$constructor<$ZodXor> = /*@__PURE__*/ core.$constructor("$ZodXor", (inst, def) => {
|
|
2596
|
+
$ZodUnion.init(inst, def);
|
|
2597
|
+
def.inclusive = false;
|
|
2598
|
+
|
|
2599
|
+
const first = def.options.length === 1 ? def.options[0]._zod.run : null;
|
|
2600
|
+
|
|
2601
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2602
|
+
if (first) {
|
|
2603
|
+
return first(payload, ctx);
|
|
2604
|
+
}
|
|
2605
|
+
let async = false;
|
|
2606
|
+
|
|
2607
|
+
const results: util.MaybeAsync<ParsePayload>[] = [];
|
|
2608
|
+
for (const option of def.options) {
|
|
2609
|
+
const result = option._zod.run(
|
|
2610
|
+
{
|
|
2611
|
+
value: payload.value,
|
|
2612
|
+
issues: [],
|
|
2613
|
+
},
|
|
2614
|
+
ctx
|
|
2615
|
+
);
|
|
2616
|
+
if (result instanceof Promise) {
|
|
2617
|
+
results.push(result);
|
|
2618
|
+
async = true;
|
|
2619
|
+
} else {
|
|
2620
|
+
results.push(result);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
if (!async) return handleExclusiveUnionResults(results as ParsePayload[], payload, inst, ctx);
|
|
2625
|
+
return Promise.all(results).then((results) => {
|
|
2626
|
+
return handleExclusiveUnionResults(results as ParsePayload[], payload, inst, ctx);
|
|
2627
|
+
});
|
|
2628
|
+
};
|
|
2629
|
+
});
|
|
2630
|
+
|
|
1992
2631
|
//////////////////////////////////////////////////////
|
|
1993
2632
|
//////////////////////////////////////////////////////
|
|
1994
2633
|
////////// //////////
|
|
@@ -1997,66 +2636,133 @@ export const $ZodUnion: core.$constructor<$ZodUnion> = /*@__PURE__*/ core.$const
|
|
|
1997
2636
|
//////////////////////////////////////////////////////
|
|
1998
2637
|
//////////////////////////////////////////////////////
|
|
1999
2638
|
|
|
2000
|
-
export interface $ZodDiscriminatedUnionDef<
|
|
2001
|
-
extends $
|
|
2002
|
-
|
|
2639
|
+
export interface $ZodDiscriminatedUnionDef<
|
|
2640
|
+
Options extends readonly SomeType[] = readonly $ZodType[],
|
|
2641
|
+
Disc extends string = string,
|
|
2642
|
+
> extends $ZodUnionDef<Options> {
|
|
2643
|
+
discriminator: Disc;
|
|
2003
2644
|
unionFallback?: boolean;
|
|
2004
2645
|
}
|
|
2005
2646
|
|
|
2006
|
-
export interface $ZodDiscriminatedUnionInternals<
|
|
2007
|
-
extends $
|
|
2008
|
-
|
|
2647
|
+
export interface $ZodDiscriminatedUnionInternals<
|
|
2648
|
+
Options extends readonly SomeType[] = readonly $ZodType[],
|
|
2649
|
+
Disc extends string = string,
|
|
2650
|
+
> extends $ZodUnionInternals<Options> {
|
|
2651
|
+
def: $ZodDiscriminatedUnionDef<Options, Disc>;
|
|
2009
2652
|
propValues: util.PropValues;
|
|
2653
|
+
bag: util.LoosePartial<{
|
|
2654
|
+
optionsMap: Map<util.Primitive, $ZodType | null>;
|
|
2655
|
+
}>;
|
|
2010
2656
|
}
|
|
2011
2657
|
|
|
2012
|
-
|
|
2013
|
-
|
|
2658
|
+
/** The discriminator values a member of `Options` can declare. An omittable discriminator contributes `undefined`, matching what `propValues` claims for it. */
|
|
2659
|
+
export type $DiscriminatorValue<Options extends readonly SomeType[], Disc extends string> = {
|
|
2660
|
+
[I in keyof Options]: Options[I] extends { _zod: { output: infer Out } }
|
|
2661
|
+
? Disc extends keyof Out
|
|
2662
|
+
? Out[Disc]
|
|
2663
|
+
: never
|
|
2664
|
+
: never;
|
|
2665
|
+
}[number];
|
|
2666
|
+
|
|
2667
|
+
/** The member of `Options` that declares `V`. */
|
|
2668
|
+
export type $DiscriminatedOption<Options extends readonly SomeType[], Disc extends string, V> = {
|
|
2669
|
+
[I in keyof Options]: Options[I] extends { _zod: { output: infer Out } }
|
|
2670
|
+
? Disc extends keyof Out
|
|
2671
|
+
? V extends Out[Disc]
|
|
2672
|
+
? Options[I]
|
|
2673
|
+
: never
|
|
2674
|
+
: never
|
|
2675
|
+
: never;
|
|
2676
|
+
}[number];
|
|
2677
|
+
|
|
2678
|
+
/** Returns the option whose discriminator claims `value`, or throws if ambiguous. */
|
|
2679
|
+
export function getDiscriminatedOption<
|
|
2680
|
+
Options extends readonly SomeType[],
|
|
2681
|
+
Disc extends string,
|
|
2682
|
+
const V extends $DiscriminatorValue<Options, Disc>,
|
|
2683
|
+
>(union: $ZodDiscriminatedUnion<Options, Disc>, value: V): $DiscriminatedOption<Options, Disc, V> {
|
|
2684
|
+
const internals = union._zod;
|
|
2685
|
+
let map = internals.bag.optionsMap;
|
|
2686
|
+
if (!map) {
|
|
2687
|
+
map = discriminatorMap(internals.def);
|
|
2688
|
+
internals.bag.optionsMap = map;
|
|
2689
|
+
}
|
|
2690
|
+
const option = map.get(value as util.Primitive);
|
|
2691
|
+
if (option === null) throw new Error(`Ambiguous discriminator value "${String(value)}"`);
|
|
2692
|
+
return option as any;
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
function discriminatorMap(def: $ZodDiscriminatedUnionDef<readonly SomeType[]>): Map<util.Primitive, $ZodType | null> {
|
|
2696
|
+
const map = new Map<util.Primitive, $ZodType | null>();
|
|
2697
|
+
for (const option of def.options as readonly $ZodType[]) {
|
|
2698
|
+
const values = option._zod.propValues?.[def.discriminator];
|
|
2699
|
+
if (!values || values.size === 0)
|
|
2700
|
+
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
2701
|
+
for (const value of values) {
|
|
2702
|
+
if (map.has(value)) {
|
|
2703
|
+
if (value !== undefined) throw new Error(`Duplicate discriminator value "${String(value)}"`);
|
|
2704
|
+
// keep the collision marked so a later member cannot reclaim it
|
|
2705
|
+
map.set(value, null);
|
|
2706
|
+
} else {
|
|
2707
|
+
map.set(value, option);
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
return map;
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2714
|
+
export interface $ZodDiscriminatedUnion<
|
|
2715
|
+
Options extends readonly SomeType[] = readonly $ZodType[],
|
|
2716
|
+
Disc extends string = string,
|
|
2717
|
+
> extends $ZodType {
|
|
2718
|
+
_zod: $ZodDiscriminatedUnionInternals<Options, Disc>;
|
|
2014
2719
|
}
|
|
2015
2720
|
|
|
2016
2721
|
export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
|
|
2017
2722
|
/*@__PURE__*/
|
|
2018
2723
|
core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
|
2724
|
+
def.inclusive = false;
|
|
2725
|
+
|
|
2019
2726
|
$ZodUnion.init(inst, def);
|
|
2020
2727
|
|
|
2021
2728
|
const _super = inst._zod.parse;
|
|
2022
|
-
util.
|
|
2729
|
+
util.defineLazyInternal(inst, "propValues", (zod) => {
|
|
2023
2730
|
const propValues: util.PropValues = {};
|
|
2024
|
-
|
|
2731
|
+
let undefinedCount = 0;
|
|
2732
|
+
for (const option of zod.def.options) {
|
|
2025
2733
|
const pv = option._zod.propValues;
|
|
2026
2734
|
if (!pv || Object.keys(pv).length === 0)
|
|
2027
|
-
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
2735
|
+
throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
|
|
2736
|
+
if (pv[zod.def.discriminator]?.has(undefined)) undefinedCount++;
|
|
2028
2737
|
for (const [k, v] of Object.entries(pv!)) {
|
|
2029
|
-
if (!propValues
|
|
2738
|
+
if (!Object.prototype.hasOwnProperty.call(propValues, k)) {
|
|
2739
|
+
util.assignProp(propValues, k, new Set());
|
|
2740
|
+
}
|
|
2030
2741
|
for (const val of v) {
|
|
2031
2742
|
propValues[k].add(val);
|
|
2032
2743
|
}
|
|
2033
2744
|
}
|
|
2034
2745
|
}
|
|
2746
|
+
if (!zod.def.unionFallback && undefinedCount > 1) propValues[zod.def.discriminator]?.delete(undefined);
|
|
2035
2747
|
return propValues;
|
|
2036
2748
|
});
|
|
2037
2749
|
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
const
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
if (!values || values.size === 0)
|
|
2044
|
-
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
|
|
2045
|
-
for (const v of values) {
|
|
2046
|
-
if (map.has(v)) {
|
|
2047
|
-
throw new Error(`Duplicate discriminator value "${String(v)}"`);
|
|
2048
|
-
}
|
|
2049
|
-
map.set(v, o);
|
|
2050
|
-
}
|
|
2750
|
+
// Checked now rather than in the lookup map below, so an option that lacks the discriminator fails at the `discriminatedUnion` call instead of on the first object parsed. Options whose shape cannot be enumerated without resolving it — pipes and lazies — are left to the map.
|
|
2751
|
+
def.options.forEach((option, i) => {
|
|
2752
|
+
const propShape = util.rawShape(option._zod.def);
|
|
2753
|
+
if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) {
|
|
2754
|
+
throw new Error(`Invalid discriminated union option at index "${i}"`);
|
|
2051
2755
|
}
|
|
2052
|
-
return map;
|
|
2053
2756
|
});
|
|
2054
2757
|
|
|
2758
|
+
const disc = util.cached(() => discriminatorMap(def));
|
|
2759
|
+
|
|
2055
2760
|
inst._zod.parse = (payload, ctx) => {
|
|
2056
2761
|
const input = payload.value;
|
|
2057
2762
|
if (!util.isObject(input)) {
|
|
2058
2763
|
payload.issues.push({
|
|
2059
2764
|
code: "invalid_type",
|
|
2765
|
+
|
|
2060
2766
|
expected: "object",
|
|
2061
2767
|
input,
|
|
2062
2768
|
inst,
|
|
@@ -2064,12 +2770,17 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
|
|
|
2064
2770
|
return payload;
|
|
2065
2771
|
}
|
|
2066
2772
|
|
|
2067
|
-
const
|
|
2068
|
-
|
|
2773
|
+
const value = input?.[def.discriminator];
|
|
2774
|
+
const opt = disc.value.get(value as util.Primitive);
|
|
2775
|
+
// forward metadata cannot choose an encoder for an absent tag
|
|
2776
|
+
if (opt && (value !== undefined || ctx.direction !== "backward")) {
|
|
2069
2777
|
return opt._zod.run(payload, ctx) as any;
|
|
2070
2778
|
}
|
|
2071
2779
|
|
|
2072
|
-
|
|
2780
|
+
// Fall back to union matching when the fast discriminator path fails:
|
|
2781
|
+
// - explicitly enabled via unionFallback, or
|
|
2782
|
+
// - during backward direction (encode), since codec-based discriminators have different values in forward vs backward directions
|
|
2783
|
+
if (def.unionFallback || ctx.direction === "backward") {
|
|
2073
2784
|
return _super(payload, ctx);
|
|
2074
2785
|
}
|
|
2075
2786
|
|
|
@@ -2078,6 +2789,8 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
|
|
|
2078
2789
|
code: "invalid_union",
|
|
2079
2790
|
errors: [],
|
|
2080
2791
|
note: "No matching discriminator",
|
|
2792
|
+
discriminator: def.discriminator,
|
|
2793
|
+
options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
|
|
2081
2794
|
input,
|
|
2082
2795
|
path: [def.discriminator],
|
|
2083
2796
|
inst,
|
|
@@ -2103,11 +2816,14 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
|
|
|
2103
2816
|
}
|
|
2104
2817
|
|
|
2105
2818
|
export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType>
|
|
2106
|
-
extends $ZodTypeInternals
|
|
2819
|
+
extends _$ZodTypeInternals {
|
|
2820
|
+
// $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>>
|
|
2107
2821
|
def: $ZodIntersectionDef<A, B>;
|
|
2108
2822
|
isst: never;
|
|
2109
2823
|
optin: A["_zod"]["optin"] | B["_zod"]["optin"];
|
|
2110
2824
|
optout: A["_zod"]["optout"] | B["_zod"]["optout"];
|
|
2825
|
+
output: core.output<A> & core.output<B>;
|
|
2826
|
+
input: core.input<A> & core.input<B>;
|
|
2111
2827
|
}
|
|
2112
2828
|
|
|
2113
2829
|
export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
|
@@ -2136,7 +2852,7 @@ export const $ZodIntersection: core.$constructor<$ZodIntersection> = /*@__PURE__
|
|
|
2136
2852
|
}
|
|
2137
2853
|
);
|
|
2138
2854
|
|
|
2139
|
-
function mergeValues(
|
|
2855
|
+
export function mergeValues(
|
|
2140
2856
|
a: any,
|
|
2141
2857
|
b: any
|
|
2142
2858
|
): { valid: true; data: any } | { valid: false; mergeErrorPath: (string | number)[] } {
|
|
@@ -2154,7 +2870,9 @@ function mergeValues(
|
|
|
2154
2870
|
const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
2155
2871
|
|
|
2156
2872
|
const newObj: any = { ...a, ...b };
|
|
2873
|
+
if (Object.prototype.hasOwnProperty.call(newObj, "__proto__")) delete newObj.__proto__;
|
|
2157
2874
|
for (const key of sharedKeys) {
|
|
2875
|
+
if (key === "__proto__") continue;
|
|
2158
2876
|
const sharedValue = mergeValues(a[key], b[key]);
|
|
2159
2877
|
if (!sharedValue.valid) {
|
|
2160
2878
|
return {
|
|
@@ -2195,17 +2913,52 @@ function mergeValues(
|
|
|
2195
2913
|
}
|
|
2196
2914
|
|
|
2197
2915
|
function handleIntersectionResults(result: ParsePayload, left: ParsePayload, right: ParsePayload): ParsePayload {
|
|
2198
|
-
|
|
2199
|
-
|
|
2916
|
+
// Track which side(s) reject each key. A key rejection is reported only when BOTH sides reject it, so a key owned by one branch survives the other's key schema. strictObject reports these as unrecognized_keys; a record with an open key schema reports one invalid_key per key.
|
|
2917
|
+
const unrecKeys = new Map<string, { l?: true; r?: true }>();
|
|
2918
|
+
let unrecIssue: errors.$ZodRawIssue | undefined;
|
|
2919
|
+
const keyIssues = new Map<string, errors.$ZodRawIssue>();
|
|
2920
|
+
|
|
2921
|
+
const collect = (iss: errors.$ZodRawIssue, side: "l" | "r"): boolean => {
|
|
2922
|
+
let keys: string[];
|
|
2923
|
+
if (iss.code === "unrecognized_keys" && !iss.path?.length) {
|
|
2924
|
+
unrecIssue ??= iss;
|
|
2925
|
+
keys = iss.keys as string[];
|
|
2926
|
+
} else if (iss.code === "invalid_key" && iss.origin === "record" && iss.path?.length === 1) {
|
|
2927
|
+
const k = String(iss.path[0]);
|
|
2928
|
+
if (!keyIssues.has(k)) keyIssues.set(k, iss);
|
|
2929
|
+
keys = [k];
|
|
2930
|
+
} else {
|
|
2931
|
+
return false;
|
|
2932
|
+
}
|
|
2933
|
+
for (const k of keys) {
|
|
2934
|
+
if (!unrecKeys.has(k)) unrecKeys.set(k, {});
|
|
2935
|
+
unrecKeys.get(k)![side] = true;
|
|
2936
|
+
}
|
|
2937
|
+
return true;
|
|
2938
|
+
};
|
|
2939
|
+
|
|
2940
|
+
for (const iss of left.issues) {
|
|
2941
|
+
if (!collect(iss, "l")) result.issues.push(iss);
|
|
2200
2942
|
}
|
|
2201
|
-
|
|
2202
|
-
|
|
2943
|
+
|
|
2944
|
+
for (const iss of right.issues) {
|
|
2945
|
+
if (!collect(iss, "r")) result.issues.push(iss);
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
// Report only keys rejected by BOTH sides
|
|
2949
|
+
const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
|
|
2950
|
+
if (bothKeys.length) {
|
|
2951
|
+
const aggregated = unrecIssue ? bothKeys.filter((k) => (unrecIssue!.keys as string[]).includes(k)) : [];
|
|
2952
|
+
if (aggregated.length) result.issues.push({ ...unrecIssue!, keys: aggregated });
|
|
2953
|
+
for (const k of bothKeys) {
|
|
2954
|
+
if (!aggregated.includes(k) && keyIssues.has(k)) result.issues.push(keyIssues.get(k)!);
|
|
2955
|
+
}
|
|
2203
2956
|
}
|
|
2204
|
-
if (util.aborted(result)) return result;
|
|
2205
2957
|
|
|
2206
2958
|
const merged = mergeValues(left.value, right.value);
|
|
2207
2959
|
|
|
2208
2960
|
if (!merged.valid) {
|
|
2961
|
+
if (util.aborted(result)) return result;
|
|
2209
2962
|
throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
|
|
2210
2963
|
}
|
|
2211
2964
|
|
|
@@ -2241,7 +2994,7 @@ type TupleInputTypeWithOptionals<T extends util.TupleItems> = T extends readonly
|
|
|
2241
2994
|
...infer Prefix extends SomeType[],
|
|
2242
2995
|
infer Tail extends SomeType,
|
|
2243
2996
|
]
|
|
2244
|
-
? Tail["_zod"]["optin"] extends "optional"
|
|
2997
|
+
? Tail["_zod"]["optin"] extends "optional" | "defaulted"
|
|
2245
2998
|
? [...TupleInputTypeWithOptionals<Prefix>, core.input<Tail>?]
|
|
2246
2999
|
: TupleInputTypeNoOptionals<T>
|
|
2247
3000
|
: [];
|
|
@@ -2265,9 +3018,12 @@ type TupleOutputTypeWithOptionals<T extends util.TupleItems> = T extends readonl
|
|
|
2265
3018
|
export interface $ZodTupleInternals<
|
|
2266
3019
|
T extends util.TupleItems = readonly $ZodType[],
|
|
2267
3020
|
Rest extends SomeType | null = $ZodType | null,
|
|
2268
|
-
> extends $ZodTypeInternals
|
|
3021
|
+
> extends _$ZodTypeInternals {
|
|
2269
3022
|
def: $ZodTupleDef<T, Rest>;
|
|
2270
3023
|
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueTooBig<unknown[]> | errors.$ZodIssueTooSmall<unknown[]>;
|
|
3024
|
+
// $ZodTypeInternals<$InferTupleOutputType<T, Rest>, $InferTupleInputType<T, Rest>>
|
|
3025
|
+
output: $InferTupleOutputType<T, Rest>;
|
|
3026
|
+
input: $InferTupleInputType<T, Rest>;
|
|
2271
3027
|
}
|
|
2272
3028
|
|
|
2273
3029
|
export interface $ZodTuple<
|
|
@@ -2280,7 +3036,8 @@ export interface $ZodTuple<
|
|
|
2280
3036
|
export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def) => {
|
|
2281
3037
|
$ZodType.init(inst, def);
|
|
2282
3038
|
const items = def.items;
|
|
2283
|
-
const
|
|
3039
|
+
const memo = core.globalConfig.memoizer;
|
|
3040
|
+
memo?.attach(inst);
|
|
2284
3041
|
|
|
2285
3042
|
inst._zod.parse = (payload, ctx) => {
|
|
2286
3043
|
const input = payload.value;
|
|
@@ -2294,67 +3051,91 @@ export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$const
|
|
|
2294
3051
|
return payload;
|
|
2295
3052
|
}
|
|
2296
3053
|
|
|
2297
|
-
payload.value = [];
|
|
3054
|
+
payload.value = memo ? memo.alloc(inst, payload, [] as unknown[], ctx) : [];
|
|
2298
3055
|
const proms: Promise<any>[] = [];
|
|
2299
3056
|
|
|
3057
|
+
const optinStart = getTupleOptStart(items, "optin");
|
|
3058
|
+
const optoutStart = getTupleOptStart(items, "optout");
|
|
3059
|
+
|
|
2300
3060
|
if (!def.rest) {
|
|
2301
|
-
|
|
2302
|
-
const tooSmall = input.length < optStart - 1;
|
|
2303
|
-
if (tooBig || tooSmall) {
|
|
3061
|
+
if (input.length < optinStart) {
|
|
2304
3062
|
payload.issues.push({
|
|
3063
|
+
code: "too_small",
|
|
3064
|
+
minimum: optinStart,
|
|
3065
|
+
inclusive: true,
|
|
2305
3066
|
input,
|
|
2306
3067
|
inst,
|
|
2307
3068
|
origin: "array" as const,
|
|
2308
|
-
...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
|
|
2309
3069
|
});
|
|
2310
3070
|
return payload;
|
|
2311
3071
|
}
|
|
3072
|
+
if (input.length > items.length) {
|
|
3073
|
+
payload.issues.push({
|
|
3074
|
+
code: "too_big",
|
|
3075
|
+
maximum: items.length,
|
|
3076
|
+
inclusive: true,
|
|
3077
|
+
input,
|
|
3078
|
+
inst,
|
|
3079
|
+
origin: "array" as const,
|
|
3080
|
+
});
|
|
3081
|
+
}
|
|
2312
3082
|
}
|
|
2313
3083
|
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
proms.push(result.then((result) => handleTupleResult(result, payload, i)));
|
|
3084
|
+
// Run every item in parallel, collecting results into an indexed array. The post-processing in `handleTupleResults` walks them in order so it can decide whether an absent optional-output error can truncate the tail or must be reported to preserve required output.
|
|
3085
|
+
const itemResults: ParsePayload[] = new Array(items.length);
|
|
3086
|
+
// only tracked when there is a rest loop to skip
|
|
3087
|
+
const abortEarly = def.rest ? ctx?.abortEarly : undefined;
|
|
3088
|
+
let itemAborted = false;
|
|
3089
|
+
for (let i = 0; i < items.length; i++) {
|
|
3090
|
+
const r = items[i]._zod.run({ value: input[i], issues: [] }, ctx);
|
|
3091
|
+
if (r instanceof Promise) {
|
|
3092
|
+
proms.push(
|
|
3093
|
+
r.then((rr) => {
|
|
3094
|
+
itemResults[i] = rr;
|
|
3095
|
+
})
|
|
3096
|
+
);
|
|
2328
3097
|
} else {
|
|
2329
|
-
|
|
3098
|
+
itemResults[i] = r;
|
|
3099
|
+
if (abortEarly && !itemAborted && r.issues.length) itemAborted = util.aborted(r);
|
|
2330
3100
|
}
|
|
2331
3101
|
}
|
|
2332
3102
|
|
|
2333
|
-
|
|
3103
|
+
// sound because rest is non-empty exactly when every fixed index is present, the one case handleTupleResults cannot discard an item's issues
|
|
3104
|
+
if (def.rest && !itemAborted) {
|
|
3105
|
+
let i = items.length - 1;
|
|
2334
3106
|
const rest = input.slice(items.length);
|
|
3107
|
+
let seen = payload.issues.length;
|
|
2335
3108
|
for (const el of rest) {
|
|
3109
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
3110
|
+
if (util.aborted(payload, seen)) break;
|
|
3111
|
+
seen = payload.issues.length;
|
|
3112
|
+
}
|
|
2336
3113
|
i++;
|
|
2337
|
-
const result = def.rest._zod.run(
|
|
2338
|
-
{
|
|
2339
|
-
value: el,
|
|
2340
|
-
issues: [],
|
|
2341
|
-
},
|
|
2342
|
-
ctx
|
|
2343
|
-
);
|
|
2344
|
-
|
|
3114
|
+
const result = def.rest._zod.run({ value: el, issues: [] }, ctx);
|
|
2345
3115
|
if (result instanceof Promise) {
|
|
2346
|
-
proms.push(result.then((
|
|
3116
|
+
proms.push(result.then((r) => handleTupleResult(r, payload, i)));
|
|
2347
3117
|
} else {
|
|
2348
3118
|
handleTupleResult(result, payload, i);
|
|
2349
3119
|
}
|
|
2350
3120
|
}
|
|
2351
3121
|
}
|
|
2352
3122
|
|
|
2353
|
-
if (proms.length)
|
|
2354
|
-
|
|
3123
|
+
if (proms.length) {
|
|
3124
|
+
return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items, input, optoutStart));
|
|
3125
|
+
}
|
|
3126
|
+
return handleTupleResults(itemResults, payload, items, input, optoutStart);
|
|
2355
3127
|
};
|
|
2356
3128
|
});
|
|
2357
3129
|
|
|
3130
|
+
function getTupleOptStart(items: readonly $ZodType[], key: "optin" | "optout") {
|
|
3131
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
3132
|
+
// optin is a three-rung ladder so any rung above `undefined` permits an absent slot; optout stays two-valued.
|
|
3133
|
+
const omittable = key === "optin" ? items[i]._zod.optin !== undefined : items[i]._zod.optout === "optional";
|
|
3134
|
+
if (!omittable) return i + 1;
|
|
3135
|
+
}
|
|
3136
|
+
return 0;
|
|
3137
|
+
}
|
|
3138
|
+
|
|
2358
3139
|
function handleTupleResult(result: ParsePayload, final: ParsePayload<any[]>, index: number) {
|
|
2359
3140
|
if (result.issues.length) {
|
|
2360
3141
|
final.issues.push(...util.prefixIssues(index, result.issues));
|
|
@@ -2362,6 +3143,48 @@ function handleTupleResult(result: ParsePayload, final: ParsePayload<any[]>, ind
|
|
|
2362
3143
|
final.value[index] = result.value;
|
|
2363
3144
|
}
|
|
2364
3145
|
|
|
3146
|
+
function handleTupleResults(
|
|
3147
|
+
itemResults: ParsePayload[],
|
|
3148
|
+
final: ParsePayload<any[]>,
|
|
3149
|
+
items: readonly $ZodType[],
|
|
3150
|
+
input: unknown[],
|
|
3151
|
+
optoutStart: number
|
|
3152
|
+
) {
|
|
3153
|
+
// Walk results in order. Mirror $ZodObject's swallow-on-absent-optional rule, but only after `optoutStart`: the first index where the output tuple tail can be absent.
|
|
3154
|
+
for (let i = 0; i < items.length; i++) {
|
|
3155
|
+
const r = itemResults[i];
|
|
3156
|
+
const isPresent = i < input.length;
|
|
3157
|
+
// The array analog of `handlePropertyResult`'s absent-key early return: the middle rung permits absence without supplying anything in its place, so the tail truncates here instead of materializing whatever the item made of `undefined`.
|
|
3158
|
+
if (!isPresent && i >= optoutStart && items[i]._zod.optin === "optional") {
|
|
3159
|
+
final.value.length = i;
|
|
3160
|
+
break;
|
|
3161
|
+
}
|
|
3162
|
+
if (r.issues.length) {
|
|
3163
|
+
if (!isPresent && i >= optoutStart) {
|
|
3164
|
+
final.value.length = i;
|
|
3165
|
+
break;
|
|
3166
|
+
}
|
|
3167
|
+
final.issues.push(...util.prefixIssues(i, r.issues));
|
|
3168
|
+
}
|
|
3169
|
+
final.value[i] = r.value;
|
|
3170
|
+
}
|
|
3171
|
+
|
|
3172
|
+
// Drop trailing slots that produced `undefined` for absent input
|
|
3173
|
+
// (the array analog of an absent optional key on an object). The
|
|
3174
|
+
// `i >= input.length` floor is critical: an explicit `undefined`
|
|
3175
|
+
// *inside* the input must be preserved even when the schema is
|
|
3176
|
+
// optional-out (e.g. `z.string().or(z.undefined())` accepting an
|
|
3177
|
+
// explicit undefined value).
|
|
3178
|
+
for (let i = final.value.length - 1; i >= input.length; i--) {
|
|
3179
|
+
if (items[i]._zod.optout === "optional" && final.value[i] === undefined) {
|
|
3180
|
+
final.value.length = i;
|
|
3181
|
+
} else {
|
|
3182
|
+
break;
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
return final;
|
|
3186
|
+
}
|
|
3187
|
+
|
|
2365
3188
|
//////////////////////////////////////////
|
|
2366
3189
|
//////////////////////////////////////////
|
|
2367
3190
|
////////// //////////
|
|
@@ -2370,12 +3193,15 @@ function handleTupleResult(result: ParsePayload, final: ParsePayload<any[]>, ind
|
|
|
2370
3193
|
//////////////////////////////////////////
|
|
2371
3194
|
//////////////////////////////////////////
|
|
2372
3195
|
|
|
2373
|
-
export type $ZodRecordKey = $ZodType<string | number | symbol,
|
|
3196
|
+
export type $ZodRecordKey = $ZodType<string | number | symbol, unknown>; // $HasValues | $HasPattern;
|
|
2374
3197
|
export interface $ZodRecordDef<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType>
|
|
2375
3198
|
extends $ZodTypeDef {
|
|
2376
3199
|
type: "record";
|
|
2377
3200
|
keyType: Key;
|
|
2378
3201
|
valueType: Value;
|
|
3202
|
+
/** @default "strict" - errors on keys not matching keyType. "loose" passes through non-matching keys unchanged. */
|
|
3203
|
+
mode?: "strict" | "loose";
|
|
3204
|
+
partial?: boolean;
|
|
2379
3205
|
}
|
|
2380
3206
|
|
|
2381
3207
|
// export type $InferZodRecordOutput<
|
|
@@ -2409,16 +3235,23 @@ export type $InferZodRecordOutput<
|
|
|
2409
3235
|
// ? Record<core.input<Key>, core.input<Value>>
|
|
2410
3236
|
// : Record<core.input<Key>, core.input<Value>>
|
|
2411
3237
|
// : Record<core.input<Key>, core.input<Value>>;
|
|
3238
|
+
|
|
2412
3239
|
export type $InferZodRecordInput<
|
|
2413
3240
|
Key extends $ZodRecordKey = $ZodRecordKey,
|
|
2414
3241
|
Value extends SomeType = $ZodType,
|
|
2415
3242
|
> = Key extends $partial
|
|
2416
|
-
? Partial<Record<core.input<Key
|
|
2417
|
-
:
|
|
3243
|
+
? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>>
|
|
3244
|
+
: // A value schema that accepts an absent slot makes the key omittable on the way in, exactly as it does in an object shape. The output side keeps every key, since the parser fills each one.
|
|
3245
|
+
[Value] extends [OptionalInSchema]
|
|
3246
|
+
? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>>
|
|
3247
|
+
: Record<core.input<Key> & PropertyKey, core.input<Value>>;
|
|
2418
3248
|
|
|
2419
3249
|
export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType>
|
|
2420
|
-
extends $ZodTypeInternals
|
|
3250
|
+
extends $ZodTypeInternals {
|
|
2421
3251
|
def: $ZodRecordDef<Key, Value>;
|
|
3252
|
+
// members rather than base type arguments, which TypeScript 7.1 reports as circular for `z.json()`
|
|
3253
|
+
output: $InferZodRecordOutput<Key, Value>;
|
|
3254
|
+
input: $InferZodRecordInput<Key, Value>;
|
|
2422
3255
|
isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
|
|
2423
3256
|
optin?: "optional" | undefined;
|
|
2424
3257
|
optout?: "optional" | undefined;
|
|
@@ -2432,6 +3265,8 @@ export interface $ZodRecord<Key extends $ZodRecordKey = $ZodRecordKey, Value ext
|
|
|
2432
3265
|
|
|
2433
3266
|
export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, def) => {
|
|
2434
3267
|
$ZodType.init(inst, def);
|
|
3268
|
+
const memo = core.globalConfig.memoizer;
|
|
3269
|
+
memo?.attach(inst);
|
|
2435
3270
|
|
|
2436
3271
|
inst._zod.parse = (payload, ctx) => {
|
|
2437
3272
|
const input = payload.value;
|
|
@@ -2440,19 +3275,42 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2440
3275
|
payload.issues.push({
|
|
2441
3276
|
expected: "record",
|
|
2442
3277
|
code: "invalid_type",
|
|
3278
|
+
|
|
2443
3279
|
input,
|
|
2444
3280
|
inst,
|
|
2445
3281
|
});
|
|
2446
3282
|
return payload;
|
|
2447
3283
|
}
|
|
2448
3284
|
|
|
3285
|
+
// no guard in either loop below: a record's invalid_key aborts but an enclosing intersection can reconcile it, so a stopped loop hides keys the sibling does not own and the intersection then rejects nothing
|
|
2449
3286
|
const proms: Promise<any>[] = [];
|
|
2450
3287
|
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
payload.value = {};
|
|
3288
|
+
const values = def.keyType._zod.values;
|
|
3289
|
+
if (values && !def.partial) {
|
|
3290
|
+
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
|
|
3291
|
+
const recordKeys = new Set<string | symbol>();
|
|
2454
3292
|
for (const key of values) {
|
|
2455
3293
|
if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
|
|
3294
|
+
recordKeys.add(typeof key === "number" ? key.toString() : key);
|
|
3295
|
+
// A declared __proto__ is stripped but is not an unrecognized key.
|
|
3296
|
+
if (key === "__proto__") continue;
|
|
3297
|
+
const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
|
|
3298
|
+
if (keyResult instanceof Promise) {
|
|
3299
|
+
throw new Error("Async schemas not supported in object keys currently");
|
|
3300
|
+
}
|
|
3301
|
+
if (keyResult.issues.length) {
|
|
3302
|
+
payload.issues.push({
|
|
3303
|
+
code: "invalid_key",
|
|
3304
|
+
origin: "record",
|
|
3305
|
+
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
|
3306
|
+
input: key,
|
|
3307
|
+
path: [key],
|
|
3308
|
+
inst,
|
|
3309
|
+
});
|
|
3310
|
+
continue;
|
|
3311
|
+
}
|
|
3312
|
+
const outKey = keyResult.value as PropertyKey;
|
|
3313
|
+
if (outKey === "__proto__") continue;
|
|
2456
3314
|
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
|
2457
3315
|
|
|
2458
3316
|
if (result instanceof Promise) {
|
|
@@ -2461,56 +3319,91 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2461
3319
|
if (result.issues.length) {
|
|
2462
3320
|
payload.issues.push(...util.prefixIssues(key, result.issues));
|
|
2463
3321
|
}
|
|
2464
|
-
payload.value[
|
|
3322
|
+
payload.value[outKey] = result.value;
|
|
2465
3323
|
})
|
|
2466
3324
|
);
|
|
2467
3325
|
} else {
|
|
2468
3326
|
if (result.issues.length) {
|
|
2469
3327
|
payload.issues.push(...util.prefixIssues(key, result.issues));
|
|
2470
3328
|
}
|
|
2471
|
-
payload.value[
|
|
3329
|
+
payload.value[outKey] = result.value;
|
|
2472
3330
|
}
|
|
2473
3331
|
}
|
|
2474
3332
|
}
|
|
2475
3333
|
|
|
2476
3334
|
let unrecognized!: string[];
|
|
2477
3335
|
for (const key in input) {
|
|
2478
|
-
if (!
|
|
2479
|
-
|
|
2480
|
-
|
|
3336
|
+
if (!recordKeys.has(key)) {
|
|
3337
|
+
if (def.mode === "loose") {
|
|
3338
|
+
// skip __proto__ so it can't replace the result prototype via the assignment setter on the plain {} we build into
|
|
3339
|
+
if (key === "__proto__") continue;
|
|
3340
|
+
payload.value[key] = input[key];
|
|
3341
|
+
} else {
|
|
3342
|
+
unrecognized = unrecognized ?? [];
|
|
3343
|
+
unrecognized.push(key);
|
|
3344
|
+
}
|
|
2481
3345
|
}
|
|
2482
3346
|
}
|
|
2483
3347
|
if (unrecognized && unrecognized.length > 0) {
|
|
2484
3348
|
payload.issues.push({
|
|
2485
3349
|
code: "unrecognized_keys",
|
|
3350
|
+
|
|
2486
3351
|
input,
|
|
2487
3352
|
inst,
|
|
2488
3353
|
keys: unrecognized,
|
|
3354
|
+
continue: true,
|
|
2489
3355
|
});
|
|
2490
3356
|
}
|
|
2491
3357
|
} else {
|
|
2492
|
-
payload.value = {};
|
|
3358
|
+
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
|
|
3359
|
+
// An enumerable key schema declares which keys the record owns, so a key outside the set is unrecognized. A non-enumerable one (regex, refine) is a constraint every key must satisfy, so a failing key is invalid. Only the former is reconcilable against the other side of an intersection.
|
|
3360
|
+
let unrecognized!: string[];
|
|
3361
|
+
// Reflect.ownKeys for Symbol-key support; filter non-enumerable to match z.object()
|
|
2493
3362
|
for (const key of Reflect.ownKeys(input)) {
|
|
2494
3363
|
if (key === "__proto__") continue;
|
|
2495
|
-
|
|
2496
|
-
|
|
3364
|
+
if (!Object.prototype.propertyIsEnumerable.call(input, key)) continue;
|
|
3365
|
+
let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
|
|
2497
3366
|
if (keyResult instanceof Promise) {
|
|
2498
3367
|
throw new Error("Async schemas not supported in object keys currently");
|
|
2499
3368
|
}
|
|
2500
3369
|
|
|
3370
|
+
// Numeric string fallback: if key is a numeric string and failed, retry with Number(key). This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
|
|
3371
|
+
const checkNumericKey = typeof key === "string" && regexes.number.test(key) && keyResult.issues.length;
|
|
3372
|
+
if (checkNumericKey) {
|
|
3373
|
+
const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
|
|
3374
|
+
if (retryResult instanceof Promise) {
|
|
3375
|
+
throw new Error("Async schemas not supported in object keys currently");
|
|
3376
|
+
}
|
|
3377
|
+
if (retryResult.issues.length === 0) {
|
|
3378
|
+
keyResult = retryResult;
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
|
|
2501
3382
|
if (keyResult.issues.length) {
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
3383
|
+
if (def.mode === "loose") {
|
|
3384
|
+
// Pass through unchanged
|
|
3385
|
+
payload.value[key] = input[key];
|
|
3386
|
+
} else if (values) {
|
|
3387
|
+
unrecognized = unrecognized ?? [];
|
|
3388
|
+
unrecognized.push(key as string);
|
|
3389
|
+
} else {
|
|
3390
|
+
// Default "strict" behavior: error on invalid key
|
|
3391
|
+
payload.issues.push({
|
|
3392
|
+
code: "invalid_key",
|
|
3393
|
+
origin: "record",
|
|
3394
|
+
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
|
3395
|
+
input: key,
|
|
3396
|
+
path: [key],
|
|
3397
|
+
inst,
|
|
3398
|
+
});
|
|
3399
|
+
}
|
|
2511
3400
|
continue;
|
|
2512
3401
|
}
|
|
2513
3402
|
|
|
3403
|
+
// the guard above tests the raw input key, but the key schema can normalize an ordinary key into __proto__; re-check the key we actually write under
|
|
3404
|
+
const outKey = keyResult.value as PropertyKey;
|
|
3405
|
+
if (outKey === "__proto__") continue;
|
|
3406
|
+
|
|
2514
3407
|
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
|
2515
3408
|
|
|
2516
3409
|
if (result instanceof Promise) {
|
|
@@ -2519,16 +3412,27 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2519
3412
|
if (result.issues.length) {
|
|
2520
3413
|
payload.issues.push(...util.prefixIssues(key, result.issues));
|
|
2521
3414
|
}
|
|
2522
|
-
payload.value[
|
|
3415
|
+
payload.value[outKey] = result.value;
|
|
2523
3416
|
})
|
|
2524
3417
|
);
|
|
2525
3418
|
} else {
|
|
2526
3419
|
if (result.issues.length) {
|
|
2527
3420
|
payload.issues.push(...util.prefixIssues(key, result.issues));
|
|
2528
3421
|
}
|
|
2529
|
-
payload.value[
|
|
3422
|
+
payload.value[outKey] = result.value;
|
|
2530
3423
|
}
|
|
2531
3424
|
}
|
|
3425
|
+
|
|
3426
|
+
if (unrecognized && unrecognized.length > 0) {
|
|
3427
|
+
payload.issues.push({
|
|
3428
|
+
code: "unrecognized_keys",
|
|
3429
|
+
|
|
3430
|
+
input,
|
|
3431
|
+
inst,
|
|
3432
|
+
keys: unrecognized,
|
|
3433
|
+
continue: true,
|
|
3434
|
+
});
|
|
3435
|
+
}
|
|
2532
3436
|
}
|
|
2533
3437
|
|
|
2534
3438
|
if (proms.length) {
|
|
@@ -2565,6 +3469,8 @@ export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType
|
|
|
2565
3469
|
|
|
2566
3470
|
export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$constructor("$ZodMap", (inst, def) => {
|
|
2567
3471
|
$ZodType.init(inst, def);
|
|
3472
|
+
const memo = core.globalConfig.memoizer;
|
|
3473
|
+
memo?.attach(inst);
|
|
2568
3474
|
|
|
2569
3475
|
inst._zod.parse = (payload, ctx) => {
|
|
2570
3476
|
const input = payload.value;
|
|
@@ -2572,6 +3478,7 @@ export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$construct
|
|
|
2572
3478
|
payload.issues.push({
|
|
2573
3479
|
expected: "map",
|
|
2574
3480
|
code: "invalid_type",
|
|
3481
|
+
|
|
2575
3482
|
input,
|
|
2576
3483
|
inst,
|
|
2577
3484
|
});
|
|
@@ -2579,9 +3486,15 @@ export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$construct
|
|
|
2579
3486
|
}
|
|
2580
3487
|
|
|
2581
3488
|
const proms: Promise<any>[] = [];
|
|
2582
|
-
payload.value = new Map();
|
|
3489
|
+
payload.value = memo ? memo.alloc(inst, payload, new Map(), ctx) : new Map();
|
|
3490
|
+
const abortEarly = ctx?.abortEarly;
|
|
3491
|
+
let seen = payload.issues.length;
|
|
2583
3492
|
|
|
2584
3493
|
for (const [key, value] of input) {
|
|
3494
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
3495
|
+
if (util.aborted(payload, seen)) break;
|
|
3496
|
+
seen = payload.issues.length;
|
|
3497
|
+
}
|
|
2585
3498
|
const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
|
|
2586
3499
|
const valueResult = def.valueType._zod.run({ value: value, issues: [] }, ctx);
|
|
2587
3500
|
|
|
@@ -2599,6 +3512,7 @@ export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$construct
|
|
|
2599
3512
|
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
2600
3513
|
return payload;
|
|
2601
3514
|
};
|
|
3515
|
+
capSize(inst, mapSize);
|
|
2602
3516
|
});
|
|
2603
3517
|
|
|
2604
3518
|
function handleMapResult(
|
|
@@ -2615,8 +3529,9 @@ function handleMapResult(
|
|
|
2615
3529
|
final.issues.push(...util.prefixIssues(key as PropertyKey, keyResult.issues));
|
|
2616
3530
|
} else {
|
|
2617
3531
|
final.issues.push({
|
|
2618
|
-
origin: "map",
|
|
2619
3532
|
code: "invalid_key",
|
|
3533
|
+
|
|
3534
|
+
origin: "map",
|
|
2620
3535
|
input,
|
|
2621
3536
|
inst,
|
|
2622
3537
|
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
|
@@ -2630,6 +3545,7 @@ function handleMapResult(
|
|
|
2630
3545
|
final.issues.push({
|
|
2631
3546
|
origin: "map",
|
|
2632
3547
|
code: "invalid_element",
|
|
3548
|
+
|
|
2633
3549
|
input,
|
|
2634
3550
|
inst,
|
|
2635
3551
|
key: key,
|
|
@@ -2666,6 +3582,8 @@ export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
|
|
|
2666
3582
|
|
|
2667
3583
|
export const $ZodSet: core.$constructor<$ZodSet> = /*@__PURE__*/ core.$constructor("$ZodSet", (inst, def) => {
|
|
2668
3584
|
$ZodType.init(inst, def);
|
|
3585
|
+
const memo = core.globalConfig.memoizer;
|
|
3586
|
+
memo?.attach(inst);
|
|
2669
3587
|
|
|
2670
3588
|
inst._zod.parse = (payload, ctx) => {
|
|
2671
3589
|
const input = payload.value;
|
|
@@ -2680,8 +3598,14 @@ export const $ZodSet: core.$constructor<$ZodSet> = /*@__PURE__*/ core.$construct
|
|
|
2680
3598
|
}
|
|
2681
3599
|
|
|
2682
3600
|
const proms: Promise<any>[] = [];
|
|
2683
|
-
payload.value = new Set();
|
|
3601
|
+
payload.value = memo ? memo.alloc(inst, payload, new Set(), ctx) : new Set();
|
|
3602
|
+
const abortEarly = ctx?.abortEarly;
|
|
3603
|
+
let seen = payload.issues.length;
|
|
2684
3604
|
for (const item of input) {
|
|
3605
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
3606
|
+
if (util.aborted(payload, seen)) break;
|
|
3607
|
+
seen = payload.issues.length;
|
|
3608
|
+
}
|
|
2685
3609
|
const result = def.valueType._zod.run({ value: item, issues: [] }, ctx);
|
|
2686
3610
|
if (result instanceof Promise) {
|
|
2687
3611
|
proms.push(result.then((result) => handleSetResult(result, payload)));
|
|
@@ -2691,6 +3615,7 @@ export const $ZodSet: core.$constructor<$ZodSet> = /*@__PURE__*/ core.$construct
|
|
|
2691
3615
|
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
2692
3616
|
return payload;
|
|
2693
3617
|
};
|
|
3618
|
+
capSize(inst, setSize);
|
|
2694
3619
|
});
|
|
2695
3620
|
|
|
2696
3621
|
function handleSetResult(result: ParsePayload, final: ParsePayload<Set<any>>) {
|
|
@@ -2737,23 +3662,25 @@ export const $ZodEnum: core.$constructor<$ZodEnum> = /*@__PURE__*/ core.$constru
|
|
|
2737
3662
|
$ZodType.init(inst, def);
|
|
2738
3663
|
|
|
2739
3664
|
const values = util.getEnumValues(def.entries);
|
|
2740
|
-
|
|
2741
|
-
inst._zod.values =
|
|
2742
|
-
|
|
2743
|
-
inst
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
.join("|")})$`
|
|
2748
|
-
|
|
3665
|
+
const valuesSet = new Set<util.Primitive>(values);
|
|
3666
|
+
inst._zod.values = valuesSet;
|
|
3667
|
+
|
|
3668
|
+
util.defineLazyInternal(inst, "pattern", (zod) => {
|
|
3669
|
+
const patternValues = util.getEnumValues(zod.def.entries).filter((k) => util.propertyKeyTypes.has(typeof k));
|
|
3670
|
+
// unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
|
|
3671
|
+
return new RegExp(
|
|
3672
|
+
patternValues.length ? `^(${patternValues.map((o) => util.escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$"
|
|
3673
|
+
);
|
|
3674
|
+
});
|
|
2749
3675
|
|
|
2750
3676
|
inst._zod.parse = (payload, _ctx) => {
|
|
2751
3677
|
const input = payload.value;
|
|
2752
|
-
if (
|
|
3678
|
+
if (valuesSet.has(input)) {
|
|
2753
3679
|
return payload;
|
|
2754
3680
|
}
|
|
2755
3681
|
payload.issues.push({
|
|
2756
3682
|
code: "invalid_value",
|
|
3683
|
+
|
|
2757
3684
|
values,
|
|
2758
3685
|
input,
|
|
2759
3686
|
inst,
|
|
@@ -2791,21 +3718,31 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
|
|
|
2791
3718
|
(inst, def) => {
|
|
2792
3719
|
$ZodType.init(inst, def);
|
|
2793
3720
|
|
|
2794
|
-
|
|
2795
|
-
inst._zod.
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
3721
|
+
const values = new Set<util.Literal>(def.values);
|
|
3722
|
+
inst._zod.values = values;
|
|
3723
|
+
|
|
3724
|
+
util.defineLazyInternal(inst, "pattern", (zod) => {
|
|
3725
|
+
const vals = zod.def.values;
|
|
3726
|
+
// unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
|
|
3727
|
+
return new RegExp(
|
|
3728
|
+
vals.length
|
|
3729
|
+
? `^(${vals
|
|
3730
|
+
.map((o: util.Literal) =>
|
|
3731
|
+
typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)
|
|
3732
|
+
)
|
|
3733
|
+
.join("|")})$`
|
|
3734
|
+
: "^[^\\s\\S]$"
|
|
3735
|
+
);
|
|
3736
|
+
});
|
|
2801
3737
|
|
|
2802
3738
|
inst._zod.parse = (payload, _ctx) => {
|
|
2803
3739
|
const input = payload.value;
|
|
2804
|
-
if (
|
|
3740
|
+
if (values.has(input)) {
|
|
2805
3741
|
return payload;
|
|
2806
3742
|
}
|
|
2807
3743
|
payload.issues.push({
|
|
2808
3744
|
code: "invalid_value",
|
|
3745
|
+
|
|
2809
3746
|
values: def.values,
|
|
2810
3747
|
input,
|
|
2811
3748
|
inst,
|
|
@@ -2865,8 +3802,11 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
|
|
|
2865
3802
|
//////////////////////////////////////////
|
|
2866
3803
|
|
|
2867
3804
|
// provide a fallback in case the File interface isn't provided in the environment
|
|
2868
|
-
|
|
2869
|
-
|
|
3805
|
+
type _File = typeof globalThis extends { File: infer F extends new (...args: any[]) => any } ? InstanceType<F> : {};
|
|
3806
|
+
/** Do not reference this directly. */
|
|
3807
|
+
export interface File extends _File {
|
|
3808
|
+
readonly type: string;
|
|
3809
|
+
readonly size: number;
|
|
2870
3810
|
}
|
|
2871
3811
|
|
|
2872
3812
|
export interface $ZodFileDef extends $ZodTypeDef {
|
|
@@ -2892,10 +3832,12 @@ export const $ZodFile: core.$constructor<$ZodFile> = /*@__PURE__*/ core.$constru
|
|
|
2892
3832
|
|
|
2893
3833
|
inst._zod.parse = (payload, _ctx) => {
|
|
2894
3834
|
const input = payload.value;
|
|
3835
|
+
// @ts-ignore
|
|
2895
3836
|
if (input instanceof File) return payload;
|
|
2896
3837
|
payload.issues.push({
|
|
2897
3838
|
expected: "file",
|
|
2898
3839
|
code: "invalid_type",
|
|
3840
|
+
|
|
2899
3841
|
input,
|
|
2900
3842
|
inst,
|
|
2901
3843
|
});
|
|
@@ -2927,9 +3869,16 @@ export const $ZodTransform: core.$constructor<$ZodTransform> = /*@__PURE__*/ cor
|
|
|
2927
3869
|
"$ZodTransform",
|
|
2928
3870
|
(inst, def) => {
|
|
2929
3871
|
$ZodType.init(inst, def);
|
|
2930
|
-
inst._zod.
|
|
3872
|
+
inst._zod.optin = "optional";
|
|
3873
|
+
core.globalConfig.memoizer?.guard(inst);
|
|
3874
|
+
|
|
3875
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3876
|
+
if (ctx.direction === "backward") {
|
|
3877
|
+
throw new core.$ZodEncodeError(inst.constructor.name);
|
|
3878
|
+
}
|
|
3879
|
+
|
|
2931
3880
|
const _out = def.transform(payload.value, payload);
|
|
2932
|
-
if (
|
|
3881
|
+
if (ctx.async) {
|
|
2933
3882
|
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
|
|
2934
3883
|
return output.then((output) => {
|
|
2935
3884
|
payload.value = output;
|
|
@@ -2962,7 +3911,7 @@ export interface $ZodOptionalDef<T extends SomeType = $ZodType> extends $ZodType
|
|
|
2962
3911
|
export interface $ZodOptionalInternals<T extends SomeType = $ZodType>
|
|
2963
3912
|
extends $ZodTypeInternals<core.output<T> | undefined, core.input<T> | undefined> {
|
|
2964
3913
|
def: $ZodOptionalDef<T>;
|
|
2965
|
-
optin: "optional";
|
|
3914
|
+
optin: "optional" | "defaulted";
|
|
2966
3915
|
optout: "optional";
|
|
2967
3916
|
isst: never;
|
|
2968
3917
|
values: T["_zod"]["values"];
|
|
@@ -2973,33 +3922,84 @@ export interface $ZodOptional<T extends SomeType = $ZodType> extends $ZodType {
|
|
|
2973
3922
|
_zod: $ZodOptionalInternals<T>;
|
|
2974
3923
|
}
|
|
2975
3924
|
|
|
3925
|
+
function handleOptionalResult(payload: ParsePayload, result: ParsePayload) {
|
|
3926
|
+
// A substituting schema that still failed has no usable answer; yield undefined. Its issues are simply dropped: it ran on a payload of its own, so there is no shared array to truncate and nothing of the caller's to lose with it.
|
|
3927
|
+
payload.value = result.issues.length ? undefined : result.value;
|
|
3928
|
+
return payload;
|
|
3929
|
+
}
|
|
3930
|
+
|
|
2976
3931
|
export const $ZodOptional: core.$constructor<$ZodOptional> = /*@__PURE__*/ core.$constructor(
|
|
2977
3932
|
"$ZodOptional",
|
|
2978
3933
|
(inst, def) => {
|
|
2979
3934
|
$ZodType.init(inst, def);
|
|
2980
|
-
|
|
3935
|
+
// .optional() propagates absence rather than substituting for it, so a defaulted inner keeps its rung.
|
|
3936
|
+
util.defineLazyInternal(inst, "optin", (zod) =>
|
|
3937
|
+
zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional"
|
|
3938
|
+
);
|
|
2981
3939
|
inst._zod.optout = "optional";
|
|
2982
3940
|
|
|
2983
|
-
util.
|
|
2984
|
-
|
|
3941
|
+
util.defineLazyInternal(inst, "values", (zod) => {
|
|
3942
|
+
const values = (zod.def as $ZodOptionalDef).innerType._zod.values;
|
|
3943
|
+
return values ? new Set([...values, undefined]) : undefined;
|
|
2985
3944
|
});
|
|
2986
|
-
util.
|
|
2987
|
-
const pattern = def.innerType._zod.pattern;
|
|
3945
|
+
util.defineLazyInternal(inst, "pattern", (zod) => {
|
|
3946
|
+
const pattern = (zod.def as $ZodOptionalDef).innerType._zod.pattern;
|
|
2988
3947
|
return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)})?$`) : undefined;
|
|
2989
3948
|
});
|
|
2990
3949
|
|
|
2991
3950
|
inst._zod.parse = (payload, ctx) => {
|
|
2992
|
-
if (def.innerType._zod.optin === "optional") {
|
|
2993
|
-
return def.innerType._zod.run(payload, ctx);
|
|
2994
|
-
}
|
|
2995
3951
|
if (payload.value === undefined) {
|
|
2996
|
-
|
|
3952
|
+
// Only the top rung substitutes a value for absence; everything else leaves it intact, which is what .optional() means.
|
|
3953
|
+
if (def.innerType._zod.optin !== "defaulted") return payload;
|
|
3954
|
+
// Its own payload, for the same reason $ZodCatch gets one: a pipe forwards an unrecognized key through the caller's issues array, and this must not read that as the substituting schema failing and drop it.
|
|
3955
|
+
const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
|
|
3956
|
+
if (result instanceof Promise) return result.then((result) => handleOptionalResult(payload, result));
|
|
3957
|
+
return handleOptionalResult(payload, result);
|
|
2997
3958
|
}
|
|
2998
3959
|
return def.innerType._zod.run(payload, ctx);
|
|
2999
3960
|
};
|
|
3000
3961
|
}
|
|
3001
3962
|
);
|
|
3002
3963
|
|
|
3964
|
+
////////////////////////////////////////////////
|
|
3965
|
+
////////////////////////////////////////////////
|
|
3966
|
+
////////// //////////
|
|
3967
|
+
////////// $ZodExactOptional //////////
|
|
3968
|
+
////////// //////////
|
|
3969
|
+
////////////////////////////////////////////////
|
|
3970
|
+
////////////////////////////////////////////////
|
|
3971
|
+
|
|
3972
|
+
// Def extends $ZodOptionalDef (no additional fields needed)
|
|
3973
|
+
export interface $ZodExactOptionalDef<T extends SomeType = $ZodType> extends $ZodOptionalDef<T> {}
|
|
3974
|
+
|
|
3975
|
+
// Internals extends $ZodOptionalInternals but narrows output/input types (removes | undefined)
|
|
3976
|
+
export interface $ZodExactOptionalInternals<T extends SomeType = $ZodType> extends $ZodOptionalInternals<T> {
|
|
3977
|
+
def: $ZodExactOptionalDef<T>;
|
|
3978
|
+
output: core.output<T>; // NO | undefined (narrowed from parent)
|
|
3979
|
+
input: core.input<T>; // NO | undefined (narrowed from parent)
|
|
3980
|
+
}
|
|
3981
|
+
|
|
3982
|
+
export interface $ZodExactOptional<T extends SomeType = $ZodType> extends $ZodType {
|
|
3983
|
+
_zod: $ZodExactOptionalInternals<T>;
|
|
3984
|
+
}
|
|
3985
|
+
|
|
3986
|
+
export const $ZodExactOptional: core.$constructor<$ZodExactOptional> = /*@__PURE__*/ core.$constructor(
|
|
3987
|
+
"$ZodExactOptional",
|
|
3988
|
+
(inst, def) => {
|
|
3989
|
+
// Call parent init - inherits optin/optout = "optional"
|
|
3990
|
+
$ZodOptional.init(inst, def);
|
|
3991
|
+
|
|
3992
|
+
// Override values/pattern to NOT add undefined
|
|
3993
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
3994
|
+
util.defineLazyInternal(inst, "pattern", (zod) => zod.def.innerType._zod.pattern);
|
|
3995
|
+
|
|
3996
|
+
// Override parse to just delegate (no undefined handling)
|
|
3997
|
+
inst._zod.parse = (payload, ctx) => {
|
|
3998
|
+
return def.innerType._zod.run(payload, ctx);
|
|
3999
|
+
};
|
|
4000
|
+
}
|
|
4001
|
+
);
|
|
4002
|
+
|
|
3003
4003
|
////////////////////////////////////////////
|
|
3004
4004
|
////////////////////////////////////////////
|
|
3005
4005
|
////////// //////////
|
|
@@ -3030,19 +4030,20 @@ export const $ZodNullable: core.$constructor<$ZodNullable> = /*@__PURE__*/ core.
|
|
|
3030
4030
|
"$ZodNullable",
|
|
3031
4031
|
(inst, def) => {
|
|
3032
4032
|
$ZodType.init(inst, def);
|
|
3033
|
-
util.
|
|
3034
|
-
util.
|
|
4033
|
+
util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin);
|
|
4034
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
|
|
3035
4035
|
|
|
3036
|
-
util.
|
|
3037
|
-
const pattern = def.innerType._zod.pattern;
|
|
4036
|
+
util.defineLazyInternal(inst, "pattern", (zod) => {
|
|
4037
|
+
const pattern = zod.def.innerType._zod.pattern;
|
|
3038
4038
|
return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)}|null)$`) : undefined;
|
|
3039
4039
|
});
|
|
3040
4040
|
|
|
3041
|
-
util.
|
|
3042
|
-
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
|
|
4041
|
+
util.defineLazyInternal(inst, "values", (zod) => {
|
|
4042
|
+
return zod.def.innerType._zod.values ? new Set([...zod.def.innerType._zod.values, null]) : undefined;
|
|
3043
4043
|
});
|
|
3044
4044
|
|
|
3045
4045
|
inst._zod.parse = (payload, ctx) => {
|
|
4046
|
+
// Forward direction (decode): allow null to pass through
|
|
3046
4047
|
if (payload.value === null) return payload;
|
|
3047
4048
|
return def.innerType._zod.run(payload, ctx);
|
|
3048
4049
|
};
|
|
@@ -3067,7 +4068,7 @@ export interface $ZodDefaultDef<T extends SomeType = $ZodType> extends $ZodTypeD
|
|
|
3067
4068
|
export interface $ZodDefaultInternals<T extends SomeType = $ZodType>
|
|
3068
4069
|
extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
|
|
3069
4070
|
def: $ZodDefaultDef<T>;
|
|
3070
|
-
optin: "
|
|
4071
|
+
optin: "defaulted";
|
|
3071
4072
|
optout?: "optional" | undefined; // required
|
|
3072
4073
|
isst: never;
|
|
3073
4074
|
values: T["_zod"]["values"];
|
|
@@ -3083,17 +4084,23 @@ export const $ZodDefault: core.$constructor<$ZodDefault> = /*@__PURE__*/ core.$c
|
|
|
3083
4084
|
$ZodType.init(inst, def);
|
|
3084
4085
|
|
|
3085
4086
|
// inst._zod.qin = "true";
|
|
3086
|
-
inst._zod.optin = "
|
|
3087
|
-
util.
|
|
4087
|
+
inst._zod.optin = "defaulted";
|
|
4088
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
3088
4089
|
|
|
3089
4090
|
inst._zod.parse = (payload, ctx) => {
|
|
4091
|
+
if (ctx.direction === "backward") {
|
|
4092
|
+
return def.innerType._zod.run(payload, ctx);
|
|
4093
|
+
}
|
|
4094
|
+
|
|
4095
|
+
// Forward direction (decode): apply defaults for undefined input
|
|
3090
4096
|
if (payload.value === undefined) {
|
|
3091
4097
|
payload.value = def.defaultValue;
|
|
3092
4098
|
/**
|
|
3093
|
-
* $ZodDefault
|
|
4099
|
+
* $ZodDefault returns the default value immediately in forward direction.
|
|
3094
4100
|
* It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
|
|
3095
4101
|
return payload;
|
|
3096
4102
|
}
|
|
4103
|
+
// Forward direction: continue with default handling
|
|
3097
4104
|
const result = def.innerType._zod.run(payload, ctx);
|
|
3098
4105
|
if (result instanceof Promise) {
|
|
3099
4106
|
return result.then((result) => handleDefaultResult(result, def));
|
|
@@ -3126,9 +4133,9 @@ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodType
|
|
|
3126
4133
|
}
|
|
3127
4134
|
|
|
3128
4135
|
export interface $ZodPrefaultInternals<T extends SomeType = $ZodType>
|
|
3129
|
-
extends $ZodTypeInternals<
|
|
4136
|
+
extends $ZodTypeInternals<core.output<T>, core.input<T> | undefined> {
|
|
3130
4137
|
def: $ZodPrefaultDef<T>;
|
|
3131
|
-
optin: "
|
|
4138
|
+
optin: "defaulted";
|
|
3132
4139
|
optout?: "optional" | undefined;
|
|
3133
4140
|
isst: never;
|
|
3134
4141
|
values: T["_zod"]["values"];
|
|
@@ -3143,10 +4150,15 @@ export const $ZodPrefault: core.$constructor<$ZodPrefault> = /*@__PURE__*/ core.
|
|
|
3143
4150
|
(inst, def) => {
|
|
3144
4151
|
$ZodType.init(inst, def);
|
|
3145
4152
|
|
|
3146
|
-
inst._zod.optin = "
|
|
3147
|
-
util.
|
|
4153
|
+
inst._zod.optin = "defaulted";
|
|
4154
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
3148
4155
|
|
|
3149
4156
|
inst._zod.parse = (payload, ctx) => {
|
|
4157
|
+
if (ctx.direction === "backward") {
|
|
4158
|
+
return def.innerType._zod.run(payload, ctx);
|
|
4159
|
+
}
|
|
4160
|
+
|
|
4161
|
+
// Forward direction (decode): apply prefault for undefined input
|
|
3150
4162
|
if (payload.value === undefined) {
|
|
3151
4163
|
payload.value = def.defaultValue;
|
|
3152
4164
|
}
|
|
@@ -3185,8 +4197,8 @@ export const $ZodNonOptional: core.$constructor<$ZodNonOptional> = /*@__PURE__*/
|
|
|
3185
4197
|
(inst, def) => {
|
|
3186
4198
|
$ZodType.init(inst, def);
|
|
3187
4199
|
|
|
3188
|
-
util.
|
|
3189
|
-
const v = def.innerType._zod.values;
|
|
4200
|
+
util.defineLazyInternal(inst, "values", (zod) => {
|
|
4201
|
+
const v = zod.def.innerType._zod.values;
|
|
3190
4202
|
return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
|
|
3191
4203
|
});
|
|
3192
4204
|
|
|
@@ -3281,6 +4293,10 @@ export const $ZodSuccess: core.$constructor<$ZodSuccess> = /*@__PURE__*/ core.$c
|
|
|
3281
4293
|
$ZodType.init(inst, def);
|
|
3282
4294
|
|
|
3283
4295
|
inst._zod.parse = (payload, ctx) => {
|
|
4296
|
+
if (ctx.direction === "backward") {
|
|
4297
|
+
throw new core.$ZodEncodeError("ZodSuccess");
|
|
4298
|
+
}
|
|
4299
|
+
|
|
3284
4300
|
const result = def.innerType._zod.run(payload, ctx);
|
|
3285
4301
|
if (result instanceof Promise) {
|
|
3286
4302
|
return result.then((result) => {
|
|
@@ -3314,11 +4330,8 @@ export interface $ZodCatchDef<T extends SomeType = $ZodType> extends $ZodTypeDef
|
|
|
3314
4330
|
}
|
|
3315
4331
|
|
|
3316
4332
|
export interface $ZodCatchInternals<T extends SomeType = $ZodType>
|
|
3317
|
-
extends $ZodTypeInternals<core.output<T>, core.input<T
|
|
4333
|
+
extends $ZodTypeInternals<core.output<T>, core.input<T>> {
|
|
3318
4334
|
def: $ZodCatchDef<T>;
|
|
3319
|
-
// qin: T["_zod"]["qin"];
|
|
3320
|
-
// qout: T["_zod"]["qout"];
|
|
3321
|
-
|
|
3322
4335
|
optin: T["_zod"]["optin"];
|
|
3323
4336
|
optout: T["_zod"]["optout"];
|
|
3324
4337
|
isst: never;
|
|
@@ -3329,45 +4342,46 @@ export interface $ZodCatch<T extends SomeType = $ZodType> extends $ZodType {
|
|
|
3329
4342
|
_zod: $ZodCatchInternals<T>;
|
|
3330
4343
|
}
|
|
3331
4344
|
|
|
4345
|
+
function handleCatchResult(payload: ParsePayload, result: ParsePayload, def: $ZodCatchDef, ctx: ParseContextInternal) {
|
|
4346
|
+
if (!result.issues.length) {
|
|
4347
|
+
payload.value = result.value;
|
|
4348
|
+
// The value carries up, so the flag describing it has to carry with it: a back-edge into a node still being parsed must not be frozen by an enclosing readonly, and its checks belong to the node itself. Guarded so the ordinary case adds no own property.
|
|
4349
|
+
if (result.memo) payload.memo = true;
|
|
4350
|
+
return payload;
|
|
4351
|
+
}
|
|
4352
|
+
|
|
4353
|
+
// Spread the inner's own payload, not ours: `value` has to stay the input the catch was handed, and the inner ran on a payload of its own so its issues are already private to this call.
|
|
4354
|
+
payload.value = def.catchValue({
|
|
4355
|
+
...result,
|
|
4356
|
+
value: payload.value,
|
|
4357
|
+
error: {
|
|
4358
|
+
issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
|
4359
|
+
},
|
|
4360
|
+
input: payload.value,
|
|
4361
|
+
});
|
|
4362
|
+
return payload;
|
|
4363
|
+
}
|
|
4364
|
+
|
|
3332
4365
|
export const $ZodCatch: core.$constructor<$ZodCatch> = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
|
|
3333
4366
|
$ZodType.init(inst, def);
|
|
3334
|
-
inst
|
|
3335
|
-
|
|
3336
|
-
|
|
4367
|
+
util.defineLazyInternal(inst, "optin", (zod) =>
|
|
4368
|
+
zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional"
|
|
4369
|
+
);
|
|
4370
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
|
|
4371
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
3337
4372
|
|
|
3338
4373
|
inst._zod.parse = (payload, ctx) => {
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
return result.then((result) => {
|
|
3342
|
-
payload.value = result.value;
|
|
3343
|
-
if (result.issues.length) {
|
|
3344
|
-
payload.value = def.catchValue({
|
|
3345
|
-
...payload,
|
|
3346
|
-
error: {
|
|
3347
|
-
issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
|
3348
|
-
},
|
|
3349
|
-
input: payload.value,
|
|
3350
|
-
});
|
|
3351
|
-
payload.issues = [];
|
|
3352
|
-
}
|
|
3353
|
-
|
|
3354
|
-
return payload;
|
|
3355
|
-
});
|
|
4374
|
+
if (ctx.direction === "backward") {
|
|
4375
|
+
return def.innerType._zod.run(payload, ctx);
|
|
3356
4376
|
}
|
|
3357
4377
|
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
error: {
|
|
3363
|
-
issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
|
3364
|
-
},
|
|
3365
|
-
input: payload.value,
|
|
3366
|
-
});
|
|
3367
|
-
payload.issues = [];
|
|
4378
|
+
// Forward direction (decode): apply catch logic
|
|
4379
|
+
const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
|
|
4380
|
+
if (result instanceof Promise) {
|
|
4381
|
+
return result.then((result) => handleCatchResult(payload, result, def, ctx));
|
|
3368
4382
|
}
|
|
3369
4383
|
|
|
3370
|
-
return payload;
|
|
4384
|
+
return handleCatchResult(payload, result, def, ctx);
|
|
3371
4385
|
};
|
|
3372
4386
|
});
|
|
3373
4387
|
|
|
@@ -3419,6 +4433,10 @@ export interface $ZodPipeDef<A extends SomeType = $ZodType, B extends SomeType =
|
|
|
3419
4433
|
type: "pipe";
|
|
3420
4434
|
in: A;
|
|
3421
4435
|
out: B;
|
|
4436
|
+
/** Only defined inside $ZodCodec instances. */
|
|
4437
|
+
transform?: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
|
4438
|
+
/** Only defined inside $ZodCodec instances. */
|
|
4439
|
+
reverseTransform?: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
|
3422
4440
|
}
|
|
3423
4441
|
|
|
3424
4442
|
export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType>
|
|
@@ -3428,6 +4446,7 @@ export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends Some
|
|
|
3428
4446
|
values: A["_zod"]["values"];
|
|
3429
4447
|
optin: A["_zod"]["optin"];
|
|
3430
4448
|
optout: B["_zod"]["optout"];
|
|
4449
|
+
propValues: A["_zod"]["propValues"];
|
|
3431
4450
|
}
|
|
3432
4451
|
|
|
3433
4452
|
export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
|
@@ -3436,26 +4455,155 @@ export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $Z
|
|
|
3436
4455
|
|
|
3437
4456
|
export const $ZodPipe: core.$constructor<$ZodPipe> = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def) => {
|
|
3438
4457
|
$ZodType.init(inst, def);
|
|
3439
|
-
util.
|
|
3440
|
-
util.
|
|
3441
|
-
util.
|
|
4458
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
|
|
4459
|
+
util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
|
|
4460
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
|
|
4461
|
+
util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
|
|
3442
4462
|
|
|
3443
4463
|
inst._zod.parse = (payload, ctx) => {
|
|
4464
|
+
if (ctx.direction === "backward") {
|
|
4465
|
+
const right = def.out._zod.run(payload, ctx);
|
|
4466
|
+
if (right instanceof Promise) {
|
|
4467
|
+
return right.then((right) => handlePipeResult(right, def.in, ctx));
|
|
4468
|
+
}
|
|
4469
|
+
return handlePipeResult(right, def.in, ctx);
|
|
4470
|
+
}
|
|
4471
|
+
|
|
3444
4472
|
const left = def.in._zod.run(payload, ctx);
|
|
3445
4473
|
if (left instanceof Promise) {
|
|
3446
|
-
return left.then((left) => handlePipeResult(left, def, ctx));
|
|
4474
|
+
return left.then((left) => handlePipeResult(left, def.out, ctx));
|
|
3447
4475
|
}
|
|
3448
|
-
return handlePipeResult(left, def, ctx);
|
|
4476
|
+
return handlePipeResult(left, def.out, ctx);
|
|
3449
4477
|
};
|
|
3450
4478
|
});
|
|
3451
4479
|
|
|
3452
|
-
function handlePipeResult(left: ParsePayload,
|
|
3453
|
-
|
|
4480
|
+
function handlePipeResult(left: ParsePayload, next: $ZodType, ctx: ParseContextInternal) {
|
|
4481
|
+
// Any issue stops the pipe, so a failing refinement never feeds its transform. An unrecognized key is the exception: it describes the input's extra properties, not the value being piped, and an enclosing intersection may yet reconcile it.
|
|
4482
|
+
if (left.issues.some((iss) => iss.code !== "unrecognized_keys")) {
|
|
4483
|
+
// prevent further checks
|
|
4484
|
+
left.aborted = true;
|
|
3454
4485
|
return left;
|
|
3455
4486
|
}
|
|
3456
|
-
return
|
|
4487
|
+
return next._zod.run({ value: left.value, issues: left.issues }, ctx);
|
|
3457
4488
|
}
|
|
3458
4489
|
|
|
4490
|
+
////////////////////////////////////////////
|
|
4491
|
+
////////////////////////////////////////////
|
|
4492
|
+
////////// //////////
|
|
4493
|
+
////////// $ZodCodec //////////
|
|
4494
|
+
////////// //////////
|
|
4495
|
+
////////////////////////////////////////////
|
|
4496
|
+
////////////////////////////////////////////
|
|
4497
|
+
export interface $ZodCodecDef<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodPipeDef<A, B> {
|
|
4498
|
+
transform: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
|
4499
|
+
reverseTransform: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
|
4500
|
+
}
|
|
4501
|
+
|
|
4502
|
+
export interface $ZodCodecInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType>
|
|
4503
|
+
extends $ZodTypeInternals<core.output<B>, core.input<A>> {
|
|
4504
|
+
def: $ZodCodecDef<A, B>;
|
|
4505
|
+
isst: never;
|
|
4506
|
+
values: A["_zod"]["values"];
|
|
4507
|
+
optin: A["_zod"]["optin"];
|
|
4508
|
+
optout: B["_zod"]["optout"];
|
|
4509
|
+
propValues: A["_zod"]["propValues"];
|
|
4510
|
+
}
|
|
4511
|
+
|
|
4512
|
+
export interface $ZodCodec<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
|
4513
|
+
_zod: $ZodCodecInternals<A, B>;
|
|
4514
|
+
}
|
|
4515
|
+
|
|
4516
|
+
export const $ZodCodec: core.$constructor<$ZodCodec> = /*@__PURE__*/ core.$constructor("$ZodCodec", (inst, def) => {
|
|
4517
|
+
$ZodType.init(inst, def);
|
|
4518
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
|
|
4519
|
+
util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
|
|
4520
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
|
|
4521
|
+
util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
|
|
4522
|
+
|
|
4523
|
+
inst._zod.parse = (payload, ctx) => {
|
|
4524
|
+
const direction = ctx.direction || "forward";
|
|
4525
|
+
if (direction === "forward") {
|
|
4526
|
+
const left = def.in._zod.run(payload, ctx);
|
|
4527
|
+
if (left instanceof Promise) {
|
|
4528
|
+
return left.then((left) => handleCodecAResult(left, def, ctx));
|
|
4529
|
+
}
|
|
4530
|
+
return handleCodecAResult(left, def, ctx);
|
|
4531
|
+
} else {
|
|
4532
|
+
const right = def.out._zod.run(payload, ctx);
|
|
4533
|
+
if (right instanceof Promise) {
|
|
4534
|
+
return right.then((right) => handleCodecAResult(right, def, ctx));
|
|
4535
|
+
}
|
|
4536
|
+
return handleCodecAResult(right, def, ctx);
|
|
4537
|
+
}
|
|
4538
|
+
};
|
|
4539
|
+
});
|
|
4540
|
+
|
|
4541
|
+
function handleCodecAResult(result: ParsePayload, def: $ZodCodecDef, ctx: ParseContextInternal) {
|
|
4542
|
+
if (result.issues.length) {
|
|
4543
|
+
// prevent further checks
|
|
4544
|
+
result.aborted = true;
|
|
4545
|
+
return result;
|
|
4546
|
+
}
|
|
4547
|
+
|
|
4548
|
+
const direction = ctx.direction || "forward";
|
|
4549
|
+
|
|
4550
|
+
if (direction === "forward") {
|
|
4551
|
+
const transformed = def.transform(result.value, result);
|
|
4552
|
+
if (transformed instanceof Promise) {
|
|
4553
|
+
return transformed.then((value) => handleCodecTxResult(result, value, def.out, ctx));
|
|
4554
|
+
}
|
|
4555
|
+
return handleCodecTxResult(result, transformed, def.out, ctx);
|
|
4556
|
+
} else {
|
|
4557
|
+
const transformed = def.reverseTransform(result.value, result);
|
|
4558
|
+
if (transformed instanceof Promise) {
|
|
4559
|
+
return transformed.then((value) => handleCodecTxResult(result, value, def.in, ctx));
|
|
4560
|
+
}
|
|
4561
|
+
return handleCodecTxResult(result, transformed, def.in, ctx);
|
|
4562
|
+
}
|
|
4563
|
+
}
|
|
4564
|
+
|
|
4565
|
+
function handleCodecTxResult(left: ParsePayload, value: any, nextSchema: SomeType, ctx: ParseContextInternal) {
|
|
4566
|
+
// Check if transform added any issues
|
|
4567
|
+
if (left.issues.length) {
|
|
4568
|
+
left.aborted = true;
|
|
4569
|
+
return left;
|
|
4570
|
+
}
|
|
4571
|
+
|
|
4572
|
+
return nextSchema._zod.run({ value, issues: left.issues }, ctx);
|
|
4573
|
+
}
|
|
4574
|
+
|
|
4575
|
+
/////////////////////////////////////////////////
|
|
4576
|
+
/////////////////////////////////////////////////
|
|
4577
|
+
////////// //////////
|
|
4578
|
+
////////// $ZodPreprocess //////////
|
|
4579
|
+
////////// //////////
|
|
4580
|
+
/////////////////////////////////////////////////
|
|
4581
|
+
/////////////////////////////////////////////////
|
|
4582
|
+
export interface $ZodPreprocessDef<B extends SomeType = $ZodType, I = unknown>
|
|
4583
|
+
extends $ZodPipeDef<$ZodTransform<unknown, I>, B> {
|
|
4584
|
+
in: $ZodTransform<unknown, I>;
|
|
4585
|
+
out: B;
|
|
4586
|
+
}
|
|
4587
|
+
|
|
4588
|
+
export interface $ZodPreprocessInternals<B extends SomeType = $ZodType, I = unknown>
|
|
4589
|
+
extends $ZodPipeInternals<$ZodTransform<unknown, I>, B> {
|
|
4590
|
+
def: $ZodPreprocessDef<B, I>;
|
|
4591
|
+
optin: B["_zod"]["optin"];
|
|
4592
|
+
optout: B["_zod"]["optout"];
|
|
4593
|
+
}
|
|
4594
|
+
|
|
4595
|
+
export interface $ZodPreprocess<B extends SomeType = $ZodType, I = unknown>
|
|
4596
|
+
extends $ZodPipe<$ZodTransform<unknown, I>, B> {
|
|
4597
|
+
_zod: $ZodPreprocessInternals<B, I>;
|
|
4598
|
+
}
|
|
4599
|
+
|
|
4600
|
+
export const $ZodPreprocess: core.$constructor<$ZodPreprocess> = /*@__PURE__*/ core.$constructor(
|
|
4601
|
+
"$ZodPreprocess",
|
|
4602
|
+
(inst, def) => {
|
|
4603
|
+
$ZodPipe.init(inst, def);
|
|
4604
|
+
}
|
|
4605
|
+
);
|
|
4606
|
+
|
|
3459
4607
|
////////////////////////////////////////////
|
|
3460
4608
|
////////////////////////////////////////////
|
|
3461
4609
|
////////// //////////
|
|
@@ -3487,12 +4635,15 @@ export const $ZodReadonly: core.$constructor<$ZodReadonly> = /*@__PURE__*/ core.
|
|
|
3487
4635
|
"$ZodReadonly",
|
|
3488
4636
|
(inst, def) => {
|
|
3489
4637
|
$ZodType.init(inst, def);
|
|
3490
|
-
util.
|
|
3491
|
-
util.
|
|
3492
|
-
util.
|
|
3493
|
-
util.
|
|
4638
|
+
util.defineLazyInternal(inst, "propValues", (zod) => zod.def.innerType._zod.propValues);
|
|
4639
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
4640
|
+
util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType?._zod?.optin);
|
|
4641
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType?._zod?.optout);
|
|
3494
4642
|
|
|
3495
4643
|
inst._zod.parse = (payload, ctx) => {
|
|
4644
|
+
if (ctx.direction === "backward") {
|
|
4645
|
+
return def.innerType._zod.run(payload, ctx);
|
|
4646
|
+
}
|
|
3496
4647
|
const result = def.innerType._zod.run(payload, ctx);
|
|
3497
4648
|
if (result instanceof Promise) {
|
|
3498
4649
|
return result.then(handleReadonlyResult);
|
|
@@ -3503,7 +4654,8 @@ export const $ZodReadonly: core.$constructor<$ZodReadonly> = /*@__PURE__*/ core.
|
|
|
3503
4654
|
);
|
|
3504
4655
|
|
|
3505
4656
|
function handleReadonlyResult(payload: ParsePayload): ParsePayload {
|
|
3506
|
-
|
|
4657
|
+
// A repeat visit hands back a node that is still being built; freezing it here would make the rest of its keys fail to assign.
|
|
4658
|
+
if (!payload.memo) payload.value = Object.freeze(payload.value);
|
|
3507
4659
|
return payload;
|
|
3508
4660
|
}
|
|
3509
4661
|
|
|
@@ -3518,6 +4670,7 @@ function handleReadonlyResult(payload: ParsePayload): ParsePayload {
|
|
|
3518
4670
|
export interface $ZodTemplateLiteralDef extends $ZodTypeDef {
|
|
3519
4671
|
type: "template_literal";
|
|
3520
4672
|
parts: $ZodTemplateLiteralPart[];
|
|
4673
|
+
format?: string | undefined;
|
|
3521
4674
|
}
|
|
3522
4675
|
export interface $ZodTemplateLiteralInternals<Template extends string = string>
|
|
3523
4676
|
extends $ZodTypeInternals<Template, Template> {
|
|
@@ -3579,25 +4732,64 @@ export type $PartsToTemplateLiteral<Parts extends $ZodTemplateLiteralPart[]> = [
|
|
|
3579
4732
|
: never
|
|
3580
4733
|
: never;
|
|
3581
4734
|
|
|
4735
|
+
// a leaf's pattern source with its own checks folded in: the last pattern-carrying check wins, else length bounds narrow the catch-all, else an integer format narrows the number form. the fold lives here instead of on `_zod.pattern` so a bundle without template literals never pays for it
|
|
4736
|
+
function leafPattern(schema: $ZodType): string | undefined {
|
|
4737
|
+
const def = schema._zod.def as { pattern?: RegExp; format?: string; checks?: checks.$ZodCheck[] };
|
|
4738
|
+
let pattern = def.pattern;
|
|
4739
|
+
let isInt = !!def.format?.includes("int");
|
|
4740
|
+
let minimum: number | undefined;
|
|
4741
|
+
let maximum: number | undefined;
|
|
4742
|
+
for (const ch of def.checks ?? []) {
|
|
4743
|
+
const d = ch._zod.def as { pattern?: RegExp; format?: string; minimum?: number; maximum?: number; length?: number };
|
|
4744
|
+
if (d.pattern) pattern = d.pattern;
|
|
4745
|
+
isInt ||= !!d.format?.includes("int");
|
|
4746
|
+
const lo = d.minimum ?? d.length;
|
|
4747
|
+
const hi = d.maximum ?? d.length;
|
|
4748
|
+
if (lo !== undefined && (minimum === undefined || lo > minimum)) minimum = lo;
|
|
4749
|
+
if (hi !== undefined && (maximum === undefined || hi < maximum)) maximum = hi;
|
|
4750
|
+
}
|
|
4751
|
+
if (pattern) return pattern.source;
|
|
4752
|
+
// an empty range matches nothing at runtime, and `{8,5}` is not a legal quantifier
|
|
4753
|
+
if (minimum !== undefined && maximum !== undefined && minimum > maximum) return "(?!)";
|
|
4754
|
+
if (minimum !== undefined || maximum !== undefined) return regexes.string({ minimum, maximum }).source;
|
|
4755
|
+
const own = schema._zod.pattern;
|
|
4756
|
+
return (isInt && own === regexes.number ? regexes.integer : own)?.source;
|
|
4757
|
+
}
|
|
4758
|
+
|
|
4759
|
+
// a part's pattern source. a wrapper's pattern embeds its inner pattern's source verbatim, so the folded form is substituted in place without knowing the wrapper's own composition; a union's options are joined the way the union builds its own pattern
|
|
4760
|
+
function partPattern(schema: $ZodType): string | undefined {
|
|
4761
|
+
const def = schema._zod.def as { innerType?: $ZodType; options?: $ZodType[] };
|
|
4762
|
+
const own = schema._zod.pattern?.source;
|
|
4763
|
+
// lazy resolves its inner on the internals, not the def
|
|
4764
|
+
const inner = def.innerType ?? (schema._zod as { innerType?: $ZodType }).innerType;
|
|
4765
|
+
if (inner) {
|
|
4766
|
+
const before = inner._zod.pattern?.source;
|
|
4767
|
+
const after = partPattern(inner);
|
|
4768
|
+
if (own && before && after && after !== before) {
|
|
4769
|
+
return own.replace(util.cleanRegex(before), () => util.cleanRegex(after));
|
|
4770
|
+
}
|
|
4771
|
+
return own;
|
|
4772
|
+
}
|
|
4773
|
+
if (def.options) {
|
|
4774
|
+
const sources = def.options.map(partPattern);
|
|
4775
|
+
if (sources.every(Boolean)) return `^(${sources.map((s) => util.cleanRegex(s!)).join("|")})$`;
|
|
4776
|
+
}
|
|
4777
|
+
return leafPattern(schema);
|
|
4778
|
+
}
|
|
4779
|
+
|
|
3582
4780
|
export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__PURE__*/ core.$constructor(
|
|
3583
4781
|
"$ZodTemplateLiteral",
|
|
3584
4782
|
(inst, def) => {
|
|
3585
4783
|
$ZodType.init(inst, def);
|
|
3586
4784
|
const regexParts: string[] = [];
|
|
3587
4785
|
for (const part of def.parts) {
|
|
3588
|
-
if (part
|
|
3589
|
-
|
|
3590
|
-
|
|
4786
|
+
if (typeof part === "object" && part !== null) {
|
|
4787
|
+
// is Zod schema
|
|
4788
|
+
const source = partPattern(part);
|
|
4789
|
+
if (!source) {
|
|
3591
4790
|
throw new Error(`Invalid template literal part, no pattern found: ${[...(part as any)._zod.traits].shift()}`);
|
|
3592
4791
|
}
|
|
3593
|
-
|
|
3594
|
-
const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;
|
|
3595
|
-
|
|
3596
|
-
if (!source) throw new Error(`Invalid template literal part: ${part._zod.traits}`);
|
|
3597
|
-
|
|
3598
|
-
const start = source.startsWith("^") ? 1 : 0;
|
|
3599
|
-
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
3600
|
-
regexParts.push(source.slice(start, end));
|
|
4792
|
+
regexParts.push(util.cleanRegex(source));
|
|
3601
4793
|
} else if (part === null || util.primitiveTypes.has(typeof part)) {
|
|
3602
4794
|
regexParts.push(util.escapeRegex(`${part}`));
|
|
3603
4795
|
} else {
|
|
@@ -3611,7 +4803,7 @@ export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__
|
|
|
3611
4803
|
payload.issues.push({
|
|
3612
4804
|
input: payload.value,
|
|
3613
4805
|
inst,
|
|
3614
|
-
expected: "
|
|
4806
|
+
expected: "string",
|
|
3615
4807
|
code: "invalid_type",
|
|
3616
4808
|
});
|
|
3617
4809
|
return payload;
|
|
@@ -3623,8 +4815,9 @@ export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__
|
|
|
3623
4815
|
payload.issues.push({
|
|
3624
4816
|
input: payload.value,
|
|
3625
4817
|
inst,
|
|
4818
|
+
|
|
3626
4819
|
code: "invalid_format",
|
|
3627
|
-
format: "template_literal",
|
|
4820
|
+
format: def.format ?? "template_literal",
|
|
3628
4821
|
pattern: inst._zod.pattern.source,
|
|
3629
4822
|
});
|
|
3630
4823
|
return payload;
|
|
@@ -3635,6 +4828,184 @@ export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__
|
|
|
3635
4828
|
}
|
|
3636
4829
|
);
|
|
3637
4830
|
|
|
4831
|
+
//////////////////////////////////////////
|
|
4832
|
+
//////////////////////////////////////////
|
|
4833
|
+
////////// //////////
|
|
4834
|
+
////////// $ZodFunction //////////
|
|
4835
|
+
////////// //////////
|
|
4836
|
+
//////////////////////////////////////////
|
|
4837
|
+
//////////////////////////////////////////
|
|
4838
|
+
export type $ZodFunctionArgs = $ZodType<unknown[], unknown[]>;
|
|
4839
|
+
export type $ZodFunctionIn = $ZodFunctionArgs;
|
|
4840
|
+
export type $ZodFunctionOut = $ZodType;
|
|
4841
|
+
|
|
4842
|
+
export type $InferInnerFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (
|
|
4843
|
+
...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>
|
|
4844
|
+
) => core.input<Returns>;
|
|
4845
|
+
|
|
4846
|
+
export type $InferInnerFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (
|
|
4847
|
+
...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>
|
|
4848
|
+
) => util.MaybeAsync<core.input<Returns>>;
|
|
4849
|
+
|
|
4850
|
+
export type $InferOuterFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (
|
|
4851
|
+
...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>
|
|
4852
|
+
) => core.output<Returns>;
|
|
4853
|
+
|
|
4854
|
+
export type $InferOuterFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (
|
|
4855
|
+
...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>
|
|
4856
|
+
) => Promise<core.output<Returns>>;
|
|
4857
|
+
|
|
4858
|
+
export interface $ZodFunctionDef<
|
|
4859
|
+
In extends $ZodFunctionIn = $ZodFunctionIn,
|
|
4860
|
+
Out extends $ZodFunctionOut = $ZodFunctionOut,
|
|
4861
|
+
> extends $ZodTypeDef {
|
|
4862
|
+
type: "function";
|
|
4863
|
+
input: In;
|
|
4864
|
+
output: Out;
|
|
4865
|
+
}
|
|
4866
|
+
|
|
4867
|
+
export interface $ZodFunctionInternals<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut>
|
|
4868
|
+
extends $ZodTypeInternals<$InferOuterFunctionType<Args, Returns>, $InferInnerFunctionType<Args, Returns>> {
|
|
4869
|
+
def: $ZodFunctionDef<Args, Returns>;
|
|
4870
|
+
isst: errors.$ZodIssueInvalidType;
|
|
4871
|
+
}
|
|
4872
|
+
|
|
4873
|
+
export interface $ZodFunction<
|
|
4874
|
+
Args extends $ZodFunctionIn = $ZodFunctionIn,
|
|
4875
|
+
Returns extends $ZodFunctionOut = $ZodFunctionOut,
|
|
4876
|
+
> extends $ZodType<any, any, $ZodFunctionInternals<Args, Returns>> {
|
|
4877
|
+
/** @deprecated */
|
|
4878
|
+
_def: $ZodFunctionDef<Args, Returns>;
|
|
4879
|
+
_input: $InferInnerFunctionType<Args, Returns>;
|
|
4880
|
+
_output: $InferOuterFunctionType<Args, Returns>;
|
|
4881
|
+
|
|
4882
|
+
implement<F extends $InferInnerFunctionType<Args, Returns>>(
|
|
4883
|
+
func: F
|
|
4884
|
+
): // allow for return type inference
|
|
4885
|
+
(
|
|
4886
|
+
...args: Parameters<this["_output"]>
|
|
4887
|
+
) => ReturnType<F> extends ReturnType<this["_output"]> ? ReturnType<F> : ReturnType<this["_output"]>;
|
|
4888
|
+
|
|
4889
|
+
implementAsync<F extends $InferInnerFunctionTypeAsync<Args, Returns>>(
|
|
4890
|
+
func: F
|
|
4891
|
+
): F extends $InferOuterFunctionTypeAsync<Args, Returns> ? F : $InferOuterFunctionTypeAsync<Args, Returns>;
|
|
4892
|
+
|
|
4893
|
+
input<const Items extends util.TupleItems, const Rest extends $ZodFunctionOut = $ZodFunctionOut>(
|
|
4894
|
+
args: Items,
|
|
4895
|
+
rest?: Rest
|
|
4896
|
+
): $ZodFunction<$ZodTuple<Items, Rest>, Returns>;
|
|
4897
|
+
input<NewArgs extends $ZodFunctionIn>(args: NewArgs): $ZodFunction<NewArgs, Returns>;
|
|
4898
|
+
input(...args: any[]): $ZodFunction<any, Returns>;
|
|
4899
|
+
|
|
4900
|
+
output<NewReturns extends $ZodType>(output: NewReturns): $ZodFunction<Args, NewReturns>;
|
|
4901
|
+
}
|
|
4902
|
+
|
|
4903
|
+
export interface $ZodFunctionParams<I extends $ZodFunctionIn, O extends $ZodType> {
|
|
4904
|
+
input?: I;
|
|
4905
|
+
output?: O;
|
|
4906
|
+
}
|
|
4907
|
+
|
|
4908
|
+
export const $ZodFunction: core.$constructor<$ZodFunction> = /*@__PURE__*/ core.$constructor(
|
|
4909
|
+
"$ZodFunction",
|
|
4910
|
+
(inst, def) => {
|
|
4911
|
+
$ZodType.init(inst, def);
|
|
4912
|
+
// Defined, not assigned: the classic prototype exposes `_def` as a getter with no setter.
|
|
4913
|
+
Object.defineProperty(inst, "_def", { value: def });
|
|
4914
|
+
inst._zod.def = def;
|
|
4915
|
+
|
|
4916
|
+
inst.implement = (func) => {
|
|
4917
|
+
if (typeof func !== "function") {
|
|
4918
|
+
throw new Error("implement() must be called with a function");
|
|
4919
|
+
}
|
|
4920
|
+
// Defined inline so the closure stays anonymous: binding it to a `const` first names it, which costs 256 bytes per implemented function.
|
|
4921
|
+
return Object.defineProperty(
|
|
4922
|
+
function (this: any, ...args: never[]) {
|
|
4923
|
+
const parsedArgs = inst._def.input ? parse(inst._def.input, args) : args;
|
|
4924
|
+
const result = Reflect.apply(func, this, parsedArgs as never[]);
|
|
4925
|
+
if (inst._def.output) {
|
|
4926
|
+
return parse(inst._def.output, result);
|
|
4927
|
+
}
|
|
4928
|
+
return result as any;
|
|
4929
|
+
},
|
|
4930
|
+
"_zod",
|
|
4931
|
+
{ value: inst._zod, enumerable: false }
|
|
4932
|
+
) as any;
|
|
4933
|
+
};
|
|
4934
|
+
|
|
4935
|
+
inst.implementAsync = (func) => {
|
|
4936
|
+
if (typeof func !== "function") {
|
|
4937
|
+
throw new Error("implementAsync() must be called with a function");
|
|
4938
|
+
}
|
|
4939
|
+
return Object.defineProperty(
|
|
4940
|
+
async function (this: any, ...args: never[]) {
|
|
4941
|
+
const parsedArgs = inst._def.input ? await parseAsync(inst._def.input, args) : args;
|
|
4942
|
+
const result = await Reflect.apply(func, this, parsedArgs as never[]);
|
|
4943
|
+
if (inst._def.output) {
|
|
4944
|
+
return await parseAsync(inst._def.output, result);
|
|
4945
|
+
}
|
|
4946
|
+
return result;
|
|
4947
|
+
},
|
|
4948
|
+
"_zod",
|
|
4949
|
+
{ value: inst._zod, enumerable: false }
|
|
4950
|
+
) as any;
|
|
4951
|
+
};
|
|
4952
|
+
|
|
4953
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
4954
|
+
if (typeof payload.value !== "function") {
|
|
4955
|
+
payload.issues.push({
|
|
4956
|
+
code: "invalid_type",
|
|
4957
|
+
expected: "function",
|
|
4958
|
+
input: payload.value,
|
|
4959
|
+
inst,
|
|
4960
|
+
});
|
|
4961
|
+
return payload;
|
|
4962
|
+
}
|
|
4963
|
+
|
|
4964
|
+
// Check if output is a promise type to determine if we should use async implementation
|
|
4965
|
+
const hasPromiseOutput = inst._def.output && inst._def.output._zod.def.type === "promise";
|
|
4966
|
+
|
|
4967
|
+
if (hasPromiseOutput) {
|
|
4968
|
+
payload.value = inst.implementAsync(payload.value);
|
|
4969
|
+
} else {
|
|
4970
|
+
payload.value = inst.implement(payload.value);
|
|
4971
|
+
}
|
|
4972
|
+
return payload;
|
|
4973
|
+
};
|
|
4974
|
+
|
|
4975
|
+
inst.input = (...args: any[]): $ZodFunction<any, any> => {
|
|
4976
|
+
const F: any = inst.constructor;
|
|
4977
|
+
if (Array.isArray(args[0])) {
|
|
4978
|
+
return new F({
|
|
4979
|
+
type: "function",
|
|
4980
|
+
input: new $ZodTuple({
|
|
4981
|
+
type: "tuple",
|
|
4982
|
+
items: args[0],
|
|
4983
|
+
rest: args[1],
|
|
4984
|
+
}),
|
|
4985
|
+
output: inst._def.output,
|
|
4986
|
+
});
|
|
4987
|
+
}
|
|
4988
|
+
|
|
4989
|
+
return new F({
|
|
4990
|
+
type: "function",
|
|
4991
|
+
input: args[0],
|
|
4992
|
+
output: inst._def.output,
|
|
4993
|
+
});
|
|
4994
|
+
};
|
|
4995
|
+
|
|
4996
|
+
inst.output = (output) => {
|
|
4997
|
+
const F: any = inst.constructor;
|
|
4998
|
+
return new F({
|
|
4999
|
+
type: "function",
|
|
5000
|
+
input: inst._def.input,
|
|
5001
|
+
output,
|
|
5002
|
+
});
|
|
5003
|
+
};
|
|
5004
|
+
|
|
5005
|
+
return inst;
|
|
5006
|
+
}
|
|
5007
|
+
);
|
|
5008
|
+
|
|
3638
5009
|
/////////////////////////////////////////
|
|
3639
5010
|
/////////////////////////////////////////
|
|
3640
5011
|
////////// //////////
|
|
@@ -3648,7 +5019,7 @@ export interface $ZodPromiseDef<T extends SomeType = $ZodType> extends $ZodTypeD
|
|
|
3648
5019
|
}
|
|
3649
5020
|
|
|
3650
5021
|
export interface $ZodPromiseInternals<T extends SomeType = $ZodType>
|
|
3651
|
-
extends $ZodTypeInternals<core.output<T
|
|
5022
|
+
extends $ZodTypeInternals<Promise<core.output<T>>, util.MaybeAsync<core.input<T>>> {
|
|
3652
5023
|
def: $ZodPromiseDef<T>;
|
|
3653
5024
|
isst: never;
|
|
3654
5025
|
}
|
|
@@ -3700,11 +5071,16 @@ export interface $ZodLazy<T extends SomeType = $ZodType> extends $ZodType {
|
|
|
3700
5071
|
export const $ZodLazy: core.$constructor<$ZodLazy> = /*@__PURE__*/ core.$constructor("$ZodLazy", (inst, def) => {
|
|
3701
5072
|
$ZodType.init(inst, def);
|
|
3702
5073
|
|
|
3703
|
-
|
|
3704
|
-
util.defineLazy(inst._zod, "
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
5074
|
+
// Cache the resolved inner type on the shared `def` so all clones of this lazy (e.g. via `.describe()`/`.meta()`) share the same inner instance, preserving identity for cycle detection on recursive schemas.
|
|
5075
|
+
util.defineLazy(inst._zod, "innerType", () => {
|
|
5076
|
+
const d = def as $ZodLazyDef & { _cachedInner?: $ZodType };
|
|
5077
|
+
if (!d._cachedInner) d._cachedInner = def.getter() as $ZodType;
|
|
5078
|
+
return d._cachedInner;
|
|
5079
|
+
});
|
|
5080
|
+
util.defineLazyInternal(inst, "pattern", (zod) => zod.innerType?._zod?.pattern);
|
|
5081
|
+
util.defineLazyInternal(inst, "propValues", (zod) => zod.innerType?._zod?.propValues);
|
|
5082
|
+
util.defineLazyInternal(inst, "optin", (zod) => zod.innerType?._zod?.optin ?? undefined);
|
|
5083
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.innerType?._zod?.optout ?? undefined);
|
|
3708
5084
|
inst._zod.parse = (payload, ctx) => {
|
|
3709
5085
|
const inner = inst._zod.innerType;
|
|
3710
5086
|
return inner._zod.run(payload, ctx);
|
|
@@ -3800,6 +5176,7 @@ export type $ZodTypes =
|
|
|
3800
5176
|
| $ZodSet
|
|
3801
5177
|
| $ZodLiteral
|
|
3802
5178
|
| $ZodEnum
|
|
5179
|
+
| $ZodFunction
|
|
3803
5180
|
| $ZodPromise
|
|
3804
5181
|
| $ZodLazy
|
|
3805
5182
|
| $ZodOptional
|
|
@@ -3834,9 +5211,16 @@ export type $ZodStringFormatTypes =
|
|
|
3834
5211
|
| $ZodISODuration
|
|
3835
5212
|
| $ZodIPv4
|
|
3836
5213
|
| $ZodIPv6
|
|
5214
|
+
| $ZodMAC
|
|
3837
5215
|
| $ZodCIDRv4
|
|
3838
5216
|
| $ZodCIDRv6
|
|
3839
5217
|
| $ZodBase64
|
|
3840
5218
|
| $ZodBase64URL
|
|
3841
5219
|
| $ZodE164
|
|
3842
|
-
| $
|
|
5220
|
+
| $ZodCreditCard
|
|
5221
|
+
| $ZodIBAN
|
|
5222
|
+
| $ZodJWT
|
|
5223
|
+
| $ZodCustomStringFormat<"hex">
|
|
5224
|
+
| $ZodCustomStringFormat<util.HashFormat>
|
|
5225
|
+
| $ZodCustomStringFormat<"hostname">
|
|
5226
|
+
| $ZodCustomStringFormat<"currency_code">;
|