@openclaw/firecrawl-plugin 2026.9.4 → 2026.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/activity.svg +31 -0
- package/assets/icon.png +0 -0
- package/dist/{firecrawl-client-BPFpIblh.js → .setup/firecrawl-client-hBjAoE8s.mjs} +25 -26
- package/dist/{firecrawl-fetch-provider-CIpxLKLq.js → .setup/firecrawl-fetch-provider-DH8FdBjV.mjs} +1 -1
- package/dist/{firecrawl-search-provider-80szkO8A.js → .setup/firecrawl-search-provider-8H0Cu9l0.mjs} +1 -1
- package/dist/api.js +1 -1
- package/dist/index.js +3 -3
- package/dist/web-fetch-contract-api.js +1 -1
- package/dist/web-fetch-provider.js +1 -1
- package/dist/web-search-contract-api.js +1 -1
- package/dist/web-search-provider.js +1 -1
- package/node_modules/typebox/build/compile/validator.d.mts +1 -1
- package/node_modules/typebox/build/compile/validator.mjs +1 -1
- package/node_modules/typebox/build/format/idna/idn-hostname.mjs +7 -5
- package/node_modules/typebox/build/format/iri.mjs +5 -1
- package/node_modules/typebox/build/guard/emit.mjs +2 -4
- package/node_modules/typebox/build/guard/guard.mjs +6 -18
- package/node_modules/typebox/build/guard/string.mjs +16 -24
- package/node_modules/typebox/build/schema/build.mjs +2 -2
- package/node_modules/typebox/build/schema/check.mjs +1 -1
- package/node_modules/typebox/build/schema/compile.d.mts +3 -2
- package/node_modules/typebox/build/schema/compile.mjs +8 -8
- package/node_modules/typebox/build/schema/engine/_context.d.mts +6 -7
- package/node_modules/typebox/build/schema/engine/_context.mjs +23 -15
- package/node_modules/typebox/build/schema/engine/_functions.d.mts +2 -2
- package/node_modules/typebox/build/schema/engine/_functions.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/_reducer.d.mts +3 -3
- package/node_modules/typebox/build/schema/engine/_refine.d.mts +5 -5
- package/node_modules/typebox/build/schema/engine/_refine.mjs +4 -7
- package/node_modules/typebox/build/schema/engine/_stack.d.mts +34 -16
- package/node_modules/typebox/build/schema/engine/_stack.mjs +148 -104
- package/node_modules/typebox/build/schema/engine/additionalItems.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/additionalProperties.d.mts +8 -8
- package/node_modules/typebox/build/schema/engine/additionalProperties.mjs +26 -18
- package/node_modules/typebox/build/schema/engine/allOf.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/allOf.mjs +3 -3
- package/node_modules/typebox/build/schema/engine/anyOf.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/anyOf.mjs +5 -10
- package/node_modules/typebox/build/schema/engine/boolean.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/boolean.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/const.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/const.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/contains.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/contains.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/dependencies.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/dependencies.mjs +3 -6
- package/node_modules/typebox/build/schema/engine/dependentRequired.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/dependentRequired.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/dependentSchemas.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/dynamicRef.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/dynamicRef.mjs +11 -7
- package/node_modules/typebox/build/schema/engine/enum.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/enum.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/exclusiveMaximum.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/exclusiveMaximum.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/exclusiveMinimum.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/exclusiveMinimum.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/format.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/format.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/if.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/if.mjs +7 -15
- package/node_modules/typebox/build/schema/engine/items.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/items.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/maxContains.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/maxContains.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/maxItems.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/maxItems.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/maxLength.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/maxLength.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/maxProperties.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/maxProperties.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/maximum.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/maximum.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/minContains.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/minContains.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/minItems.d.mts +5 -5
- package/node_modules/typebox/build/schema/engine/minItems.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/minLength.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/minLength.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/minProperties.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/minProperties.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/minimum.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/minimum.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/multipleOf.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/multipleOf.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/not.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/not.mjs +4 -8
- package/node_modules/typebox/build/schema/engine/oneOf.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/oneOf.mjs +6 -11
- package/node_modules/typebox/build/schema/engine/pattern.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/pattern.mjs +3 -7
- package/node_modules/typebox/build/schema/engine/patternProperties.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/patternProperties.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/prefixItems.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/prefixItems.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/properties.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/properties.mjs +1 -1
- package/node_modules/typebox/build/schema/engine/propertyNames.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/propertyNames.mjs +4 -10
- package/node_modules/typebox/build/schema/engine/recursiveRef.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/recursiveRef.mjs +11 -7
- package/node_modules/typebox/build/schema/engine/ref.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/ref.mjs +19 -15
- package/node_modules/typebox/build/schema/engine/required.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/required.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/schema.d.mts +7 -7
- package/node_modules/typebox/build/schema/engine/schema.mjs +137 -133
- package/node_modules/typebox/build/schema/engine/type.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/type.mjs +2 -6
- package/node_modules/typebox/build/schema/engine/unevaluatedItems.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/unevaluatedItems.mjs +5 -9
- package/node_modules/typebox/build/schema/engine/unevaluatedProperties.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/unevaluatedProperties.mjs +5 -9
- package/node_modules/typebox/build/schema/engine/uniqueItems.d.mts +4 -4
- package/node_modules/typebox/build/schema/engine/uniqueItems.mjs +2 -6
- package/node_modules/typebox/build/schema/errors.d.mts +2 -2
- package/node_modules/typebox/build/schema/errors.mjs +8 -14
- package/node_modules/typebox/build/schema/intern/index.d.mts +1 -0
- package/node_modules/typebox/build/schema/intern/index.mjs +1 -0
- package/node_modules/typebox/build/schema/intern/intern.d.mts +11 -0
- package/node_modules/typebox/build/schema/intern/intern.mjs +293 -0
- package/node_modules/typebox/build/schema/meta/draft_2019_09.d.mts +2 -0
- package/node_modules/typebox/build/schema/meta/draft_2019_09.mjs +288 -0
- package/node_modules/typebox/build/schema/meta/draft_2020_12.d.mts +2 -0
- package/node_modules/typebox/build/schema/meta/draft_2020_12.mjs +300 -0
- package/node_modules/typebox/build/schema/meta/draft_3.d.mts +2 -0
- package/node_modules/typebox/build/schema/meta/draft_3.mjs +143 -0
- package/node_modules/typebox/build/schema/meta/draft_4.d.mts +2 -0
- package/node_modules/typebox/build/schema/meta/draft_4.mjs +149 -0
- package/node_modules/typebox/build/schema/meta/draft_6.d.mts +2 -0
- package/node_modules/typebox/build/schema/meta/draft_6.mjs +155 -0
- package/node_modules/typebox/build/schema/meta/draft_7.d.mts +2 -0
- package/node_modules/typebox/build/schema/meta/draft_7.mjs +172 -0
- package/node_modules/typebox/build/schema/meta/index.d.mts +2 -0
- package/node_modules/typebox/build/schema/meta/index.mjs +2 -0
- package/node_modules/typebox/build/schema/meta/meta.d.mts +9 -0
- package/node_modules/typebox/build/schema/meta/meta.mjs +15 -0
- package/node_modules/typebox/build/schema/meta/schema.d.mts +6 -0
- package/node_modules/typebox/build/schema/meta/schema.mjs +1 -0
- package/node_modules/typebox/build/schema/parse.d.mts +1 -0
- package/node_modules/typebox/build/schema/parse.mjs +10 -5
- package/node_modules/typebox/build/schema/resolve/resolve.d.mts +8 -3
- package/node_modules/typebox/build/schema/resolve/resolve.mjs +268 -139
- package/node_modules/typebox/build/schema/schema.d.mts +2 -0
- package/node_modules/typebox/build/schema/schema.mjs +2 -0
- package/node_modules/typebox/build/value/errors/errors.d.mts +2 -12
- package/node_modules/typebox/build/value/errors/errors.mjs +2 -7
- package/node_modules/typebox/package.json +1 -1
- package/node_modules/typebox/readme.md +59 -89
- package/node_modules/zod/README.md +29 -2
- 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 +21 -2
- package/node_modules/zod/index.d.cts +1 -2
- package/node_modules/zod/index.d.ts +1 -2
- package/node_modules/zod/index.js +5 -2
- package/node_modules/zod/locales/index.cjs +19 -0
- package/node_modules/zod/mini/index.cjs +19 -0
- package/node_modules/zod/package.json +20 -8
- package/node_modules/zod/src/compile.ts +56 -0
- package/node_modules/zod/src/index.ts +5 -2
- package/node_modules/zod/src/v3/ZodError.ts +22 -12
- package/node_modules/zod/src/v3/helpers/errorUtil.ts +1 -1
- package/node_modules/zod/src/v3/tests/error.test.ts +35 -0
- 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/object.test.ts +3 -6
- package/node_modules/zod/src/v3/tests/readonly.test.ts +0 -80
- package/node_modules/zod/src/v3/tests/string.test.ts +6 -0
- package/node_modules/zod/src/v3/types.ts +5 -5
- package/node_modules/zod/src/v4/classic/checks.ts +1 -0
- package/node_modules/zod/src/v4/classic/compat.ts +26 -18
- package/node_modules/zod/src/v4/classic/deep-partial.ts +76 -0
- package/node_modules/zod/src/v4/classic/errors.ts +59 -44
- package/node_modules/zod/src/v4/classic/external.ts +14 -9
- package/node_modules/zod/src/v4/classic/from-json-schema.ts +363 -78
- 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 +10 -4
- package/node_modules/zod/src/v4/classic/schemas.ts +640 -375
- package/node_modules/zod/src/v4/classic/tests/apply.test.ts +27 -0
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +2 -2
- package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +186 -0
- package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +36 -1
- package/node_modules/zod/src/v4/classic/tests/catch.test.ts +278 -0
- package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +1 -2
- package/node_modules/zod/src/v4/classic/tests/codec.test.ts +2 -1
- package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +3 -3
- 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 +30 -0
- package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +32 -18
- 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 +46 -0
- package/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +31 -7
- package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +261 -13
- 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 +112 -2
- package/node_modules/zod/src/v4/classic/tests/error.test.ts +403 -6
- package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +582 -10
- package/node_modules/zod/src/v4/classic/tests/function.test.ts +31 -0
- package/node_modules/zod/src/v4/classic/tests/global-config.test.ts +2 -9
- package/node_modules/zod/src/v4/classic/tests/hash.test.ts +1 -2
- 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 +21 -2
- 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 +67 -0
- package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +136 -0
- 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 +3 -10
- package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +36 -1
- package/node_modules/zod/src/v4/classic/tests/literal.test.ts +12 -1
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +12 -0
- package/node_modules/zod/src/v4/classic/tests/number.test.ts +85 -9
- package/node_modules/zod/src/v4/classic/tests/object.test.ts +301 -12
- 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 +49 -16
- package/node_modules/zod/src/v4/classic/tests/partial.test.ts +51 -4
- package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +70 -0
- package/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +20 -2
- package/node_modules/zod/src/v4/classic/tests/properties.test.ts +141 -0
- package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +0 -68
- package/node_modules/zod/src/v4/classic/tests/record.test.ts +186 -18
- package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +79 -3
- package/node_modules/zod/src/v4/classic/tests/redos.test.ts +68 -0
- package/node_modules/zod/src/v4/classic/tests/refine.test.ts +60 -0
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +9 -0
- package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +19 -0
- package/node_modules/zod/src/v4/classic/tests/string.test.ts +222 -6
- package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +18 -0
- package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +44 -3
- package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +1812 -204
- package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +45 -30
- package/node_modules/zod/src/v4/classic/tests/union.test.ts +39 -2
- 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 +87 -35
- package/node_modules/zod/src/v4/core/checks.ts +119 -146
- package/node_modules/zod/src/v4/core/compile.ts +2313 -0
- package/node_modules/zod/src/v4/core/core.ts +99 -22
- package/node_modules/zod/src/v4/core/doc.ts +17 -9
- package/node_modules/zod/src/v4/core/errors.ts +113 -25
- package/node_modules/zod/src/v4/core/index.ts +3 -0
- package/node_modules/zod/src/v4/core/json-schema-generator.ts +8 -3
- package/node_modules/zod/src/v4/core/json-schema-processors.ts +424 -156
- package/node_modules/zod/src/v4/core/json-schema.ts +2 -1
- package/node_modules/zod/src/v4/core/memoizer.ts +331 -0
- package/node_modules/zod/src/v4/core/parse.ts +164 -50
- package/node_modules/zod/src/v4/core/regexes.ts +42 -15
- package/node_modules/zod/src/v4/core/registries.ts +2 -2
- package/node_modules/zod/src/v4/core/schemas.ts +1000 -538
- 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/locales/el.test.ts +1 -2
- package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +1 -2
- package/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +3 -3
- 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/polyfill-collision.test.ts +46 -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 +283 -48
- package/node_modules/zod/src/v4/core/util.ts +454 -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 +5 -0
- package/node_modules/zod/src/v4/locales/az.ts +5 -0
- package/node_modules/zod/src/v4/locales/be.ts +12 -0
- package/node_modules/zod/src/v4/locales/bg.ts +5 -0
- package/node_modules/zod/src/v4/locales/bn.ts +123 -0
- package/node_modules/zod/src/v4/locales/ca.ts +5 -0
- package/node_modules/zod/src/v4/locales/ckb.ts +140 -0
- package/node_modules/zod/src/v4/locales/cs.ts +5 -0
- package/node_modules/zod/src/v4/locales/da.ts +7 -2
- package/node_modules/zod/src/v4/locales/de.ts +5 -0
- package/node_modules/zod/src/v4/locales/el.ts +3 -0
- package/node_modules/zod/src/v4/locales/en.ts +17 -4
- package/node_modules/zod/src/v4/locales/eo.ts +5 -0
- package/node_modules/zod/src/v4/locales/es.ts +4 -0
- package/node_modules/zod/src/v4/locales/fa.ts +5 -0
- package/node_modules/zod/src/v4/locales/fi.ts +5 -0
- package/node_modules/zod/src/v4/locales/fr-CA.ts +5 -0
- package/node_modules/zod/src/v4/locales/fr.ts +21 -14
- package/node_modules/zod/src/v4/locales/gu.ts +123 -0
- package/node_modules/zod/src/v4/locales/he.ts +8 -1
- package/node_modules/zod/src/v4/locales/hi.ts +126 -0
- package/node_modules/zod/src/v4/locales/hr.ts +4 -0
- package/node_modules/zod/src/v4/locales/hu.ts +5 -0
- package/node_modules/zod/src/v4/locales/hy.ts +11 -0
- package/node_modules/zod/src/v4/locales/id.ts +5 -0
- package/node_modules/zod/src/v4/locales/index.ts +11 -0
- package/node_modules/zod/src/v4/locales/is.ts +5 -0
- package/node_modules/zod/src/v4/locales/it.ts +5 -0
- package/node_modules/zod/src/v4/locales/ja.ts +5 -0
- package/node_modules/zod/src/v4/locales/ka.ts +5 -0
- package/node_modules/zod/src/v4/locales/km.ts +5 -0
- package/node_modules/zod/src/v4/locales/kn.ts +126 -0
- package/node_modules/zod/src/v4/locales/ko.ts +5 -0
- package/node_modules/zod/src/v4/locales/lt.ts +4 -0
- package/node_modules/zod/src/v4/locales/mk.ts +5 -0
- package/node_modules/zod/src/v4/locales/ms.ts +5 -0
- package/node_modules/zod/src/v4/locales/ne.ts +128 -0
- package/node_modules/zod/src/v4/locales/nl.ts +5 -0
- package/node_modules/zod/src/v4/locales/nn.ts +121 -0
- package/node_modules/zod/src/v4/locales/no.ts +7 -2
- package/node_modules/zod/src/v4/locales/ota.ts +5 -0
- package/node_modules/zod/src/v4/locales/pl.ts +5 -0
- package/node_modules/zod/src/v4/locales/ps.ts +5 -0
- package/node_modules/zod/src/v4/locales/pt-BR.ts +161 -0
- package/node_modules/zod/src/v4/locales/pt.ts +101 -58
- package/node_modules/zod/src/v4/locales/ro.ts +3 -0
- package/node_modules/zod/src/v4/locales/ru.ts +12 -0
- package/node_modules/zod/src/v4/locales/sk.ts +123 -0
- package/node_modules/zod/src/v4/locales/sl.ts +5 -0
- package/node_modules/zod/src/v4/locales/sv.ts +7 -2
- package/node_modules/zod/src/v4/locales/ta.ts +5 -0
- package/node_modules/zod/src/v4/locales/tg.ts +135 -0
- package/node_modules/zod/src/v4/locales/th.ts +5 -0
- package/node_modules/zod/src/v4/locales/tk.ts +113 -0
- package/node_modules/zod/src/v4/locales/tr.ts +5 -0
- package/node_modules/zod/src/v4/locales/uk.ts +5 -0
- package/node_modules/zod/src/v4/locales/ur.ts +5 -0
- package/node_modules/zod/src/v4/locales/uz.ts +3 -0
- package/node_modules/zod/src/v4/locales/vi.ts +5 -0
- package/node_modules/zod/src/v4/locales/yo.ts +5 -0
- package/node_modules/zod/src/v4/locales/zh-CN.ts +5 -0
- package/node_modules/zod/src/v4/locales/zh-TW.ts +5 -0
- package/node_modules/zod/src/v4/mini/checks.ts +1 -0
- package/node_modules/zod/src/v4/mini/deep-partial.ts +73 -0
- package/node_modules/zod/src/v4/mini/external.ts +12 -1
- package/node_modules/zod/src/v4/mini/in-out.ts +45 -0
- package/node_modules/zod/src/v4/mini/parse.ts +2 -0
- package/node_modules/zod/src/v4/mini/schemas.ts +167 -63
- package/node_modules/zod/src/v4/mini/tests/apply.test.ts +33 -0
- package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +62 -1
- package/node_modules/zod/src/v4/mini/tests/checks.test.ts +14 -0
- package/node_modules/zod/src/v4/mini/tests/codec.test.ts +35 -1
- package/node_modules/zod/src/v4/mini/tests/computed.test.ts +11 -17
- 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 +23 -4
- package/node_modules/zod/src/v4/mini/tests/functions.test.ts +9 -0
- package/node_modules/zod/src/v4/mini/tests/index.test.ts +158 -5
- package/node_modules/zod/src/v4/mini/tests/number.test.ts +14 -0
- package/node_modules/zod/src/v4/mini/tests/object.test.ts +65 -0
- package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +16 -0
- package/node_modules/zod/src/v4/mini/tests/string.test.ts +44 -0
- package/node_modules/zod/v3/ZodError.cjs +41 -12
- package/node_modules/zod/v3/ZodError.d.cts +1 -1
- package/node_modules/zod/v3/ZodError.d.ts +1 -1
- package/node_modules/zod/v3/ZodError.js +22 -12
- 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/standard-schema.cjs +19 -0
- package/node_modules/zod/v3/types.cjs +26 -5
- package/node_modules/zod/v3/types.js +7 -5
- package/node_modules/zod/v4/classic/checks.cjs +21 -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 +19 -0
- package/node_modules/zod/v4/classic/compat.d.cts +9 -11
- package/node_modules/zod/v4/classic/compat.d.ts +9 -11
- 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 +62 -34
- 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 +43 -34
- package/node_modules/zod/v4/classic/external.cjs +51 -27
- package/node_modules/zod/v4/classic/external.d.cts +5 -2
- package/node_modules/zod/v4/classic/external.d.ts +5 -2
- package/node_modules/zod/v4/classic/external.js +5 -8
- package/node_modules/zod/v4/classic/from-json-schema.cjs +376 -75
- package/node_modules/zod/v4/classic/from-json-schema.js +357 -75
- 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/parse.cjs +23 -1
- package/node_modules/zod/v4/classic/parse.d.cts +17 -4
- package/node_modules/zod/v4/classic/parse.d.ts +17 -4
- package/node_modules/zod/v4/classic/parse.js +1 -0
- package/node_modules/zod/v4/classic/schemas.cjs +591 -426
- package/node_modules/zod/v4/classic/schemas.d.cts +68 -19
- package/node_modules/zod/v4/classic/schemas.d.ts +68 -19
- package/node_modules/zod/v4/classic/schemas.js +564 -424
- package/node_modules/zod/v4/core/api.cjs +66 -24
- package/node_modules/zod/v4/core/api.d.cts +22 -12
- package/node_modules/zod/v4/core/api.d.ts +22 -12
- package/node_modules/zod/v4/core/api.js +44 -24
- package/node_modules/zod/v4/core/checks.cjs +88 -128
- package/node_modules/zod/v4/core/checks.d.cts +29 -13
- package/node_modules/zod/v4/core/checks.d.ts +29 -13
- package/node_modules/zod/v4/core/checks.js +68 -127
- package/node_modules/zod/v4/core/compile.cjs +1908 -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 +1858 -0
- package/node_modules/zod/v4/core/core.cjs +101 -19
- package/node_modules/zod/v4/core/core.d.cts +16 -4
- package/node_modules/zod/v4/core/core.d.ts +16 -4
- package/node_modules/zod/v4/core/core.js +83 -20
- package/node_modules/zod/v4/core/doc.cjs +31 -9
- package/node_modules/zod/v4/core/doc.d.cts +3 -1
- package/node_modules/zod/v4/core/doc.d.ts +3 -1
- package/node_modules/zod/v4/core/doc.js +12 -9
- package/node_modules/zod/v4/core/errors.cjs +126 -25
- package/node_modules/zod/v4/core/errors.d.cts +4 -0
- package/node_modules/zod/v4/core/errors.d.ts +4 -0
- package/node_modules/zod/v4/core/errors.js +107 -25
- package/node_modules/zod/v4/core/index.cjs +24 -1
- package/node_modules/zod/v4/core/index.d.cts +3 -0
- package/node_modules/zod/v4/core/index.d.ts +3 -0
- package/node_modules/zod/v4/core/index.js +3 -0
- package/node_modules/zod/v4/core/json-schema-generator.cjs +24 -1
- package/node_modules/zod/v4/core/json-schema-generator.d.cts +2 -2
- package/node_modules/zod/v4/core/json-schema-generator.d.ts +2 -2
- package/node_modules/zod/v4/core/json-schema-generator.js +6 -2
- package/node_modules/zod/v4/core/json-schema-processors.cjs +441 -156
- package/node_modules/zod/v4/core/json-schema-processors.d.cts +16 -0
- package/node_modules/zod/v4/core/json-schema-processors.d.ts +16 -0
- package/node_modules/zod/v4/core/json-schema-processors.js +400 -158
- package/node_modules/zod/v4/core/json-schema.cjs +19 -0
- package/node_modules/zod/v4/core/json-schema.d.cts +2 -1
- package/node_modules/zod/v4/core/json-schema.d.ts +2 -1
- 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/parse.cjs +148 -46
- package/node_modules/zod/v4/core/parse.d.cts +14 -11
- package/node_modules/zod/v4/core/parse.d.ts +14 -11
- package/node_modules/zod/v4/core/parse.js +127 -45
- package/node_modules/zod/v4/core/regexes.cjs +54 -17
- package/node_modules/zod/v4/core/regexes.d.cts +5 -0
- package/node_modules/zod/v4/core/regexes.d.ts +5 -0
- package/node_modules/zod/v4/core/regexes.js +32 -15
- package/node_modules/zod/v4/core/registries.cjs +19 -0
- package/node_modules/zod/v4/core/registries.js +2 -2
- package/node_modules/zod/v4/core/schemas.cjs +785 -386
- package/node_modules/zod/v4/core/schemas.d.cts +123 -34
- package/node_modules/zod/v4/core/schemas.d.ts +123 -34
- package/node_modules/zod/v4/core/schemas.js +753 -386
- package/node_modules/zod/v4/core/standard-schema.cjs +19 -0
- package/node_modules/zod/v4/core/to-json-schema.cjs +269 -45
- package/node_modules/zod/v4/core/to-json-schema.d.cts +45 -5
- package/node_modules/zod/v4/core/to-json-schema.d.ts +45 -5
- package/node_modules/zod/v4/core/to-json-schema.js +247 -44
- package/node_modules/zod/v4/core/util.cjs +372 -157
- package/node_modules/zod/v4/core/util.d.cts +79 -1
- package/node_modules/zod/v4/core/util.d.ts +79 -1
- package/node_modules/zod/v4/core/util.js +341 -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 +5 -0
- package/node_modules/zod/v4/locales/ar.js +5 -0
- package/node_modules/zod/v4/locales/az.cjs +5 -0
- package/node_modules/zod/v4/locales/az.js +5 -0
- package/node_modules/zod/v4/locales/be.cjs +12 -0
- package/node_modules/zod/v4/locales/be.js +12 -0
- package/node_modules/zod/v4/locales/bg.cjs +5 -0
- package/node_modules/zod/v4/locales/bg.js +5 -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 +5 -0
- package/node_modules/zod/v4/locales/ca.js +5 -0
- 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 +5 -0
- package/node_modules/zod/v4/locales/cs.js +5 -0
- package/node_modules/zod/v4/locales/da.cjs +7 -2
- package/node_modules/zod/v4/locales/da.js +7 -2
- package/node_modules/zod/v4/locales/de.cjs +5 -0
- package/node_modules/zod/v4/locales/de.js +5 -0
- package/node_modules/zod/v4/locales/el.cjs +3 -0
- package/node_modules/zod/v4/locales/el.js +3 -0
- package/node_modules/zod/v4/locales/en.cjs +16 -4
- package/node_modules/zod/v4/locales/en.js +16 -4
- package/node_modules/zod/v4/locales/eo.cjs +5 -0
- package/node_modules/zod/v4/locales/eo.js +5 -0
- package/node_modules/zod/v4/locales/es.cjs +4 -0
- package/node_modules/zod/v4/locales/es.js +4 -0
- package/node_modules/zod/v4/locales/fa.cjs +5 -0
- package/node_modules/zod/v4/locales/fa.js +5 -0
- package/node_modules/zod/v4/locales/fi.cjs +5 -0
- package/node_modules/zod/v4/locales/fi.js +5 -0
- package/node_modules/zod/v4/locales/fr-CA.cjs +5 -0
- package/node_modules/zod/v4/locales/fr-CA.js +5 -0
- package/node_modules/zod/v4/locales/fr.cjs +18 -14
- package/node_modules/zod/v4/locales/fr.js +18 -14
- 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 +7 -0
- package/node_modules/zod/v4/locales/he.js +7 -0
- 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 +4 -0
- package/node_modules/zod/v4/locales/hr.js +4 -0
- package/node_modules/zod/v4/locales/hu.cjs +5 -0
- package/node_modules/zod/v4/locales/hu.js +5 -0
- package/node_modules/zod/v4/locales/hy.cjs +11 -0
- package/node_modules/zod/v4/locales/hy.js +11 -0
- package/node_modules/zod/v4/locales/id.cjs +5 -0
- package/node_modules/zod/v4/locales/id.js +5 -0
- package/node_modules/zod/v4/locales/index.cjs +43 -2
- package/node_modules/zod/v4/locales/index.d.cts +11 -0
- package/node_modules/zod/v4/locales/index.d.ts +11 -0
- package/node_modules/zod/v4/locales/index.js +11 -0
- package/node_modules/zod/v4/locales/is.cjs +5 -0
- package/node_modules/zod/v4/locales/is.js +5 -0
- package/node_modules/zod/v4/locales/it.cjs +5 -0
- package/node_modules/zod/v4/locales/it.js +5 -0
- package/node_modules/zod/v4/locales/ja.cjs +5 -0
- package/node_modules/zod/v4/locales/ja.js +5 -0
- package/node_modules/zod/v4/locales/ka.cjs +5 -0
- package/node_modules/zod/v4/locales/ka.js +5 -0
- package/node_modules/zod/v4/locales/km.cjs +5 -0
- package/node_modules/zod/v4/locales/km.js +5 -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 +5 -0
- package/node_modules/zod/v4/locales/ko.js +5 -0
- package/node_modules/zod/v4/locales/lt.cjs +4 -0
- package/node_modules/zod/v4/locales/lt.js +4 -0
- package/node_modules/zod/v4/locales/mk.cjs +5 -0
- package/node_modules/zod/v4/locales/mk.js +5 -0
- package/node_modules/zod/v4/locales/ms.cjs +5 -0
- package/node_modules/zod/v4/locales/ms.js +5 -0
- 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 +5 -0
- package/node_modules/zod/v4/locales/nl.js +5 -0
- 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 +7 -2
- package/node_modules/zod/v4/locales/no.js +7 -2
- package/node_modules/zod/v4/locales/ota.cjs +5 -0
- package/node_modules/zod/v4/locales/ota.js +5 -0
- package/node_modules/zod/v4/locales/pl.cjs +5 -0
- package/node_modules/zod/v4/locales/pl.js +5 -0
- package/node_modules/zod/v4/locales/ps.cjs +5 -0
- package/node_modules/zod/v4/locales/ps.js +5 -0
- 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 +89 -55
- package/node_modules/zod/v4/locales/pt.js +89 -55
- package/node_modules/zod/v4/locales/ro.cjs +3 -0
- package/node_modules/zod/v4/locales/ro.js +3 -0
- package/node_modules/zod/v4/locales/ru.cjs +12 -0
- package/node_modules/zod/v4/locales/ru.js +12 -0
- 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 +5 -0
- package/node_modules/zod/v4/locales/sl.js +5 -0
- package/node_modules/zod/v4/locales/sv.cjs +7 -2
- package/node_modules/zod/v4/locales/sv.js +7 -2
- package/node_modules/zod/v4/locales/ta.cjs +5 -0
- package/node_modules/zod/v4/locales/ta.js +5 -0
- 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 +5 -0
- package/node_modules/zod/v4/locales/th.js +5 -0
- 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 +5 -0
- package/node_modules/zod/v4/locales/tr.js +5 -0
- package/node_modules/zod/v4/locales/uk.cjs +5 -0
- package/node_modules/zod/v4/locales/uk.js +5 -0
- package/node_modules/zod/v4/locales/ur.cjs +5 -0
- package/node_modules/zod/v4/locales/ur.js +5 -0
- package/node_modules/zod/v4/locales/uz.cjs +3 -0
- package/node_modules/zod/v4/locales/uz.js +3 -0
- package/node_modules/zod/v4/locales/vi.cjs +5 -0
- package/node_modules/zod/v4/locales/vi.js +5 -0
- package/node_modules/zod/v4/locales/yo.cjs +5 -0
- package/node_modules/zod/v4/locales/yo.js +5 -0
- package/node_modules/zod/v4/locales/zh-CN.cjs +5 -0
- package/node_modules/zod/v4/locales/zh-CN.js +5 -0
- package/node_modules/zod/v4/locales/zh-TW.cjs +5 -0
- package/node_modules/zod/v4/locales/zh-TW.js +5 -0
- 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 +19 -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 +33 -1
- package/node_modules/zod/v4/mini/external.d.cts +5 -2
- package/node_modules/zod/v4/mini/external.d.ts +5 -2
- package/node_modules/zod/v4/mini/external.js +3 -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 +19 -0
- package/node_modules/zod/v4/mini/parse.cjs +22 -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 +117 -53
- package/node_modules/zod/v4/mini/schemas.d.cts +49 -14
- package/node_modules/zod/v4/mini/schemas.d.ts +49 -14
- package/node_modules/zod/v4/mini/schemas.js +92 -51
- package/node_modules/zod/v4-mini/index.cjs +19 -0
- package/openclaw.plugin.json +15 -1
- package/package.json +9 -7
- package/node_modules/zod/src/v4/core/config.ts +0 -15
|
@@ -1,10 +1,11 @@
|
|
|
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
7
|
import type * as JSONSchema from "./json-schema.js";
|
|
7
|
-
import { parse, parseAsync
|
|
8
|
+
import { parse, parseAsync } from "./parse.js";
|
|
8
9
|
import * as regexes from "./regexes.js";
|
|
9
10
|
import type { StandardSchemaV1 } from "./standard-schema.js";
|
|
10
11
|
import type { ProcessParams, ToJSONSchemaContext } from "./to-json-schema.js";
|
|
@@ -29,6 +30,15 @@ export interface ParseContextInternal<T extends errors.$ZodIssueBase = never> ex
|
|
|
29
30
|
readonly async?: boolean | undefined;
|
|
30
31
|
readonly direction?: "forward" | "backward";
|
|
31
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;
|
|
32
42
|
}
|
|
33
43
|
|
|
34
44
|
export interface ParsePayload<T = unknown> {
|
|
@@ -36,11 +46,9 @@ export interface ParsePayload<T = unknown> {
|
|
|
36
46
|
issues: errors.$ZodRawIssue[];
|
|
37
47
|
/** A way to mark a whole payload as aborted. Used in codecs/pipes. */
|
|
38
48
|
aborted?: boolean;
|
|
39
|
-
/** @internal
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
* $ZodTransform invocation. */
|
|
43
|
-
fallback?: boolean | undefined;
|
|
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;
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>;
|
|
@@ -120,8 +128,13 @@ export interface _$ZodTypeInternals {
|
|
|
120
128
|
* @default Required
|
|
121
129
|
*/
|
|
122
130
|
|
|
123
|
-
/** @internal
|
|
124
|
-
|
|
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;
|
|
125
138
|
/** @internal */
|
|
126
139
|
optout?: "optional" | undefined;
|
|
127
140
|
|
|
@@ -187,137 +200,164 @@ export interface $ZodType<
|
|
|
187
200
|
export interface _$ZodType<T extends $ZodTypeInternals = $ZodTypeInternals>
|
|
188
201
|
extends $ZodType<T["output"], T["input"], T> {}
|
|
189
202
|
|
|
190
|
-
export const $ZodType: core.$constructor<$ZodType> = /*@__PURE__*/ core.$constructor
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
checks.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
+
}
|
|
207
224
|
}
|
|
208
|
-
}
|
|
209
225
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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;
|
|
236
253
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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 {
|
|
243
266
|
const nextLen = payload.issues.length;
|
|
244
|
-
if (nextLen === currLen)
|
|
267
|
+
if (nextLen === currLen) continue;
|
|
268
|
+
util.attachSchema(payload.issues, currLen, inst);
|
|
245
269
|
if (!isAborted) isAborted = util.aborted(payload, currLen);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (asyncResult) {
|
|
274
|
+
return asyncResult.then(() => {
|
|
275
|
+
return payload;
|
|
246
276
|
});
|
|
247
|
-
} else {
|
|
248
|
-
const nextLen = payload.issues.length;
|
|
249
|
-
if (nextLen === currLen) continue;
|
|
250
|
-
if (!isAborted) isAborted = util.aborted(payload, currLen);
|
|
251
277
|
}
|
|
252
|
-
|
|
278
|
+
return payload;
|
|
279
|
+
};
|
|
253
280
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
};
|
|
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
|
+
}
|
|
261
287
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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));
|
|
293
|
+
}
|
|
294
|
+
return inst._zod.parse(checkResult, ctx);
|
|
295
|
+
};
|
|
268
296
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
};
|
|
297
|
+
inst._zod.run = (payload, ctx) => {
|
|
298
|
+
if (ctx.skipChecks) {
|
|
299
|
+
return inst._zod.parse(payload, ctx);
|
|
300
|
+
}
|
|
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 });
|
|
277
304
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
// run canary
|
|
284
|
-
// initial pass (no checks)
|
|
285
|
-
const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
|
|
305
|
+
if (canary instanceof Promise) {
|
|
306
|
+
return canary.then((canary) => {
|
|
307
|
+
return handleCanaryResult(canary, payload, ctx);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
286
310
|
|
|
287
|
-
|
|
288
|
-
return canary.then((canary) => {
|
|
289
|
-
return handleCanaryResult(canary, payload, ctx);
|
|
290
|
-
});
|
|
311
|
+
return handleCanaryResult(canary, payload, ctx);
|
|
291
312
|
}
|
|
292
313
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
if (ctx.async === false) throw new core.$ZodAsyncError();
|
|
300
|
-
return result.then((result) => runChecks(result, checks, ctx));
|
|
301
|
-
}
|
|
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
|
+
}
|
|
302
320
|
|
|
303
|
-
|
|
304
|
-
|
|
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
|
+
},
|
|
305
333
|
}
|
|
334
|
+
);
|
|
306
335
|
|
|
307
|
-
|
|
308
|
-
|
|
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 };
|
|
340
|
+
|
|
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
|
+
}
|
|
345
|
+
|
|
346
|
+
export function standardProps(inst: $ZodType): StandardSchemaV1.Props<any, any> {
|
|
347
|
+
return {
|
|
309
348
|
validate: (value: unknown) => {
|
|
349
|
+
const ctx: ParseContextInternal = { async: false };
|
|
310
350
|
try {
|
|
311
|
-
const r =
|
|
312
|
-
|
|
313
|
-
} catch (_) {
|
|
314
|
-
|
|
315
|
-
|
|
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);
|
|
316
356
|
},
|
|
317
357
|
vendor: "zod",
|
|
318
358
|
version: 1 as const,
|
|
319
|
-
}
|
|
320
|
-
}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
321
361
|
|
|
322
362
|
export { clone } from "./util.js";
|
|
323
363
|
|
|
@@ -347,6 +387,8 @@ export interface $ZodStringInternals<Input> extends $ZodTypeInternals<string, In
|
|
|
347
387
|
patterns: Set<RegExp>;
|
|
348
388
|
format: string;
|
|
349
389
|
contentEncoding: string;
|
|
390
|
+
/** the pattern admits strings its `format` keyword forbids, so `toJSONSchema` must not emit it */
|
|
391
|
+
laxFormat: boolean;
|
|
350
392
|
}>;
|
|
351
393
|
}
|
|
352
394
|
|
|
@@ -356,7 +398,8 @@ export interface $ZodString<Input = unknown> extends _$ZodType<$ZodStringInterna
|
|
|
356
398
|
|
|
357
399
|
export const $ZodString: core.$constructor<$ZodString> = /*@__PURE__*/ core.$constructor("$ZodString", (inst, def) => {
|
|
358
400
|
$ZodType.init(inst, def);
|
|
359
|
-
|
|
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;
|
|
360
403
|
inst._zod.parse = (payload, _) => {
|
|
361
404
|
if (def.coerce)
|
|
362
405
|
try {
|
|
@@ -477,71 +520,133 @@ export interface $ZodURL extends $ZodType {
|
|
|
477
520
|
_zod: $ZodURLInternals;
|
|
478
521
|
}
|
|
479
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
|
+
|
|
480
587
|
export const $ZodURL: core.$constructor<$ZodURL> = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) => {
|
|
481
588
|
$ZodStringFormat.init(inst, def);
|
|
482
589
|
inst._zod.check = (payload) => {
|
|
483
590
|
try {
|
|
484
591
|
// Trim whitespace from input
|
|
485
592
|
const trimmed = payload.value.trim();
|
|
593
|
+
const url = validateURL(trimmed, def);
|
|
486
594
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
continue: !def.abort,
|
|
498
|
-
});
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
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;
|
|
501
605
|
}
|
|
502
606
|
|
|
503
|
-
|
|
504
|
-
|
|
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;
|
|
616
|
+
}
|
|
505
617
|
|
|
506
|
-
if (
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
payload.issues.push({
|
|
510
|
-
code: "invalid_format",
|
|
511
|
-
format: "url",
|
|
512
|
-
note: "Invalid hostname",
|
|
513
|
-
pattern: def.hostname.source,
|
|
514
|
-
input: payload.value,
|
|
515
|
-
inst,
|
|
516
|
-
continue: !def.abort,
|
|
517
|
-
});
|
|
518
|
-
}
|
|
618
|
+
if (url === true) {
|
|
619
|
+
payload.value = stripTabAndNewline(trimmed);
|
|
620
|
+
return;
|
|
519
621
|
}
|
|
520
622
|
|
|
521
|
-
if (def.
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
continue: !def.abort,
|
|
532
|
-
});
|
|
533
|
-
}
|
|
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
|
+
});
|
|
534
633
|
}
|
|
535
634
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
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
|
+
});
|
|
543
645
|
}
|
|
544
646
|
|
|
647
|
+
// Set the output value based on normalize flag
|
|
648
|
+
payload.value = def.normalize ? url.href : stripTabAndNewline(trimmed);
|
|
649
|
+
|
|
545
650
|
return;
|
|
546
651
|
} catch (_) {
|
|
547
652
|
payload.issues.push({
|
|
@@ -574,8 +679,12 @@ export const $ZodEmoji: core.$constructor<$ZodEmoji> = /*@__PURE__*/ core.$const
|
|
|
574
679
|
|
|
575
680
|
////////////////////////////// ZodNanoID //////////////////////////////
|
|
576
681
|
|
|
577
|
-
export interface $ZodNanoIDDef extends $ZodStringFormatDef<"nanoid"> {
|
|
578
|
-
|
|
682
|
+
export interface $ZodNanoIDDef extends $ZodStringFormatDef<"nanoid"> {
|
|
683
|
+
length?: number | undefined;
|
|
684
|
+
}
|
|
685
|
+
export interface $ZodNanoIDInternals extends $ZodStringFormatInternals<"nanoid"> {
|
|
686
|
+
def: $ZodNanoIDDef;
|
|
687
|
+
}
|
|
579
688
|
|
|
580
689
|
export interface $ZodNanoID extends $ZodType {
|
|
581
690
|
_zod: $ZodNanoIDInternals;
|
|
@@ -584,7 +693,9 @@ export interface $ZodNanoID extends $ZodType {
|
|
|
584
693
|
export const $ZodNanoID: core.$constructor<$ZodNanoID> = /*@__PURE__*/ core.$constructor(
|
|
585
694
|
"$ZodNanoID",
|
|
586
695
|
(inst, def): void => {
|
|
587
|
-
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);
|
|
588
699
|
$ZodStringFormat.init(inst, def);
|
|
589
700
|
}
|
|
590
701
|
);
|
|
@@ -782,8 +893,6 @@ export interface $ZodIPv4 extends $ZodType {
|
|
|
782
893
|
export const $ZodIPv4: core.$constructor<$ZodIPv4> = /*@__PURE__*/ core.$constructor("$ZodIPv4", (inst, def): void => {
|
|
783
894
|
def.pattern ??= regexes.ipv4;
|
|
784
895
|
$ZodStringFormat.init(inst, def);
|
|
785
|
-
|
|
786
|
-
inst._zod.bag.format = `ipv4`;
|
|
787
896
|
});
|
|
788
897
|
|
|
789
898
|
////////////////////////////// ZodIPv6 //////////////////////////////
|
|
@@ -800,18 +909,20 @@ export interface $ZodIPv6 extends $ZodType {
|
|
|
800
909
|
_zod: $ZodIPv6Internals;
|
|
801
910
|
}
|
|
802
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
|
+
|
|
803
920
|
export const $ZodIPv6: core.$constructor<$ZodIPv6> = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def): void => {
|
|
804
921
|
def.pattern ??= regexes.ipv6;
|
|
805
922
|
$ZodStringFormat.init(inst, def);
|
|
806
923
|
|
|
807
|
-
inst._zod.bag.format = `ipv6`;
|
|
808
|
-
|
|
809
924
|
inst._zod.check = (payload) => {
|
|
810
|
-
|
|
811
|
-
// @ts-ignore
|
|
812
|
-
new URL(`http://[${payload.value}]`);
|
|
813
|
-
// return;
|
|
814
|
-
} catch {
|
|
925
|
+
if (!isValidIPv6(payload.value)) {
|
|
815
926
|
payload.issues.push({
|
|
816
927
|
code: "invalid_format",
|
|
817
928
|
format: "ipv6",
|
|
@@ -839,8 +950,6 @@ export interface $ZodMAC extends $ZodType {
|
|
|
839
950
|
export const $ZodMAC: core.$constructor<$ZodMAC> = /*@__PURE__*/ core.$constructor("$ZodMAC", (inst, def): void => {
|
|
840
951
|
def.pattern ??= regexes.mac(def.delimiter);
|
|
841
952
|
$ZodStringFormat.init(inst, def);
|
|
842
|
-
|
|
843
|
-
inst._zod.bag.format = `mac`;
|
|
844
953
|
});
|
|
845
954
|
|
|
846
955
|
////////////////////////////// ZodCIDRv4 //////////////////////////////
|
|
@@ -879,6 +988,17 @@ export interface $ZodCIDRv6 extends $ZodType {
|
|
|
879
988
|
_zod: $ZodCIDRv6Internals;
|
|
880
989
|
}
|
|
881
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
|
+
|
|
882
1002
|
export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$constructor(
|
|
883
1003
|
"$ZodCIDRv6",
|
|
884
1004
|
(inst, def): void => {
|
|
@@ -886,17 +1006,7 @@ export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$con
|
|
|
886
1006
|
$ZodStringFormat.init(inst, def);
|
|
887
1007
|
|
|
888
1008
|
inst._zod.check = (payload) => {
|
|
889
|
-
|
|
890
|
-
try {
|
|
891
|
-
if (parts.length !== 2) throw new Error();
|
|
892
|
-
const [address, prefix] = parts;
|
|
893
|
-
if (!prefix) throw new Error();
|
|
894
|
-
const prefixNum = Number(prefix);
|
|
895
|
-
if (`${prefixNum}` !== prefix) throw new Error();
|
|
896
|
-
if (prefixNum < 0 || prefixNum > 128) throw new Error();
|
|
897
|
-
// @ts-ignore
|
|
898
|
-
new URL(`http://[${address}]`);
|
|
899
|
-
} catch {
|
|
1009
|
+
if (!isValidCIDRv6(payload.value)) {
|
|
900
1010
|
payload.issues.push({
|
|
901
1011
|
code: "invalid_format",
|
|
902
1012
|
format: "cidrv6",
|
|
@@ -931,14 +1041,15 @@ export interface $ZodBase64 extends $ZodType {
|
|
|
931
1041
|
_zod: $ZodBase64Internals;
|
|
932
1042
|
}
|
|
933
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
|
+
|
|
934
1047
|
export const $ZodBase64: core.$constructor<$ZodBase64> = /*@__PURE__*/ core.$constructor(
|
|
935
1048
|
"$ZodBase64",
|
|
936
1049
|
(inst, def): void => {
|
|
937
|
-
def.pattern ??=
|
|
1050
|
+
def.pattern ??= base64Charset;
|
|
938
1051
|
$ZodStringFormat.init(inst, def);
|
|
939
1052
|
|
|
940
|
-
inst._zod.bag.contentEncoding = "base64";
|
|
941
|
-
|
|
942
1053
|
inst._zod.check = (payload) => {
|
|
943
1054
|
if (isValidBase64(payload.value)) return;
|
|
944
1055
|
|
|
@@ -953,9 +1064,12 @@ export const $ZodBase64: core.$constructor<$ZodBase64> = /*@__PURE__*/ core.$con
|
|
|
953
1064
|
}
|
|
954
1065
|
);
|
|
955
1066
|
|
|
956
|
-
//////////////////////////////
|
|
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
|
+
|
|
957
1071
|
export function isValidBase64URL(data: string): boolean {
|
|
958
|
-
if (!
|
|
1072
|
+
if (!base64urlCharset.test(data)) return false;
|
|
959
1073
|
const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
|
|
960
1074
|
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
|
|
961
1075
|
return isValidBase64(padded);
|
|
@@ -971,11 +1085,9 @@ export interface $ZodBase64URL extends $ZodType {
|
|
|
971
1085
|
export const $ZodBase64URL: core.$constructor<$ZodBase64URL> = /*@__PURE__*/ core.$constructor(
|
|
972
1086
|
"$ZodBase64URL",
|
|
973
1087
|
(inst, def): void => {
|
|
974
|
-
def.pattern ??=
|
|
1088
|
+
def.pattern ??= base64urlCharset;
|
|
975
1089
|
$ZodStringFormat.init(inst, def);
|
|
976
1090
|
|
|
977
|
-
inst._zod.bag.contentEncoding = "base64url";
|
|
978
|
-
|
|
979
1091
|
inst._zod.check = (payload) => {
|
|
980
1092
|
if (isValidBase64URL(payload.value)) return;
|
|
981
1093
|
|
|
@@ -1004,6 +1116,103 @@ export const $ZodE164: core.$constructor<$ZodE164> = /*@__PURE__*/ core.$constru
|
|
|
1004
1116
|
$ZodStringFormat.init(inst, def);
|
|
1005
1117
|
});
|
|
1006
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
|
+
|
|
1007
1216
|
////////////////////////////// ZodJWT //////////////////////////////
|
|
1008
1217
|
|
|
1009
1218
|
export function isValidJWT(token: string, algorithm: util.JWTAlgorithm | null = null): boolean {
|
|
@@ -1120,7 +1329,7 @@ export interface $ZodNumber<Input = unknown> extends $ZodType {
|
|
|
1120
1329
|
export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, def) => {
|
|
1121
1330
|
$ZodType.init(inst, def);
|
|
1122
1331
|
|
|
1123
|
-
inst._zod.pattern =
|
|
1332
|
+
inst._zod.pattern = regexes.number;
|
|
1124
1333
|
inst._zod.parse = (payload, _ctx) => {
|
|
1125
1334
|
if (def.coerce)
|
|
1126
1335
|
try {
|
|
@@ -1136,7 +1345,7 @@ export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$con
|
|
|
1136
1345
|
? Number.isNaN(input)
|
|
1137
1346
|
? "NaN"
|
|
1138
1347
|
: !Number.isFinite(input)
|
|
1139
|
-
?
|
|
1348
|
+
? String(input)
|
|
1140
1349
|
: undefined
|
|
1141
1350
|
: undefined;
|
|
1142
1351
|
|
|
@@ -1155,15 +1364,19 @@ export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$con
|
|
|
1155
1364
|
///////////////////////////////////////////////
|
|
1156
1365
|
////////// ZodNumberFormat //////////
|
|
1157
1366
|
///////////////////////////////////////////////
|
|
1158
|
-
export interface $ZodNumberFormatDef extends $
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
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>;
|
|
1162
1375
|
isst: errors.$ZodIssueInvalidType;
|
|
1163
1376
|
}
|
|
1164
1377
|
|
|
1165
|
-
export interface $ZodNumberFormat extends $ZodType {
|
|
1166
|
-
_zod: $ZodNumberFormatInternals
|
|
1378
|
+
export interface $ZodNumberFormat<Format extends $ZodNumberFormats = $ZodNumberFormats> extends $ZodType {
|
|
1379
|
+
_zod: $ZodNumberFormatInternals<Format>;
|
|
1167
1380
|
}
|
|
1168
1381
|
|
|
1169
1382
|
export const $ZodNumberFormat: core.$constructor<$ZodNumberFormat> = /*@__PURE__*/ core.$constructor(
|
|
@@ -1278,16 +1491,20 @@ export const $ZodBigInt: core.$constructor<$ZodBigInt> = /*@__PURE__*/ core.$con
|
|
|
1278
1491
|
///////////////////////////////////////////////
|
|
1279
1492
|
////////// ZodBigIntFormat //////////
|
|
1280
1493
|
///////////////////////////////////////////////
|
|
1281
|
-
export interface $ZodBigIntFormatDef extends $
|
|
1494
|
+
export interface $ZodBigIntFormatDef<Format extends $ZodBigIntFormats = $ZodBigIntFormats>
|
|
1495
|
+
extends $ZodBigIntDef,
|
|
1496
|
+
checks.$ZodCheckBigIntFormatDef<Format> {
|
|
1282
1497
|
check: "bigint_format";
|
|
1283
1498
|
}
|
|
1284
1499
|
|
|
1285
|
-
export interface $ZodBigIntFormatInternals extends $
|
|
1286
|
-
|
|
1500
|
+
export interface $ZodBigIntFormatInternals<Format extends $ZodBigIntFormats = $ZodBigIntFormats>
|
|
1501
|
+
extends $ZodBigIntInternals<bigint>,
|
|
1502
|
+
checks.$ZodCheckBigIntFormatInternals<Format> {
|
|
1503
|
+
def: $ZodBigIntFormatDef<Format>;
|
|
1287
1504
|
}
|
|
1288
1505
|
|
|
1289
|
-
export interface $ZodBigIntFormat extends $ZodType {
|
|
1290
|
-
_zod: $ZodBigIntFormatInternals
|
|
1506
|
+
export interface $ZodBigIntFormat<Format extends $ZodBigIntFormats = $ZodBigIntFormats> extends $ZodType {
|
|
1507
|
+
_zod: $ZodBigIntFormatInternals<Format>;
|
|
1291
1508
|
}
|
|
1292
1509
|
|
|
1293
1510
|
export const $ZodBigIntFormat: core.$constructor<$ZodBigIntFormat> = /*@__PURE__*/ core.$constructor(
|
|
@@ -1637,6 +1854,9 @@ function handleArrayResult(result: ParsePayload<any>, final: ParsePayload<any[]>
|
|
|
1637
1854
|
export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def) => {
|
|
1638
1855
|
$ZodType.init(inst, def);
|
|
1639
1856
|
|
|
1857
|
+
const memo = core.globalConfig.memoizer;
|
|
1858
|
+
memo?.attach(inst);
|
|
1859
|
+
|
|
1640
1860
|
inst._zod.parse = (payload, ctx) => {
|
|
1641
1861
|
const input = payload.value;
|
|
1642
1862
|
|
|
@@ -1651,8 +1871,9 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
|
|
|
1651
1871
|
return payload;
|
|
1652
1872
|
}
|
|
1653
1873
|
|
|
1654
|
-
payload.value = Array(input.length);
|
|
1874
|
+
payload.value = memo ? memo.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
|
|
1655
1875
|
const proms: Promise<any>[] = [];
|
|
1876
|
+
const abortEarly = ctx?.abortEarly;
|
|
1656
1877
|
for (let i = 0; i < input.length; i++) {
|
|
1657
1878
|
const item = input[i];
|
|
1658
1879
|
const result = def.element._zod.run(
|
|
@@ -1667,6 +1888,8 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
|
|
|
1667
1888
|
proms.push(result.then((result) => handleArrayResult(result, payload, i)));
|
|
1668
1889
|
} else {
|
|
1669
1890
|
handleArrayResult(result, payload, i);
|
|
1891
|
+
// the element's payload is authoritative here, since handleArrayResult forwards every issue; an object's is not, because it drops a failed absent optional
|
|
1892
|
+
if (abortEarly && result.issues.length !== 0 && util.aborted(result)) break;
|
|
1670
1893
|
}
|
|
1671
1894
|
}
|
|
1672
1895
|
|
|
@@ -1687,12 +1910,12 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
|
|
|
1687
1910
|
//////////////////////////////////////////
|
|
1688
1911
|
|
|
1689
1912
|
type OptionalOutSchema = { _zod: { optout: "optional" } };
|
|
1690
|
-
type OptionalInSchema = { _zod: { optin: "optional" } };
|
|
1913
|
+
type OptionalInSchema = { _zod: { optin: "optional" | "defaulted" } };
|
|
1691
1914
|
|
|
1692
1915
|
export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T
|
|
1693
1916
|
? util.IsAny<T[keyof T]> extends true
|
|
1694
1917
|
? Record<string, unknown>
|
|
1695
|
-
:
|
|
1918
|
+
: { [k in string]: core.output<T[keyof T]> }
|
|
1696
1919
|
: keyof (T & Extra) extends never
|
|
1697
1920
|
? Record<string, never>
|
|
1698
1921
|
: util.Prettify<
|
|
@@ -1736,7 +1959,7 @@ export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<st
|
|
|
1736
1959
|
export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T
|
|
1737
1960
|
? util.IsAny<T[keyof T]> extends true
|
|
1738
1961
|
? Record<string, unknown>
|
|
1739
|
-
:
|
|
1962
|
+
: { [k in string]: core.input<T[keyof T]> }
|
|
1740
1963
|
: keyof (T & Extra) extends never
|
|
1741
1964
|
? Record<string, never>
|
|
1742
1965
|
: util.Prettify<
|
|
@@ -1752,19 +1975,24 @@ function handlePropertyResult(
|
|
|
1752
1975
|
final: ParsePayload,
|
|
1753
1976
|
key: PropertyKey,
|
|
1754
1977
|
input: any,
|
|
1755
|
-
|
|
1756
|
-
|
|
1978
|
+
optin: "optional" | "defaulted" | undefined,
|
|
1979
|
+
optout: "optional" | undefined
|
|
1757
1980
|
) {
|
|
1758
1981
|
const isPresent = key in input;
|
|
1982
|
+
const isOptionalOut = optout === "optional";
|
|
1983
|
+
// 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.
|
|
1984
|
+
if (!isPresent && isOptionalOut && optin === "optional") {
|
|
1985
|
+
return;
|
|
1986
|
+
}
|
|
1759
1987
|
if (result.issues.length) {
|
|
1760
1988
|
// For optional-in/out schemas, ignore errors on absent keys.
|
|
1761
|
-
if (
|
|
1989
|
+
if (optin !== undefined && isOptionalOut && !isPresent) {
|
|
1762
1990
|
return;
|
|
1763
1991
|
}
|
|
1764
1992
|
final.issues.push(...util.prefixIssues(key, result.issues));
|
|
1765
1993
|
}
|
|
1766
1994
|
|
|
1767
|
-
if (!isPresent &&
|
|
1995
|
+
if (!isPresent && optin === undefined) {
|
|
1768
1996
|
if (!result.issues.length) {
|
|
1769
1997
|
final.issues.push({
|
|
1770
1998
|
code: "invalid_type",
|
|
@@ -1777,7 +2005,7 @@ function handlePropertyResult(
|
|
|
1777
2005
|
}
|
|
1778
2006
|
|
|
1779
2007
|
if (result.value === undefined) {
|
|
1780
|
-
if (isPresent) {
|
|
2008
|
+
if (isPresent || (optin === "defaulted" && !isOptionalOut)) {
|
|
1781
2009
|
(final.value as any)[key] = undefined;
|
|
1782
2010
|
}
|
|
1783
2011
|
} else {
|
|
@@ -1835,18 +2063,27 @@ export interface $ZodObject<
|
|
|
1835
2063
|
out Params extends $ZodObjectConfig = $ZodObjectConfig,
|
|
1836
2064
|
> extends $ZodType<any, any, $ZodObjectInternals<Shape, Params>> {}
|
|
1837
2065
|
|
|
2066
|
+
// one shared instance; a fresh [] per schema cost 56 bytes retained
|
|
2067
|
+
const NO_SYMBOL_KEYS: symbol[] = [];
|
|
2068
|
+
|
|
1838
2069
|
function normalizeDef(def: $ZodObjectDef) {
|
|
1839
2070
|
const keys = Object.keys(def.shape);
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
2071
|
+
const ownSymbols = Object.getOwnPropertySymbols(def.shape);
|
|
2072
|
+
const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
|
|
2073
|
+
// aliases `keys` when there are no symbols, so a string-only shape keeps one array
|
|
2074
|
+
const allKeys: (string | symbol)[] = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
|
|
2075
|
+
for (const k of allKeys) {
|
|
2076
|
+
if (!(def.shape as any)?.[k]?._zod?.traits?.has("$ZodType")) {
|
|
2077
|
+
throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
|
|
1843
2078
|
}
|
|
1844
2079
|
}
|
|
1845
2080
|
const okeys = util.optionalKeys(def.shape);
|
|
1846
2081
|
|
|
1847
2082
|
return {
|
|
1848
2083
|
...def,
|
|
1849
|
-
|
|
2084
|
+
allKeys,
|
|
2085
|
+
symbolKeys,
|
|
2086
|
+
// string-only: handleCatchall matches it against `for...in`, which never yields a symbol
|
|
1850
2087
|
keySet: new Set(keys),
|
|
1851
2088
|
numKeys: keys.length,
|
|
1852
2089
|
optionalKeys: new Set(okeys),
|
|
@@ -1857,21 +2094,31 @@ function handleCatchall(
|
|
|
1857
2094
|
proms: Promise<any>[],
|
|
1858
2095
|
input: any,
|
|
1859
2096
|
payload: ParsePayload,
|
|
1860
|
-
ctx:
|
|
2097
|
+
ctx: ParseContextInternal,
|
|
1861
2098
|
def: ReturnType<typeof normalizeDef>,
|
|
1862
|
-
inst: $ZodObject
|
|
2099
|
+
inst: $ZodObject,
|
|
2100
|
+
abortEarly: boolean
|
|
1863
2101
|
) {
|
|
1864
2102
|
const unrecognized: string[] = [];
|
|
1865
2103
|
const keySet = def.keySet;
|
|
1866
2104
|
const _catchall = def.catchall!._zod;
|
|
1867
2105
|
const t = _catchall.def.type;
|
|
1868
|
-
const
|
|
1869
|
-
const
|
|
2106
|
+
const optin = _catchall.optin;
|
|
2107
|
+
const optout = _catchall.optout;
|
|
2108
|
+
// starts at 0, not the current length: the shape phase already ran and may have aborted
|
|
2109
|
+
let seen = 0;
|
|
1870
2110
|
for (const key in input) {
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
2111
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
2112
|
+
if (util.aborted(payload, seen)) break;
|
|
2113
|
+
seen = payload.issues.length;
|
|
2114
|
+
}
|
|
2115
|
+
// Must precede the __proto__ branch: a declared key is not unrecognized, even though the shape loop deliberately strips __proto__ from the parsed output.
|
|
1874
2116
|
if (keySet.has(key)) continue;
|
|
2117
|
+
// 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.
|
|
2118
|
+
if (key === "__proto__") {
|
|
2119
|
+
if (t === "never") unrecognized.push(key);
|
|
2120
|
+
continue;
|
|
2121
|
+
}
|
|
1875
2122
|
if (t === "never") {
|
|
1876
2123
|
unrecognized.push(key);
|
|
1877
2124
|
continue;
|
|
@@ -1879,9 +2126,9 @@ function handleCatchall(
|
|
|
1879
2126
|
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
|
1880
2127
|
|
|
1881
2128
|
if (r instanceof Promise) {
|
|
1882
|
-
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input,
|
|
2129
|
+
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
|
|
1883
2130
|
} else {
|
|
1884
|
-
handlePropertyResult(r, payload, key, input,
|
|
2131
|
+
handlePropertyResult(r, payload, key, input, optin, optout);
|
|
1885
2132
|
}
|
|
1886
2133
|
}
|
|
1887
2134
|
|
|
@@ -1891,6 +2138,8 @@ function handleCatchall(
|
|
|
1891
2138
|
keys: unrecognized,
|
|
1892
2139
|
input,
|
|
1893
2140
|
inst,
|
|
2141
|
+
// 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.
|
|
2142
|
+
continue: true,
|
|
1894
2143
|
});
|
|
1895
2144
|
}
|
|
1896
2145
|
|
|
@@ -1903,32 +2152,35 @@ function handleCatchall(
|
|
|
1903
2152
|
export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
|
|
1904
2153
|
// requires cast because technically $ZodObject doesn't extend
|
|
1905
2154
|
$ZodType.init(inst, def);
|
|
1906
|
-
// const sh = def.shape;
|
|
1907
2155
|
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
});
|
|
2156
|
+
// 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
|
|
2157
|
+
const sh = desc?.get ? (desc.get as util.ShapeGetter).raw : (def.shape ?? {});
|
|
2158
|
+
if (sh) {
|
|
2159
|
+
// Freezes the shape on first read, so its getters resolve once and every later read sees the same schemas.
|
|
2160
|
+
const get: util.ShapeGetter = () => {
|
|
2161
|
+
const newSh = { ...sh };
|
|
2162
|
+
Object.defineProperty(def, "shape", { value: newSh });
|
|
2163
|
+
get.raw = newSh;
|
|
2164
|
+
return newSh;
|
|
2165
|
+
};
|
|
2166
|
+
get.raw = sh;
|
|
2167
|
+
Object.defineProperty(def, "shape", { get });
|
|
1920
2168
|
}
|
|
1921
2169
|
|
|
1922
2170
|
const _normalized = util.cached(() => normalizeDef(def));
|
|
1923
2171
|
|
|
1924
|
-
util.
|
|
1925
|
-
const shape = def.shape;
|
|
2172
|
+
util.defineLazyInternal(inst, "propValues", (zod) => {
|
|
2173
|
+
const shape = zod.def.shape;
|
|
1926
2174
|
const propValues: util.PropValues = {};
|
|
1927
2175
|
for (const key in shape) {
|
|
1928
2176
|
const field = shape[key]!._zod;
|
|
1929
2177
|
if (field.values) {
|
|
1930
|
-
propValues
|
|
2178
|
+
if (!Object.prototype.hasOwnProperty.call(propValues, key)) {
|
|
2179
|
+
util.assignProp(propValues, key, new Set());
|
|
2180
|
+
}
|
|
1931
2181
|
for (const v of field.values) propValues[key].add(v);
|
|
2182
|
+
// 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.
|
|
2183
|
+
if (field.optin !== undefined) propValues[key].add(undefined);
|
|
1932
2184
|
}
|
|
1933
2185
|
}
|
|
1934
2186
|
return propValues;
|
|
@@ -1938,6 +2190,8 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
|
|
|
1938
2190
|
const catchall = def.catchall;
|
|
1939
2191
|
|
|
1940
2192
|
let value!: typeof _normalized.value;
|
|
2193
|
+
const memo = core.globalConfig.memoizer;
|
|
2194
|
+
memo?.attach(inst);
|
|
1941
2195
|
|
|
1942
2196
|
inst._zod.parse = (payload, ctx) => {
|
|
1943
2197
|
value ??= _normalized.value;
|
|
@@ -1952,21 +2206,28 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
|
|
|
1952
2206
|
return payload;
|
|
1953
2207
|
}
|
|
1954
2208
|
|
|
1955
|
-
payload.value = {};
|
|
2209
|
+
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
|
|
1956
2210
|
|
|
1957
2211
|
const proms: Promise<any>[] = [];
|
|
1958
2212
|
const shape = value.shape;
|
|
2213
|
+
const abortEarly = ctx?.abortEarly;
|
|
2214
|
+
let seen = payload.issues.length;
|
|
1959
2215
|
|
|
1960
|
-
for (const key of value.
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
2216
|
+
for (const key of value.allKeys) {
|
|
2217
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
2218
|
+
if (util.aborted(payload, seen)) break;
|
|
2219
|
+
seen = payload.issues.length;
|
|
2220
|
+
}
|
|
2221
|
+
if (key === "__proto__") continue;
|
|
2222
|
+
const el = (shape as any)[key]!;
|
|
2223
|
+
const optin = el._zod.optin;
|
|
2224
|
+
const optout = el._zod.optout;
|
|
1964
2225
|
|
|
1965
2226
|
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
|
|
1966
2227
|
if (r instanceof Promise) {
|
|
1967
|
-
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input,
|
|
2228
|
+
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
|
|
1968
2229
|
} else {
|
|
1969
|
-
handlePropertyResult(r, payload, key, input,
|
|
2230
|
+
handlePropertyResult(r, payload, key, input, optin, optout);
|
|
1970
2231
|
}
|
|
1971
2232
|
}
|
|
1972
2233
|
|
|
@@ -1974,7 +2235,7 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
|
|
|
1974
2235
|
return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
1975
2236
|
}
|
|
1976
2237
|
|
|
1977
|
-
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
|
|
2238
|
+
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst, abortEarly === true);
|
|
1978
2239
|
};
|
|
1979
2240
|
});
|
|
1980
2241
|
|
|
@@ -1987,63 +2248,71 @@ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$
|
|
|
1987
2248
|
const superParse = inst._zod.parse;
|
|
1988
2249
|
const _normalized = util.cached(() => normalizeDef(def));
|
|
1989
2250
|
|
|
2251
|
+
const memo = core.globalConfig.memoizer;
|
|
2252
|
+
|
|
1990
2253
|
const generateFastpass = (shape: any) => {
|
|
1991
|
-
const doc = new Doc(["shape", "payload", "ctx"]);
|
|
1992
2254
|
const normalized = _normalized.value;
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
}
|
|
2255
|
+
const syms = normalized.symbolKeys;
|
|
2256
|
+
// a symbol has no source literal, so it is read as `syms[i]` off the closed-over scope
|
|
2257
|
+
const doc = new Doc(["payload", "ctx"], { shape, inst, memo, syms });
|
|
2258
|
+
|
|
2259
|
+
const parseStr = (k: string) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
|
|
2260
|
+
|
|
2261
|
+
// 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
|
|
2262
|
+
const prefixStr = (id: string, k: string) => `
|
|
2263
|
+
let ${id}_ab = false;
|
|
2264
|
+
for (let i = 0; i < ${id}.issues.length; i++) {
|
|
2265
|
+
const iss = ${id}.issues[i];
|
|
2266
|
+
iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
|
|
2267
|
+
payload.issues.push(iss);
|
|
2268
|
+
if (iss.continue !== true) ${id}_ab = true;
|
|
2269
|
+
}
|
|
2270
|
+
if (${id}_ab && ctx && ctx.abortEarly) {
|
|
2271
|
+
payload.value = newResult;
|
|
2272
|
+
return payload;
|
|
2273
|
+
}`;
|
|
1998
2274
|
|
|
1999
2275
|
doc.write(`const input = payload.value;`);
|
|
2000
2276
|
|
|
2001
2277
|
const ids: any = Object.create(null);
|
|
2002
2278
|
let counter = 0;
|
|
2003
|
-
for (const key of normalized.
|
|
2279
|
+
for (const key of normalized.allKeys) {
|
|
2004
2280
|
ids[key] = `key_${counter++}`;
|
|
2005
2281
|
}
|
|
2006
2282
|
|
|
2007
2283
|
// A: preserve key order {
|
|
2008
|
-
doc.write(`const newResult = {};`);
|
|
2009
|
-
for (const key of normalized.
|
|
2284
|
+
doc.write(memo ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
|
|
2285
|
+
for (const key of normalized.allKeys) {
|
|
2286
|
+
if (key === "__proto__") continue;
|
|
2010
2287
|
const id = ids[key];
|
|
2011
|
-
const k = util.esc(key);
|
|
2288
|
+
const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : util.esc(key);
|
|
2289
|
+
const isPresent = `${k} in input`;
|
|
2012
2290
|
const schema = shape[key];
|
|
2013
|
-
const
|
|
2291
|
+
const optin = schema?._zod?.optin;
|
|
2292
|
+
const isOptionalIn = optin !== undefined;
|
|
2014
2293
|
const isOptionalOut = schema?._zod?.optout === "optional";
|
|
2015
2294
|
|
|
2016
|
-
doc.write(`const ${id} = ${parseStr(
|
|
2295
|
+
doc.write(`const ${id} = ${parseStr(k)};`);
|
|
2017
2296
|
|
|
2018
2297
|
if (isOptionalIn && isOptionalOut) {
|
|
2019
|
-
// For optional-in/out schemas, ignore errors on absent keys
|
|
2298
|
+
// 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.
|
|
2299
|
+
const assign = optin === "optional" ? `${id}_present` : `${id}.value !== undefined || ${id}_present`;
|
|
2020
2300
|
doc.write(`
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
...iss,
|
|
2025
|
-
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
2026
|
-
})));
|
|
2301
|
+
const ${id}_present = ${isPresent};
|
|
2302
|
+
if (!${id}.issues.length || ${id}_present) {
|
|
2303
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
2027
2304
|
}
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
if (${k} in input) {
|
|
2032
|
-
newResult[${k}] = undefined;
|
|
2305
|
+
|
|
2306
|
+
if (${assign}) {
|
|
2307
|
+
newResult[${k}] = ${id}.value;
|
|
2033
2308
|
}
|
|
2034
|
-
} else {
|
|
2035
|
-
newResult[${k}] = ${id}.value;
|
|
2036
2309
|
}
|
|
2037
|
-
|
|
2310
|
+
|
|
2038
2311
|
`);
|
|
2039
2312
|
} else if (!isOptionalIn) {
|
|
2040
2313
|
doc.write(`
|
|
2041
|
-
const ${id}_present = ${
|
|
2042
|
-
if (${id}.issues.length) {
|
|
2043
|
-
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
2044
|
-
...iss,
|
|
2045
|
-
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
2046
|
-
})));
|
|
2314
|
+
const ${id}_present = ${isPresent};
|
|
2315
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
2047
2316
|
}
|
|
2048
2317
|
if (!${id}_present && !${id}.issues.length) {
|
|
2049
2318
|
payload.issues.push({
|
|
@@ -2052,42 +2321,38 @@ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$
|
|
|
2052
2321
|
input: undefined,
|
|
2053
2322
|
path: [${k}]
|
|
2054
2323
|
});
|
|
2324
|
+
if (ctx && ctx.abortEarly) {
|
|
2325
|
+
payload.value = newResult;
|
|
2326
|
+
return payload;
|
|
2327
|
+
}
|
|
2055
2328
|
}
|
|
2056
2329
|
|
|
2057
2330
|
if (${id}_present) {
|
|
2058
|
-
|
|
2059
|
-
newResult[${k}] = undefined;
|
|
2060
|
-
} else {
|
|
2061
|
-
newResult[${k}] = ${id}.value;
|
|
2062
|
-
}
|
|
2331
|
+
newResult[${k}] = ${id}.value;
|
|
2063
2332
|
}
|
|
2064
2333
|
|
|
2065
2334
|
`);
|
|
2066
2335
|
} else {
|
|
2067
2336
|
doc.write(`
|
|
2068
|
-
if (${id}.issues.length) {
|
|
2069
|
-
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
2070
|
-
...iss,
|
|
2071
|
-
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
2072
|
-
})));
|
|
2337
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
2073
2338
|
}
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
}
|
|
2339
|
+
`);
|
|
2340
|
+
if (optin === "defaulted") {
|
|
2341
|
+
doc.write(`newResult[${k}] = ${id}.value;`);
|
|
2342
|
+
} else {
|
|
2343
|
+
doc.write(`
|
|
2344
|
+
if (${id}.value !== undefined || ${isPresent}) {
|
|
2080
2345
|
newResult[${k}] = ${id}.value;
|
|
2081
2346
|
}
|
|
2082
|
-
|
|
2083
2347
|
`);
|
|
2348
|
+
}
|
|
2084
2349
|
}
|
|
2085
2350
|
}
|
|
2086
2351
|
|
|
2087
2352
|
doc.write(`payload.value = newResult;`);
|
|
2088
2353
|
doc.write(`return payload;`);
|
|
2089
|
-
|
|
2090
|
-
return (payload: any, ctx: any) =>
|
|
2354
|
+
// 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
|
|
2355
|
+
return doc.compile() as (payload: any, ctx: any) => any;
|
|
2091
2356
|
};
|
|
2092
2357
|
|
|
2093
2358
|
let fastpass!: ReturnType<typeof generateFastpass>;
|
|
@@ -2120,7 +2385,7 @@ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$
|
|
|
2120
2385
|
payload = fastpass(payload, ctx);
|
|
2121
2386
|
|
|
2122
2387
|
if (!catchall) return payload;
|
|
2123
|
-
return handleCatchall([], input, payload, ctx, value, inst);
|
|
2388
|
+
return handleCatchall([], input, payload, ctx, value, inst, ctx?.abortEarly === true);
|
|
2124
2389
|
}
|
|
2125
2390
|
|
|
2126
2391
|
return superParse(payload, ctx);
|
|
@@ -2155,7 +2420,7 @@ export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $Zo
|
|
|
2155
2420
|
output: $InferUnionOutput<T[number]>;
|
|
2156
2421
|
input: $InferUnionInput<T[number]>;
|
|
2157
2422
|
// if any element in the union is optional, then the union is optional
|
|
2158
|
-
optin: IsOptionalIn<T[number]> extends false ? "optional" | undefined : "optional";
|
|
2423
|
+
optin: IsOptionalIn<T[number]> extends false ? "optional" | "defaulted" | undefined : "optional" | "defaulted";
|
|
2159
2424
|
optout: IsOptionalOut<T[number]> extends false ? "optional" | undefined : "optional";
|
|
2160
2425
|
}
|
|
2161
2426
|
|
|
@@ -2192,24 +2457,28 @@ function handleUnionResults(results: ParsePayload[], final: ParsePayload, inst:
|
|
|
2192
2457
|
export const $ZodUnion: core.$constructor<$ZodUnion> = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def) => {
|
|
2193
2458
|
$ZodType.init(inst, def);
|
|
2194
2459
|
|
|
2195
|
-
util.
|
|
2196
|
-
def.options.some((o) => o._zod.optin === "
|
|
2460
|
+
util.defineLazyInternal(inst, "optin", (zod) =>
|
|
2461
|
+
zod.def.options.some((o) => o._zod.optin === "defaulted")
|
|
2462
|
+
? "defaulted"
|
|
2463
|
+
: zod.def.options.some((o) => o._zod.optin !== undefined)
|
|
2464
|
+
? "optional"
|
|
2465
|
+
: undefined
|
|
2197
2466
|
);
|
|
2198
2467
|
|
|
2199
|
-
util.
|
|
2200
|
-
def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined
|
|
2468
|
+
util.defineLazyInternal(inst, "optout", (zod) =>
|
|
2469
|
+
zod.def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined
|
|
2201
2470
|
);
|
|
2202
2471
|
|
|
2203
|
-
util.
|
|
2204
|
-
if (def.options.every((o) => o._zod.values)) {
|
|
2205
|
-
return new Set<util.Primitive>(def.options.flatMap((option) => Array.from(option._zod.values!)));
|
|
2472
|
+
util.defineLazyInternal(inst, "values", (zod) => {
|
|
2473
|
+
if (zod.def.options.every((o) => o._zod.values)) {
|
|
2474
|
+
return new Set<util.Primitive>(zod.def.options.flatMap((option) => Array.from(option._zod.values!)));
|
|
2206
2475
|
}
|
|
2207
2476
|
return undefined;
|
|
2208
2477
|
});
|
|
2209
2478
|
|
|
2210
|
-
util.
|
|
2211
|
-
if (def.options.every((o) => o._zod.pattern)) {
|
|
2212
|
-
const patterns = def.options.map((o) => o._zod.pattern);
|
|
2479
|
+
util.defineLazyInternal(inst, "pattern", (zod) => {
|
|
2480
|
+
if (zod.def.options.every((o) => o._zod.pattern)) {
|
|
2481
|
+
const patterns = zod.def.options.map((o) => o._zod.pattern);
|
|
2213
2482
|
return new RegExp(`^(${patterns.map((p) => util.cleanRegex(p!.source)).join("|")})$`);
|
|
2214
2483
|
}
|
|
2215
2484
|
return undefined;
|
|
@@ -2254,14 +2523,17 @@ function handleExclusiveUnionResults(
|
|
|
2254
2523
|
inst: $ZodUnion,
|
|
2255
2524
|
ctx?: ParseContext
|
|
2256
2525
|
) {
|
|
2257
|
-
const
|
|
2526
|
+
const matches: number[] = [];
|
|
2527
|
+
for (let i = 0; i < results.length; i++) {
|
|
2528
|
+
if (results[i].issues.length === 0) matches.push(i);
|
|
2529
|
+
}
|
|
2258
2530
|
|
|
2259
|
-
if (
|
|
2260
|
-
final.value =
|
|
2531
|
+
if (matches.length === 1) {
|
|
2532
|
+
final.value = results[matches[0]].value;
|
|
2261
2533
|
return final;
|
|
2262
2534
|
}
|
|
2263
2535
|
|
|
2264
|
-
if (
|
|
2536
|
+
if (matches.length === 0) {
|
|
2265
2537
|
// No matches - same as regular union
|
|
2266
2538
|
final.issues.push({
|
|
2267
2539
|
code: "invalid_union",
|
|
@@ -2277,6 +2549,7 @@ function handleExclusiveUnionResults(
|
|
|
2277
2549
|
inst,
|
|
2278
2550
|
errors: [],
|
|
2279
2551
|
inclusive: false,
|
|
2552
|
+
matches,
|
|
2280
2553
|
});
|
|
2281
2554
|
}
|
|
2282
2555
|
|
|
@@ -2348,6 +2621,65 @@ export interface $ZodDiscriminatedUnionInternals<
|
|
|
2348
2621
|
> extends $ZodUnionInternals<Options> {
|
|
2349
2622
|
def: $ZodDiscriminatedUnionDef<Options, Disc>;
|
|
2350
2623
|
propValues: util.PropValues;
|
|
2624
|
+
bag: util.LoosePartial<{
|
|
2625
|
+
optionsMap: Map<util.Primitive, $ZodType | null>;
|
|
2626
|
+
}>;
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2629
|
+
/** The discriminator values a member of `Options` can declare. An omittable discriminator contributes `undefined`, matching what `propValues` claims for it. */
|
|
2630
|
+
export type $DiscriminatorValue<Options extends readonly SomeType[], Disc extends string> = {
|
|
2631
|
+
[I in keyof Options]: Options[I] extends { _zod: { output: infer Out } }
|
|
2632
|
+
? Disc extends keyof Out
|
|
2633
|
+
? Out[Disc]
|
|
2634
|
+
: never
|
|
2635
|
+
: never;
|
|
2636
|
+
}[number];
|
|
2637
|
+
|
|
2638
|
+
/** The member of `Options` that declares `V`. */
|
|
2639
|
+
export type $DiscriminatedOption<Options extends readonly SomeType[], Disc extends string, V> = {
|
|
2640
|
+
[I in keyof Options]: Options[I] extends { _zod: { output: infer Out } }
|
|
2641
|
+
? Disc extends keyof Out
|
|
2642
|
+
? V extends Out[Disc]
|
|
2643
|
+
? Options[I]
|
|
2644
|
+
: never
|
|
2645
|
+
: never
|
|
2646
|
+
: never;
|
|
2647
|
+
}[number];
|
|
2648
|
+
|
|
2649
|
+
/** Returns the option whose discriminator claims `value`, or throws if ambiguous. */
|
|
2650
|
+
export function getDiscriminatedOption<
|
|
2651
|
+
Options extends readonly SomeType[],
|
|
2652
|
+
Disc extends string,
|
|
2653
|
+
const V extends $DiscriminatorValue<Options, Disc>,
|
|
2654
|
+
>(union: $ZodDiscriminatedUnion<Options, Disc>, value: V): $DiscriminatedOption<Options, Disc, V> {
|
|
2655
|
+
const internals = union._zod;
|
|
2656
|
+
let map = internals.bag.optionsMap;
|
|
2657
|
+
if (!map) {
|
|
2658
|
+
map = discriminatorMap(internals.def);
|
|
2659
|
+
internals.bag.optionsMap = map;
|
|
2660
|
+
}
|
|
2661
|
+
const option = map.get(value as util.Primitive);
|
|
2662
|
+
if (option === null) throw new Error(`Ambiguous discriminator value "${String(value)}"`);
|
|
2663
|
+
return option as any;
|
|
2664
|
+
}
|
|
2665
|
+
|
|
2666
|
+
function discriminatorMap(def: $ZodDiscriminatedUnionDef<readonly SomeType[]>): Map<util.Primitive, $ZodType | null> {
|
|
2667
|
+
const map = new Map<util.Primitive, $ZodType | null>();
|
|
2668
|
+
for (const option of def.options as readonly $ZodType[]) {
|
|
2669
|
+
const values = option._zod.propValues?.[def.discriminator];
|
|
2670
|
+
if (!values || values.size === 0)
|
|
2671
|
+
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
2672
|
+
for (const value of values) {
|
|
2673
|
+
if (map.has(value)) {
|
|
2674
|
+
if (value !== undefined) throw new Error(`Duplicate discriminator value "${String(value)}"`);
|
|
2675
|
+
// keep the collision marked so a later member cannot reclaim it
|
|
2676
|
+
map.set(value, null);
|
|
2677
|
+
} else {
|
|
2678
|
+
map.set(value, option);
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
return map;
|
|
2351
2683
|
}
|
|
2352
2684
|
|
|
2353
2685
|
export interface $ZodDiscriminatedUnion<
|
|
@@ -2365,39 +2697,37 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
|
|
|
2365
2697
|
$ZodUnion.init(inst, def);
|
|
2366
2698
|
|
|
2367
2699
|
const _super = inst._zod.parse;
|
|
2368
|
-
util.
|
|
2700
|
+
util.defineLazyInternal(inst, "propValues", (zod) => {
|
|
2369
2701
|
const propValues: util.PropValues = {};
|
|
2370
|
-
|
|
2702
|
+
let undefinedCount = 0;
|
|
2703
|
+
for (const option of zod.def.options) {
|
|
2371
2704
|
const pv = option._zod.propValues;
|
|
2372
2705
|
if (!pv || Object.keys(pv).length === 0)
|
|
2373
|
-
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
2706
|
+
throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
|
|
2707
|
+
if (pv[zod.def.discriminator]?.has(undefined)) undefinedCount++;
|
|
2374
2708
|
for (const [k, v] of Object.entries(pv!)) {
|
|
2375
|
-
if (!propValues
|
|
2709
|
+
if (!Object.prototype.hasOwnProperty.call(propValues, k)) {
|
|
2710
|
+
util.assignProp(propValues, k, new Set());
|
|
2711
|
+
}
|
|
2376
2712
|
for (const val of v) {
|
|
2377
2713
|
propValues[k].add(val);
|
|
2378
2714
|
}
|
|
2379
2715
|
}
|
|
2380
2716
|
}
|
|
2717
|
+
if (!zod.def.unionFallback && undefinedCount > 1) propValues[zod.def.discriminator]?.delete(undefined);
|
|
2381
2718
|
return propValues;
|
|
2382
2719
|
});
|
|
2383
2720
|
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
const
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
if (!values || values.size === 0)
|
|
2390
|
-
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
|
|
2391
|
-
for (const v of values) {
|
|
2392
|
-
if (map.has(v)) {
|
|
2393
|
-
throw new Error(`Duplicate discriminator value "${String(v)}"`);
|
|
2394
|
-
}
|
|
2395
|
-
map.set(v, o);
|
|
2396
|
-
}
|
|
2721
|
+
// 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.
|
|
2722
|
+
def.options.forEach((option, i) => {
|
|
2723
|
+
const propShape = util.rawShape(option._zod.def);
|
|
2724
|
+
if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) {
|
|
2725
|
+
throw new Error(`Invalid discriminated union option at index "${i}"`);
|
|
2397
2726
|
}
|
|
2398
|
-
return map;
|
|
2399
2727
|
});
|
|
2400
2728
|
|
|
2729
|
+
const disc = util.cached(() => discriminatorMap(def));
|
|
2730
|
+
|
|
2401
2731
|
inst._zod.parse = (payload, ctx) => {
|
|
2402
2732
|
const input = payload.value;
|
|
2403
2733
|
if (!util.isObject(input)) {
|
|
@@ -2411,15 +2741,16 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
|
|
|
2411
2741
|
return payload;
|
|
2412
2742
|
}
|
|
2413
2743
|
|
|
2414
|
-
const
|
|
2415
|
-
|
|
2744
|
+
const value = input?.[def.discriminator];
|
|
2745
|
+
const opt = disc.value.get(value as util.Primitive);
|
|
2746
|
+
// forward metadata cannot choose an encoder for an absent tag
|
|
2747
|
+
if (opt && (value !== undefined || ctx.direction !== "backward")) {
|
|
2416
2748
|
return opt._zod.run(payload, ctx) as any;
|
|
2417
2749
|
}
|
|
2418
2750
|
|
|
2419
2751
|
// Fall back to union matching when the fast discriminator path fails:
|
|
2420
2752
|
// - explicitly enabled via unionFallback, or
|
|
2421
|
-
// - during backward direction (encode), since codec-based discriminators
|
|
2422
|
-
// have different values in forward vs backward directions
|
|
2753
|
+
// - during backward direction (encode), since codec-based discriminators have different values in forward vs backward directions
|
|
2423
2754
|
if (def.unionFallback || ctx.direction === "backward") {
|
|
2424
2755
|
return _super(payload, ctx);
|
|
2425
2756
|
}
|
|
@@ -2430,7 +2761,7 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
|
|
|
2430
2761
|
errors: [],
|
|
2431
2762
|
note: "No matching discriminator",
|
|
2432
2763
|
discriminator: def.discriminator,
|
|
2433
|
-
options: Array.from(disc.value.keys()),
|
|
2764
|
+
options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
|
|
2434
2765
|
input,
|
|
2435
2766
|
path: [def.discriminator],
|
|
2436
2767
|
inst,
|
|
@@ -2492,7 +2823,7 @@ export const $ZodIntersection: core.$constructor<$ZodIntersection> = /*@__PURE__
|
|
|
2492
2823
|
}
|
|
2493
2824
|
);
|
|
2494
2825
|
|
|
2495
|
-
function mergeValues(
|
|
2826
|
+
export function mergeValues(
|
|
2496
2827
|
a: any,
|
|
2497
2828
|
b: any
|
|
2498
2829
|
): { valid: true; data: any } | { valid: false; mergeErrorPath: (string | number)[] } {
|
|
@@ -2510,7 +2841,9 @@ function mergeValues(
|
|
|
2510
2841
|
const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
2511
2842
|
|
|
2512
2843
|
const newObj: any = { ...a, ...b };
|
|
2844
|
+
if (Object.prototype.hasOwnProperty.call(newObj, "__proto__")) delete newObj.__proto__;
|
|
2513
2845
|
for (const key of sharedKeys) {
|
|
2846
|
+
if (key === "__proto__") continue;
|
|
2514
2847
|
const sharedValue = mergeValues(a[key], b[key]);
|
|
2515
2848
|
if (!sharedValue.valid) {
|
|
2516
2849
|
return {
|
|
@@ -2551,44 +2884,52 @@ function mergeValues(
|
|
|
2551
2884
|
}
|
|
2552
2885
|
|
|
2553
2886
|
function handleIntersectionResults(result: ParsePayload, left: ParsePayload, right: ParsePayload): ParsePayload {
|
|
2554
|
-
// Track which side(s)
|
|
2887
|
+
// 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.
|
|
2555
2888
|
const unrecKeys = new Map<string, { l?: true; r?: true }>();
|
|
2556
2889
|
let unrecIssue: errors.$ZodRawIssue | undefined;
|
|
2890
|
+
const keyIssues = new Map<string, errors.$ZodRawIssue>();
|
|
2557
2891
|
|
|
2558
|
-
|
|
2559
|
-
|
|
2892
|
+
const collect = (iss: errors.$ZodRawIssue, side: "l" | "r"): boolean => {
|
|
2893
|
+
let keys: string[];
|
|
2894
|
+
if (iss.code === "unrecognized_keys" && !iss.path?.length) {
|
|
2560
2895
|
unrecIssue ??= iss;
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2896
|
+
keys = iss.keys as string[];
|
|
2897
|
+
} else if (iss.code === "invalid_key" && iss.origin === "record" && iss.path?.length === 1) {
|
|
2898
|
+
const k = String(iss.path[0]);
|
|
2899
|
+
if (!keyIssues.has(k)) keyIssues.set(k, iss);
|
|
2900
|
+
keys = [k];
|
|
2565
2901
|
} else {
|
|
2566
|
-
|
|
2902
|
+
return false;
|
|
2567
2903
|
}
|
|
2904
|
+
for (const k of keys) {
|
|
2905
|
+
if (!unrecKeys.has(k)) unrecKeys.set(k, {});
|
|
2906
|
+
unrecKeys.get(k)![side] = true;
|
|
2907
|
+
}
|
|
2908
|
+
return true;
|
|
2909
|
+
};
|
|
2910
|
+
|
|
2911
|
+
for (const iss of left.issues) {
|
|
2912
|
+
if (!collect(iss, "l")) result.issues.push(iss);
|
|
2568
2913
|
}
|
|
2569
2914
|
|
|
2570
2915
|
for (const iss of right.issues) {
|
|
2571
|
-
if (iss
|
|
2572
|
-
for (const k of iss.keys) {
|
|
2573
|
-
if (!unrecKeys.has(k)) unrecKeys.set(k, {});
|
|
2574
|
-
unrecKeys.get(k)!.r = true;
|
|
2575
|
-
}
|
|
2576
|
-
} else {
|
|
2577
|
-
result.issues.push(iss);
|
|
2578
|
-
}
|
|
2916
|
+
if (!collect(iss, "r")) result.issues.push(iss);
|
|
2579
2917
|
}
|
|
2580
2918
|
|
|
2581
|
-
// Report only keys
|
|
2919
|
+
// Report only keys rejected by BOTH sides
|
|
2582
2920
|
const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
|
|
2583
|
-
if (bothKeys.length
|
|
2584
|
-
|
|
2921
|
+
if (bothKeys.length) {
|
|
2922
|
+
const aggregated = unrecIssue ? bothKeys.filter((k) => (unrecIssue!.keys as string[]).includes(k)) : [];
|
|
2923
|
+
if (aggregated.length) result.issues.push({ ...unrecIssue!, keys: aggregated });
|
|
2924
|
+
for (const k of bothKeys) {
|
|
2925
|
+
if (!aggregated.includes(k) && keyIssues.has(k)) result.issues.push(keyIssues.get(k)!);
|
|
2926
|
+
}
|
|
2585
2927
|
}
|
|
2586
2928
|
|
|
2587
|
-
if (util.aborted(result)) return result;
|
|
2588
|
-
|
|
2589
2929
|
const merged = mergeValues(left.value, right.value);
|
|
2590
2930
|
|
|
2591
2931
|
if (!merged.valid) {
|
|
2932
|
+
if (util.aborted(result)) return result;
|
|
2592
2933
|
throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
|
|
2593
2934
|
}
|
|
2594
2935
|
|
|
@@ -2624,7 +2965,7 @@ type TupleInputTypeWithOptionals<T extends util.TupleItems> = T extends readonly
|
|
|
2624
2965
|
...infer Prefix extends SomeType[],
|
|
2625
2966
|
infer Tail extends SomeType,
|
|
2626
2967
|
]
|
|
2627
|
-
? Tail["_zod"]["optin"] extends "optional"
|
|
2968
|
+
? Tail["_zod"]["optin"] extends "optional" | "defaulted"
|
|
2628
2969
|
? [...TupleInputTypeWithOptionals<Prefix>, core.input<Tail>?]
|
|
2629
2970
|
: TupleInputTypeNoOptionals<T>
|
|
2630
2971
|
: [];
|
|
@@ -2666,6 +3007,8 @@ export interface $ZodTuple<
|
|
|
2666
3007
|
export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def) => {
|
|
2667
3008
|
$ZodType.init(inst, def);
|
|
2668
3009
|
const items = def.items;
|
|
3010
|
+
const memo = core.globalConfig.memoizer;
|
|
3011
|
+
memo?.attach(inst);
|
|
2669
3012
|
|
|
2670
3013
|
inst._zod.parse = (payload, ctx) => {
|
|
2671
3014
|
const input = payload.value;
|
|
@@ -2679,7 +3022,7 @@ export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$const
|
|
|
2679
3022
|
return payload;
|
|
2680
3023
|
}
|
|
2681
3024
|
|
|
2682
|
-
payload.value = [];
|
|
3025
|
+
payload.value = memo ? memo.alloc(inst, payload, [] as unknown[], ctx) : [];
|
|
2683
3026
|
const proms: Promise<any>[] = [];
|
|
2684
3027
|
|
|
2685
3028
|
const optinStart = getTupleOptStart(items, "optin");
|
|
@@ -2709,11 +3052,11 @@ export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$const
|
|
|
2709
3052
|
}
|
|
2710
3053
|
}
|
|
2711
3054
|
|
|
2712
|
-
// Run every item in parallel, collecting results into an indexed
|
|
2713
|
-
// array. The post-processing in `handleTupleResults` walks them in
|
|
2714
|
-
// order so it can decide whether an absent optional-output error can
|
|
2715
|
-
// truncate the tail or must be reported to preserve required output.
|
|
3055
|
+
// 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.
|
|
2716
3056
|
const itemResults: ParsePayload[] = new Array(items.length);
|
|
3057
|
+
// only tracked when there is a rest loop to skip
|
|
3058
|
+
const abortEarly = def.rest ? ctx?.abortEarly : undefined;
|
|
3059
|
+
let itemAborted = false;
|
|
2717
3060
|
for (let i = 0; i < items.length; i++) {
|
|
2718
3061
|
const r = items[i]._zod.run({ value: input[i], issues: [] }, ctx);
|
|
2719
3062
|
if (r instanceof Promise) {
|
|
@@ -2724,13 +3067,20 @@ export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$const
|
|
|
2724
3067
|
);
|
|
2725
3068
|
} else {
|
|
2726
3069
|
itemResults[i] = r;
|
|
3070
|
+
if (abortEarly && !itemAborted && r.issues.length) itemAborted = util.aborted(r);
|
|
2727
3071
|
}
|
|
2728
3072
|
}
|
|
2729
3073
|
|
|
2730
|
-
|
|
3074
|
+
// sound because rest is non-empty exactly when every fixed index is present, the one case handleTupleResults cannot discard an item's issues
|
|
3075
|
+
if (def.rest && !itemAborted) {
|
|
2731
3076
|
let i = items.length - 1;
|
|
2732
3077
|
const rest = input.slice(items.length);
|
|
3078
|
+
let seen = payload.issues.length;
|
|
2733
3079
|
for (const el of rest) {
|
|
3080
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
3081
|
+
if (util.aborted(payload, seen)) break;
|
|
3082
|
+
seen = payload.issues.length;
|
|
3083
|
+
}
|
|
2734
3084
|
i++;
|
|
2735
3085
|
const result = def.rest._zod.run({ value: el, issues: [] }, ctx);
|
|
2736
3086
|
if (result instanceof Promise) {
|
|
@@ -2750,7 +3100,9 @@ export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$const
|
|
|
2750
3100
|
|
|
2751
3101
|
function getTupleOptStart(items: readonly $ZodType[], key: "optin" | "optout") {
|
|
2752
3102
|
for (let i = items.length - 1; i >= 0; i--) {
|
|
2753
|
-
|
|
3103
|
+
// optin is a three-rung ladder so any rung above `undefined` permits an absent slot; optout stays two-valued.
|
|
3104
|
+
const omittable = key === "optin" ? items[i]._zod.optin !== undefined : items[i]._zod.optout === "optional";
|
|
3105
|
+
if (!omittable) return i + 1;
|
|
2754
3106
|
}
|
|
2755
3107
|
return 0;
|
|
2756
3108
|
}
|
|
@@ -2769,12 +3121,15 @@ function handleTupleResults(
|
|
|
2769
3121
|
input: unknown[],
|
|
2770
3122
|
optoutStart: number
|
|
2771
3123
|
) {
|
|
2772
|
-
// Walk results in order. Mirror $ZodObject's swallow-on-absent-optional
|
|
2773
|
-
// rule, but only after `optoutStart`: the first index where the output
|
|
2774
|
-
// tuple tail can be absent.
|
|
3124
|
+
// 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.
|
|
2775
3125
|
for (let i = 0; i < items.length; i++) {
|
|
2776
3126
|
const r = itemResults[i];
|
|
2777
3127
|
const isPresent = i < input.length;
|
|
3128
|
+
// 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`.
|
|
3129
|
+
if (!isPresent && i >= optoutStart && items[i]._zod.optin === "optional") {
|
|
3130
|
+
final.value.length = i;
|
|
3131
|
+
break;
|
|
3132
|
+
}
|
|
2778
3133
|
if (r.issues.length) {
|
|
2779
3134
|
if (!isPresent && i >= optoutStart) {
|
|
2780
3135
|
final.value.length = i;
|
|
@@ -2817,6 +3172,7 @@ export interface $ZodRecordDef<Key extends $ZodRecordKey = $ZodRecordKey, Value
|
|
|
2817
3172
|
valueType: Value;
|
|
2818
3173
|
/** @default "strict" - errors on keys not matching keyType. "loose" passes through non-matching keys unchanged. */
|
|
2819
3174
|
mode?: "strict" | "loose";
|
|
3175
|
+
partial?: boolean;
|
|
2820
3176
|
}
|
|
2821
3177
|
|
|
2822
3178
|
// export type $InferZodRecordOutput<
|
|
@@ -2856,7 +3212,10 @@ export type $InferZodRecordInput<
|
|
|
2856
3212
|
Value extends SomeType = $ZodType,
|
|
2857
3213
|
> = Key extends $partial
|
|
2858
3214
|
? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>>
|
|
2859
|
-
:
|
|
3215
|
+
: // 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.
|
|
3216
|
+
[Value] extends [OptionalInSchema]
|
|
3217
|
+
? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>>
|
|
3218
|
+
: Record<core.input<Key> & PropertyKey, core.input<Value>>;
|
|
2860
3219
|
|
|
2861
3220
|
export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType>
|
|
2862
3221
|
extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
|
|
@@ -2874,6 +3233,8 @@ export interface $ZodRecord<Key extends $ZodRecordKey = $ZodRecordKey, Value ext
|
|
|
2874
3233
|
|
|
2875
3234
|
export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, def) => {
|
|
2876
3235
|
$ZodType.init(inst, def);
|
|
3236
|
+
const memo = core.globalConfig.memoizer;
|
|
3237
|
+
memo?.attach(inst);
|
|
2877
3238
|
|
|
2878
3239
|
inst._zod.parse = (payload, ctx) => {
|
|
2879
3240
|
const input = payload.value;
|
|
@@ -2889,15 +3250,18 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2889
3250
|
return payload;
|
|
2890
3251
|
}
|
|
2891
3252
|
|
|
3253
|
+
// 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
|
|
2892
3254
|
const proms: Promise<any>[] = [];
|
|
2893
3255
|
|
|
2894
3256
|
const values = def.keyType._zod.values;
|
|
2895
|
-
if (values) {
|
|
2896
|
-
payload.value = {};
|
|
3257
|
+
if (values && !def.partial) {
|
|
3258
|
+
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
|
|
2897
3259
|
const recordKeys = new Set<string | symbol>();
|
|
2898
3260
|
for (const key of values) {
|
|
2899
3261
|
if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
|
|
2900
3262
|
recordKeys.add(typeof key === "number" ? key.toString() : key);
|
|
3263
|
+
// A declared __proto__ is stripped but is not an unrecognized key.
|
|
3264
|
+
if (key === "__proto__") continue;
|
|
2901
3265
|
const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
|
|
2902
3266
|
if (keyResult instanceof Promise) {
|
|
2903
3267
|
throw new Error("Async schemas not supported in object keys currently");
|
|
@@ -2914,6 +3278,7 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2914
3278
|
continue;
|
|
2915
3279
|
}
|
|
2916
3280
|
const outKey = keyResult.value as PropertyKey;
|
|
3281
|
+
if (outKey === "__proto__") continue;
|
|
2917
3282
|
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
|
2918
3283
|
|
|
2919
3284
|
if (result instanceof Promise) {
|
|
@@ -2937,8 +3302,14 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2937
3302
|
let unrecognized!: string[];
|
|
2938
3303
|
for (const key in input) {
|
|
2939
3304
|
if (!recordKeys.has(key)) {
|
|
2940
|
-
|
|
2941
|
-
|
|
3305
|
+
if (def.mode === "loose") {
|
|
3306
|
+
// skip __proto__ so it can't replace the result prototype via the assignment setter on the plain {} we build into
|
|
3307
|
+
if (key === "__proto__") continue;
|
|
3308
|
+
payload.value[key] = input[key];
|
|
3309
|
+
} else {
|
|
3310
|
+
unrecognized = unrecognized ?? [];
|
|
3311
|
+
unrecognized.push(key);
|
|
3312
|
+
}
|
|
2942
3313
|
}
|
|
2943
3314
|
}
|
|
2944
3315
|
if (unrecognized && unrecognized.length > 0) {
|
|
@@ -2948,10 +3319,13 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2948
3319
|
input,
|
|
2949
3320
|
inst,
|
|
2950
3321
|
keys: unrecognized,
|
|
3322
|
+
continue: true,
|
|
2951
3323
|
});
|
|
2952
3324
|
}
|
|
2953
3325
|
} else {
|
|
2954
|
-
payload.value = {};
|
|
3326
|
+
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
|
|
3327
|
+
// 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.
|
|
3328
|
+
let unrecognized!: string[];
|
|
2955
3329
|
// Reflect.ownKeys for Symbol-key support; filter non-enumerable to match z.object()
|
|
2956
3330
|
for (const key of Reflect.ownKeys(input)) {
|
|
2957
3331
|
if (key === "__proto__") continue;
|
|
@@ -2961,8 +3335,7 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2961
3335
|
throw new Error("Async schemas not supported in object keys currently");
|
|
2962
3336
|
}
|
|
2963
3337
|
|
|
2964
|
-
// Numeric string fallback: if key is a numeric string and failed, retry with Number(key)
|
|
2965
|
-
// This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
|
|
3338
|
+
// 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
|
|
2966
3339
|
const checkNumericKey = typeof key === "string" && regexes.number.test(key) && keyResult.issues.length;
|
|
2967
3340
|
if (checkNumericKey) {
|
|
2968
3341
|
const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
|
|
@@ -2978,6 +3351,9 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2978
3351
|
if (def.mode === "loose") {
|
|
2979
3352
|
// Pass through unchanged
|
|
2980
3353
|
payload.value[key] = input[key];
|
|
3354
|
+
} else if (values) {
|
|
3355
|
+
unrecognized = unrecognized ?? [];
|
|
3356
|
+
unrecognized.push(key as string);
|
|
2981
3357
|
} else {
|
|
2982
3358
|
// Default "strict" behavior: error on invalid key
|
|
2983
3359
|
payload.issues.push({
|
|
@@ -2992,6 +3368,10 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2992
3368
|
continue;
|
|
2993
3369
|
}
|
|
2994
3370
|
|
|
3371
|
+
// 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
|
|
3372
|
+
const outKey = keyResult.value as PropertyKey;
|
|
3373
|
+
if (outKey === "__proto__") continue;
|
|
3374
|
+
|
|
2995
3375
|
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
|
2996
3376
|
|
|
2997
3377
|
if (result instanceof Promise) {
|
|
@@ -3000,16 +3380,27 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
3000
3380
|
if (result.issues.length) {
|
|
3001
3381
|
payload.issues.push(...util.prefixIssues(key, result.issues));
|
|
3002
3382
|
}
|
|
3003
|
-
payload.value[
|
|
3383
|
+
payload.value[outKey] = result.value;
|
|
3004
3384
|
})
|
|
3005
3385
|
);
|
|
3006
3386
|
} else {
|
|
3007
3387
|
if (result.issues.length) {
|
|
3008
3388
|
payload.issues.push(...util.prefixIssues(key, result.issues));
|
|
3009
3389
|
}
|
|
3010
|
-
payload.value[
|
|
3390
|
+
payload.value[outKey] = result.value;
|
|
3011
3391
|
}
|
|
3012
3392
|
}
|
|
3393
|
+
|
|
3394
|
+
if (unrecognized && unrecognized.length > 0) {
|
|
3395
|
+
payload.issues.push({
|
|
3396
|
+
code: "unrecognized_keys",
|
|
3397
|
+
|
|
3398
|
+
input,
|
|
3399
|
+
inst,
|
|
3400
|
+
keys: unrecognized,
|
|
3401
|
+
continue: true,
|
|
3402
|
+
});
|
|
3403
|
+
}
|
|
3013
3404
|
}
|
|
3014
3405
|
|
|
3015
3406
|
if (proms.length) {
|
|
@@ -3046,6 +3437,8 @@ export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType
|
|
|
3046
3437
|
|
|
3047
3438
|
export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$constructor("$ZodMap", (inst, def) => {
|
|
3048
3439
|
$ZodType.init(inst, def);
|
|
3440
|
+
const memo = core.globalConfig.memoizer;
|
|
3441
|
+
memo?.attach(inst);
|
|
3049
3442
|
|
|
3050
3443
|
inst._zod.parse = (payload, ctx) => {
|
|
3051
3444
|
const input = payload.value;
|
|
@@ -3061,9 +3454,15 @@ export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$construct
|
|
|
3061
3454
|
}
|
|
3062
3455
|
|
|
3063
3456
|
const proms: Promise<any>[] = [];
|
|
3064
|
-
payload.value = new Map();
|
|
3457
|
+
payload.value = memo ? memo.alloc(inst, payload, new Map(), ctx) : new Map();
|
|
3458
|
+
const abortEarly = ctx?.abortEarly;
|
|
3459
|
+
let seen = payload.issues.length;
|
|
3065
3460
|
|
|
3066
3461
|
for (const [key, value] of input) {
|
|
3462
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
3463
|
+
if (util.aborted(payload, seen)) break;
|
|
3464
|
+
seen = payload.issues.length;
|
|
3465
|
+
}
|
|
3067
3466
|
const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
|
|
3068
3467
|
const valueResult = def.valueType._zod.run({ value: value, issues: [] }, ctx);
|
|
3069
3468
|
|
|
@@ -3150,6 +3549,8 @@ export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
|
|
|
3150
3549
|
|
|
3151
3550
|
export const $ZodSet: core.$constructor<$ZodSet> = /*@__PURE__*/ core.$constructor("$ZodSet", (inst, def) => {
|
|
3152
3551
|
$ZodType.init(inst, def);
|
|
3552
|
+
const memo = core.globalConfig.memoizer;
|
|
3553
|
+
memo?.attach(inst);
|
|
3153
3554
|
|
|
3154
3555
|
inst._zod.parse = (payload, ctx) => {
|
|
3155
3556
|
const input = payload.value;
|
|
@@ -3164,8 +3565,14 @@ export const $ZodSet: core.$constructor<$ZodSet> = /*@__PURE__*/ core.$construct
|
|
|
3164
3565
|
}
|
|
3165
3566
|
|
|
3166
3567
|
const proms: Promise<any>[] = [];
|
|
3167
|
-
payload.value = new Set();
|
|
3568
|
+
payload.value = memo ? memo.alloc(inst, payload, new Set(), ctx) : new Set();
|
|
3569
|
+
const abortEarly = ctx?.abortEarly;
|
|
3570
|
+
let seen = payload.issues.length;
|
|
3168
3571
|
for (const item of input) {
|
|
3572
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
3573
|
+
if (util.aborted(payload, seen)) break;
|
|
3574
|
+
seen = payload.issues.length;
|
|
3575
|
+
}
|
|
3169
3576
|
const result = def.valueType._zod.run({ value: item, issues: [] }, ctx);
|
|
3170
3577
|
if (result instanceof Promise) {
|
|
3171
3578
|
proms.push(result.then((result) => handleSetResult(result, payload)));
|
|
@@ -3224,12 +3631,13 @@ export const $ZodEnum: core.$constructor<$ZodEnum> = /*@__PURE__*/ core.$constru
|
|
|
3224
3631
|
const valuesSet = new Set<util.Primitive>(values);
|
|
3225
3632
|
inst._zod.values = valuesSet;
|
|
3226
3633
|
|
|
3227
|
-
inst
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
.join("|")})$`
|
|
3232
|
-
|
|
3634
|
+
util.defineLazyInternal(inst, "pattern", (zod) => {
|
|
3635
|
+
const patternValues = util.getEnumValues(zod.def.entries).filter((k) => util.propertyKeyTypes.has(typeof k));
|
|
3636
|
+
// unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
|
|
3637
|
+
return new RegExp(
|
|
3638
|
+
patternValues.length ? `^(${patternValues.map((o) => util.escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$"
|
|
3639
|
+
);
|
|
3640
|
+
});
|
|
3233
3641
|
|
|
3234
3642
|
inst._zod.parse = (payload, _ctx) => {
|
|
3235
3643
|
const input = payload.value;
|
|
@@ -3275,18 +3683,23 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
|
|
|
3275
3683
|
"$ZodLiteral",
|
|
3276
3684
|
(inst, def) => {
|
|
3277
3685
|
$ZodType.init(inst, def);
|
|
3278
|
-
if (def.values.length === 0) {
|
|
3279
|
-
throw new Error("Cannot create literal schema with no valid values");
|
|
3280
|
-
}
|
|
3281
3686
|
|
|
3282
3687
|
const values = new Set<util.Literal>(def.values);
|
|
3283
3688
|
inst._zod.values = values;
|
|
3284
|
-
inst._zod.pattern = new RegExp(
|
|
3285
|
-
`^(${def.values
|
|
3286
3689
|
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3690
|
+
util.defineLazyInternal(inst, "pattern", (zod) => {
|
|
3691
|
+
const vals = zod.def.values;
|
|
3692
|
+
// unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
|
|
3693
|
+
return new RegExp(
|
|
3694
|
+
vals.length
|
|
3695
|
+
? `^(${vals
|
|
3696
|
+
.map((o: util.Literal) =>
|
|
3697
|
+
typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)
|
|
3698
|
+
)
|
|
3699
|
+
.join("|")})$`
|
|
3700
|
+
: "^[^\\s\\S]$"
|
|
3701
|
+
);
|
|
3702
|
+
});
|
|
3290
3703
|
|
|
3291
3704
|
inst._zod.parse = (payload, _ctx) => {
|
|
3292
3705
|
const input = payload.value;
|
|
@@ -3423,6 +3836,8 @@ export const $ZodTransform: core.$constructor<$ZodTransform> = /*@__PURE__*/ cor
|
|
|
3423
3836
|
(inst, def) => {
|
|
3424
3837
|
$ZodType.init(inst, def);
|
|
3425
3838
|
inst._zod.optin = "optional";
|
|
3839
|
+
core.globalConfig.memoizer?.guard(inst);
|
|
3840
|
+
|
|
3426
3841
|
inst._zod.parse = (payload, ctx) => {
|
|
3427
3842
|
if (ctx.direction === "backward") {
|
|
3428
3843
|
throw new core.$ZodEncodeError(inst.constructor.name);
|
|
@@ -3433,7 +3848,6 @@ export const $ZodTransform: core.$constructor<$ZodTransform> = /*@__PURE__*/ cor
|
|
|
3433
3848
|
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
|
|
3434
3849
|
return output.then((output) => {
|
|
3435
3850
|
payload.value = output;
|
|
3436
|
-
payload.fallback = true;
|
|
3437
3851
|
return payload;
|
|
3438
3852
|
});
|
|
3439
3853
|
}
|
|
@@ -3443,7 +3857,6 @@ export const $ZodTransform: core.$constructor<$ZodTransform> = /*@__PURE__*/ cor
|
|
|
3443
3857
|
}
|
|
3444
3858
|
|
|
3445
3859
|
payload.value = _out;
|
|
3446
|
-
payload.fallback = true;
|
|
3447
3860
|
return payload;
|
|
3448
3861
|
};
|
|
3449
3862
|
}
|
|
@@ -3464,7 +3877,7 @@ export interface $ZodOptionalDef<T extends SomeType = $ZodType> extends $ZodType
|
|
|
3464
3877
|
export interface $ZodOptionalInternals<T extends SomeType = $ZodType>
|
|
3465
3878
|
extends $ZodTypeInternals<core.output<T> | undefined, core.input<T> | undefined> {
|
|
3466
3879
|
def: $ZodOptionalDef<T>;
|
|
3467
|
-
optin: "optional";
|
|
3880
|
+
optin: "optional" | "defaulted";
|
|
3468
3881
|
optout: "optional";
|
|
3469
3882
|
isst: never;
|
|
3470
3883
|
values: T["_zod"]["values"];
|
|
@@ -3475,37 +3888,39 @@ export interface $ZodOptional<T extends SomeType = $ZodType> extends $ZodType {
|
|
|
3475
3888
|
_zod: $ZodOptionalInternals<T>;
|
|
3476
3889
|
}
|
|
3477
3890
|
|
|
3478
|
-
function handleOptionalResult(
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
return result;
|
|
3891
|
+
function handleOptionalResult(payload: ParsePayload, result: ParsePayload) {
|
|
3892
|
+
// 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.
|
|
3893
|
+
payload.value = result.issues.length ? undefined : result.value;
|
|
3894
|
+
return payload;
|
|
3483
3895
|
}
|
|
3484
3896
|
|
|
3485
3897
|
export const $ZodOptional: core.$constructor<$ZodOptional> = /*@__PURE__*/ core.$constructor(
|
|
3486
3898
|
"$ZodOptional",
|
|
3487
3899
|
(inst, def) => {
|
|
3488
3900
|
$ZodType.init(inst, def);
|
|
3489
|
-
|
|
3901
|
+
// .optional() propagates absence rather than substituting for it, so a defaulted inner keeps its rung.
|
|
3902
|
+
util.defineLazyInternal(inst, "optin", (zod) =>
|
|
3903
|
+
zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional"
|
|
3904
|
+
);
|
|
3490
3905
|
inst._zod.optout = "optional";
|
|
3491
3906
|
|
|
3492
|
-
util.
|
|
3493
|
-
|
|
3907
|
+
util.defineLazyInternal(inst, "values", (zod) => {
|
|
3908
|
+
const values = (zod.def as $ZodOptionalDef).innerType._zod.values;
|
|
3909
|
+
return values ? new Set([...values, undefined]) : undefined;
|
|
3494
3910
|
});
|
|
3495
|
-
util.
|
|
3496
|
-
const pattern = def.innerType._zod.pattern;
|
|
3911
|
+
util.defineLazyInternal(inst, "pattern", (zod) => {
|
|
3912
|
+
const pattern = (zod.def as $ZodOptionalDef).innerType._zod.pattern;
|
|
3497
3913
|
return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)})?$`) : undefined;
|
|
3498
3914
|
});
|
|
3499
3915
|
|
|
3500
3916
|
inst._zod.parse = (payload, ctx) => {
|
|
3501
|
-
if (def.innerType._zod.optin === "optional") {
|
|
3502
|
-
const input = payload.value;
|
|
3503
|
-
const result = def.innerType._zod.run(payload, ctx);
|
|
3504
|
-
if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, input));
|
|
3505
|
-
return handleOptionalResult(result, input);
|
|
3506
|
-
}
|
|
3507
3917
|
if (payload.value === undefined) {
|
|
3508
|
-
|
|
3918
|
+
// Only the top rung substitutes a value for absence; everything else leaves it intact, which is what .optional() means.
|
|
3919
|
+
if (def.innerType._zod.optin !== "defaulted") return payload;
|
|
3920
|
+
// 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.
|
|
3921
|
+
const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
|
|
3922
|
+
if (result instanceof Promise) return result.then((result) => handleOptionalResult(payload, result));
|
|
3923
|
+
return handleOptionalResult(payload, result);
|
|
3509
3924
|
}
|
|
3510
3925
|
return def.innerType._zod.run(payload, ctx);
|
|
3511
3926
|
};
|
|
@@ -3541,8 +3956,8 @@ export const $ZodExactOptional: core.$constructor<$ZodExactOptional> = /*@__PURE
|
|
|
3541
3956
|
$ZodOptional.init(inst, def);
|
|
3542
3957
|
|
|
3543
3958
|
// Override values/pattern to NOT add undefined
|
|
3544
|
-
util.
|
|
3545
|
-
util.
|
|
3959
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
3960
|
+
util.defineLazyInternal(inst, "pattern", (zod) => zod.def.innerType._zod.pattern);
|
|
3546
3961
|
|
|
3547
3962
|
// Override parse to just delegate (no undefined handling)
|
|
3548
3963
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -3581,16 +3996,16 @@ export const $ZodNullable: core.$constructor<$ZodNullable> = /*@__PURE__*/ core.
|
|
|
3581
3996
|
"$ZodNullable",
|
|
3582
3997
|
(inst, def) => {
|
|
3583
3998
|
$ZodType.init(inst, def);
|
|
3584
|
-
util.
|
|
3585
|
-
util.
|
|
3999
|
+
util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin);
|
|
4000
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
|
|
3586
4001
|
|
|
3587
|
-
util.
|
|
3588
|
-
const pattern = def.innerType._zod.pattern;
|
|
4002
|
+
util.defineLazyInternal(inst, "pattern", (zod) => {
|
|
4003
|
+
const pattern = zod.def.innerType._zod.pattern;
|
|
3589
4004
|
return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)}|null)$`) : undefined;
|
|
3590
4005
|
});
|
|
3591
4006
|
|
|
3592
|
-
util.
|
|
3593
|
-
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
|
|
4007
|
+
util.defineLazyInternal(inst, "values", (zod) => {
|
|
4008
|
+
return zod.def.innerType._zod.values ? new Set([...zod.def.innerType._zod.values, null]) : undefined;
|
|
3594
4009
|
});
|
|
3595
4010
|
|
|
3596
4011
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -3619,7 +4034,7 @@ export interface $ZodDefaultDef<T extends SomeType = $ZodType> extends $ZodTypeD
|
|
|
3619
4034
|
export interface $ZodDefaultInternals<T extends SomeType = $ZodType>
|
|
3620
4035
|
extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
|
|
3621
4036
|
def: $ZodDefaultDef<T>;
|
|
3622
|
-
optin: "
|
|
4037
|
+
optin: "defaulted";
|
|
3623
4038
|
optout?: "optional" | undefined; // required
|
|
3624
4039
|
isst: never;
|
|
3625
4040
|
values: T["_zod"]["values"];
|
|
@@ -3635,8 +4050,8 @@ export const $ZodDefault: core.$constructor<$ZodDefault> = /*@__PURE__*/ core.$c
|
|
|
3635
4050
|
$ZodType.init(inst, def);
|
|
3636
4051
|
|
|
3637
4052
|
// inst._zod.qin = "true";
|
|
3638
|
-
inst._zod.optin = "
|
|
3639
|
-
util.
|
|
4053
|
+
inst._zod.optin = "defaulted";
|
|
4054
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
3640
4055
|
|
|
3641
4056
|
inst._zod.parse = (payload, ctx) => {
|
|
3642
4057
|
if (ctx.direction === "backward") {
|
|
@@ -3684,9 +4099,9 @@ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodType
|
|
|
3684
4099
|
}
|
|
3685
4100
|
|
|
3686
4101
|
export interface $ZodPrefaultInternals<T extends SomeType = $ZodType>
|
|
3687
|
-
extends $ZodTypeInternals<
|
|
4102
|
+
extends $ZodTypeInternals<core.output<T>, core.input<T> | undefined> {
|
|
3688
4103
|
def: $ZodPrefaultDef<T>;
|
|
3689
|
-
optin: "
|
|
4104
|
+
optin: "defaulted";
|
|
3690
4105
|
optout?: "optional" | undefined;
|
|
3691
4106
|
isst: never;
|
|
3692
4107
|
values: T["_zod"]["values"];
|
|
@@ -3701,8 +4116,8 @@ export const $ZodPrefault: core.$constructor<$ZodPrefault> = /*@__PURE__*/ core.
|
|
|
3701
4116
|
(inst, def) => {
|
|
3702
4117
|
$ZodType.init(inst, def);
|
|
3703
4118
|
|
|
3704
|
-
inst._zod.optin = "
|
|
3705
|
-
util.
|
|
4119
|
+
inst._zod.optin = "defaulted";
|
|
4120
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
3706
4121
|
|
|
3707
4122
|
inst._zod.parse = (payload, ctx) => {
|
|
3708
4123
|
if (ctx.direction === "backward") {
|
|
@@ -3748,8 +4163,8 @@ export const $ZodNonOptional: core.$constructor<$ZodNonOptional> = /*@__PURE__*/
|
|
|
3748
4163
|
(inst, def) => {
|
|
3749
4164
|
$ZodType.init(inst, def);
|
|
3750
4165
|
|
|
3751
|
-
util.
|
|
3752
|
-
const v = def.innerType._zod.values;
|
|
4166
|
+
util.defineLazyInternal(inst, "values", (zod) => {
|
|
4167
|
+
const v = zod.def.innerType._zod.values;
|
|
3753
4168
|
return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
|
|
3754
4169
|
});
|
|
3755
4170
|
|
|
@@ -3893,11 +4308,33 @@ export interface $ZodCatch<T extends SomeType = $ZodType> extends $ZodType {
|
|
|
3893
4308
|
_zod: $ZodCatchInternals<T>;
|
|
3894
4309
|
}
|
|
3895
4310
|
|
|
4311
|
+
function handleCatchResult(payload: ParsePayload, result: ParsePayload, def: $ZodCatchDef, ctx: ParseContextInternal) {
|
|
4312
|
+
if (!result.issues.length) {
|
|
4313
|
+
payload.value = result.value;
|
|
4314
|
+
// 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.
|
|
4315
|
+
if (result.memo) payload.memo = true;
|
|
4316
|
+
return payload;
|
|
4317
|
+
}
|
|
4318
|
+
|
|
4319
|
+
// 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.
|
|
4320
|
+
payload.value = def.catchValue({
|
|
4321
|
+
...result,
|
|
4322
|
+
value: payload.value,
|
|
4323
|
+
error: {
|
|
4324
|
+
issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
|
4325
|
+
},
|
|
4326
|
+
input: payload.value,
|
|
4327
|
+
});
|
|
4328
|
+
return payload;
|
|
4329
|
+
}
|
|
4330
|
+
|
|
3896
4331
|
export const $ZodCatch: core.$constructor<$ZodCatch> = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
|
|
3897
4332
|
$ZodType.init(inst, def);
|
|
3898
|
-
inst
|
|
3899
|
-
|
|
3900
|
-
|
|
4333
|
+
util.defineLazyInternal(inst, "optin", (zod) =>
|
|
4334
|
+
zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional"
|
|
4335
|
+
);
|
|
4336
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
|
|
4337
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
3901
4338
|
|
|
3902
4339
|
inst._zod.parse = (payload, ctx) => {
|
|
3903
4340
|
if (ctx.direction === "backward") {
|
|
@@ -3905,41 +4342,12 @@ export const $ZodCatch: core.$constructor<$ZodCatch> = /*@__PURE__*/ core.$const
|
|
|
3905
4342
|
}
|
|
3906
4343
|
|
|
3907
4344
|
// Forward direction (decode): apply catch logic
|
|
3908
|
-
const result = def.innerType._zod.run(payload, ctx);
|
|
4345
|
+
const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
|
|
3909
4346
|
if (result instanceof Promise) {
|
|
3910
|
-
return result.then((result) =>
|
|
3911
|
-
payload.value = result.value;
|
|
3912
|
-
if (result.issues.length) {
|
|
3913
|
-
payload.value = def.catchValue({
|
|
3914
|
-
...payload,
|
|
3915
|
-
error: {
|
|
3916
|
-
issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
|
3917
|
-
},
|
|
3918
|
-
input: payload.value,
|
|
3919
|
-
});
|
|
3920
|
-
payload.issues = [];
|
|
3921
|
-
payload.fallback = true;
|
|
3922
|
-
}
|
|
3923
|
-
|
|
3924
|
-
return payload;
|
|
3925
|
-
});
|
|
3926
|
-
}
|
|
3927
|
-
|
|
3928
|
-
payload.value = result.value;
|
|
3929
|
-
if (result.issues.length) {
|
|
3930
|
-
payload.value = def.catchValue({
|
|
3931
|
-
...payload,
|
|
3932
|
-
error: {
|
|
3933
|
-
issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
|
3934
|
-
},
|
|
3935
|
-
input: payload.value,
|
|
3936
|
-
});
|
|
3937
|
-
|
|
3938
|
-
payload.issues = [];
|
|
3939
|
-
payload.fallback = true;
|
|
4347
|
+
return result.then((result) => handleCatchResult(payload, result, def, ctx));
|
|
3940
4348
|
}
|
|
3941
4349
|
|
|
3942
|
-
return payload;
|
|
4350
|
+
return handleCatchResult(payload, result, def, ctx);
|
|
3943
4351
|
};
|
|
3944
4352
|
});
|
|
3945
4353
|
|
|
@@ -4013,10 +4421,10 @@ export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $Z
|
|
|
4013
4421
|
|
|
4014
4422
|
export const $ZodPipe: core.$constructor<$ZodPipe> = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def) => {
|
|
4015
4423
|
$ZodType.init(inst, def);
|
|
4016
|
-
util.
|
|
4017
|
-
util.
|
|
4018
|
-
util.
|
|
4019
|
-
util.
|
|
4424
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
|
|
4425
|
+
util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
|
|
4426
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
|
|
4427
|
+
util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
|
|
4020
4428
|
|
|
4021
4429
|
inst._zod.parse = (payload, ctx) => {
|
|
4022
4430
|
if (ctx.direction === "backward") {
|
|
@@ -4036,12 +4444,13 @@ export const $ZodPipe: core.$constructor<$ZodPipe> = /*@__PURE__*/ core.$constru
|
|
|
4036
4444
|
});
|
|
4037
4445
|
|
|
4038
4446
|
function handlePipeResult(left: ParsePayload, next: $ZodType, ctx: ParseContextInternal) {
|
|
4039
|
-
|
|
4447
|
+
// 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.
|
|
4448
|
+
if (left.issues.some((iss) => iss.code !== "unrecognized_keys")) {
|
|
4040
4449
|
// prevent further checks
|
|
4041
4450
|
left.aborted = true;
|
|
4042
4451
|
return left;
|
|
4043
4452
|
}
|
|
4044
|
-
return next._zod.run({ value: left.value, issues: left.issues
|
|
4453
|
+
return next._zod.run({ value: left.value, issues: left.issues }, ctx);
|
|
4045
4454
|
}
|
|
4046
4455
|
|
|
4047
4456
|
////////////////////////////////////////////
|
|
@@ -4072,10 +4481,10 @@ export interface $ZodCodec<A extends SomeType = $ZodType, B extends SomeType = $
|
|
|
4072
4481
|
|
|
4073
4482
|
export const $ZodCodec: core.$constructor<$ZodCodec> = /*@__PURE__*/ core.$constructor("$ZodCodec", (inst, def) => {
|
|
4074
4483
|
$ZodType.init(inst, def);
|
|
4075
|
-
util.
|
|
4076
|
-
util.
|
|
4077
|
-
util.
|
|
4078
|
-
util.
|
|
4484
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
|
|
4485
|
+
util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
|
|
4486
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
|
|
4487
|
+
util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
|
|
4079
4488
|
|
|
4080
4489
|
inst._zod.parse = (payload, ctx) => {
|
|
4081
4490
|
const direction = ctx.direction || "forward";
|
|
@@ -4136,19 +4545,22 @@ function handleCodecTxResult(left: ParsePayload, value: any, nextSchema: SomeTyp
|
|
|
4136
4545
|
////////// //////////
|
|
4137
4546
|
/////////////////////////////////////////////////
|
|
4138
4547
|
/////////////////////////////////////////////////
|
|
4139
|
-
export interface $ZodPreprocessDef<B extends SomeType = $ZodType
|
|
4140
|
-
|
|
4548
|
+
export interface $ZodPreprocessDef<B extends SomeType = $ZodType, I = unknown>
|
|
4549
|
+
extends $ZodPipeDef<$ZodTransform<unknown, I>, B> {
|
|
4550
|
+
in: $ZodTransform<unknown, I>;
|
|
4141
4551
|
out: B;
|
|
4142
4552
|
}
|
|
4143
4553
|
|
|
4144
|
-
export interface $ZodPreprocessInternals<B extends SomeType = $ZodType
|
|
4145
|
-
|
|
4554
|
+
export interface $ZodPreprocessInternals<B extends SomeType = $ZodType, I = unknown>
|
|
4555
|
+
extends $ZodPipeInternals<$ZodTransform<unknown, I>, B> {
|
|
4556
|
+
def: $ZodPreprocessDef<B, I>;
|
|
4146
4557
|
optin: B["_zod"]["optin"];
|
|
4147
4558
|
optout: B["_zod"]["optout"];
|
|
4148
4559
|
}
|
|
4149
4560
|
|
|
4150
|
-
export interface $ZodPreprocess<B extends SomeType = $ZodType
|
|
4151
|
-
|
|
4561
|
+
export interface $ZodPreprocess<B extends SomeType = $ZodType, I = unknown>
|
|
4562
|
+
extends $ZodPipe<$ZodTransform<unknown, I>, B> {
|
|
4563
|
+
_zod: $ZodPreprocessInternals<B, I>;
|
|
4152
4564
|
}
|
|
4153
4565
|
|
|
4154
4566
|
export const $ZodPreprocess: core.$constructor<$ZodPreprocess> = /*@__PURE__*/ core.$constructor(
|
|
@@ -4189,10 +4601,10 @@ export const $ZodReadonly: core.$constructor<$ZodReadonly> = /*@__PURE__*/ core.
|
|
|
4189
4601
|
"$ZodReadonly",
|
|
4190
4602
|
(inst, def) => {
|
|
4191
4603
|
$ZodType.init(inst, def);
|
|
4192
|
-
util.
|
|
4193
|
-
util.
|
|
4194
|
-
util.
|
|
4195
|
-
util.
|
|
4604
|
+
util.defineLazyInternal(inst, "propValues", (zod) => zod.def.innerType._zod.propValues);
|
|
4605
|
+
util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
4606
|
+
util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType?._zod?.optin);
|
|
4607
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType?._zod?.optout);
|
|
4196
4608
|
|
|
4197
4609
|
inst._zod.parse = (payload, ctx) => {
|
|
4198
4610
|
if (ctx.direction === "backward") {
|
|
@@ -4208,7 +4620,8 @@ export const $ZodReadonly: core.$constructor<$ZodReadonly> = /*@__PURE__*/ core.
|
|
|
4208
4620
|
);
|
|
4209
4621
|
|
|
4210
4622
|
function handleReadonlyResult(payload: ParsePayload): ParsePayload {
|
|
4211
|
-
|
|
4623
|
+
// 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.
|
|
4624
|
+
if (!payload.memo) payload.value = Object.freeze(payload.value);
|
|
4212
4625
|
return payload;
|
|
4213
4626
|
}
|
|
4214
4627
|
|
|
@@ -4285,6 +4698,51 @@ export type $PartsToTemplateLiteral<Parts extends $ZodTemplateLiteralPart[]> = [
|
|
|
4285
4698
|
: never
|
|
4286
4699
|
: never;
|
|
4287
4700
|
|
|
4701
|
+
// 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
|
|
4702
|
+
function leafPattern(schema: $ZodType): string | undefined {
|
|
4703
|
+
const def = schema._zod.def as { pattern?: RegExp; format?: string; checks?: checks.$ZodCheck[] };
|
|
4704
|
+
let pattern = def.pattern;
|
|
4705
|
+
let isInt = !!def.format?.includes("int");
|
|
4706
|
+
let minimum: number | undefined;
|
|
4707
|
+
let maximum: number | undefined;
|
|
4708
|
+
for (const ch of def.checks ?? []) {
|
|
4709
|
+
const d = ch._zod.def as { pattern?: RegExp; format?: string; minimum?: number; maximum?: number; length?: number };
|
|
4710
|
+
if (d.pattern) pattern = d.pattern;
|
|
4711
|
+
isInt ||= !!d.format?.includes("int");
|
|
4712
|
+
const lo = d.minimum ?? d.length;
|
|
4713
|
+
const hi = d.maximum ?? d.length;
|
|
4714
|
+
if (lo !== undefined && (minimum === undefined || lo > minimum)) minimum = lo;
|
|
4715
|
+
if (hi !== undefined && (maximum === undefined || hi < maximum)) maximum = hi;
|
|
4716
|
+
}
|
|
4717
|
+
if (pattern) return pattern.source;
|
|
4718
|
+
// an empty range matches nothing at runtime, and `{8,5}` is not a legal quantifier
|
|
4719
|
+
if (minimum !== undefined && maximum !== undefined && minimum > maximum) return "(?!)";
|
|
4720
|
+
if (minimum !== undefined || maximum !== undefined) return regexes.string({ minimum, maximum }).source;
|
|
4721
|
+
const own = schema._zod.pattern;
|
|
4722
|
+
return (isInt && own === regexes.number ? regexes.integer : own)?.source;
|
|
4723
|
+
}
|
|
4724
|
+
|
|
4725
|
+
// 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
|
|
4726
|
+
function partPattern(schema: $ZodType): string | undefined {
|
|
4727
|
+
const def = schema._zod.def as { innerType?: $ZodType; options?: $ZodType[] };
|
|
4728
|
+
const own = schema._zod.pattern?.source;
|
|
4729
|
+
// lazy resolves its inner on the internals, not the def
|
|
4730
|
+
const inner = def.innerType ?? (schema._zod as { innerType?: $ZodType }).innerType;
|
|
4731
|
+
if (inner) {
|
|
4732
|
+
const before = inner._zod.pattern?.source;
|
|
4733
|
+
const after = partPattern(inner);
|
|
4734
|
+
if (own && before && after && after !== before) {
|
|
4735
|
+
return own.replace(util.cleanRegex(before), () => util.cleanRegex(after));
|
|
4736
|
+
}
|
|
4737
|
+
return own;
|
|
4738
|
+
}
|
|
4739
|
+
if (def.options) {
|
|
4740
|
+
const sources = def.options.map(partPattern);
|
|
4741
|
+
if (sources.every(Boolean)) return `^(${sources.map((s) => util.cleanRegex(s!)).join("|")})$`;
|
|
4742
|
+
}
|
|
4743
|
+
return leafPattern(schema);
|
|
4744
|
+
}
|
|
4745
|
+
|
|
4288
4746
|
export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__PURE__*/ core.$constructor(
|
|
4289
4747
|
"$ZodTemplateLiteral",
|
|
4290
4748
|
(inst, def) => {
|
|
@@ -4293,18 +4751,11 @@ export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__
|
|
|
4293
4751
|
for (const part of def.parts) {
|
|
4294
4752
|
if (typeof part === "object" && part !== null) {
|
|
4295
4753
|
// is Zod schema
|
|
4296
|
-
|
|
4297
|
-
|
|
4754
|
+
const source = partPattern(part);
|
|
4755
|
+
if (!source) {
|
|
4298
4756
|
throw new Error(`Invalid template literal part, no pattern found: ${[...(part as any)._zod.traits].shift()}`);
|
|
4299
4757
|
}
|
|
4300
|
-
|
|
4301
|
-
const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;
|
|
4302
|
-
|
|
4303
|
-
if (!source) throw new Error(`Invalid template literal part: ${part._zod.traits}`);
|
|
4304
|
-
|
|
4305
|
-
const start = source.startsWith("^") ? 1 : 0;
|
|
4306
|
-
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
4307
|
-
regexParts.push(source.slice(start, end));
|
|
4758
|
+
regexParts.push(util.cleanRegex(source));
|
|
4308
4759
|
} else if (part === null || util.primitiveTypes.has(typeof part)) {
|
|
4309
4760
|
regexParts.push(util.escapeRegex(`${part}`));
|
|
4310
4761
|
} else {
|
|
@@ -4424,35 +4875,45 @@ export const $ZodFunction: core.$constructor<$ZodFunction> = /*@__PURE__*/ core.
|
|
|
4424
4875
|
"$ZodFunction",
|
|
4425
4876
|
(inst, def) => {
|
|
4426
4877
|
$ZodType.init(inst, def);
|
|
4427
|
-
|
|
4878
|
+
// Defined, not assigned: the classic prototype exposes `_def` as a getter with no setter.
|
|
4879
|
+
Object.defineProperty(inst, "_def", { value: def });
|
|
4428
4880
|
inst._zod.def = def;
|
|
4429
4881
|
|
|
4430
4882
|
inst.implement = (func) => {
|
|
4431
4883
|
if (typeof func !== "function") {
|
|
4432
4884
|
throw new Error("implement() must be called with a function");
|
|
4433
4885
|
}
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4886
|
+
// Defined inline so the closure stays anonymous: binding it to a `const` first names it, which costs 256 bytes per implemented function.
|
|
4887
|
+
return Object.defineProperty(
|
|
4888
|
+
function (this: any, ...args: never[]) {
|
|
4889
|
+
const parsedArgs = inst._def.input ? parse(inst._def.input, args) : args;
|
|
4890
|
+
const result = Reflect.apply(func, this, parsedArgs as never[]);
|
|
4891
|
+
if (inst._def.output) {
|
|
4892
|
+
return parse(inst._def.output, result);
|
|
4893
|
+
}
|
|
4894
|
+
return result as any;
|
|
4895
|
+
},
|
|
4896
|
+
"_zod",
|
|
4897
|
+
{ value: inst._zod, enumerable: false }
|
|
4898
|
+
) as any;
|
|
4442
4899
|
};
|
|
4443
4900
|
|
|
4444
4901
|
inst.implementAsync = (func) => {
|
|
4445
4902
|
if (typeof func !== "function") {
|
|
4446
4903
|
throw new Error("implementAsync() must be called with a function");
|
|
4447
4904
|
}
|
|
4448
|
-
return
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4905
|
+
return Object.defineProperty(
|
|
4906
|
+
async function (this: any, ...args: never[]) {
|
|
4907
|
+
const parsedArgs = inst._def.input ? await parseAsync(inst._def.input, args) : args;
|
|
4908
|
+
const result = await Reflect.apply(func, this, parsedArgs as never[]);
|
|
4909
|
+
if (inst._def.output) {
|
|
4910
|
+
return await parseAsync(inst._def.output, result);
|
|
4911
|
+
}
|
|
4912
|
+
return result;
|
|
4913
|
+
},
|
|
4914
|
+
"_zod",
|
|
4915
|
+
{ value: inst._zod, enumerable: false }
|
|
4916
|
+
) as any;
|
|
4456
4917
|
};
|
|
4457
4918
|
|
|
4458
4919
|
inst._zod.parse = (payload, _ctx) => {
|
|
@@ -4576,18 +5037,16 @@ export interface $ZodLazy<T extends SomeType = $ZodType> extends $ZodType {
|
|
|
4576
5037
|
export const $ZodLazy: core.$constructor<$ZodLazy> = /*@__PURE__*/ core.$constructor("$ZodLazy", (inst, def) => {
|
|
4577
5038
|
$ZodType.init(inst, def);
|
|
4578
5039
|
|
|
4579
|
-
// Cache the resolved inner type on the shared `def` so all clones of this
|
|
4580
|
-
// lazy (e.g. via `.describe()`/`.meta()`) share the same inner instance,
|
|
4581
|
-
// preserving identity for cycle detection on recursive schemas.
|
|
5040
|
+
// 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.
|
|
4582
5041
|
util.defineLazy(inst._zod, "innerType", () => {
|
|
4583
5042
|
const d = def as $ZodLazyDef & { _cachedInner?: $ZodType };
|
|
4584
5043
|
if (!d._cachedInner) d._cachedInner = def.getter() as $ZodType;
|
|
4585
5044
|
return d._cachedInner;
|
|
4586
5045
|
});
|
|
4587
|
-
util.
|
|
4588
|
-
util.
|
|
4589
|
-
util.
|
|
4590
|
-
util.
|
|
5046
|
+
util.defineLazyInternal(inst, "pattern", (zod) => zod.innerType?._zod?.pattern);
|
|
5047
|
+
util.defineLazyInternal(inst, "propValues", (zod) => zod.innerType?._zod?.propValues);
|
|
5048
|
+
util.defineLazyInternal(inst, "optin", (zod) => zod.innerType?._zod?.optin ?? undefined);
|
|
5049
|
+
util.defineLazyInternal(inst, "optout", (zod) => zod.innerType?._zod?.optout ?? undefined);
|
|
4591
5050
|
inst._zod.parse = (payload, ctx) => {
|
|
4592
5051
|
const inner = inst._zod.innerType;
|
|
4593
5052
|
return inner._zod.run(payload, ctx);
|
|
@@ -4724,7 +5183,10 @@ export type $ZodStringFormatTypes =
|
|
|
4724
5183
|
| $ZodBase64
|
|
4725
5184
|
| $ZodBase64URL
|
|
4726
5185
|
| $ZodE164
|
|
5186
|
+
| $ZodCreditCard
|
|
5187
|
+
| $ZodIBAN
|
|
4727
5188
|
| $ZodJWT
|
|
4728
5189
|
| $ZodCustomStringFormat<"hex">
|
|
4729
5190
|
| $ZodCustomStringFormat<util.HashFormat>
|
|
4730
|
-
| $ZodCustomStringFormat<"hostname"
|
|
5191
|
+
| $ZodCustomStringFormat<"hostname">
|
|
5192
|
+
| $ZodCustomStringFormat<"currency_code">;
|