@suveren/gateway 0.38.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (764) hide show
  1. package/dist/mcp-server/http.mjs +1 -1
  2. package/dist/ui/assets/index-C-lA_7Lt.js +123 -0
  3. package/dist/ui/assets/index-DM9WXky8.css +1 -0
  4. package/dist/ui/index.html +2 -2
  5. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.d.ts.map +1 -1
  6. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.js +10 -0
  7. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.js.map +1 -1
  8. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/transport.d.ts +8 -8
  9. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/transport.d.ts.map +1 -1
  10. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.d.ts.map +1 -1
  11. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js +10 -0
  12. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js.map +1 -1
  13. package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/transport.d.ts +8 -8
  14. package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/transport.d.ts.map +1 -1
  15. package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/README.md +17 -13
  16. package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/lib/read.js +74 -57
  17. package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/lib/types/json.js +11 -11
  18. package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/lib/types/urlencoded.js +5 -5
  19. package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/lib/utils.js +0 -15
  20. package/node_modules/@modelcontextprotocol/sdk/node_modules/body-parser/package.json +7 -12
  21. package/node_modules/@modelcontextprotocol/sdk/package.json +1 -1
  22. package/node_modules/body-parser/HISTORY.md +7 -2
  23. package/node_modules/body-parser/README.md +3 -3
  24. package/node_modules/body-parser/lib/read.js +26 -8
  25. package/node_modules/body-parser/package.json +1 -1
  26. package/node_modules/follow-redirects/README.md +27 -1
  27. package/node_modules/follow-redirects/index.js +1 -5
  28. package/node_modules/follow-redirects/package.json +1 -1
  29. package/node_modules/hono/README.md +2 -3
  30. package/node_modules/hono/dist/cjs/helper/css/common.js +8 -3
  31. package/node_modules/hono/dist/cjs/helper/css/index.js +1 -1
  32. package/node_modules/hono/dist/cjs/helper/route/index.js +3 -1
  33. package/node_modules/hono/dist/cjs/jsx/base.js +1 -1
  34. package/node_modules/hono/dist/cjs/middleware/bearer-auth/index.js +8 -0
  35. package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +3 -1
  36. package/node_modules/hono/dist/cjs/router/trie-router/node.js +2 -2
  37. package/node_modules/hono/dist/cjs/utils/url.js +11 -6
  38. package/node_modules/hono/dist/helper/css/common.js +8 -3
  39. package/node_modules/hono/dist/helper/css/index.js +1 -1
  40. package/node_modules/hono/dist/helper/route/index.js +3 -1
  41. package/node_modules/hono/dist/jsx/base.js +1 -1
  42. package/node_modules/hono/dist/middleware/bearer-auth/index.js +8 -0
  43. package/node_modules/hono/dist/middleware/serve-static/index.js +3 -1
  44. package/node_modules/hono/dist/router/trie-router/node.js +2 -2
  45. package/node_modules/hono/dist/types/adapter/aws-lambda/conninfo.d.ts +1 -1
  46. package/node_modules/hono/dist/types/adapter/bun/conninfo.d.ts +1 -1
  47. package/node_modules/hono/dist/types/adapter/bun/ssg.d.ts +1 -1
  48. package/node_modules/hono/dist/types/adapter/cloudflare-pages/conninfo.d.ts +1 -1
  49. package/node_modules/hono/dist/types/adapter/cloudflare-workers/conninfo.d.ts +1 -1
  50. package/node_modules/hono/dist/types/adapter/deno/conninfo.d.ts +1 -1
  51. package/node_modules/hono/dist/types/adapter/deno/ssg.d.ts +1 -1
  52. package/node_modules/hono/dist/types/adapter/lambda-edge/conninfo.d.ts +1 -1
  53. package/node_modules/hono/dist/types/adapter/netlify/conninfo.d.ts +1 -1
  54. package/node_modules/hono/dist/types/adapter/vercel/conninfo.d.ts +1 -1
  55. package/node_modules/hono/dist/types/helper/testing/index.d.ts +2 -1
  56. package/node_modules/hono/dist/types/hono-base.d.ts +21 -9
  57. package/node_modules/hono/dist/types/index.d.ts +1 -1
  58. package/node_modules/hono/dist/types/jsx/components.d.ts +2 -2
  59. package/node_modules/hono/dist/types/jsx/context.d.ts +2 -2
  60. package/node_modules/hono/dist/types/jsx/dom/components.d.ts +2 -2
  61. package/node_modules/hono/dist/types/jsx/dom/css.d.ts +2 -2
  62. package/node_modules/hono/dist/types/jsx/streaming.d.ts +4 -3
  63. package/node_modules/hono/dist/types/middleware/bearer-auth/index.d.ts +2 -1
  64. package/node_modules/hono/dist/types/middleware/ip-restriction/index.d.ts +3 -3
  65. package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +3 -3
  66. package/node_modules/hono/dist/types/utils/ipaddr.d.ts +1 -1
  67. package/node_modules/hono/dist/utils/url.js +11 -6
  68. package/node_modules/hono/package.json +1 -1
  69. package/node_modules/http-proxy-middleware/dist/handlers/fix-request-body.js +2 -2
  70. package/node_modules/http-proxy-middleware/package.json +1 -1
  71. package/node_modules/ip-address/dist/common.js +2 -2
  72. package/node_modules/ip-address/dist/common.js.map +1 -1
  73. package/node_modules/ip-address/package.json +2 -2
  74. package/node_modules/on-finished/index.js +14 -2
  75. package/node_modules/on-finished/package.json +11 -7
  76. package/node_modules/postcss/lib/input.js +1 -1
  77. package/node_modules/postcss/lib/lazy-result.js +1 -1
  78. package/node_modules/postcss/lib/no-work-result.js +1 -1
  79. package/node_modules/postcss/lib/node.js +2 -2
  80. package/node_modules/postcss/lib/processor.js +1 -1
  81. package/node_modules/postcss/lib/warning.js +1 -0
  82. package/node_modules/postcss/package.json +1 -1
  83. package/node_modules/zod/README.md +34 -24
  84. package/node_modules/zod/compile.cjs +96 -0
  85. package/node_modules/zod/compile.d.cts +1 -0
  86. package/node_modules/zod/compile.d.ts +1 -0
  87. package/node_modules/zod/compile.js +52 -0
  88. package/node_modules/zod/index.cjs +22 -3
  89. package/node_modules/zod/index.d.cts +3 -4
  90. package/node_modules/zod/index.d.ts +3 -4
  91. package/node_modules/zod/index.js +7 -4
  92. package/node_modules/zod/locales/index.cjs +36 -0
  93. package/node_modules/zod/locales/index.d.cts +1 -0
  94. package/node_modules/zod/locales/index.d.ts +1 -0
  95. package/node_modules/zod/locales/index.js +1 -0
  96. package/node_modules/zod/locales/package.json +7 -0
  97. package/node_modules/zod/mini/index.cjs +51 -0
  98. package/node_modules/zod/mini/index.d.cts +3 -0
  99. package/node_modules/zod/mini/index.d.ts +3 -0
  100. package/node_modules/zod/mini/index.js +3 -0
  101. package/node_modules/zod/mini/package.json +7 -0
  102. package/node_modules/zod/package.json +44 -15
  103. package/node_modules/zod/src/compile.ts +56 -0
  104. package/node_modules/zod/src/index.ts +7 -4
  105. package/node_modules/zod/src/locales/index.ts +1 -0
  106. package/node_modules/zod/src/mini/index.ts +3 -0
  107. package/node_modules/zod/src/v3/ZodError.ts +23 -13
  108. package/node_modules/zod/src/v3/helpers/errorUtil.ts +1 -1
  109. package/node_modules/zod/src/v3/tests/all-errors.test.ts +3 -3
  110. package/node_modules/zod/src/v3/tests/complex.test.ts +17 -3
  111. package/node_modules/zod/src/v3/tests/error.test.ts +35 -0
  112. package/node_modules/zod/src/v3/tests/function.test.ts +7 -3
  113. package/node_modules/zod/src/v3/tests/intersection.test.ts +18 -0
  114. package/node_modules/zod/src/v3/tests/language-server.test.ts +1 -2
  115. package/node_modules/zod/src/v3/tests/nan.test.ts +5 -2
  116. package/node_modules/zod/src/v3/tests/object.test.ts +10 -13
  117. package/node_modules/zod/src/v3/tests/partials.test.ts +3 -3
  118. package/node_modules/zod/src/v3/tests/readonly.test.ts +0 -80
  119. package/node_modules/zod/src/v3/tests/string.test.ts +8 -2
  120. package/node_modules/zod/src/v3/types.ts +8 -6
  121. package/node_modules/zod/src/v4/classic/checks.ts +3 -0
  122. package/node_modules/zod/src/v4/classic/compat.ts +30 -18
  123. package/node_modules/zod/src/v4/classic/deep-partial.ts +76 -0
  124. package/node_modules/zod/src/v4/classic/errors.ts +61 -39
  125. package/node_modules/zod/src/v4/classic/external.ts +18 -11
  126. package/node_modules/zod/src/v4/classic/from-json-schema.ts +944 -0
  127. package/node_modules/zod/src/v4/classic/in-out.ts +45 -0
  128. package/node_modules/zod/src/v4/classic/index.ts +2 -2
  129. package/node_modules/zod/src/v4/classic/iso.ts +2 -72
  130. package/node_modules/zod/src/v4/classic/parse.ts +57 -2
  131. package/node_modules/zod/src/v4/classic/schemas.ts +1258 -375
  132. package/node_modules/zod/src/v4/classic/tests/apply.test.ts +86 -0
  133. package/node_modules/zod/src/v4/classic/tests/array.test.ts +35 -8
  134. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +192 -0
  135. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +36 -1
  136. package/node_modules/zod/src/v4/classic/tests/brand.test.ts +43 -0
  137. package/node_modules/zod/src/v4/classic/tests/catch.test.ts +357 -5
  138. package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +572 -0
  139. package/node_modules/zod/src/v4/classic/tests/codec.test.ts +704 -0
  140. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +27 -5
  141. package/node_modules/zod/src/v4/classic/tests/credit-card.test.ts +76 -0
  142. package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +985 -0
  143. package/node_modules/zod/src/v4/classic/tests/date.test.ts +67 -6
  144. package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +37 -17
  145. package/node_modules/zod/src/v4/classic/tests/deep-partial.test.ts +380 -0
  146. package/node_modules/zod/src/v4/classic/tests/default-locale.test.ts +32 -0
  147. package/node_modules/zod/src/v4/classic/tests/default.test.ts +142 -0
  148. package/node_modules/zod/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
  149. package/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +221 -0
  150. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +333 -10
  151. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +20 -0
  152. package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +394 -4
  153. package/node_modules/zod/src/v4/classic/tests/error.test.ts +403 -6
  154. package/node_modules/zod/src/v4/classic/tests/file.test.ts +9 -4
  155. package/node_modules/zod/src/v4/classic/tests/firstparty.test.ts +4 -0
  156. package/node_modules/zod/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
  157. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +1467 -0
  158. package/node_modules/zod/src/v4/classic/tests/function.test.ts +160 -37
  159. package/node_modules/zod/src/v4/classic/tests/global-config.test.ts +32 -0
  160. package/node_modules/zod/src/v4/classic/tests/hash.test.ts +67 -0
  161. package/node_modules/zod/src/v4/classic/tests/iban.test.ts +81 -0
  162. package/node_modules/zod/src/v4/classic/tests/in-out.test.ts +159 -0
  163. package/node_modules/zod/src/v4/classic/tests/index.test.ts +134 -5
  164. package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +319 -0
  165. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +93 -0
  166. package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +168 -5
  167. package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +215 -0
  168. package/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +39 -0
  169. package/node_modules/zod/src/v4/classic/tests/json.test.ts +4 -3
  170. package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +36 -1
  171. package/node_modules/zod/src/v4/classic/tests/literal.test.ts +37 -1
  172. package/node_modules/zod/src/v4/classic/tests/locales_ka.test.ts +29 -0
  173. package/node_modules/zod/src/v4/classic/tests/locales_ro.test.ts +24 -0
  174. package/node_modules/zod/src/v4/classic/tests/map.test.ts +153 -0
  175. package/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts +15 -0
  176. package/node_modules/zod/src/v4/classic/tests/number.test.ts +161 -7
  177. package/node_modules/zod/src/v4/classic/tests/object.test.ts +457 -14
  178. package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +235 -0
  179. package/node_modules/zod/src/v4/classic/tests/optional.test.ts +255 -12
  180. package/node_modules/zod/src/v4/classic/tests/partial.test.ts +350 -0
  181. package/node_modules/zod/src/v4/classic/tests/pickomit.test.ts +89 -5
  182. package/node_modules/zod/src/v4/classic/tests/pipe.test.ts +25 -5
  183. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +107 -0
  184. package/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +44 -0
  185. package/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +74 -21
  186. package/node_modules/zod/src/v4/classic/tests/promise.test.ts +1 -1
  187. package/node_modules/zod/src/v4/classic/tests/properties.test.ts +141 -0
  188. package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +1 -69
  189. package/node_modules/zod/src/v4/classic/tests/record.test.ts +553 -10
  190. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +352 -1
  191. package/node_modules/zod/src/v4/classic/tests/redos.test.ts +68 -0
  192. package/node_modules/zod/src/v4/classic/tests/refine.test.ts +229 -68
  193. package/node_modules/zod/src/v4/classic/tests/registries.test.ts +40 -1
  194. package/node_modules/zod/src/v4/classic/tests/set.test.ts +20 -3
  195. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +96 -0
  196. package/node_modules/zod/src/v4/classic/tests/string-formats.test.ts +16 -0
  197. package/node_modules/zod/src/v4/classic/tests/string.test.ts +568 -9
  198. package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +58 -0
  199. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +70 -16
  200. package/node_modules/zod/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  201. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +3409 -990
  202. package/node_modules/zod/src/v4/classic/tests/transform.test.ts +128 -0
  203. package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +353 -5
  204. package/node_modules/zod/src/v4/classic/tests/union.test.ts +219 -3
  205. package/node_modules/zod/src/v4/classic/tests/url.test.ts +13 -0
  206. package/node_modules/zod/src/v4/classic/tests/validate.test.ts +645 -0
  207. package/node_modules/zod/src/v4/classic/tests/validations.test.ts +2 -2
  208. package/node_modules/zod/src/v4/core/api.ts +442 -161
  209. package/node_modules/zod/src/v4/core/checks.ts +134 -151
  210. package/node_modules/zod/src/v4/core/compile.ts +2322 -0
  211. package/node_modules/zod/src/v4/core/core.ts +146 -50
  212. package/node_modules/zod/src/v4/core/doc.ts +18 -10
  213. package/node_modules/zod/src/v4/core/errors.ts +221 -102
  214. package/node_modules/zod/src/v4/core/index.ts +5 -1
  215. package/node_modules/zod/src/v4/core/json-schema-generator.ts +131 -0
  216. package/node_modules/zod/src/v4/core/json-schema-processors.ts +934 -0
  217. package/node_modules/zod/src/v4/core/json-schema.ts +9 -4
  218. package/node_modules/zod/src/v4/core/memoizer.ts +331 -0
  219. package/node_modules/zod/src/v4/core/parse.ts +252 -37
  220. package/node_modules/zod/src/v4/core/regexes.ts +112 -30
  221. package/node_modules/zod/src/v4/core/registries.ts +19 -10
  222. package/node_modules/zod/src/v4/core/schemas.ts +1972 -588
  223. package/node_modules/zod/src/v4/core/standard-schema.ts +114 -19
  224. package/node_modules/zod/src/v4/core/tests/cached.test.ts +54 -0
  225. package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +1004 -0
  226. package/node_modules/zod/src/v4/core/tests/compile-generative.test.ts +445 -0
  227. package/node_modules/zod/src/v4/core/tests/compile-global.test.ts +89 -0
  228. package/node_modules/zod/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
  229. package/node_modules/zod/src/v4/core/tests/compile-stats.test.ts +34 -0
  230. package/node_modules/zod/src/v4/core/tests/compile.test.ts +2036 -0
  231. package/node_modules/zod/src/v4/core/tests/email-regex.test.ts +140 -0
  232. package/node_modules/zod/src/v4/core/tests/extend.test.ts +59 -0
  233. package/node_modules/zod/src/v4/core/tests/locales/el.test.ts +214 -0
  234. package/node_modules/zod/src/v4/core/tests/locales/en.test.ts +1 -1
  235. package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +180 -0
  236. package/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +72 -0
  237. package/node_modules/zod/src/v4/core/tests/locales/he.test.ts +379 -0
  238. package/node_modules/zod/src/v4/core/tests/locales/hr.test.ts +163 -0
  239. package/node_modules/zod/src/v4/core/tests/locales/nl.test.ts +46 -0
  240. package/node_modules/zod/src/v4/core/tests/locales/parity.test.ts +42 -0
  241. package/node_modules/zod/src/v4/core/tests/locales/tg.test.ts +85 -0
  242. package/node_modules/zod/src/v4/core/tests/locales/tk.test.ts +69 -0
  243. package/node_modules/zod/src/v4/core/tests/locales/tr.test.ts +2 -2
  244. package/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +105 -0
  245. package/node_modules/zod/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  246. package/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +125 -0
  247. package/node_modules/zod/src/v4/core/tests/recursive-tuples.test.ts +45 -0
  248. package/node_modules/zod/src/v4/core/tests/treeshake.test.ts +51 -0
  249. package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +133 -0
  250. package/node_modules/zod/src/v4/core/to-json-schema.ts +706 -826
  251. package/node_modules/zod/src/v4/core/util.ts +675 -157
  252. package/node_modules/zod/src/v4/core/versions.ts +2 -2
  253. package/node_modules/zod/src/v4/core/visit.ts +193 -0
  254. package/node_modules/zod/src/v4/index.ts +3 -3
  255. package/node_modules/zod/src/v4/locales/ar.ts +22 -27
  256. package/node_modules/zod/src/v4/locales/az.ts +22 -27
  257. package/node_modules/zod/src/v4/locales/be.ts +31 -27
  258. package/node_modules/zod/src/v4/locales/bg.ts +133 -0
  259. package/node_modules/zod/src/v4/locales/bn.ts +123 -0
  260. package/node_modules/zod/src/v4/locales/ca.ts +22 -28
  261. package/node_modules/zod/src/v4/locales/ckb.ts +140 -0
  262. package/node_modules/zod/src/v4/locales/cs.ts +26 -45
  263. package/node_modules/zod/src/v4/locales/da.ts +128 -0
  264. package/node_modules/zod/src/v4/locales/de.ts +24 -27
  265. package/node_modules/zod/src/v4/locales/el.ts +124 -0
  266. package/node_modules/zod/src/v4/locales/en.ts +38 -29
  267. package/node_modules/zod/src/v4/locales/eo.ts +25 -27
  268. package/node_modules/zod/src/v4/locales/es.ts +53 -33
  269. package/node_modules/zod/src/v4/locales/fa.ts +24 -27
  270. package/node_modules/zod/src/v4/locales/fi.ts +22 -27
  271. package/node_modules/zod/src/v4/locales/fr-CA.ts +22 -27
  272. package/node_modules/zod/src/v4/locales/fr.ts +58 -43
  273. package/node_modules/zod/src/v4/locales/gu.ts +123 -0
  274. package/node_modules/zod/src/v4/locales/he.ts +208 -80
  275. package/node_modules/zod/src/v4/locales/hi.ts +126 -0
  276. package/node_modules/zod/src/v4/locales/hr.ts +135 -0
  277. package/node_modules/zod/src/v4/locales/hu.ts +24 -28
  278. package/node_modules/zod/src/v4/locales/hy.ts +175 -0
  279. package/node_modules/zod/src/v4/locales/id.ts +22 -27
  280. package/node_modules/zod/src/v4/locales/index.ts +24 -0
  281. package/node_modules/zod/src/v4/locales/is.ts +124 -0
  282. package/node_modules/zod/src/v4/locales/it.ts +24 -28
  283. package/node_modules/zod/src/v4/locales/ja.ts +24 -27
  284. package/node_modules/zod/src/v4/locales/ka.ts +128 -0
  285. package/node_modules/zod/src/v4/locales/kh.ts +3 -122
  286. package/node_modules/zod/src/v4/locales/km.ts +124 -0
  287. package/node_modules/zod/src/v4/locales/kn.ts +126 -0
  288. package/node_modules/zod/src/v4/locales/ko.ts +22 -27
  289. package/node_modules/zod/src/v4/locales/lt.ts +243 -0
  290. package/node_modules/zod/src/v4/locales/mk.ts +24 -28
  291. package/node_modules/zod/src/v4/locales/ms.ts +23 -27
  292. package/node_modules/zod/src/v4/locales/ne.ts +128 -0
  293. package/node_modules/zod/src/v4/locales/nl.ts +37 -37
  294. package/node_modules/zod/src/v4/locales/nn.ts +121 -0
  295. package/node_modules/zod/src/v4/locales/no.ts +26 -29
  296. package/node_modules/zod/src/v4/locales/ota.ts +25 -28
  297. package/node_modules/zod/src/v4/locales/pl.ts +24 -27
  298. package/node_modules/zod/src/v4/locales/ps.ts +24 -26
  299. package/node_modules/zod/src/v4/locales/pt-BR.ts +161 -0
  300. package/node_modules/zod/src/v4/locales/pt.ts +107 -71
  301. package/node_modules/zod/src/v4/locales/ro.ts +132 -0
  302. package/node_modules/zod/src/v4/locales/ru.ts +31 -27
  303. package/node_modules/zod/src/v4/locales/sk.ts +123 -0
  304. package/node_modules/zod/src/v4/locales/sl.ts +24 -27
  305. package/node_modules/zod/src/v4/locales/sv.ts +26 -29
  306. package/node_modules/zod/src/v4/locales/ta.ts +25 -27
  307. package/node_modules/zod/src/v4/locales/tg.ts +135 -0
  308. package/node_modules/zod/src/v4/locales/th.ts +25 -27
  309. package/node_modules/zod/src/v4/locales/tk.ts +113 -0
  310. package/node_modules/zod/src/v4/locales/tr.ts +22 -27
  311. package/node_modules/zod/src/v4/locales/ua.ts +3 -122
  312. package/node_modules/zod/src/v4/locales/uk.ts +122 -0
  313. package/node_modules/zod/src/v4/locales/ur.ts +25 -27
  314. package/node_modules/zod/src/v4/locales/uz.ts +120 -0
  315. package/node_modules/zod/src/v4/locales/vi.ts +24 -27
  316. package/node_modules/zod/src/v4/locales/yo.ts +129 -0
  317. package/node_modules/zod/src/v4/locales/zh-CN.ts +25 -27
  318. package/node_modules/zod/src/v4/locales/zh-TW.ts +22 -27
  319. package/node_modules/zod/src/v4/mini/checks.ts +1 -0
  320. package/node_modules/zod/src/v4/mini/coerce.ts +5 -0
  321. package/node_modules/zod/src/v4/mini/deep-partial.ts +73 -0
  322. package/node_modules/zod/src/v4/mini/external.ts +15 -3
  323. package/node_modules/zod/src/v4/mini/in-out.ts +45 -0
  324. package/node_modules/zod/src/v4/mini/iso.ts +8 -4
  325. package/node_modules/zod/src/v4/mini/parse.ts +16 -1
  326. package/node_modules/zod/src/v4/mini/schemas.ts +586 -114
  327. package/node_modules/zod/src/v4/mini/tests/apply.test.ts +57 -0
  328. package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +63 -2
  329. package/node_modules/zod/src/v4/mini/tests/brand.test.ts +43 -0
  330. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +14 -0
  331. package/node_modules/zod/src/v4/mini/tests/codec.test.ts +582 -0
  332. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +12 -18
  333. package/node_modules/zod/src/v4/mini/tests/cyclic-data.test.ts +84 -0
  334. package/node_modules/zod/src/v4/mini/tests/deep-partial.test.ts +54 -0
  335. package/node_modules/zod/src/v4/mini/tests/error.test.ts +24 -5
  336. package/node_modules/zod/src/v4/mini/tests/functions.test.ts +7 -36
  337. package/node_modules/zod/src/v4/mini/tests/index.test.ts +281 -6
  338. package/node_modules/zod/src/v4/mini/tests/number.test.ts +15 -1
  339. package/node_modules/zod/src/v4/mini/tests/object.test.ts +116 -9
  340. package/node_modules/zod/src/v4/mini/tests/prototypes.test.ts +1 -1
  341. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +68 -2
  342. package/node_modules/zod/src/v4/mini/tests/standard-schema.test.ts +50 -0
  343. package/node_modules/zod/src/v4/mini/tests/string.test.ts +98 -1
  344. package/node_modules/zod/src/v4-mini/index.ts +3 -1
  345. package/node_modules/zod/v3/ZodError.cjs +42 -13
  346. package/node_modules/zod/v3/ZodError.d.cts +6 -6
  347. package/node_modules/zod/v3/ZodError.d.ts +6 -6
  348. package/node_modules/zod/v3/ZodError.js +23 -13
  349. package/node_modules/zod/v3/errors.cjs +19 -0
  350. package/node_modules/zod/v3/external.cjs +19 -0
  351. package/node_modules/zod/v3/helpers/enumUtil.cjs +19 -0
  352. package/node_modules/zod/v3/helpers/errorUtil.cjs +20 -1
  353. package/node_modules/zod/v3/helpers/errorUtil.js +1 -1
  354. package/node_modules/zod/v3/helpers/parseUtil.cjs +19 -0
  355. package/node_modules/zod/v3/helpers/partialUtil.cjs +19 -0
  356. package/node_modules/zod/v3/helpers/typeAliases.cjs +19 -0
  357. package/node_modules/zod/v3/helpers/util.cjs +19 -0
  358. package/node_modules/zod/v3/index.cjs +19 -0
  359. package/node_modules/zod/v3/locales/en.cjs +1 -0
  360. package/node_modules/zod/v3/locales/en.d.cts +1 -1
  361. package/node_modules/zod/v3/package.json +7 -0
  362. package/node_modules/zod/v3/standard-schema.cjs +19 -0
  363. package/node_modules/zod/v3/types.cjs +28 -5
  364. package/node_modules/zod/v3/types.d.cts +4 -1
  365. package/node_modules/zod/v3/types.d.ts +4 -1
  366. package/node_modules/zod/v3/types.js +9 -5
  367. package/node_modules/zod/v4/classic/checks.cjs +22 -1
  368. package/node_modules/zod/v4/classic/checks.d.cts +1 -1
  369. package/node_modules/zod/v4/classic/checks.d.ts +1 -1
  370. package/node_modules/zod/v4/classic/checks.js +1 -1
  371. package/node_modules/zod/v4/classic/coerce.cjs +19 -0
  372. package/node_modules/zod/v4/classic/compat.cjs +24 -1
  373. package/node_modules/zod/v4/classic/compat.d.cts +13 -11
  374. package/node_modules/zod/v4/classic/compat.d.ts +13 -11
  375. package/node_modules/zod/v4/classic/compat.js +4 -0
  376. package/node_modules/zod/v4/classic/deep-partial.cjs +58 -0
  377. package/node_modules/zod/v4/classic/deep-partial.d.cts +14 -0
  378. package/node_modules/zod/v4/classic/deep-partial.d.ts +14 -0
  379. package/node_modules/zod/v4/classic/deep-partial.js +13 -0
  380. package/node_modules/zod/v4/classic/errors.cjs +63 -28
  381. package/node_modules/zod/v4/classic/errors.d.cts +3 -4
  382. package/node_modules/zod/v4/classic/errors.d.ts +3 -4
  383. package/node_modules/zod/v4/classic/errors.js +45 -29
  384. package/node_modules/zod/v4/classic/external.cjs +55 -28
  385. package/node_modules/zod/v4/classic/external.d.cts +8 -2
  386. package/node_modules/zod/v4/classic/external.d.ts +8 -2
  387. package/node_modules/zod/v4/classic/external.js +7 -8
  388. package/node_modules/zod/v4/classic/from-json-schema.cjs +926 -0
  389. package/node_modules/zod/v4/classic/from-json-schema.d.cts +12 -0
  390. package/node_modules/zod/v4/classic/from-json-schema.d.ts +12 -0
  391. package/node_modules/zod/v4/classic/from-json-schema.js +881 -0
  392. package/node_modules/zod/v4/classic/in-out.cjs +82 -0
  393. package/node_modules/zod/v4/classic/in-out.d.cts +8 -0
  394. package/node_modules/zod/v4/classic/in-out.d.ts +8 -0
  395. package/node_modules/zod/v4/classic/in-out.js +36 -0
  396. package/node_modules/zod/v4/classic/index.cjs +21 -2
  397. package/node_modules/zod/v4/classic/index.d.cts +1 -2
  398. package/node_modules/zod/v4/classic/index.d.ts +1 -2
  399. package/node_modules/zod/v4/classic/index.js +2 -2
  400. package/node_modules/zod/v4/classic/iso.cjs +30 -22
  401. package/node_modules/zod/v4/classic/iso.d.cts +2 -17
  402. package/node_modules/zod/v4/classic/iso.d.ts +2 -17
  403. package/node_modules/zod/v4/classic/iso.js +2 -17
  404. package/node_modules/zod/v4/classic/package.json +7 -0
  405. package/node_modules/zod/v4/classic/parse.cjs +32 -1
  406. package/node_modules/zod/v4/classic/parse.d.cts +21 -0
  407. package/node_modules/zod/v4/classic/parse.d.ts +21 -0
  408. package/node_modules/zod/v4/classic/parse.js +10 -0
  409. package/node_modules/zod/v4/classic/schemas.cjs +805 -238
  410. package/node_modules/zod/v4/classic/schemas.d.cts +241 -55
  411. package/node_modules/zod/v4/classic/schemas.d.ts +241 -55
  412. package/node_modules/zod/v4/classic/schemas.js +766 -237
  413. package/node_modules/zod/v4/core/api.cjs +284 -54
  414. package/node_modules/zod/v4/core/api.d.cts +133 -82
  415. package/node_modules/zod/v4/core/api.d.ts +133 -82
  416. package/node_modules/zod/v4/core/api.js +255 -54
  417. package/node_modules/zod/v4/core/checks.cjs +100 -130
  418. package/node_modules/zod/v4/core/checks.d.cts +32 -16
  419. package/node_modules/zod/v4/core/checks.d.ts +32 -16
  420. package/node_modules/zod/v4/core/checks.js +80 -129
  421. package/node_modules/zod/v4/core/compile.cjs +1916 -0
  422. package/node_modules/zod/v4/core/compile.d.cts +65 -0
  423. package/node_modules/zod/v4/core/compile.d.ts +65 -0
  424. package/node_modules/zod/v4/core/compile.js +1866 -0
  425. package/node_modules/zod/v4/core/core.cjs +120 -20
  426. package/node_modules/zod/v4/core/core.d.cts +40 -7
  427. package/node_modules/zod/v4/core/core.d.ts +40 -7
  428. package/node_modules/zod/v4/core/core.js +101 -21
  429. package/node_modules/zod/v4/core/doc.cjs +31 -9
  430. package/node_modules/zod/v4/core/doc.d.cts +4 -2
  431. package/node_modules/zod/v4/core/doc.d.ts +4 -2
  432. package/node_modules/zod/v4/core/doc.js +12 -9
  433. package/node_modules/zod/v4/core/errors.cjs +151 -60
  434. package/node_modules/zod/v4/core/errors.d.cts +41 -24
  435. package/node_modules/zod/v4/core/errors.d.ts +41 -24
  436. package/node_modules/zod/v4/core/errors.js +132 -60
  437. package/node_modules/zod/v4/core/index.cjs +28 -2
  438. package/node_modules/zod/v4/core/index.d.cts +5 -1
  439. package/node_modules/zod/v4/core/index.d.ts +5 -1
  440. package/node_modules/zod/v4/core/index.js +5 -1
  441. package/node_modules/zod/v4/core/json-schema-generator.cjs +122 -0
  442. package/node_modules/zod/v4/core/json-schema-generator.d.cts +65 -0
  443. package/node_modules/zod/v4/core/json-schema-generator.d.ts +65 -0
  444. package/node_modules/zod/v4/core/json-schema-generator.js +99 -0
  445. package/node_modules/zod/v4/core/json-schema-processors.cjs +929 -0
  446. package/node_modules/zod/v4/core/json-schema-processors.d.cts +65 -0
  447. package/node_modules/zod/v4/core/json-schema-processors.d.ts +65 -0
  448. package/node_modules/zod/v4/core/json-schema-processors.js +843 -0
  449. package/node_modules/zod/v4/core/json-schema.cjs +19 -0
  450. package/node_modules/zod/v4/core/json-schema.d.cts +6 -4
  451. package/node_modules/zod/v4/core/json-schema.d.ts +6 -4
  452. package/node_modules/zod/v4/core/memoizer.cjs +360 -0
  453. package/node_modules/zod/v4/core/memoizer.d.cts +15 -0
  454. package/node_modules/zod/v4/core/memoizer.d.ts +15 -0
  455. package/node_modules/zod/v4/core/memoizer.js +311 -0
  456. package/node_modules/zod/v4/core/package.json +7 -0
  457. package/node_modules/zod/v4/core/parse.cjs +183 -37
  458. package/node_modules/zod/v4/core/parse.d.cts +34 -7
  459. package/node_modules/zod/v4/core/parse.d.ts +34 -7
  460. package/node_modules/zod/v4/core/parse.js +154 -36
  461. package/node_modules/zod/v4/core/regexes.cjs +137 -31
  462. package/node_modules/zod/v4/core/regexes.d.cts +30 -2
  463. package/node_modules/zod/v4/core/regexes.d.ts +30 -2
  464. package/node_modules/zod/v4/core/regexes.js +90 -29
  465. package/node_modules/zod/v4/core/registries.cjs +26 -7
  466. package/node_modules/zod/v4/core/registries.d.cts +2 -2
  467. package/node_modules/zod/v4/core/registries.d.ts +2 -2
  468. package/node_modules/zod/v4/core/registries.js +9 -9
  469. package/node_modules/zod/v4/core/schemas.cjs +1373 -422
  470. package/node_modules/zod/v4/core/schemas.d.cts +276 -42
  471. package/node_modules/zod/v4/core/schemas.d.ts +276 -42
  472. package/node_modules/zod/v4/core/schemas.js +1341 -422
  473. package/node_modules/zod/v4/core/standard-schema.cjs +19 -0
  474. package/node_modules/zod/v4/core/standard-schema.d.cts +90 -19
  475. package/node_modules/zod/v4/core/standard-schema.d.ts +90 -19
  476. package/node_modules/zod/v4/core/to-json-schema.cjs +628 -801
  477. package/node_modules/zod/v4/core/to-json-schema.d.cts +103 -37
  478. package/node_modules/zod/v4/core/to-json-schema.d.ts +103 -37
  479. package/node_modules/zod/v4/core/to-json-schema.js +602 -800
  480. package/node_modules/zod/v4/core/util.cjs +580 -155
  481. package/node_modules/zod/v4/core/util.d.cts +98 -1
  482. package/node_modules/zod/v4/core/util.d.ts +98 -1
  483. package/node_modules/zod/v4/core/util.js +536 -156
  484. package/node_modules/zod/v4/core/versions.cjs +21 -2
  485. package/node_modules/zod/v4/core/versions.d.cts +1 -1
  486. package/node_modules/zod/v4/core/versions.d.ts +1 -1
  487. package/node_modules/zod/v4/core/versions.js +2 -2
  488. package/node_modules/zod/v4/core/visit.cjs +214 -0
  489. package/node_modules/zod/v4/core/visit.d.cts +30 -0
  490. package/node_modules/zod/v4/core/visit.d.ts +30 -0
  491. package/node_modules/zod/v4/core/visit.js +169 -0
  492. package/node_modules/zod/v4/index.cjs +34 -5
  493. package/node_modules/zod/v4/index.d.cts +2 -2
  494. package/node_modules/zod/v4/index.d.ts +2 -2
  495. package/node_modules/zod/v4/index.js +3 -2
  496. package/node_modules/zod/v4/locales/ar.cjs +20 -24
  497. package/node_modules/zod/v4/locales/ar.d.cts +2 -1
  498. package/node_modules/zod/v4/locales/ar.js +19 -24
  499. package/node_modules/zod/v4/locales/az.cjs +20 -24
  500. package/node_modules/zod/v4/locales/az.d.cts +2 -1
  501. package/node_modules/zod/v4/locales/az.js +19 -24
  502. package/node_modules/zod/v4/locales/be.cjs +29 -24
  503. package/node_modules/zod/v4/locales/be.d.cts +2 -1
  504. package/node_modules/zod/v4/locales/be.js +28 -24
  505. package/node_modules/zod/v4/locales/bg.cjs +152 -0
  506. package/node_modules/zod/v4/locales/bg.d.cts +5 -0
  507. package/node_modules/zod/v4/locales/bg.d.ts +4 -0
  508. package/node_modules/zod/v4/locales/bg.js +125 -0
  509. package/node_modules/zod/v4/locales/bn.cjs +140 -0
  510. package/node_modules/zod/v4/locales/bn.d.cts +5 -0
  511. package/node_modules/zod/v4/locales/bn.d.ts +4 -0
  512. package/node_modules/zod/v4/locales/bn.js +113 -0
  513. package/node_modules/zod/v4/locales/ca.cjs +20 -25
  514. package/node_modules/zod/v4/locales/ca.d.cts +2 -1
  515. package/node_modules/zod/v4/locales/ca.js +19 -25
  516. package/node_modules/zod/v4/locales/ckb.cjs +160 -0
  517. package/node_modules/zod/v4/locales/ckb.d.cts +5 -0
  518. package/node_modules/zod/v4/locales/ckb.d.ts +4 -0
  519. package/node_modules/zod/v4/locales/ckb.js +133 -0
  520. package/node_modules/zod/v4/locales/cs.cjs +24 -42
  521. package/node_modules/zod/v4/locales/cs.d.cts +2 -1
  522. package/node_modules/zod/v4/locales/cs.js +23 -42
  523. package/node_modules/zod/v4/locales/da.cjs +147 -0
  524. package/node_modules/zod/v4/locales/da.d.cts +5 -0
  525. package/node_modules/zod/v4/locales/da.d.ts +4 -0
  526. package/node_modules/zod/v4/locales/da.js +120 -0
  527. package/node_modules/zod/v4/locales/de.cjs +22 -24
  528. package/node_modules/zod/v4/locales/de.d.cts +2 -1
  529. package/node_modules/zod/v4/locales/de.js +21 -24
  530. package/node_modules/zod/v4/locales/el.cjs +139 -0
  531. package/node_modules/zod/v4/locales/el.d.cts +5 -0
  532. package/node_modules/zod/v4/locales/el.d.ts +4 -0
  533. package/node_modules/zod/v4/locales/el.js +112 -0
  534. package/node_modules/zod/v4/locales/en.cjs +35 -28
  535. package/node_modules/zod/v4/locales/en.d.cts +2 -2
  536. package/node_modules/zod/v4/locales/en.d.ts +0 -1
  537. package/node_modules/zod/v4/locales/en.js +34 -26
  538. package/node_modules/zod/v4/locales/eo.cjs +23 -26
  539. package/node_modules/zod/v4/locales/eo.d.cts +2 -2
  540. package/node_modules/zod/v4/locales/eo.d.ts +0 -1
  541. package/node_modules/zod/v4/locales/eo.js +22 -24
  542. package/node_modules/zod/v4/locales/es.cjs +51 -31
  543. package/node_modules/zod/v4/locales/es.d.cts +2 -1
  544. package/node_modules/zod/v4/locales/es.js +50 -31
  545. package/node_modules/zod/v4/locales/fa.cjs +22 -24
  546. package/node_modules/zod/v4/locales/fa.d.cts +2 -1
  547. package/node_modules/zod/v4/locales/fa.js +21 -24
  548. package/node_modules/zod/v4/locales/fi.cjs +20 -24
  549. package/node_modules/zod/v4/locales/fi.d.cts +2 -1
  550. package/node_modules/zod/v4/locales/fi.js +19 -24
  551. package/node_modules/zod/v4/locales/fr-CA.cjs +20 -24
  552. package/node_modules/zod/v4/locales/fr-CA.d.cts +2 -1
  553. package/node_modules/zod/v4/locales/fr-CA.js +19 -24
  554. package/node_modules/zod/v4/locales/fr.cjs +53 -39
  555. package/node_modules/zod/v4/locales/fr.d.cts +2 -1
  556. package/node_modules/zod/v4/locales/fr.js +52 -39
  557. package/node_modules/zod/v4/locales/gu.cjs +140 -0
  558. package/node_modules/zod/v4/locales/gu.d.cts +5 -0
  559. package/node_modules/zod/v4/locales/gu.d.ts +4 -0
  560. package/node_modules/zod/v4/locales/gu.js +113 -0
  561. package/node_modules/zod/v4/locales/he.cjs +183 -78
  562. package/node_modules/zod/v4/locales/he.d.cts +2 -1
  563. package/node_modules/zod/v4/locales/he.js +182 -78
  564. package/node_modules/zod/v4/locales/hi.cjs +138 -0
  565. package/node_modules/zod/v4/locales/hi.d.cts +5 -0
  566. package/node_modules/zod/v4/locales/hi.d.ts +4 -0
  567. package/node_modules/zod/v4/locales/hi.js +111 -0
  568. package/node_modules/zod/v4/locales/hr.cjs +153 -0
  569. package/node_modules/zod/v4/locales/hr.d.cts +5 -0
  570. package/node_modules/zod/v4/locales/hr.d.ts +4 -0
  571. package/node_modules/zod/v4/locales/hr.js +126 -0
  572. package/node_modules/zod/v4/locales/hu.cjs +22 -25
  573. package/node_modules/zod/v4/locales/hu.d.cts +2 -1
  574. package/node_modules/zod/v4/locales/hu.js +21 -25
  575. package/node_modules/zod/v4/locales/hy.cjs +185 -0
  576. package/node_modules/zod/v4/locales/hy.d.cts +5 -0
  577. package/node_modules/zod/v4/locales/hy.d.ts +4 -0
  578. package/node_modules/zod/v4/locales/hy.js +158 -0
  579. package/node_modules/zod/v4/locales/id.cjs +20 -24
  580. package/node_modules/zod/v4/locales/id.d.cts +2 -1
  581. package/node_modules/zod/v4/locales/id.js +19 -24
  582. package/node_modules/zod/v4/locales/index.cjs +69 -1
  583. package/node_modules/zod/v4/locales/index.d.cts +24 -0
  584. package/node_modules/zod/v4/locales/index.d.ts +24 -0
  585. package/node_modules/zod/v4/locales/index.js +24 -0
  586. package/node_modules/zod/v4/locales/is.cjs +141 -0
  587. package/node_modules/zod/v4/locales/is.d.cts +5 -0
  588. package/node_modules/zod/v4/locales/is.d.ts +4 -0
  589. package/node_modules/zod/v4/locales/is.js +114 -0
  590. package/node_modules/zod/v4/locales/it.cjs +22 -25
  591. package/node_modules/zod/v4/locales/it.d.cts +2 -1
  592. package/node_modules/zod/v4/locales/it.js +21 -25
  593. package/node_modules/zod/v4/locales/ja.cjs +22 -24
  594. package/node_modules/zod/v4/locales/ja.d.cts +2 -1
  595. package/node_modules/zod/v4/locales/ja.js +21 -24
  596. package/node_modules/zod/v4/locales/ka.cjs +144 -0
  597. package/node_modules/zod/v4/locales/ka.d.cts +5 -0
  598. package/node_modules/zod/v4/locales/ka.d.ts +4 -0
  599. package/node_modules/zod/v4/locales/ka.js +117 -0
  600. package/node_modules/zod/v4/locales/kh.cjs +6 -137
  601. package/node_modules/zod/v4/locales/kh.d.cts +2 -1
  602. package/node_modules/zod/v4/locales/kh.d.ts +1 -0
  603. package/node_modules/zod/v4/locales/kh.js +3 -115
  604. package/node_modules/zod/v4/locales/km.cjs +142 -0
  605. package/node_modules/zod/v4/locales/km.d.cts +5 -0
  606. package/node_modules/zod/v4/locales/km.d.ts +4 -0
  607. package/node_modules/zod/v4/locales/km.js +115 -0
  608. package/node_modules/zod/v4/locales/kn.cjs +143 -0
  609. package/node_modules/zod/v4/locales/kn.d.cts +5 -0
  610. package/node_modules/zod/v4/locales/kn.d.ts +4 -0
  611. package/node_modules/zod/v4/locales/kn.js +116 -0
  612. package/node_modules/zod/v4/locales/ko.cjs +20 -24
  613. package/node_modules/zod/v4/locales/ko.d.cts +2 -1
  614. package/node_modules/zod/v4/locales/ko.js +19 -24
  615. package/node_modules/zod/v4/locales/lt.cjs +234 -0
  616. package/node_modules/zod/v4/locales/lt.d.cts +5 -0
  617. package/node_modules/zod/v4/locales/lt.d.ts +4 -0
  618. package/node_modules/zod/v4/locales/lt.js +207 -0
  619. package/node_modules/zod/v4/locales/mk.cjs +22 -25
  620. package/node_modules/zod/v4/locales/mk.d.cts +2 -1
  621. package/node_modules/zod/v4/locales/mk.js +21 -25
  622. package/node_modules/zod/v4/locales/ms.cjs +21 -24
  623. package/node_modules/zod/v4/locales/ms.d.cts +2 -1
  624. package/node_modules/zod/v4/locales/ms.js +20 -24
  625. package/node_modules/zod/v4/locales/ne.cjs +138 -0
  626. package/node_modules/zod/v4/locales/ne.d.cts +5 -0
  627. package/node_modules/zod/v4/locales/ne.d.ts +4 -0
  628. package/node_modules/zod/v4/locales/ne.js +111 -0
  629. package/node_modules/zod/v4/locales/nl.cjs +31 -32
  630. package/node_modules/zod/v4/locales/nl.d.cts +2 -1
  631. package/node_modules/zod/v4/locales/nl.js +30 -32
  632. package/node_modules/zod/v4/locales/nn.cjs +140 -0
  633. package/node_modules/zod/v4/locales/nn.d.cts +5 -0
  634. package/node_modules/zod/v4/locales/nn.d.ts +4 -0
  635. package/node_modules/zod/v4/locales/nn.js +113 -0
  636. package/node_modules/zod/v4/locales/no.cjs +24 -26
  637. package/node_modules/zod/v4/locales/no.d.cts +2 -1
  638. package/node_modules/zod/v4/locales/no.js +23 -26
  639. package/node_modules/zod/v4/locales/ota.cjs +23 -25
  640. package/node_modules/zod/v4/locales/ota.d.cts +2 -1
  641. package/node_modules/zod/v4/locales/ota.js +22 -25
  642. package/node_modules/zod/v4/locales/package.json +7 -0
  643. package/node_modules/zod/v4/locales/pl.cjs +22 -24
  644. package/node_modules/zod/v4/locales/pl.d.cts +2 -1
  645. package/node_modules/zod/v4/locales/pl.js +21 -24
  646. package/node_modules/zod/v4/locales/ps.cjs +22 -24
  647. package/node_modules/zod/v4/locales/ps.d.cts +2 -1
  648. package/node_modules/zod/v4/locales/ps.js +21 -24
  649. package/node_modules/zod/v4/locales/pt-BR.cjs +170 -0
  650. package/node_modules/zod/v4/locales/pt-BR.d.cts +5 -0
  651. package/node_modules/zod/v4/locales/pt-BR.d.ts +4 -0
  652. package/node_modules/zod/v4/locales/pt-BR.js +143 -0
  653. package/node_modules/zod/v4/locales/pt.cjs +95 -68
  654. package/node_modules/zod/v4/locales/pt.d.cts +2 -1
  655. package/node_modules/zod/v4/locales/pt.js +94 -68
  656. package/node_modules/zod/v4/locales/ro.cjs +149 -0
  657. package/node_modules/zod/v4/locales/ro.d.cts +5 -0
  658. package/node_modules/zod/v4/locales/ro.d.ts +4 -0
  659. package/node_modules/zod/v4/locales/ro.js +122 -0
  660. package/node_modules/zod/v4/locales/ru.cjs +29 -24
  661. package/node_modules/zod/v4/locales/ru.d.cts +2 -1
  662. package/node_modules/zod/v4/locales/ru.js +28 -24
  663. package/node_modules/zod/v4/locales/sk.cjs +143 -0
  664. package/node_modules/zod/v4/locales/sk.d.cts +5 -0
  665. package/node_modules/zod/v4/locales/sk.d.ts +4 -0
  666. package/node_modules/zod/v4/locales/sk.js +116 -0
  667. package/node_modules/zod/v4/locales/sl.cjs +22 -24
  668. package/node_modules/zod/v4/locales/sl.d.cts +2 -1
  669. package/node_modules/zod/v4/locales/sl.js +21 -24
  670. package/node_modules/zod/v4/locales/sv.cjs +24 -26
  671. package/node_modules/zod/v4/locales/sv.d.cts +2 -1
  672. package/node_modules/zod/v4/locales/sv.js +23 -26
  673. package/node_modules/zod/v4/locales/ta.cjs +23 -24
  674. package/node_modules/zod/v4/locales/ta.d.cts +2 -1
  675. package/node_modules/zod/v4/locales/ta.js +22 -24
  676. package/node_modules/zod/v4/locales/tg.cjs +144 -0
  677. package/node_modules/zod/v4/locales/tg.d.cts +5 -0
  678. package/node_modules/zod/v4/locales/tg.d.ts +4 -0
  679. package/node_modules/zod/v4/locales/tg.js +117 -0
  680. package/node_modules/zod/v4/locales/th.cjs +23 -24
  681. package/node_modules/zod/v4/locales/th.d.cts +2 -1
  682. package/node_modules/zod/v4/locales/th.js +22 -24
  683. package/node_modules/zod/v4/locales/tk.cjs +134 -0
  684. package/node_modules/zod/v4/locales/tk.d.cts +5 -0
  685. package/node_modules/zod/v4/locales/tk.d.ts +4 -0
  686. package/node_modules/zod/v4/locales/tk.js +107 -0
  687. package/node_modules/zod/v4/locales/tr.cjs +20 -26
  688. package/node_modules/zod/v4/locales/tr.d.cts +2 -2
  689. package/node_modules/zod/v4/locales/tr.d.ts +0 -1
  690. package/node_modules/zod/v4/locales/tr.js +19 -24
  691. package/node_modules/zod/v4/locales/ua.cjs +6 -137
  692. package/node_modules/zod/v4/locales/ua.d.cts +2 -1
  693. package/node_modules/zod/v4/locales/ua.d.ts +1 -0
  694. package/node_modules/zod/v4/locales/ua.js +3 -115
  695. package/node_modules/zod/v4/locales/uk.cjs +140 -0
  696. package/node_modules/zod/v4/locales/uk.d.cts +5 -0
  697. package/node_modules/zod/v4/locales/uk.d.ts +4 -0
  698. package/node_modules/zod/v4/locales/uk.js +113 -0
  699. package/node_modules/zod/v4/locales/ur.cjs +23 -24
  700. package/node_modules/zod/v4/locales/ur.d.cts +2 -1
  701. package/node_modules/zod/v4/locales/ur.js +22 -24
  702. package/node_modules/zod/v4/locales/uz.cjs +140 -0
  703. package/node_modules/zod/v4/locales/uz.d.cts +5 -0
  704. package/node_modules/zod/v4/locales/uz.d.ts +4 -0
  705. package/node_modules/zod/v4/locales/uz.js +113 -0
  706. package/node_modules/zod/v4/locales/vi.cjs +22 -24
  707. package/node_modules/zod/v4/locales/vi.d.cts +2 -1
  708. package/node_modules/zod/v4/locales/vi.js +21 -24
  709. package/node_modules/zod/v4/locales/yo.cjs +139 -0
  710. package/node_modules/zod/v4/locales/yo.d.cts +5 -0
  711. package/node_modules/zod/v4/locales/yo.d.ts +4 -0
  712. package/node_modules/zod/v4/locales/yo.js +112 -0
  713. package/node_modules/zod/v4/locales/zh-CN.cjs +23 -24
  714. package/node_modules/zod/v4/locales/zh-CN.d.cts +2 -1
  715. package/node_modules/zod/v4/locales/zh-CN.js +22 -24
  716. package/node_modules/zod/v4/locales/zh-TW.cjs +20 -24
  717. package/node_modules/zod/v4/locales/zh-TW.d.cts +2 -1
  718. package/node_modules/zod/v4/locales/zh-TW.js +19 -24
  719. package/node_modules/zod/v4/mini/checks.cjs +21 -1
  720. package/node_modules/zod/v4/mini/checks.d.cts +1 -1
  721. package/node_modules/zod/v4/mini/checks.d.ts +1 -1
  722. package/node_modules/zod/v4/mini/checks.js +1 -1
  723. package/node_modules/zod/v4/mini/coerce.cjs +24 -0
  724. package/node_modules/zod/v4/mini/coerce.js +5 -0
  725. package/node_modules/zod/v4/mini/deep-partial.cjs +58 -0
  726. package/node_modules/zod/v4/mini/deep-partial.d.cts +14 -0
  727. package/node_modules/zod/v4/mini/deep-partial.d.ts +14 -0
  728. package/node_modules/zod/v4/mini/deep-partial.js +13 -0
  729. package/node_modules/zod/v4/mini/external.cjs +36 -3
  730. package/node_modules/zod/v4/mini/external.d.cts +7 -2
  731. package/node_modules/zod/v4/mini/external.d.ts +7 -2
  732. package/node_modules/zod/v4/mini/external.js +4 -1
  733. package/node_modules/zod/v4/mini/in-out.cjs +82 -0
  734. package/node_modules/zod/v4/mini/in-out.d.cts +8 -0
  735. package/node_modules/zod/v4/mini/in-out.d.ts +8 -0
  736. package/node_modules/zod/v4/mini/in-out.js +36 -0
  737. package/node_modules/zod/v4/mini/index.cjs +19 -0
  738. package/node_modules/zod/v4/mini/iso.cjs +27 -4
  739. package/node_modules/zod/v4/mini/iso.js +8 -4
  740. package/node_modules/zod/v4/mini/package.json +7 -0
  741. package/node_modules/zod/v4/mini/parse.cjs +30 -1
  742. package/node_modules/zod/v4/mini/parse.d.cts +1 -1
  743. package/node_modules/zod/v4/mini/parse.d.ts +1 -1
  744. package/node_modules/zod/v4/mini/parse.js +1 -1
  745. package/node_modules/zod/v4/mini/schemas.cjs +390 -82
  746. package/node_modules/zod/v4/mini/schemas.d.cts +156 -32
  747. package/node_modules/zod/v4/mini/schemas.d.ts +156 -32
  748. package/node_modules/zod/v4/mini/schemas.js +329 -59
  749. package/node_modules/zod/v4/package.json +7 -0
  750. package/node_modules/zod/v4-mini/index.cjs +35 -1
  751. package/node_modules/zod/v4-mini/index.d.cts +3 -1
  752. package/node_modules/zod/v4-mini/index.d.ts +3 -1
  753. package/node_modules/zod/v4-mini/index.js +3 -1
  754. package/node_modules/zod/v4-mini/package.json +7 -0
  755. package/package.json +3 -3
  756. package/dist/ui/assets/index--GktkOfY.js +0 -123
  757. package/dist/ui/assets/index-7tDbGQbQ.css +0 -1
  758. package/node_modules/on-finished/HISTORY.md +0 -98
  759. package/node_modules/zod/src/v4/core/config.ts +0 -15
  760. package/node_modules/zod/src/v4/core/function.ts +0 -176
  761. package/node_modules/zod/v4/core/function.cjs +0 -102
  762. package/node_modules/zod/v4/core/function.d.cts +0 -52
  763. package/node_modules/zod/v4/core/function.d.ts +0 -52
  764. package/node_modules/zod/v4/core/function.js +0 -75
@@ -23,11 +23,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.$ZodSet = exports.$ZodMap = exports.$ZodRecord = exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = exports.$ZodUnion = exports.$ZodObject = exports.$ZodArray = exports.$ZodDate = exports.$ZodVoid = exports.$ZodNever = exports.$ZodUnknown = exports.$ZodAny = exports.$ZodNull = exports.$ZodUndefined = exports.$ZodSymbol = exports.$ZodBigIntFormat = exports.$ZodBigInt = exports.$ZodBoolean = exports.$ZodNumberFormat = exports.$ZodNumber = exports.$ZodCustomStringFormat = exports.$ZodJWT = exports.$ZodE164 = exports.$ZodBase64URL = exports.$ZodBase64 = exports.$ZodCIDRv6 = exports.$ZodCIDRv4 = exports.$ZodIPv6 = exports.$ZodIPv4 = exports.$ZodISODuration = exports.$ZodISOTime = exports.$ZodISODate = exports.$ZodISODateTime = exports.$ZodKSUID = exports.$ZodXID = exports.$ZodULID = exports.$ZodCUID2 = exports.$ZodCUID = exports.$ZodNanoID = exports.$ZodEmoji = exports.$ZodURL = exports.$ZodEmail = exports.$ZodUUID = exports.$ZodGUID = exports.$ZodStringFormat = exports.$ZodString = exports.clone = exports.$ZodType = void 0;
27
- exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = void 0;
26
+ exports.$ZodObject = exports.$ZodArray = exports.$ZodDate = exports.$ZodVoid = exports.$ZodNever = exports.$ZodUnknown = exports.$ZodAny = exports.$ZodNull = exports.$ZodUndefined = exports.$ZodSymbol = exports.$ZodBigIntFormat = exports.$ZodBigInt = exports.$ZodBoolean = exports.$ZodNumberFormat = exports.$ZodNumber = exports.$ZodCustomStringFormat = exports.$ZodJWT = exports.$ZodIBAN = exports.$ZodCreditCard = exports.$ZodE164 = exports.$ZodBase64URL = exports.base64urlCharset = exports.$ZodBase64 = exports.base64Charset = exports.$ZodCIDRv6 = exports.$ZodCIDRv4 = exports.$ZodMAC = exports.$ZodIPv6 = exports.$ZodIPv4 = exports.$ZodISODuration = exports.$ZodISOTime = exports.$ZodISODate = exports.$ZodISODateTime = exports.$ZodKSUID = exports.$ZodXID = exports.$ZodULID = exports.$ZodCUID2 = exports.$ZodCUID = exports.$ZodNanoID = exports.$ZodEmoji = exports.$ZodURL = exports.URL_UNPARSEABLE = exports.URL_BAD_FORMAT = exports.$ZodEmail = exports.$ZodUUID = exports.$ZodGUID = exports.$ZodStringFormat = exports.$ZodString = exports.clone = exports.$ZodType = void 0;
27
+ exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodFunction = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodPreprocess = exports.$ZodCodec = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodExactOptional = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = exports.$ZodSet = exports.$ZodMap = exports.$ZodRecord = exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = exports.$ZodXor = exports.$ZodUnion = exports.$ZodObjectJIT = void 0;
28
+ exports.standardProps = standardProps;
29
+ exports.canParseURL = canParseURL;
30
+ exports.validateURL = validateURL;
31
+ exports.parseURLObject = parseURLObject;
32
+ exports.stripTabAndNewline = stripTabAndNewline;
33
+ exports.urlHostnameOk = urlHostnameOk;
34
+ exports.urlProtocolOk = urlProtocolOk;
35
+ exports.isValidIPv6 = isValidIPv6;
36
+ exports.isValidCIDRv6 = isValidCIDRv6;
28
37
  exports.isValidBase64 = isValidBase64;
29
38
  exports.isValidBase64URL = isValidBase64URL;
39
+ exports.isValidCreditCard = isValidCreditCard;
40
+ exports.isValidIBAN = isValidIBAN;
30
41
  exports.isValidJWT = isValidJWT;
42
+ exports.getDiscriminatedOption = getDiscriminatedOption;
43
+ exports.mergeValues = mergeValues;
31
44
  const checks = __importStar(require("./checks.cjs"));
32
45
  const core = __importStar(require("./core.cjs"));
33
46
  const doc_js_1 = require("./doc.cjs");
@@ -41,20 +54,20 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
41
54
  inst._zod.def = def; // set _def property
42
55
  inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
43
56
  inst._zod.version = versions_js_1.version;
44
- const checks = [...(inst._zod.def.checks ?? [])];
57
+ const defChecks = inst._zod.def.checks;
45
58
  // if inst is itself a checks.$ZodCheck, run it as a check
46
- if (inst._zod.traits.has("$ZodCheck")) {
47
- checks.unshift(inst);
48
- }
49
- //
59
+ const checks = inst._zod.traits.has("$ZodCheck")
60
+ ? [inst, ...(defChecks ?? [])]
61
+ : defChecks?.length
62
+ ? [...defChecks]
63
+ : [];
50
64
  for (const ch of checks) {
51
65
  for (const fn of ch._zod.onattach) {
52
66
  fn(inst);
53
67
  }
54
68
  }
55
69
  if (checks.length === 0) {
56
- // deferred initializer
57
- // inst._zod.parse is not yet defined
70
+ // deferred initializer inst._zod.parse is not yet defined
58
71
  (_a = inst._zod).deferred ?? (_a.deferred = []);
59
72
  inst._zod.deferred?.push(() => {
60
73
  inst._zod.run = inst._zod.parse;
@@ -62,10 +75,14 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
62
75
  }
63
76
  else {
64
77
  const runChecks = (payload, checks, ctx) => {
78
+ if (payload.memo)
79
+ return payload;
65
80
  let isAborted = util.aborted(payload);
66
81
  let asyncResult;
67
82
  for (const ch of checks) {
68
83
  if (ch._zod.def.when) {
84
+ if (util.explicitlyAborted(payload))
85
+ continue;
69
86
  const shouldRun = ch._zod.def.when(payload);
70
87
  if (!shouldRun)
71
88
  continue;
@@ -84,6 +101,7 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
84
101
  const nextLen = payload.issues.length;
85
102
  if (nextLen === currLen)
86
103
  return;
104
+ util.attachSchema(payload.issues, currLen, inst);
87
105
  if (!isAborted)
88
106
  isAborted = util.aborted(payload, currLen);
89
107
  });
@@ -92,6 +110,7 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
92
110
  const nextLen = payload.issues.length;
93
111
  if (nextLen === currLen)
94
112
  continue;
113
+ util.attachSchema(payload.issues, currLen, inst);
95
114
  if (!isAborted)
96
115
  isAborted = util.aborted(payload, currLen);
97
116
  }
@@ -103,7 +122,36 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
103
122
  }
104
123
  return payload;
105
124
  };
125
+ const handleCanaryResult = (canary, payload, ctx) => {
126
+ // abort if the canary is aborted
127
+ if (util.aborted(canary)) {
128
+ canary.aborted = true;
129
+ return canary;
130
+ }
131
+ // run checks first, then
132
+ const checkResult = runChecks(payload, checks, ctx);
133
+ if (checkResult instanceof Promise) {
134
+ if (ctx.async === false)
135
+ throw new core.$ZodAsyncError();
136
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
137
+ }
138
+ return inst._zod.parse(checkResult, ctx);
139
+ };
106
140
  inst._zod.run = (payload, ctx) => {
141
+ if (ctx.skipChecks) {
142
+ return inst._zod.parse(payload, ctx);
143
+ }
144
+ if (ctx.direction === "backward") {
145
+ // run canary initial pass (no checks)
146
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
147
+ if (canary instanceof Promise) {
148
+ return canary.then((canary) => {
149
+ return handleCanaryResult(canary, payload, ctx);
150
+ });
151
+ }
152
+ return handleCanaryResult(canary, payload, ctx);
153
+ }
154
+ // forward
107
155
  const result = inst._zod.parse(payload, ctx);
108
156
  if (result instanceof Promise) {
109
157
  if (ctx.async === false)
@@ -113,25 +161,45 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
113
161
  return runChecks(result, checks, ctx);
114
162
  };
115
163
  }
116
- inst["~standard"] = {
164
+ }, {
165
+ // Wrappers extend this by installing a richer factory over it; reading it eagerly would defeat the laziness.
166
+ get "~standard"() {
167
+ return util.hide(this, "~standard", standardProps(this));
168
+ },
169
+ set "~standard"(value) {
170
+ util.own(this, "~standard", value);
171
+ },
172
+ });
173
+ /** The Standard Schema surface for `inst`. Shared so wrappers can extend it without forcing it. */
174
+ // 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
175
+ const toStandardResult = (r, ctx) => r.issues.length ? { issues: r.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())) } : { value: r.value };
176
+ async function validateAsync(inst, value) {
177
+ const ctx = { async: true };
178
+ return toStandardResult((await inst._zod.run({ value, issues: [] }, ctx)), ctx);
179
+ }
180
+ function standardProps(inst) {
181
+ return {
117
182
  validate: (value) => {
183
+ const ctx = { async: false };
118
184
  try {
119
- const r = (0, parse_js_1.safeParse)(inst, value);
120
- return r.success ? { value: r.data } : { issues: r.error?.issues };
121
- }
122
- catch (_) {
123
- return (0, parse_js_1.safeParseAsync)(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
185
+ const r = inst._zod.run({ value, issues: [] }, ctx);
186
+ if (!(r instanceof Promise))
187
+ return toStandardResult(r, ctx);
124
188
  }
189
+ catch (_) { }
190
+ // async function so a synchronously throwing check rejects instead of escaping validate
191
+ return validateAsync(inst, value);
125
192
  },
126
193
  vendor: "zod",
127
194
  version: 1,
128
195
  };
129
- });
196
+ }
130
197
  var util_js_1 = require("./util.cjs");
131
198
  Object.defineProperty(exports, "clone", { enumerable: true, get: function () { return util_js_1.clone; } });
132
199
  exports.$ZodString = core.$constructor("$ZodString", (inst, def) => {
133
200
  exports.$ZodType.init(inst, def);
134
- inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? regexes.string(inst._zod.bag);
201
+ // a format's own pattern, else unbounded; a template literal derives the check-aware form itself
202
+ inst._zod.pattern = def.pattern ?? regexes.anyString;
135
203
  inst._zod.parse = (payload, _) => {
136
204
  if (def.coerce)
137
205
  try {
@@ -183,48 +251,115 @@ exports.$ZodEmail = core.$constructor("$ZodEmail", (inst, def) => {
183
251
  def.pattern ?? (def.pattern = regexes.email);
184
252
  exports.$ZodStringFormat.init(inst, def);
185
253
  });
254
+ /** The `://` guard rejected the input before the URL constructor saw it. */
255
+ exports.URL_BAD_FORMAT = 1;
256
+ /** The URL parser rejected the input. */
257
+ exports.URL_UNPARSEABLE = 2;
258
+ function canParseURL(input) {
259
+ try {
260
+ if (typeof URL !== "undefined" && typeof URL.canParse === "function")
261
+ return URL.canParse(input);
262
+ new URL(input);
263
+ return true;
264
+ }
265
+ catch {
266
+ return false;
267
+ }
268
+ }
269
+ function validateURL(trimmed, def) {
270
+ if (!("normalize" in def) && !("hostname" in def) && !("protocol" in def)) {
271
+ return canParseURL(trimmed) || exports.URL_UNPARSEABLE;
272
+ }
273
+ return parseURLObject(trimmed, def);
274
+ }
275
+ /** Parses a URL while preserving the non-normalizing HTTP guard. */
276
+ function parseURLObject(trimmed, def) {
277
+ // When normalize is off, require :// for http/https URLs. This prevents strings like "http:example.com" or "https:/path" from being silently accepted
278
+ if (!def.normalize && def.protocol?.source === regexes.httpProtocol.source && !/^https?:\/\//i.test(trimmed)) {
279
+ return exports.URL_BAD_FORMAT;
280
+ }
281
+ try {
282
+ if (typeof URL !== "undefined") {
283
+ const URLStatic = URL;
284
+ if (typeof URLStatic.parse === "function")
285
+ return URLStatic.parse(trimmed) ?? exports.URL_UNPARSEABLE;
286
+ }
287
+ // @ts-ignore
288
+ return new URL(trimmed);
289
+ }
290
+ catch {
291
+ return exports.URL_UNPARSEABLE;
292
+ }
293
+ }
294
+ const asciiTabOrNewline = /[\t\n\r]/g;
295
+ /** 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. */
296
+ function stripTabAndNewline(value) {
297
+ return value.replace(asciiTabOrNewline, "");
298
+ }
299
+ function urlHostnameOk(url, hostname) {
300
+ hostname.lastIndex = 0;
301
+ return hostname.test(url.hostname);
302
+ }
303
+ function urlProtocolOk(url, protocol) {
304
+ protocol.lastIndex = 0;
305
+ return protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol);
306
+ }
186
307
  exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
187
308
  exports.$ZodStringFormat.init(inst, def);
188
309
  inst._zod.check = (payload) => {
189
310
  try {
190
- const orig = payload.value;
191
- const url = new URL(orig);
192
- const href = url.href;
193
- if (def.hostname) {
194
- def.hostname.lastIndex = 0;
195
- if (!def.hostname.test(url.hostname)) {
196
- payload.issues.push({
197
- code: "invalid_format",
198
- format: "url",
199
- note: "Invalid hostname",
200
- pattern: regexes.hostname.source,
201
- input: payload.value,
202
- inst,
203
- continue: !def.abort,
204
- });
205
- }
311
+ // Trim whitespace from input
312
+ const trimmed = payload.value.trim();
313
+ const url = validateURL(trimmed, def);
314
+ if (url === exports.URL_BAD_FORMAT) {
315
+ payload.issues.push({
316
+ code: "invalid_format",
317
+ format: "url",
318
+ note: "Invalid URL format",
319
+ input: payload.value,
320
+ inst,
321
+ continue: !def.abort,
322
+ });
323
+ return;
206
324
  }
207
- if (def.protocol) {
208
- def.protocol.lastIndex = 0;
209
- if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
210
- payload.issues.push({
211
- code: "invalid_format",
212
- format: "url",
213
- note: "Invalid protocol",
214
- pattern: def.protocol.source,
215
- input: payload.value,
216
- inst,
217
- continue: !def.abort,
218
- });
219
- }
325
+ if (url === exports.URL_UNPARSEABLE) {
326
+ payload.issues.push({
327
+ code: "invalid_format",
328
+ format: "url",
329
+ input: payload.value,
330
+ inst,
331
+ continue: !def.abort,
332
+ });
333
+ return;
220
334
  }
221
- // payload.value = url.href;
222
- if (!orig.endsWith("/") && href.endsWith("/")) {
223
- payload.value = href.slice(0, -1);
335
+ if (url === true) {
336
+ payload.value = stripTabAndNewline(trimmed);
337
+ return;
224
338
  }
225
- else {
226
- payload.value = href;
339
+ if (def.hostname && !urlHostnameOk(url, def.hostname)) {
340
+ payload.issues.push({
341
+ code: "invalid_format",
342
+ format: "url",
343
+ note: "Invalid hostname",
344
+ pattern: def.hostname.source,
345
+ input: payload.value,
346
+ inst,
347
+ continue: !def.abort,
348
+ });
349
+ }
350
+ if (def.protocol && !urlProtocolOk(url, def.protocol)) {
351
+ payload.issues.push({
352
+ code: "invalid_format",
353
+ format: "url",
354
+ note: "Invalid protocol",
355
+ pattern: def.protocol.source,
356
+ input: payload.value,
357
+ inst,
358
+ continue: !def.abort,
359
+ });
227
360
  }
361
+ // Set the output value based on normalize flag
362
+ payload.value = def.normalize ? url.href : stripTabAndNewline(trimmed);
228
363
  return;
229
364
  }
230
365
  catch (_) {
@@ -243,9 +378,16 @@ exports.$ZodEmoji = core.$constructor("$ZodEmoji", (inst, def) => {
243
378
  exports.$ZodStringFormat.init(inst, def);
244
379
  });
245
380
  exports.$ZodNanoID = core.$constructor("$ZodNanoID", (inst, def) => {
246
- def.pattern ?? (def.pattern = regexes.nanoid);
381
+ if (def.length !== undefined && (!Number.isInteger(def.length) || def.length < 1))
382
+ throw new Error(`Invalid nanoid length: ${def.length}`);
383
+ def.pattern ?? (def.pattern = def.length === undefined ? regexes.nanoid : regexes.nanoidOfLength(def.length));
247
384
  exports.$ZodStringFormat.init(inst, def);
248
385
  });
386
+ /**
387
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
388
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
389
+ * See https://github.com/paralleldrive/cuid.
390
+ */
249
391
  exports.$ZodCUID = core.$constructor("$ZodCUID", (inst, def) => {
250
392
  def.pattern ?? (def.pattern = regexes.cuid);
251
393
  exports.$ZodStringFormat.init(inst, def);
@@ -285,24 +427,19 @@ exports.$ZodISODuration = core.$constructor("$ZodISODuration", (inst, def) => {
285
427
  exports.$ZodIPv4 = core.$constructor("$ZodIPv4", (inst, def) => {
286
428
  def.pattern ?? (def.pattern = regexes.ipv4);
287
429
  exports.$ZodStringFormat.init(inst, def);
288
- inst._zod.onattach.push((inst) => {
289
- const bag = inst._zod.bag;
290
- bag.format = `ipv4`;
291
- });
292
430
  });
431
+ /** 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`. */
432
+ const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
433
+ function isValidIPv6(value) {
434
+ if (!ipv6Alphabet.test(value))
435
+ return false;
436
+ return canParseURL(`http://[${value}]`);
437
+ }
293
438
  exports.$ZodIPv6 = core.$constructor("$ZodIPv6", (inst, def) => {
294
439
  def.pattern ?? (def.pattern = regexes.ipv6);
295
440
  exports.$ZodStringFormat.init(inst, def);
296
- inst._zod.onattach.push((inst) => {
297
- const bag = inst._zod.bag;
298
- bag.format = `ipv6`;
299
- });
300
441
  inst._zod.check = (payload) => {
301
- try {
302
- new URL(`http://[${payload.value}]`);
303
- // return;
304
- }
305
- catch {
442
+ if (!isValidIPv6(payload.value)) {
306
443
  payload.issues.push({
307
444
  code: "invalid_format",
308
445
  format: "ipv6",
@@ -313,26 +450,33 @@ exports.$ZodIPv6 = core.$constructor("$ZodIPv6", (inst, def) => {
313
450
  }
314
451
  };
315
452
  });
453
+ exports.$ZodMAC = core.$constructor("$ZodMAC", (inst, def) => {
454
+ def.pattern ?? (def.pattern = regexes.mac(def.delimiter));
455
+ exports.$ZodStringFormat.init(inst, def);
456
+ });
316
457
  exports.$ZodCIDRv4 = core.$constructor("$ZodCIDRv4", (inst, def) => {
317
458
  def.pattern ?? (def.pattern = regexes.cidrv4);
318
459
  exports.$ZodStringFormat.init(inst, def);
319
460
  });
461
+ function isValidCIDRv6(value) {
462
+ const parts = value.split("/");
463
+ if (parts.length !== 2)
464
+ return false;
465
+ const [address, prefix] = parts;
466
+ if (!prefix)
467
+ return false;
468
+ const prefixNum = Number(prefix);
469
+ if (`${prefixNum}` !== prefix)
470
+ return false;
471
+ if (prefixNum < 0 || prefixNum > 128)
472
+ return false;
473
+ return isValidIPv6(address);
474
+ }
320
475
  exports.$ZodCIDRv6 = core.$constructor("$ZodCIDRv6", (inst, def) => {
321
476
  def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
322
477
  exports.$ZodStringFormat.init(inst, def);
323
478
  inst._zod.check = (payload) => {
324
- const [address, prefix] = payload.value.split("/");
325
- try {
326
- if (!prefix)
327
- throw new Error();
328
- const prefixNum = Number(prefix);
329
- if (`${prefixNum}` !== prefix)
330
- throw new Error();
331
- if (prefixNum < 0 || prefixNum > 128)
332
- throw new Error();
333
- new URL(`http://[${address}]`);
334
- }
335
- catch {
479
+ if (!isValidCIDRv6(payload.value)) {
336
480
  payload.issues.push({
337
481
  code: "invalid_format",
338
482
  format: "cidrv6",
@@ -347,9 +491,13 @@ exports.$ZodCIDRv6 = core.$constructor("$ZodCIDRv6", (inst, def) => {
347
491
  function isValidBase64(data) {
348
492
  if (data === "")
349
493
  return true;
494
+ // atob ignores whitespace, so reject it up front.
495
+ if (/\s/.test(data))
496
+ return false;
350
497
  if (data.length % 4 !== 0)
351
498
  return false;
352
499
  try {
500
+ // @ts-ignore
353
501
  atob(data);
354
502
  return true;
355
503
  }
@@ -357,12 +505,11 @@ function isValidBase64(data) {
357
505
  return false;
358
506
  }
359
507
  }
508
+ // 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
509
+ exports.base64Charset = /^[0-9a-zA-Z+/]*={0,2}$/;
360
510
  exports.$ZodBase64 = core.$constructor("$ZodBase64", (inst, def) => {
361
- def.pattern ?? (def.pattern = regexes.base64);
511
+ def.pattern ?? (def.pattern = exports.base64Charset);
362
512
  exports.$ZodStringFormat.init(inst, def);
363
- inst._zod.onattach.push((inst) => {
364
- inst._zod.bag.contentEncoding = "base64";
365
- });
366
513
  inst._zod.check = (payload) => {
367
514
  if (isValidBase64(payload.value))
368
515
  return;
@@ -375,20 +522,19 @@ exports.$ZodBase64 = core.$constructor("$ZodBase64", (inst, def) => {
375
522
  });
376
523
  };
377
524
  });
378
- ////////////////////////////// ZodBase64 //////////////////////////////
525
+ ////////////////////////////// ZodBase64URL //////////////////////////////
526
+ // lax on purpose: the quantified regexes.base64url overflows the regex stack on multi-MB input; isValidBase64 enforces length on the padded string
527
+ exports.base64urlCharset = /^[A-Za-z0-9_-]*$/;
379
528
  function isValidBase64URL(data) {
380
- if (!regexes.base64url.test(data))
529
+ if (!exports.base64urlCharset.test(data))
381
530
  return false;
382
531
  const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
383
532
  const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
384
533
  return isValidBase64(padded);
385
534
  }
386
535
  exports.$ZodBase64URL = core.$constructor("$ZodBase64URL", (inst, def) => {
387
- def.pattern ?? (def.pattern = regexes.base64url);
536
+ def.pattern ?? (def.pattern = exports.base64urlCharset);
388
537
  exports.$ZodStringFormat.init(inst, def);
389
- inst._zod.onattach.push((inst) => {
390
- inst._zod.bag.contentEncoding = "base64url";
391
- });
392
538
  inst._zod.check = (payload) => {
393
539
  if (isValidBase64URL(payload.value))
394
540
  return;
@@ -405,6 +551,77 @@ exports.$ZodE164 = core.$constructor("$ZodE164", (inst, def) => {
405
551
  def.pattern ?? (def.pattern = regexes.e164);
406
552
  exports.$ZodStringFormat.init(inst, def);
407
553
  });
554
+ ////////////////////////////// ZodCreditCard //////////////////////////////
555
+ const CC_SANITIZE = /[- ]/g;
556
+ /** Luhn checksum on a digit-only string. Adapted from valibot (MIT). */
557
+ function isLuhnAlgo(digits) {
558
+ let length = digits.length;
559
+ let bit = 1;
560
+ let sum = 0;
561
+ while (length) {
562
+ const value = digits.charCodeAt(--length) - 48;
563
+ bit ^= 1;
564
+ sum += bit ? [0, 2, 4, 6, 8, 1, 3, 5, 7, 9][value] : value;
565
+ }
566
+ return sum % 10 === 0;
567
+ }
568
+ function isValidCreditCard(input) {
569
+ if (!regexes.creditCard.test(input))
570
+ return false;
571
+ return isLuhnAlgo(input.replace(CC_SANITIZE, ""));
572
+ }
573
+ exports.$ZodCreditCard = core.$constructor("$ZodCreditCard", (inst, def) => {
574
+ // 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.
575
+ def.pattern ?? (def.pattern = regexes.creditCard);
576
+ exports.$ZodStringFormat.init(inst, def);
577
+ inst._zod.check = (payload) => {
578
+ if (isValidCreditCard(payload.value))
579
+ return;
580
+ payload.issues.push({
581
+ code: "invalid_format",
582
+ format: "credit_card",
583
+ input: payload.value,
584
+ inst,
585
+ continue: !def.abort,
586
+ });
587
+ };
588
+ });
589
+ ////////////////////////////// ZodIBAN //////////////////////////////
590
+ // iso 7064 mod 97-10 checksum without BigInt
591
+ function isIso7064Mod97(iban) {
592
+ let remainder = 0;
593
+ const len = iban.length;
594
+ for (let i = 4; i < len; i++) {
595
+ const code = iban.charCodeAt(i);
596
+ remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
597
+ }
598
+ for (let i = 0; i < 4; i++) {
599
+ const code = iban.charCodeAt(i);
600
+ remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
601
+ }
602
+ return remainder === 1;
603
+ }
604
+ function isValidIBAN(input) {
605
+ if (!regexes.iban.test(input))
606
+ return false;
607
+ return isIso7064Mod97(input);
608
+ }
609
+ exports.$ZodIBAN = core.$constructor("$ZodIBAN", (inst, def) => {
610
+ // shape only — checksum is not expressible as a pattern
611
+ def.pattern ?? (def.pattern = regexes.iban);
612
+ exports.$ZodStringFormat.init(inst, def);
613
+ inst._zod.check = (payload) => {
614
+ if (isValidIBAN(payload.value))
615
+ return;
616
+ payload.issues.push({
617
+ code: "invalid_format",
618
+ format: "iban",
619
+ input: payload.value,
620
+ inst,
621
+ continue: !def.abort,
622
+ });
623
+ };
624
+ });
408
625
  ////////////////////////////// ZodJWT //////////////////////////////
409
626
  function isValidJWT(token, algorithm = null) {
410
627
  try {
@@ -414,6 +631,7 @@ function isValidJWT(token, algorithm = null) {
414
631
  const [header] = tokensParts;
415
632
  if (!header)
416
633
  return false;
634
+ // @ts-ignore
417
635
  const parsedHeader = JSON.parse(atob(header));
418
636
  if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
419
637
  return false;
@@ -457,7 +675,7 @@ exports.$ZodCustomStringFormat = core.$constructor("$ZodCustomStringFormat", (in
457
675
  });
458
676
  exports.$ZodNumber = core.$constructor("$ZodNumber", (inst, def) => {
459
677
  exports.$ZodType.init(inst, def);
460
- inst._zod.pattern = inst._zod.bag.pattern ?? regexes.number;
678
+ inst._zod.pattern = regexes.number;
461
679
  inst._zod.parse = (payload, _ctx) => {
462
680
  if (def.coerce)
463
681
  try {
@@ -472,7 +690,7 @@ exports.$ZodNumber = core.$constructor("$ZodNumber", (inst, def) => {
472
690
  ? Number.isNaN(input)
473
691
  ? "NaN"
474
692
  : !Number.isFinite(input)
475
- ? "Infinity"
693
+ ? String(input)
476
694
  : undefined
477
695
  : undefined;
478
696
  payload.issues.push({
@@ -485,9 +703,9 @@ exports.$ZodNumber = core.$constructor("$ZodNumber", (inst, def) => {
485
703
  return payload;
486
704
  };
487
705
  });
488
- exports.$ZodNumberFormat = core.$constructor("$ZodNumber", (inst, def) => {
706
+ exports.$ZodNumberFormat = core.$constructor("$ZodNumberFormat", (inst, def) => {
489
707
  checks.$ZodCheckNumberFormat.init(inst, def);
490
- exports.$ZodNumber.init(inst, def); // no format checksp
708
+ exports.$ZodNumber.init(inst, def); // no format checks
491
709
  });
492
710
  exports.$ZodBoolean = core.$constructor("$ZodBoolean", (inst, def) => {
493
711
  exports.$ZodType.init(inst, def);
@@ -530,7 +748,7 @@ exports.$ZodBigInt = core.$constructor("$ZodBigInt", (inst, def) => {
530
748
  return payload;
531
749
  };
532
750
  });
533
- exports.$ZodBigIntFormat = core.$constructor("$ZodBigInt", (inst, def) => {
751
+ exports.$ZodBigIntFormat = core.$constructor("$ZodBigIntFormat", (inst, def) => {
534
752
  checks.$ZodCheckBigIntFormat.init(inst, def);
535
753
  exports.$ZodBigInt.init(inst, def); // no format checks
536
754
  });
@@ -553,8 +771,6 @@ exports.$ZodUndefined = core.$constructor("$ZodUndefined", (inst, def) => {
553
771
  exports.$ZodType.init(inst, def);
554
772
  inst._zod.pattern = regexes.undefined;
555
773
  inst._zod.values = new Set([undefined]);
556
- inst._zod.optin = "optional";
557
- inst._zod.optout = "optional";
558
774
  inst._zod.parse = (payload, _ctx) => {
559
775
  const input = payload.value;
560
776
  if (typeof input === "undefined")
@@ -644,6 +860,33 @@ exports.$ZodDate = core.$constructor("$ZodDate", (inst, def) => {
644
860
  return payload;
645
861
  };
646
862
  });
863
+ // an oversized container fails its leading size checks before any element is parsed
864
+ function capSize(inst, size) {
865
+ const caps = util.sizeCaps(inst._zod.def.checks);
866
+ if (!caps.length)
867
+ return;
868
+ const cap = Math.min(...caps.map((c) => c[0]));
869
+ const parse = inst._zod.parse;
870
+ inst._zod.parse = (payload, ctx) => {
871
+ const n = size(payload.value);
872
+ if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
873
+ for (const [max, ch] of util.sizeCaps(inst._zod.def.checks)) {
874
+ if (n > max && ch._zod.def.when(payload)) {
875
+ const start = payload.issues.length;
876
+ ch._zod.check(payload);
877
+ // the value is still the raw input, so no later check may read it
878
+ payload.issues[start].continue = false;
879
+ util.attachSchema(payload.issues, start, inst);
880
+ return payload;
881
+ }
882
+ }
883
+ }
884
+ return parse(payload, ctx);
885
+ };
886
+ }
887
+ const arraySize = (input) => (Array.isArray(input) ? input.length : -1);
888
+ const mapSize = (input) => (input instanceof Map ? input.size : -1);
889
+ const setSize = (input) => (input instanceof Set ? input.size : -1);
647
890
  function handleArrayResult(result, final, index) {
648
891
  if (result.issues.length) {
649
892
  final.issues.push(...util.prefixIssues(index, result.issues));
@@ -652,6 +895,8 @@ function handleArrayResult(result, final, index) {
652
895
  }
653
896
  exports.$ZodArray = core.$constructor("$ZodArray", (inst, def) => {
654
897
  exports.$ZodType.init(inst, def);
898
+ const memo = core.globalConfig.memoizer;
899
+ memo?.attach(inst);
655
900
  inst._zod.parse = (payload, ctx) => {
656
901
  const input = payload.value;
657
902
  if (!Array.isArray(input)) {
@@ -663,8 +908,9 @@ exports.$ZodArray = core.$constructor("$ZodArray", (inst, def) => {
663
908
  });
664
909
  return payload;
665
910
  }
666
- payload.value = Array(input.length);
911
+ payload.value = memo ? memo.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
667
912
  const proms = [];
913
+ const abortEarly = ctx?.abortEarly;
668
914
  for (let i = 0; i < input.length; i++) {
669
915
  const item = input[i];
670
916
  const result = def.element._zod.run({
@@ -676,6 +922,9 @@ exports.$ZodArray = core.$constructor("$ZodArray", (inst, def) => {
676
922
  }
677
923
  else {
678
924
  handleArrayResult(result, payload, i);
925
+ // the element's payload is authoritative here, since handleArrayResult forwards every issue; an object's is not, because it drops a failed absent optional
926
+ if (abortEarly && result.issues.length !== 0 && util.aborted(result))
927
+ break;
679
928
  }
680
929
  }
681
930
  if (proms.length) {
@@ -683,129 +932,306 @@ exports.$ZodArray = core.$constructor("$ZodArray", (inst, def) => {
683
932
  }
684
933
  return payload; //handleArrayResultsAsync(parseResults, final);
685
934
  };
935
+ capSize(inst, arraySize);
686
936
  });
687
- function handleObjectResult(result, final, key) {
688
- // if(isOptional)
689
- if (result.issues.length) {
690
- final.issues.push(...util.prefixIssues(key, result.issues));
937
+ function handlePropertyResult(result, final, key, input, optin, optout) {
938
+ const isPresent = key in input;
939
+ const isOptionalOut = optout === "optional";
940
+ // 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.
941
+ if (!isPresent && isOptionalOut && optin === "optional") {
942
+ return;
691
943
  }
692
- final.value[key] = result.value;
693
- }
694
- function handleOptionalObjectResult(result, final, key, input) {
695
944
  if (result.issues.length) {
696
- // validation failed against value schema
697
- if (input[key] === undefined) {
698
- // if input was undefined, ignore the error
699
- if (key in input) {
700
- final.value[key] = undefined;
701
- }
702
- else {
703
- final.value[key] = result.value;
704
- }
945
+ // For optional-in/out schemas, ignore errors on absent keys.
946
+ if (optin !== undefined && isOptionalOut && !isPresent) {
947
+ return;
705
948
  }
706
- else {
707
- final.issues.push(...util.prefixIssues(key, result.issues));
949
+ final.issues.push(...util.prefixIssues(key, result.issues));
950
+ }
951
+ if (!isPresent && optin === undefined) {
952
+ if (!result.issues.length) {
953
+ final.issues.push({
954
+ code: "invalid_type",
955
+ expected: "nonoptional",
956
+ input: undefined,
957
+ path: [key],
958
+ });
708
959
  }
960
+ return;
709
961
  }
710
- else if (result.value === undefined) {
711
- // validation returned `undefined`
712
- if (key in input)
962
+ if (result.value === undefined) {
963
+ if (isPresent || (optin === "defaulted" && !isOptionalOut)) {
713
964
  final.value[key] = undefined;
965
+ }
714
966
  }
715
967
  else {
716
- // non-undefined value
717
968
  final.value[key] = result.value;
718
969
  }
719
970
  }
971
+ // one shared instance; a fresh [] per schema cost 56 bytes retained
972
+ const NO_SYMBOL_KEYS = [];
973
+ function normalizeDef(def) {
974
+ const keys = Object.keys(def.shape);
975
+ const ownSymbols = Object.getOwnPropertySymbols(def.shape);
976
+ const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
977
+ // aliases `keys` when there are no symbols, so a string-only shape keeps one array
978
+ const allKeys = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
979
+ for (const k of allKeys) {
980
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
981
+ throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
982
+ }
983
+ }
984
+ const okeys = util.optionalKeys(def.shape);
985
+ return {
986
+ ...def,
987
+ allKeys,
988
+ symbolKeys,
989
+ // string-only: handleCatchall matches it against `for...in`, which never yields a symbol
990
+ keySet: new Set(keys),
991
+ numKeys: keys.length,
992
+ optionalKeys: new Set(okeys),
993
+ };
994
+ }
995
+ function handleCatchall(proms, input, payload, ctx, def, inst, abortEarly) {
996
+ const unrecognized = [];
997
+ const keySet = def.keySet;
998
+ const _catchall = def.catchall._zod;
999
+ const t = _catchall.def.type;
1000
+ const optin = _catchall.optin;
1001
+ const optout = _catchall.optout;
1002
+ // starts at 0, not the current length: the shape phase already ran and may have aborted
1003
+ let seen = 0;
1004
+ for (const key in input) {
1005
+ if (abortEarly && payload.issues.length !== seen) {
1006
+ if (util.aborted(payload, seen))
1007
+ break;
1008
+ seen = payload.issues.length;
1009
+ }
1010
+ // Must precede the __proto__ branch: a declared key is not unrecognized, even though the shape loop deliberately strips __proto__ from the parsed output.
1011
+ if (keySet.has(key))
1012
+ continue;
1013
+ // 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.
1014
+ if (key === "__proto__") {
1015
+ if (t === "never")
1016
+ unrecognized.push(key);
1017
+ continue;
1018
+ }
1019
+ if (t === "never") {
1020
+ unrecognized.push(key);
1021
+ continue;
1022
+ }
1023
+ const r = _catchall.run({ value: input[key], issues: [] }, ctx);
1024
+ if (r instanceof Promise) {
1025
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
1026
+ }
1027
+ else {
1028
+ handlePropertyResult(r, payload, key, input, optin, optout);
1029
+ }
1030
+ }
1031
+ if (unrecognized.length) {
1032
+ payload.issues.push({
1033
+ code: "unrecognized_keys",
1034
+ keys: unrecognized,
1035
+ input,
1036
+ inst,
1037
+ // 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.
1038
+ continue: true,
1039
+ });
1040
+ }
1041
+ if (!proms.length)
1042
+ return payload;
1043
+ return Promise.all(proms).then(() => {
1044
+ return payload;
1045
+ });
1046
+ }
720
1047
  exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
721
1048
  // requires cast because technically $ZodObject doesn't extend
722
1049
  exports.$ZodType.init(inst, def);
723
- const _normalized = util.cached(() => {
724
- const keys = Object.keys(def.shape);
725
- for (const k of keys) {
726
- if (!(def.shape[k] instanceof exports.$ZodType)) {
727
- throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
728
- }
729
- }
730
- const okeys = util.optionalKeys(def.shape);
731
- return {
732
- shape: def.shape,
733
- keys,
734
- keySet: new Set(keys),
735
- numKeys: keys.length,
736
- optionalKeys: new Set(okeys),
1050
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
1051
+ // 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
1052
+ const sh = desc?.get ? desc.get.raw : (def.shape ?? {});
1053
+ if (sh) {
1054
+ // Freezes the shape on first read, so its getters resolve once and every later read sees the same schemas.
1055
+ const get = () => {
1056
+ const newSh = { ...sh };
1057
+ Object.defineProperty(def, "shape", { value: newSh });
1058
+ get.raw = newSh;
1059
+ return newSh;
737
1060
  };
738
- });
739
- util.defineLazy(inst._zod, "propValues", () => {
740
- const shape = def.shape;
1061
+ get.raw = sh;
1062
+ Object.defineProperty(def, "shape", { get });
1063
+ }
1064
+ const _normalized = util.cached(() => normalizeDef(def));
1065
+ util.defineLazyInternal(inst, "propValues", (zod) => {
1066
+ const shape = zod.def.shape;
741
1067
  const propValues = {};
742
1068
  for (const key in shape) {
743
1069
  const field = shape[key]._zod;
744
1070
  if (field.values) {
745
- propValues[key] ?? (propValues[key] = new Set());
1071
+ if (!Object.prototype.hasOwnProperty.call(propValues, key)) {
1072
+ util.assignProp(propValues, key, new Set());
1073
+ }
746
1074
  for (const v of field.values)
747
1075
  propValues[key].add(v);
1076
+ // 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.
1077
+ if (field.optin !== undefined)
1078
+ propValues[key].add(undefined);
748
1079
  }
749
1080
  }
750
1081
  return propValues;
751
1082
  });
1083
+ const isObject = util.isObject;
1084
+ const catchall = def.catchall;
1085
+ let value;
1086
+ const memo = core.globalConfig.memoizer;
1087
+ memo?.attach(inst);
1088
+ inst._zod.parse = (payload, ctx) => {
1089
+ value ?? (value = _normalized.value);
1090
+ const input = payload.value;
1091
+ if (!isObject(input)) {
1092
+ payload.issues.push({
1093
+ expected: "object",
1094
+ code: "invalid_type",
1095
+ input,
1096
+ inst,
1097
+ });
1098
+ return payload;
1099
+ }
1100
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
1101
+ const proms = [];
1102
+ const shape = value.shape;
1103
+ const abortEarly = ctx?.abortEarly;
1104
+ let seen = payload.issues.length;
1105
+ for (const key of value.allKeys) {
1106
+ if (abortEarly && payload.issues.length !== seen) {
1107
+ if (util.aborted(payload, seen))
1108
+ break;
1109
+ seen = payload.issues.length;
1110
+ }
1111
+ if (key === "__proto__")
1112
+ continue;
1113
+ const el = shape[key];
1114
+ const optin = el._zod.optin;
1115
+ const optout = el._zod.optout;
1116
+ const r = el._zod.run({ value: input[key], issues: [] }, ctx);
1117
+ if (r instanceof Promise) {
1118
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
1119
+ }
1120
+ else {
1121
+ handlePropertyResult(r, payload, key, input, optin, optout);
1122
+ }
1123
+ }
1124
+ if (!catchall) {
1125
+ return proms.length ? Promise.all(proms).then(() => payload) : payload;
1126
+ }
1127
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst, abortEarly === true);
1128
+ };
1129
+ });
1130
+ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
1131
+ // requires cast because technically $ZodObject doesn't extend
1132
+ exports.$ZodObject.init(inst, def);
1133
+ const superParse = inst._zod.parse;
1134
+ const _normalized = util.cached(() => normalizeDef(def));
1135
+ const memo = core.globalConfig.memoizer;
752
1136
  const generateFastpass = (shape) => {
753
- const doc = new doc_js_1.Doc(["shape", "payload", "ctx"]);
754
1137
  const normalized = _normalized.value;
755
- const parseStr = (key) => {
756
- const k = util.esc(key);
757
- return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
758
- };
1138
+ const syms = normalized.symbolKeys;
1139
+ // a symbol has no source literal, so it is read as `syms[i]` off the closed-over scope
1140
+ const doc = new doc_js_1.Doc(["payload", "ctx"], { shape, inst, memo, syms });
1141
+ const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1142
+ // 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
1143
+ const prefixStr = (id, k) => `
1144
+ let ${id}_ab = false;
1145
+ for (let i = 0; i < ${id}.issues.length; i++) {
1146
+ const iss = ${id}.issues[i];
1147
+ iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
1148
+ payload.issues.push(iss);
1149
+ if (iss.continue !== true) ${id}_ab = true;
1150
+ }
1151
+ if (${id}_ab && ctx && ctx.abortEarly) {
1152
+ payload.value = newResult;
1153
+ return payload;
1154
+ }`;
759
1155
  doc.write(`const input = payload.value;`);
760
1156
  const ids = Object.create(null);
761
1157
  let counter = 0;
762
- for (const key of normalized.keys) {
1158
+ for (const key of normalized.allKeys) {
763
1159
  ids[key] = `key_${counter++}`;
764
1160
  }
765
1161
  // A: preserve key order {
766
- doc.write(`const newResult = {}`);
767
- for (const key of normalized.keys) {
768
- if (normalized.optionalKeys.has(key)) {
769
- const id = ids[key];
770
- doc.write(`const ${id} = ${parseStr(key)};`);
771
- const k = util.esc(key);
1162
+ doc.write(memo ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
1163
+ for (const key of normalized.allKeys) {
1164
+ if (key === "__proto__")
1165
+ continue;
1166
+ const id = ids[key];
1167
+ const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : util.esc(key);
1168
+ const isPresent = `${k} in input`;
1169
+ const schema = shape[key];
1170
+ const optin = schema?._zod?.optin;
1171
+ const isOptionalIn = optin !== undefined;
1172
+ const isOptionalOut = schema?._zod?.optout === "optional";
1173
+ doc.write(`const ${id} = ${parseStr(k)};`);
1174
+ if (isOptionalIn && isOptionalOut) {
1175
+ // 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.
1176
+ const assign = optin === "optional" ? `${id}_present` : `${id}.value !== undefined || ${id}_present`;
772
1177
  doc.write(`
773
- if (${id}.issues.length) {
774
- if (input[${k}] === undefined) {
775
- if (${k} in input) {
776
- newResult[${k}] = undefined;
1178
+ const ${id}_present = ${isPresent};
1179
+ if (!${id}.issues.length || ${id}_present) {
1180
+ if (${id}.issues.length) {${prefixStr(id, k)}
1181
+ }
1182
+
1183
+ if (${assign}) {
1184
+ newResult[${k}] = ${id}.value;
1185
+ }
1186
+ }
1187
+
1188
+ `);
777
1189
  }
778
- } else {
779
- payload.issues = payload.issues.concat(
780
- ${id}.issues.map((iss) => ({
781
- ...iss,
782
- path: iss.path ? [${k}, ...iss.path] : [${k}],
783
- }))
784
- );
1190
+ else if (!isOptionalIn) {
1191
+ doc.write(`
1192
+ const ${id}_present = ${isPresent};
1193
+ if (${id}.issues.length) {${prefixStr(id, k)}
1194
+ }
1195
+ if (!${id}_present && !${id}.issues.length) {
1196
+ payload.issues.push({
1197
+ code: "invalid_type",
1198
+ expected: "nonoptional",
1199
+ input: undefined,
1200
+ path: [${k}]
1201
+ });
1202
+ if (ctx && ctx.abortEarly) {
1203
+ payload.value = newResult;
1204
+ return payload;
785
1205
  }
786
- } else if (${id}.value === undefined) {
787
- if (${k} in input) newResult[${k}] = undefined;
788
- } else {
1206
+ }
1207
+
1208
+ if (${id}_present) {
789
1209
  newResult[${k}] = ${id}.value;
790
1210
  }
791
- `);
1211
+
1212
+ `);
792
1213
  }
793
1214
  else {
794
- const id = ids[key];
795
- // const id = ids[key];
796
- doc.write(`const ${id} = ${parseStr(key)};`);
797
1215
  doc.write(`
798
- if (${id}.issues.length) payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
799
- ...iss,
800
- path: iss.path ? [${util.esc(key)}, ...iss.path] : [${util.esc(key)}]
801
- })));`);
802
- doc.write(`newResult[${util.esc(key)}] = ${id}.value`);
1216
+ if (${id}.issues.length) {${prefixStr(id, k)}
1217
+ }
1218
+ `);
1219
+ if (optin === "defaulted") {
1220
+ doc.write(`newResult[${k}] = ${id}.value;`);
1221
+ }
1222
+ else {
1223
+ doc.write(`
1224
+ if (${id}.value !== undefined || ${isPresent}) {
1225
+ newResult[${k}] = ${id}.value;
1226
+ }
1227
+ `);
1228
+ }
803
1229
  }
804
1230
  }
805
1231
  doc.write(`payload.value = newResult;`);
806
1232
  doc.write(`return payload;`);
807
- const fn = doc.compile();
808
- return (payload, ctx) => fn(shape, payload, ctx);
1233
+ // 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
1234
+ return doc.compile();
809
1235
  };
810
1236
  let fastpass;
811
1237
  const isObject = util.isObject;
@@ -826,80 +1252,16 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
826
1252
  });
827
1253
  return payload;
828
1254
  }
829
- const proms = [];
830
1255
  if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
831
1256
  // always synchronous
832
1257
  if (!fastpass)
833
1258
  fastpass = generateFastpass(def.shape);
834
1259
  payload = fastpass(payload, ctx);
1260
+ if (!catchall)
1261
+ return payload;
1262
+ return handleCatchall([], input, payload, ctx, value, inst, ctx?.abortEarly === true);
835
1263
  }
836
- else {
837
- payload.value = {};
838
- const shape = value.shape;
839
- for (const key of value.keys) {
840
- const el = shape[key];
841
- // do not add omitted optional keys
842
- // if (!(key in input)) {
843
- // if (optionalKeys.has(key)) continue;
844
- // payload.issues.push({
845
- // code: "invalid_type",
846
- // path: [key],
847
- // expected: "nonoptional",
848
- // note: `Missing required key: "${key}"`,
849
- // input,
850
- // inst,
851
- // });
852
- // }
853
- const r = el._zod.run({ value: input[key], issues: [] }, ctx);
854
- const isOptional = el._zod.optin === "optional" && el._zod.optout === "optional";
855
- if (r instanceof Promise) {
856
- proms.push(r.then((r) => isOptional ? handleOptionalObjectResult(r, payload, key, input) : handleObjectResult(r, payload, key)));
857
- }
858
- else if (isOptional) {
859
- handleOptionalObjectResult(r, payload, key, input);
860
- }
861
- else {
862
- handleObjectResult(r, payload, key);
863
- }
864
- }
865
- }
866
- if (!catchall) {
867
- // return payload;
868
- return proms.length ? Promise.all(proms).then(() => payload) : payload;
869
- }
870
- const unrecognized = [];
871
- // iterate over input keys
872
- const keySet = value.keySet;
873
- const _catchall = catchall._zod;
874
- const t = _catchall.def.type;
875
- for (const key of Object.keys(input)) {
876
- if (keySet.has(key))
877
- continue;
878
- if (t === "never") {
879
- unrecognized.push(key);
880
- continue;
881
- }
882
- const r = _catchall.run({ value: input[key], issues: [] }, ctx);
883
- if (r instanceof Promise) {
884
- proms.push(r.then((r) => handleObjectResult(r, payload, key)));
885
- }
886
- else {
887
- handleObjectResult(r, payload, key);
888
- }
889
- }
890
- if (unrecognized.length) {
891
- payload.issues.push({
892
- code: "unrecognized_keys",
893
- keys: unrecognized,
894
- input,
895
- inst,
896
- });
897
- }
898
- if (!proms.length)
899
- return payload;
900
- return Promise.all(proms).then(() => {
901
- return payload;
902
- });
1264
+ return superParse(payload, ctx);
903
1265
  };
904
1266
  });
905
1267
  function handleUnionResults(results, final, inst, ctx) {
@@ -909,6 +1271,11 @@ function handleUnionResults(results, final, inst, ctx) {
909
1271
  return final;
910
1272
  }
911
1273
  }
1274
+ const nonaborted = results.filter((r) => !util.aborted(r));
1275
+ if (nonaborted.length === 1) {
1276
+ final.value = nonaborted[0].value;
1277
+ return nonaborted[0];
1278
+ }
912
1279
  final.issues.push({
913
1280
  code: "invalid_union",
914
1281
  input: final.value,
@@ -919,22 +1286,30 @@ function handleUnionResults(results, final, inst, ctx) {
919
1286
  }
920
1287
  exports.$ZodUnion = core.$constructor("$ZodUnion", (inst, def) => {
921
1288
  exports.$ZodType.init(inst, def);
922
- util.defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined);
923
- util.defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
924
- util.defineLazy(inst._zod, "values", () => {
925
- if (def.options.every((o) => o._zod.values)) {
926
- return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1289
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.options.some((o) => o._zod.optin === "defaulted")
1290
+ ? "defaulted"
1291
+ : zod.def.options.some((o) => o._zod.optin !== undefined)
1292
+ ? "optional"
1293
+ : undefined);
1294
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
1295
+ util.defineLazyInternal(inst, "values", (zod) => {
1296
+ if (zod.def.options.every((o) => o._zod.values)) {
1297
+ return new Set(zod.def.options.flatMap((option) => Array.from(option._zod.values)));
927
1298
  }
928
1299
  return undefined;
929
1300
  });
930
- util.defineLazy(inst._zod, "pattern", () => {
931
- if (def.options.every((o) => o._zod.pattern)) {
932
- const patterns = def.options.map((o) => o._zod.pattern);
1301
+ util.defineLazyInternal(inst, "pattern", (zod) => {
1302
+ if (zod.def.options.every((o) => o._zod.pattern)) {
1303
+ const patterns = zod.def.options.map((o) => o._zod.pattern);
933
1304
  return new RegExp(`^(${patterns.map((p) => util.cleanRegex(p.source)).join("|")})$`);
934
1305
  }
935
1306
  return undefined;
936
1307
  });
1308
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
937
1309
  inst._zod.parse = (payload, ctx) => {
1310
+ if (first) {
1311
+ return first(payload, ctx);
1312
+ }
938
1313
  let async = false;
939
1314
  const results = [];
940
1315
  for (const option of def.options) {
@@ -959,43 +1334,137 @@ exports.$ZodUnion = core.$constructor("$ZodUnion", (inst, def) => {
959
1334
  });
960
1335
  };
961
1336
  });
1337
+ function handleExclusiveUnionResults(results, final, inst, ctx) {
1338
+ const matches = [];
1339
+ for (let i = 0; i < results.length; i++) {
1340
+ if (results[i].issues.length === 0)
1341
+ matches.push(i);
1342
+ }
1343
+ if (matches.length === 1) {
1344
+ final.value = results[matches[0]].value;
1345
+ return final;
1346
+ }
1347
+ if (matches.length === 0) {
1348
+ // No matches - same as regular union
1349
+ final.issues.push({
1350
+ code: "invalid_union",
1351
+ input: final.value,
1352
+ inst,
1353
+ errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
1354
+ });
1355
+ }
1356
+ else {
1357
+ // Multiple matches - exclusive union failure
1358
+ final.issues.push({
1359
+ code: "invalid_union",
1360
+ input: final.value,
1361
+ inst,
1362
+ errors: [],
1363
+ inclusive: false,
1364
+ matches,
1365
+ });
1366
+ }
1367
+ return final;
1368
+ }
1369
+ exports.$ZodXor = core.$constructor("$ZodXor", (inst, def) => {
1370
+ exports.$ZodUnion.init(inst, def);
1371
+ def.inclusive = false;
1372
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
1373
+ inst._zod.parse = (payload, ctx) => {
1374
+ if (first) {
1375
+ return first(payload, ctx);
1376
+ }
1377
+ let async = false;
1378
+ const results = [];
1379
+ for (const option of def.options) {
1380
+ const result = option._zod.run({
1381
+ value: payload.value,
1382
+ issues: [],
1383
+ }, ctx);
1384
+ if (result instanceof Promise) {
1385
+ results.push(result);
1386
+ async = true;
1387
+ }
1388
+ else {
1389
+ results.push(result);
1390
+ }
1391
+ }
1392
+ if (!async)
1393
+ return handleExclusiveUnionResults(results, payload, inst, ctx);
1394
+ return Promise.all(results).then((results) => {
1395
+ return handleExclusiveUnionResults(results, payload, inst, ctx);
1396
+ });
1397
+ };
1398
+ });
1399
+ /** Returns the option whose discriminator claims `value`, or throws if ambiguous. */
1400
+ function getDiscriminatedOption(union, value) {
1401
+ const internals = union._zod;
1402
+ let map = internals.bag.optionsMap;
1403
+ if (!map) {
1404
+ map = discriminatorMap(internals.def);
1405
+ internals.bag.optionsMap = map;
1406
+ }
1407
+ const option = map.get(value);
1408
+ if (option === null)
1409
+ throw new Error(`Ambiguous discriminator value "${String(value)}"`);
1410
+ return option;
1411
+ }
1412
+ function discriminatorMap(def) {
1413
+ const map = new Map();
1414
+ for (const option of def.options) {
1415
+ const values = option._zod.propValues?.[def.discriminator];
1416
+ if (!values || values.size === 0)
1417
+ throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
1418
+ for (const value of values) {
1419
+ if (map.has(value)) {
1420
+ if (value !== undefined)
1421
+ throw new Error(`Duplicate discriminator value "${String(value)}"`);
1422
+ // keep the collision marked so a later member cannot reclaim it
1423
+ map.set(value, null);
1424
+ }
1425
+ else {
1426
+ map.set(value, option);
1427
+ }
1428
+ }
1429
+ }
1430
+ return map;
1431
+ }
962
1432
  exports.$ZodDiscriminatedUnion =
963
1433
  /*@__PURE__*/
964
1434
  core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1435
+ def.inclusive = false;
965
1436
  exports.$ZodUnion.init(inst, def);
966
1437
  const _super = inst._zod.parse;
967
- util.defineLazy(inst._zod, "propValues", () => {
1438
+ util.defineLazyInternal(inst, "propValues", (zod) => {
968
1439
  const propValues = {};
969
- for (const option of def.options) {
1440
+ let undefinedCount = 0;
1441
+ for (const option of zod.def.options) {
970
1442
  const pv = option._zod.propValues;
971
1443
  if (!pv || Object.keys(pv).length === 0)
972
- throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
1444
+ throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
1445
+ if (pv[zod.def.discriminator]?.has(undefined))
1446
+ undefinedCount++;
973
1447
  for (const [k, v] of Object.entries(pv)) {
974
- if (!propValues[k])
975
- propValues[k] = new Set();
1448
+ if (!Object.prototype.hasOwnProperty.call(propValues, k)) {
1449
+ util.assignProp(propValues, k, new Set());
1450
+ }
976
1451
  for (const val of v) {
977
1452
  propValues[k].add(val);
978
1453
  }
979
1454
  }
980
1455
  }
1456
+ if (!zod.def.unionFallback && undefinedCount > 1)
1457
+ propValues[zod.def.discriminator]?.delete(undefined);
981
1458
  return propValues;
982
1459
  });
983
- const disc = util.cached(() => {
984
- const opts = def.options;
985
- const map = new Map();
986
- for (const o of opts) {
987
- const values = o._zod.propValues[def.discriminator];
988
- if (!values || values.size === 0)
989
- throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
990
- for (const v of values) {
991
- if (map.has(v)) {
992
- throw new Error(`Duplicate discriminator value "${String(v)}"`);
993
- }
994
- map.set(v, o);
995
- }
1460
+ // 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.
1461
+ def.options.forEach((option, i) => {
1462
+ const propShape = util.rawShape(option._zod.def);
1463
+ if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) {
1464
+ throw new Error(`Invalid discriminated union option at index "${i}"`);
996
1465
  }
997
- return map;
998
1466
  });
1467
+ const disc = util.cached(() => discriminatorMap(def));
999
1468
  inst._zod.parse = (payload, ctx) => {
1000
1469
  const input = payload.value;
1001
1470
  if (!util.isObject(input)) {
@@ -1007,11 +1476,16 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1007
1476
  });
1008
1477
  return payload;
1009
1478
  }
1010
- const opt = disc.value.get(input?.[def.discriminator]);
1011
- if (opt) {
1479
+ const value = input?.[def.discriminator];
1480
+ const opt = disc.value.get(value);
1481
+ // forward metadata cannot choose an encoder for an absent tag
1482
+ if (opt && (value !== undefined || ctx.direction !== "backward")) {
1012
1483
  return opt._zod.run(payload, ctx);
1013
1484
  }
1014
- if (def.unionFallback) {
1485
+ // Fall back to union matching when the fast discriminator path fails:
1486
+ // - explicitly enabled via unionFallback, or
1487
+ // - during backward direction (encode), since codec-based discriminators have different values in forward vs backward directions
1488
+ if (def.unionFallback || ctx.direction === "backward") {
1015
1489
  return _super(payload, ctx);
1016
1490
  }
1017
1491
  // no matching discriminator
@@ -1019,6 +1493,8 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1019
1493
  code: "invalid_union",
1020
1494
  errors: [],
1021
1495
  note: "No matching discriminator",
1496
+ discriminator: def.discriminator,
1497
+ options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
1022
1498
  input,
1023
1499
  path: [def.discriminator],
1024
1500
  inst,
@@ -1054,7 +1530,11 @@ function mergeValues(a, b) {
1054
1530
  const bKeys = Object.keys(b);
1055
1531
  const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1056
1532
  const newObj = { ...a, ...b };
1533
+ if (Object.prototype.hasOwnProperty.call(newObj, "__proto__"))
1534
+ delete newObj.__proto__;
1057
1535
  for (const key of sharedKeys) {
1536
+ if (key === "__proto__")
1537
+ continue;
1058
1538
  const sharedValue = mergeValues(a[key], b[key]);
1059
1539
  if (!sharedValue.valid) {
1060
1540
  return {
@@ -1088,16 +1568,55 @@ function mergeValues(a, b) {
1088
1568
  return { valid: false, mergeErrorPath: [] };
1089
1569
  }
1090
1570
  function handleIntersectionResults(result, left, right) {
1091
- if (left.issues.length) {
1092
- result.issues.push(...left.issues);
1571
+ // 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.
1572
+ const unrecKeys = new Map();
1573
+ let unrecIssue;
1574
+ const keyIssues = new Map();
1575
+ const collect = (iss, side) => {
1576
+ let keys;
1577
+ if (iss.code === "unrecognized_keys" && !iss.path?.length) {
1578
+ unrecIssue ?? (unrecIssue = iss);
1579
+ keys = iss.keys;
1580
+ }
1581
+ else if (iss.code === "invalid_key" && iss.origin === "record" && iss.path?.length === 1) {
1582
+ const k = String(iss.path[0]);
1583
+ if (!keyIssues.has(k))
1584
+ keyIssues.set(k, iss);
1585
+ keys = [k];
1586
+ }
1587
+ else {
1588
+ return false;
1589
+ }
1590
+ for (const k of keys) {
1591
+ if (!unrecKeys.has(k))
1592
+ unrecKeys.set(k, {});
1593
+ unrecKeys.get(k)[side] = true;
1594
+ }
1595
+ return true;
1596
+ };
1597
+ for (const iss of left.issues) {
1598
+ if (!collect(iss, "l"))
1599
+ result.issues.push(iss);
1093
1600
  }
1094
- if (right.issues.length) {
1095
- result.issues.push(...right.issues);
1601
+ for (const iss of right.issues) {
1602
+ if (!collect(iss, "r"))
1603
+ result.issues.push(iss);
1604
+ }
1605
+ // Report only keys rejected by BOTH sides
1606
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
1607
+ if (bothKeys.length) {
1608
+ const aggregated = unrecIssue ? bothKeys.filter((k) => unrecIssue.keys.includes(k)) : [];
1609
+ if (aggregated.length)
1610
+ result.issues.push({ ...unrecIssue, keys: aggregated });
1611
+ for (const k of bothKeys) {
1612
+ if (!aggregated.includes(k) && keyIssues.has(k))
1613
+ result.issues.push(keyIssues.get(k));
1614
+ }
1096
1615
  }
1097
- if (util.aborted(result))
1098
- return result;
1099
1616
  const merged = mergeValues(left.value, right.value);
1100
1617
  if (!merged.valid) {
1618
+ if (util.aborted(result))
1619
+ return result;
1101
1620
  throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
1102
1621
  }
1103
1622
  result.value = merged.data;
@@ -1106,7 +1625,8 @@ function handleIntersectionResults(result, left, right) {
1106
1625
  exports.$ZodTuple = core.$constructor("$ZodTuple", (inst, def) => {
1107
1626
  exports.$ZodType.init(inst, def);
1108
1627
  const items = def.items;
1109
- const optStart = items.length - [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
1628
+ const memo = core.globalConfig.memoizer;
1629
+ memo?.attach(inst);
1110
1630
  inst._zod.parse = (payload, ctx) => {
1111
1631
  const input = payload.value;
1112
1632
  if (!Array.isArray(input)) {
@@ -1118,67 +1638,132 @@ exports.$ZodTuple = core.$constructor("$ZodTuple", (inst, def) => {
1118
1638
  });
1119
1639
  return payload;
1120
1640
  }
1121
- payload.value = [];
1641
+ payload.value = memo ? memo.alloc(inst, payload, [], ctx) : [];
1122
1642
  const proms = [];
1643
+ const optinStart = getTupleOptStart(items, "optin");
1644
+ const optoutStart = getTupleOptStart(items, "optout");
1123
1645
  if (!def.rest) {
1124
- const tooBig = input.length > items.length;
1125
- const tooSmall = input.length < optStart - 1;
1126
- if (tooBig || tooSmall) {
1646
+ if (input.length < optinStart) {
1127
1647
  payload.issues.push({
1648
+ code: "too_small",
1649
+ minimum: optinStart,
1650
+ inclusive: true,
1128
1651
  input,
1129
1652
  inst,
1130
1653
  origin: "array",
1131
- ...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
1132
1654
  });
1133
1655
  return payload;
1134
1656
  }
1657
+ if (input.length > items.length) {
1658
+ payload.issues.push({
1659
+ code: "too_big",
1660
+ maximum: items.length,
1661
+ inclusive: true,
1662
+ input,
1663
+ inst,
1664
+ origin: "array",
1665
+ });
1666
+ }
1135
1667
  }
1136
- let i = -1;
1137
- for (const item of items) {
1138
- i++;
1139
- if (i >= input.length)
1140
- if (i >= optStart)
1141
- continue;
1142
- const result = item._zod.run({
1143
- value: input[i],
1144
- issues: [],
1145
- }, ctx);
1146
- if (result instanceof Promise) {
1147
- proms.push(result.then((result) => handleTupleResult(result, payload, i)));
1668
+ // 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.
1669
+ const itemResults = new Array(items.length);
1670
+ // only tracked when there is a rest loop to skip
1671
+ const abortEarly = def.rest ? ctx?.abortEarly : undefined;
1672
+ let itemAborted = false;
1673
+ for (let i = 0; i < items.length; i++) {
1674
+ const r = items[i]._zod.run({ value: input[i], issues: [] }, ctx);
1675
+ if (r instanceof Promise) {
1676
+ proms.push(r.then((rr) => {
1677
+ itemResults[i] = rr;
1678
+ }));
1148
1679
  }
1149
1680
  else {
1150
- handleTupleResult(result, payload, i);
1681
+ itemResults[i] = r;
1682
+ if (abortEarly && !itemAborted && r.issues.length)
1683
+ itemAborted = util.aborted(r);
1151
1684
  }
1152
1685
  }
1153
- if (def.rest) {
1686
+ // sound because rest is non-empty exactly when every fixed index is present, the one case handleTupleResults cannot discard an item's issues
1687
+ if (def.rest && !itemAborted) {
1688
+ let i = items.length - 1;
1154
1689
  const rest = input.slice(items.length);
1690
+ let seen = payload.issues.length;
1155
1691
  for (const el of rest) {
1692
+ if (abortEarly && payload.issues.length !== seen) {
1693
+ if (util.aborted(payload, seen))
1694
+ break;
1695
+ seen = payload.issues.length;
1696
+ }
1156
1697
  i++;
1157
- const result = def.rest._zod.run({
1158
- value: el,
1159
- issues: [],
1160
- }, ctx);
1698
+ const result = def.rest._zod.run({ value: el, issues: [] }, ctx);
1161
1699
  if (result instanceof Promise) {
1162
- proms.push(result.then((result) => handleTupleResult(result, payload, i)));
1700
+ proms.push(result.then((r) => handleTupleResult(r, payload, i)));
1163
1701
  }
1164
1702
  else {
1165
1703
  handleTupleResult(result, payload, i);
1166
1704
  }
1167
1705
  }
1168
1706
  }
1169
- if (proms.length)
1170
- return Promise.all(proms).then(() => payload);
1171
- return payload;
1707
+ if (proms.length) {
1708
+ return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items, input, optoutStart));
1709
+ }
1710
+ return handleTupleResults(itemResults, payload, items, input, optoutStart);
1172
1711
  };
1173
1712
  });
1713
+ function getTupleOptStart(items, key) {
1714
+ for (let i = items.length - 1; i >= 0; i--) {
1715
+ // optin is a three-rung ladder so any rung above `undefined` permits an absent slot; optout stays two-valued.
1716
+ const omittable = key === "optin" ? items[i]._zod.optin !== undefined : items[i]._zod.optout === "optional";
1717
+ if (!omittable)
1718
+ return i + 1;
1719
+ }
1720
+ return 0;
1721
+ }
1174
1722
  function handleTupleResult(result, final, index) {
1175
1723
  if (result.issues.length) {
1176
1724
  final.issues.push(...util.prefixIssues(index, result.issues));
1177
1725
  }
1178
1726
  final.value[index] = result.value;
1179
1727
  }
1728
+ function handleTupleResults(itemResults, final, items, input, optoutStart) {
1729
+ // 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.
1730
+ for (let i = 0; i < items.length; i++) {
1731
+ const r = itemResults[i];
1732
+ const isPresent = i < input.length;
1733
+ // 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`.
1734
+ if (!isPresent && i >= optoutStart && items[i]._zod.optin === "optional") {
1735
+ final.value.length = i;
1736
+ break;
1737
+ }
1738
+ if (r.issues.length) {
1739
+ if (!isPresent && i >= optoutStart) {
1740
+ final.value.length = i;
1741
+ break;
1742
+ }
1743
+ final.issues.push(...util.prefixIssues(i, r.issues));
1744
+ }
1745
+ final.value[i] = r.value;
1746
+ }
1747
+ // Drop trailing slots that produced `undefined` for absent input
1748
+ // (the array analog of an absent optional key on an object). The
1749
+ // `i >= input.length` floor is critical: an explicit `undefined`
1750
+ // *inside* the input must be preserved even when the schema is
1751
+ // optional-out (e.g. `z.string().or(z.undefined())` accepting an
1752
+ // explicit undefined value).
1753
+ for (let i = final.value.length - 1; i >= input.length; i--) {
1754
+ if (items[i]._zod.optout === "optional" && final.value[i] === undefined) {
1755
+ final.value.length = i;
1756
+ }
1757
+ else {
1758
+ break;
1759
+ }
1760
+ }
1761
+ return final;
1762
+ }
1180
1763
  exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
1181
1764
  exports.$ZodType.init(inst, def);
1765
+ const memo = core.globalConfig.memoizer;
1766
+ memo?.attach(inst);
1182
1767
  inst._zod.parse = (payload, ctx) => {
1183
1768
  const input = payload.value;
1184
1769
  if (!util.isPlainObject(input)) {
@@ -1190,34 +1775,66 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
1190
1775
  });
1191
1776
  return payload;
1192
1777
  }
1778
+ // 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
1193
1779
  const proms = [];
1194
- if (def.keyType._zod.values) {
1195
- const values = def.keyType._zod.values;
1196
- payload.value = {};
1780
+ const values = def.keyType._zod.values;
1781
+ if (values && !def.partial) {
1782
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
1783
+ const recordKeys = new Set();
1197
1784
  for (const key of values) {
1198
1785
  if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1786
+ recordKeys.add(typeof key === "number" ? key.toString() : key);
1787
+ // A declared __proto__ is stripped but is not an unrecognized key.
1788
+ if (key === "__proto__")
1789
+ continue;
1790
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1791
+ if (keyResult instanceof Promise) {
1792
+ throw new Error("Async schemas not supported in object keys currently");
1793
+ }
1794
+ if (keyResult.issues.length) {
1795
+ payload.issues.push({
1796
+ code: "invalid_key",
1797
+ origin: "record",
1798
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1799
+ input: key,
1800
+ path: [key],
1801
+ inst,
1802
+ });
1803
+ continue;
1804
+ }
1805
+ const outKey = keyResult.value;
1806
+ if (outKey === "__proto__")
1807
+ continue;
1199
1808
  const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1200
1809
  if (result instanceof Promise) {
1201
1810
  proms.push(result.then((result) => {
1202
1811
  if (result.issues.length) {
1203
1812
  payload.issues.push(...util.prefixIssues(key, result.issues));
1204
1813
  }
1205
- payload.value[key] = result.value;
1814
+ payload.value[outKey] = result.value;
1206
1815
  }));
1207
1816
  }
1208
1817
  else {
1209
1818
  if (result.issues.length) {
1210
1819
  payload.issues.push(...util.prefixIssues(key, result.issues));
1211
1820
  }
1212
- payload.value[key] = result.value;
1821
+ payload.value[outKey] = result.value;
1213
1822
  }
1214
1823
  }
1215
1824
  }
1216
1825
  let unrecognized;
1217
1826
  for (const key in input) {
1218
- if (!values.has(key)) {
1219
- unrecognized = unrecognized ?? [];
1220
- unrecognized.push(key);
1827
+ if (!recordKeys.has(key)) {
1828
+ if (def.mode === "loose") {
1829
+ // skip __proto__ so it can't replace the result prototype via the assignment setter on the plain {} we build into
1830
+ if (key === "__proto__")
1831
+ continue;
1832
+ payload.value[key] = input[key];
1833
+ }
1834
+ else {
1835
+ unrecognized = unrecognized ?? [];
1836
+ unrecognized.push(key);
1837
+ }
1221
1838
  }
1222
1839
  }
1223
1840
  if (unrecognized && unrecognized.length > 0) {
@@ -1226,46 +1843,86 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
1226
1843
  input,
1227
1844
  inst,
1228
1845
  keys: unrecognized,
1846
+ continue: true,
1229
1847
  });
1230
1848
  }
1231
1849
  }
1232
1850
  else {
1233
- payload.value = {};
1851
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
1852
+ // 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.
1853
+ let unrecognized;
1854
+ // Reflect.ownKeys for Symbol-key support; filter non-enumerable to match z.object()
1234
1855
  for (const key of Reflect.ownKeys(input)) {
1235
1856
  if (key === "__proto__")
1236
1857
  continue;
1237
- const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1858
+ if (!Object.prototype.propertyIsEnumerable.call(input, key))
1859
+ continue;
1860
+ let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1238
1861
  if (keyResult instanceof Promise) {
1239
1862
  throw new Error("Async schemas not supported in object keys currently");
1240
1863
  }
1864
+ // 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
1865
+ const checkNumericKey = typeof key === "string" && regexes.number.test(key) && keyResult.issues.length;
1866
+ if (checkNumericKey) {
1867
+ const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
1868
+ if (retryResult instanceof Promise) {
1869
+ throw new Error("Async schemas not supported in object keys currently");
1870
+ }
1871
+ if (retryResult.issues.length === 0) {
1872
+ keyResult = retryResult;
1873
+ }
1874
+ }
1241
1875
  if (keyResult.issues.length) {
1242
- payload.issues.push({
1243
- origin: "record",
1244
- code: "invalid_key",
1245
- issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1246
- input: key,
1247
- path: [key],
1248
- inst,
1249
- });
1250
- payload.value[keyResult.value] = keyResult.value;
1876
+ if (def.mode === "loose") {
1877
+ // Pass through unchanged
1878
+ payload.value[key] = input[key];
1879
+ }
1880
+ else if (values) {
1881
+ unrecognized = unrecognized ?? [];
1882
+ unrecognized.push(key);
1883
+ }
1884
+ else {
1885
+ // Default "strict" behavior: error on invalid key
1886
+ payload.issues.push({
1887
+ code: "invalid_key",
1888
+ origin: "record",
1889
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1890
+ input: key,
1891
+ path: [key],
1892
+ inst,
1893
+ });
1894
+ }
1251
1895
  continue;
1252
1896
  }
1897
+ // 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
1898
+ const outKey = keyResult.value;
1899
+ if (outKey === "__proto__")
1900
+ continue;
1253
1901
  const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1254
1902
  if (result instanceof Promise) {
1255
1903
  proms.push(result.then((result) => {
1256
1904
  if (result.issues.length) {
1257
1905
  payload.issues.push(...util.prefixIssues(key, result.issues));
1258
1906
  }
1259
- payload.value[keyResult.value] = result.value;
1907
+ payload.value[outKey] = result.value;
1260
1908
  }));
1261
1909
  }
1262
1910
  else {
1263
1911
  if (result.issues.length) {
1264
1912
  payload.issues.push(...util.prefixIssues(key, result.issues));
1265
1913
  }
1266
- payload.value[keyResult.value] = result.value;
1914
+ payload.value[outKey] = result.value;
1267
1915
  }
1268
1916
  }
1917
+ if (unrecognized && unrecognized.length > 0) {
1918
+ payload.issues.push({
1919
+ code: "unrecognized_keys",
1920
+ input,
1921
+ inst,
1922
+ keys: unrecognized,
1923
+ continue: true,
1924
+ });
1925
+ }
1269
1926
  }
1270
1927
  if (proms.length) {
1271
1928
  return Promise.all(proms).then(() => payload);
@@ -1275,6 +1932,8 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
1275
1932
  });
1276
1933
  exports.$ZodMap = core.$constructor("$ZodMap", (inst, def) => {
1277
1934
  exports.$ZodType.init(inst, def);
1935
+ const memo = core.globalConfig.memoizer;
1936
+ memo?.attach(inst);
1278
1937
  inst._zod.parse = (payload, ctx) => {
1279
1938
  const input = payload.value;
1280
1939
  if (!(input instanceof Map)) {
@@ -1287,8 +1946,15 @@ exports.$ZodMap = core.$constructor("$ZodMap", (inst, def) => {
1287
1946
  return payload;
1288
1947
  }
1289
1948
  const proms = [];
1290
- payload.value = new Map();
1949
+ payload.value = memo ? memo.alloc(inst, payload, new Map(), ctx) : new Map();
1950
+ const abortEarly = ctx?.abortEarly;
1951
+ let seen = payload.issues.length;
1291
1952
  for (const [key, value] of input) {
1953
+ if (abortEarly && payload.issues.length !== seen) {
1954
+ if (util.aborted(payload, seen))
1955
+ break;
1956
+ seen = payload.issues.length;
1957
+ }
1292
1958
  const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1293
1959
  const valueResult = def.valueType._zod.run({ value: value, issues: [] }, ctx);
1294
1960
  if (keyResult instanceof Promise || valueResult instanceof Promise) {
@@ -1304,6 +1970,7 @@ exports.$ZodMap = core.$constructor("$ZodMap", (inst, def) => {
1304
1970
  return Promise.all(proms).then(() => payload);
1305
1971
  return payload;
1306
1972
  };
1973
+ capSize(inst, mapSize);
1307
1974
  });
1308
1975
  function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1309
1976
  if (keyResult.issues.length) {
@@ -1312,8 +1979,8 @@ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1312
1979
  }
1313
1980
  else {
1314
1981
  final.issues.push({
1315
- origin: "map",
1316
1982
  code: "invalid_key",
1983
+ origin: "map",
1317
1984
  input,
1318
1985
  inst,
1319
1986
  issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
@@ -1339,6 +2006,8 @@ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1339
2006
  }
1340
2007
  exports.$ZodSet = core.$constructor("$ZodSet", (inst, def) => {
1341
2008
  exports.$ZodType.init(inst, def);
2009
+ const memo = core.globalConfig.memoizer;
2010
+ memo?.attach(inst);
1342
2011
  inst._zod.parse = (payload, ctx) => {
1343
2012
  const input = payload.value;
1344
2013
  if (!(input instanceof Set)) {
@@ -1351,8 +2020,15 @@ exports.$ZodSet = core.$constructor("$ZodSet", (inst, def) => {
1351
2020
  return payload;
1352
2021
  }
1353
2022
  const proms = [];
1354
- payload.value = new Set();
2023
+ payload.value = memo ? memo.alloc(inst, payload, new Set(), ctx) : new Set();
2024
+ const abortEarly = ctx?.abortEarly;
2025
+ let seen = payload.issues.length;
1355
2026
  for (const item of input) {
2027
+ if (abortEarly && payload.issues.length !== seen) {
2028
+ if (util.aborted(payload, seen))
2029
+ break;
2030
+ seen = payload.issues.length;
2031
+ }
1356
2032
  const result = def.valueType._zod.run({ value: item, issues: [] }, ctx);
1357
2033
  if (result instanceof Promise) {
1358
2034
  proms.push(result.then((result) => handleSetResult(result, payload)));
@@ -1364,6 +2040,7 @@ exports.$ZodSet = core.$constructor("$ZodSet", (inst, def) => {
1364
2040
  return Promise.all(proms).then(() => payload);
1365
2041
  return payload;
1366
2042
  };
2043
+ capSize(inst, setSize);
1367
2044
  });
1368
2045
  function handleSetResult(result, final) {
1369
2046
  if (result.issues.length) {
@@ -1374,14 +2051,16 @@ function handleSetResult(result, final) {
1374
2051
  exports.$ZodEnum = core.$constructor("$ZodEnum", (inst, def) => {
1375
2052
  exports.$ZodType.init(inst, def);
1376
2053
  const values = util.getEnumValues(def.entries);
1377
- inst._zod.values = new Set(values);
1378
- inst._zod.pattern = new RegExp(`^(${values
1379
- .filter((k) => util.propertyKeyTypes.has(typeof k))
1380
- .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o.toString()))
1381
- .join("|")})$`);
2054
+ const valuesSet = new Set(values);
2055
+ inst._zod.values = valuesSet;
2056
+ util.defineLazyInternal(inst, "pattern", (zod) => {
2057
+ const patternValues = util.getEnumValues(zod.def.entries).filter((k) => util.propertyKeyTypes.has(typeof k));
2058
+ // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
2059
+ return new RegExp(patternValues.length ? `^(${patternValues.map((o) => util.escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$");
2060
+ });
1382
2061
  inst._zod.parse = (payload, _ctx) => {
1383
2062
  const input = payload.value;
1384
- if (inst._zod.values.has(input)) {
2063
+ if (valuesSet.has(input)) {
1385
2064
  return payload;
1386
2065
  }
1387
2066
  payload.issues.push({
@@ -1395,13 +2074,20 @@ exports.$ZodEnum = core.$constructor("$ZodEnum", (inst, def) => {
1395
2074
  });
1396
2075
  exports.$ZodLiteral = core.$constructor("$ZodLiteral", (inst, def) => {
1397
2076
  exports.$ZodType.init(inst, def);
1398
- inst._zod.values = new Set(def.values);
1399
- inst._zod.pattern = new RegExp(`^(${def.values
1400
- .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? o.toString() : String(o)))
1401
- .join("|")})$`);
2077
+ const values = new Set(def.values);
2078
+ inst._zod.values = values;
2079
+ util.defineLazyInternal(inst, "pattern", (zod) => {
2080
+ const vals = zod.def.values;
2081
+ // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
2082
+ return new RegExp(vals.length
2083
+ ? `^(${vals
2084
+ .map((o) => typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o))
2085
+ .join("|")})$`
2086
+ : "^[^\\s\\S]$");
2087
+ });
1402
2088
  inst._zod.parse = (payload, _ctx) => {
1403
2089
  const input = payload.value;
1404
- if (inst._zod.values.has(input)) {
2090
+ if (values.has(input)) {
1405
2091
  return payload;
1406
2092
  }
1407
2093
  payload.issues.push({
@@ -1417,6 +2103,7 @@ exports.$ZodFile = core.$constructor("$ZodFile", (inst, def) => {
1417
2103
  exports.$ZodType.init(inst, def);
1418
2104
  inst._zod.parse = (payload, _ctx) => {
1419
2105
  const input = payload.value;
2106
+ // @ts-ignore
1420
2107
  if (input instanceof File)
1421
2108
  return payload;
1422
2109
  payload.issues.push({
@@ -1430,9 +2117,14 @@ exports.$ZodFile = core.$constructor("$ZodFile", (inst, def) => {
1430
2117
  });
1431
2118
  exports.$ZodTransform = core.$constructor("$ZodTransform", (inst, def) => {
1432
2119
  exports.$ZodType.init(inst, def);
1433
- inst._zod.parse = (payload, _ctx) => {
2120
+ inst._zod.optin = "optional";
2121
+ core.globalConfig.memoizer?.guard(inst);
2122
+ inst._zod.parse = (payload, ctx) => {
2123
+ if (ctx.direction === "backward") {
2124
+ throw new core.$ZodEncodeError(inst.constructor.name);
2125
+ }
1434
2126
  const _out = def.transform(payload.value, payload);
1435
- if (_ctx.async) {
2127
+ if (ctx.async) {
1436
2128
  const output = _out instanceof Promise ? _out : Promise.resolve(_out);
1437
2129
  return output.then((output) => {
1438
2130
  payload.value = output;
@@ -1446,39 +2138,62 @@ exports.$ZodTransform = core.$constructor("$ZodTransform", (inst, def) => {
1446
2138
  return payload;
1447
2139
  };
1448
2140
  });
2141
+ function handleOptionalResult(payload, result) {
2142
+ // 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.
2143
+ payload.value = result.issues.length ? undefined : result.value;
2144
+ return payload;
2145
+ }
1449
2146
  exports.$ZodOptional = core.$constructor("$ZodOptional", (inst, def) => {
1450
2147
  exports.$ZodType.init(inst, def);
1451
- inst._zod.optin = "optional";
2148
+ // .optional() propagates absence rather than substituting for it, so a defaulted inner keeps its rung.
2149
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional");
1452
2150
  inst._zod.optout = "optional";
1453
- util.defineLazy(inst._zod, "values", () => {
1454
- return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
2151
+ util.defineLazyInternal(inst, "values", (zod) => {
2152
+ const values = zod.def.innerType._zod.values;
2153
+ return values ? new Set([...values, undefined]) : undefined;
1455
2154
  });
1456
- util.defineLazy(inst._zod, "pattern", () => {
1457
- const pattern = def.innerType._zod.pattern;
2155
+ util.defineLazyInternal(inst, "pattern", (zod) => {
2156
+ const pattern = zod.def.innerType._zod.pattern;
1458
2157
  return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)})?$`) : undefined;
1459
2158
  });
1460
2159
  inst._zod.parse = (payload, ctx) => {
1461
- if (def.innerType._zod.optin === "optional") {
1462
- return def.innerType._zod.run(payload, ctx);
1463
- }
1464
2160
  if (payload.value === undefined) {
1465
- return payload;
2161
+ // Only the top rung substitutes a value for absence; everything else leaves it intact, which is what .optional() means.
2162
+ if (def.innerType._zod.optin !== "defaulted")
2163
+ return payload;
2164
+ // 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.
2165
+ const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
2166
+ if (result instanceof Promise)
2167
+ return result.then((result) => handleOptionalResult(payload, result));
2168
+ return handleOptionalResult(payload, result);
1466
2169
  }
1467
2170
  return def.innerType._zod.run(payload, ctx);
1468
2171
  };
1469
2172
  });
2173
+ exports.$ZodExactOptional = core.$constructor("$ZodExactOptional", (inst, def) => {
2174
+ // Call parent init - inherits optin/optout = "optional"
2175
+ exports.$ZodOptional.init(inst, def);
2176
+ // Override values/pattern to NOT add undefined
2177
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
2178
+ util.defineLazyInternal(inst, "pattern", (zod) => zod.def.innerType._zod.pattern);
2179
+ // Override parse to just delegate (no undefined handling)
2180
+ inst._zod.parse = (payload, ctx) => {
2181
+ return def.innerType._zod.run(payload, ctx);
2182
+ };
2183
+ });
1470
2184
  exports.$ZodNullable = core.$constructor("$ZodNullable", (inst, def) => {
1471
2185
  exports.$ZodType.init(inst, def);
1472
- util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1473
- util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1474
- util.defineLazy(inst._zod, "pattern", () => {
1475
- const pattern = def.innerType._zod.pattern;
2186
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin);
2187
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
2188
+ util.defineLazyInternal(inst, "pattern", (zod) => {
2189
+ const pattern = zod.def.innerType._zod.pattern;
1476
2190
  return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)}|null)$`) : undefined;
1477
2191
  });
1478
- util.defineLazy(inst._zod, "values", () => {
1479
- return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
2192
+ util.defineLazyInternal(inst, "values", (zod) => {
2193
+ return zod.def.innerType._zod.values ? new Set([...zod.def.innerType._zod.values, null]) : undefined;
1480
2194
  });
1481
2195
  inst._zod.parse = (payload, ctx) => {
2196
+ // Forward direction (decode): allow null to pass through
1482
2197
  if (payload.value === null)
1483
2198
  return payload;
1484
2199
  return def.innerType._zod.run(payload, ctx);
@@ -1487,16 +2202,21 @@ exports.$ZodNullable = core.$constructor("$ZodNullable", (inst, def) => {
1487
2202
  exports.$ZodDefault = core.$constructor("$ZodDefault", (inst, def) => {
1488
2203
  exports.$ZodType.init(inst, def);
1489
2204
  // inst._zod.qin = "true";
1490
- inst._zod.optin = "optional";
1491
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2205
+ inst._zod.optin = "defaulted";
2206
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1492
2207
  inst._zod.parse = (payload, ctx) => {
2208
+ if (ctx.direction === "backward") {
2209
+ return def.innerType._zod.run(payload, ctx);
2210
+ }
2211
+ // Forward direction (decode): apply defaults for undefined input
1493
2212
  if (payload.value === undefined) {
1494
2213
  payload.value = def.defaultValue;
1495
2214
  /**
1496
- * $ZodDefault always returns the default value immediately.
2215
+ * $ZodDefault returns the default value immediately in forward direction.
1497
2216
  * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
1498
2217
  return payload;
1499
2218
  }
2219
+ // Forward direction: continue with default handling
1500
2220
  const result = def.innerType._zod.run(payload, ctx);
1501
2221
  if (result instanceof Promise) {
1502
2222
  return result.then((result) => handleDefaultResult(result, def));
@@ -1512,9 +2232,13 @@ function handleDefaultResult(payload, def) {
1512
2232
  }
1513
2233
  exports.$ZodPrefault = core.$constructor("$ZodPrefault", (inst, def) => {
1514
2234
  exports.$ZodType.init(inst, def);
1515
- inst._zod.optin = "optional";
1516
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2235
+ inst._zod.optin = "defaulted";
2236
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1517
2237
  inst._zod.parse = (payload, ctx) => {
2238
+ if (ctx.direction === "backward") {
2239
+ return def.innerType._zod.run(payload, ctx);
2240
+ }
2241
+ // Forward direction (decode): apply prefault for undefined input
1518
2242
  if (payload.value === undefined) {
1519
2243
  payload.value = def.defaultValue;
1520
2244
  }
@@ -1523,8 +2247,8 @@ exports.$ZodPrefault = core.$constructor("$ZodPrefault", (inst, def) => {
1523
2247
  });
1524
2248
  exports.$ZodNonOptional = core.$constructor("$ZodNonOptional", (inst, def) => {
1525
2249
  exports.$ZodType.init(inst, def);
1526
- util.defineLazy(inst._zod, "values", () => {
1527
- const v = def.innerType._zod.values;
2250
+ util.defineLazyInternal(inst, "values", (zod) => {
2251
+ const v = zod.def.innerType._zod.values;
1528
2252
  return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
1529
2253
  });
1530
2254
  inst._zod.parse = (payload, ctx) => {
@@ -1549,6 +2273,9 @@ function handleNonOptionalResult(payload, inst) {
1549
2273
  exports.$ZodSuccess = core.$constructor("$ZodSuccess", (inst, def) => {
1550
2274
  exports.$ZodType.init(inst, def);
1551
2275
  inst._zod.parse = (payload, ctx) => {
2276
+ if (ctx.direction === "backward") {
2277
+ throw new core.$ZodEncodeError("ZodSuccess");
2278
+ }
1552
2279
  const result = def.innerType._zod.run(payload, ctx);
1553
2280
  if (result instanceof Promise) {
1554
2281
  return result.then((result) => {
@@ -1560,41 +2287,40 @@ exports.$ZodSuccess = core.$constructor("$ZodSuccess", (inst, def) => {
1560
2287
  return payload;
1561
2288
  };
1562
2289
  });
2290
+ function handleCatchResult(payload, result, def, ctx) {
2291
+ if (!result.issues.length) {
2292
+ payload.value = result.value;
2293
+ // 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.
2294
+ if (result.memo)
2295
+ payload.memo = true;
2296
+ return payload;
2297
+ }
2298
+ // 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.
2299
+ payload.value = def.catchValue({
2300
+ ...result,
2301
+ value: payload.value,
2302
+ error: {
2303
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
2304
+ },
2305
+ input: payload.value,
2306
+ });
2307
+ return payload;
2308
+ }
1563
2309
  exports.$ZodCatch = core.$constructor("$ZodCatch", (inst, def) => {
1564
2310
  exports.$ZodType.init(inst, def);
1565
- inst._zod.optin = "optional";
1566
- util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1567
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2311
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional");
2312
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
2313
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1568
2314
  inst._zod.parse = (payload, ctx) => {
1569
- const result = def.innerType._zod.run(payload, ctx);
1570
- if (result instanceof Promise) {
1571
- return result.then((result) => {
1572
- payload.value = result.value;
1573
- if (result.issues.length) {
1574
- payload.value = def.catchValue({
1575
- ...payload,
1576
- error: {
1577
- issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1578
- },
1579
- input: payload.value,
1580
- });
1581
- payload.issues = [];
1582
- }
1583
- return payload;
1584
- });
2315
+ if (ctx.direction === "backward") {
2316
+ return def.innerType._zod.run(payload, ctx);
1585
2317
  }
1586
- payload.value = result.value;
1587
- if (result.issues.length) {
1588
- payload.value = def.catchValue({
1589
- ...payload,
1590
- error: {
1591
- issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1592
- },
1593
- input: payload.value,
1594
- });
1595
- payload.issues = [];
2318
+ // Forward direction (decode): apply catch logic
2319
+ const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
2320
+ if (result instanceof Promise) {
2321
+ return result.then((result) => handleCatchResult(payload, result, def, ctx));
1596
2322
  }
1597
- return payload;
2323
+ return handleCatchResult(payload, result, def, ctx);
1598
2324
  };
1599
2325
  });
1600
2326
  exports.$ZodNaN = core.$constructor("$ZodNaN", (inst, def) => {
@@ -1614,30 +2340,101 @@ exports.$ZodNaN = core.$constructor("$ZodNaN", (inst, def) => {
1614
2340
  });
1615
2341
  exports.$ZodPipe = core.$constructor("$ZodPipe", (inst, def) => {
1616
2342
  exports.$ZodType.init(inst, def);
1617
- util.defineLazy(inst._zod, "values", () => def.in._zod.values);
1618
- util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1619
- util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
2343
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
2344
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
2345
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
2346
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
1620
2347
  inst._zod.parse = (payload, ctx) => {
2348
+ if (ctx.direction === "backward") {
2349
+ const right = def.out._zod.run(payload, ctx);
2350
+ if (right instanceof Promise) {
2351
+ return right.then((right) => handlePipeResult(right, def.in, ctx));
2352
+ }
2353
+ return handlePipeResult(right, def.in, ctx);
2354
+ }
1621
2355
  const left = def.in._zod.run(payload, ctx);
1622
2356
  if (left instanceof Promise) {
1623
- return left.then((left) => handlePipeResult(left, def, ctx));
2357
+ return left.then((left) => handlePipeResult(left, def.out, ctx));
1624
2358
  }
1625
- return handlePipeResult(left, def, ctx);
2359
+ return handlePipeResult(left, def.out, ctx);
1626
2360
  };
1627
2361
  });
1628
- function handlePipeResult(left, def, ctx) {
1629
- if (util.aborted(left)) {
2362
+ function handlePipeResult(left, next, ctx) {
2363
+ // 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.
2364
+ if (left.issues.some((iss) => iss.code !== "unrecognized_keys")) {
2365
+ // prevent further checks
2366
+ left.aborted = true;
1630
2367
  return left;
1631
2368
  }
1632
- return def.out._zod.run({ value: left.value, issues: left.issues }, ctx);
2369
+ return next._zod.run({ value: left.value, issues: left.issues }, ctx);
1633
2370
  }
2371
+ exports.$ZodCodec = core.$constructor("$ZodCodec", (inst, def) => {
2372
+ exports.$ZodType.init(inst, def);
2373
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
2374
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
2375
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
2376
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
2377
+ inst._zod.parse = (payload, ctx) => {
2378
+ const direction = ctx.direction || "forward";
2379
+ if (direction === "forward") {
2380
+ const left = def.in._zod.run(payload, ctx);
2381
+ if (left instanceof Promise) {
2382
+ return left.then((left) => handleCodecAResult(left, def, ctx));
2383
+ }
2384
+ return handleCodecAResult(left, def, ctx);
2385
+ }
2386
+ else {
2387
+ const right = def.out._zod.run(payload, ctx);
2388
+ if (right instanceof Promise) {
2389
+ return right.then((right) => handleCodecAResult(right, def, ctx));
2390
+ }
2391
+ return handleCodecAResult(right, def, ctx);
2392
+ }
2393
+ };
2394
+ });
2395
+ function handleCodecAResult(result, def, ctx) {
2396
+ if (result.issues.length) {
2397
+ // prevent further checks
2398
+ result.aborted = true;
2399
+ return result;
2400
+ }
2401
+ const direction = ctx.direction || "forward";
2402
+ if (direction === "forward") {
2403
+ const transformed = def.transform(result.value, result);
2404
+ if (transformed instanceof Promise) {
2405
+ return transformed.then((value) => handleCodecTxResult(result, value, def.out, ctx));
2406
+ }
2407
+ return handleCodecTxResult(result, transformed, def.out, ctx);
2408
+ }
2409
+ else {
2410
+ const transformed = def.reverseTransform(result.value, result);
2411
+ if (transformed instanceof Promise) {
2412
+ return transformed.then((value) => handleCodecTxResult(result, value, def.in, ctx));
2413
+ }
2414
+ return handleCodecTxResult(result, transformed, def.in, ctx);
2415
+ }
2416
+ }
2417
+ function handleCodecTxResult(left, value, nextSchema, ctx) {
2418
+ // Check if transform added any issues
2419
+ if (left.issues.length) {
2420
+ left.aborted = true;
2421
+ return left;
2422
+ }
2423
+ return nextSchema._zod.run({ value, issues: left.issues }, ctx);
2424
+ }
2425
+ exports.$ZodPreprocess = core.$constructor("$ZodPreprocess", (inst, def) => {
2426
+ exports.$ZodPipe.init(inst, def);
2427
+ });
1634
2428
  exports.$ZodReadonly = core.$constructor("$ZodReadonly", (inst, def) => {
1635
2429
  exports.$ZodType.init(inst, def);
1636
- util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1637
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1638
- util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1639
- util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2430
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.innerType._zod.propValues);
2431
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
2432
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType?._zod?.optin);
2433
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType?._zod?.optout);
1640
2434
  inst._zod.parse = (payload, ctx) => {
2435
+ if (ctx.direction === "backward") {
2436
+ return def.innerType._zod.run(payload, ctx);
2437
+ }
1641
2438
  const result = def.innerType._zod.run(payload, ctx);
1642
2439
  if (result instanceof Promise) {
1643
2440
  return result.then(handleReadonlyResult);
@@ -1646,24 +2443,72 @@ exports.$ZodReadonly = core.$constructor("$ZodReadonly", (inst, def) => {
1646
2443
  };
1647
2444
  });
1648
2445
  function handleReadonlyResult(payload) {
1649
- payload.value = Object.freeze(payload.value);
2446
+ // 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.
2447
+ if (!payload.memo)
2448
+ payload.value = Object.freeze(payload.value);
1650
2449
  return payload;
1651
2450
  }
2451
+ // 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
2452
+ function leafPattern(schema) {
2453
+ const def = schema._zod.def;
2454
+ let pattern = def.pattern;
2455
+ let isInt = !!def.format?.includes("int");
2456
+ let minimum;
2457
+ let maximum;
2458
+ for (const ch of def.checks ?? []) {
2459
+ const d = ch._zod.def;
2460
+ if (d.pattern)
2461
+ pattern = d.pattern;
2462
+ isInt || (isInt = !!d.format?.includes("int"));
2463
+ const lo = d.minimum ?? d.length;
2464
+ const hi = d.maximum ?? d.length;
2465
+ if (lo !== undefined && (minimum === undefined || lo > minimum))
2466
+ minimum = lo;
2467
+ if (hi !== undefined && (maximum === undefined || hi < maximum))
2468
+ maximum = hi;
2469
+ }
2470
+ if (pattern)
2471
+ return pattern.source;
2472
+ // an empty range matches nothing at runtime, and `{8,5}` is not a legal quantifier
2473
+ if (minimum !== undefined && maximum !== undefined && minimum > maximum)
2474
+ return "(?!)";
2475
+ if (minimum !== undefined || maximum !== undefined)
2476
+ return regexes.string({ minimum, maximum }).source;
2477
+ const own = schema._zod.pattern;
2478
+ return (isInt && own === regexes.number ? regexes.integer : own)?.source;
2479
+ }
2480
+ // 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
2481
+ function partPattern(schema) {
2482
+ const def = schema._zod.def;
2483
+ const own = schema._zod.pattern?.source;
2484
+ // lazy resolves its inner on the internals, not the def
2485
+ const inner = def.innerType ?? schema._zod.innerType;
2486
+ if (inner) {
2487
+ const before = inner._zod.pattern?.source;
2488
+ const after = partPattern(inner);
2489
+ if (own && before && after && after !== before) {
2490
+ return own.replace(util.cleanRegex(before), () => util.cleanRegex(after));
2491
+ }
2492
+ return own;
2493
+ }
2494
+ if (def.options) {
2495
+ const sources = def.options.map(partPattern);
2496
+ if (sources.every(Boolean))
2497
+ return `^(${sources.map((s) => util.cleanRegex(s)).join("|")})$`;
2498
+ }
2499
+ return leafPattern(schema);
2500
+ }
1652
2501
  exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, def) => {
1653
2502
  exports.$ZodType.init(inst, def);
1654
2503
  const regexParts = [];
1655
2504
  for (const part of def.parts) {
1656
- if (part instanceof exports.$ZodType) {
1657
- if (!part._zod.pattern) {
1658
- // if (!source)
2505
+ if (typeof part === "object" && part !== null) {
2506
+ // is Zod schema
2507
+ const source = partPattern(part);
2508
+ if (!source) {
1659
2509
  throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
1660
2510
  }
1661
- const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;
1662
- if (!source)
1663
- throw new Error(`Invalid template literal part: ${part._zod.traits}`);
1664
- const start = source.startsWith("^") ? 1 : 0;
1665
- const end = source.endsWith("$") ? source.length - 1 : source.length;
1666
- regexParts.push(source.slice(start, end));
2511
+ regexParts.push(util.cleanRegex(source));
1667
2512
  }
1668
2513
  else if (part === null || util.primitiveTypes.has(typeof part)) {
1669
2514
  regexParts.push(util.escapeRegex(`${part}`));
@@ -1678,7 +2523,7 @@ exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, de
1678
2523
  payload.issues.push({
1679
2524
  input: payload.value,
1680
2525
  inst,
1681
- expected: "template_literal",
2526
+ expected: "string",
1682
2527
  code: "invalid_type",
1683
2528
  });
1684
2529
  return payload;
@@ -1689,7 +2534,7 @@ exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, de
1689
2534
  input: payload.value,
1690
2535
  inst,
1691
2536
  code: "invalid_format",
1692
- format: "template_literal",
2537
+ format: def.format ?? "template_literal",
1693
2538
  pattern: inst._zod.pattern.source,
1694
2539
  });
1695
2540
  return payload;
@@ -1697,6 +2542,87 @@ exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, de
1697
2542
  return payload;
1698
2543
  };
1699
2544
  });
2545
+ exports.$ZodFunction = core.$constructor("$ZodFunction", (inst, def) => {
2546
+ exports.$ZodType.init(inst, def);
2547
+ // Defined, not assigned: the classic prototype exposes `_def` as a getter with no setter.
2548
+ Object.defineProperty(inst, "_def", { value: def });
2549
+ inst._zod.def = def;
2550
+ inst.implement = (func) => {
2551
+ if (typeof func !== "function") {
2552
+ throw new Error("implement() must be called with a function");
2553
+ }
2554
+ // Defined inline so the closure stays anonymous: binding it to a `const` first names it, which costs 256 bytes per implemented function.
2555
+ return Object.defineProperty(function (...args) {
2556
+ const parsedArgs = inst._def.input ? (0, parse_js_1.parse)(inst._def.input, args) : args;
2557
+ const result = Reflect.apply(func, this, parsedArgs);
2558
+ if (inst._def.output) {
2559
+ return (0, parse_js_1.parse)(inst._def.output, result);
2560
+ }
2561
+ return result;
2562
+ }, "_zod", { value: inst._zod, enumerable: false });
2563
+ };
2564
+ inst.implementAsync = (func) => {
2565
+ if (typeof func !== "function") {
2566
+ throw new Error("implementAsync() must be called with a function");
2567
+ }
2568
+ return Object.defineProperty(async function (...args) {
2569
+ const parsedArgs = inst._def.input ? await (0, parse_js_1.parseAsync)(inst._def.input, args) : args;
2570
+ const result = await Reflect.apply(func, this, parsedArgs);
2571
+ if (inst._def.output) {
2572
+ return await (0, parse_js_1.parseAsync)(inst._def.output, result);
2573
+ }
2574
+ return result;
2575
+ }, "_zod", { value: inst._zod, enumerable: false });
2576
+ };
2577
+ inst._zod.parse = (payload, _ctx) => {
2578
+ if (typeof payload.value !== "function") {
2579
+ payload.issues.push({
2580
+ code: "invalid_type",
2581
+ expected: "function",
2582
+ input: payload.value,
2583
+ inst,
2584
+ });
2585
+ return payload;
2586
+ }
2587
+ // Check if output is a promise type to determine if we should use async implementation
2588
+ const hasPromiseOutput = inst._def.output && inst._def.output._zod.def.type === "promise";
2589
+ if (hasPromiseOutput) {
2590
+ payload.value = inst.implementAsync(payload.value);
2591
+ }
2592
+ else {
2593
+ payload.value = inst.implement(payload.value);
2594
+ }
2595
+ return payload;
2596
+ };
2597
+ inst.input = (...args) => {
2598
+ const F = inst.constructor;
2599
+ if (Array.isArray(args[0])) {
2600
+ return new F({
2601
+ type: "function",
2602
+ input: new exports.$ZodTuple({
2603
+ type: "tuple",
2604
+ items: args[0],
2605
+ rest: args[1],
2606
+ }),
2607
+ output: inst._def.output,
2608
+ });
2609
+ }
2610
+ return new F({
2611
+ type: "function",
2612
+ input: args[0],
2613
+ output: inst._def.output,
2614
+ });
2615
+ };
2616
+ inst.output = (output) => {
2617
+ const F = inst.constructor;
2618
+ return new F({
2619
+ type: "function",
2620
+ input: inst._def.input,
2621
+ output,
2622
+ });
2623
+ };
2624
+ return inst;
2625
+ });
1700
2626
  exports.$ZodPromise = core.$constructor("$ZodPromise", (inst, def) => {
1701
2627
  exports.$ZodType.init(inst, def);
1702
2628
  inst._zod.parse = (payload, ctx) => {
@@ -1705,11 +2631,17 @@ exports.$ZodPromise = core.$constructor("$ZodPromise", (inst, def) => {
1705
2631
  });
1706
2632
  exports.$ZodLazy = core.$constructor("$ZodLazy", (inst, def) => {
1707
2633
  exports.$ZodType.init(inst, def);
1708
- util.defineLazy(inst._zod, "innerType", () => def.getter());
1709
- util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType._zod.pattern);
1710
- util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType._zod.propValues);
1711
- util.defineLazy(inst._zod, "optin", () => inst._zod.innerType._zod.optin);
1712
- util.defineLazy(inst._zod, "optout", () => inst._zod.innerType._zod.optout);
2634
+ // 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.
2635
+ util.defineLazy(inst._zod, "innerType", () => {
2636
+ const d = def;
2637
+ if (!d._cachedInner)
2638
+ d._cachedInner = def.getter();
2639
+ return d._cachedInner;
2640
+ });
2641
+ util.defineLazyInternal(inst, "pattern", (zod) => zod.innerType?._zod?.pattern);
2642
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.innerType?._zod?.propValues);
2643
+ util.defineLazyInternal(inst, "optin", (zod) => zod.innerType?._zod?.optin ?? undefined);
2644
+ util.defineLazyInternal(inst, "optout", (zod) => zod.innerType?._zod?.optout ?? undefined);
1713
2645
  inst._zod.parse = (payload, ctx) => {
1714
2646
  const inner = inst._zod.innerType;
1715
2647
  return inner._zod.run(payload, ctx);
@@ -1746,3 +2678,22 @@ function handleRefineResult(result, payload, input, inst) {
1746
2678
  payload.issues.push(util.issue(_iss));
1747
2679
  }
1748
2680
  }
2681
+
2682
+ // seal-cjs-exports
2683
+ (function () {
2684
+ var keys = Object.getOwnPropertyNames(exports);
2685
+ for (var i = 0; i < keys.length; i++) {
2686
+ var desc = Object.getOwnPropertyDescriptor(exports, keys[i]);
2687
+ if (!desc || !desc.get || !desc.configurable) continue;
2688
+ var value;
2689
+ try {
2690
+ value = desc.get();
2691
+ } catch (e) {
2692
+ continue;
2693
+ }
2694
+ // a circular require may not have settled this one yet, so leave it live
2695
+ if (value === undefined) continue;
2696
+ Object.defineProperty(exports, keys[i], { value: value, writable: false, enumerable: desc.enumerable, configurable: false });
2697
+ }
2698
+ Object.freeze(exports);
2699
+ })();