@nullix/zod-mongoose-studio 3.3.1 → 3.3.3

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 (325) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/_nuxt/{BCIlnd0g.js → 5ZXm4f56.js} +1 -1
  3. package/.output/public/_nuxt/{DcJ7oPvZ.js → B2fcLSyW.js} +1 -1
  4. package/.output/public/_nuxt/{B0N6xv5E.js → BBN7l5Hn.js} +1 -1
  5. package/.output/public/_nuxt/BBTTtb8r.js +41 -0
  6. package/.output/public/_nuxt/{5Tu2WUJz.js → BDbISGvP.js} +1 -1
  7. package/.output/public/_nuxt/{D87QMS6j.js → BijI4RNx.js} +1 -1
  8. package/.output/public/_nuxt/{C2BHp-MG.js → Bp9qkJ9m.js} +1 -1
  9. package/.output/public/_nuxt/{I3Ucam2s.js → Bu3-sqCf.js} +1 -1
  10. package/.output/public/_nuxt/{BO4hqv6q.js → C-FtTvwz.js} +1 -1
  11. package/.output/public/_nuxt/C02JV0Aj.js +1 -0
  12. package/.output/public/_nuxt/{sKEJiAHO.js → C1UkIsDc.js} +1 -1
  13. package/.output/public/_nuxt/{CKULsFUz.js → CJT28r6J.js} +1 -1
  14. package/.output/public/_nuxt/{BNDnV2op.js → CL7qtgl2.js} +3 -3
  15. package/.output/public/_nuxt/{DA0pQuyP.js → CRMd2YH2.js} +3 -3
  16. package/.output/public/_nuxt/{DpKrXpkK.js → CRkdQgFz.js} +1 -1
  17. package/.output/public/_nuxt/{B0cUlOSM.js → Cw1XFOz5.js} +1 -1
  18. package/.output/public/_nuxt/{CzbCpNnc.js → D5yWk6Ly.js} +1 -1
  19. package/.output/public/_nuxt/{BOsJJ_ZU.js → DA9GjKpR.js} +1 -1
  20. package/.output/public/_nuxt/{Dce9SnGa.js → DaWAlZhp.js} +1 -1
  21. package/.output/public/_nuxt/{tqQNlhT9.js → DafLMUHo.js} +1 -1
  22. package/.output/public/_nuxt/{ypRHVLFO.js → Dyaldc-t.js} +1 -1
  23. package/.output/public/_nuxt/{o-NCh2rp.js → UU9fpRNQ.js} +1 -1
  24. package/.output/public/_nuxt/builds/latest.json +1 -1
  25. package/.output/public/_nuxt/builds/meta/717459d8-0da1-42ed-af0b-9ec5395e8fdc.json +1 -0
  26. package/.output/public/_nuxt/entry.CDPplHzk.css +1 -0
  27. package/.output/public/_nuxt/error-404.hPtlUQpd.css +1 -0
  28. package/.output/public/_nuxt/error-500.E-PXUb6B.css +1 -0
  29. package/.output/public/_nuxt/{CMH9iX_E.js → kFZJW2-u.js} +2 -2
  30. package/.output/public/_nuxt/{DsnIpnT9.js → u3DlT5Mh.js} +1 -1
  31. package/.output/server/chunks/_/error-500.mjs.map +1 -1
  32. package/.output/server/chunks/_/parse-request.mjs +29 -0
  33. package/.output/server/chunks/_/parse-request.mjs.map +1 -0
  34. package/.output/server/chunks/build/client.precomputed.mjs +1 -1
  35. package/.output/server/chunks/build/{error-404-KRkA0DPI.mjs → error-404-aQ5PiVuX.mjs} +6 -12
  36. package/.output/server/chunks/build/error-404-aQ5PiVuX.mjs.map +1 -0
  37. package/.output/server/chunks/build/error-404-styles.DIZfBVBR.mjs +8 -0
  38. package/.output/server/chunks/build/error-404-styles.DIZfBVBR.mjs.map +1 -0
  39. package/.output/server/chunks/build/{error-500-DIIFf55p.mjs → error-500-BY6ZAZZ2.mjs} +6 -12
  40. package/.output/server/chunks/build/error-500-BY6ZAZZ2.mjs.map +1 -0
  41. package/.output/server/chunks/build/error-500-styles.BZXgEzR5.mjs +8 -0
  42. package/.output/server/chunks/build/error-500-styles.BZXgEzR5.mjs.map +1 -0
  43. package/.output/server/chunks/build/index-57_mtIua.mjs +235 -0
  44. package/.output/server/chunks/build/index-57_mtIua.mjs.map +1 -0
  45. package/.output/server/chunks/build/{index-CB1N4gax.mjs → index-Qa-4KqCB.mjs} +7 -13
  46. package/.output/server/chunks/build/index-Qa-4KqCB.mjs.map +1 -0
  47. package/.output/server/chunks/build/server.mjs +3913 -3378
  48. package/.output/server/chunks/build/server.mjs.map +1 -1
  49. package/.output/server/chunks/build/styles.mjs +4 -4
  50. package/.output/server/chunks/nitro/nitro.mjs +652 -2278
  51. package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
  52. package/.output/server/chunks/routes/api/editor-types.get.mjs +91 -28
  53. package/.output/server/chunks/routes/api/editor-types.get.mjs.map +1 -1
  54. package/.output/server/chunks/routes/api/parse.post.mjs +1599 -7
  55. package/.output/server/chunks/routes/api/parse.post.mjs.map +1 -1
  56. package/.output/server/chunks/routes/api/resolve.get.mjs +0 -6
  57. package/.output/server/chunks/routes/api/resolve.get.mjs.map +1 -1
  58. package/.output/server/chunks/routes/api/studio/run.post.mjs +50 -12
  59. package/.output/server/chunks/routes/api/studio/run.post.mjs.map +1 -1
  60. package/.output/server/chunks/routes/renderer.mjs +21 -44
  61. package/.output/server/chunks/routes/renderer.mjs.map +1 -1
  62. package/.output/server/index.mjs +1 -7
  63. package/.output/server/index.mjs.map +1 -1
  64. package/.output/server/node_modules/.nitro/@vue/compiler-core@3.5.43/dist/compiler-core.cjs.prod.js +6801 -0
  65. package/.output/server/node_modules/.nitro/@vue/compiler-core@3.5.43/package.json +58 -0
  66. package/.output/server/node_modules/.nitro/@vue/compiler-dom@3.5.43/dist/compiler-dom.cjs.prod.js +692 -0
  67. package/.output/server/node_modules/.nitro/@vue/compiler-dom@3.5.43/package.json +57 -0
  68. package/.output/server/node_modules/.nitro/@vue/reactivity@3.5.43/dist/reactivity.cjs.prod.js +1905 -0
  69. package/.output/server/node_modules/.nitro/@vue/reactivity@3.5.43/package.json +55 -0
  70. package/.output/server/node_modules/.nitro/@vue/runtime-core@3.5.43/dist/runtime-core.cjs.prod.js +7006 -0
  71. package/.output/server/node_modules/.nitro/@vue/runtime-core@3.5.43/package.json +52 -0
  72. package/.output/server/node_modules/.nitro/@vue/runtime-dom@3.5.43/dist/runtime-dom.cjs.prod.js +1867 -0
  73. package/.output/server/node_modules/.nitro/@vue/runtime-dom@3.5.43/package.json +60 -0
  74. package/.output/server/node_modules/.nitro/@vue/shared@3.5.43/dist/shared.cjs.prod.js +655 -0
  75. package/.output/server/node_modules/.nitro/@vue/shared@3.5.43/package.json +47 -0
  76. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/array-set.js +121 -0
  77. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/base64-vlq.js +140 -0
  78. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/base64.js +67 -0
  79. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/binary-search.js +111 -0
  80. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/mapping-list.js +79 -0
  81. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/quick-sort.js +141 -0
  82. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/source-map-consumer.js +1236 -0
  83. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/source-map-generator.js +446 -0
  84. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/source-node.js +420 -0
  85. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/lib/util.js +594 -0
  86. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/package.json +71 -0
  87. package/.output/server/node_modules/.nitro/source-map-js@1.2.2/source-map.js +8 -0
  88. package/.output/server/node_modules/.nitro/vue@3.5.43/dist/vue.cjs.js +80 -0
  89. package/.output/server/node_modules/.nitro/vue@3.5.43/dist/vue.cjs.prod.js +66 -0
  90. package/.output/server/node_modules/.nitro/vue@3.5.43/index.js +7 -0
  91. package/.output/server/node_modules/.nitro/vue@3.5.43/index.mjs +1 -0
  92. package/.output/server/node_modules/.nitro/vue@3.5.43/package.json +112 -0
  93. package/.output/server/node_modules/@babel/parser/lib/index.js +55 -21
  94. package/.output/server/node_modules/@babel/parser/package.json +7 -7
  95. package/.output/server/node_modules/@esbuild/linux-x64/bin/esbuild +0 -0
  96. package/.output/server/node_modules/@esbuild/linux-x64/package.json +1 -1
  97. package/.output/server/node_modules/@iconify/utils/lib/colors/index.js +19 -16
  98. package/.output/server/node_modules/@iconify/utils/lib/colors/keywords.js +3 -4
  99. package/.output/server/node_modules/@iconify/utils/lib/css/common.js +16 -16
  100. package/.output/server/node_modules/@iconify/utils/lib/css/format.js +1 -2
  101. package/.output/server/node_modules/@iconify/utils/lib/css/icon.js +11 -14
  102. package/.output/server/node_modules/@iconify/utils/lib/css/icons.js +13 -16
  103. package/.output/server/node_modules/@iconify/utils/lib/customisations/bool.js +1 -2
  104. package/.output/server/node_modules/@iconify/utils/lib/customisations/defaults.js +1 -3
  105. package/.output/server/node_modules/@iconify/utils/lib/customisations/flip.js +2 -5
  106. package/.output/server/node_modules/@iconify/utils/lib/customisations/merge.js +1 -3
  107. package/.output/server/node_modules/@iconify/utils/lib/customisations/rotate.js +4 -5
  108. package/.output/server/node_modules/@iconify/utils/lib/emoji/cleanup.js +1 -3
  109. package/.output/server/node_modules/@iconify/utils/lib/emoji/convert.js +9 -11
  110. package/.output/server/node_modules/@iconify/utils/lib/emoji/data.js +1 -2
  111. package/.output/server/node_modules/@iconify/utils/lib/emoji/format.js +1 -3
  112. package/.output/server/node_modules/@iconify/utils/lib/emoji/parse.js +1 -3
  113. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/base.js +12 -18
  114. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/create.js +3 -4
  115. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/numbers.js +5 -7
  116. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/similar.js +1 -8
  117. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/tree.js +11 -12
  118. package/.output/server/node_modules/@iconify/utils/lib/emoji/replace/find.js +5 -7
  119. package/.output/server/node_modules/@iconify/utils/lib/emoji/replace/replace.js +1 -3
  120. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/components.js +1 -3
  121. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/missing.js +7 -7
  122. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/name.js +2 -4
  123. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/parse.js +5 -9
  124. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/similar.js +3 -5
  125. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/tree.js +2 -4
  126. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/variations.js +7 -8
  127. package/.output/server/node_modules/@iconify/utils/lib/icon/defaults.js +1 -2
  128. package/.output/server/node_modules/@iconify/utils/lib/icon/merge.js +1 -3
  129. package/.output/server/node_modules/@iconify/utils/lib/icon/name.js +3 -4
  130. package/.output/server/node_modules/@iconify/utils/lib/icon/square.js +1 -2
  131. package/.output/server/node_modules/@iconify/utils/lib/icon/transformations.js +1 -2
  132. package/.output/server/node_modules/@iconify/utils/lib/icon-set/convert-info.js +10 -15
  133. package/.output/server/node_modules/@iconify/utils/lib/icon-set/expand.js +1 -3
  134. package/.output/server/node_modules/@iconify/utils/lib/icon-set/get-icon.js +3 -5
  135. package/.output/server/node_modules/@iconify/utils/lib/icon-set/get-icons.js +1 -3
  136. package/.output/server/node_modules/@iconify/utils/lib/icon-set/minify.js +1 -3
  137. package/.output/server/node_modules/@iconify/utils/lib/icon-set/parse.js +1 -3
  138. package/.output/server/node_modules/@iconify/utils/lib/icon-set/tree.js +1 -2
  139. package/.output/server/node_modules/@iconify/utils/lib/icon-set/validate-basic.js +1 -3
  140. package/.output/server/node_modules/@iconify/utils/lib/icon-set/validate.js +21 -13
  141. package/.output/server/node_modules/@iconify/utils/lib/index.js +1 -2
  142. package/.output/server/node_modules/@iconify/utils/lib/loader/custom.js +3 -3
  143. package/.output/server/node_modules/@iconify/utils/lib/loader/hmr-utils.js +33 -0
  144. package/.output/server/node_modules/@iconify/utils/lib/loader/loader.js +22 -22
  145. package/.output/server/node_modules/@iconify/utils/lib/loader/modern.js +7 -22
  146. package/.output/server/node_modules/@iconify/utils/lib/loader/utils.js +60 -16
  147. package/.output/server/node_modules/@iconify/utils/lib/misc/objects.js +1 -2
  148. package/.output/server/node_modules/@iconify/utils/lib/misc/strings.js +1 -2
  149. package/.output/server/node_modules/@iconify/utils/lib/misc/title.js +1 -2
  150. package/.output/server/node_modules/@iconify/utils/lib/svg/build.js +9 -11
  151. package/.output/server/node_modules/@iconify/utils/lib/svg/defs.js +1 -2
  152. package/.output/server/node_modules/@iconify/utils/lib/svg/encode-svg-for-css.js +1 -3
  153. package/.output/server/node_modules/@iconify/utils/lib/svg/html.js +1 -2
  154. package/.output/server/node_modules/@iconify/utils/lib/svg/id.js +1 -2
  155. package/.output/server/node_modules/@iconify/utils/lib/svg/inner-html.js +1 -2
  156. package/.output/server/node_modules/@iconify/utils/lib/svg/parse.js +3 -5
  157. package/.output/server/node_modules/@iconify/utils/lib/svg/pretty.js +5 -4
  158. package/.output/server/node_modules/@iconify/utils/lib/svg/size.js +1 -2
  159. package/.output/server/node_modules/@iconify/utils/lib/svg/trim.js +1 -2
  160. package/.output/server/node_modules/@iconify/utils/lib/svg/url.js +1 -2
  161. package/.output/server/node_modules/@iconify/utils/lib/svg/viewbox.js +2 -3
  162. package/.output/server/node_modules/@iconify/utils/package.json +15 -13
  163. package/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +8 -1
  164. package/.output/server/node_modules/@vue/compiler-ssr/package.json +3 -3
  165. package/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +34 -13
  166. package/.output/server/node_modules/@vue/server-renderer/package.json +4 -6
  167. package/.output/server/node_modules/devalue/index.js +15 -2
  168. package/.output/server/node_modules/devalue/package.json +5 -3
  169. package/.output/server/node_modules/devalue/src/base64.js +46 -96
  170. package/.output/server/node_modules/devalue/src/constants.js +5 -0
  171. package/.output/server/node_modules/devalue/src/operations.js +221 -0
  172. package/.output/server/node_modules/devalue/src/parse.js +76 -62
  173. package/.output/server/node_modules/devalue/src/stringify.js +164 -81
  174. package/.output/server/node_modules/devalue/src/uneval.js +312 -104
  175. package/.output/server/node_modules/devalue/src/utils.js +61 -19
  176. package/.output/server/node_modules/esbuild/lib/main.js +12 -8
  177. package/.output/server/node_modules/esbuild/package.json +50 -50
  178. package/.output/server/node_modules/hookable/dist/index.mjs +2 -11
  179. package/.output/server/node_modules/hookable/package.json +23 -22
  180. package/.output/server/node_modules/ip-address/dist/ipv4.js +7 -0
  181. package/.output/server/node_modules/ip-address/package.json +1 -1
  182. package/.output/server/node_modules/zod/package.json +20 -8
  183. package/.output/server/node_modules/zod/v4/classic/checks.js +1 -1
  184. package/.output/server/node_modules/zod/v4/classic/deep-partial.js +13 -0
  185. package/.output/server/node_modules/zod/v4/classic/errors.js +44 -35
  186. package/.output/server/node_modules/zod/v4/classic/external.js +5 -8
  187. package/.output/server/node_modules/zod/v4/classic/from-json-schema.js +375 -78
  188. package/.output/server/node_modules/zod/v4/classic/in-out.js +36 -0
  189. package/.output/server/node_modules/zod/v4/classic/index.js +2 -2
  190. package/.output/server/node_modules/zod/v4/classic/iso.js +2 -17
  191. package/.output/server/node_modules/zod/v4/classic/package.json +2 -1
  192. package/.output/server/node_modules/zod/v4/classic/parse.js +1 -0
  193. package/.output/server/node_modules/zod/v4/classic/schemas.js +601 -223
  194. package/.output/server/node_modules/zod/v4/core/api.js +51 -26
  195. package/.output/server/node_modules/zod/v4/core/checks.js +68 -127
  196. package/.output/server/node_modules/zod/v4/core/compile.js +1858 -0
  197. package/.output/server/node_modules/zod/v4/core/core.js +87 -22
  198. package/.output/server/node_modules/zod/v4/core/doc.js +12 -9
  199. package/.output/server/node_modules/zod/v4/core/errors.js +127 -42
  200. package/.output/server/node_modules/zod/v4/core/index.js +3 -0
  201. package/.output/server/node_modules/zod/v4/core/json-schema-generator.js +6 -2
  202. package/.output/server/node_modules/zod/v4/core/json-schema-processors.js +413 -175
  203. package/.output/server/node_modules/zod/v4/core/memoizer.js +311 -0
  204. package/.output/server/node_modules/zod/v4/core/package.json +2 -1
  205. package/.output/server/node_modules/zod/v4/core/parse.js +130 -48
  206. package/.output/server/node_modules/zod/v4/core/regexes.js +39 -16
  207. package/.output/server/node_modules/zod/v4/core/registries.js +2 -2
  208. package/.output/server/node_modules/zod/v4/core/schemas.js +895 -382
  209. package/.output/server/node_modules/zod/v4/core/to-json-schema.js +253 -39
  210. package/.output/server/node_modules/zod/v4/core/util.js +383 -175
  211. package/.output/server/node_modules/zod/v4/core/versions.js +2 -2
  212. package/.output/server/node_modules/zod/v4/core/visit.js +169 -0
  213. package/.output/server/node_modules/zod/v4/index.js +3 -2
  214. package/.output/server/node_modules/zod/v4/locales/ar.js +5 -0
  215. package/.output/server/node_modules/zod/v4/locales/az.js +5 -0
  216. package/.output/server/node_modules/zod/v4/locales/be.js +12 -0
  217. package/.output/server/node_modules/zod/v4/locales/bg.js +5 -0
  218. package/.output/server/node_modules/zod/v4/locales/bn.js +113 -0
  219. package/.output/server/node_modules/zod/v4/locales/ca.js +5 -0
  220. package/.output/server/node_modules/zod/v4/locales/ckb.js +133 -0
  221. package/.output/server/node_modules/zod/v4/locales/cs.js +5 -0
  222. package/.output/server/node_modules/zod/v4/locales/da.js +7 -2
  223. package/.output/server/node_modules/zod/v4/locales/de.js +5 -0
  224. package/.output/server/node_modules/zod/v4/locales/el.js +112 -0
  225. package/.output/server/node_modules/zod/v4/locales/en.js +20 -4
  226. package/.output/server/node_modules/zod/v4/locales/eo.js +5 -0
  227. package/.output/server/node_modules/zod/v4/locales/es.js +4 -0
  228. package/.output/server/node_modules/zod/v4/locales/fa.js +5 -0
  229. package/.output/server/node_modules/zod/v4/locales/fi.js +5 -0
  230. package/.output/server/node_modules/zod/v4/locales/fr-CA.js +5 -0
  231. package/.output/server/node_modules/zod/v4/locales/fr.js +38 -17
  232. package/.output/server/node_modules/zod/v4/locales/gu.js +113 -0
  233. package/.output/server/node_modules/zod/v4/locales/he.js +7 -0
  234. package/.output/server/node_modules/zod/v4/locales/hi.js +111 -0
  235. package/.output/server/node_modules/zod/v4/locales/hr.js +126 -0
  236. package/.output/server/node_modules/zod/v4/locales/hu.js +5 -0
  237. package/.output/server/node_modules/zod/v4/locales/hy.js +11 -0
  238. package/.output/server/node_modules/zod/v4/locales/id.js +5 -0
  239. package/.output/server/node_modules/zod/v4/locales/index.js +14 -0
  240. package/.output/server/node_modules/zod/v4/locales/is.js +5 -0
  241. package/.output/server/node_modules/zod/v4/locales/it.js +6 -1
  242. package/.output/server/node_modules/zod/v4/locales/ja.js +5 -0
  243. package/.output/server/node_modules/zod/v4/locales/ka.js +13 -8
  244. package/.output/server/node_modules/zod/v4/locales/km.js +5 -0
  245. package/.output/server/node_modules/zod/v4/locales/kn.js +116 -0
  246. package/.output/server/node_modules/zod/v4/locales/ko.js +5 -0
  247. package/.output/server/node_modules/zod/v4/locales/lt.js +4 -0
  248. package/.output/server/node_modules/zod/v4/locales/mk.js +5 -0
  249. package/.output/server/node_modules/zod/v4/locales/ms.js +5 -0
  250. package/.output/server/node_modules/zod/v4/locales/ne.js +111 -0
  251. package/.output/server/node_modules/zod/v4/locales/nl.js +5 -0
  252. package/.output/server/node_modules/zod/v4/locales/nn.js +113 -0
  253. package/.output/server/node_modules/zod/v4/locales/no.js +7 -2
  254. package/.output/server/node_modules/zod/v4/locales/ota.js +5 -0
  255. package/.output/server/node_modules/zod/v4/locales/package.json +2 -1
  256. package/.output/server/node_modules/zod/v4/locales/pl.js +5 -0
  257. package/.output/server/node_modules/zod/v4/locales/ps.js +5 -0
  258. package/.output/server/node_modules/zod/v4/locales/pt-BR.js +143 -0
  259. package/.output/server/node_modules/zod/v4/locales/pt.js +89 -55
  260. package/.output/server/node_modules/zod/v4/locales/ro.js +122 -0
  261. package/.output/server/node_modules/zod/v4/locales/ru.js +12 -0
  262. package/.output/server/node_modules/zod/v4/locales/sk.js +116 -0
  263. package/.output/server/node_modules/zod/v4/locales/sl.js +5 -0
  264. package/.output/server/node_modules/zod/v4/locales/sv.js +7 -2
  265. package/.output/server/node_modules/zod/v4/locales/ta.js +5 -0
  266. package/.output/server/node_modules/zod/v4/locales/tg.js +117 -0
  267. package/.output/server/node_modules/zod/v4/locales/th.js +5 -0
  268. package/.output/server/node_modules/zod/v4/locales/tk.js +107 -0
  269. package/.output/server/node_modules/zod/v4/locales/tr.js +5 -0
  270. package/.output/server/node_modules/zod/v4/locales/uk.js +5 -0
  271. package/.output/server/node_modules/zod/v4/locales/ur.js +5 -0
  272. package/.output/server/node_modules/zod/v4/locales/uz.js +4 -0
  273. package/.output/server/node_modules/zod/v4/locales/vi.js +5 -0
  274. package/.output/server/node_modules/zod/v4/locales/yo.js +5 -0
  275. package/.output/server/node_modules/zod/v4/locales/zh-CN.js +5 -0
  276. package/.output/server/node_modules/zod/v4/locales/zh-TW.js +5 -0
  277. package/.output/server/node_modules/zod/v4/package.json +2 -1
  278. package/.output/server/package.json +18 -18
  279. package/README.md +12 -1
  280. package/package.json +10 -9
  281. package/server/api/editor-types.get.ts +2 -23
  282. package/server/api/studio/run.post.ts +18 -6
  283. package/server/utils/editor-types.json +1 -0
  284. package/.output/public/_nuxt/B9paGgN0.js +0 -33
  285. package/.output/public/_nuxt/builds/meta/51f1351c-0667-4235-9ddc-16582a51ce03.json +0 -1
  286. package/.output/public/_nuxt/entry.B-vs1tRH.css +0 -1
  287. package/.output/public/_nuxt/error-404.CTSXlFYa.css +0 -1
  288. package/.output/public/_nuxt/error-500.DqEfQnVZ.css +0 -1
  289. package/.output/server/chunks/build/error-404-KRkA0DPI.mjs.map +0 -1
  290. package/.output/server/chunks/build/error-404-styles.I0NYw-Bn.mjs +0 -8
  291. package/.output/server/chunks/build/error-404-styles.I0NYw-Bn.mjs.map +0 -1
  292. package/.output/server/chunks/build/error-500-DIIFf55p.mjs.map +0 -1
  293. package/.output/server/chunks/build/error-500-styles.D1cs9hQy.mjs +0 -8
  294. package/.output/server/chunks/build/error-500-styles.D1cs9hQy.mjs.map +0 -1
  295. package/.output/server/chunks/build/index-CB1N4gax.mjs.map +0 -1
  296. /package/.output/server/node_modules/{@vue/compiler-core → .nitro/@vue/compiler-core@3.5.32}/dist/compiler-core.cjs.prod.js +0 -0
  297. /package/.output/server/node_modules/{@vue/compiler-core → .nitro/@vue/compiler-core@3.5.32}/package.json +0 -0
  298. /package/.output/server/node_modules/{@vue/compiler-dom → .nitro/@vue/compiler-dom@3.5.32}/dist/compiler-dom.cjs.prod.js +0 -0
  299. /package/.output/server/node_modules/{@vue/compiler-dom → .nitro/@vue/compiler-dom@3.5.32}/package.json +0 -0
  300. /package/.output/server/node_modules/{@vue/reactivity → .nitro/@vue/reactivity@3.5.32}/dist/reactivity.cjs.prod.js +0 -0
  301. /package/.output/server/node_modules/{@vue/reactivity → .nitro/@vue/reactivity@3.5.32}/package.json +0 -0
  302. /package/.output/server/node_modules/{@vue/runtime-core → .nitro/@vue/runtime-core@3.5.32}/dist/runtime-core.cjs.prod.js +0 -0
  303. /package/.output/server/node_modules/{@vue/runtime-core → .nitro/@vue/runtime-core@3.5.32}/package.json +0 -0
  304. /package/.output/server/node_modules/{@vue/runtime-dom → .nitro/@vue/runtime-dom@3.5.32}/dist/runtime-dom.cjs.prod.js +0 -0
  305. /package/.output/server/node_modules/{@vue/runtime-dom → .nitro/@vue/runtime-dom@3.5.32}/package.json +0 -0
  306. /package/.output/server/node_modules/{@vue/shared → .nitro/@vue/shared@3.5.32}/dist/shared.cjs.prod.js +0 -0
  307. /package/.output/server/node_modules/{@vue/shared → .nitro/@vue/shared@3.5.32}/package.json +0 -0
  308. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/array-set.js +0 -0
  309. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/base64-vlq.js +0 -0
  310. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/base64.js +0 -0
  311. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/binary-search.js +0 -0
  312. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/mapping-list.js +0 -0
  313. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/quick-sort.js +0 -0
  314. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/source-map-consumer.js +0 -0
  315. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/source-map-generator.js +0 -0
  316. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/source-node.js +0 -0
  317. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/lib/util.js +0 -0
  318. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/package.json +0 -0
  319. /package/.output/server/node_modules/{source-map-js → .nitro/source-map-js@1.2.1}/source-map.js +0 -0
  320. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.32}/dist/vue.cjs.js +0 -0
  321. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.32}/dist/vue.cjs.prod.js +0 -0
  322. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.32}/index.js +0 -0
  323. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.32}/index.mjs +0 -0
  324. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.32}/package.json +0 -0
  325. /package/.output/server/node_modules/{vue → .nitro/vue@3.5.43}/server-renderer/index.mjs +0 -0
@@ -1,7 +1,7 @@
1
1
  import * as checks from "./checks.js";
2
2
  import * as core from "./core.js";
3
3
  import { Doc } from "./doc.js";
4
- import { parse, parseAsync, safeParse, safeParseAsync } from "./parse.js";
4
+ import { parse, parseAsync } from "./parse.js";
5
5
  import * as regexes from "./regexes.js";
6
6
  import * as util from "./util.js";
7
7
  import { version } from "./versions.js";
@@ -11,19 +11,20 @@ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def)
11
11
  inst._zod.def = def; // set _def property
12
12
  inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
13
13
  inst._zod.version = version;
14
- const checks = [...(inst._zod.def.checks ?? [])];
14
+ const defChecks = inst._zod.def.checks;
15
15
  // if inst is itself a checks.$ZodCheck, run it as a check
16
- if (inst._zod.traits.has("$ZodCheck")) {
17
- checks.unshift(inst);
18
- }
16
+ const checks = inst._zod.traits.has("$ZodCheck")
17
+ ? [inst, ...(defChecks ?? [])]
18
+ : defChecks?.length
19
+ ? [...defChecks]
20
+ : [];
19
21
  for (const ch of checks) {
20
22
  for (const fn of ch._zod.onattach) {
21
23
  fn(inst);
22
24
  }
23
25
  }
24
26
  if (checks.length === 0) {
25
- // deferred initializer
26
- // inst._zod.parse is not yet defined
27
+ // deferred initializer inst._zod.parse is not yet defined
27
28
  (_a = inst._zod).deferred ?? (_a.deferred = []);
28
29
  inst._zod.deferred?.push(() => {
29
30
  inst._zod.run = inst._zod.parse;
@@ -31,10 +32,14 @@ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def)
31
32
  }
32
33
  else {
33
34
  const runChecks = (payload, checks, ctx) => {
35
+ if (payload.memo)
36
+ return payload;
34
37
  let isAborted = util.aborted(payload);
35
38
  let asyncResult;
36
39
  for (const ch of checks) {
37
40
  if (ch._zod.def.when) {
41
+ if (util.explicitlyAborted(payload))
42
+ continue;
38
43
  const shouldRun = ch._zod.def.when(payload);
39
44
  if (!shouldRun)
40
45
  continue;
@@ -53,6 +58,7 @@ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def)
53
58
  const nextLen = payload.issues.length;
54
59
  if (nextLen === currLen)
55
60
  return;
61
+ util.attachSchema(payload.issues, currLen, inst);
56
62
  if (!isAborted)
57
63
  isAborted = util.aborted(payload, currLen);
58
64
  });
@@ -61,6 +67,7 @@ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def)
61
67
  const nextLen = payload.issues.length;
62
68
  if (nextLen === currLen)
63
69
  continue;
70
+ util.attachSchema(payload.issues, currLen, inst);
64
71
  if (!isAborted)
65
72
  isAborted = util.aborted(payload, currLen);
66
73
  }
@@ -92,8 +99,7 @@ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def)
92
99
  return inst._zod.parse(payload, ctx);
93
100
  }
94
101
  if (ctx.direction === "backward") {
95
- // run canary
96
- // initial pass (no checks)
102
+ // run canary initial pass (no checks)
97
103
  const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
98
104
  if (canary instanceof Promise) {
99
105
  return canary.then((canary) => {
@@ -112,25 +118,44 @@ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def)
112
118
  return runChecks(result, checks, ctx);
113
119
  };
114
120
  }
115
- // Lazy initialize ~standard to avoid creating objects for every schema
116
- util.defineLazy(inst, "~standard", () => ({
121
+ }, {
122
+ // Wrappers extend this by installing a richer factory over it; reading it eagerly would defeat the laziness.
123
+ get "~standard"() {
124
+ return util.hide(this, "~standard", standardProps(this));
125
+ },
126
+ set "~standard"(value) {
127
+ util.own(this, "~standard", value);
128
+ },
129
+ });
130
+ /** The Standard Schema surface for `inst`. Shared so wrappers can extend it without forcing it. */
131
+ // 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
132
+ const toStandardResult = (r, ctx) => r.issues.length ? { issues: r.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())) } : { value: r.value };
133
+ async function validateAsync(inst, value) {
134
+ const ctx = { async: true };
135
+ return toStandardResult((await inst._zod.run({ value, issues: [] }, ctx)), ctx);
136
+ }
137
+ export function standardProps(inst) {
138
+ return {
117
139
  validate: (value) => {
140
+ const ctx = { async: false };
118
141
  try {
119
- const r = safeParse(inst, value);
120
- return r.success ? { value: r.data } : { issues: r.error?.issues };
121
- }
122
- catch (_) {
123
- return safeParseAsync(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
142
+ const r = inst._zod.run({ value, issues: [] }, ctx);
143
+ if (!(r instanceof Promise))
144
+ return toStandardResult(r, ctx);
124
145
  }
146
+ catch (_) { }
147
+ // async function so a synchronously throwing check rejects instead of escaping validate
148
+ return validateAsync(inst, value);
125
149
  },
126
150
  vendor: "zod",
127
151
  version: 1,
128
- }));
129
- });
152
+ };
153
+ }
130
154
  export { clone } from "./util.js";
131
155
  export const $ZodString = /*@__PURE__*/ core.$constructor("$ZodString", (inst, def) => {
132
156
  $ZodType.init(inst, def);
133
- inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? regexes.string(inst._zod.bag);
157
+ // a format's own pattern, else unbounded; a template literal derives the check-aware form itself
158
+ inst._zod.pattern = def.pattern ?? regexes.anyString;
134
159
  inst._zod.parse = (payload, _) => {
135
160
  if (def.coerce)
136
161
  try {
@@ -182,51 +207,115 @@ export const $ZodEmail = /*@__PURE__*/ core.$constructor("$ZodEmail", (inst, def
182
207
  def.pattern ?? (def.pattern = regexes.email);
183
208
  $ZodStringFormat.init(inst, def);
184
209
  });
210
+ /** The `://` guard rejected the input before the URL constructor saw it. */
211
+ export const URL_BAD_FORMAT = 1;
212
+ /** The URL parser rejected the input. */
213
+ export const URL_UNPARSEABLE = 2;
214
+ export function canParseURL(input) {
215
+ try {
216
+ if (typeof URL !== "undefined" && typeof URL.canParse === "function")
217
+ return URL.canParse(input);
218
+ new URL(input);
219
+ return true;
220
+ }
221
+ catch {
222
+ return false;
223
+ }
224
+ }
225
+ export function validateURL(trimmed, def) {
226
+ if (!("normalize" in def) && !("hostname" in def) && !("protocol" in def)) {
227
+ return canParseURL(trimmed) || URL_UNPARSEABLE;
228
+ }
229
+ return parseURLObject(trimmed, def);
230
+ }
231
+ /** Parses a URL while preserving the non-normalizing HTTP guard. */
232
+ export function parseURLObject(trimmed, def) {
233
+ // When normalize is off, require :// for http/https URLs. This prevents strings like "http:example.com" or "https:/path" from being silently accepted
234
+ if (!def.normalize && def.protocol?.source === regexes.httpProtocol.source && !/^https?:\/\//i.test(trimmed)) {
235
+ return URL_BAD_FORMAT;
236
+ }
237
+ try {
238
+ if (typeof URL !== "undefined") {
239
+ const URLStatic = URL;
240
+ if (typeof URLStatic.parse === "function")
241
+ return URLStatic.parse(trimmed) ?? URL_UNPARSEABLE;
242
+ }
243
+ // @ts-ignore
244
+ return new URL(trimmed);
245
+ }
246
+ catch {
247
+ return URL_UNPARSEABLE;
248
+ }
249
+ }
250
+ const asciiTabOrNewline = /[\t\n\r]/g;
251
+ /** 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. */
252
+ export function stripTabAndNewline(value) {
253
+ return value.replace(asciiTabOrNewline, "");
254
+ }
255
+ export function urlHostnameOk(url, hostname) {
256
+ hostname.lastIndex = 0;
257
+ return hostname.test(url.hostname);
258
+ }
259
+ export function urlProtocolOk(url, protocol) {
260
+ protocol.lastIndex = 0;
261
+ return protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol);
262
+ }
185
263
  export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) => {
186
264
  $ZodStringFormat.init(inst, def);
187
265
  inst._zod.check = (payload) => {
188
266
  try {
189
267
  // Trim whitespace from input
190
268
  const trimmed = payload.value.trim();
191
- // @ts-ignore
192
- const url = new URL(trimmed);
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: def.hostname.source,
201
- input: payload.value,
202
- inst,
203
- continue: !def.abort,
204
- });
205
- }
269
+ const url = validateURL(trimmed, def);
270
+ if (url === URL_BAD_FORMAT) {
271
+ payload.issues.push({
272
+ code: "invalid_format",
273
+ format: "url",
274
+ note: "Invalid URL format",
275
+ input: payload.value,
276
+ inst,
277
+ continue: !def.abort,
278
+ });
279
+ return;
206
280
  }
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
- }
281
+ if (url === URL_UNPARSEABLE) {
282
+ payload.issues.push({
283
+ code: "invalid_format",
284
+ format: "url",
285
+ input: payload.value,
286
+ inst,
287
+ continue: !def.abort,
288
+ });
289
+ return;
220
290
  }
221
- // Set the output value based on normalize flag
222
- if (def.normalize) {
223
- // Use normalized URL
224
- payload.value = url.href;
291
+ if (url === true) {
292
+ payload.value = stripTabAndNewline(trimmed);
293
+ return;
225
294
  }
226
- else {
227
- // Preserve the original input (trimmed)
228
- payload.value = trimmed;
295
+ if (def.hostname && !urlHostnameOk(url, def.hostname)) {
296
+ payload.issues.push({
297
+ code: "invalid_format",
298
+ format: "url",
299
+ note: "Invalid hostname",
300
+ pattern: def.hostname.source,
301
+ input: payload.value,
302
+ inst,
303
+ continue: !def.abort,
304
+ });
305
+ }
306
+ if (def.protocol && !urlProtocolOk(url, def.protocol)) {
307
+ payload.issues.push({
308
+ code: "invalid_format",
309
+ format: "url",
310
+ note: "Invalid protocol",
311
+ pattern: def.protocol.source,
312
+ input: payload.value,
313
+ inst,
314
+ continue: !def.abort,
315
+ });
229
316
  }
317
+ // Set the output value based on normalize flag
318
+ payload.value = def.normalize ? url.href : stripTabAndNewline(trimmed);
230
319
  return;
231
320
  }
232
321
  catch (_) {
@@ -245,9 +334,16 @@ export const $ZodEmoji = /*@__PURE__*/ core.$constructor("$ZodEmoji", (inst, def
245
334
  $ZodStringFormat.init(inst, def);
246
335
  });
247
336
  export const $ZodNanoID = /*@__PURE__*/ core.$constructor("$ZodNanoID", (inst, def) => {
248
- def.pattern ?? (def.pattern = regexes.nanoid);
337
+ if (def.length !== undefined && (!Number.isInteger(def.length) || def.length < 1))
338
+ throw new Error(`Invalid nanoid length: ${def.length}`);
339
+ def.pattern ?? (def.pattern = def.length === undefined ? regexes.nanoid : regexes.nanoidOfLength(def.length));
249
340
  $ZodStringFormat.init(inst, def);
250
341
  });
342
+ /**
343
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
344
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
345
+ * See https://github.com/paralleldrive/cuid.
346
+ */
251
347
  export const $ZodCUID = /*@__PURE__*/ core.$constructor("$ZodCUID", (inst, def) => {
252
348
  def.pattern ?? (def.pattern = regexes.cuid);
253
349
  $ZodStringFormat.init(inst, def);
@@ -287,19 +383,19 @@ export const $ZodISODuration = /*@__PURE__*/ core.$constructor("$ZodISODuration"
287
383
  export const $ZodIPv4 = /*@__PURE__*/ core.$constructor("$ZodIPv4", (inst, def) => {
288
384
  def.pattern ?? (def.pattern = regexes.ipv4);
289
385
  $ZodStringFormat.init(inst, def);
290
- inst._zod.bag.format = `ipv4`;
291
386
  });
387
+ /** 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`. */
388
+ const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
389
+ export function isValidIPv6(value) {
390
+ if (!ipv6Alphabet.test(value))
391
+ return false;
392
+ return canParseURL(`http://[${value}]`);
393
+ }
292
394
  export const $ZodIPv6 = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def) => {
293
395
  def.pattern ?? (def.pattern = regexes.ipv6);
294
396
  $ZodStringFormat.init(inst, def);
295
- inst._zod.bag.format = `ipv6`;
296
397
  inst._zod.check = (payload) => {
297
- try {
298
- // @ts-ignore
299
- new URL(`http://[${payload.value}]`);
300
- // return;
301
- }
302
- catch {
398
+ if (!isValidIPv6(payload.value)) {
303
399
  payload.issues.push({
304
400
  code: "invalid_format",
305
401
  format: "ipv6",
@@ -313,32 +409,30 @@ export const $ZodIPv6 = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def)
313
409
  export const $ZodMAC = /*@__PURE__*/ core.$constructor("$ZodMAC", (inst, def) => {
314
410
  def.pattern ?? (def.pattern = regexes.mac(def.delimiter));
315
411
  $ZodStringFormat.init(inst, def);
316
- inst._zod.bag.format = `mac`;
317
412
  });
318
413
  export const $ZodCIDRv4 = /*@__PURE__*/ core.$constructor("$ZodCIDRv4", (inst, def) => {
319
414
  def.pattern ?? (def.pattern = regexes.cidrv4);
320
415
  $ZodStringFormat.init(inst, def);
321
416
  });
417
+ export function isValidCIDRv6(value) {
418
+ const parts = value.split("/");
419
+ if (parts.length !== 2)
420
+ return false;
421
+ const [address, prefix] = parts;
422
+ if (!prefix)
423
+ return false;
424
+ const prefixNum = Number(prefix);
425
+ if (`${prefixNum}` !== prefix)
426
+ return false;
427
+ if (prefixNum < 0 || prefixNum > 128)
428
+ return false;
429
+ return isValidIPv6(address);
430
+ }
322
431
  export const $ZodCIDRv6 = /*@__PURE__*/ core.$constructor("$ZodCIDRv6", (inst, def) => {
323
432
  def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
324
433
  $ZodStringFormat.init(inst, def);
325
434
  inst._zod.check = (payload) => {
326
- const parts = payload.value.split("/");
327
- try {
328
- if (parts.length !== 2)
329
- throw new Error();
330
- const [address, prefix] = parts;
331
- if (!prefix)
332
- throw new Error();
333
- const prefixNum = Number(prefix);
334
- if (`${prefixNum}` !== prefix)
335
- throw new Error();
336
- if (prefixNum < 0 || prefixNum > 128)
337
- throw new Error();
338
- // @ts-ignore
339
- new URL(`http://[${address}]`);
340
- }
341
- catch {
435
+ if (!isValidCIDRv6(payload.value)) {
342
436
  payload.issues.push({
343
437
  code: "invalid_format",
344
438
  format: "cidrv6",
@@ -353,6 +447,9 @@ export const $ZodCIDRv6 = /*@__PURE__*/ core.$constructor("$ZodCIDRv6", (inst, d
353
447
  export function isValidBase64(data) {
354
448
  if (data === "")
355
449
  return true;
450
+ // atob ignores whitespace, so reject it up front.
451
+ if (/\s/.test(data))
452
+ return false;
356
453
  if (data.length % 4 !== 0)
357
454
  return false;
358
455
  try {
@@ -364,10 +461,11 @@ export function isValidBase64(data) {
364
461
  return false;
365
462
  }
366
463
  }
464
+ // 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
465
+ export const base64Charset = /^[0-9a-zA-Z+/]*={0,2}$/;
367
466
  export const $ZodBase64 = /*@__PURE__*/ core.$constructor("$ZodBase64", (inst, def) => {
368
- def.pattern ?? (def.pattern = regexes.base64);
467
+ def.pattern ?? (def.pattern = base64Charset);
369
468
  $ZodStringFormat.init(inst, def);
370
- inst._zod.bag.contentEncoding = "base64";
371
469
  inst._zod.check = (payload) => {
372
470
  if (isValidBase64(payload.value))
373
471
  return;
@@ -380,18 +478,19 @@ export const $ZodBase64 = /*@__PURE__*/ core.$constructor("$ZodBase64", (inst, d
380
478
  });
381
479
  };
382
480
  });
383
- ////////////////////////////// ZodBase64 //////////////////////////////
481
+ ////////////////////////////// ZodBase64URL //////////////////////////////
482
+ // lax on purpose: the quantified regexes.base64url overflows the regex stack on multi-MB input; isValidBase64 enforces length on the padded string
483
+ export const base64urlCharset = /^[A-Za-z0-9_-]*$/;
384
484
  export function isValidBase64URL(data) {
385
- if (!regexes.base64url.test(data))
485
+ if (!base64urlCharset.test(data))
386
486
  return false;
387
487
  const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
388
488
  const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
389
489
  return isValidBase64(padded);
390
490
  }
391
491
  export const $ZodBase64URL = /*@__PURE__*/ core.$constructor("$ZodBase64URL", (inst, def) => {
392
- def.pattern ?? (def.pattern = regexes.base64url);
492
+ def.pattern ?? (def.pattern = base64urlCharset);
393
493
  $ZodStringFormat.init(inst, def);
394
- inst._zod.bag.contentEncoding = "base64url";
395
494
  inst._zod.check = (payload) => {
396
495
  if (isValidBase64URL(payload.value))
397
496
  return;
@@ -408,6 +507,77 @@ export const $ZodE164 = /*@__PURE__*/ core.$constructor("$ZodE164", (inst, def)
408
507
  def.pattern ?? (def.pattern = regexes.e164);
409
508
  $ZodStringFormat.init(inst, def);
410
509
  });
510
+ ////////////////////////////// ZodCreditCard //////////////////////////////
511
+ const CC_SANITIZE = /[- ]/g;
512
+ /** Luhn checksum on a digit-only string. Adapted from valibot (MIT). */
513
+ function isLuhnAlgo(digits) {
514
+ let length = digits.length;
515
+ let bit = 1;
516
+ let sum = 0;
517
+ while (length) {
518
+ const value = digits.charCodeAt(--length) - 48;
519
+ bit ^= 1;
520
+ sum += bit ? [0, 2, 4, 6, 8, 1, 3, 5, 7, 9][value] : value;
521
+ }
522
+ return sum % 10 === 0;
523
+ }
524
+ export function isValidCreditCard(input) {
525
+ if (!regexes.creditCard.test(input))
526
+ return false;
527
+ return isLuhnAlgo(input.replace(CC_SANITIZE, ""));
528
+ }
529
+ export const $ZodCreditCard = /*@__PURE__*/ core.$constructor("$ZodCreditCard", (inst, def) => {
530
+ // 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.
531
+ def.pattern ?? (def.pattern = regexes.creditCard);
532
+ $ZodStringFormat.init(inst, def);
533
+ inst._zod.check = (payload) => {
534
+ if (isValidCreditCard(payload.value))
535
+ return;
536
+ payload.issues.push({
537
+ code: "invalid_format",
538
+ format: "credit_card",
539
+ input: payload.value,
540
+ inst,
541
+ continue: !def.abort,
542
+ });
543
+ };
544
+ });
545
+ ////////////////////////////// ZodIBAN //////////////////////////////
546
+ // iso 7064 mod 97-10 checksum without BigInt
547
+ function isIso7064Mod97(iban) {
548
+ let remainder = 0;
549
+ const len = iban.length;
550
+ for (let i = 4; i < len; i++) {
551
+ const code = iban.charCodeAt(i);
552
+ remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
553
+ }
554
+ for (let i = 0; i < 4; i++) {
555
+ const code = iban.charCodeAt(i);
556
+ remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
557
+ }
558
+ return remainder === 1;
559
+ }
560
+ export function isValidIBAN(input) {
561
+ if (!regexes.iban.test(input))
562
+ return false;
563
+ return isIso7064Mod97(input);
564
+ }
565
+ export const $ZodIBAN = /*@__PURE__*/ core.$constructor("$ZodIBAN", (inst, def) => {
566
+ // shape only — checksum is not expressible as a pattern
567
+ def.pattern ?? (def.pattern = regexes.iban);
568
+ $ZodStringFormat.init(inst, def);
569
+ inst._zod.check = (payload) => {
570
+ if (isValidIBAN(payload.value))
571
+ return;
572
+ payload.issues.push({
573
+ code: "invalid_format",
574
+ format: "iban",
575
+ input: payload.value,
576
+ inst,
577
+ continue: !def.abort,
578
+ });
579
+ };
580
+ });
411
581
  ////////////////////////////// ZodJWT //////////////////////////////
412
582
  export function isValidJWT(token, algorithm = null) {
413
583
  try {
@@ -461,7 +631,7 @@ export const $ZodCustomStringFormat = /*@__PURE__*/ core.$constructor("$ZodCusto
461
631
  });
462
632
  export const $ZodNumber = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, def) => {
463
633
  $ZodType.init(inst, def);
464
- inst._zod.pattern = inst._zod.bag.pattern ?? regexes.number;
634
+ inst._zod.pattern = regexes.number;
465
635
  inst._zod.parse = (payload, _ctx) => {
466
636
  if (def.coerce)
467
637
  try {
@@ -476,7 +646,7 @@ export const $ZodNumber = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, d
476
646
  ? Number.isNaN(input)
477
647
  ? "NaN"
478
648
  : !Number.isFinite(input)
479
- ? "Infinity"
649
+ ? String(input)
480
650
  : undefined
481
651
  : undefined;
482
652
  payload.issues.push({
@@ -557,8 +727,6 @@ export const $ZodUndefined = /*@__PURE__*/ core.$constructor("$ZodUndefined", (i
557
727
  $ZodType.init(inst, def);
558
728
  inst._zod.pattern = regexes.undefined;
559
729
  inst._zod.values = new Set([undefined]);
560
- inst._zod.optin = "optional";
561
- inst._zod.optout = "optional";
562
730
  inst._zod.parse = (payload, _ctx) => {
563
731
  const input = payload.value;
564
732
  if (typeof input === "undefined")
@@ -656,6 +824,8 @@ function handleArrayResult(result, final, index) {
656
824
  }
657
825
  export const $ZodArray = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def) => {
658
826
  $ZodType.init(inst, def);
827
+ const memo = core.globalConfig.memoizer;
828
+ memo?.attach(inst);
659
829
  inst._zod.parse = (payload, ctx) => {
660
830
  const input = payload.value;
661
831
  if (!Array.isArray(input)) {
@@ -667,8 +837,9 @@ export const $ZodArray = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def
667
837
  });
668
838
  return payload;
669
839
  }
670
- payload.value = Array(input.length);
840
+ payload.value = memo ? memo.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
671
841
  const proms = [];
842
+ const abortEarly = ctx?.abortEarly;
672
843
  for (let i = 0; i < input.length; i++) {
673
844
  const item = input[i];
674
845
  const result = def.element._zod.run({
@@ -680,6 +851,9 @@ export const $ZodArray = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def
680
851
  }
681
852
  else {
682
853
  handleArrayResult(result, payload, i);
854
+ // the element's payload is authoritative here, since handleArrayResult forwards every issue; an object's is not, because it drops a failed absent optional
855
+ if (abortEarly && result.issues.length !== 0 && util.aborted(result))
856
+ break;
683
857
  }
684
858
  }
685
859
  if (proms.length) {
@@ -688,16 +862,33 @@ export const $ZodArray = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def
688
862
  return payload; //handleArrayResultsAsync(parseResults, final);
689
863
  };
690
864
  });
691
- function handlePropertyResult(result, final, key, input, isOptionalOut) {
865
+ function handlePropertyResult(result, final, key, input, optin, optout) {
866
+ const isPresent = key in input;
867
+ const isOptionalOut = optout === "optional";
868
+ // 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.
869
+ if (!isPresent && isOptionalOut && optin === "optional") {
870
+ return;
871
+ }
692
872
  if (result.issues.length) {
693
- // For optional-out schemas, ignore errors on absent keys
694
- if (isOptionalOut && !(key in input)) {
873
+ // For optional-in/out schemas, ignore errors on absent keys.
874
+ if (optin !== undefined && isOptionalOut && !isPresent) {
695
875
  return;
696
876
  }
697
877
  final.issues.push(...util.prefixIssues(key, result.issues));
698
878
  }
879
+ if (!isPresent && optin === undefined) {
880
+ if (!result.issues.length) {
881
+ final.issues.push({
882
+ code: "invalid_type",
883
+ expected: "nonoptional",
884
+ input: undefined,
885
+ path: [key],
886
+ });
887
+ }
888
+ return;
889
+ }
699
890
  if (result.value === undefined) {
700
- if (key in input) {
891
+ if (isPresent || (optin === "defaulted" && !isOptionalOut)) {
701
892
  final.value[key] = undefined;
702
893
  }
703
894
  }
@@ -705,42 +896,64 @@ function handlePropertyResult(result, final, key, input, isOptionalOut) {
705
896
  final.value[key] = result.value;
706
897
  }
707
898
  }
899
+ // one shared instance; a fresh [] per schema cost 56 bytes retained
900
+ const NO_SYMBOL_KEYS = [];
708
901
  function normalizeDef(def) {
709
902
  const keys = Object.keys(def.shape);
710
- for (const k of keys) {
903
+ const ownSymbols = Object.getOwnPropertySymbols(def.shape);
904
+ const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
905
+ // aliases `keys` when there are no symbols, so a string-only shape keeps one array
906
+ const allKeys = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
907
+ for (const k of allKeys) {
711
908
  if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
712
- throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
909
+ throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
713
910
  }
714
911
  }
715
912
  const okeys = util.optionalKeys(def.shape);
716
913
  return {
717
914
  ...def,
718
- keys,
915
+ allKeys,
916
+ symbolKeys,
917
+ // string-only: handleCatchall matches it against `for...in`, which never yields a symbol
719
918
  keySet: new Set(keys),
720
919
  numKeys: keys.length,
721
920
  optionalKeys: new Set(okeys),
722
921
  };
723
922
  }
724
- function handleCatchall(proms, input, payload, ctx, def, inst) {
923
+ function handleCatchall(proms, input, payload, ctx, def, inst, abortEarly) {
725
924
  const unrecognized = [];
726
- // iterate over input keys
727
925
  const keySet = def.keySet;
728
926
  const _catchall = def.catchall._zod;
729
927
  const t = _catchall.def.type;
730
- const isOptionalOut = _catchall.optout === "optional";
928
+ const optin = _catchall.optin;
929
+ const optout = _catchall.optout;
930
+ // starts at 0, not the current length: the shape phase already ran and may have aborted
931
+ let seen = 0;
731
932
  for (const key in input) {
933
+ if (abortEarly && payload.issues.length !== seen) {
934
+ if (util.aborted(payload, seen))
935
+ break;
936
+ seen = payload.issues.length;
937
+ }
938
+ // Must precede the __proto__ branch: a declared key is not unrecognized, even though the shape loop deliberately strips __proto__ from the parsed output.
732
939
  if (keySet.has(key))
733
940
  continue;
941
+ // 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.
942
+ if (key === "__proto__") {
943
+ if (t === "never")
944
+ unrecognized.push(key);
945
+ continue;
946
+ }
734
947
  if (t === "never") {
735
948
  unrecognized.push(key);
736
949
  continue;
737
950
  }
738
951
  const r = _catchall.run({ value: input[key], issues: [] }, ctx);
739
952
  if (r instanceof Promise) {
740
- proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
953
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
741
954
  }
742
955
  else {
743
- handlePropertyResult(r, payload, key, input, isOptionalOut);
956
+ handlePropertyResult(r, payload, key, input, optin, optout);
744
957
  }
745
958
  }
746
959
  if (unrecognized.length) {
@@ -749,6 +962,8 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
749
962
  keys: unrecognized,
750
963
  input,
751
964
  inst,
965
+ // 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.
966
+ continue: true,
752
967
  });
753
968
  }
754
969
  if (!proms.length)
@@ -760,30 +975,35 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
760
975
  export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
761
976
  // requires cast because technically $ZodObject doesn't extend
762
977
  $ZodType.init(inst, def);
763
- // const sh = def.shape;
764
978
  const desc = Object.getOwnPropertyDescriptor(def, "shape");
765
- if (!desc?.get) {
766
- const sh = def.shape;
767
- Object.defineProperty(def, "shape", {
768
- get: () => {
769
- const newSh = { ...sh };
770
- Object.defineProperty(def, "shape", {
771
- value: newSh,
772
- });
773
- return newSh;
774
- },
775
- });
979
+ // 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
980
+ const sh = desc?.get ? desc.get.raw : (def.shape ?? {});
981
+ if (sh) {
982
+ // Freezes the shape on first read, so its getters resolve once and every later read sees the same schemas.
983
+ const get = () => {
984
+ const newSh = { ...sh };
985
+ Object.defineProperty(def, "shape", { value: newSh });
986
+ get.raw = newSh;
987
+ return newSh;
988
+ };
989
+ get.raw = sh;
990
+ Object.defineProperty(def, "shape", { get });
776
991
  }
777
992
  const _normalized = util.cached(() => normalizeDef(def));
778
- util.defineLazy(inst._zod, "propValues", () => {
779
- const shape = def.shape;
993
+ util.defineLazyInternal(inst, "propValues", (zod) => {
994
+ const shape = zod.def.shape;
780
995
  const propValues = {};
781
996
  for (const key in shape) {
782
997
  const field = shape[key]._zod;
783
998
  if (field.values) {
784
- propValues[key] ?? (propValues[key] = new Set());
999
+ if (!Object.prototype.hasOwnProperty.call(propValues, key)) {
1000
+ util.assignProp(propValues, key, new Set());
1001
+ }
785
1002
  for (const v of field.values)
786
1003
  propValues[key].add(v);
1004
+ // 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.
1005
+ if (field.optin !== undefined)
1006
+ propValues[key].add(undefined);
787
1007
  }
788
1008
  }
789
1009
  return propValues;
@@ -791,6 +1011,8 @@ export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, d
791
1011
  const isObject = util.isObject;
792
1012
  const catchall = def.catchall;
793
1013
  let value;
1014
+ const memo = core.globalConfig.memoizer;
1015
+ memo?.attach(inst);
794
1016
  inst._zod.parse = (payload, ctx) => {
795
1017
  value ?? (value = _normalized.value);
796
1018
  const input = payload.value;
@@ -803,24 +1025,34 @@ export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, d
803
1025
  });
804
1026
  return payload;
805
1027
  }
806
- payload.value = {};
1028
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
807
1029
  const proms = [];
808
1030
  const shape = value.shape;
809
- for (const key of value.keys) {
1031
+ const abortEarly = ctx?.abortEarly;
1032
+ let seen = payload.issues.length;
1033
+ for (const key of value.allKeys) {
1034
+ if (abortEarly && payload.issues.length !== seen) {
1035
+ if (util.aborted(payload, seen))
1036
+ break;
1037
+ seen = payload.issues.length;
1038
+ }
1039
+ if (key === "__proto__")
1040
+ continue;
810
1041
  const el = shape[key];
811
- const isOptionalOut = el._zod.optout === "optional";
1042
+ const optin = el._zod.optin;
1043
+ const optout = el._zod.optout;
812
1044
  const r = el._zod.run({ value: input[key], issues: [] }, ctx);
813
1045
  if (r instanceof Promise) {
814
- proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
1046
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
815
1047
  }
816
1048
  else {
817
- handlePropertyResult(r, payload, key, input, isOptionalOut);
1049
+ handlePropertyResult(r, payload, key, input, optin, optout);
818
1050
  }
819
1051
  }
820
1052
  if (!catchall) {
821
1053
  return proms.length ? Promise.all(proms).then(() => payload) : payload;
822
1054
  }
823
- return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
1055
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst, abortEarly === true);
824
1056
  };
825
1057
  });
826
1058
  export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (inst, def) => {
@@ -828,73 +1060,106 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
828
1060
  $ZodObject.init(inst, def);
829
1061
  const superParse = inst._zod.parse;
830
1062
  const _normalized = util.cached(() => normalizeDef(def));
1063
+ const memo = core.globalConfig.memoizer;
831
1064
  const generateFastpass = (shape) => {
832
- const doc = new Doc(["shape", "payload", "ctx"]);
833
1065
  const normalized = _normalized.value;
834
- const parseStr = (key) => {
835
- const k = util.esc(key);
836
- return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
837
- };
1066
+ const syms = normalized.symbolKeys;
1067
+ // a symbol has no source literal, so it is read as `syms[i]` off the closed-over scope
1068
+ const doc = new Doc(["payload", "ctx"], { shape, inst, memo, syms });
1069
+ const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1070
+ // 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
1071
+ const prefixStr = (id, k) => `
1072
+ let ${id}_ab = false;
1073
+ for (let i = 0; i < ${id}.issues.length; i++) {
1074
+ const iss = ${id}.issues[i];
1075
+ iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
1076
+ payload.issues.push(iss);
1077
+ if (iss.continue !== true) ${id}_ab = true;
1078
+ }
1079
+ if (${id}_ab && ctx && ctx.abortEarly) {
1080
+ payload.value = newResult;
1081
+ return payload;
1082
+ }`;
838
1083
  doc.write(`const input = payload.value;`);
839
1084
  const ids = Object.create(null);
840
1085
  let counter = 0;
841
- for (const key of normalized.keys) {
1086
+ for (const key of normalized.allKeys) {
842
1087
  ids[key] = `key_${counter++}`;
843
1088
  }
844
1089
  // A: preserve key order {
845
- doc.write(`const newResult = {};`);
846
- for (const key of normalized.keys) {
1090
+ doc.write(memo ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
1091
+ for (const key of normalized.allKeys) {
1092
+ if (key === "__proto__")
1093
+ continue;
847
1094
  const id = ids[key];
848
- const k = util.esc(key);
1095
+ const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : util.esc(key);
1096
+ const isPresent = `${k} in input`;
849
1097
  const schema = shape[key];
1098
+ const optin = schema?._zod?.optin;
1099
+ const isOptionalIn = optin !== undefined;
850
1100
  const isOptionalOut = schema?._zod?.optout === "optional";
851
- doc.write(`const ${id} = ${parseStr(key)};`);
852
- if (isOptionalOut) {
853
- // For optional-out schemas, ignore errors on absent keys
1101
+ doc.write(`const ${id} = ${parseStr(k)};`);
1102
+ if (isOptionalIn && isOptionalOut) {
1103
+ // 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.
1104
+ const assign = optin === "optional" ? `${id}_present` : `${id}.value !== undefined || ${id}_present`;
854
1105
  doc.write(`
855
- if (${id}.issues.length) {
856
- if (${k} in input) {
857
- payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
858
- ...iss,
859
- path: iss.path ? [${k}, ...iss.path] : [${k}]
860
- })));
1106
+ const ${id}_present = ${isPresent};
1107
+ if (!${id}.issues.length || ${id}_present) {
1108
+ if (${id}.issues.length) {${prefixStr(id, k)}
1109
+ }
1110
+
1111
+ if (${assign}) {
1112
+ newResult[${k}] = ${id}.value;
861
1113
  }
862
1114
  }
863
-
864
- if (${id}.value === undefined) {
865
- if (${k} in input) {
866
- newResult[${k}] = undefined;
1115
+
1116
+ `);
1117
+ }
1118
+ else if (!isOptionalIn) {
1119
+ doc.write(`
1120
+ const ${id}_present = ${isPresent};
1121
+ if (${id}.issues.length) {${prefixStr(id, k)}
1122
+ }
1123
+ if (!${id}_present && !${id}.issues.length) {
1124
+ payload.issues.push({
1125
+ code: "invalid_type",
1126
+ expected: "nonoptional",
1127
+ input: undefined,
1128
+ path: [${k}]
1129
+ });
1130
+ if (ctx && ctx.abortEarly) {
1131
+ payload.value = newResult;
1132
+ return payload;
867
1133
  }
868
- } else {
1134
+ }
1135
+
1136
+ if (${id}_present) {
869
1137
  newResult[${k}] = ${id}.value;
870
1138
  }
871
-
1139
+
872
1140
  `);
873
1141
  }
874
1142
  else {
875
1143
  doc.write(`
876
- if (${id}.issues.length) {
877
- payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
878
- ...iss,
879
- path: iss.path ? [${k}, ...iss.path] : [${k}]
880
- })));
881
- }
882
-
883
- if (${id}.value === undefined) {
884
- if (${k} in input) {
885
- newResult[${k}] = undefined;
886
- }
887
- } else {
1144
+ if (${id}.issues.length) {${prefixStr(id, k)}
1145
+ }
1146
+ `);
1147
+ if (optin === "defaulted") {
1148
+ doc.write(`newResult[${k}] = ${id}.value;`);
1149
+ }
1150
+ else {
1151
+ doc.write(`
1152
+ if (${id}.value !== undefined || ${isPresent}) {
888
1153
  newResult[${k}] = ${id}.value;
889
1154
  }
890
-
891
1155
  `);
1156
+ }
892
1157
  }
893
1158
  }
894
1159
  doc.write(`payload.value = newResult;`);
895
1160
  doc.write(`return payload;`);
896
- const fn = doc.compile();
897
- return (payload, ctx) => fn(shape, payload, ctx);
1161
+ // 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
1162
+ return doc.compile();
898
1163
  };
899
1164
  let fastpass;
900
1165
  const isObject = util.isObject;
@@ -922,7 +1187,7 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
922
1187
  payload = fastpass(payload, ctx);
923
1188
  if (!catchall)
924
1189
  return payload;
925
- return handleCatchall([], input, payload, ctx, value, inst);
1190
+ return handleCatchall([], input, payload, ctx, value, inst, ctx?.abortEarly === true);
926
1191
  }
927
1192
  return superParse(payload, ctx);
928
1193
  };
@@ -949,25 +1214,28 @@ function handleUnionResults(results, final, inst, ctx) {
949
1214
  }
950
1215
  export const $ZodUnion = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def) => {
951
1216
  $ZodType.init(inst, def);
952
- util.defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined);
953
- util.defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
954
- util.defineLazy(inst._zod, "values", () => {
955
- if (def.options.every((o) => o._zod.values)) {
956
- return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1217
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.options.some((o) => o._zod.optin === "defaulted")
1218
+ ? "defaulted"
1219
+ : zod.def.options.some((o) => o._zod.optin !== undefined)
1220
+ ? "optional"
1221
+ : undefined);
1222
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
1223
+ util.defineLazyInternal(inst, "values", (zod) => {
1224
+ if (zod.def.options.every((o) => o._zod.values)) {
1225
+ return new Set(zod.def.options.flatMap((option) => Array.from(option._zod.values)));
957
1226
  }
958
1227
  return undefined;
959
1228
  });
960
- util.defineLazy(inst._zod, "pattern", () => {
961
- if (def.options.every((o) => o._zod.pattern)) {
962
- const patterns = def.options.map((o) => o._zod.pattern);
1229
+ util.defineLazyInternal(inst, "pattern", (zod) => {
1230
+ if (zod.def.options.every((o) => o._zod.pattern)) {
1231
+ const patterns = zod.def.options.map((o) => o._zod.pattern);
963
1232
  return new RegExp(`^(${patterns.map((p) => util.cleanRegex(p.source)).join("|")})$`);
964
1233
  }
965
1234
  return undefined;
966
1235
  });
967
- const single = def.options.length === 1;
968
- const first = def.options[0]._zod.run;
1236
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
969
1237
  inst._zod.parse = (payload, ctx) => {
970
- if (single) {
1238
+ if (first) {
971
1239
  return first(payload, ctx);
972
1240
  }
973
1241
  let async = false;
@@ -995,12 +1263,16 @@ export const $ZodUnion = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def
995
1263
  };
996
1264
  });
997
1265
  function handleExclusiveUnionResults(results, final, inst, ctx) {
998
- const successes = results.filter((r) => r.issues.length === 0);
999
- if (successes.length === 1) {
1000
- final.value = successes[0].value;
1266
+ const matches = [];
1267
+ for (let i = 0; i < results.length; i++) {
1268
+ if (results[i].issues.length === 0)
1269
+ matches.push(i);
1270
+ }
1271
+ if (matches.length === 1) {
1272
+ final.value = results[matches[0]].value;
1001
1273
  return final;
1002
1274
  }
1003
- if (successes.length === 0) {
1275
+ if (matches.length === 0) {
1004
1276
  // No matches - same as regular union
1005
1277
  final.issues.push({
1006
1278
  code: "invalid_union",
@@ -1017,6 +1289,7 @@ function handleExclusiveUnionResults(results, final, inst, ctx) {
1017
1289
  inst,
1018
1290
  errors: [],
1019
1291
  inclusive: false,
1292
+ matches,
1020
1293
  });
1021
1294
  }
1022
1295
  return final;
@@ -1024,10 +1297,9 @@ function handleExclusiveUnionResults(results, final, inst, ctx) {
1024
1297
  export const $ZodXor = /*@__PURE__*/ core.$constructor("$ZodXor", (inst, def) => {
1025
1298
  $ZodUnion.init(inst, def);
1026
1299
  def.inclusive = false;
1027
- const single = def.options.length === 1;
1028
- const first = def.options[0]._zod.run;
1300
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
1029
1301
  inst._zod.parse = (payload, ctx) => {
1030
- if (single) {
1302
+ if (first) {
1031
1303
  return first(payload, ctx);
1032
1304
  }
1033
1305
  let async = false;
@@ -1052,44 +1324,75 @@ export const $ZodXor = /*@__PURE__*/ core.$constructor("$ZodXor", (inst, def) =>
1052
1324
  });
1053
1325
  };
1054
1326
  });
1327
+ /** Returns the option whose discriminator claims `value`, or throws if ambiguous. */
1328
+ export function getDiscriminatedOption(union, value) {
1329
+ const internals = union._zod;
1330
+ let map = internals.bag.optionsMap;
1331
+ if (!map) {
1332
+ map = discriminatorMap(internals.def);
1333
+ internals.bag.optionsMap = map;
1334
+ }
1335
+ const option = map.get(value);
1336
+ if (option === null)
1337
+ throw new Error(`Ambiguous discriminator value "${String(value)}"`);
1338
+ return option;
1339
+ }
1340
+ function discriminatorMap(def) {
1341
+ const map = new Map();
1342
+ for (const option of def.options) {
1343
+ const values = option._zod.propValues?.[def.discriminator];
1344
+ if (!values || values.size === 0)
1345
+ throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
1346
+ for (const value of values) {
1347
+ if (map.has(value)) {
1348
+ if (value !== undefined)
1349
+ throw new Error(`Duplicate discriminator value "${String(value)}"`);
1350
+ // keep the collision marked so a later member cannot reclaim it
1351
+ map.set(value, null);
1352
+ }
1353
+ else {
1354
+ map.set(value, option);
1355
+ }
1356
+ }
1357
+ }
1358
+ return map;
1359
+ }
1055
1360
  export const $ZodDiscriminatedUnion =
1056
1361
  /*@__PURE__*/
1057
1362
  core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1058
1363
  def.inclusive = false;
1059
1364
  $ZodUnion.init(inst, def);
1060
1365
  const _super = inst._zod.parse;
1061
- util.defineLazy(inst._zod, "propValues", () => {
1366
+ util.defineLazyInternal(inst, "propValues", (zod) => {
1062
1367
  const propValues = {};
1063
- for (const option of def.options) {
1368
+ let undefinedCount = 0;
1369
+ for (const option of zod.def.options) {
1064
1370
  const pv = option._zod.propValues;
1065
1371
  if (!pv || Object.keys(pv).length === 0)
1066
- throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
1372
+ throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
1373
+ if (pv[zod.def.discriminator]?.has(undefined))
1374
+ undefinedCount++;
1067
1375
  for (const [k, v] of Object.entries(pv)) {
1068
- if (!propValues[k])
1069
- propValues[k] = new Set();
1376
+ if (!Object.prototype.hasOwnProperty.call(propValues, k)) {
1377
+ util.assignProp(propValues, k, new Set());
1378
+ }
1070
1379
  for (const val of v) {
1071
1380
  propValues[k].add(val);
1072
1381
  }
1073
1382
  }
1074
1383
  }
1384
+ if (!zod.def.unionFallback && undefinedCount > 1)
1385
+ propValues[zod.def.discriminator]?.delete(undefined);
1075
1386
  return propValues;
1076
1387
  });
1077
- const disc = util.cached(() => {
1078
- const opts = def.options;
1079
- const map = new Map();
1080
- for (const o of opts) {
1081
- const values = o._zod.propValues?.[def.discriminator];
1082
- if (!values || values.size === 0)
1083
- throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
1084
- for (const v of values) {
1085
- if (map.has(v)) {
1086
- throw new Error(`Duplicate discriminator value "${String(v)}"`);
1087
- }
1088
- map.set(v, o);
1089
- }
1388
+ // 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.
1389
+ def.options.forEach((option, i) => {
1390
+ const propShape = util.rawShape(option._zod.def);
1391
+ if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) {
1392
+ throw new Error(`Invalid discriminated union option at index "${i}"`);
1090
1393
  }
1091
- return map;
1092
1394
  });
1395
+ const disc = util.cached(() => discriminatorMap(def));
1093
1396
  inst._zod.parse = (payload, ctx) => {
1094
1397
  const input = payload.value;
1095
1398
  if (!util.isObject(input)) {
@@ -1101,11 +1404,16 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1101
1404
  });
1102
1405
  return payload;
1103
1406
  }
1104
- const opt = disc.value.get(input?.[def.discriminator]);
1105
- if (opt) {
1407
+ const value = input?.[def.discriminator];
1408
+ const opt = disc.value.get(value);
1409
+ // forward metadata cannot choose an encoder for an absent tag
1410
+ if (opt && (value !== undefined || ctx.direction !== "backward")) {
1106
1411
  return opt._zod.run(payload, ctx);
1107
1412
  }
1108
- if (def.unionFallback) {
1413
+ // Fall back to union matching when the fast discriminator path fails:
1414
+ // - explicitly enabled via unionFallback, or
1415
+ // - during backward direction (encode), since codec-based discriminators have different values in forward vs backward directions
1416
+ if (def.unionFallback || ctx.direction === "backward") {
1109
1417
  return _super(payload, ctx);
1110
1418
  }
1111
1419
  // no matching discriminator
@@ -1114,6 +1422,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1114
1422
  errors: [],
1115
1423
  note: "No matching discriminator",
1116
1424
  discriminator: def.discriminator,
1425
+ options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
1117
1426
  input,
1118
1427
  path: [def.discriminator],
1119
1428
  inst,
@@ -1136,7 +1445,7 @@ export const $ZodIntersection = /*@__PURE__*/ core.$constructor("$ZodIntersectio
1136
1445
  return handleIntersectionResults(payload, left, right);
1137
1446
  };
1138
1447
  });
1139
- function mergeValues(a, b) {
1448
+ export function mergeValues(a, b) {
1140
1449
  // const aType = parse.t(a);
1141
1450
  // const bType = parse.t(b);
1142
1451
  if (a === b) {
@@ -1149,7 +1458,11 @@ function mergeValues(a, b) {
1149
1458
  const bKeys = Object.keys(b);
1150
1459
  const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1151
1460
  const newObj = { ...a, ...b };
1461
+ if (Object.prototype.hasOwnProperty.call(newObj, "__proto__"))
1462
+ delete newObj.__proto__;
1152
1463
  for (const key of sharedKeys) {
1464
+ if (key === "__proto__")
1465
+ continue;
1153
1466
  const sharedValue = mergeValues(a[key], b[key]);
1154
1467
  if (!sharedValue.valid) {
1155
1468
  return {
@@ -1183,43 +1496,55 @@ function mergeValues(a, b) {
1183
1496
  return { valid: false, mergeErrorPath: [] };
1184
1497
  }
1185
1498
  function handleIntersectionResults(result, left, right) {
1186
- // Track which side(s) report each key as unrecognized
1499
+ // 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.
1187
1500
  const unrecKeys = new Map();
1188
1501
  let unrecIssue;
1189
- for (const iss of left.issues) {
1190
- if (iss.code === "unrecognized_keys") {
1502
+ const keyIssues = new Map();
1503
+ const collect = (iss, side) => {
1504
+ let keys;
1505
+ if (iss.code === "unrecognized_keys" && !iss.path?.length) {
1191
1506
  unrecIssue ?? (unrecIssue = iss);
1192
- for (const k of iss.keys) {
1193
- if (!unrecKeys.has(k))
1194
- unrecKeys.set(k, {});
1195
- unrecKeys.get(k).l = true;
1196
- }
1507
+ keys = iss.keys;
1508
+ }
1509
+ else if (iss.code === "invalid_key" && iss.origin === "record" && iss.path?.length === 1) {
1510
+ const k = String(iss.path[0]);
1511
+ if (!keyIssues.has(k))
1512
+ keyIssues.set(k, iss);
1513
+ keys = [k];
1197
1514
  }
1198
1515
  else {
1199
- result.issues.push(iss);
1516
+ return false;
1200
1517
  }
1518
+ for (const k of keys) {
1519
+ if (!unrecKeys.has(k))
1520
+ unrecKeys.set(k, {});
1521
+ unrecKeys.get(k)[side] = true;
1522
+ }
1523
+ return true;
1524
+ };
1525
+ for (const iss of left.issues) {
1526
+ if (!collect(iss, "l"))
1527
+ result.issues.push(iss);
1201
1528
  }
1202
1529
  for (const iss of right.issues) {
1203
- if (iss.code === "unrecognized_keys") {
1204
- for (const k of iss.keys) {
1205
- if (!unrecKeys.has(k))
1206
- unrecKeys.set(k, {});
1207
- unrecKeys.get(k).r = true;
1208
- }
1209
- }
1210
- else {
1530
+ if (!collect(iss, "r"))
1211
1531
  result.issues.push(iss);
1212
- }
1213
1532
  }
1214
- // Report only keys unrecognized by BOTH sides
1533
+ // Report only keys rejected by BOTH sides
1215
1534
  const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
1216
- if (bothKeys.length && unrecIssue) {
1217
- result.issues.push({ ...unrecIssue, keys: bothKeys });
1535
+ if (bothKeys.length) {
1536
+ const aggregated = unrecIssue ? bothKeys.filter((k) => unrecIssue.keys.includes(k)) : [];
1537
+ if (aggregated.length)
1538
+ result.issues.push({ ...unrecIssue, keys: aggregated });
1539
+ for (const k of bothKeys) {
1540
+ if (!aggregated.includes(k) && keyIssues.has(k))
1541
+ result.issues.push(keyIssues.get(k));
1542
+ }
1218
1543
  }
1219
- if (util.aborted(result))
1220
- return result;
1221
1544
  const merged = mergeValues(left.value, right.value);
1222
1545
  if (!merged.valid) {
1546
+ if (util.aborted(result))
1547
+ return result;
1223
1548
  throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
1224
1549
  }
1225
1550
  result.value = merged.data;
@@ -1228,6 +1553,8 @@ function handleIntersectionResults(result, left, right) {
1228
1553
  export const $ZodTuple = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def) => {
1229
1554
  $ZodType.init(inst, def);
1230
1555
  const items = def.items;
1556
+ const memo = core.globalConfig.memoizer;
1557
+ memo?.attach(inst);
1231
1558
  inst._zod.parse = (payload, ctx) => {
1232
1559
  const input = payload.value;
1233
1560
  if (!Array.isArray(input)) {
@@ -1239,71 +1566,132 @@ export const $ZodTuple = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def
1239
1566
  });
1240
1567
  return payload;
1241
1568
  }
1242
- payload.value = [];
1569
+ payload.value = memo ? memo.alloc(inst, payload, [], ctx) : [];
1243
1570
  const proms = [];
1244
- const reversedIndex = [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
1245
- const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;
1571
+ const optinStart = getTupleOptStart(items, "optin");
1572
+ const optoutStart = getTupleOptStart(items, "optout");
1246
1573
  if (!def.rest) {
1247
- const tooBig = input.length > items.length;
1248
- const tooSmall = input.length < optStart - 1;
1249
- if (tooBig || tooSmall) {
1574
+ if (input.length < optinStart) {
1250
1575
  payload.issues.push({
1251
- ...(tooBig
1252
- ? { code: "too_big", maximum: items.length, inclusive: true }
1253
- : { code: "too_small", minimum: items.length }),
1576
+ code: "too_small",
1577
+ minimum: optinStart,
1578
+ inclusive: true,
1254
1579
  input,
1255
1580
  inst,
1256
1581
  origin: "array",
1257
1582
  });
1258
1583
  return payload;
1259
1584
  }
1585
+ if (input.length > items.length) {
1586
+ payload.issues.push({
1587
+ code: "too_big",
1588
+ maximum: items.length,
1589
+ inclusive: true,
1590
+ input,
1591
+ inst,
1592
+ origin: "array",
1593
+ });
1594
+ }
1260
1595
  }
1261
- let i = -1;
1262
- for (const item of items) {
1263
- i++;
1264
- if (i >= input.length)
1265
- if (i >= optStart)
1266
- continue;
1267
- const result = item._zod.run({
1268
- value: input[i],
1269
- issues: [],
1270
- }, ctx);
1271
- if (result instanceof Promise) {
1272
- proms.push(result.then((result) => handleTupleResult(result, payload, i)));
1596
+ // 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.
1597
+ const itemResults = new Array(items.length);
1598
+ // only tracked when there is a rest loop to skip
1599
+ const abortEarly = def.rest ? ctx?.abortEarly : undefined;
1600
+ let itemAborted = false;
1601
+ for (let i = 0; i < items.length; i++) {
1602
+ const r = items[i]._zod.run({ value: input[i], issues: [] }, ctx);
1603
+ if (r instanceof Promise) {
1604
+ proms.push(r.then((rr) => {
1605
+ itemResults[i] = rr;
1606
+ }));
1273
1607
  }
1274
1608
  else {
1275
- handleTupleResult(result, payload, i);
1609
+ itemResults[i] = r;
1610
+ if (abortEarly && !itemAborted && r.issues.length)
1611
+ itemAborted = util.aborted(r);
1276
1612
  }
1277
1613
  }
1278
- if (def.rest) {
1614
+ // sound because rest is non-empty exactly when every fixed index is present, the one case handleTupleResults cannot discard an item's issues
1615
+ if (def.rest && !itemAborted) {
1616
+ let i = items.length - 1;
1279
1617
  const rest = input.slice(items.length);
1618
+ let seen = payload.issues.length;
1280
1619
  for (const el of rest) {
1620
+ if (abortEarly && payload.issues.length !== seen) {
1621
+ if (util.aborted(payload, seen))
1622
+ break;
1623
+ seen = payload.issues.length;
1624
+ }
1281
1625
  i++;
1282
- const result = def.rest._zod.run({
1283
- value: el,
1284
- issues: [],
1285
- }, ctx);
1626
+ const result = def.rest._zod.run({ value: el, issues: [] }, ctx);
1286
1627
  if (result instanceof Promise) {
1287
- proms.push(result.then((result) => handleTupleResult(result, payload, i)));
1628
+ proms.push(result.then((r) => handleTupleResult(r, payload, i)));
1288
1629
  }
1289
1630
  else {
1290
1631
  handleTupleResult(result, payload, i);
1291
1632
  }
1292
1633
  }
1293
1634
  }
1294
- if (proms.length)
1295
- return Promise.all(proms).then(() => payload);
1296
- return payload;
1635
+ if (proms.length) {
1636
+ return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items, input, optoutStart));
1637
+ }
1638
+ return handleTupleResults(itemResults, payload, items, input, optoutStart);
1297
1639
  };
1298
1640
  });
1641
+ function getTupleOptStart(items, key) {
1642
+ for (let i = items.length - 1; i >= 0; i--) {
1643
+ // optin is a three-rung ladder so any rung above `undefined` permits an absent slot; optout stays two-valued.
1644
+ const omittable = key === "optin" ? items[i]._zod.optin !== undefined : items[i]._zod.optout === "optional";
1645
+ if (!omittable)
1646
+ return i + 1;
1647
+ }
1648
+ return 0;
1649
+ }
1299
1650
  function handleTupleResult(result, final, index) {
1300
1651
  if (result.issues.length) {
1301
1652
  final.issues.push(...util.prefixIssues(index, result.issues));
1302
1653
  }
1303
1654
  final.value[index] = result.value;
1304
1655
  }
1656
+ function handleTupleResults(itemResults, final, items, input, optoutStart) {
1657
+ // 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.
1658
+ for (let i = 0; i < items.length; i++) {
1659
+ const r = itemResults[i];
1660
+ const isPresent = i < input.length;
1661
+ // 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`.
1662
+ if (!isPresent && i >= optoutStart && items[i]._zod.optin === "optional") {
1663
+ final.value.length = i;
1664
+ break;
1665
+ }
1666
+ if (r.issues.length) {
1667
+ if (!isPresent && i >= optoutStart) {
1668
+ final.value.length = i;
1669
+ break;
1670
+ }
1671
+ final.issues.push(...util.prefixIssues(i, r.issues));
1672
+ }
1673
+ final.value[i] = r.value;
1674
+ }
1675
+ // Drop trailing slots that produced `undefined` for absent input
1676
+ // (the array analog of an absent optional key on an object). The
1677
+ // `i >= input.length` floor is critical: an explicit `undefined`
1678
+ // *inside* the input must be preserved even when the schema is
1679
+ // optional-out (e.g. `z.string().or(z.undefined())` accepting an
1680
+ // explicit undefined value).
1681
+ for (let i = final.value.length - 1; i >= input.length; i--) {
1682
+ if (items[i]._zod.optout === "optional" && final.value[i] === undefined) {
1683
+ final.value.length = i;
1684
+ }
1685
+ else {
1686
+ break;
1687
+ }
1688
+ }
1689
+ return final;
1690
+ }
1305
1691
  export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, def) => {
1306
1692
  $ZodType.init(inst, def);
1693
+ const memo = core.globalConfig.memoizer;
1694
+ memo?.attach(inst);
1307
1695
  inst._zod.parse = (payload, ctx) => {
1308
1696
  const input = payload.value;
1309
1697
  if (!util.isPlainObject(input)) {
@@ -1315,36 +1703,66 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
1315
1703
  });
1316
1704
  return payload;
1317
1705
  }
1706
+ // 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
1318
1707
  const proms = [];
1319
1708
  const values = def.keyType._zod.values;
1320
- if (values) {
1321
- payload.value = {};
1709
+ if (values && !def.partial) {
1710
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
1322
1711
  const recordKeys = new Set();
1323
1712
  for (const key of values) {
1324
1713
  if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1325
1714
  recordKeys.add(typeof key === "number" ? key.toString() : key);
1715
+ // A declared __proto__ is stripped but is not an unrecognized key.
1716
+ if (key === "__proto__")
1717
+ continue;
1718
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1719
+ if (keyResult instanceof Promise) {
1720
+ throw new Error("Async schemas not supported in object keys currently");
1721
+ }
1722
+ if (keyResult.issues.length) {
1723
+ payload.issues.push({
1724
+ code: "invalid_key",
1725
+ origin: "record",
1726
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1727
+ input: key,
1728
+ path: [key],
1729
+ inst,
1730
+ });
1731
+ continue;
1732
+ }
1733
+ const outKey = keyResult.value;
1734
+ if (outKey === "__proto__")
1735
+ continue;
1326
1736
  const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1327
1737
  if (result instanceof Promise) {
1328
1738
  proms.push(result.then((result) => {
1329
1739
  if (result.issues.length) {
1330
1740
  payload.issues.push(...util.prefixIssues(key, result.issues));
1331
1741
  }
1332
- payload.value[key] = result.value;
1742
+ payload.value[outKey] = result.value;
1333
1743
  }));
1334
1744
  }
1335
1745
  else {
1336
1746
  if (result.issues.length) {
1337
1747
  payload.issues.push(...util.prefixIssues(key, result.issues));
1338
1748
  }
1339
- payload.value[key] = result.value;
1749
+ payload.value[outKey] = result.value;
1340
1750
  }
1341
1751
  }
1342
1752
  }
1343
1753
  let unrecognized;
1344
1754
  for (const key in input) {
1345
1755
  if (!recordKeys.has(key)) {
1346
- unrecognized = unrecognized ?? [];
1347
- unrecognized.push(key);
1756
+ if (def.mode === "loose") {
1757
+ // skip __proto__ so it can't replace the result prototype via the assignment setter on the plain {} we build into
1758
+ if (key === "__proto__")
1759
+ continue;
1760
+ payload.value[key] = input[key];
1761
+ }
1762
+ else {
1763
+ unrecognized = unrecognized ?? [];
1764
+ unrecognized.push(key);
1765
+ }
1348
1766
  }
1349
1767
  }
1350
1768
  if (unrecognized && unrecognized.length > 0) {
@@ -1353,20 +1771,25 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
1353
1771
  input,
1354
1772
  inst,
1355
1773
  keys: unrecognized,
1774
+ continue: true,
1356
1775
  });
1357
1776
  }
1358
1777
  }
1359
1778
  else {
1360
- payload.value = {};
1779
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
1780
+ // 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.
1781
+ let unrecognized;
1782
+ // Reflect.ownKeys for Symbol-key support; filter non-enumerable to match z.object()
1361
1783
  for (const key of Reflect.ownKeys(input)) {
1362
1784
  if (key === "__proto__")
1363
1785
  continue;
1786
+ if (!Object.prototype.propertyIsEnumerable.call(input, key))
1787
+ continue;
1364
1788
  let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1365
1789
  if (keyResult instanceof Promise) {
1366
1790
  throw new Error("Async schemas not supported in object keys currently");
1367
1791
  }
1368
- // Numeric string fallback: if key is a numeric string and failed, retry with Number(key)
1369
- // This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
1792
+ // 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
1370
1793
  const checkNumericKey = typeof key === "string" && regexes.number.test(key) && keyResult.issues.length;
1371
1794
  if (checkNumericKey) {
1372
1795
  const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
@@ -1382,6 +1805,10 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
1382
1805
  // Pass through unchanged
1383
1806
  payload.value[key] = input[key];
1384
1807
  }
1808
+ else if (values) {
1809
+ unrecognized = unrecognized ?? [];
1810
+ unrecognized.push(key);
1811
+ }
1385
1812
  else {
1386
1813
  // Default "strict" behavior: error on invalid key
1387
1814
  payload.issues.push({
@@ -1395,22 +1822,35 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
1395
1822
  }
1396
1823
  continue;
1397
1824
  }
1825
+ // 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
1826
+ const outKey = keyResult.value;
1827
+ if (outKey === "__proto__")
1828
+ continue;
1398
1829
  const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1399
1830
  if (result instanceof Promise) {
1400
1831
  proms.push(result.then((result) => {
1401
1832
  if (result.issues.length) {
1402
1833
  payload.issues.push(...util.prefixIssues(key, result.issues));
1403
1834
  }
1404
- payload.value[keyResult.value] = result.value;
1835
+ payload.value[outKey] = result.value;
1405
1836
  }));
1406
1837
  }
1407
1838
  else {
1408
1839
  if (result.issues.length) {
1409
1840
  payload.issues.push(...util.prefixIssues(key, result.issues));
1410
1841
  }
1411
- payload.value[keyResult.value] = result.value;
1842
+ payload.value[outKey] = result.value;
1412
1843
  }
1413
1844
  }
1845
+ if (unrecognized && unrecognized.length > 0) {
1846
+ payload.issues.push({
1847
+ code: "unrecognized_keys",
1848
+ input,
1849
+ inst,
1850
+ keys: unrecognized,
1851
+ continue: true,
1852
+ });
1853
+ }
1414
1854
  }
1415
1855
  if (proms.length) {
1416
1856
  return Promise.all(proms).then(() => payload);
@@ -1420,6 +1860,8 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
1420
1860
  });
1421
1861
  export const $ZodMap = /*@__PURE__*/ core.$constructor("$ZodMap", (inst, def) => {
1422
1862
  $ZodType.init(inst, def);
1863
+ const memo = core.globalConfig.memoizer;
1864
+ memo?.attach(inst);
1423
1865
  inst._zod.parse = (payload, ctx) => {
1424
1866
  const input = payload.value;
1425
1867
  if (!(input instanceof Map)) {
@@ -1432,8 +1874,15 @@ export const $ZodMap = /*@__PURE__*/ core.$constructor("$ZodMap", (inst, def) =>
1432
1874
  return payload;
1433
1875
  }
1434
1876
  const proms = [];
1435
- payload.value = new Map();
1877
+ payload.value = memo ? memo.alloc(inst, payload, new Map(), ctx) : new Map();
1878
+ const abortEarly = ctx?.abortEarly;
1879
+ let seen = payload.issues.length;
1436
1880
  for (const [key, value] of input) {
1881
+ if (abortEarly && payload.issues.length !== seen) {
1882
+ if (util.aborted(payload, seen))
1883
+ break;
1884
+ seen = payload.issues.length;
1885
+ }
1437
1886
  const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1438
1887
  const valueResult = def.valueType._zod.run({ value: value, issues: [] }, ctx);
1439
1888
  if (keyResult instanceof Promise || valueResult instanceof Promise) {
@@ -1484,6 +1933,8 @@ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1484
1933
  }
1485
1934
  export const $ZodSet = /*@__PURE__*/ core.$constructor("$ZodSet", (inst, def) => {
1486
1935
  $ZodType.init(inst, def);
1936
+ const memo = core.globalConfig.memoizer;
1937
+ memo?.attach(inst);
1487
1938
  inst._zod.parse = (payload, ctx) => {
1488
1939
  const input = payload.value;
1489
1940
  if (!(input instanceof Set)) {
@@ -1496,8 +1947,15 @@ export const $ZodSet = /*@__PURE__*/ core.$constructor("$ZodSet", (inst, def) =>
1496
1947
  return payload;
1497
1948
  }
1498
1949
  const proms = [];
1499
- payload.value = new Set();
1950
+ payload.value = memo ? memo.alloc(inst, payload, new Set(), ctx) : new Set();
1951
+ const abortEarly = ctx?.abortEarly;
1952
+ let seen = payload.issues.length;
1500
1953
  for (const item of input) {
1954
+ if (abortEarly && payload.issues.length !== seen) {
1955
+ if (util.aborted(payload, seen))
1956
+ break;
1957
+ seen = payload.issues.length;
1958
+ }
1501
1959
  const result = def.valueType._zod.run({ value: item, issues: [] }, ctx);
1502
1960
  if (result instanceof Promise) {
1503
1961
  proms.push(result.then((result) => handleSetResult(result, payload)));
@@ -1521,10 +1979,11 @@ export const $ZodEnum = /*@__PURE__*/ core.$constructor("$ZodEnum", (inst, def)
1521
1979
  const values = util.getEnumValues(def.entries);
1522
1980
  const valuesSet = new Set(values);
1523
1981
  inst._zod.values = valuesSet;
1524
- inst._zod.pattern = new RegExp(`^(${values
1525
- .filter((k) => util.propertyKeyTypes.has(typeof k))
1526
- .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o.toString()))
1527
- .join("|")})$`);
1982
+ util.defineLazyInternal(inst, "pattern", (zod) => {
1983
+ const patternValues = util.getEnumValues(zod.def.entries).filter((k) => util.propertyKeyTypes.has(typeof k));
1984
+ // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
1985
+ return new RegExp(patternValues.length ? `^(${patternValues.map((o) => util.escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$");
1986
+ });
1528
1987
  inst._zod.parse = (payload, _ctx) => {
1529
1988
  const input = payload.value;
1530
1989
  if (valuesSet.has(input)) {
@@ -1541,14 +2000,17 @@ export const $ZodEnum = /*@__PURE__*/ core.$constructor("$ZodEnum", (inst, def)
1541
2000
  });
1542
2001
  export const $ZodLiteral = /*@__PURE__*/ core.$constructor("$ZodLiteral", (inst, def) => {
1543
2002
  $ZodType.init(inst, def);
1544
- if (def.values.length === 0) {
1545
- throw new Error("Cannot create literal schema with no valid values");
1546
- }
1547
2003
  const values = new Set(def.values);
1548
2004
  inst._zod.values = values;
1549
- inst._zod.pattern = new RegExp(`^(${def.values
1550
- .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
1551
- .join("|")})$`);
2005
+ util.defineLazyInternal(inst, "pattern", (zod) => {
2006
+ const vals = zod.def.values;
2007
+ // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
2008
+ return new RegExp(vals.length
2009
+ ? `^(${vals
2010
+ .map((o) => typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o))
2011
+ .join("|")})$`
2012
+ : "^[^\\s\\S]$");
2013
+ });
1552
2014
  inst._zod.parse = (payload, _ctx) => {
1553
2015
  const input = payload.value;
1554
2016
  if (values.has(input)) {
@@ -1581,6 +2043,8 @@ export const $ZodFile = /*@__PURE__*/ core.$constructor("$ZodFile", (inst, def)
1581
2043
  });
1582
2044
  export const $ZodTransform = /*@__PURE__*/ core.$constructor("$ZodTransform", (inst, def) => {
1583
2045
  $ZodType.init(inst, def);
2046
+ inst._zod.optin = "optional";
2047
+ core.globalConfig.memoizer?.guard(inst);
1584
2048
  inst._zod.parse = (payload, ctx) => {
1585
2049
  if (ctx.direction === "backward") {
1586
2050
  throw new core.$ZodEncodeError(inst.constructor.name);
@@ -1600,32 +2064,34 @@ export const $ZodTransform = /*@__PURE__*/ core.$constructor("$ZodTransform", (i
1600
2064
  return payload;
1601
2065
  };
1602
2066
  });
1603
- function handleOptionalResult(result, input) {
1604
- if (result.issues.length && input === undefined) {
1605
- return { issues: [], value: undefined };
1606
- }
1607
- return result;
2067
+ function handleOptionalResult(payload, result) {
2068
+ // 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.
2069
+ payload.value = result.issues.length ? undefined : result.value;
2070
+ return payload;
1608
2071
  }
1609
2072
  export const $ZodOptional = /*@__PURE__*/ core.$constructor("$ZodOptional", (inst, def) => {
1610
2073
  $ZodType.init(inst, def);
1611
- inst._zod.optin = "optional";
2074
+ // .optional() propagates absence rather than substituting for it, so a defaulted inner keeps its rung.
2075
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional");
1612
2076
  inst._zod.optout = "optional";
1613
- util.defineLazy(inst._zod, "values", () => {
1614
- return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
2077
+ util.defineLazyInternal(inst, "values", (zod) => {
2078
+ const values = zod.def.innerType._zod.values;
2079
+ return values ? new Set([...values, undefined]) : undefined;
1615
2080
  });
1616
- util.defineLazy(inst._zod, "pattern", () => {
1617
- const pattern = def.innerType._zod.pattern;
2081
+ util.defineLazyInternal(inst, "pattern", (zod) => {
2082
+ const pattern = zod.def.innerType._zod.pattern;
1618
2083
  return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)})?$`) : undefined;
1619
2084
  });
1620
2085
  inst._zod.parse = (payload, ctx) => {
1621
- if (def.innerType._zod.optin === "optional") {
1622
- const result = def.innerType._zod.run(payload, ctx);
1623
- if (result instanceof Promise)
1624
- return result.then((r) => handleOptionalResult(r, payload.value));
1625
- return handleOptionalResult(result, payload.value);
1626
- }
1627
2086
  if (payload.value === undefined) {
1628
- return payload;
2087
+ // Only the top rung substitutes a value for absence; everything else leaves it intact, which is what .optional() means.
2088
+ if (def.innerType._zod.optin !== "defaulted")
2089
+ return payload;
2090
+ // 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.
2091
+ const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
2092
+ if (result instanceof Promise)
2093
+ return result.then((result) => handleOptionalResult(payload, result));
2094
+ return handleOptionalResult(payload, result);
1629
2095
  }
1630
2096
  return def.innerType._zod.run(payload, ctx);
1631
2097
  };
@@ -1634,8 +2100,8 @@ export const $ZodExactOptional = /*@__PURE__*/ core.$constructor("$ZodExactOptio
1634
2100
  // Call parent init - inherits optin/optout = "optional"
1635
2101
  $ZodOptional.init(inst, def);
1636
2102
  // Override values/pattern to NOT add undefined
1637
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1638
- util.defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
2103
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
2104
+ util.defineLazyInternal(inst, "pattern", (zod) => zod.def.innerType._zod.pattern);
1639
2105
  // Override parse to just delegate (no undefined handling)
1640
2106
  inst._zod.parse = (payload, ctx) => {
1641
2107
  return def.innerType._zod.run(payload, ctx);
@@ -1643,14 +2109,14 @@ export const $ZodExactOptional = /*@__PURE__*/ core.$constructor("$ZodExactOptio
1643
2109
  });
1644
2110
  export const $ZodNullable = /*@__PURE__*/ core.$constructor("$ZodNullable", (inst, def) => {
1645
2111
  $ZodType.init(inst, def);
1646
- util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1647
- util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1648
- util.defineLazy(inst._zod, "pattern", () => {
1649
- const pattern = def.innerType._zod.pattern;
2112
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin);
2113
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
2114
+ util.defineLazyInternal(inst, "pattern", (zod) => {
2115
+ const pattern = zod.def.innerType._zod.pattern;
1650
2116
  return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)}|null)$`) : undefined;
1651
2117
  });
1652
- util.defineLazy(inst._zod, "values", () => {
1653
- return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
2118
+ util.defineLazyInternal(inst, "values", (zod) => {
2119
+ return zod.def.innerType._zod.values ? new Set([...zod.def.innerType._zod.values, null]) : undefined;
1654
2120
  });
1655
2121
  inst._zod.parse = (payload, ctx) => {
1656
2122
  // Forward direction (decode): allow null to pass through
@@ -1662,8 +2128,8 @@ export const $ZodNullable = /*@__PURE__*/ core.$constructor("$ZodNullable", (ins
1662
2128
  export const $ZodDefault = /*@__PURE__*/ core.$constructor("$ZodDefault", (inst, def) => {
1663
2129
  $ZodType.init(inst, def);
1664
2130
  // inst._zod.qin = "true";
1665
- inst._zod.optin = "optional";
1666
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2131
+ inst._zod.optin = "defaulted";
2132
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1667
2133
  inst._zod.parse = (payload, ctx) => {
1668
2134
  if (ctx.direction === "backward") {
1669
2135
  return def.innerType._zod.run(payload, ctx);
@@ -1692,8 +2158,8 @@ function handleDefaultResult(payload, def) {
1692
2158
  }
1693
2159
  export const $ZodPrefault = /*@__PURE__*/ core.$constructor("$ZodPrefault", (inst, def) => {
1694
2160
  $ZodType.init(inst, def);
1695
- inst._zod.optin = "optional";
1696
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2161
+ inst._zod.optin = "defaulted";
2162
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1697
2163
  inst._zod.parse = (payload, ctx) => {
1698
2164
  if (ctx.direction === "backward") {
1699
2165
  return def.innerType._zod.run(payload, ctx);
@@ -1707,8 +2173,8 @@ export const $ZodPrefault = /*@__PURE__*/ core.$constructor("$ZodPrefault", (ins
1707
2173
  });
1708
2174
  export const $ZodNonOptional = /*@__PURE__*/ core.$constructor("$ZodNonOptional", (inst, def) => {
1709
2175
  $ZodType.init(inst, def);
1710
- util.defineLazy(inst._zod, "values", () => {
1711
- const v = def.innerType._zod.values;
2176
+ util.defineLazyInternal(inst, "values", (zod) => {
2177
+ const v = zod.def.innerType._zod.values;
1712
2178
  return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
1713
2179
  });
1714
2180
  inst._zod.parse = (payload, ctx) => {
@@ -1747,45 +2213,40 @@ export const $ZodSuccess = /*@__PURE__*/ core.$constructor("$ZodSuccess", (inst,
1747
2213
  return payload;
1748
2214
  };
1749
2215
  });
2216
+ function handleCatchResult(payload, result, def, ctx) {
2217
+ if (!result.issues.length) {
2218
+ payload.value = result.value;
2219
+ // 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.
2220
+ if (result.memo)
2221
+ payload.memo = true;
2222
+ return payload;
2223
+ }
2224
+ // 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.
2225
+ payload.value = def.catchValue({
2226
+ ...result,
2227
+ value: payload.value,
2228
+ error: {
2229
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
2230
+ },
2231
+ input: payload.value,
2232
+ });
2233
+ return payload;
2234
+ }
1750
2235
  export const $ZodCatch = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
1751
2236
  $ZodType.init(inst, def);
1752
- util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1753
- util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1754
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2237
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional");
2238
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
2239
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
1755
2240
  inst._zod.parse = (payload, ctx) => {
1756
2241
  if (ctx.direction === "backward") {
1757
2242
  return def.innerType._zod.run(payload, ctx);
1758
2243
  }
1759
2244
  // Forward direction (decode): apply catch logic
1760
- const result = def.innerType._zod.run(payload, ctx);
2245
+ const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
1761
2246
  if (result instanceof Promise) {
1762
- return result.then((result) => {
1763
- payload.value = result.value;
1764
- if (result.issues.length) {
1765
- payload.value = def.catchValue({
1766
- ...payload,
1767
- error: {
1768
- issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1769
- },
1770
- input: payload.value,
1771
- });
1772
- payload.issues = [];
1773
- }
1774
- return payload;
1775
- });
1776
- }
1777
- payload.value = result.value;
1778
- if (result.issues.length) {
1779
- payload.value = def.catchValue({
1780
- ...payload,
1781
- error: {
1782
- issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1783
- },
1784
- input: payload.value,
1785
- });
1786
- payload.issues = [];
2247
+ return result.then((result) => handleCatchResult(payload, result, def, ctx));
1787
2248
  }
1788
- return payload;
2249
+ return handleCatchResult(payload, result, def, ctx);
1789
2250
  };
1790
2251
  });
1791
2252
  export const $ZodNaN = /*@__PURE__*/ core.$constructor("$ZodNaN", (inst, def) => {
@@ -1805,10 +2266,10 @@ export const $ZodNaN = /*@__PURE__*/ core.$constructor("$ZodNaN", (inst, def) =>
1805
2266
  });
1806
2267
  export const $ZodPipe = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def) => {
1807
2268
  $ZodType.init(inst, def);
1808
- util.defineLazy(inst._zod, "values", () => def.in._zod.values);
1809
- util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1810
- util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1811
- util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
2269
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
2270
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
2271
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
2272
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
1812
2273
  inst._zod.parse = (payload, ctx) => {
1813
2274
  if (ctx.direction === "backward") {
1814
2275
  const right = def.out._zod.run(payload, ctx);
@@ -1825,7 +2286,8 @@ export const $ZodPipe = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def)
1825
2286
  };
1826
2287
  });
1827
2288
  function handlePipeResult(left, next, ctx) {
1828
- if (left.issues.length) {
2289
+ // 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.
2290
+ if (left.issues.some((iss) => iss.code !== "unrecognized_keys")) {
1829
2291
  // prevent further checks
1830
2292
  left.aborted = true;
1831
2293
  return left;
@@ -1834,10 +2296,10 @@ function handlePipeResult(left, next, ctx) {
1834
2296
  }
1835
2297
  export const $ZodCodec = /*@__PURE__*/ core.$constructor("$ZodCodec", (inst, def) => {
1836
2298
  $ZodType.init(inst, def);
1837
- util.defineLazy(inst._zod, "values", () => def.in._zod.values);
1838
- util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1839
- util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1840
- util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
2299
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
2300
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
2301
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
2302
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
1841
2303
  inst._zod.parse = (payload, ctx) => {
1842
2304
  const direction = ctx.direction || "forward";
1843
2305
  if (direction === "forward") {
@@ -1886,12 +2348,15 @@ function handleCodecTxResult(left, value, nextSchema, ctx) {
1886
2348
  }
1887
2349
  return nextSchema._zod.run({ value, issues: left.issues }, ctx);
1888
2350
  }
2351
+ export const $ZodPreprocess = /*@__PURE__*/ core.$constructor("$ZodPreprocess", (inst, def) => {
2352
+ $ZodPipe.init(inst, def);
2353
+ });
1889
2354
  export const $ZodReadonly = /*@__PURE__*/ core.$constructor("$ZodReadonly", (inst, def) => {
1890
2355
  $ZodType.init(inst, def);
1891
- util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1892
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1893
- util.defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
1894
- util.defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
2356
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.innerType._zod.propValues);
2357
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
2358
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType?._zod?.optin);
2359
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType?._zod?.optout);
1895
2360
  inst._zod.parse = (payload, ctx) => {
1896
2361
  if (ctx.direction === "backward") {
1897
2362
  return def.innerType._zod.run(payload, ctx);
@@ -1904,25 +2369,72 @@ export const $ZodReadonly = /*@__PURE__*/ core.$constructor("$ZodReadonly", (ins
1904
2369
  };
1905
2370
  });
1906
2371
  function handleReadonlyResult(payload) {
1907
- payload.value = Object.freeze(payload.value);
2372
+ // 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.
2373
+ if (!payload.memo)
2374
+ payload.value = Object.freeze(payload.value);
1908
2375
  return payload;
1909
2376
  }
2377
+ // 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
2378
+ function leafPattern(schema) {
2379
+ const def = schema._zod.def;
2380
+ let pattern = def.pattern;
2381
+ let isInt = !!def.format?.includes("int");
2382
+ let minimum;
2383
+ let maximum;
2384
+ for (const ch of def.checks ?? []) {
2385
+ const d = ch._zod.def;
2386
+ if (d.pattern)
2387
+ pattern = d.pattern;
2388
+ isInt || (isInt = !!d.format?.includes("int"));
2389
+ const lo = d.minimum ?? d.length;
2390
+ const hi = d.maximum ?? d.length;
2391
+ if (lo !== undefined && (minimum === undefined || lo > minimum))
2392
+ minimum = lo;
2393
+ if (hi !== undefined && (maximum === undefined || hi < maximum))
2394
+ maximum = hi;
2395
+ }
2396
+ if (pattern)
2397
+ return pattern.source;
2398
+ // an empty range matches nothing at runtime, and `{8,5}` is not a legal quantifier
2399
+ if (minimum !== undefined && maximum !== undefined && minimum > maximum)
2400
+ return "(?!)";
2401
+ if (minimum !== undefined || maximum !== undefined)
2402
+ return regexes.string({ minimum, maximum }).source;
2403
+ const own = schema._zod.pattern;
2404
+ return (isInt && own === regexes.number ? regexes.integer : own)?.source;
2405
+ }
2406
+ // 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
2407
+ function partPattern(schema) {
2408
+ const def = schema._zod.def;
2409
+ const own = schema._zod.pattern?.source;
2410
+ // lazy resolves its inner on the internals, not the def
2411
+ const inner = def.innerType ?? schema._zod.innerType;
2412
+ if (inner) {
2413
+ const before = inner._zod.pattern?.source;
2414
+ const after = partPattern(inner);
2415
+ if (own && before && after && after !== before) {
2416
+ return own.replace(util.cleanRegex(before), () => util.cleanRegex(after));
2417
+ }
2418
+ return own;
2419
+ }
2420
+ if (def.options) {
2421
+ const sources = def.options.map(partPattern);
2422
+ if (sources.every(Boolean))
2423
+ return `^(${sources.map((s) => util.cleanRegex(s)).join("|")})$`;
2424
+ }
2425
+ return leafPattern(schema);
2426
+ }
1910
2427
  export const $ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("$ZodTemplateLiteral", (inst, def) => {
1911
2428
  $ZodType.init(inst, def);
1912
2429
  const regexParts = [];
1913
2430
  for (const part of def.parts) {
1914
2431
  if (typeof part === "object" && part !== null) {
1915
2432
  // is Zod schema
1916
- if (!part._zod.pattern) {
1917
- // if (!source)
2433
+ const source = partPattern(part);
2434
+ if (!source) {
1918
2435
  throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
1919
2436
  }
1920
- const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;
1921
- if (!source)
1922
- throw new Error(`Invalid template literal part: ${part._zod.traits}`);
1923
- const start = source.startsWith("^") ? 1 : 0;
1924
- const end = source.endsWith("$") ? source.length - 1 : source.length;
1925
- regexParts.push(source.slice(start, end));
2437
+ regexParts.push(util.cleanRegex(source));
1926
2438
  }
1927
2439
  else if (part === null || util.primitiveTypes.has(typeof part)) {
1928
2440
  regexParts.push(util.escapeRegex(`${part}`));
@@ -1958,33 +2470,35 @@ export const $ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("$ZodTemplate
1958
2470
  });
1959
2471
  export const $ZodFunction = /*@__PURE__*/ core.$constructor("$ZodFunction", (inst, def) => {
1960
2472
  $ZodType.init(inst, def);
1961
- inst._def = def;
2473
+ // Defined, not assigned: the classic prototype exposes `_def` as a getter with no setter.
2474
+ Object.defineProperty(inst, "_def", { value: def });
1962
2475
  inst._zod.def = def;
1963
2476
  inst.implement = (func) => {
1964
2477
  if (typeof func !== "function") {
1965
2478
  throw new Error("implement() must be called with a function");
1966
2479
  }
1967
- return function (...args) {
2480
+ // Defined inline so the closure stays anonymous: binding it to a `const` first names it, which costs 256 bytes per implemented function.
2481
+ return Object.defineProperty(function (...args) {
1968
2482
  const parsedArgs = inst._def.input ? parse(inst._def.input, args) : args;
1969
2483
  const result = Reflect.apply(func, this, parsedArgs);
1970
2484
  if (inst._def.output) {
1971
2485
  return parse(inst._def.output, result);
1972
2486
  }
1973
2487
  return result;
1974
- };
2488
+ }, "_zod", { value: inst._zod, enumerable: false });
1975
2489
  };
1976
2490
  inst.implementAsync = (func) => {
1977
2491
  if (typeof func !== "function") {
1978
2492
  throw new Error("implementAsync() must be called with a function");
1979
2493
  }
1980
- return async function (...args) {
2494
+ return Object.defineProperty(async function (...args) {
1981
2495
  const parsedArgs = inst._def.input ? await parseAsync(inst._def.input, args) : args;
1982
2496
  const result = await Reflect.apply(func, this, parsedArgs);
1983
2497
  if (inst._def.output) {
1984
2498
  return await parseAsync(inst._def.output, result);
1985
2499
  }
1986
2500
  return result;
1987
- };
2501
+ }, "_zod", { value: inst._zod, enumerable: false });
1988
2502
  };
1989
2503
  inst._zod.parse = (payload, _ctx) => {
1990
2504
  if (typeof payload.value !== "function") {
@@ -2043,18 +2557,17 @@ export const $ZodPromise = /*@__PURE__*/ core.$constructor("$ZodPromise", (inst,
2043
2557
  });
2044
2558
  export const $ZodLazy = /*@__PURE__*/ core.$constructor("$ZodLazy", (inst, def) => {
2045
2559
  $ZodType.init(inst, def);
2046
- // let _innerType!: any;
2047
- // util.defineLazy(def, "getter", () => {
2048
- // if (!_innerType) {
2049
- // _innerType = def.getter();
2050
- // }
2051
- // return () => _innerType;
2052
- // });
2053
- util.defineLazy(inst._zod, "innerType", () => def.getter());
2054
- util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod?.pattern);
2055
- util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod?.propValues);
2056
- util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod?.optin ?? undefined);
2057
- util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod?.optout ?? undefined);
2560
+ // 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.
2561
+ util.defineLazy(inst._zod, "innerType", () => {
2562
+ const d = def;
2563
+ if (!d._cachedInner)
2564
+ d._cachedInner = def.getter();
2565
+ return d._cachedInner;
2566
+ });
2567
+ util.defineLazyInternal(inst, "pattern", (zod) => zod.innerType?._zod?.pattern);
2568
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.innerType?._zod?.propValues);
2569
+ util.defineLazyInternal(inst, "optin", (zod) => zod.innerType?._zod?.optin ?? undefined);
2570
+ util.defineLazyInternal(inst, "optout", (zod) => zod.innerType?._zod?.optout ?? undefined);
2058
2571
  inst._zod.parse = (payload, ctx) => {
2059
2572
  const inner = inst._zod.innerType;
2060
2573
  return inner._zod.run(payload, ctx);