cross-seed 7.0.0-21 → 7.0.0-23

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 (785) hide show
  1. package/dist/action.js +7 -8
  2. package/dist/action.js.map +1 -1
  3. package/dist/arr.js +2 -2
  4. package/dist/arr.js.map +1 -1
  5. package/dist/bencode.d.ts +62 -0
  6. package/dist/bencode.js +248 -0
  7. package/dist/bencode.js.map +1 -0
  8. package/dist/clients/Deluge.d.ts +5 -10
  9. package/dist/clients/Deluge.js +115 -89
  10. package/dist/clients/Deluge.js.map +1 -1
  11. package/dist/clients/QBittorrent.d.ts +3 -0
  12. package/dist/clients/QBittorrent.js +43 -30
  13. package/dist/clients/QBittorrent.js.map +1 -1
  14. package/dist/clients/RTorrent.d.ts +3 -2
  15. package/dist/clients/RTorrent.js +120 -41
  16. package/dist/clients/RTorrent.js.map +1 -1
  17. package/dist/clients/TorrentClient.d.ts +3 -2
  18. package/dist/clients/TorrentClient.js +3 -5
  19. package/dist/clients/TorrentClient.js.map +1 -1
  20. package/dist/clients/Transmission.d.ts +1 -0
  21. package/dist/clients/Transmission.js +90 -40
  22. package/dist/clients/Transmission.js.map +1 -1
  23. package/dist/clients/qbittorrent-version.d.ts +6 -0
  24. package/dist/clients/qbittorrent-version.js +11 -0
  25. package/dist/clients/qbittorrent-version.js.map +1 -0
  26. package/dist/clients/scgi.d.ts +14 -0
  27. package/dist/clients/scgi.js +111 -0
  28. package/dist/clients/scgi.js.map +1 -0
  29. package/dist/cmd.js +1 -1
  30. package/dist/cmd.js.map +1 -1
  31. package/dist/configuration.js +49 -9
  32. package/dist/configuration.js.map +1 -1
  33. package/dist/constants.d.ts +10 -0
  34. package/dist/constants.js +12 -2
  35. package/dist/constants.js.map +1 -1
  36. package/dist/dataFiles.d.ts +1 -0
  37. package/dist/dataFiles.js +252 -60
  38. package/dist/dataFiles.js.map +1 -1
  39. package/dist/db.js +8 -4
  40. package/dist/db.js.map +1 -1
  41. package/dist/decide.js +8 -8
  42. package/dist/decide.js.map +1 -1
  43. package/dist/devLogin.js.map +1 -1
  44. package/dist/diff.js.map +1 -1
  45. package/dist/indexers.js +5 -4
  46. package/dist/indexers.js.map +1 -1
  47. package/dist/inject.js +5 -5
  48. package/dist/inject.js.map +1 -1
  49. package/dist/jobs.js +2 -1
  50. package/dist/jobs.js.map +1 -1
  51. package/dist/libraryInventory.d.ts +176 -0
  52. package/dist/libraryInventory.js +701 -0
  53. package/dist/libraryInventory.js.map +1 -0
  54. package/dist/logger.js +7 -5
  55. package/dist/logger.js.map +1 -1
  56. package/dist/migrations/09-clientAndDataSearchees.js +1 -0
  57. package/dist/migrations/09-clientAndDataSearchees.js.map +1 -1
  58. package/dist/migrations/17-api-key-settings-json.js +3 -1
  59. package/dist/migrations/17-api-key-settings-json.js.map +1 -1
  60. package/dist/migrations/18-library-inventory.d.ts +9 -0
  61. package/dist/migrations/18-library-inventory.js +48 -0
  62. package/dist/migrations/18-library-inventory.js.map +1 -0
  63. package/dist/migrations/19-library-files.d.ts +9 -0
  64. package/dist/migrations/19-library-files.js +26 -0
  65. package/dist/migrations/19-library-files.js.map +1 -0
  66. package/dist/migrations/migrations.d.ts +12 -5
  67. package/dist/migrations/migrations.js +5 -1
  68. package/dist/migrations/migrations.js.map +1 -1
  69. package/dist/parseTorrent.d.ts +1 -1
  70. package/dist/parseTorrent.js +18 -4
  71. package/dist/parseTorrent.js.map +1 -1
  72. package/dist/pipeline.js +12 -11
  73. package/dist/pipeline.js.map +1 -1
  74. package/dist/problems/linking.js +1 -1
  75. package/dist/problems/linking.js.map +1 -1
  76. package/dist/problems.js +2 -1
  77. package/dist/problems.js.map +1 -1
  78. package/dist/pushNotifier.js +10 -9
  79. package/dist/pushNotifier.js.map +1 -1
  80. package/dist/routes/baseApi.d.ts +8 -0
  81. package/dist/routes/baseApi.js +26 -52
  82. package/dist/routes/baseApi.js.map +1 -1
  83. package/dist/routes/devLogin.js +1 -0
  84. package/dist/routes/devLogin.js.map +1 -1
  85. package/dist/routes/indexerApi.js +1 -0
  86. package/dist/routes/indexerApi.js.map +1 -1
  87. package/dist/routes/staticFrontendPlugin.js +1 -0
  88. package/dist/routes/staticFrontendPlugin.js.map +1 -1
  89. package/dist/searchee.d.ts +14 -2
  90. package/dist/searchee.js +26 -9
  91. package/dist/searchee.js.map +1 -1
  92. package/dist/services/indexerService.js +8 -2
  93. package/dist/services/indexerService.js.map +1 -1
  94. package/dist/startup.d.ts +1 -0
  95. package/dist/startup.js +11 -4
  96. package/dist/startup.js.map +1 -1
  97. package/dist/torrent.js +302 -115
  98. package/dist/torrent.js.map +1 -1
  99. package/dist/torznab.d.ts +2 -2
  100. package/dist/torznab.js +15 -14
  101. package/dist/torznab.js.map +1 -1
  102. package/dist/trpc/routers/auth.js +1 -1
  103. package/dist/trpc/routers/auth.js.map +1 -1
  104. package/dist/trpc/routers/clients.js +8 -13
  105. package/dist/trpc/routers/clients.js.map +1 -1
  106. package/dist/trpc/routers/index.d.ts +51 -50
  107. package/dist/trpc/routers/index.js +2 -2
  108. package/dist/trpc/routers/index.js.map +1 -1
  109. package/dist/trpc/routers/jobs.js +1 -1
  110. package/dist/trpc/routers/jobs.js.map +1 -1
  111. package/dist/trpc/routers/library.d.ts +50 -0
  112. package/dist/trpc/routers/library.js +85 -0
  113. package/dist/trpc/routers/library.js.map +1 -0
  114. package/dist/trpc/routers/logs.js +6 -5
  115. package/dist/trpc/routers/logs.js.map +1 -1
  116. package/dist/trpc/routers/settings.js +78 -21
  117. package/dist/trpc/routers/settings.js.map +1 -1
  118. package/dist/trpc/routers/stats.d.ts +1 -0
  119. package/dist/trpc/routers/stats.js +11 -5
  120. package/dist/trpc/routers/stats.js.map +1 -1
  121. package/dist/userAuth.js +1 -1
  122. package/dist/userAuth.js.map +1 -1
  123. package/dist/utils/background.d.ts +7 -0
  124. package/dist/utils/background.js +14 -0
  125. package/dist/utils/background.js.map +1 -0
  126. package/dist/utils/logWatcher.js +3 -2
  127. package/dist/utils/logWatcher.js.map +1 -1
  128. package/dist/utils.d.ts +11 -1
  129. package/dist/utils.js +47 -8
  130. package/dist/utils.js.map +1 -1
  131. package/dist/webui/assets/DeleteOption-DkdJCiOu.js +1 -0
  132. package/dist/webui/assets/FieldInfo-rcCXc0d-.js +1 -0
  133. package/dist/webui/assets/Page-CKwSnUie.js +1 -0
  134. package/dist/webui/assets/array-field-DM2mAVqa.js +1 -0
  135. package/dist/webui/assets/badge-CLUazitN.js +1 -0
  136. package/dist/webui/assets/button-DoKPR9Fv.js +1 -0
  137. package/dist/webui/assets/check-BlfHpqkp.js +1 -0
  138. package/dist/webui/assets/clients-B5C80D0F.js +1 -0
  139. package/dist/webui/assets/connect-BM7yGLAl.js +2 -0
  140. package/dist/webui/assets/createLucideIcon-Cv-_CLkr.js +1 -0
  141. package/dist/webui/assets/debug-C8d57uIb.js +1 -0
  142. package/dist/webui/assets/directories-DkJnb01t.js +1 -0
  143. package/dist/webui/assets/dist-B7BqKb_s.js +1 -0
  144. package/dist/webui/assets/dist-CXZZv-cf.js +41 -0
  145. package/dist/webui/assets/dist-ChMQZgJB.js +1 -0
  146. package/dist/webui/assets/dist-DQ6Xm99Z.js +1 -0
  147. package/dist/webui/assets/duration-field-w-qiOS_S.js +1 -0
  148. package/dist/webui/assets/general-2HmkyF5T.js +1 -0
  149. package/dist/webui/assets/health-D6tv4ioy.js +1 -0
  150. package/dist/webui/assets/index-NlorOk2I.js +11 -0
  151. package/dist/webui/assets/index-UQKt4Igp.css +2 -0
  152. package/dist/webui/assets/input-BggK3IOz.js +1 -0
  153. package/dist/webui/assets/jobs-Do8vAIqy.js +1 -0
  154. package/dist/webui/assets/library-B1r1nAY-.js +1 -0
  155. package/dist/webui/assets/loader-circle-D988WNxu.js +1 -0
  156. package/dist/webui/assets/logs-_rm8bxf-.js +1 -0
  157. package/dist/webui/assets/number-field-CeKyqI7R.js +1 -0
  158. package/dist/webui/assets/react-dom-DtIef6y6.js +1 -0
  159. package/dist/webui/assets/required-indicator-Ba9NOQEP.js +1 -0
  160. package/dist/webui/assets/routes-Djgf7dZI.js +1 -0
  161. package/dist/webui/assets/search-DGY0ui92.js +1 -0
  162. package/dist/webui/assets/select-BzZ418Yt.js +1 -0
  163. package/dist/webui/assets/select-field-DsBowTDT.js +1 -0
  164. package/dist/webui/assets/settings-B4G8vHXc.js +1 -0
  165. package/dist/webui/assets/sidebar-Qy-rYdhU.js +5 -0
  166. package/dist/webui/assets/submit-button-Bx2Dvr03.js +1 -0
  167. package/dist/webui/assets/switch-CttdmVGp.js +1 -0
  168. package/dist/webui/assets/switch-field-p-JPVVvW.js +1 -0
  169. package/dist/webui/assets/table-Bs6CQscS.js +1 -0
  170. package/dist/webui/assets/{test-tube-CbcievIk.js → test-tube-DD9Yz2bZ.js} +1 -1
  171. package/dist/webui/assets/text-field-B0a3dEGb.js +1 -0
  172. package/dist/webui/assets/time-KFQKyrl-.js +1 -0
  173. package/dist/webui/assets/trackers-DG-YCaaO.js +7 -0
  174. package/dist/webui/assets/{trash-D083IWKI.js → trash-PHXIGUCt.js} +1 -1
  175. package/dist/webui/assets/use-settings-form-submit-CDmMUcwW.js +57 -0
  176. package/dist/webui/assets/useSelector-BoN-mufS.js +2 -0
  177. package/dist/webui/assets/utils-P-unlvb4.js +1 -0
  178. package/dist/webui/assets/with-selector-fbK2t2oY.js +1 -0
  179. package/dist/webui/index.html +12 -14
  180. package/node_modules/@cross-seed/shared/dist/tsconfig.tsbuildinfo +1 -1
  181. package/node_modules/@cross-seed/shared/package.json +6 -2
  182. package/node_modules/zod/README.md +30 -20
  183. package/node_modules/zod/compile.cjs +96 -0
  184. package/node_modules/zod/compile.d.cts +1 -0
  185. package/node_modules/zod/compile.d.ts +1 -0
  186. package/node_modules/zod/compile.js +52 -0
  187. package/node_modules/zod/index.cjs +21 -2
  188. package/node_modules/zod/index.d.cts +1 -2
  189. package/node_modules/zod/index.d.ts +1 -2
  190. package/node_modules/zod/index.js +5 -2
  191. package/node_modules/zod/locales/index.cjs +19 -0
  192. package/node_modules/zod/locales/package.json +2 -1
  193. package/node_modules/zod/mini/index.cjs +19 -0
  194. package/node_modules/zod/mini/package.json +2 -1
  195. package/node_modules/zod/package.json +20 -8
  196. package/node_modules/zod/src/compile.ts +56 -0
  197. package/node_modules/zod/src/index.ts +5 -2
  198. package/node_modules/zod/src/v3/ZodError.ts +22 -12
  199. package/node_modules/zod/src/v3/helpers/errorUtil.ts +1 -1
  200. package/node_modules/zod/src/v3/tests/all-errors.test.ts +3 -3
  201. package/node_modules/zod/src/v3/tests/error.test.ts +35 -0
  202. package/node_modules/zod/src/v3/tests/intersection.test.ts +18 -0
  203. package/node_modules/zod/src/v3/tests/language-server.test.ts +1 -2
  204. package/node_modules/zod/src/v3/tests/object.test.ts +8 -11
  205. package/node_modules/zod/src/v3/tests/partials.test.ts +3 -3
  206. package/node_modules/zod/src/v3/tests/readonly.test.ts +0 -80
  207. package/node_modules/zod/src/v3/tests/string.test.ts +6 -0
  208. package/node_modules/zod/src/v3/types.ts +5 -5
  209. package/node_modules/zod/src/v4/classic/checks.ts +1 -0
  210. package/node_modules/zod/src/v4/classic/compat.ts +26 -18
  211. package/node_modules/zod/src/v4/classic/deep-partial.ts +76 -0
  212. package/node_modules/zod/src/v4/classic/errors.ts +60 -45
  213. package/node_modules/zod/src/v4/classic/external.ts +15 -9
  214. package/node_modules/zod/src/v4/classic/from-json-schema.ts +389 -88
  215. package/node_modules/zod/src/v4/classic/in-out.ts +45 -0
  216. package/node_modules/zod/src/v4/classic/index.ts +2 -2
  217. package/node_modules/zod/src/v4/classic/iso.ts +2 -72
  218. package/node_modules/zod/src/v4/classic/parse.ts +16 -10
  219. package/node_modules/zod/src/v4/classic/schemas.ts +863 -335
  220. package/node_modules/zod/src/v4/classic/tests/apply.test.ts +27 -0
  221. package/node_modules/zod/src/v4/classic/tests/array.test.ts +29 -2
  222. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +192 -0
  223. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +36 -1
  224. package/node_modules/zod/src/v4/classic/tests/catch.test.ts +328 -0
  225. package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +1 -2
  226. package/node_modules/zod/src/v4/classic/tests/codec.test.ts +144 -2
  227. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +4 -4
  228. package/node_modules/zod/src/v4/classic/tests/credit-card.test.ts +76 -0
  229. package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +985 -0
  230. package/node_modules/zod/src/v4/classic/tests/date.test.ts +30 -0
  231. package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +31 -17
  232. package/node_modules/zod/src/v4/classic/tests/deep-partial.test.ts +380 -0
  233. package/node_modules/zod/src/v4/classic/tests/default-locale.test.ts +32 -0
  234. package/node_modules/zod/src/v4/classic/tests/default.test.ts +90 -0
  235. package/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +221 -0
  236. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +291 -10
  237. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +20 -0
  238. package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +324 -2
  239. package/node_modules/zod/src/v4/classic/tests/error.test.ts +403 -6
  240. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +743 -10
  241. package/node_modules/zod/src/v4/classic/tests/function.test.ts +37 -6
  242. package/node_modules/zod/src/v4/classic/tests/global-config.test.ts +32 -0
  243. package/node_modules/zod/src/v4/classic/tests/hash.test.ts +1 -2
  244. package/node_modules/zod/src/v4/classic/tests/iban.test.ts +81 -0
  245. package/node_modules/zod/src/v4/classic/tests/in-out.test.ts +159 -0
  246. package/node_modules/zod/src/v4/classic/tests/index.test.ts +23 -4
  247. package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +319 -0
  248. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +67 -0
  249. package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +136 -0
  250. package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +215 -0
  251. package/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +39 -0
  252. package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +36 -1
  253. package/node_modules/zod/src/v4/classic/tests/literal.test.ts +12 -1
  254. package/node_modules/zod/src/v4/classic/tests/locales_ka.test.ts +29 -0
  255. package/node_modules/zod/src/v4/classic/tests/locales_ro.test.ts +24 -0
  256. package/node_modules/zod/src/v4/classic/tests/map.test.ts +19 -0
  257. package/node_modules/zod/src/v4/classic/tests/number.test.ts +138 -7
  258. package/node_modules/zod/src/v4/classic/tests/object.test.ts +378 -12
  259. package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +235 -0
  260. package/node_modules/zod/src/v4/classic/tests/optional.test.ts +156 -13
  261. package/node_modules/zod/src/v4/classic/tests/partial.test.ts +71 -1
  262. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +71 -1
  263. package/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +44 -0
  264. package/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +69 -0
  265. package/node_modules/zod/src/v4/classic/tests/properties.test.ts +141 -0
  266. package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +0 -68
  267. package/node_modules/zod/src/v4/classic/tests/record.test.ts +269 -16
  268. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +126 -1
  269. package/node_modules/zod/src/v4/classic/tests/redos.test.ts +68 -0
  270. package/node_modules/zod/src/v4/classic/tests/refine.test.ts +123 -0
  271. package/node_modules/zod/src/v4/classic/tests/set.test.ts +15 -0
  272. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +19 -0
  273. package/node_modules/zod/src/v4/classic/tests/string.test.ts +269 -4
  274. package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +18 -0
  275. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +48 -7
  276. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +1948 -205
  277. package/node_modules/zod/src/v4/classic/tests/transform.test.ts +17 -0
  278. package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +330 -2
  279. package/node_modules/zod/src/v4/classic/tests/union.test.ts +93 -2
  280. package/node_modules/zod/src/v4/classic/tests/validate.test.ts +645 -0
  281. package/node_modules/zod/src/v4/classic/tests/validations.test.ts +2 -2
  282. package/node_modules/zod/src/v4/core/api.ts +111 -34
  283. package/node_modules/zod/src/v4/core/checks.ts +120 -147
  284. package/node_modules/zod/src/v4/core/compile.ts +2322 -0
  285. package/node_modules/zod/src/v4/core/core.ts +116 -24
  286. package/node_modules/zod/src/v4/core/doc.ts +17 -9
  287. package/node_modules/zod/src/v4/core/errors.ts +138 -43
  288. package/node_modules/zod/src/v4/core/index.ts +3 -0
  289. package/node_modules/zod/src/v4/core/json-schema-generator.ts +8 -3
  290. package/node_modules/zod/src/v4/core/json-schema-processors.ts +440 -173
  291. package/node_modules/zod/src/v4/core/json-schema.ts +2 -1
  292. package/node_modules/zod/src/v4/core/memoizer.ts +331 -0
  293. package/node_modules/zod/src/v4/core/parse.ts +167 -53
  294. package/node_modules/zod/src/v4/core/regexes.ts +50 -16
  295. package/node_modules/zod/src/v4/core/registries.ts +2 -2
  296. package/node_modules/zod/src/v4/core/schemas.ts +1219 -531
  297. package/node_modules/zod/src/v4/core/tests/cached.test.ts +54 -0
  298. package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +1004 -0
  299. package/node_modules/zod/src/v4/core/tests/compile-generative.test.ts +445 -0
  300. package/node_modules/zod/src/v4/core/tests/compile-global.test.ts +89 -0
  301. package/node_modules/zod/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
  302. package/node_modules/zod/src/v4/core/tests/compile-stats.test.ts +34 -0
  303. package/node_modules/zod/src/v4/core/tests/compile.test.ts +2036 -0
  304. package/node_modules/zod/src/v4/core/tests/email-regex.test.ts +140 -0
  305. package/node_modules/zod/src/v4/core/tests/locales/el.test.ts +214 -0
  306. package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +1 -2
  307. package/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +72 -0
  308. package/node_modules/zod/src/v4/core/tests/locales/hr.test.ts +163 -0
  309. package/node_modules/zod/src/v4/core/tests/locales/parity.test.ts +42 -0
  310. package/node_modules/zod/src/v4/core/tests/locales/tg.test.ts +85 -0
  311. package/node_modules/zod/src/v4/core/tests/locales/tk.test.ts +69 -0
  312. package/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +22 -0
  313. package/node_modules/zod/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  314. package/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +58 -0
  315. package/node_modules/zod/src/v4/core/tests/treeshake.test.ts +51 -0
  316. package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +133 -0
  317. package/node_modules/zod/src/v4/core/to-json-schema.ts +288 -44
  318. package/node_modules/zod/src/v4/core/util.ts +506 -179
  319. package/node_modules/zod/src/v4/core/versions.ts +2 -2
  320. package/node_modules/zod/src/v4/core/visit.ts +193 -0
  321. package/node_modules/zod/src/v4/index.ts +3 -3
  322. package/node_modules/zod/src/v4/locales/ar.ts +5 -0
  323. package/node_modules/zod/src/v4/locales/az.ts +5 -0
  324. package/node_modules/zod/src/v4/locales/be.ts +12 -0
  325. package/node_modules/zod/src/v4/locales/bg.ts +5 -0
  326. package/node_modules/zod/src/v4/locales/bn.ts +123 -0
  327. package/node_modules/zod/src/v4/locales/ca.ts +5 -0
  328. package/node_modules/zod/src/v4/locales/ckb.ts +140 -0
  329. package/node_modules/zod/src/v4/locales/cs.ts +5 -0
  330. package/node_modules/zod/src/v4/locales/da.ts +7 -2
  331. package/node_modules/zod/src/v4/locales/de.ts +5 -0
  332. package/node_modules/zod/src/v4/locales/el.ts +124 -0
  333. package/node_modules/zod/src/v4/locales/en.ts +21 -4
  334. package/node_modules/zod/src/v4/locales/eo.ts +5 -0
  335. package/node_modules/zod/src/v4/locales/es.ts +4 -0
  336. package/node_modules/zod/src/v4/locales/fa.ts +5 -0
  337. package/node_modules/zod/src/v4/locales/fi.ts +5 -0
  338. package/node_modules/zod/src/v4/locales/fr-CA.ts +5 -0
  339. package/node_modules/zod/src/v4/locales/fr.ts +41 -18
  340. package/node_modules/zod/src/v4/locales/gu.ts +123 -0
  341. package/node_modules/zod/src/v4/locales/he.ts +8 -1
  342. package/node_modules/zod/src/v4/locales/hi.ts +126 -0
  343. package/node_modules/zod/src/v4/locales/hr.ts +135 -0
  344. package/node_modules/zod/src/v4/locales/hu.ts +5 -0
  345. package/node_modules/zod/src/v4/locales/hy.ts +11 -0
  346. package/node_modules/zod/src/v4/locales/id.ts +5 -0
  347. package/node_modules/zod/src/v4/locales/index.ts +14 -0
  348. package/node_modules/zod/src/v4/locales/is.ts +5 -0
  349. package/node_modules/zod/src/v4/locales/it.ts +6 -1
  350. package/node_modules/zod/src/v4/locales/ja.ts +5 -0
  351. package/node_modules/zod/src/v4/locales/ka.ts +13 -8
  352. package/node_modules/zod/src/v4/locales/km.ts +5 -0
  353. package/node_modules/zod/src/v4/locales/kn.ts +126 -0
  354. package/node_modules/zod/src/v4/locales/ko.ts +5 -0
  355. package/node_modules/zod/src/v4/locales/lt.ts +4 -0
  356. package/node_modules/zod/src/v4/locales/mk.ts +5 -0
  357. package/node_modules/zod/src/v4/locales/ms.ts +5 -0
  358. package/node_modules/zod/src/v4/locales/ne.ts +128 -0
  359. package/node_modules/zod/src/v4/locales/nl.ts +5 -0
  360. package/node_modules/zod/src/v4/locales/nn.ts +121 -0
  361. package/node_modules/zod/src/v4/locales/no.ts +7 -2
  362. package/node_modules/zod/src/v4/locales/ota.ts +5 -0
  363. package/node_modules/zod/src/v4/locales/pl.ts +5 -0
  364. package/node_modules/zod/src/v4/locales/ps.ts +5 -0
  365. package/node_modules/zod/src/v4/locales/pt-BR.ts +161 -0
  366. package/node_modules/zod/src/v4/locales/pt.ts +101 -58
  367. package/node_modules/zod/src/v4/locales/ro.ts +132 -0
  368. package/node_modules/zod/src/v4/locales/ru.ts +12 -0
  369. package/node_modules/zod/src/v4/locales/sk.ts +123 -0
  370. package/node_modules/zod/src/v4/locales/sl.ts +5 -0
  371. package/node_modules/zod/src/v4/locales/sv.ts +7 -2
  372. package/node_modules/zod/src/v4/locales/ta.ts +5 -0
  373. package/node_modules/zod/src/v4/locales/tg.ts +135 -0
  374. package/node_modules/zod/src/v4/locales/th.ts +5 -0
  375. package/node_modules/zod/src/v4/locales/tk.ts +113 -0
  376. package/node_modules/zod/src/v4/locales/tr.ts +5 -0
  377. package/node_modules/zod/src/v4/locales/uk.ts +5 -0
  378. package/node_modules/zod/src/v4/locales/ur.ts +5 -0
  379. package/node_modules/zod/src/v4/locales/uz.ts +4 -0
  380. package/node_modules/zod/src/v4/locales/vi.ts +5 -0
  381. package/node_modules/zod/src/v4/locales/yo.ts +5 -0
  382. package/node_modules/zod/src/v4/locales/zh-CN.ts +5 -0
  383. package/node_modules/zod/src/v4/locales/zh-TW.ts +5 -0
  384. package/node_modules/zod/src/v4/mini/checks.ts +1 -0
  385. package/node_modules/zod/src/v4/mini/deep-partial.ts +73 -0
  386. package/node_modules/zod/src/v4/mini/external.ts +13 -1
  387. package/node_modules/zod/src/v4/mini/in-out.ts +45 -0
  388. package/node_modules/zod/src/v4/mini/parse.ts +2 -0
  389. package/node_modules/zod/src/v4/mini/schemas.ts +214 -79
  390. package/node_modules/zod/src/v4/mini/tests/apply.test.ts +33 -0
  391. package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +62 -1
  392. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +14 -0
  393. package/node_modules/zod/src/v4/mini/tests/codec.test.ts +54 -1
  394. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +11 -17
  395. package/node_modules/zod/src/v4/mini/tests/cyclic-data.test.ts +84 -0
  396. package/node_modules/zod/src/v4/mini/tests/deep-partial.test.ts +54 -0
  397. package/node_modules/zod/src/v4/mini/tests/error.test.ts +23 -4
  398. package/node_modules/zod/src/v4/mini/tests/functions.test.ts +9 -0
  399. package/node_modules/zod/src/v4/mini/tests/index.test.ts +187 -4
  400. package/node_modules/zod/src/v4/mini/tests/number.test.ts +14 -0
  401. package/node_modules/zod/src/v4/mini/tests/object.test.ts +74 -9
  402. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +67 -1
  403. package/node_modules/zod/src/v4/mini/tests/string.test.ts +49 -0
  404. package/node_modules/zod/v3/ZodError.cjs +41 -12
  405. package/node_modules/zod/v3/ZodError.d.cts +1 -1
  406. package/node_modules/zod/v3/ZodError.d.ts +1 -1
  407. package/node_modules/zod/v3/ZodError.js +22 -12
  408. package/node_modules/zod/v3/errors.cjs +19 -0
  409. package/node_modules/zod/v3/external.cjs +19 -0
  410. package/node_modules/zod/v3/helpers/enumUtil.cjs +19 -0
  411. package/node_modules/zod/v3/helpers/errorUtil.cjs +20 -1
  412. package/node_modules/zod/v3/helpers/errorUtil.js +1 -1
  413. package/node_modules/zod/v3/helpers/parseUtil.cjs +19 -0
  414. package/node_modules/zod/v3/helpers/partialUtil.cjs +19 -0
  415. package/node_modules/zod/v3/helpers/typeAliases.cjs +19 -0
  416. package/node_modules/zod/v3/helpers/util.cjs +19 -0
  417. package/node_modules/zod/v3/index.cjs +19 -0
  418. package/node_modules/zod/v3/package.json +2 -1
  419. package/node_modules/zod/v3/standard-schema.cjs +19 -0
  420. package/node_modules/zod/v3/types.cjs +26 -5
  421. package/node_modules/zod/v3/types.js +7 -5
  422. package/node_modules/zod/v4/classic/checks.cjs +21 -1
  423. package/node_modules/zod/v4/classic/checks.d.cts +1 -1
  424. package/node_modules/zod/v4/classic/checks.d.ts +1 -1
  425. package/node_modules/zod/v4/classic/checks.js +1 -1
  426. package/node_modules/zod/v4/classic/coerce.cjs +19 -0
  427. package/node_modules/zod/v4/classic/compat.cjs +19 -0
  428. package/node_modules/zod/v4/classic/compat.d.cts +9 -11
  429. package/node_modules/zod/v4/classic/compat.d.ts +9 -11
  430. package/node_modules/zod/v4/classic/deep-partial.cjs +58 -0
  431. package/node_modules/zod/v4/classic/deep-partial.d.cts +14 -0
  432. package/node_modules/zod/v4/classic/deep-partial.d.ts +14 -0
  433. package/node_modules/zod/v4/classic/deep-partial.js +13 -0
  434. package/node_modules/zod/v4/classic/errors.cjs +62 -34
  435. package/node_modules/zod/v4/classic/errors.d.cts +3 -4
  436. package/node_modules/zod/v4/classic/errors.d.ts +3 -4
  437. package/node_modules/zod/v4/classic/errors.js +44 -35
  438. package/node_modules/zod/v4/classic/external.cjs +51 -27
  439. package/node_modules/zod/v4/classic/external.d.cts +6 -2
  440. package/node_modules/zod/v4/classic/external.d.ts +6 -2
  441. package/node_modules/zod/v4/classic/external.js +5 -8
  442. package/node_modules/zod/v4/classic/from-json-schema.cjs +394 -78
  443. package/node_modules/zod/v4/classic/from-json-schema.js +375 -78
  444. package/node_modules/zod/v4/classic/in-out.cjs +82 -0
  445. package/node_modules/zod/v4/classic/in-out.d.cts +8 -0
  446. package/node_modules/zod/v4/classic/in-out.d.ts +8 -0
  447. package/node_modules/zod/v4/classic/in-out.js +36 -0
  448. package/node_modules/zod/v4/classic/index.cjs +21 -2
  449. package/node_modules/zod/v4/classic/index.d.cts +1 -2
  450. package/node_modules/zod/v4/classic/index.d.ts +1 -2
  451. package/node_modules/zod/v4/classic/index.js +2 -2
  452. package/node_modules/zod/v4/classic/iso.cjs +30 -22
  453. package/node_modules/zod/v4/classic/iso.d.cts +2 -17
  454. package/node_modules/zod/v4/classic/iso.d.ts +2 -17
  455. package/node_modules/zod/v4/classic/iso.js +2 -17
  456. package/node_modules/zod/v4/classic/package.json +2 -1
  457. package/node_modules/zod/v4/classic/parse.cjs +23 -1
  458. package/node_modules/zod/v4/classic/parse.d.cts +17 -4
  459. package/node_modules/zod/v4/classic/parse.d.ts +17 -4
  460. package/node_modules/zod/v4/classic/parse.js +1 -0
  461. package/node_modules/zod/v4/classic/schemas.cjs +629 -225
  462. package/node_modules/zod/v4/classic/schemas.d.cts +104 -27
  463. package/node_modules/zod/v4/classic/schemas.d.ts +104 -27
  464. package/node_modules/zod/v4/classic/schemas.js +601 -223
  465. package/node_modules/zod/v4/core/api.cjs +73 -26
  466. package/node_modules/zod/v4/core/api.d.cts +40 -9
  467. package/node_modules/zod/v4/core/api.d.ts +40 -9
  468. package/node_modules/zod/v4/core/api.js +51 -26
  469. package/node_modules/zod/v4/core/checks.cjs +88 -128
  470. package/node_modules/zod/v4/core/checks.d.cts +30 -14
  471. package/node_modules/zod/v4/core/checks.d.ts +30 -14
  472. package/node_modules/zod/v4/core/checks.js +68 -127
  473. package/node_modules/zod/v4/core/compile.cjs +1916 -0
  474. package/node_modules/zod/v4/core/compile.d.cts +65 -0
  475. package/node_modules/zod/v4/core/compile.d.ts +65 -0
  476. package/node_modules/zod/v4/core/compile.js +1866 -0
  477. package/node_modules/zod/v4/core/core.cjs +104 -20
  478. package/node_modules/zod/v4/core/core.d.cts +16 -4
  479. package/node_modules/zod/v4/core/core.d.ts +16 -4
  480. package/node_modules/zod/v4/core/core.js +87 -22
  481. package/node_modules/zod/v4/core/doc.cjs +31 -9
  482. package/node_modules/zod/v4/core/doc.d.cts +3 -1
  483. package/node_modules/zod/v4/core/doc.d.ts +3 -1
  484. package/node_modules/zod/v4/core/doc.js +12 -9
  485. package/node_modules/zod/v4/core/errors.cjs +146 -42
  486. package/node_modules/zod/v4/core/errors.d.cts +5 -0
  487. package/node_modules/zod/v4/core/errors.d.ts +5 -0
  488. package/node_modules/zod/v4/core/errors.js +127 -42
  489. package/node_modules/zod/v4/core/index.cjs +24 -1
  490. package/node_modules/zod/v4/core/index.d.cts +3 -0
  491. package/node_modules/zod/v4/core/index.d.ts +3 -0
  492. package/node_modules/zod/v4/core/index.js +3 -0
  493. package/node_modules/zod/v4/core/json-schema-generator.cjs +24 -1
  494. package/node_modules/zod/v4/core/json-schema-generator.d.cts +2 -2
  495. package/node_modules/zod/v4/core/json-schema-generator.d.ts +2 -2
  496. package/node_modules/zod/v4/core/json-schema-generator.js +6 -2
  497. package/node_modules/zod/v4/core/json-schema-processors.cjs +454 -173
  498. package/node_modules/zod/v4/core/json-schema-processors.d.cts +16 -0
  499. package/node_modules/zod/v4/core/json-schema-processors.d.ts +16 -0
  500. package/node_modules/zod/v4/core/json-schema-processors.js +413 -175
  501. package/node_modules/zod/v4/core/json-schema.cjs +19 -0
  502. package/node_modules/zod/v4/core/json-schema.d.cts +2 -1
  503. package/node_modules/zod/v4/core/json-schema.d.ts +2 -1
  504. package/node_modules/zod/v4/core/memoizer.cjs +360 -0
  505. package/node_modules/zod/v4/core/memoizer.d.cts +15 -0
  506. package/node_modules/zod/v4/core/memoizer.d.ts +15 -0
  507. package/node_modules/zod/v4/core/memoizer.js +311 -0
  508. package/node_modules/zod/v4/core/package.json +2 -1
  509. package/node_modules/zod/v4/core/parse.cjs +151 -49
  510. package/node_modules/zod/v4/core/parse.d.cts +14 -11
  511. package/node_modules/zod/v4/core/parse.d.ts +14 -11
  512. package/node_modules/zod/v4/core/parse.js +130 -48
  513. package/node_modules/zod/v4/core/regexes.cjs +61 -18
  514. package/node_modules/zod/v4/core/regexes.d.cts +11 -0
  515. package/node_modules/zod/v4/core/regexes.d.ts +11 -0
  516. package/node_modules/zod/v4/core/regexes.js +39 -16
  517. package/node_modules/zod/v4/core/registries.cjs +19 -0
  518. package/node_modules/zod/v4/core/registries.js +2 -2
  519. package/node_modules/zod/v4/core/schemas.cjs +957 -382
  520. package/node_modules/zod/v4/core/schemas.d.cts +154 -25
  521. package/node_modules/zod/v4/core/schemas.d.ts +154 -25
  522. package/node_modules/zod/v4/core/schemas.js +925 -382
  523. package/node_modules/zod/v4/core/standard-schema.cjs +19 -0
  524. package/node_modules/zod/v4/core/to-json-schema.cjs +275 -40
  525. package/node_modules/zod/v4/core/to-json-schema.d.cts +45 -5
  526. package/node_modules/zod/v4/core/to-json-schema.d.ts +45 -5
  527. package/node_modules/zod/v4/core/to-json-schema.js +253 -39
  528. package/node_modules/zod/v4/core/util.cjs +428 -174
  529. package/node_modules/zod/v4/core/util.d.cts +82 -1
  530. package/node_modules/zod/v4/core/util.d.ts +82 -1
  531. package/node_modules/zod/v4/core/util.js +397 -175
  532. package/node_modules/zod/v4/core/versions.cjs +21 -2
  533. package/node_modules/zod/v4/core/versions.d.cts +1 -1
  534. package/node_modules/zod/v4/core/versions.d.ts +1 -1
  535. package/node_modules/zod/v4/core/versions.js +2 -2
  536. package/node_modules/zod/v4/core/visit.cjs +214 -0
  537. package/node_modules/zod/v4/core/visit.d.cts +30 -0
  538. package/node_modules/zod/v4/core/visit.d.ts +30 -0
  539. package/node_modules/zod/v4/core/visit.js +169 -0
  540. package/node_modules/zod/v4/index.cjs +34 -5
  541. package/node_modules/zod/v4/index.d.cts +2 -2
  542. package/node_modules/zod/v4/index.d.ts +2 -2
  543. package/node_modules/zod/v4/index.js +3 -2
  544. package/node_modules/zod/v4/locales/ar.cjs +5 -0
  545. package/node_modules/zod/v4/locales/ar.js +5 -0
  546. package/node_modules/zod/v4/locales/az.cjs +5 -0
  547. package/node_modules/zod/v4/locales/az.js +5 -0
  548. package/node_modules/zod/v4/locales/be.cjs +12 -0
  549. package/node_modules/zod/v4/locales/be.js +12 -0
  550. package/node_modules/zod/v4/locales/bg.cjs +5 -0
  551. package/node_modules/zod/v4/locales/bg.js +5 -0
  552. package/node_modules/zod/v4/locales/bn.cjs +140 -0
  553. package/node_modules/zod/v4/locales/bn.d.cts +5 -0
  554. package/node_modules/zod/v4/locales/bn.d.ts +4 -0
  555. package/node_modules/zod/v4/locales/bn.js +113 -0
  556. package/node_modules/zod/v4/locales/ca.cjs +5 -0
  557. package/node_modules/zod/v4/locales/ca.js +5 -0
  558. package/node_modules/zod/v4/locales/ckb.cjs +160 -0
  559. package/node_modules/zod/v4/locales/ckb.d.cts +5 -0
  560. package/node_modules/zod/v4/locales/ckb.d.ts +4 -0
  561. package/node_modules/zod/v4/locales/ckb.js +133 -0
  562. package/node_modules/zod/v4/locales/cs.cjs +5 -0
  563. package/node_modules/zod/v4/locales/cs.js +5 -0
  564. package/node_modules/zod/v4/locales/da.cjs +7 -2
  565. package/node_modules/zod/v4/locales/da.js +7 -2
  566. package/node_modules/zod/v4/locales/de.cjs +5 -0
  567. package/node_modules/zod/v4/locales/de.js +5 -0
  568. package/node_modules/zod/v4/locales/el.cjs +139 -0
  569. package/node_modules/zod/v4/locales/el.d.cts +5 -0
  570. package/node_modules/zod/v4/locales/el.d.ts +4 -0
  571. package/node_modules/zod/v4/locales/el.js +112 -0
  572. package/node_modules/zod/v4/locales/en.cjs +20 -4
  573. package/node_modules/zod/v4/locales/en.js +20 -4
  574. package/node_modules/zod/v4/locales/eo.cjs +5 -0
  575. package/node_modules/zod/v4/locales/eo.js +5 -0
  576. package/node_modules/zod/v4/locales/es.cjs +4 -0
  577. package/node_modules/zod/v4/locales/es.js +4 -0
  578. package/node_modules/zod/v4/locales/fa.cjs +5 -0
  579. package/node_modules/zod/v4/locales/fa.js +5 -0
  580. package/node_modules/zod/v4/locales/fi.cjs +5 -0
  581. package/node_modules/zod/v4/locales/fi.js +5 -0
  582. package/node_modules/zod/v4/locales/fr-CA.cjs +5 -0
  583. package/node_modules/zod/v4/locales/fr-CA.js +5 -0
  584. package/node_modules/zod/v4/locales/fr.cjs +38 -17
  585. package/node_modules/zod/v4/locales/fr.js +38 -17
  586. package/node_modules/zod/v4/locales/gu.cjs +140 -0
  587. package/node_modules/zod/v4/locales/gu.d.cts +5 -0
  588. package/node_modules/zod/v4/locales/gu.d.ts +4 -0
  589. package/node_modules/zod/v4/locales/gu.js +113 -0
  590. package/node_modules/zod/v4/locales/he.cjs +7 -0
  591. package/node_modules/zod/v4/locales/he.js +7 -0
  592. package/node_modules/zod/v4/locales/hi.cjs +138 -0
  593. package/node_modules/zod/v4/locales/hi.d.cts +5 -0
  594. package/node_modules/zod/v4/locales/hi.d.ts +4 -0
  595. package/node_modules/zod/v4/locales/hi.js +111 -0
  596. package/node_modules/zod/v4/locales/hr.cjs +153 -0
  597. package/node_modules/zod/v4/locales/hr.d.cts +5 -0
  598. package/node_modules/zod/v4/locales/hr.d.ts +4 -0
  599. package/node_modules/zod/v4/locales/hr.js +126 -0
  600. package/node_modules/zod/v4/locales/hu.cjs +5 -0
  601. package/node_modules/zod/v4/locales/hu.js +5 -0
  602. package/node_modules/zod/v4/locales/hy.cjs +11 -0
  603. package/node_modules/zod/v4/locales/hy.js +11 -0
  604. package/node_modules/zod/v4/locales/id.cjs +5 -0
  605. package/node_modules/zod/v4/locales/id.js +5 -0
  606. package/node_modules/zod/v4/locales/index.cjs +49 -1
  607. package/node_modules/zod/v4/locales/index.d.cts +14 -0
  608. package/node_modules/zod/v4/locales/index.d.ts +14 -0
  609. package/node_modules/zod/v4/locales/index.js +14 -0
  610. package/node_modules/zod/v4/locales/is.cjs +5 -0
  611. package/node_modules/zod/v4/locales/is.js +5 -0
  612. package/node_modules/zod/v4/locales/it.cjs +6 -1
  613. package/node_modules/zod/v4/locales/it.js +6 -1
  614. package/node_modules/zod/v4/locales/ja.cjs +5 -0
  615. package/node_modules/zod/v4/locales/ja.js +5 -0
  616. package/node_modules/zod/v4/locales/ka.cjs +13 -8
  617. package/node_modules/zod/v4/locales/ka.js +13 -8
  618. package/node_modules/zod/v4/locales/km.cjs +5 -0
  619. package/node_modules/zod/v4/locales/km.js +5 -0
  620. package/node_modules/zod/v4/locales/kn.cjs +143 -0
  621. package/node_modules/zod/v4/locales/kn.d.cts +5 -0
  622. package/node_modules/zod/v4/locales/kn.d.ts +4 -0
  623. package/node_modules/zod/v4/locales/kn.js +116 -0
  624. package/node_modules/zod/v4/locales/ko.cjs +5 -0
  625. package/node_modules/zod/v4/locales/ko.js +5 -0
  626. package/node_modules/zod/v4/locales/lt.cjs +4 -0
  627. package/node_modules/zod/v4/locales/lt.js +4 -0
  628. package/node_modules/zod/v4/locales/mk.cjs +5 -0
  629. package/node_modules/zod/v4/locales/mk.js +5 -0
  630. package/node_modules/zod/v4/locales/ms.cjs +5 -0
  631. package/node_modules/zod/v4/locales/ms.js +5 -0
  632. package/node_modules/zod/v4/locales/ne.cjs +138 -0
  633. package/node_modules/zod/v4/locales/ne.d.cts +5 -0
  634. package/node_modules/zod/v4/locales/ne.d.ts +4 -0
  635. package/node_modules/zod/v4/locales/ne.js +111 -0
  636. package/node_modules/zod/v4/locales/nl.cjs +5 -0
  637. package/node_modules/zod/v4/locales/nl.js +5 -0
  638. package/node_modules/zod/v4/locales/nn.cjs +140 -0
  639. package/node_modules/zod/v4/locales/nn.d.cts +5 -0
  640. package/node_modules/zod/v4/locales/nn.d.ts +4 -0
  641. package/node_modules/zod/v4/locales/nn.js +113 -0
  642. package/node_modules/zod/v4/locales/no.cjs +7 -2
  643. package/node_modules/zod/v4/locales/no.js +7 -2
  644. package/node_modules/zod/v4/locales/ota.cjs +5 -0
  645. package/node_modules/zod/v4/locales/ota.js +5 -0
  646. package/node_modules/zod/v4/locales/package.json +2 -1
  647. package/node_modules/zod/v4/locales/pl.cjs +5 -0
  648. package/node_modules/zod/v4/locales/pl.js +5 -0
  649. package/node_modules/zod/v4/locales/ps.cjs +5 -0
  650. package/node_modules/zod/v4/locales/ps.js +5 -0
  651. package/node_modules/zod/v4/locales/pt-BR.cjs +170 -0
  652. package/node_modules/zod/v4/locales/pt-BR.d.cts +5 -0
  653. package/node_modules/zod/v4/locales/pt-BR.d.ts +4 -0
  654. package/node_modules/zod/v4/locales/pt-BR.js +143 -0
  655. package/node_modules/zod/v4/locales/pt.cjs +89 -55
  656. package/node_modules/zod/v4/locales/pt.js +89 -55
  657. package/node_modules/zod/v4/locales/ro.cjs +149 -0
  658. package/node_modules/zod/v4/locales/ro.d.cts +5 -0
  659. package/node_modules/zod/v4/locales/ro.d.ts +4 -0
  660. package/node_modules/zod/v4/locales/ro.js +122 -0
  661. package/node_modules/zod/v4/locales/ru.cjs +12 -0
  662. package/node_modules/zod/v4/locales/ru.js +12 -0
  663. package/node_modules/zod/v4/locales/sk.cjs +143 -0
  664. package/node_modules/zod/v4/locales/sk.d.cts +5 -0
  665. package/node_modules/zod/v4/locales/sk.d.ts +4 -0
  666. package/node_modules/zod/v4/locales/sk.js +116 -0
  667. package/node_modules/zod/v4/locales/sl.cjs +5 -0
  668. package/node_modules/zod/v4/locales/sl.js +5 -0
  669. package/node_modules/zod/v4/locales/sv.cjs +7 -2
  670. package/node_modules/zod/v4/locales/sv.js +7 -2
  671. package/node_modules/zod/v4/locales/ta.cjs +5 -0
  672. package/node_modules/zod/v4/locales/ta.js +5 -0
  673. package/node_modules/zod/v4/locales/tg.cjs +144 -0
  674. package/node_modules/zod/v4/locales/tg.d.cts +5 -0
  675. package/node_modules/zod/v4/locales/tg.d.ts +4 -0
  676. package/node_modules/zod/v4/locales/tg.js +117 -0
  677. package/node_modules/zod/v4/locales/th.cjs +5 -0
  678. package/node_modules/zod/v4/locales/th.js +5 -0
  679. package/node_modules/zod/v4/locales/tk.cjs +134 -0
  680. package/node_modules/zod/v4/locales/tk.d.cts +5 -0
  681. package/node_modules/zod/v4/locales/tk.d.ts +4 -0
  682. package/node_modules/zod/v4/locales/tk.js +107 -0
  683. package/node_modules/zod/v4/locales/tr.cjs +5 -0
  684. package/node_modules/zod/v4/locales/tr.js +5 -0
  685. package/node_modules/zod/v4/locales/uk.cjs +5 -0
  686. package/node_modules/zod/v4/locales/uk.js +5 -0
  687. package/node_modules/zod/v4/locales/ur.cjs +5 -0
  688. package/node_modules/zod/v4/locales/ur.js +5 -0
  689. package/node_modules/zod/v4/locales/uz.cjs +4 -0
  690. package/node_modules/zod/v4/locales/uz.js +4 -0
  691. package/node_modules/zod/v4/locales/vi.cjs +5 -0
  692. package/node_modules/zod/v4/locales/vi.js +5 -0
  693. package/node_modules/zod/v4/locales/yo.cjs +5 -0
  694. package/node_modules/zod/v4/locales/yo.js +5 -0
  695. package/node_modules/zod/v4/locales/zh-CN.cjs +5 -0
  696. package/node_modules/zod/v4/locales/zh-CN.js +5 -0
  697. package/node_modules/zod/v4/locales/zh-TW.cjs +5 -0
  698. package/node_modules/zod/v4/locales/zh-TW.js +5 -0
  699. package/node_modules/zod/v4/mini/checks.cjs +21 -1
  700. package/node_modules/zod/v4/mini/checks.d.cts +1 -1
  701. package/node_modules/zod/v4/mini/checks.d.ts +1 -1
  702. package/node_modules/zod/v4/mini/checks.js +1 -1
  703. package/node_modules/zod/v4/mini/coerce.cjs +19 -0
  704. package/node_modules/zod/v4/mini/deep-partial.cjs +58 -0
  705. package/node_modules/zod/v4/mini/deep-partial.d.cts +14 -0
  706. package/node_modules/zod/v4/mini/deep-partial.d.ts +14 -0
  707. package/node_modules/zod/v4/mini/deep-partial.js +13 -0
  708. package/node_modules/zod/v4/mini/external.cjs +33 -1
  709. package/node_modules/zod/v4/mini/external.d.cts +6 -2
  710. package/node_modules/zod/v4/mini/external.d.ts +6 -2
  711. package/node_modules/zod/v4/mini/external.js +3 -1
  712. package/node_modules/zod/v4/mini/in-out.cjs +82 -0
  713. package/node_modules/zod/v4/mini/in-out.d.cts +8 -0
  714. package/node_modules/zod/v4/mini/in-out.d.ts +8 -0
  715. package/node_modules/zod/v4/mini/in-out.js +36 -0
  716. package/node_modules/zod/v4/mini/index.cjs +19 -0
  717. package/node_modules/zod/v4/mini/iso.cjs +19 -0
  718. package/node_modules/zod/v4/mini/package.json +2 -1
  719. package/node_modules/zod/v4/mini/parse.cjs +22 -1
  720. package/node_modules/zod/v4/mini/parse.d.cts +1 -1
  721. package/node_modules/zod/v4/mini/parse.d.ts +1 -1
  722. package/node_modules/zod/v4/mini/parse.js +1 -1
  723. package/node_modules/zod/v4/mini/schemas.cjs +151 -50
  724. package/node_modules/zod/v4/mini/schemas.d.cts +75 -22
  725. package/node_modules/zod/v4/mini/schemas.d.ts +75 -22
  726. package/node_modules/zod/v4/mini/schemas.js +125 -48
  727. package/node_modules/zod/v4/package.json +2 -1
  728. package/node_modules/zod/v4-mini/index.cjs +19 -0
  729. package/node_modules/zod/v4-mini/package.json +2 -1
  730. package/package.json +16 -14
  731. package/dist/trpc/routers/searchees.d.ts +0 -51
  732. package/dist/trpc/routers/searchees.js +0 -156
  733. package/dist/trpc/routers/searchees.js.map +0 -1
  734. package/dist/webui/assets/ClientOnly-CzZIsGML.js +0 -1
  735. package/dist/webui/assets/DeleteOption-dxKSbv6N.js +0 -1
  736. package/dist/webui/assets/FieldInfo-FLjtPgL4.js +0 -1
  737. package/dist/webui/assets/Page-C7KClZ28.js +0 -1
  738. package/dist/webui/assets/array-field-DGB7Lbh7.js +0 -1
  739. package/dist/webui/assets/badge-hukNSIir.js +0 -1
  740. package/dist/webui/assets/button-1cIaa9Lf.js +0 -1
  741. package/dist/webui/assets/check-CUrWQ2C7.js +0 -1
  742. package/dist/webui/assets/chevron-down-CVVogpPh.js +0 -1
  743. package/dist/webui/assets/clients-CHdgqO4r.js +0 -1
  744. package/dist/webui/assets/connect-Cr6Q3W8U.js +0 -2
  745. package/dist/webui/assets/createLucideIcon-zYRS_Hrv.js +0 -1
  746. package/dist/webui/assets/debug-CEmoQ2W_.js +0 -1
  747. package/dist/webui/assets/directories-CNuHKfHz.js +0 -1
  748. package/dist/webui/assets/dist-Bbmh5Du9.js +0 -1
  749. package/dist/webui/assets/dist-DhH_lYkz.js +0 -1
  750. package/dist/webui/assets/dist-DzdkRn7I.js +0 -1
  751. package/dist/webui/assets/dist-b2njvUJz.js +0 -41
  752. package/dist/webui/assets/dist-d-Lt00zD.js +0 -1
  753. package/dist/webui/assets/duration-field-CnlQcr37.js +0 -1
  754. package/dist/webui/assets/form-context-B-ekdUc0.js +0 -1
  755. package/dist/webui/assets/form-validation-context-CPAPOloL.js +0 -1
  756. package/dist/webui/assets/general-Cs8dEydJ.js +0 -1
  757. package/dist/webui/assets/health-DugF7R6A.js +0 -1
  758. package/dist/webui/assets/index-DhV1H9AB.css +0 -2
  759. package/dist/webui/assets/index-DinSQfHc.js +0 -11
  760. package/dist/webui/assets/input-CsfmMUT5.js +0 -1
  761. package/dist/webui/assets/jobs-Cr1xWWzM.js +0 -1
  762. package/dist/webui/assets/library-BNsctrbc.js +0 -1
  763. package/dist/webui/assets/loader-circle-BQbzoYGJ.js +0 -1
  764. package/dist/webui/assets/logs-C1l3cu_j.js +0 -1
  765. package/dist/webui/assets/number-field-Ce3QdLSz.js +0 -1
  766. package/dist/webui/assets/react-dom-mEftaaxx.js +0 -1
  767. package/dist/webui/assets/required-indicator-BXf2UzTH.js +0 -1
  768. package/dist/webui/assets/routes-Bw2nXmFg.js +0 -1
  769. package/dist/webui/assets/search-D9W5vk_0.js +0 -1
  770. package/dist/webui/assets/select-CZn10WME.js +0 -1
  771. package/dist/webui/assets/select-field-DozTirAZ.js +0 -1
  772. package/dist/webui/assets/settings-BXbhXNDK.js +0 -1
  773. package/dist/webui/assets/sidebar-y9WJu7Jw.js +0 -5
  774. package/dist/webui/assets/submit-button-CBOzR0f_.js +0 -1
  775. package/dist/webui/assets/switch-D4S9As9u.js +0 -1
  776. package/dist/webui/assets/switch-field-2E9ctvy_.js +0 -1
  777. package/dist/webui/assets/table-B1Y18B60.js +0 -1
  778. package/dist/webui/assets/text-field-DV4EP-I8.js +0 -1
  779. package/dist/webui/assets/time-DjUFOA4D.js +0 -1
  780. package/dist/webui/assets/trackers-ULhLxA6-.js +0 -7
  781. package/dist/webui/assets/use-settings-form-submit-D87nmJRy.js +0 -79
  782. package/dist/webui/assets/useBaseQuery-BvrWhgOK.js +0 -1
  783. package/dist/webui/assets/useRouterState-CZfD5Xdv.js +0 -1
  784. package/dist/webui/assets/useStore-CusP06SD.js +0 -1
  785. package/node_modules/zod/src/v4/core/config.ts +0 -15
@@ -1,10 +1,11 @@
1
- import type { $ZodTypeDiscriminable } from "./api.js";
2
1
  import * as checks from "./checks.js";
2
+ import type { $ZodNumberFormats } from "./checks.js";
3
+ import type { $ZodBigIntFormats } from "./checks.js";
3
4
  import * as core from "./core.js";
4
5
  import { Doc } from "./doc.js";
5
6
  import type * as errors from "./errors.js";
6
7
  import type * as JSONSchema from "./json-schema.js";
7
- import { parse, parseAsync, safeParse, safeParseAsync } from "./parse.js";
8
+ import { parse, parseAsync } from "./parse.js";
8
9
  import * as regexes from "./regexes.js";
9
10
  import type { StandardSchemaV1 } from "./standard-schema.js";
10
11
  import type { ProcessParams, ToJSONSchemaContext } from "./to-json-schema.js";
@@ -29,13 +30,25 @@ export interface ParseContextInternal<T extends errors.$ZodIssueBase = never> ex
29
30
  readonly async?: boolean | undefined;
30
31
  readonly direction?: "forward" | "backward";
31
32
  readonly skipChecks?: boolean;
33
+ /** Set only by `validate`/`validateAsync`. A container may stop before its next child, never inside one, so a map entry and a tuple's fixed items parse whole. */
34
+ readonly abortEarly?: boolean;
35
+ }
36
+
37
+ /** Gives a container cycle support: `attach` wraps its parse, and `alloc` registers the object it builds into before any child is parsed so a reference back to the same input resolves to it. */
38
+ export interface $ZodMemoizer {
39
+ attach(inst: $ZodType): void;
40
+ guard(inst: $ZodType): void;
41
+ alloc<T extends object>(inst: $ZodType, payload: ParsePayload, empty: T, ctx: ParseContextInternal): T;
32
42
  }
33
43
 
34
44
  export interface ParsePayload<T = unknown> {
35
45
  value: T;
36
46
  issues: errors.$ZodRawIssue[];
37
- /** A may to mark a whole payload as aborted. Used in codecs/pipes. */
47
+ /** A way to mark a whole payload as aborted. Used in codecs/pipes. */
38
48
  aborted?: boolean;
49
+ /** @internal Set when the value came from a repeat visit to a node still being
50
+ * parsed. Its checks run on the node itself, against the finished value. */
51
+ memo?: boolean | undefined;
39
52
  }
40
53
 
41
54
  export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>;
@@ -115,8 +128,13 @@ export interface _$ZodTypeInternals {
115
128
  * @default Required
116
129
  */
117
130
 
118
- /** @internal */
119
- optin?: "optional" | undefined;
131
+ /** @internal Three rungs, each strictly stronger than the last:
132
+ * undefined — required; the container may not omit this slot
133
+ * "optional" — the container may omit it; nothing is supplied in its place
134
+ * "defaulted" — the container may omit it AND this schema substitutes a value
135
+ * Consumers asking "may the slot be absent?" test `!== undefined`.
136
+ * $ZodOptional asks the stronger question and tests `=== "defaulted"`. */
137
+ optin?: "optional" | "defaulted" | undefined;
120
138
  /** @internal */
121
139
  optout?: "optional" | undefined;
122
140
 
@@ -182,136 +200,164 @@ export interface $ZodType<
182
200
  export interface _$ZodType<T extends $ZodTypeInternals = $ZodTypeInternals>
183
201
  extends $ZodType<T["output"], T["input"], T> {}
184
202
 
185
- export const $ZodType: core.$constructor<$ZodType> = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def) => {
186
- inst ??= {} as any;
187
-
188
- inst._zod.def = def; // set _def property
189
- inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
190
- inst._zod.version = version;
191
-
192
- const checks = [...(inst._zod.def.checks ?? [])];
193
-
194
- // if inst is itself a checks.$ZodCheck, run it as a check
195
- if (inst._zod.traits.has("$ZodCheck")) {
196
- checks.unshift(inst as any);
197
- }
198
-
199
- for (const ch of checks) {
200
- for (const fn of ch._zod.onattach) {
201
- fn(inst);
203
+ export const $ZodType: core.$constructor<$ZodType> = /*@__PURE__*/ core.$constructor<$ZodType>(
204
+ "$ZodType",
205
+ (inst, def) => {
206
+ inst ??= {} as any;
207
+
208
+ inst._zod.def = def; // set _def property
209
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
210
+ inst._zod.version = version;
211
+
212
+ const defChecks = inst._zod.def.checks;
213
+ // if inst is itself a checks.$ZodCheck, run it as a check
214
+ const checks: checks.$ZodCheck<never>[] = inst._zod.traits.has("$ZodCheck")
215
+ ? [inst as any, ...(defChecks ?? [])]
216
+ : defChecks?.length
217
+ ? [...defChecks]
218
+ : [];
219
+
220
+ for (const ch of checks) {
221
+ for (const fn of ch._zod.onattach) {
222
+ fn(inst);
223
+ }
202
224
  }
203
- }
204
225
 
205
- if (checks.length === 0) {
206
- // deferred initializer
207
- // inst._zod.parse is not yet defined
208
- inst._zod.deferred ??= [];
209
- inst._zod.deferred?.push(() => {
210
- inst._zod.run = inst._zod.parse;
211
- });
212
- } else {
213
- const runChecks = (
214
- payload: ParsePayload,
215
- checks: checks.$ZodCheck<never>[],
216
- ctx?: ParseContextInternal | undefined
217
- ): util.MaybeAsync<ParsePayload> => {
218
- let isAborted = util.aborted(payload);
219
-
220
- let asyncResult!: Promise<unknown> | undefined;
221
- for (const ch of checks) {
222
- if (ch._zod.def.when) {
223
- const shouldRun = ch._zod.def.when(payload);
224
- if (!shouldRun) continue;
225
- } else if (isAborted) {
226
- continue;
227
- }
228
- const currLen = payload.issues.length;
229
- const _ = ch._zod.check(payload as any) as any as ParsePayload;
226
+ if (checks.length === 0) {
227
+ // deferred initializer inst._zod.parse is not yet defined
228
+ inst._zod.deferred ??= [];
229
+ inst._zod.deferred?.push(() => {
230
+ inst._zod.run = inst._zod.parse;
231
+ });
232
+ } else {
233
+ const runChecks = (
234
+ payload: ParsePayload,
235
+ checks: checks.$ZodCheck<never>[],
236
+ ctx?: ParseContextInternal | undefined
237
+ ): util.MaybeAsync<ParsePayload> => {
238
+ if (payload.memo) return payload;
239
+
240
+ let isAborted = util.aborted(payload);
241
+
242
+ let asyncResult!: Promise<unknown> | undefined;
243
+ for (const ch of checks) {
244
+ if (ch._zod.def.when) {
245
+ if (util.explicitlyAborted(payload)) continue;
246
+ const shouldRun = ch._zod.def.when(payload);
247
+ if (!shouldRun) continue;
248
+ } else if (isAborted) {
249
+ continue;
250
+ }
251
+ const currLen = payload.issues.length;
252
+ const _ = ch._zod.check(payload as any) as any as ParsePayload;
230
253
 
231
- if (_ instanceof Promise && ctx?.async === false) {
232
- throw new core.$ZodAsyncError();
233
- }
234
- if (asyncResult || _ instanceof Promise) {
235
- asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
236
- await _;
254
+ if (_ instanceof Promise && ctx?.async === false) {
255
+ throw new core.$ZodAsyncError();
256
+ }
257
+ if (asyncResult || _ instanceof Promise) {
258
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
259
+ await _;
260
+ const nextLen = payload.issues.length;
261
+ if (nextLen === currLen) return;
262
+ util.attachSchema(payload.issues, currLen, inst);
263
+ if (!isAborted) isAborted = util.aborted(payload, currLen);
264
+ });
265
+ } else {
237
266
  const nextLen = payload.issues.length;
238
- if (nextLen === currLen) return;
267
+ if (nextLen === currLen) continue;
268
+ util.attachSchema(payload.issues, currLen, inst);
239
269
  if (!isAborted) isAborted = util.aborted(payload, currLen);
270
+ }
271
+ }
272
+
273
+ if (asyncResult) {
274
+ return asyncResult.then(() => {
275
+ return payload;
240
276
  });
241
- } else {
242
- const nextLen = payload.issues.length;
243
- if (nextLen === currLen) continue;
244
- if (!isAborted) isAborted = util.aborted(payload, currLen);
245
277
  }
246
- }
278
+ return payload;
279
+ };
247
280
 
248
- if (asyncResult) {
249
- return asyncResult.then(() => {
250
- return payload;
251
- });
252
- }
253
- return payload;
254
- };
281
+ const handleCanaryResult = (canary: ParsePayload, payload: ParsePayload, ctx: ParseContextInternal) => {
282
+ // abort if the canary is aborted
283
+ if (util.aborted(canary)) {
284
+ canary.aborted = true;
285
+ return canary;
286
+ }
255
287
 
256
- const handleCanaryResult = (canary: ParsePayload, payload: ParsePayload, ctx: ParseContextInternal) => {
257
- // abort if the canary is aborted
258
- if (util.aborted(canary)) {
259
- canary.aborted = true;
260
- return canary;
261
- }
288
+ // run checks first, then
289
+ const checkResult = runChecks(payload, checks, ctx);
290
+ if (checkResult instanceof Promise) {
291
+ if (ctx.async === false) throw new core.$ZodAsyncError();
292
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
293
+ }
294
+ return inst._zod.parse(checkResult, ctx);
295
+ };
262
296
 
263
- // run checks first, then
264
- const checkResult = runChecks(payload, checks, ctx);
265
- if (checkResult instanceof Promise) {
266
- if (ctx.async === false) throw new core.$ZodAsyncError();
267
- return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
268
- }
269
- return inst._zod.parse(checkResult, ctx);
270
- };
297
+ inst._zod.run = (payload, ctx) => {
298
+ if (ctx.skipChecks) {
299
+ return inst._zod.parse(payload, ctx);
300
+ }
301
+ if (ctx.direction === "backward") {
302
+ // run canary initial pass (no checks)
303
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
271
304
 
272
- inst._zod.run = (payload, ctx) => {
273
- if (ctx.skipChecks) {
274
- return inst._zod.parse(payload, ctx);
275
- }
276
- if (ctx.direction === "backward") {
277
- // run canary
278
- // initial pass (no checks)
279
- const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
305
+ if (canary instanceof Promise) {
306
+ return canary.then((canary) => {
307
+ return handleCanaryResult(canary, payload, ctx);
308
+ });
309
+ }
280
310
 
281
- if (canary instanceof Promise) {
282
- return canary.then((canary) => {
283
- return handleCanaryResult(canary, payload, ctx);
284
- });
311
+ return handleCanaryResult(canary, payload, ctx);
285
312
  }
286
313
 
287
- return handleCanaryResult(canary, payload, ctx);
288
- }
289
-
290
- // forward
291
- const result = inst._zod.parse(payload, ctx);
292
- if (result instanceof Promise) {
293
- if (ctx.async === false) throw new core.$ZodAsyncError();
294
- return result.then((result) => runChecks(result, checks, ctx));
295
- }
314
+ // forward
315
+ const result = inst._zod.parse(payload, ctx);
316
+ if (result instanceof Promise) {
317
+ if (ctx.async === false) throw new core.$ZodAsyncError();
318
+ return result.then((result) => runChecks(result, checks, ctx));
319
+ }
296
320
 
297
- return runChecks(result, checks, ctx);
298
- };
321
+ return runChecks(result, checks, ctx);
322
+ };
323
+ }
324
+ },
325
+ {
326
+ // Wrappers extend this by installing a richer factory over it; reading it eagerly would defeat the laziness.
327
+ get "~standard"(): StandardSchemaV1.Props<any, any> {
328
+ return util.hide(this, "~standard", standardProps(this));
329
+ },
330
+ set "~standard"(value: StandardSchemaV1.Props<any, any>) {
331
+ util.own(this, "~standard", value);
332
+ },
299
333
  }
334
+ );
335
+
336
+ /** The Standard Schema surface for `inst`. Shared so wrappers can extend it without forcing it. */
337
+ // a Standard Schema result only reports issues, so a failure finalizes them straight off the raw payload: no ZodError, and no lazy result to read through
338
+ const toStandardResult = (r: ParsePayload, ctx: ParseContextInternal) =>
339
+ r.issues.length ? { issues: r.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())) } : { value: r.value };
300
340
 
301
- // Lazy initialize ~standard to avoid creating objects for every schema
302
- util.defineLazy(inst, "~standard", () => ({
341
+ async function validateAsync(inst: $ZodType, value: unknown) {
342
+ const ctx: ParseContextInternal = { async: true };
343
+ return toStandardResult((await inst._zod.run({ value, issues: [] }, ctx)) as ParsePayload, ctx);
344
+ }
345
+
346
+ export function standardProps(inst: $ZodType): StandardSchemaV1.Props<any, any> {
347
+ return {
303
348
  validate: (value: unknown) => {
349
+ const ctx: ParseContextInternal = { async: false };
304
350
  try {
305
- const r = safeParse(inst, value);
306
- return r.success ? { value: r.data } : { issues: r.error?.issues };
307
- } catch (_) {
308
- return safeParseAsync(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
309
- }
351
+ const r = inst._zod.run({ value, issues: [] }, ctx);
352
+ if (!(r instanceof Promise)) return toStandardResult(r, ctx);
353
+ } catch (_) {}
354
+ // async function so a synchronously throwing check rejects instead of escaping validate
355
+ return validateAsync(inst, value);
310
356
  },
311
357
  vendor: "zod",
312
358
  version: 1 as const,
313
- }));
314
- });
359
+ };
360
+ }
315
361
 
316
362
  export { clone } from "./util.js";
317
363
 
@@ -341,6 +387,8 @@ export interface $ZodStringInternals<Input> extends $ZodTypeInternals<string, In
341
387
  patterns: Set<RegExp>;
342
388
  format: string;
343
389
  contentEncoding: string;
390
+ /** the pattern admits strings its `format` keyword forbids, so `toJSONSchema` must not emit it */
391
+ laxFormat: boolean;
344
392
  }>;
345
393
  }
346
394
 
@@ -350,7 +398,8 @@ export interface $ZodString<Input = unknown> extends _$ZodType<$ZodStringInterna
350
398
 
351
399
  export const $ZodString: core.$constructor<$ZodString> = /*@__PURE__*/ core.$constructor("$ZodString", (inst, def) => {
352
400
  $ZodType.init(inst, def);
353
- inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? regexes.string(inst._zod.bag);
401
+ // a format's own pattern, else unbounded; a template literal derives the check-aware form itself
402
+ inst._zod.pattern = (def as $ZodStringFormatDef).pattern ?? regexes.anyString;
354
403
  inst._zod.parse = (payload, _) => {
355
404
  if (def.coerce)
356
405
  try {
@@ -471,54 +520,133 @@ export interface $ZodURL extends $ZodType {
471
520
  _zod: $ZodURLInternals;
472
521
  }
473
522
 
523
+ /** The `://` guard rejected the input before the URL constructor saw it. */
524
+ export const URL_BAD_FORMAT = 1;
525
+ /** The URL parser rejected the input. */
526
+ export const URL_UNPARSEABLE = 2;
527
+
528
+ export function canParseURL(input: string): boolean {
529
+ try {
530
+ if (typeof URL !== "undefined" && typeof URL.canParse === "function") return URL.canParse(input);
531
+ new URL(input);
532
+ return true;
533
+ } catch {
534
+ return false;
535
+ }
536
+ }
537
+
538
+ export function validateURL(
539
+ trimmed: string,
540
+ def: Pick<$ZodURLDef, "protocol" | "hostname" | "normalize">
541
+ ): URL | true | typeof URL_BAD_FORMAT | typeof URL_UNPARSEABLE {
542
+ if (!("normalize" in def) && !("hostname" in def) && !("protocol" in def)) {
543
+ return canParseURL(trimmed) || URL_UNPARSEABLE;
544
+ }
545
+ return parseURLObject(trimmed, def);
546
+ }
547
+
548
+ /** Parses a URL while preserving the non-normalizing HTTP guard. */
549
+ export function parseURLObject(
550
+ trimmed: string,
551
+ def: Pick<$ZodURLDef, "protocol" | "normalize">
552
+ ): URL | typeof URL_BAD_FORMAT | typeof URL_UNPARSEABLE {
553
+ // When normalize is off, require :// for http/https URLs. This prevents strings like "http:example.com" or "https:/path" from being silently accepted
554
+ if (!def.normalize && def.protocol?.source === regexes.httpProtocol.source && !/^https?:\/\//i.test(trimmed)) {
555
+ return URL_BAD_FORMAT;
556
+ }
557
+
558
+ try {
559
+ if (typeof URL !== "undefined") {
560
+ const URLStatic = URL as typeof URL & { parse?: (input: string) => URL | null };
561
+ if (typeof URLStatic.parse === "function") return URLStatic.parse(trimmed) ?? URL_UNPARSEABLE;
562
+ }
563
+ // @ts-ignore
564
+ return new URL(trimmed);
565
+ } catch {
566
+ return URL_UNPARSEABLE;
567
+ }
568
+ }
569
+
570
+ const asciiTabOrNewline = /[\t\n\r]/g;
571
+
572
+ /** The URL parser deletes every ASCII tab, LF and CR from its input before it parses, so `new URL("https://exa\nmple.com")` reports on `example.com`. Applying the same deletion to the returned value closes the half of that divergence which can move the host; the parser's other rewrite, stripping C0 controls at the edges, cannot. */
573
+ export function stripTabAndNewline(value: string): string {
574
+ return value.replace(asciiTabOrNewline, "");
575
+ }
576
+
577
+ export function urlHostnameOk(url: URL, hostname: RegExp): boolean {
578
+ hostname.lastIndex = 0;
579
+ return hostname.test(url.hostname);
580
+ }
581
+
582
+ export function urlProtocolOk(url: URL, protocol: RegExp): boolean {
583
+ protocol.lastIndex = 0;
584
+ return protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol);
585
+ }
586
+
474
587
  export const $ZodURL: core.$constructor<$ZodURL> = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) => {
475
588
  $ZodStringFormat.init(inst, def);
476
589
  inst._zod.check = (payload) => {
477
590
  try {
478
591
  // Trim whitespace from input
479
592
  const trimmed = payload.value.trim();
480
- // @ts-ignore
481
- const url = new URL(trimmed);
593
+ const url = validateURL(trimmed, def);
482
594
 
483
- if (def.hostname) {
484
- def.hostname.lastIndex = 0;
485
- if (!def.hostname.test(url.hostname)) {
486
- payload.issues.push({
487
- code: "invalid_format",
488
- format: "url",
489
- note: "Invalid hostname",
490
- pattern: def.hostname.source,
491
- input: payload.value,
492
- inst,
493
- continue: !def.abort,
494
- });
495
- }
595
+ if (url === URL_BAD_FORMAT) {
596
+ payload.issues.push({
597
+ code: "invalid_format",
598
+ format: "url",
599
+ note: "Invalid URL format",
600
+ input: payload.value,
601
+ inst,
602
+ continue: !def.abort,
603
+ });
604
+ return;
496
605
  }
497
606
 
498
- if (def.protocol) {
499
- def.protocol.lastIndex = 0;
500
- if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
501
- payload.issues.push({
502
- code: "invalid_format",
503
- format: "url",
504
- note: "Invalid protocol",
505
- pattern: def.protocol.source,
506
- input: payload.value,
507
- inst,
508
- continue: !def.abort,
509
- });
510
- }
607
+ if (url === URL_UNPARSEABLE) {
608
+ payload.issues.push({
609
+ code: "invalid_format",
610
+ format: "url",
611
+ input: payload.value,
612
+ inst,
613
+ continue: !def.abort,
614
+ });
615
+ return;
511
616
  }
512
617
 
513
- // Set the output value based on normalize flag
514
- if (def.normalize) {
515
- // Use normalized URL
516
- payload.value = url.href;
517
- } else {
518
- // Preserve the original input (trimmed)
519
- payload.value = trimmed;
618
+ if (url === true) {
619
+ payload.value = stripTabAndNewline(trimmed);
620
+ return;
520
621
  }
521
622
 
623
+ if (def.hostname && !urlHostnameOk(url, def.hostname)) {
624
+ payload.issues.push({
625
+ code: "invalid_format",
626
+ format: "url",
627
+ note: "Invalid hostname",
628
+ pattern: def.hostname.source,
629
+ input: payload.value,
630
+ inst,
631
+ continue: !def.abort,
632
+ });
633
+ }
634
+
635
+ if (def.protocol && !urlProtocolOk(url, def.protocol)) {
636
+ payload.issues.push({
637
+ code: "invalid_format",
638
+ format: "url",
639
+ note: "Invalid protocol",
640
+ pattern: def.protocol.source,
641
+ input: payload.value,
642
+ inst,
643
+ continue: !def.abort,
644
+ });
645
+ }
646
+
647
+ // Set the output value based on normalize flag
648
+ payload.value = def.normalize ? url.href : stripTabAndNewline(trimmed);
649
+
522
650
  return;
523
651
  } catch (_) {
524
652
  payload.issues.push({
@@ -551,8 +679,12 @@ export const $ZodEmoji: core.$constructor<$ZodEmoji> = /*@__PURE__*/ core.$const
551
679
 
552
680
  ////////////////////////////// ZodNanoID //////////////////////////////
553
681
 
554
- export interface $ZodNanoIDDef extends $ZodStringFormatDef<"nanoid"> {}
555
- export interface $ZodNanoIDInternals extends $ZodStringFormatInternals<"nanoid"> {}
682
+ export interface $ZodNanoIDDef extends $ZodStringFormatDef<"nanoid"> {
683
+ length?: number | undefined;
684
+ }
685
+ export interface $ZodNanoIDInternals extends $ZodStringFormatInternals<"nanoid"> {
686
+ def: $ZodNanoIDDef;
687
+ }
556
688
 
557
689
  export interface $ZodNanoID extends $ZodType {
558
690
  _zod: $ZodNanoIDInternals;
@@ -561,20 +693,42 @@ export interface $ZodNanoID extends $ZodType {
561
693
  export const $ZodNanoID: core.$constructor<$ZodNanoID> = /*@__PURE__*/ core.$constructor(
562
694
  "$ZodNanoID",
563
695
  (inst, def): void => {
564
- def.pattern ??= regexes.nanoid;
696
+ if (def.length !== undefined && (!Number.isInteger(def.length) || def.length < 1))
697
+ throw new Error(`Invalid nanoid length: ${def.length}`);
698
+ def.pattern ??= def.length === undefined ? regexes.nanoid : regexes.nanoidOfLength(def.length);
565
699
  $ZodStringFormat.init(inst, def);
566
700
  }
567
701
  );
568
702
 
569
703
  ////////////////////////////// ZodCUID //////////////////////////////
570
704
 
705
+ /**
706
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
707
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
708
+ * See https://github.com/paralleldrive/cuid.
709
+ */
571
710
  export interface $ZodCUIDDef extends $ZodStringFormatDef<"cuid"> {}
711
+ /**
712
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
713
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
714
+ * See https://github.com/paralleldrive/cuid.
715
+ */
572
716
  export interface $ZodCUIDInternals extends $ZodStringFormatInternals<"cuid"> {}
573
717
 
718
+ /**
719
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
720
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
721
+ * See https://github.com/paralleldrive/cuid.
722
+ */
574
723
  export interface $ZodCUID extends $ZodType {
575
724
  _zod: $ZodCUIDInternals;
576
725
  }
577
726
 
727
+ /**
728
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
729
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
730
+ * See https://github.com/paralleldrive/cuid.
731
+ */
578
732
  export const $ZodCUID: core.$constructor<$ZodCUID> = /*@__PURE__*/ core.$constructor("$ZodCUID", (inst, def): void => {
579
733
  def.pattern ??= regexes.cuid;
580
734
  $ZodStringFormat.init(inst, def);
@@ -739,8 +893,6 @@ export interface $ZodIPv4 extends $ZodType {
739
893
  export const $ZodIPv4: core.$constructor<$ZodIPv4> = /*@__PURE__*/ core.$constructor("$ZodIPv4", (inst, def): void => {
740
894
  def.pattern ??= regexes.ipv4;
741
895
  $ZodStringFormat.init(inst, def);
742
-
743
- inst._zod.bag.format = `ipv4`;
744
896
  });
745
897
 
746
898
  ////////////////////////////// ZodIPv6 //////////////////////////////
@@ -757,18 +909,20 @@ export interface $ZodIPv6 extends $ZodType {
757
909
  _zod: $ZodIPv6Internals;
758
910
  }
759
911
 
912
+ /** An IPv6 address is written with hex digits, colons and dots, and nothing else. The guard is what makes the check below an IPv6 check: `new URL("http://[...]")` parses an authority, not an address, so `@` and `\` re-delimit it and `"::@1\\"` validates against the host `0.0.0.1`. The URL parser also deletes ASCII tab, LF and CR rather than failing, which is how `"::1\n"` validated as `::1`. */
913
+ const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
914
+
915
+ export function isValidIPv6(value: string): boolean {
916
+ if (!ipv6Alphabet.test(value)) return false;
917
+ return canParseURL(`http://[${value}]`);
918
+ }
919
+
760
920
  export const $ZodIPv6: core.$constructor<$ZodIPv6> = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def): void => {
761
921
  def.pattern ??= regexes.ipv6;
762
922
  $ZodStringFormat.init(inst, def);
763
923
 
764
- inst._zod.bag.format = `ipv6`;
765
-
766
924
  inst._zod.check = (payload) => {
767
- try {
768
- // @ts-ignore
769
- new URL(`http://[${payload.value}]`);
770
- // return;
771
- } catch {
925
+ if (!isValidIPv6(payload.value)) {
772
926
  payload.issues.push({
773
927
  code: "invalid_format",
774
928
  format: "ipv6",
@@ -796,8 +950,6 @@ export interface $ZodMAC extends $ZodType {
796
950
  export const $ZodMAC: core.$constructor<$ZodMAC> = /*@__PURE__*/ core.$constructor("$ZodMAC", (inst, def): void => {
797
951
  def.pattern ??= regexes.mac(def.delimiter);
798
952
  $ZodStringFormat.init(inst, def);
799
-
800
- inst._zod.bag.format = `mac`;
801
953
  });
802
954
 
803
955
  ////////////////////////////// ZodCIDRv4 //////////////////////////////
@@ -836,6 +988,17 @@ export interface $ZodCIDRv6 extends $ZodType {
836
988
  _zod: $ZodCIDRv6Internals;
837
989
  }
838
990
 
991
+ export function isValidCIDRv6(value: string): boolean {
992
+ const parts = value.split("/");
993
+ if (parts.length !== 2) return false;
994
+ const [address, prefix] = parts;
995
+ if (!prefix) return false;
996
+ const prefixNum = Number(prefix);
997
+ if (`${prefixNum}` !== prefix) return false;
998
+ if (prefixNum < 0 || prefixNum > 128) return false;
999
+ return isValidIPv6(address);
1000
+ }
1001
+
839
1002
  export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$constructor(
840
1003
  "$ZodCIDRv6",
841
1004
  (inst, def): void => {
@@ -843,17 +1006,7 @@ export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$con
843
1006
  $ZodStringFormat.init(inst, def);
844
1007
 
845
1008
  inst._zod.check = (payload) => {
846
- const parts = payload.value.split("/");
847
- try {
848
- if (parts.length !== 2) throw new Error();
849
- const [address, prefix] = parts;
850
- if (!prefix) throw new Error();
851
- const prefixNum = Number(prefix);
852
- if (`${prefixNum}` !== prefix) throw new Error();
853
- if (prefixNum < 0 || prefixNum > 128) throw new Error();
854
- // @ts-ignore
855
- new URL(`http://[${address}]`);
856
- } catch {
1009
+ if (!isValidCIDRv6(payload.value)) {
857
1010
  payload.issues.push({
858
1011
  code: "invalid_format",
859
1012
  format: "cidrv6",
@@ -869,6 +1022,8 @@ export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$con
869
1022
  ////////////////////////////// ZodBase64 //////////////////////////////
870
1023
  export function isValidBase64(data: string): boolean {
871
1024
  if (data === "") return true;
1025
+ // atob ignores whitespace, so reject it up front.
1026
+ if (/\s/.test(data)) return false;
872
1027
  if (data.length % 4 !== 0) return false;
873
1028
  try {
874
1029
  // @ts-ignore
@@ -886,14 +1041,15 @@ export interface $ZodBase64 extends $ZodType {
886
1041
  _zod: $ZodBase64Internals;
887
1042
  }
888
1043
 
1044
+ // lax on purpose: the quantified regexes.base64 overflows the regex stack on multi-MB input and its leading ^$| alternation leaks through template-literal composition; isValidBase64 enforces length and padding
1045
+ export const base64Charset: RegExp = /^[0-9a-zA-Z+/]*={0,2}$/;
1046
+
889
1047
  export const $ZodBase64: core.$constructor<$ZodBase64> = /*@__PURE__*/ core.$constructor(
890
1048
  "$ZodBase64",
891
1049
  (inst, def): void => {
892
- def.pattern ??= regexes.base64;
1050
+ def.pattern ??= base64Charset;
893
1051
  $ZodStringFormat.init(inst, def);
894
1052
 
895
- inst._zod.bag.contentEncoding = "base64";
896
-
897
1053
  inst._zod.check = (payload) => {
898
1054
  if (isValidBase64(payload.value)) return;
899
1055
 
@@ -908,9 +1064,12 @@ export const $ZodBase64: core.$constructor<$ZodBase64> = /*@__PURE__*/ core.$con
908
1064
  }
909
1065
  );
910
1066
 
911
- ////////////////////////////// ZodBase64 //////////////////////////////
1067
+ ////////////////////////////// ZodBase64URL //////////////////////////////
1068
+ // lax on purpose: the quantified regexes.base64url overflows the regex stack on multi-MB input; isValidBase64 enforces length on the padded string
1069
+ export const base64urlCharset: RegExp = /^[A-Za-z0-9_-]*$/;
1070
+
912
1071
  export function isValidBase64URL(data: string): boolean {
913
- if (!regexes.base64url.test(data)) return false;
1072
+ if (!base64urlCharset.test(data)) return false;
914
1073
  const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
915
1074
  const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
916
1075
  return isValidBase64(padded);
@@ -926,11 +1085,9 @@ export interface $ZodBase64URL extends $ZodType {
926
1085
  export const $ZodBase64URL: core.$constructor<$ZodBase64URL> = /*@__PURE__*/ core.$constructor(
927
1086
  "$ZodBase64URL",
928
1087
  (inst, def): void => {
929
- def.pattern ??= regexes.base64url;
1088
+ def.pattern ??= base64urlCharset;
930
1089
  $ZodStringFormat.init(inst, def);
931
1090
 
932
- inst._zod.bag.contentEncoding = "base64url";
933
-
934
1091
  inst._zod.check = (payload) => {
935
1092
  if (isValidBase64URL(payload.value)) return;
936
1093
 
@@ -959,6 +1116,103 @@ export const $ZodE164: core.$constructor<$ZodE164> = /*@__PURE__*/ core.$constru
959
1116
  $ZodStringFormat.init(inst, def);
960
1117
  });
961
1118
 
1119
+ ////////////////////////////// ZodCreditCard //////////////////////////////
1120
+
1121
+ const CC_SANITIZE = /[- ]/g;
1122
+
1123
+ /** Luhn checksum on a digit-only string. Adapted from valibot (MIT). */
1124
+ function isLuhnAlgo(digits: string): boolean {
1125
+ let length = digits.length;
1126
+ let bit = 1;
1127
+ let sum = 0;
1128
+ while (length) {
1129
+ const value = digits.charCodeAt(--length) - 48;
1130
+ bit ^= 1;
1131
+ sum += bit ? [0, 2, 4, 6, 8, 1, 3, 5, 7, 9][value]! : value;
1132
+ }
1133
+ return sum % 10 === 0;
1134
+ }
1135
+
1136
+ export function isValidCreditCard(input: string): boolean {
1137
+ if (!regexes.creditCard.test(input)) return false;
1138
+ return isLuhnAlgo(input.replace(CC_SANITIZE, ""));
1139
+ }
1140
+
1141
+ export interface $ZodCreditCardDef extends $ZodStringFormatDef<"credit_card"> {}
1142
+ export interface $ZodCreditCardInternals extends $ZodStringFormatInternals<"credit_card"> {
1143
+ def: $ZodCreditCardDef;
1144
+ }
1145
+
1146
+ export interface $ZodCreditCard extends $ZodType {
1147
+ _zod: $ZodCreditCardInternals;
1148
+ }
1149
+
1150
+ export const $ZodCreditCard: core.$constructor<$ZodCreditCard> = /*@__PURE__*/ core.$constructor(
1151
+ "$ZodCreditCard",
1152
+ (inst, def): void => {
1153
+ // Shape only — the Luhn check below is not expressible as a pattern, so consumers of `pattern` (JSON Schema, template literals) get the length and separator rules alone.
1154
+ def.pattern ??= regexes.creditCard;
1155
+ $ZodStringFormat.init(inst, def);
1156
+ inst._zod.check = (payload) => {
1157
+ if (isValidCreditCard(payload.value)) return;
1158
+ payload.issues.push({
1159
+ code: "invalid_format",
1160
+ format: "credit_card",
1161
+ input: payload.value,
1162
+ inst,
1163
+ continue: !def.abort,
1164
+ });
1165
+ };
1166
+ }
1167
+ );
1168
+
1169
+ ////////////////////////////// ZodIBAN //////////////////////////////
1170
+
1171
+ // iso 7064 mod 97-10 checksum without BigInt
1172
+ function isIso7064Mod97(iban: string): boolean {
1173
+ let remainder = 0;
1174
+ const len = iban.length;
1175
+ for (let i = 4; i < len; i++) {
1176
+ const code = iban.charCodeAt(i);
1177
+ remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
1178
+ }
1179
+ for (let i = 0; i < 4; i++) {
1180
+ const code = iban.charCodeAt(i);
1181
+ remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
1182
+ }
1183
+ return remainder === 1;
1184
+ }
1185
+
1186
+ export function isValidIBAN(input: string): boolean {
1187
+ if (!regexes.iban.test(input)) return false;
1188
+ return isIso7064Mod97(input);
1189
+ }
1190
+
1191
+ export interface $ZodIBANDef extends $ZodStringFormatDef<"iban"> {}
1192
+ export interface $ZodIBANInternals extends $ZodStringFormatInternals<"iban"> {
1193
+ def: $ZodIBANDef;
1194
+ }
1195
+
1196
+ export interface $ZodIBAN extends $ZodType {
1197
+ _zod: $ZodIBANInternals;
1198
+ }
1199
+
1200
+ export const $ZodIBAN: core.$constructor<$ZodIBAN> = /*@__PURE__*/ core.$constructor("$ZodIBAN", (inst, def): void => {
1201
+ // shape only — checksum is not expressible as a pattern
1202
+ def.pattern ??= regexes.iban;
1203
+ $ZodStringFormat.init(inst, def);
1204
+ inst._zod.check = (payload) => {
1205
+ if (isValidIBAN(payload.value)) return;
1206
+ payload.issues.push({
1207
+ code: "invalid_format",
1208
+ format: "iban",
1209
+ input: payload.value,
1210
+ inst,
1211
+ continue: !def.abort,
1212
+ });
1213
+ };
1214
+ });
1215
+
962
1216
  ////////////////////////////// ZodJWT //////////////////////////////
963
1217
 
964
1218
  export function isValidJWT(token: string, algorithm: util.JWTAlgorithm | null = null): boolean {
@@ -1075,7 +1329,7 @@ export interface $ZodNumber<Input = unknown> extends $ZodType {
1075
1329
  export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, def) => {
1076
1330
  $ZodType.init(inst, def);
1077
1331
 
1078
- inst._zod.pattern = inst._zod.bag.pattern ?? regexes.number;
1332
+ inst._zod.pattern = regexes.number;
1079
1333
  inst._zod.parse = (payload, _ctx) => {
1080
1334
  if (def.coerce)
1081
1335
  try {
@@ -1091,7 +1345,7 @@ export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$con
1091
1345
  ? Number.isNaN(input)
1092
1346
  ? "NaN"
1093
1347
  : !Number.isFinite(input)
1094
- ? "Infinity"
1348
+ ? String(input)
1095
1349
  : undefined
1096
1350
  : undefined;
1097
1351
 
@@ -1110,15 +1364,19 @@ export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$con
1110
1364
  ///////////////////////////////////////////////
1111
1365
  ////////// ZodNumberFormat //////////
1112
1366
  ///////////////////////////////////////////////
1113
- export interface $ZodNumberFormatDef extends $ZodNumberDef, checks.$ZodCheckNumberFormatDef {}
1114
-
1115
- export interface $ZodNumberFormatInternals extends $ZodNumberInternals<number>, checks.$ZodCheckNumberFormatInternals {
1116
- def: $ZodNumberFormatDef;
1367
+ export interface $ZodNumberFormatDef<Format extends $ZodNumberFormats = $ZodNumberFormats>
1368
+ extends $ZodNumberDef,
1369
+ checks.$ZodCheckNumberFormatDef<Format> {}
1370
+
1371
+ export interface $ZodNumberFormatInternals<Format extends $ZodNumberFormats = $ZodNumberFormats>
1372
+ extends $ZodNumberInternals<number>,
1373
+ checks.$ZodCheckNumberFormatInternals<Format> {
1374
+ def: $ZodNumberFormatDef<Format>;
1117
1375
  isst: errors.$ZodIssueInvalidType;
1118
1376
  }
1119
1377
 
1120
- export interface $ZodNumberFormat extends $ZodType {
1121
- _zod: $ZodNumberFormatInternals;
1378
+ export interface $ZodNumberFormat<Format extends $ZodNumberFormats = $ZodNumberFormats> extends $ZodType {
1379
+ _zod: $ZodNumberFormatInternals<Format>;
1122
1380
  }
1123
1381
 
1124
1382
  export const $ZodNumberFormat: core.$constructor<$ZodNumberFormat> = /*@__PURE__*/ core.$constructor(
@@ -1233,16 +1491,20 @@ export const $ZodBigInt: core.$constructor<$ZodBigInt> = /*@__PURE__*/ core.$con
1233
1491
  ///////////////////////////////////////////////
1234
1492
  ////////// ZodBigIntFormat //////////
1235
1493
  ///////////////////////////////////////////////
1236
- export interface $ZodBigIntFormatDef extends $ZodBigIntDef, checks.$ZodCheckBigIntFormatDef {
1494
+ export interface $ZodBigIntFormatDef<Format extends $ZodBigIntFormats = $ZodBigIntFormats>
1495
+ extends $ZodBigIntDef,
1496
+ checks.$ZodCheckBigIntFormatDef<Format> {
1237
1497
  check: "bigint_format";
1238
1498
  }
1239
1499
 
1240
- export interface $ZodBigIntFormatInternals extends $ZodBigIntInternals<bigint>, checks.$ZodCheckBigIntFormatInternals {
1241
- def: $ZodBigIntFormatDef;
1500
+ export interface $ZodBigIntFormatInternals<Format extends $ZodBigIntFormats = $ZodBigIntFormats>
1501
+ extends $ZodBigIntInternals<bigint>,
1502
+ checks.$ZodCheckBigIntFormatInternals<Format> {
1503
+ def: $ZodBigIntFormatDef<Format>;
1242
1504
  }
1243
1505
 
1244
- export interface $ZodBigIntFormat extends $ZodType {
1245
- _zod: $ZodBigIntFormatInternals;
1506
+ export interface $ZodBigIntFormat<Format extends $ZodBigIntFormats = $ZodBigIntFormats> extends $ZodType {
1507
+ _zod: $ZodBigIntFormatInternals<Format>;
1246
1508
  }
1247
1509
 
1248
1510
  export const $ZodBigIntFormat: core.$constructor<$ZodBigIntFormat> = /*@__PURE__*/ core.$constructor(
@@ -1318,8 +1580,6 @@ export const $ZodUndefined: core.$constructor<$ZodUndefined> = /*@__PURE__*/ cor
1318
1580
  $ZodType.init(inst, def);
1319
1581
  inst._zod.pattern = regexes.undefined;
1320
1582
  inst._zod.values = new Set([undefined]);
1321
- inst._zod.optin = "optional";
1322
- inst._zod.optout = "optional";
1323
1583
 
1324
1584
  inst._zod.parse = (payload, _ctx) => {
1325
1585
  const input = payload.value;
@@ -1584,6 +1844,34 @@ export interface $ZodArrayInternals<T extends SomeType = $ZodType> extends _$Zod
1584
1844
 
1585
1845
  export interface $ZodArray<T extends SomeType = $ZodType> extends $ZodType<any, any, $ZodArrayInternals<T>> {}
1586
1846
 
1847
+ // an oversized container fails its leading size checks before any element is parsed
1848
+ function capSize(inst: $ZodType, size: (input: any) => number): void {
1849
+ const caps = util.sizeCaps(inst._zod.def.checks);
1850
+ if (!caps.length) return;
1851
+ const cap = Math.min(...caps.map((c) => c[0]));
1852
+ const parse = inst._zod.parse;
1853
+ inst._zod.parse = (payload, ctx) => {
1854
+ const n = size(payload.value);
1855
+ if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
1856
+ for (const [max, ch] of util.sizeCaps(inst._zod.def.checks)) {
1857
+ if (n > max && ch._zod.def.when!(payload)) {
1858
+ const start = payload.issues.length;
1859
+ ch._zod.check(payload as ParsePayload<never>);
1860
+ // the value is still the raw input, so no later check may read it
1861
+ (payload.issues[start] as { continue?: boolean }).continue = false;
1862
+ util.attachSchema(payload.issues, start, inst);
1863
+ return payload;
1864
+ }
1865
+ }
1866
+ }
1867
+ return parse(payload, ctx);
1868
+ };
1869
+ }
1870
+
1871
+ const arraySize = (input: unknown): number => (Array.isArray(input) ? input.length : -1);
1872
+ const mapSize = (input: unknown): number => (input instanceof Map ? input.size : -1);
1873
+ const setSize = (input: unknown): number => (input instanceof Set ? input.size : -1);
1874
+
1587
1875
  function handleArrayResult(result: ParsePayload<any>, final: ParsePayload<any[]>, index: number) {
1588
1876
  if (result.issues.length) {
1589
1877
  final.issues.push(...util.prefixIssues(index, result.issues));
@@ -1594,6 +1882,9 @@ function handleArrayResult(result: ParsePayload<any>, final: ParsePayload<any[]>
1594
1882
  export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def) => {
1595
1883
  $ZodType.init(inst, def);
1596
1884
 
1885
+ const memo = core.globalConfig.memoizer;
1886
+ memo?.attach(inst);
1887
+
1597
1888
  inst._zod.parse = (payload, ctx) => {
1598
1889
  const input = payload.value;
1599
1890
 
@@ -1608,8 +1899,9 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
1608
1899
  return payload;
1609
1900
  }
1610
1901
 
1611
- payload.value = Array(input.length);
1902
+ payload.value = memo ? memo.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
1612
1903
  const proms: Promise<any>[] = [];
1904
+ const abortEarly = ctx?.abortEarly;
1613
1905
  for (let i = 0; i < input.length; i++) {
1614
1906
  const item = input[i];
1615
1907
  const result = def.element._zod.run(
@@ -1624,6 +1916,8 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
1624
1916
  proms.push(result.then((result) => handleArrayResult(result, payload, i)));
1625
1917
  } else {
1626
1918
  handleArrayResult(result, payload, i);
1919
+ // the element's payload is authoritative here, since handleArrayResult forwards every issue; an object's is not, because it drops a failed absent optional
1920
+ if (abortEarly && result.issues.length !== 0 && util.aborted(result)) break;
1627
1921
  }
1628
1922
  }
1629
1923
 
@@ -1633,6 +1927,7 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
1633
1927
 
1634
1928
  return payload; //handleArrayResultsAsync(parseResults, final);
1635
1929
  };
1930
+ capSize(inst, arraySize);
1636
1931
  });
1637
1932
 
1638
1933
  //////////////////////////////////////////
@@ -1644,12 +1939,12 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
1644
1939
  //////////////////////////////////////////
1645
1940
 
1646
1941
  type OptionalOutSchema = { _zod: { optout: "optional" } };
1647
- type OptionalInSchema = { _zod: { optin: "optional" } };
1942
+ type OptionalInSchema = { _zod: { optin: "optional" | "defaulted" } };
1648
1943
 
1649
1944
  export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T
1650
1945
  ? util.IsAny<T[keyof T]> extends true
1651
1946
  ? Record<string, unknown>
1652
- : Record<string, core.output<T[keyof T]>>
1947
+ : { [k in string]: core.output<T[keyof T]> }
1653
1948
  : keyof (T & Extra) extends never
1654
1949
  ? Record<string, never>
1655
1950
  : util.Prettify<
@@ -1693,7 +1988,7 @@ export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<st
1693
1988
  export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T
1694
1989
  ? util.IsAny<T[keyof T]> extends true
1695
1990
  ? Record<string, unknown>
1696
- : Record<string, core.input<T[keyof T]>>
1991
+ : { [k in string]: core.input<T[keyof T]> }
1697
1992
  : keyof (T & Extra) extends never
1698
1993
  ? Record<string, never>
1699
1994
  : util.Prettify<
@@ -1709,18 +2004,37 @@ function handlePropertyResult(
1709
2004
  final: ParsePayload,
1710
2005
  key: PropertyKey,
1711
2006
  input: any,
1712
- isOptionalOut: boolean
2007
+ optin: "optional" | "defaulted" | undefined,
2008
+ optout: "optional" | undefined
1713
2009
  ) {
2010
+ const isPresent = key in input;
2011
+ const isOptionalOut = optout === "optional";
2012
+ // The middle rung means "absence permitted, nothing supplied in its place", so an absent key contributes nothing — whatever the schema made of `undefined` is invented, not substituted. Only `optional` reaches this with a value: `defaulted` substitutes, and a schema that isn't optional-out has to keep the key.
2013
+ if (!isPresent && isOptionalOut && optin === "optional") {
2014
+ return;
2015
+ }
1714
2016
  if (result.issues.length) {
1715
- // For optional-out schemas, ignore errors on absent keys
1716
- if (isOptionalOut && !(key in input)) {
2017
+ // For optional-in/out schemas, ignore errors on absent keys.
2018
+ if (optin !== undefined && isOptionalOut && !isPresent) {
1717
2019
  return;
1718
2020
  }
1719
2021
  final.issues.push(...util.prefixIssues(key, result.issues));
1720
2022
  }
1721
2023
 
2024
+ if (!isPresent && optin === undefined) {
2025
+ if (!result.issues.length) {
2026
+ final.issues.push({
2027
+ code: "invalid_type",
2028
+ expected: "nonoptional",
2029
+ input: undefined,
2030
+ path: [key],
2031
+ });
2032
+ }
2033
+ return;
2034
+ }
2035
+
1722
2036
  if (result.value === undefined) {
1723
- if (key in input) {
2037
+ if (isPresent || (optin === "defaulted" && !isOptionalOut)) {
1724
2038
  (final.value as any)[key] = undefined;
1725
2039
  }
1726
2040
  } else {
@@ -1778,18 +2092,27 @@ export interface $ZodObject<
1778
2092
  out Params extends $ZodObjectConfig = $ZodObjectConfig,
1779
2093
  > extends $ZodType<any, any, $ZodObjectInternals<Shape, Params>> {}
1780
2094
 
2095
+ // one shared instance; a fresh [] per schema cost 56 bytes retained
2096
+ const NO_SYMBOL_KEYS: symbol[] = [];
2097
+
1781
2098
  function normalizeDef(def: $ZodObjectDef) {
1782
2099
  const keys = Object.keys(def.shape);
1783
- for (const k of keys) {
1784
- if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
1785
- throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
2100
+ const ownSymbols = Object.getOwnPropertySymbols(def.shape);
2101
+ const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
2102
+ // aliases `keys` when there are no symbols, so a string-only shape keeps one array
2103
+ const allKeys: (string | symbol)[] = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
2104
+ for (const k of allKeys) {
2105
+ if (!(def.shape as any)?.[k]?._zod?.traits?.has("$ZodType")) {
2106
+ throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
1786
2107
  }
1787
2108
  }
1788
2109
  const okeys = util.optionalKeys(def.shape);
1789
2110
 
1790
2111
  return {
1791
2112
  ...def,
1792
- keys,
2113
+ allKeys,
2114
+ symbolKeys,
2115
+ // string-only: handleCatchall matches it against `for...in`, which never yields a symbol
1793
2116
  keySet: new Set(keys),
1794
2117
  numKeys: keys.length,
1795
2118
  optionalKeys: new Set(okeys),
@@ -1800,18 +2123,31 @@ function handleCatchall(
1800
2123
  proms: Promise<any>[],
1801
2124
  input: any,
1802
2125
  payload: ParsePayload,
1803
- ctx: ParseContext,
2126
+ ctx: ParseContextInternal,
1804
2127
  def: ReturnType<typeof normalizeDef>,
1805
- inst: $ZodObject
2128
+ inst: $ZodObject,
2129
+ abortEarly: boolean
1806
2130
  ) {
1807
2131
  const unrecognized: string[] = [];
1808
- // iterate over input keys
1809
2132
  const keySet = def.keySet;
1810
2133
  const _catchall = def.catchall!._zod;
1811
2134
  const t = _catchall.def.type;
1812
- const isOptionalOut = _catchall.optout === "optional";
2135
+ const optin = _catchall.optin;
2136
+ const optout = _catchall.optout;
2137
+ // starts at 0, not the current length: the shape phase already ran and may have aborted
2138
+ let seen = 0;
1813
2139
  for (const key in input) {
2140
+ if (abortEarly && payload.issues.length !== seen) {
2141
+ if (util.aborted(payload, seen)) break;
2142
+ seen = payload.issues.length;
2143
+ }
2144
+ // Must precede the __proto__ branch: a declared key is not unrecognized, even though the shape loop deliberately strips __proto__ from the parsed output.
1814
2145
  if (keySet.has(key)) continue;
2146
+ // Don't copy an undeclared __proto__ into the result; assignment to a plain {} would replace the result prototype. But in strict mode it is still an unknown key, so report it before skipping.
2147
+ if (key === "__proto__") {
2148
+ if (t === "never") unrecognized.push(key);
2149
+ continue;
2150
+ }
1815
2151
  if (t === "never") {
1816
2152
  unrecognized.push(key);
1817
2153
  continue;
@@ -1819,9 +2155,9 @@ function handleCatchall(
1819
2155
  const r = _catchall.run({ value: input[key], issues: [] }, ctx);
1820
2156
 
1821
2157
  if (r instanceof Promise) {
1822
- proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
2158
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
1823
2159
  } else {
1824
- handlePropertyResult(r, payload, key, input, isOptionalOut);
2160
+ handlePropertyResult(r, payload, key, input, optin, optout);
1825
2161
  }
1826
2162
  }
1827
2163
 
@@ -1831,6 +2167,8 @@ function handleCatchall(
1831
2167
  keys: unrecognized,
1832
2168
  input,
1833
2169
  inst,
2170
+ // Describes the shape of the input, not the validity of the parsed value, so it never aborts. The parse still fails; the schema's own checks just get to run first, and an enclosing intersection can reconcile the key against a sibling operand.
2171
+ continue: true,
1834
2172
  });
1835
2173
  }
1836
2174
 
@@ -1843,32 +2181,35 @@ function handleCatchall(
1843
2181
  export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
1844
2182
  // requires cast because technically $ZodObject doesn't extend
1845
2183
  $ZodType.init(inst, def);
1846
- // const sh = def.shape;
1847
2184
  const desc = Object.getOwnPropertyDescriptor(def, "shape");
1848
- if (!desc?.get) {
1849
- const sh = def.shape;
1850
- Object.defineProperty(def, "shape", {
1851
- get: () => {
1852
- const newSh = { ...sh };
1853
- Object.defineProperty(def, "shape", {
1854
- value: newSh,
1855
- });
1856
-
1857
- return newSh;
1858
- },
1859
- });
2185
+ // a cloned def carries its source's accessor, which knows the shape it answers from; adopting that keeps the clone's keys readable without running it
2186
+ const sh = desc?.get ? (desc.get as util.ShapeGetter).raw : (def.shape ?? {});
2187
+ if (sh) {
2188
+ // Freezes the shape on first read, so its getters resolve once and every later read sees the same schemas.
2189
+ const get: util.ShapeGetter = () => {
2190
+ const newSh = { ...sh };
2191
+ Object.defineProperty(def, "shape", { value: newSh });
2192
+ get.raw = newSh;
2193
+ return newSh;
2194
+ };
2195
+ get.raw = sh;
2196
+ Object.defineProperty(def, "shape", { get });
1860
2197
  }
1861
2198
 
1862
2199
  const _normalized = util.cached(() => normalizeDef(def));
1863
2200
 
1864
- util.defineLazy(inst._zod, "propValues", () => {
1865
- const shape = def.shape;
2201
+ util.defineLazyInternal(inst, "propValues", (zod) => {
2202
+ const shape = zod.def.shape;
1866
2203
  const propValues: util.PropValues = {};
1867
2204
  for (const key in shape) {
1868
2205
  const field = shape[key]!._zod;
1869
2206
  if (field.values) {
1870
- propValues[key] ??= new Set();
2207
+ if (!Object.prototype.hasOwnProperty.call(propValues, key)) {
2208
+ util.assignProp(propValues, key, new Set());
2209
+ }
1871
2210
  for (const v of field.values) propValues[key].add(v);
2211
+ // An omittable slot reads back as undefined at a discriminator lookup, so it has to claim undefined: two options that can both omit the key are not discriminable on it.
2212
+ if (field.optin !== undefined) propValues[key].add(undefined);
1872
2213
  }
1873
2214
  }
1874
2215
  return propValues;
@@ -1878,6 +2219,8 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
1878
2219
  const catchall = def.catchall;
1879
2220
 
1880
2221
  let value!: typeof _normalized.value;
2222
+ const memo = core.globalConfig.memoizer;
2223
+ memo?.attach(inst);
1881
2224
 
1882
2225
  inst._zod.parse = (payload, ctx) => {
1883
2226
  value ??= _normalized.value;
@@ -1892,20 +2235,28 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
1892
2235
  return payload;
1893
2236
  }
1894
2237
 
1895
- payload.value = {};
2238
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
1896
2239
 
1897
2240
  const proms: Promise<any>[] = [];
1898
2241
  const shape = value.shape;
2242
+ const abortEarly = ctx?.abortEarly;
2243
+ let seen = payload.issues.length;
1899
2244
 
1900
- for (const key of value.keys) {
1901
- const el = shape[key]!;
1902
- const isOptionalOut = el._zod.optout === "optional";
2245
+ for (const key of value.allKeys) {
2246
+ if (abortEarly && payload.issues.length !== seen) {
2247
+ if (util.aborted(payload, seen)) break;
2248
+ seen = payload.issues.length;
2249
+ }
2250
+ if (key === "__proto__") continue;
2251
+ const el = (shape as any)[key]!;
2252
+ const optin = el._zod.optin;
2253
+ const optout = el._zod.optout;
1903
2254
 
1904
2255
  const r = el._zod.run({ value: input[key], issues: [] }, ctx);
1905
2256
  if (r instanceof Promise) {
1906
- proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
2257
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
1907
2258
  } else {
1908
- handlePropertyResult(r, payload, key, input, isOptionalOut);
2259
+ handlePropertyResult(r, payload, key, input, optin, optout);
1909
2260
  }
1910
2261
  }
1911
2262
 
@@ -1913,7 +2264,7 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
1913
2264
  return proms.length ? Promise.all(proms).then(() => payload) : payload;
1914
2265
  }
1915
2266
 
1916
- return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
2267
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst, abortEarly === true);
1917
2268
  };
1918
2269
  });
1919
2270
 
@@ -1926,79 +2277,111 @@ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$
1926
2277
  const superParse = inst._zod.parse;
1927
2278
  const _normalized = util.cached(() => normalizeDef(def));
1928
2279
 
2280
+ const memo = core.globalConfig.memoizer;
2281
+
1929
2282
  const generateFastpass = (shape: any) => {
1930
- const doc = new Doc(["shape", "payload", "ctx"]);
1931
2283
  const normalized = _normalized.value;
1932
-
1933
- const parseStr = (key: string) => {
1934
- const k = util.esc(key);
1935
- return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1936
- };
2284
+ const syms = normalized.symbolKeys;
2285
+ // a symbol has no source literal, so it is read as `syms[i]` off the closed-over scope
2286
+ const doc = new Doc(["payload", "ctx"], { shape, inst, memo, syms });
2287
+
2288
+ const parseStr = (k: string) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
2289
+
2290
+ // prefixes in place, like util.prefixIssues. newResult must land before the early return: a catchall runs after this and would otherwise write onto the caller's input
2291
+ const prefixStr = (id: string, k: string) => `
2292
+ let ${id}_ab = false;
2293
+ for (let i = 0; i < ${id}.issues.length; i++) {
2294
+ const iss = ${id}.issues[i];
2295
+ iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
2296
+ payload.issues.push(iss);
2297
+ if (iss.continue !== true) ${id}_ab = true;
2298
+ }
2299
+ if (${id}_ab && ctx && ctx.abortEarly) {
2300
+ payload.value = newResult;
2301
+ return payload;
2302
+ }`;
1937
2303
 
1938
2304
  doc.write(`const input = payload.value;`);
1939
2305
 
1940
2306
  const ids: any = Object.create(null);
1941
2307
  let counter = 0;
1942
- for (const key of normalized.keys) {
2308
+ for (const key of normalized.allKeys) {
1943
2309
  ids[key] = `key_${counter++}`;
1944
2310
  }
1945
2311
 
1946
2312
  // A: preserve key order {
1947
- doc.write(`const newResult = {};`);
1948
- for (const key of normalized.keys) {
2313
+ doc.write(memo ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
2314
+ for (const key of normalized.allKeys) {
2315
+ if (key === "__proto__") continue;
1949
2316
  const id = ids[key];
1950
- const k = util.esc(key);
2317
+ const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : util.esc(key);
2318
+ const isPresent = `${k} in input`;
1951
2319
  const schema = shape[key];
2320
+ const optin = schema?._zod?.optin;
2321
+ const isOptionalIn = optin !== undefined;
1952
2322
  const isOptionalOut = schema?._zod?.optout === "optional";
1953
2323
 
1954
- doc.write(`const ${id} = ${parseStr(key)};`);
2324
+ doc.write(`const ${id} = ${parseStr(k)};`);
1955
2325
 
1956
- if (isOptionalOut) {
1957
- // For optional-out schemas, ignore errors on absent keys
2326
+ if (isOptionalIn && isOptionalOut) {
2327
+ // For optional-in/out schemas, ignore errors on absent keys — and, like the interpreted path, drop the value produced alongside them. The middle rung goes further: it permits absence without supplying anything in its place, so an absent key contributes nothing at all.
2328
+ const assign = optin === "optional" ? `${id}_present` : `${id}.value !== undefined || ${id}_present`;
1958
2329
  doc.write(`
1959
- if (${id}.issues.length) {
1960
- if (${k} in input) {
1961
- payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1962
- ...iss,
1963
- path: iss.path ? [${k}, ...iss.path] : [${k}]
1964
- })));
2330
+ const ${id}_present = ${isPresent};
2331
+ if (!${id}.issues.length || ${id}_present) {
2332
+ if (${id}.issues.length) {${prefixStr(id, k)}
2333
+ }
2334
+
2335
+ if (${assign}) {
2336
+ newResult[${k}] = ${id}.value;
1965
2337
  }
1966
2338
  }
1967
-
1968
- if (${id}.value === undefined) {
1969
- if (${k} in input) {
1970
- newResult[${k}] = undefined;
2339
+
2340
+ `);
2341
+ } else if (!isOptionalIn) {
2342
+ doc.write(`
2343
+ const ${id}_present = ${isPresent};
2344
+ if (${id}.issues.length) {${prefixStr(id, k)}
2345
+ }
2346
+ if (!${id}_present && !${id}.issues.length) {
2347
+ payload.issues.push({
2348
+ code: "invalid_type",
2349
+ expected: "nonoptional",
2350
+ input: undefined,
2351
+ path: [${k}]
2352
+ });
2353
+ if (ctx && ctx.abortEarly) {
2354
+ payload.value = newResult;
2355
+ return payload;
1971
2356
  }
1972
- } else {
2357
+ }
2358
+
2359
+ if (${id}_present) {
1973
2360
  newResult[${k}] = ${id}.value;
1974
2361
  }
1975
-
2362
+
1976
2363
  `);
1977
2364
  } else {
1978
2365
  doc.write(`
1979
- if (${id}.issues.length) {
1980
- payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1981
- ...iss,
1982
- path: iss.path ? [${k}, ...iss.path] : [${k}]
1983
- })));
2366
+ if (${id}.issues.length) {${prefixStr(id, k)}
1984
2367
  }
1985
-
1986
- if (${id}.value === undefined) {
1987
- if (${k} in input) {
1988
- newResult[${k}] = undefined;
1989
- }
1990
- } else {
2368
+ `);
2369
+ if (optin === "defaulted") {
2370
+ doc.write(`newResult[${k}] = ${id}.value;`);
2371
+ } else {
2372
+ doc.write(`
2373
+ if (${id}.value !== undefined || ${isPresent}) {
1991
2374
  newResult[${k}] = ${id}.value;
1992
2375
  }
1993
-
1994
2376
  `);
2377
+ }
1995
2378
  }
1996
2379
  }
1997
2380
 
1998
2381
  doc.write(`payload.value = newResult;`);
1999
2382
  doc.write(`return payload;`);
2000
- const fn = doc.compile();
2001
- return (payload: any, ctx: any) => fn(shape, payload, ctx);
2383
+ // closing `shape` in is what pays: turbofan specializes the parser against that one shape object, so every `shape[k]._zod.run` folds to a known callee. as a parameter it stays a generic load and measures 13% slower even with the forwarding frame gone
2384
+ return doc.compile() as (payload: any, ctx: any) => any;
2002
2385
  };
2003
2386
 
2004
2387
  let fastpass!: ReturnType<typeof generateFastpass>;
@@ -2031,7 +2414,7 @@ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$
2031
2414
  payload = fastpass(payload, ctx);
2032
2415
 
2033
2416
  if (!catchall) return payload;
2034
- return handleCatchall([], input, payload, ctx, value, inst);
2417
+ return handleCatchall([], input, payload, ctx, value, inst, ctx?.abortEarly === true);
2035
2418
  }
2036
2419
 
2037
2420
  return superParse(payload, ctx);
@@ -2066,7 +2449,7 @@ export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $Zo
2066
2449
  output: $InferUnionOutput<T[number]>;
2067
2450
  input: $InferUnionInput<T[number]>;
2068
2451
  // if any element in the union is optional, then the union is optional
2069
- optin: IsOptionalIn<T[number]> extends false ? "optional" | undefined : "optional";
2452
+ optin: IsOptionalIn<T[number]> extends false ? "optional" | "defaulted" | undefined : "optional" | "defaulted";
2070
2453
  optout: IsOptionalOut<T[number]> extends false ? "optional" | undefined : "optional";
2071
2454
  }
2072
2455
 
@@ -2103,34 +2486,37 @@ function handleUnionResults(results: ParsePayload[], final: ParsePayload, inst:
2103
2486
  export const $ZodUnion: core.$constructor<$ZodUnion> = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def) => {
2104
2487
  $ZodType.init(inst, def);
2105
2488
 
2106
- util.defineLazy(inst._zod, "optin", () =>
2107
- def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined
2489
+ util.defineLazyInternal(inst, "optin", (zod) =>
2490
+ zod.def.options.some((o) => o._zod.optin === "defaulted")
2491
+ ? "defaulted"
2492
+ : zod.def.options.some((o) => o._zod.optin !== undefined)
2493
+ ? "optional"
2494
+ : undefined
2108
2495
  );
2109
2496
 
2110
- util.defineLazy(inst._zod, "optout", () =>
2111
- def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined
2497
+ util.defineLazyInternal(inst, "optout", (zod) =>
2498
+ zod.def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined
2112
2499
  );
2113
2500
 
2114
- util.defineLazy(inst._zod, "values", () => {
2115
- if (def.options.every((o) => o._zod.values)) {
2116
- return new Set<util.Primitive>(def.options.flatMap((option) => Array.from(option._zod.values!)));
2501
+ util.defineLazyInternal(inst, "values", (zod) => {
2502
+ if (zod.def.options.every((o) => o._zod.values)) {
2503
+ return new Set<util.Primitive>(zod.def.options.flatMap((option) => Array.from(option._zod.values!)));
2117
2504
  }
2118
2505
  return undefined;
2119
2506
  });
2120
2507
 
2121
- util.defineLazy(inst._zod, "pattern", () => {
2122
- if (def.options.every((o) => o._zod.pattern)) {
2123
- const patterns = def.options.map((o) => o._zod.pattern);
2508
+ util.defineLazyInternal(inst, "pattern", (zod) => {
2509
+ if (zod.def.options.every((o) => o._zod.pattern)) {
2510
+ const patterns = zod.def.options.map((o) => o._zod.pattern);
2124
2511
  return new RegExp(`^(${patterns.map((p) => util.cleanRegex(p!.source)).join("|")})$`);
2125
2512
  }
2126
2513
  return undefined;
2127
2514
  });
2128
2515
 
2129
- const single = def.options.length === 1;
2130
- const first = def.options[0]._zod.run;
2516
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
2131
2517
 
2132
2518
  inst._zod.parse = (payload, ctx) => {
2133
- if (single) {
2519
+ if (first) {
2134
2520
  return first(payload, ctx);
2135
2521
  }
2136
2522
  let async = false;
@@ -2166,14 +2552,17 @@ function handleExclusiveUnionResults(
2166
2552
  inst: $ZodUnion,
2167
2553
  ctx?: ParseContext
2168
2554
  ) {
2169
- const successes = results.filter((r) => r.issues.length === 0);
2555
+ const matches: number[] = [];
2556
+ for (let i = 0; i < results.length; i++) {
2557
+ if (results[i].issues.length === 0) matches.push(i);
2558
+ }
2170
2559
 
2171
- if (successes.length === 1) {
2172
- final.value = successes[0].value;
2560
+ if (matches.length === 1) {
2561
+ final.value = results[matches[0]].value;
2173
2562
  return final;
2174
2563
  }
2175
2564
 
2176
- if (successes.length === 0) {
2565
+ if (matches.length === 0) {
2177
2566
  // No matches - same as regular union
2178
2567
  final.issues.push({
2179
2568
  code: "invalid_union",
@@ -2189,6 +2578,7 @@ function handleExclusiveUnionResults(
2189
2578
  inst,
2190
2579
  errors: [],
2191
2580
  inclusive: false,
2581
+ matches,
2192
2582
  });
2193
2583
  }
2194
2584
 
@@ -2206,11 +2596,10 @@ export const $ZodXor: core.$constructor<$ZodXor> = /*@__PURE__*/ core.$construct
2206
2596
  $ZodUnion.init(inst, def);
2207
2597
  def.inclusive = false;
2208
2598
 
2209
- const single = def.options.length === 1;
2210
- const first = def.options[0]._zod.run;
2599
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
2211
2600
 
2212
2601
  inst._zod.parse = (payload, ctx) => {
2213
- if (single) {
2602
+ if (first) {
2214
2603
  return first(payload, ctx);
2215
2604
  }
2216
2605
  let async = false;
@@ -2261,6 +2650,65 @@ export interface $ZodDiscriminatedUnionInternals<
2261
2650
  > extends $ZodUnionInternals<Options> {
2262
2651
  def: $ZodDiscriminatedUnionDef<Options, Disc>;
2263
2652
  propValues: util.PropValues;
2653
+ bag: util.LoosePartial<{
2654
+ optionsMap: Map<util.Primitive, $ZodType | null>;
2655
+ }>;
2656
+ }
2657
+
2658
+ /** The discriminator values a member of `Options` can declare. An omittable discriminator contributes `undefined`, matching what `propValues` claims for it. */
2659
+ export type $DiscriminatorValue<Options extends readonly SomeType[], Disc extends string> = {
2660
+ [I in keyof Options]: Options[I] extends { _zod: { output: infer Out } }
2661
+ ? Disc extends keyof Out
2662
+ ? Out[Disc]
2663
+ : never
2664
+ : never;
2665
+ }[number];
2666
+
2667
+ /** The member of `Options` that declares `V`. */
2668
+ export type $DiscriminatedOption<Options extends readonly SomeType[], Disc extends string, V> = {
2669
+ [I in keyof Options]: Options[I] extends { _zod: { output: infer Out } }
2670
+ ? Disc extends keyof Out
2671
+ ? V extends Out[Disc]
2672
+ ? Options[I]
2673
+ : never
2674
+ : never
2675
+ : never;
2676
+ }[number];
2677
+
2678
+ /** Returns the option whose discriminator claims `value`, or throws if ambiguous. */
2679
+ export function getDiscriminatedOption<
2680
+ Options extends readonly SomeType[],
2681
+ Disc extends string,
2682
+ const V extends $DiscriminatorValue<Options, Disc>,
2683
+ >(union: $ZodDiscriminatedUnion<Options, Disc>, value: V): $DiscriminatedOption<Options, Disc, V> {
2684
+ const internals = union._zod;
2685
+ let map = internals.bag.optionsMap;
2686
+ if (!map) {
2687
+ map = discriminatorMap(internals.def);
2688
+ internals.bag.optionsMap = map;
2689
+ }
2690
+ const option = map.get(value as util.Primitive);
2691
+ if (option === null) throw new Error(`Ambiguous discriminator value "${String(value)}"`);
2692
+ return option as any;
2693
+ }
2694
+
2695
+ function discriminatorMap(def: $ZodDiscriminatedUnionDef<readonly SomeType[]>): Map<util.Primitive, $ZodType | null> {
2696
+ const map = new Map<util.Primitive, $ZodType | null>();
2697
+ for (const option of def.options as readonly $ZodType[]) {
2698
+ const values = option._zod.propValues?.[def.discriminator];
2699
+ if (!values || values.size === 0)
2700
+ throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
2701
+ for (const value of values) {
2702
+ if (map.has(value)) {
2703
+ if (value !== undefined) throw new Error(`Duplicate discriminator value "${String(value)}"`);
2704
+ // keep the collision marked so a later member cannot reclaim it
2705
+ map.set(value, null);
2706
+ } else {
2707
+ map.set(value, option);
2708
+ }
2709
+ }
2710
+ }
2711
+ return map;
2264
2712
  }
2265
2713
 
2266
2714
  export interface $ZodDiscriminatedUnion<
@@ -2278,39 +2726,37 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
2278
2726
  $ZodUnion.init(inst, def);
2279
2727
 
2280
2728
  const _super = inst._zod.parse;
2281
- util.defineLazy(inst._zod, "propValues", () => {
2729
+ util.defineLazyInternal(inst, "propValues", (zod) => {
2282
2730
  const propValues: util.PropValues = {};
2283
- for (const option of def.options) {
2731
+ let undefinedCount = 0;
2732
+ for (const option of zod.def.options) {
2284
2733
  const pv = option._zod.propValues;
2285
2734
  if (!pv || Object.keys(pv).length === 0)
2286
- throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
2735
+ throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
2736
+ if (pv[zod.def.discriminator]?.has(undefined)) undefinedCount++;
2287
2737
  for (const [k, v] of Object.entries(pv!)) {
2288
- if (!propValues[k]) propValues[k] = new Set();
2738
+ if (!Object.prototype.hasOwnProperty.call(propValues, k)) {
2739
+ util.assignProp(propValues, k, new Set());
2740
+ }
2289
2741
  for (const val of v) {
2290
2742
  propValues[k].add(val);
2291
2743
  }
2292
2744
  }
2293
2745
  }
2746
+ if (!zod.def.unionFallback && undefinedCount > 1) propValues[zod.def.discriminator]?.delete(undefined);
2294
2747
  return propValues;
2295
2748
  });
2296
2749
 
2297
- const disc = util.cached(() => {
2298
- const opts = def.options as $ZodTypeDiscriminable[];
2299
- const map: Map<util.Primitive, $ZodType> = new Map();
2300
- for (const o of opts) {
2301
- const values = o._zod.propValues?.[def.discriminator];
2302
- if (!values || values.size === 0)
2303
- throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
2304
- for (const v of values) {
2305
- if (map.has(v)) {
2306
- throw new Error(`Duplicate discriminator value "${String(v)}"`);
2307
- }
2308
- map.set(v, o);
2309
- }
2750
+ // Checked now rather than in the lookup map below, so an option that lacks the discriminator fails at the `discriminatedUnion` call instead of on the first object parsed. Options whose shape cannot be enumerated without resolving it — pipes and lazies — are left to the map.
2751
+ def.options.forEach((option, i) => {
2752
+ const propShape = util.rawShape(option._zod.def);
2753
+ if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) {
2754
+ throw new Error(`Invalid discriminated union option at index "${i}"`);
2310
2755
  }
2311
- return map;
2312
2756
  });
2313
2757
 
2758
+ const disc = util.cached(() => discriminatorMap(def));
2759
+
2314
2760
  inst._zod.parse = (payload, ctx) => {
2315
2761
  const input = payload.value;
2316
2762
  if (!util.isObject(input)) {
@@ -2324,22 +2770,27 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
2324
2770
  return payload;
2325
2771
  }
2326
2772
 
2327
- const opt = disc.value.get(input?.[def.discriminator] as any);
2328
- if (opt) {
2773
+ const value = input?.[def.discriminator];
2774
+ const opt = disc.value.get(value as util.Primitive);
2775
+ // forward metadata cannot choose an encoder for an absent tag
2776
+ if (opt && (value !== undefined || ctx.direction !== "backward")) {
2329
2777
  return opt._zod.run(payload, ctx) as any;
2330
2778
  }
2331
2779
 
2332
- if (def.unionFallback) {
2780
+ // Fall back to union matching when the fast discriminator path fails:
2781
+ // - explicitly enabled via unionFallback, or
2782
+ // - during backward direction (encode), since codec-based discriminators have different values in forward vs backward directions
2783
+ if (def.unionFallback || ctx.direction === "backward") {
2333
2784
  return _super(payload, ctx);
2334
2785
  }
2335
2786
 
2336
2787
  // no matching discriminator
2337
2788
  payload.issues.push({
2338
2789
  code: "invalid_union",
2339
-
2340
2790
  errors: [],
2341
2791
  note: "No matching discriminator",
2342
2792
  discriminator: def.discriminator,
2793
+ options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
2343
2794
  input,
2344
2795
  path: [def.discriminator],
2345
2796
  inst,
@@ -2401,7 +2852,7 @@ export const $ZodIntersection: core.$constructor<$ZodIntersection> = /*@__PURE__
2401
2852
  }
2402
2853
  );
2403
2854
 
2404
- function mergeValues(
2855
+ export function mergeValues(
2405
2856
  a: any,
2406
2857
  b: any
2407
2858
  ): { valid: true; data: any } | { valid: false; mergeErrorPath: (string | number)[] } {
@@ -2419,7 +2870,9 @@ function mergeValues(
2419
2870
  const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
2420
2871
 
2421
2872
  const newObj: any = { ...a, ...b };
2873
+ if (Object.prototype.hasOwnProperty.call(newObj, "__proto__")) delete newObj.__proto__;
2422
2874
  for (const key of sharedKeys) {
2875
+ if (key === "__proto__") continue;
2423
2876
  const sharedValue = mergeValues(a[key], b[key]);
2424
2877
  if (!sharedValue.valid) {
2425
2878
  return {
@@ -2460,44 +2913,52 @@ function mergeValues(
2460
2913
  }
2461
2914
 
2462
2915
  function handleIntersectionResults(result: ParsePayload, left: ParsePayload, right: ParsePayload): ParsePayload {
2463
- // Track which side(s) report each key as unrecognized
2916
+ // Track which side(s) reject each key. A key rejection is reported only when BOTH sides reject it, so a key owned by one branch survives the other's key schema. strictObject reports these as unrecognized_keys; a record with an open key schema reports one invalid_key per key.
2464
2917
  const unrecKeys = new Map<string, { l?: true; r?: true }>();
2465
2918
  let unrecIssue: errors.$ZodRawIssue | undefined;
2919
+ const keyIssues = new Map<string, errors.$ZodRawIssue>();
2466
2920
 
2467
- for (const iss of left.issues) {
2468
- if (iss.code === "unrecognized_keys") {
2921
+ const collect = (iss: errors.$ZodRawIssue, side: "l" | "r"): boolean => {
2922
+ let keys: string[];
2923
+ if (iss.code === "unrecognized_keys" && !iss.path?.length) {
2469
2924
  unrecIssue ??= iss;
2470
- for (const k of iss.keys) {
2471
- if (!unrecKeys.has(k)) unrecKeys.set(k, {});
2472
- unrecKeys.get(k)!.l = true;
2473
- }
2925
+ keys = iss.keys as string[];
2926
+ } else if (iss.code === "invalid_key" && iss.origin === "record" && iss.path?.length === 1) {
2927
+ const k = String(iss.path[0]);
2928
+ if (!keyIssues.has(k)) keyIssues.set(k, iss);
2929
+ keys = [k];
2474
2930
  } else {
2475
- result.issues.push(iss);
2931
+ return false;
2476
2932
  }
2933
+ for (const k of keys) {
2934
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
2935
+ unrecKeys.get(k)![side] = true;
2936
+ }
2937
+ return true;
2938
+ };
2939
+
2940
+ for (const iss of left.issues) {
2941
+ if (!collect(iss, "l")) result.issues.push(iss);
2477
2942
  }
2478
2943
 
2479
2944
  for (const iss of right.issues) {
2480
- if (iss.code === "unrecognized_keys") {
2481
- for (const k of iss.keys) {
2482
- if (!unrecKeys.has(k)) unrecKeys.set(k, {});
2483
- unrecKeys.get(k)!.r = true;
2484
- }
2485
- } else {
2486
- result.issues.push(iss);
2487
- }
2945
+ if (!collect(iss, "r")) result.issues.push(iss);
2488
2946
  }
2489
2947
 
2490
- // Report only keys unrecognized by BOTH sides
2948
+ // Report only keys rejected by BOTH sides
2491
2949
  const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
2492
- if (bothKeys.length && unrecIssue) {
2493
- result.issues.push({ ...unrecIssue, keys: bothKeys });
2950
+ if (bothKeys.length) {
2951
+ const aggregated = unrecIssue ? bothKeys.filter((k) => (unrecIssue!.keys as string[]).includes(k)) : [];
2952
+ if (aggregated.length) result.issues.push({ ...unrecIssue!, keys: aggregated });
2953
+ for (const k of bothKeys) {
2954
+ if (!aggregated.includes(k) && keyIssues.has(k)) result.issues.push(keyIssues.get(k)!);
2955
+ }
2494
2956
  }
2495
2957
 
2496
- if (util.aborted(result)) return result;
2497
-
2498
2958
  const merged = mergeValues(left.value, right.value);
2499
2959
 
2500
2960
  if (!merged.valid) {
2961
+ if (util.aborted(result)) return result;
2501
2962
  throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
2502
2963
  }
2503
2964
 
@@ -2533,7 +2994,7 @@ type TupleInputTypeWithOptionals<T extends util.TupleItems> = T extends readonly
2533
2994
  ...infer Prefix extends SomeType[],
2534
2995
  infer Tail extends SomeType,
2535
2996
  ]
2536
- ? Tail["_zod"]["optin"] extends "optional"
2997
+ ? Tail["_zod"]["optin"] extends "optional" | "defaulted"
2537
2998
  ? [...TupleInputTypeWithOptionals<Prefix>, core.input<Tail>?]
2538
2999
  : TupleInputTypeNoOptionals<T>
2539
3000
  : [];
@@ -2575,6 +3036,8 @@ export interface $ZodTuple<
2575
3036
  export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def) => {
2576
3037
  $ZodType.init(inst, def);
2577
3038
  const items = def.items;
3039
+ const memo = core.globalConfig.memoizer;
3040
+ memo?.attach(inst);
2578
3041
 
2579
3042
  inst._zod.parse = (payload, ctx) => {
2580
3043
  const input = payload.value;
@@ -2588,73 +3051,91 @@ export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$const
2588
3051
  return payload;
2589
3052
  }
2590
3053
 
2591
- payload.value = [];
3054
+ payload.value = memo ? memo.alloc(inst, payload, [] as unknown[], ctx) : [];
2592
3055
  const proms: Promise<any>[] = [];
2593
3056
 
2594
- const reversedIndex = [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
2595
- const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;
3057
+ const optinStart = getTupleOptStart(items, "optin");
3058
+ const optoutStart = getTupleOptStart(items, "optout");
2596
3059
 
2597
3060
  if (!def.rest) {
2598
- const tooBig = input.length > items.length;
2599
- const tooSmall = input.length < optStart - 1;
2600
- if (tooBig || tooSmall) {
3061
+ if (input.length < optinStart) {
2601
3062
  payload.issues.push({
2602
- ...(tooBig
2603
- ? { code: "too_big", maximum: items.length, inclusive: true }
2604
- : { code: "too_small", minimum: items.length }),
2605
-
3063
+ code: "too_small",
3064
+ minimum: optinStart,
3065
+ inclusive: true,
2606
3066
  input,
2607
3067
  inst,
2608
3068
  origin: "array" as const,
2609
3069
  });
2610
3070
  return payload;
2611
3071
  }
3072
+ if (input.length > items.length) {
3073
+ payload.issues.push({
3074
+ code: "too_big",
3075
+ maximum: items.length,
3076
+ inclusive: true,
3077
+ input,
3078
+ inst,
3079
+ origin: "array" as const,
3080
+ });
3081
+ }
2612
3082
  }
2613
3083
 
2614
- let i = -1;
2615
- for (const item of items) {
2616
- i++;
2617
- if (i >= input.length) if (i >= optStart) continue;
2618
- const result = item._zod.run(
2619
- {
2620
- value: input[i],
2621
- issues: [],
2622
- },
2623
- ctx
2624
- );
2625
-
2626
- if (result instanceof Promise) {
2627
- proms.push(result.then((result) => handleTupleResult(result, payload, i)));
3084
+ // Run every item in parallel, collecting results into an indexed array. The post-processing in `handleTupleResults` walks them in order so it can decide whether an absent optional-output error can truncate the tail or must be reported to preserve required output.
3085
+ const itemResults: ParsePayload[] = new Array(items.length);
3086
+ // only tracked when there is a rest loop to skip
3087
+ const abortEarly = def.rest ? ctx?.abortEarly : undefined;
3088
+ let itemAborted = false;
3089
+ for (let i = 0; i < items.length; i++) {
3090
+ const r = items[i]._zod.run({ value: input[i], issues: [] }, ctx);
3091
+ if (r instanceof Promise) {
3092
+ proms.push(
3093
+ r.then((rr) => {
3094
+ itemResults[i] = rr;
3095
+ })
3096
+ );
2628
3097
  } else {
2629
- handleTupleResult(result, payload, i);
3098
+ itemResults[i] = r;
3099
+ if (abortEarly && !itemAborted && r.issues.length) itemAborted = util.aborted(r);
2630
3100
  }
2631
3101
  }
2632
3102
 
2633
- if (def.rest) {
3103
+ // sound because rest is non-empty exactly when every fixed index is present, the one case handleTupleResults cannot discard an item's issues
3104
+ if (def.rest && !itemAborted) {
3105
+ let i = items.length - 1;
2634
3106
  const rest = input.slice(items.length);
3107
+ let seen = payload.issues.length;
2635
3108
  for (const el of rest) {
3109
+ if (abortEarly && payload.issues.length !== seen) {
3110
+ if (util.aborted(payload, seen)) break;
3111
+ seen = payload.issues.length;
3112
+ }
2636
3113
  i++;
2637
- const result = def.rest._zod.run(
2638
- {
2639
- value: el,
2640
- issues: [],
2641
- },
2642
- ctx
2643
- );
2644
-
3114
+ const result = def.rest._zod.run({ value: el, issues: [] }, ctx);
2645
3115
  if (result instanceof Promise) {
2646
- proms.push(result.then((result) => handleTupleResult(result, payload, i)));
3116
+ proms.push(result.then((r) => handleTupleResult(r, payload, i)));
2647
3117
  } else {
2648
3118
  handleTupleResult(result, payload, i);
2649
3119
  }
2650
3120
  }
2651
3121
  }
2652
3122
 
2653
- if (proms.length) return Promise.all(proms).then(() => payload);
2654
- return payload;
3123
+ if (proms.length) {
3124
+ return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items, input, optoutStart));
3125
+ }
3126
+ return handleTupleResults(itemResults, payload, items, input, optoutStart);
2655
3127
  };
2656
3128
  });
2657
3129
 
3130
+ function getTupleOptStart(items: readonly $ZodType[], key: "optin" | "optout") {
3131
+ for (let i = items.length - 1; i >= 0; i--) {
3132
+ // optin is a three-rung ladder so any rung above `undefined` permits an absent slot; optout stays two-valued.
3133
+ const omittable = key === "optin" ? items[i]._zod.optin !== undefined : items[i]._zod.optout === "optional";
3134
+ if (!omittable) return i + 1;
3135
+ }
3136
+ return 0;
3137
+ }
3138
+
2658
3139
  function handleTupleResult(result: ParsePayload, final: ParsePayload<any[]>, index: number) {
2659
3140
  if (result.issues.length) {
2660
3141
  final.issues.push(...util.prefixIssues(index, result.issues));
@@ -2662,6 +3143,48 @@ function handleTupleResult(result: ParsePayload, final: ParsePayload<any[]>, ind
2662
3143
  final.value[index] = result.value;
2663
3144
  }
2664
3145
 
3146
+ function handleTupleResults(
3147
+ itemResults: ParsePayload[],
3148
+ final: ParsePayload<any[]>,
3149
+ items: readonly $ZodType[],
3150
+ input: unknown[],
3151
+ optoutStart: number
3152
+ ) {
3153
+ // Walk results in order. Mirror $ZodObject's swallow-on-absent-optional rule, but only after `optoutStart`: the first index where the output tuple tail can be absent.
3154
+ for (let i = 0; i < items.length; i++) {
3155
+ const r = itemResults[i];
3156
+ const isPresent = i < input.length;
3157
+ // The array analog of `handlePropertyResult`'s absent-key early return: the middle rung permits absence without supplying anything in its place, so the tail truncates here instead of materializing whatever the item made of `undefined`.
3158
+ if (!isPresent && i >= optoutStart && items[i]._zod.optin === "optional") {
3159
+ final.value.length = i;
3160
+ break;
3161
+ }
3162
+ if (r.issues.length) {
3163
+ if (!isPresent && i >= optoutStart) {
3164
+ final.value.length = i;
3165
+ break;
3166
+ }
3167
+ final.issues.push(...util.prefixIssues(i, r.issues));
3168
+ }
3169
+ final.value[i] = r.value;
3170
+ }
3171
+
3172
+ // Drop trailing slots that produced `undefined` for absent input
3173
+ // (the array analog of an absent optional key on an object). The
3174
+ // `i >= input.length` floor is critical: an explicit `undefined`
3175
+ // *inside* the input must be preserved even when the schema is
3176
+ // optional-out (e.g. `z.string().or(z.undefined())` accepting an
3177
+ // explicit undefined value).
3178
+ for (let i = final.value.length - 1; i >= input.length; i--) {
3179
+ if (items[i]._zod.optout === "optional" && final.value[i] === undefined) {
3180
+ final.value.length = i;
3181
+ } else {
3182
+ break;
3183
+ }
3184
+ }
3185
+ return final;
3186
+ }
3187
+
2665
3188
  //////////////////////////////////////////
2666
3189
  //////////////////////////////////////////
2667
3190
  ////////// //////////
@@ -2678,6 +3201,7 @@ export interface $ZodRecordDef<Key extends $ZodRecordKey = $ZodRecordKey, Value
2678
3201
  valueType: Value;
2679
3202
  /** @default "strict" - errors on keys not matching keyType. "loose" passes through non-matching keys unchanged. */
2680
3203
  mode?: "strict" | "loose";
3204
+ partial?: boolean;
2681
3205
  }
2682
3206
 
2683
3207
  // export type $InferZodRecordOutput<
@@ -2717,11 +3241,17 @@ export type $InferZodRecordInput<
2717
3241
  Value extends SomeType = $ZodType,
2718
3242
  > = Key extends $partial
2719
3243
  ? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>>
2720
- : Record<core.input<Key> & PropertyKey, core.input<Value>>;
3244
+ : // A value schema that accepts an absent slot makes the key omittable on the way in, exactly as it does in an object shape. The output side keeps every key, since the parser fills each one.
3245
+ [Value] extends [OptionalInSchema]
3246
+ ? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>>
3247
+ : Record<core.input<Key> & PropertyKey, core.input<Value>>;
2721
3248
 
2722
3249
  export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType>
2723
- extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
3250
+ extends $ZodTypeInternals {
2724
3251
  def: $ZodRecordDef<Key, Value>;
3252
+ // members rather than base type arguments, which TypeScript 7.1 reports as circular for `z.json()`
3253
+ output: $InferZodRecordOutput<Key, Value>;
3254
+ input: $InferZodRecordInput<Key, Value>;
2725
3255
  isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
2726
3256
  optin?: "optional" | undefined;
2727
3257
  optout?: "optional" | undefined;
@@ -2735,6 +3265,8 @@ export interface $ZodRecord<Key extends $ZodRecordKey = $ZodRecordKey, Value ext
2735
3265
 
2736
3266
  export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, def) => {
2737
3267
  $ZodType.init(inst, def);
3268
+ const memo = core.globalConfig.memoizer;
3269
+ memo?.attach(inst);
2738
3270
 
2739
3271
  inst._zod.parse = (payload, ctx) => {
2740
3272
  const input = payload.value;
@@ -2750,15 +3282,35 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
2750
3282
  return payload;
2751
3283
  }
2752
3284
 
3285
+ // no guard in either loop below: a record's invalid_key aborts but an enclosing intersection can reconcile it, so a stopped loop hides keys the sibling does not own and the intersection then rejects nothing
2753
3286
  const proms: Promise<any>[] = [];
2754
3287
 
2755
3288
  const values = def.keyType._zod.values;
2756
- if (values) {
2757
- payload.value = {};
3289
+ if (values && !def.partial) {
3290
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
2758
3291
  const recordKeys = new Set<string | symbol>();
2759
3292
  for (const key of values) {
2760
3293
  if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
2761
3294
  recordKeys.add(typeof key === "number" ? key.toString() : key);
3295
+ // A declared __proto__ is stripped but is not an unrecognized key.
3296
+ if (key === "__proto__") continue;
3297
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
3298
+ if (keyResult instanceof Promise) {
3299
+ throw new Error("Async schemas not supported in object keys currently");
3300
+ }
3301
+ if (keyResult.issues.length) {
3302
+ payload.issues.push({
3303
+ code: "invalid_key",
3304
+ origin: "record",
3305
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
3306
+ input: key,
3307
+ path: [key],
3308
+ inst,
3309
+ });
3310
+ continue;
3311
+ }
3312
+ const outKey = keyResult.value as PropertyKey;
3313
+ if (outKey === "__proto__") continue;
2762
3314
  const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
2763
3315
 
2764
3316
  if (result instanceof Promise) {
@@ -2767,14 +3319,14 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
2767
3319
  if (result.issues.length) {
2768
3320
  payload.issues.push(...util.prefixIssues(key, result.issues));
2769
3321
  }
2770
- payload.value[key] = result.value;
3322
+ payload.value[outKey] = result.value;
2771
3323
  })
2772
3324
  );
2773
3325
  } else {
2774
3326
  if (result.issues.length) {
2775
3327
  payload.issues.push(...util.prefixIssues(key, result.issues));
2776
3328
  }
2777
- payload.value[key] = result.value;
3329
+ payload.value[outKey] = result.value;
2778
3330
  }
2779
3331
  }
2780
3332
  }
@@ -2782,8 +3334,14 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
2782
3334
  let unrecognized!: string[];
2783
3335
  for (const key in input) {
2784
3336
  if (!recordKeys.has(key)) {
2785
- unrecognized = unrecognized ?? [];
2786
- unrecognized.push(key);
3337
+ if (def.mode === "loose") {
3338
+ // skip __proto__ so it can't replace the result prototype via the assignment setter on the plain {} we build into
3339
+ if (key === "__proto__") continue;
3340
+ payload.value[key] = input[key];
3341
+ } else {
3342
+ unrecognized = unrecognized ?? [];
3343
+ unrecognized.push(key);
3344
+ }
2787
3345
  }
2788
3346
  }
2789
3347
  if (unrecognized && unrecognized.length > 0) {
@@ -2793,19 +3351,23 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
2793
3351
  input,
2794
3352
  inst,
2795
3353
  keys: unrecognized,
3354
+ continue: true,
2796
3355
  });
2797
3356
  }
2798
3357
  } else {
2799
- payload.value = {};
3358
+ payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
3359
+ // An enumerable key schema declares which keys the record owns, so a key outside the set is unrecognized. A non-enumerable one (regex, refine) is a constraint every key must satisfy, so a failing key is invalid. Only the former is reconcilable against the other side of an intersection.
3360
+ let unrecognized!: string[];
3361
+ // Reflect.ownKeys for Symbol-key support; filter non-enumerable to match z.object()
2800
3362
  for (const key of Reflect.ownKeys(input)) {
2801
3363
  if (key === "__proto__") continue;
3364
+ if (!Object.prototype.propertyIsEnumerable.call(input, key)) continue;
2802
3365
  let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
2803
3366
  if (keyResult instanceof Promise) {
2804
3367
  throw new Error("Async schemas not supported in object keys currently");
2805
3368
  }
2806
3369
 
2807
- // Numeric string fallback: if key is a numeric string and failed, retry with Number(key)
2808
- // This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
3370
+ // Numeric string fallback: if key is a numeric string and failed, retry with Number(key). This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
2809
3371
  const checkNumericKey = typeof key === "string" && regexes.number.test(key) && keyResult.issues.length;
2810
3372
  if (checkNumericKey) {
2811
3373
  const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
@@ -2821,6 +3383,9 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
2821
3383
  if (def.mode === "loose") {
2822
3384
  // Pass through unchanged
2823
3385
  payload.value[key] = input[key];
3386
+ } else if (values) {
3387
+ unrecognized = unrecognized ?? [];
3388
+ unrecognized.push(key as string);
2824
3389
  } else {
2825
3390
  // Default "strict" behavior: error on invalid key
2826
3391
  payload.issues.push({
@@ -2835,6 +3400,10 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
2835
3400
  continue;
2836
3401
  }
2837
3402
 
3403
+ // the guard above tests the raw input key, but the key schema can normalize an ordinary key into __proto__; re-check the key we actually write under
3404
+ const outKey = keyResult.value as PropertyKey;
3405
+ if (outKey === "__proto__") continue;
3406
+
2838
3407
  const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
2839
3408
 
2840
3409
  if (result instanceof Promise) {
@@ -2843,16 +3412,27 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
2843
3412
  if (result.issues.length) {
2844
3413
  payload.issues.push(...util.prefixIssues(key, result.issues));
2845
3414
  }
2846
- payload.value[keyResult.value as PropertyKey] = result.value;
3415
+ payload.value[outKey] = result.value;
2847
3416
  })
2848
3417
  );
2849
3418
  } else {
2850
3419
  if (result.issues.length) {
2851
3420
  payload.issues.push(...util.prefixIssues(key, result.issues));
2852
3421
  }
2853
- payload.value[keyResult.value as PropertyKey] = result.value;
3422
+ payload.value[outKey] = result.value;
2854
3423
  }
2855
3424
  }
3425
+
3426
+ if (unrecognized && unrecognized.length > 0) {
3427
+ payload.issues.push({
3428
+ code: "unrecognized_keys",
3429
+
3430
+ input,
3431
+ inst,
3432
+ keys: unrecognized,
3433
+ continue: true,
3434
+ });
3435
+ }
2856
3436
  }
2857
3437
 
2858
3438
  if (proms.length) {
@@ -2889,6 +3469,8 @@ export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType
2889
3469
 
2890
3470
  export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$constructor("$ZodMap", (inst, def) => {
2891
3471
  $ZodType.init(inst, def);
3472
+ const memo = core.globalConfig.memoizer;
3473
+ memo?.attach(inst);
2892
3474
 
2893
3475
  inst._zod.parse = (payload, ctx) => {
2894
3476
  const input = payload.value;
@@ -2904,9 +3486,15 @@ export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$construct
2904
3486
  }
2905
3487
 
2906
3488
  const proms: Promise<any>[] = [];
2907
- payload.value = new Map();
3489
+ payload.value = memo ? memo.alloc(inst, payload, new Map(), ctx) : new Map();
3490
+ const abortEarly = ctx?.abortEarly;
3491
+ let seen = payload.issues.length;
2908
3492
 
2909
3493
  for (const [key, value] of input) {
3494
+ if (abortEarly && payload.issues.length !== seen) {
3495
+ if (util.aborted(payload, seen)) break;
3496
+ seen = payload.issues.length;
3497
+ }
2910
3498
  const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
2911
3499
  const valueResult = def.valueType._zod.run({ value: value, issues: [] }, ctx);
2912
3500
 
@@ -2924,6 +3512,7 @@ export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$construct
2924
3512
  if (proms.length) return Promise.all(proms).then(() => payload);
2925
3513
  return payload;
2926
3514
  };
3515
+ capSize(inst, mapSize);
2927
3516
  });
2928
3517
 
2929
3518
  function handleMapResult(
@@ -2993,6 +3582,8 @@ export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
2993
3582
 
2994
3583
  export const $ZodSet: core.$constructor<$ZodSet> = /*@__PURE__*/ core.$constructor("$ZodSet", (inst, def) => {
2995
3584
  $ZodType.init(inst, def);
3585
+ const memo = core.globalConfig.memoizer;
3586
+ memo?.attach(inst);
2996
3587
 
2997
3588
  inst._zod.parse = (payload, ctx) => {
2998
3589
  const input = payload.value;
@@ -3007,8 +3598,14 @@ export const $ZodSet: core.$constructor<$ZodSet> = /*@__PURE__*/ core.$construct
3007
3598
  }
3008
3599
 
3009
3600
  const proms: Promise<any>[] = [];
3010
- payload.value = new Set();
3601
+ payload.value = memo ? memo.alloc(inst, payload, new Set(), ctx) : new Set();
3602
+ const abortEarly = ctx?.abortEarly;
3603
+ let seen = payload.issues.length;
3011
3604
  for (const item of input) {
3605
+ if (abortEarly && payload.issues.length !== seen) {
3606
+ if (util.aborted(payload, seen)) break;
3607
+ seen = payload.issues.length;
3608
+ }
3012
3609
  const result = def.valueType._zod.run({ value: item, issues: [] }, ctx);
3013
3610
  if (result instanceof Promise) {
3014
3611
  proms.push(result.then((result) => handleSetResult(result, payload)));
@@ -3018,6 +3615,7 @@ export const $ZodSet: core.$constructor<$ZodSet> = /*@__PURE__*/ core.$construct
3018
3615
  if (proms.length) return Promise.all(proms).then(() => payload);
3019
3616
  return payload;
3020
3617
  };
3618
+ capSize(inst, setSize);
3021
3619
  });
3022
3620
 
3023
3621
  function handleSetResult(result: ParsePayload, final: ParsePayload<Set<any>>) {
@@ -3067,12 +3665,13 @@ export const $ZodEnum: core.$constructor<$ZodEnum> = /*@__PURE__*/ core.$constru
3067
3665
  const valuesSet = new Set<util.Primitive>(values);
3068
3666
  inst._zod.values = valuesSet;
3069
3667
 
3070
- inst._zod.pattern = new RegExp(
3071
- `^(${values
3072
- .filter((k) => util.propertyKeyTypes.has(typeof k))
3073
- .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o.toString()))
3074
- .join("|")})$`
3075
- );
3668
+ util.defineLazyInternal(inst, "pattern", (zod) => {
3669
+ const patternValues = util.getEnumValues(zod.def.entries).filter((k) => util.propertyKeyTypes.has(typeof k));
3670
+ // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
3671
+ return new RegExp(
3672
+ patternValues.length ? `^(${patternValues.map((o) => util.escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$"
3673
+ );
3674
+ });
3076
3675
 
3077
3676
  inst._zod.parse = (payload, _ctx) => {
3078
3677
  const input = payload.value;
@@ -3118,18 +3717,23 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
3118
3717
  "$ZodLiteral",
3119
3718
  (inst, def) => {
3120
3719
  $ZodType.init(inst, def);
3121
- if (def.values.length === 0) {
3122
- throw new Error("Cannot create literal schema with no valid values");
3123
- }
3124
3720
 
3125
3721
  const values = new Set<util.Literal>(def.values);
3126
3722
  inst._zod.values = values;
3127
- inst._zod.pattern = new RegExp(
3128
- `^(${def.values
3129
3723
 
3130
- .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
3131
- .join("|")})$`
3132
- );
3724
+ util.defineLazyInternal(inst, "pattern", (zod) => {
3725
+ const vals = zod.def.values;
3726
+ // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
3727
+ return new RegExp(
3728
+ vals.length
3729
+ ? `^(${vals
3730
+ .map((o: util.Literal) =>
3731
+ typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)
3732
+ )
3733
+ .join("|")})$`
3734
+ : "^[^\\s\\S]$"
3735
+ );
3736
+ });
3133
3737
 
3134
3738
  inst._zod.parse = (payload, _ctx) => {
3135
3739
  const input = payload.value;
@@ -3265,6 +3869,9 @@ export const $ZodTransform: core.$constructor<$ZodTransform> = /*@__PURE__*/ cor
3265
3869
  "$ZodTransform",
3266
3870
  (inst, def) => {
3267
3871
  $ZodType.init(inst, def);
3872
+ inst._zod.optin = "optional";
3873
+ core.globalConfig.memoizer?.guard(inst);
3874
+
3268
3875
  inst._zod.parse = (payload, ctx) => {
3269
3876
  if (ctx.direction === "backward") {
3270
3877
  throw new core.$ZodEncodeError(inst.constructor.name);
@@ -3304,7 +3911,7 @@ export interface $ZodOptionalDef<T extends SomeType = $ZodType> extends $ZodType
3304
3911
  export interface $ZodOptionalInternals<T extends SomeType = $ZodType>
3305
3912
  extends $ZodTypeInternals<core.output<T> | undefined, core.input<T> | undefined> {
3306
3913
  def: $ZodOptionalDef<T>;
3307
- optin: "optional";
3914
+ optin: "optional" | "defaulted";
3308
3915
  optout: "optional";
3309
3916
  isst: never;
3310
3917
  values: T["_zod"]["values"];
@@ -3315,36 +3922,39 @@ export interface $ZodOptional<T extends SomeType = $ZodType> extends $ZodType {
3315
3922
  _zod: $ZodOptionalInternals<T>;
3316
3923
  }
3317
3924
 
3318
- function handleOptionalResult(result: ParsePayload, input: unknown) {
3319
- if (result.issues.length && input === undefined) {
3320
- return { issues: [], value: undefined };
3321
- }
3322
- return result;
3925
+ function handleOptionalResult(payload: ParsePayload, result: ParsePayload) {
3926
+ // A substituting schema that still failed has no usable answer; yield undefined. Its issues are simply dropped: it ran on a payload of its own, so there is no shared array to truncate and nothing of the caller's to lose with it.
3927
+ payload.value = result.issues.length ? undefined : result.value;
3928
+ return payload;
3323
3929
  }
3324
3930
 
3325
3931
  export const $ZodOptional: core.$constructor<$ZodOptional> = /*@__PURE__*/ core.$constructor(
3326
3932
  "$ZodOptional",
3327
3933
  (inst, def) => {
3328
3934
  $ZodType.init(inst, def);
3329
- inst._zod.optin = "optional";
3935
+ // .optional() propagates absence rather than substituting for it, so a defaulted inner keeps its rung.
3936
+ util.defineLazyInternal(inst, "optin", (zod) =>
3937
+ zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional"
3938
+ );
3330
3939
  inst._zod.optout = "optional";
3331
3940
 
3332
- util.defineLazy(inst._zod, "values", () => {
3333
- return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
3941
+ util.defineLazyInternal(inst, "values", (zod) => {
3942
+ const values = (zod.def as $ZodOptionalDef).innerType._zod.values;
3943
+ return values ? new Set([...values, undefined]) : undefined;
3334
3944
  });
3335
- util.defineLazy(inst._zod, "pattern", () => {
3336
- const pattern = def.innerType._zod.pattern;
3945
+ util.defineLazyInternal(inst, "pattern", (zod) => {
3946
+ const pattern = (zod.def as $ZodOptionalDef).innerType._zod.pattern;
3337
3947
  return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)})?$`) : undefined;
3338
3948
  });
3339
3949
 
3340
3950
  inst._zod.parse = (payload, ctx) => {
3341
- if (def.innerType._zod.optin === "optional") {
3342
- const result = def.innerType._zod.run(payload, ctx);
3343
- if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, payload.value));
3344
- return handleOptionalResult(result, payload.value);
3345
- }
3346
3951
  if (payload.value === undefined) {
3347
- return payload;
3952
+ // Only the top rung substitutes a value for absence; everything else leaves it intact, which is what .optional() means.
3953
+ if (def.innerType._zod.optin !== "defaulted") return payload;
3954
+ // Its own payload, for the same reason $ZodCatch gets one: a pipe forwards an unrecognized key through the caller's issues array, and this must not read that as the substituting schema failing and drop it.
3955
+ const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
3956
+ if (result instanceof Promise) return result.then((result) => handleOptionalResult(payload, result));
3957
+ return handleOptionalResult(payload, result);
3348
3958
  }
3349
3959
  return def.innerType._zod.run(payload, ctx);
3350
3960
  };
@@ -3380,8 +3990,8 @@ export const $ZodExactOptional: core.$constructor<$ZodExactOptional> = /*@__PURE
3380
3990
  $ZodOptional.init(inst, def);
3381
3991
 
3382
3992
  // Override values/pattern to NOT add undefined
3383
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
3384
- util.defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
3993
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
3994
+ util.defineLazyInternal(inst, "pattern", (zod) => zod.def.innerType._zod.pattern);
3385
3995
 
3386
3996
  // Override parse to just delegate (no undefined handling)
3387
3997
  inst._zod.parse = (payload, ctx) => {
@@ -3420,16 +4030,16 @@ export const $ZodNullable: core.$constructor<$ZodNullable> = /*@__PURE__*/ core.
3420
4030
  "$ZodNullable",
3421
4031
  (inst, def) => {
3422
4032
  $ZodType.init(inst, def);
3423
- util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
3424
- util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
4033
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin);
4034
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
3425
4035
 
3426
- util.defineLazy(inst._zod, "pattern", () => {
3427
- const pattern = def.innerType._zod.pattern;
4036
+ util.defineLazyInternal(inst, "pattern", (zod) => {
4037
+ const pattern = zod.def.innerType._zod.pattern;
3428
4038
  return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)}|null)$`) : undefined;
3429
4039
  });
3430
4040
 
3431
- util.defineLazy(inst._zod, "values", () => {
3432
- return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
4041
+ util.defineLazyInternal(inst, "values", (zod) => {
4042
+ return zod.def.innerType._zod.values ? new Set([...zod.def.innerType._zod.values, null]) : undefined;
3433
4043
  });
3434
4044
 
3435
4045
  inst._zod.parse = (payload, ctx) => {
@@ -3458,7 +4068,7 @@ export interface $ZodDefaultDef<T extends SomeType = $ZodType> extends $ZodTypeD
3458
4068
  export interface $ZodDefaultInternals<T extends SomeType = $ZodType>
3459
4069
  extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
3460
4070
  def: $ZodDefaultDef<T>;
3461
- optin: "optional";
4071
+ optin: "defaulted";
3462
4072
  optout?: "optional" | undefined; // required
3463
4073
  isst: never;
3464
4074
  values: T["_zod"]["values"];
@@ -3474,8 +4084,8 @@ export const $ZodDefault: core.$constructor<$ZodDefault> = /*@__PURE__*/ core.$c
3474
4084
  $ZodType.init(inst, def);
3475
4085
 
3476
4086
  // inst._zod.qin = "true";
3477
- inst._zod.optin = "optional";
3478
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
4087
+ inst._zod.optin = "defaulted";
4088
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
3479
4089
 
3480
4090
  inst._zod.parse = (payload, ctx) => {
3481
4091
  if (ctx.direction === "backward") {
@@ -3523,9 +4133,9 @@ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodType
3523
4133
  }
3524
4134
 
3525
4135
  export interface $ZodPrefaultInternals<T extends SomeType = $ZodType>
3526
- extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
4136
+ extends $ZodTypeInternals<core.output<T>, core.input<T> | undefined> {
3527
4137
  def: $ZodPrefaultDef<T>;
3528
- optin: "optional";
4138
+ optin: "defaulted";
3529
4139
  optout?: "optional" | undefined;
3530
4140
  isst: never;
3531
4141
  values: T["_zod"]["values"];
@@ -3540,8 +4150,8 @@ export const $ZodPrefault: core.$constructor<$ZodPrefault> = /*@__PURE__*/ core.
3540
4150
  (inst, def) => {
3541
4151
  $ZodType.init(inst, def);
3542
4152
 
3543
- inst._zod.optin = "optional";
3544
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
4153
+ inst._zod.optin = "defaulted";
4154
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
3545
4155
 
3546
4156
  inst._zod.parse = (payload, ctx) => {
3547
4157
  if (ctx.direction === "backward") {
@@ -3587,8 +4197,8 @@ export const $ZodNonOptional: core.$constructor<$ZodNonOptional> = /*@__PURE__*/
3587
4197
  (inst, def) => {
3588
4198
  $ZodType.init(inst, def);
3589
4199
 
3590
- util.defineLazy(inst._zod, "values", () => {
3591
- const v = def.innerType._zod.values;
4200
+ util.defineLazyInternal(inst, "values", (zod) => {
4201
+ const v = zod.def.innerType._zod.values;
3592
4202
  return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
3593
4203
  });
3594
4204
 
@@ -3732,11 +4342,33 @@ export interface $ZodCatch<T extends SomeType = $ZodType> extends $ZodType {
3732
4342
  _zod: $ZodCatchInternals<T>;
3733
4343
  }
3734
4344
 
4345
+ function handleCatchResult(payload: ParsePayload, result: ParsePayload, def: $ZodCatchDef, ctx: ParseContextInternal) {
4346
+ if (!result.issues.length) {
4347
+ payload.value = result.value;
4348
+ // The value carries up, so the flag describing it has to carry with it: a back-edge into a node still being parsed must not be frozen by an enclosing readonly, and its checks belong to the node itself. Guarded so the ordinary case adds no own property.
4349
+ if (result.memo) payload.memo = true;
4350
+ return payload;
4351
+ }
4352
+
4353
+ // Spread the inner's own payload, not ours: `value` has to stay the input the catch was handed, and the inner ran on a payload of its own so its issues are already private to this call.
4354
+ payload.value = def.catchValue({
4355
+ ...result,
4356
+ value: payload.value,
4357
+ error: {
4358
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
4359
+ },
4360
+ input: payload.value,
4361
+ });
4362
+ return payload;
4363
+ }
4364
+
3735
4365
  export const $ZodCatch: core.$constructor<$ZodCatch> = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
3736
4366
  $ZodType.init(inst, def);
3737
- util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
3738
- util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
3739
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
4367
+ util.defineLazyInternal(inst, "optin", (zod) =>
4368
+ zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional"
4369
+ );
4370
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
4371
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
3740
4372
 
3741
4373
  inst._zod.parse = (payload, ctx) => {
3742
4374
  if (ctx.direction === "backward") {
@@ -3744,39 +4376,12 @@ export const $ZodCatch: core.$constructor<$ZodCatch> = /*@__PURE__*/ core.$const
3744
4376
  }
3745
4377
 
3746
4378
  // Forward direction (decode): apply catch logic
3747
- const result = def.innerType._zod.run(payload, ctx);
4379
+ const result = def.innerType._zod.run({ value: payload.value, issues: [] }, ctx);
3748
4380
  if (result instanceof Promise) {
3749
- return result.then((result) => {
3750
- payload.value = result.value;
3751
- if (result.issues.length) {
3752
- payload.value = def.catchValue({
3753
- ...payload,
3754
- error: {
3755
- issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
3756
- },
3757
- input: payload.value,
3758
- });
3759
- payload.issues = [];
3760
- }
3761
-
3762
- return payload;
3763
- });
4381
+ return result.then((result) => handleCatchResult(payload, result, def, ctx));
3764
4382
  }
3765
4383
 
3766
- payload.value = result.value;
3767
- if (result.issues.length) {
3768
- payload.value = def.catchValue({
3769
- ...payload,
3770
- error: {
3771
- issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
3772
- },
3773
- input: payload.value,
3774
- });
3775
-
3776
- payload.issues = [];
3777
- }
3778
-
3779
- return payload;
4384
+ return handleCatchResult(payload, result, def, ctx);
3780
4385
  };
3781
4386
  });
3782
4387
 
@@ -3850,10 +4455,10 @@ export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $Z
3850
4455
 
3851
4456
  export const $ZodPipe: core.$constructor<$ZodPipe> = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def) => {
3852
4457
  $ZodType.init(inst, def);
3853
- util.defineLazy(inst._zod, "values", () => def.in._zod.values);
3854
- util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
3855
- util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
3856
- util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
4458
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
4459
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
4460
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
4461
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
3857
4462
 
3858
4463
  inst._zod.parse = (payload, ctx) => {
3859
4464
  if (ctx.direction === "backward") {
@@ -3873,7 +4478,8 @@ export const $ZodPipe: core.$constructor<$ZodPipe> = /*@__PURE__*/ core.$constru
3873
4478
  });
3874
4479
 
3875
4480
  function handlePipeResult(left: ParsePayload, next: $ZodType, ctx: ParseContextInternal) {
3876
- if (left.issues.length) {
4481
+ // Any issue stops the pipe, so a failing refinement never feeds its transform. An unrecognized key is the exception: it describes the input's extra properties, not the value being piped, and an enclosing intersection may yet reconcile it.
4482
+ if (left.issues.some((iss) => iss.code !== "unrecognized_keys")) {
3877
4483
  // prevent further checks
3878
4484
  left.aborted = true;
3879
4485
  return left;
@@ -3909,10 +4515,10 @@ export interface $ZodCodec<A extends SomeType = $ZodType, B extends SomeType = $
3909
4515
 
3910
4516
  export const $ZodCodec: core.$constructor<$ZodCodec> = /*@__PURE__*/ core.$constructor("$ZodCodec", (inst, def) => {
3911
4517
  $ZodType.init(inst, def);
3912
- util.defineLazy(inst._zod, "values", () => def.in._zod.values);
3913
- util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
3914
- util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
3915
- util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
4518
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
4519
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
4520
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
4521
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
3916
4522
 
3917
4523
  inst._zod.parse = (payload, ctx) => {
3918
4524
  const direction = ctx.direction || "forward";
@@ -3966,6 +4572,38 @@ function handleCodecTxResult(left: ParsePayload, value: any, nextSchema: SomeTyp
3966
4572
  return nextSchema._zod.run({ value, issues: left.issues }, ctx);
3967
4573
  }
3968
4574
 
4575
+ /////////////////////////////////////////////////
4576
+ /////////////////////////////////////////////////
4577
+ ////////// //////////
4578
+ ////////// $ZodPreprocess //////////
4579
+ ////////// //////////
4580
+ /////////////////////////////////////////////////
4581
+ /////////////////////////////////////////////////
4582
+ export interface $ZodPreprocessDef<B extends SomeType = $ZodType, I = unknown>
4583
+ extends $ZodPipeDef<$ZodTransform<unknown, I>, B> {
4584
+ in: $ZodTransform<unknown, I>;
4585
+ out: B;
4586
+ }
4587
+
4588
+ export interface $ZodPreprocessInternals<B extends SomeType = $ZodType, I = unknown>
4589
+ extends $ZodPipeInternals<$ZodTransform<unknown, I>, B> {
4590
+ def: $ZodPreprocessDef<B, I>;
4591
+ optin: B["_zod"]["optin"];
4592
+ optout: B["_zod"]["optout"];
4593
+ }
4594
+
4595
+ export interface $ZodPreprocess<B extends SomeType = $ZodType, I = unknown>
4596
+ extends $ZodPipe<$ZodTransform<unknown, I>, B> {
4597
+ _zod: $ZodPreprocessInternals<B, I>;
4598
+ }
4599
+
4600
+ export const $ZodPreprocess: core.$constructor<$ZodPreprocess> = /*@__PURE__*/ core.$constructor(
4601
+ "$ZodPreprocess",
4602
+ (inst, def) => {
4603
+ $ZodPipe.init(inst, def);
4604
+ }
4605
+ );
4606
+
3969
4607
  ////////////////////////////////////////////
3970
4608
  ////////////////////////////////////////////
3971
4609
  ////////// //////////
@@ -3997,10 +4635,10 @@ export const $ZodReadonly: core.$constructor<$ZodReadonly> = /*@__PURE__*/ core.
3997
4635
  "$ZodReadonly",
3998
4636
  (inst, def) => {
3999
4637
  $ZodType.init(inst, def);
4000
- util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
4001
- util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
4002
- util.defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
4003
- util.defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
4638
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.def.innerType._zod.propValues);
4639
+ util.defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
4640
+ util.defineLazyInternal(inst, "optin", (zod) => zod.def.innerType?._zod?.optin);
4641
+ util.defineLazyInternal(inst, "optout", (zod) => zod.def.innerType?._zod?.optout);
4004
4642
 
4005
4643
  inst._zod.parse = (payload, ctx) => {
4006
4644
  if (ctx.direction === "backward") {
@@ -4016,7 +4654,8 @@ export const $ZodReadonly: core.$constructor<$ZodReadonly> = /*@__PURE__*/ core.
4016
4654
  );
4017
4655
 
4018
4656
  function handleReadonlyResult(payload: ParsePayload): ParsePayload {
4019
- payload.value = Object.freeze(payload.value);
4657
+ // A repeat visit hands back a node that is still being built; freezing it here would make the rest of its keys fail to assign.
4658
+ if (!payload.memo) payload.value = Object.freeze(payload.value);
4020
4659
  return payload;
4021
4660
  }
4022
4661
 
@@ -4093,6 +4732,51 @@ export type $PartsToTemplateLiteral<Parts extends $ZodTemplateLiteralPart[]> = [
4093
4732
  : never
4094
4733
  : never;
4095
4734
 
4735
+ // a leaf's pattern source with its own checks folded in: the last pattern-carrying check wins, else length bounds narrow the catch-all, else an integer format narrows the number form. the fold lives here instead of on `_zod.pattern` so a bundle without template literals never pays for it
4736
+ function leafPattern(schema: $ZodType): string | undefined {
4737
+ const def = schema._zod.def as { pattern?: RegExp; format?: string; checks?: checks.$ZodCheck[] };
4738
+ let pattern = def.pattern;
4739
+ let isInt = !!def.format?.includes("int");
4740
+ let minimum: number | undefined;
4741
+ let maximum: number | undefined;
4742
+ for (const ch of def.checks ?? []) {
4743
+ const d = ch._zod.def as { pattern?: RegExp; format?: string; minimum?: number; maximum?: number; length?: number };
4744
+ if (d.pattern) pattern = d.pattern;
4745
+ isInt ||= !!d.format?.includes("int");
4746
+ const lo = d.minimum ?? d.length;
4747
+ const hi = d.maximum ?? d.length;
4748
+ if (lo !== undefined && (minimum === undefined || lo > minimum)) minimum = lo;
4749
+ if (hi !== undefined && (maximum === undefined || hi < maximum)) maximum = hi;
4750
+ }
4751
+ if (pattern) return pattern.source;
4752
+ // an empty range matches nothing at runtime, and `{8,5}` is not a legal quantifier
4753
+ if (minimum !== undefined && maximum !== undefined && minimum > maximum) return "(?!)";
4754
+ if (minimum !== undefined || maximum !== undefined) return regexes.string({ minimum, maximum }).source;
4755
+ const own = schema._zod.pattern;
4756
+ return (isInt && own === regexes.number ? regexes.integer : own)?.source;
4757
+ }
4758
+
4759
+ // a part's pattern source. a wrapper's pattern embeds its inner pattern's source verbatim, so the folded form is substituted in place without knowing the wrapper's own composition; a union's options are joined the way the union builds its own pattern
4760
+ function partPattern(schema: $ZodType): string | undefined {
4761
+ const def = schema._zod.def as { innerType?: $ZodType; options?: $ZodType[] };
4762
+ const own = schema._zod.pattern?.source;
4763
+ // lazy resolves its inner on the internals, not the def
4764
+ const inner = def.innerType ?? (schema._zod as { innerType?: $ZodType }).innerType;
4765
+ if (inner) {
4766
+ const before = inner._zod.pattern?.source;
4767
+ const after = partPattern(inner);
4768
+ if (own && before && after && after !== before) {
4769
+ return own.replace(util.cleanRegex(before), () => util.cleanRegex(after));
4770
+ }
4771
+ return own;
4772
+ }
4773
+ if (def.options) {
4774
+ const sources = def.options.map(partPattern);
4775
+ if (sources.every(Boolean)) return `^(${sources.map((s) => util.cleanRegex(s!)).join("|")})$`;
4776
+ }
4777
+ return leafPattern(schema);
4778
+ }
4779
+
4096
4780
  export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__PURE__*/ core.$constructor(
4097
4781
  "$ZodTemplateLiteral",
4098
4782
  (inst, def) => {
@@ -4101,18 +4785,11 @@ export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__
4101
4785
  for (const part of def.parts) {
4102
4786
  if (typeof part === "object" && part !== null) {
4103
4787
  // is Zod schema
4104
- if (!part._zod.pattern) {
4105
- // if (!source)
4788
+ const source = partPattern(part);
4789
+ if (!source) {
4106
4790
  throw new Error(`Invalid template literal part, no pattern found: ${[...(part as any)._zod.traits].shift()}`);
4107
4791
  }
4108
-
4109
- const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;
4110
-
4111
- if (!source) throw new Error(`Invalid template literal part: ${part._zod.traits}`);
4112
-
4113
- const start = source.startsWith("^") ? 1 : 0;
4114
- const end = source.endsWith("$") ? source.length - 1 : source.length;
4115
- regexParts.push(source.slice(start, end));
4792
+ regexParts.push(util.cleanRegex(source));
4116
4793
  } else if (part === null || util.primitiveTypes.has(typeof part)) {
4117
4794
  regexParts.push(util.escapeRegex(`${part}`));
4118
4795
  } else {
@@ -4232,35 +4909,45 @@ export const $ZodFunction: core.$constructor<$ZodFunction> = /*@__PURE__*/ core.
4232
4909
  "$ZodFunction",
4233
4910
  (inst, def) => {
4234
4911
  $ZodType.init(inst, def);
4235
- inst._def = def;
4912
+ // Defined, not assigned: the classic prototype exposes `_def` as a getter with no setter.
4913
+ Object.defineProperty(inst, "_def", { value: def });
4236
4914
  inst._zod.def = def;
4237
4915
 
4238
4916
  inst.implement = (func) => {
4239
4917
  if (typeof func !== "function") {
4240
4918
  throw new Error("implement() must be called with a function");
4241
4919
  }
4242
- return function (this: any, ...args: never[]) {
4243
- const parsedArgs = inst._def.input ? parse(inst._def.input, args) : args;
4244
- const result = Reflect.apply(func, this, parsedArgs as never[]);
4245
- if (inst._def.output) {
4246
- return parse(inst._def.output, result);
4247
- }
4248
- return result as any;
4249
- };
4920
+ // Defined inline so the closure stays anonymous: binding it to a `const` first names it, which costs 256 bytes per implemented function.
4921
+ return Object.defineProperty(
4922
+ function (this: any, ...args: never[]) {
4923
+ const parsedArgs = inst._def.input ? parse(inst._def.input, args) : args;
4924
+ const result = Reflect.apply(func, this, parsedArgs as never[]);
4925
+ if (inst._def.output) {
4926
+ return parse(inst._def.output, result);
4927
+ }
4928
+ return result as any;
4929
+ },
4930
+ "_zod",
4931
+ { value: inst._zod, enumerable: false }
4932
+ ) as any;
4250
4933
  };
4251
4934
 
4252
4935
  inst.implementAsync = (func) => {
4253
4936
  if (typeof func !== "function") {
4254
4937
  throw new Error("implementAsync() must be called with a function");
4255
4938
  }
4256
- return async function (this: any, ...args: never[]) {
4257
- const parsedArgs = inst._def.input ? await parseAsync(inst._def.input, args) : args;
4258
- const result = await Reflect.apply(func, this, parsedArgs as never[]);
4259
- if (inst._def.output) {
4260
- return await parseAsync(inst._def.output, result);
4261
- }
4262
- return result;
4263
- } as any;
4939
+ return Object.defineProperty(
4940
+ async function (this: any, ...args: never[]) {
4941
+ const parsedArgs = inst._def.input ? await parseAsync(inst._def.input, args) : args;
4942
+ const result = await Reflect.apply(func, this, parsedArgs as never[]);
4943
+ if (inst._def.output) {
4944
+ return await parseAsync(inst._def.output, result);
4945
+ }
4946
+ return result;
4947
+ },
4948
+ "_zod",
4949
+ { value: inst._zod, enumerable: false }
4950
+ ) as any;
4264
4951
  };
4265
4952
 
4266
4953
  inst._zod.parse = (payload, _ctx) => {
@@ -4384,18 +5071,16 @@ export interface $ZodLazy<T extends SomeType = $ZodType> extends $ZodType {
4384
5071
  export const $ZodLazy: core.$constructor<$ZodLazy> = /*@__PURE__*/ core.$constructor("$ZodLazy", (inst, def) => {
4385
5072
  $ZodType.init(inst, def);
4386
5073
 
4387
- // let _innerType!: any;
4388
- // util.defineLazy(def, "getter", () => {
4389
- // if (!_innerType) {
4390
- // _innerType = def.getter();
4391
- // }
4392
- // return () => _innerType;
4393
- // });
4394
- util.defineLazy(inst._zod, "innerType", () => def.getter() as $ZodType);
4395
- util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod?.pattern);
4396
- util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod?.propValues);
4397
- util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod?.optin ?? undefined);
4398
- util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod?.optout ?? undefined);
5074
+ // Cache the resolved inner type on the shared `def` so all clones of this lazy (e.g. via `.describe()`/`.meta()`) share the same inner instance, preserving identity for cycle detection on recursive schemas.
5075
+ util.defineLazy(inst._zod, "innerType", () => {
5076
+ const d = def as $ZodLazyDef & { _cachedInner?: $ZodType };
5077
+ if (!d._cachedInner) d._cachedInner = def.getter() as $ZodType;
5078
+ return d._cachedInner;
5079
+ });
5080
+ util.defineLazyInternal(inst, "pattern", (zod) => zod.innerType?._zod?.pattern);
5081
+ util.defineLazyInternal(inst, "propValues", (zod) => zod.innerType?._zod?.propValues);
5082
+ util.defineLazyInternal(inst, "optin", (zod) => zod.innerType?._zod?.optin ?? undefined);
5083
+ util.defineLazyInternal(inst, "optout", (zod) => zod.innerType?._zod?.optout ?? undefined);
4399
5084
  inst._zod.parse = (payload, ctx) => {
4400
5085
  const inner = inst._zod.innerType;
4401
5086
  return inner._zod.run(payload, ctx);
@@ -4532,7 +5217,10 @@ export type $ZodStringFormatTypes =
4532
5217
  | $ZodBase64
4533
5218
  | $ZodBase64URL
4534
5219
  | $ZodE164
5220
+ | $ZodCreditCard
5221
+ | $ZodIBAN
4535
5222
  | $ZodJWT
4536
5223
  | $ZodCustomStringFormat<"hex">
4537
5224
  | $ZodCustomStringFormat<util.HashFormat>
4538
- | $ZodCustomStringFormat<"hostname">;
5225
+ | $ZodCustomStringFormat<"hostname">
5226
+ | $ZodCustomStringFormat<"currency_code">;