@cabloy/zod 4.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (701) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +208 -0
  3. package/index.cjs +33 -0
  4. package/index.d.cts +4 -0
  5. package/index.d.ts +4 -0
  6. package/index.js +4 -0
  7. package/locales/index.cjs +17 -0
  8. package/locales/index.d.cts +1 -0
  9. package/locales/index.d.ts +1 -0
  10. package/locales/index.js +1 -0
  11. package/locales/package.json +7 -0
  12. package/mini/index.cjs +32 -0
  13. package/mini/index.d.cts +3 -0
  14. package/mini/index.d.ts +3 -0
  15. package/mini/index.js +3 -0
  16. package/mini/package.json +7 -0
  17. package/package.json +135 -0
  18. package/src/index.ts +4 -0
  19. package/src/locales/index.ts +1 -0
  20. package/src/mini/index.ts +3 -0
  21. package/src/v3/ZodError.ts +330 -0
  22. package/src/v3/benchmarks/datetime.ts +58 -0
  23. package/src/v3/benchmarks/discriminatedUnion.ts +80 -0
  24. package/src/v3/benchmarks/index.ts +59 -0
  25. package/src/v3/benchmarks/ipv4.ts +57 -0
  26. package/src/v3/benchmarks/object.ts +69 -0
  27. package/src/v3/benchmarks/primitives.ts +162 -0
  28. package/src/v3/benchmarks/realworld.ts +63 -0
  29. package/src/v3/benchmarks/string.ts +55 -0
  30. package/src/v3/benchmarks/union.ts +80 -0
  31. package/src/v3/errors.ts +13 -0
  32. package/src/v3/external.ts +6 -0
  33. package/src/v3/helpers/enumUtil.ts +17 -0
  34. package/src/v3/helpers/errorUtil.ts +8 -0
  35. package/src/v3/helpers/parseUtil.ts +176 -0
  36. package/src/v3/helpers/partialUtil.ts +34 -0
  37. package/src/v3/helpers/typeAliases.ts +2 -0
  38. package/src/v3/helpers/util.ts +224 -0
  39. package/src/v3/index.ts +4 -0
  40. package/src/v3/locales/en.ts +124 -0
  41. package/src/v3/standard-schema.ts +113 -0
  42. package/src/v3/tests/Mocker.ts +54 -0
  43. package/src/v3/tests/all-errors.test.ts +157 -0
  44. package/src/v3/tests/anyunknown.test.ts +28 -0
  45. package/src/v3/tests/array.test.ts +71 -0
  46. package/src/v3/tests/async-parsing.test.ts +388 -0
  47. package/src/v3/tests/async-refinements.test.ts +46 -0
  48. package/src/v3/tests/base.test.ts +29 -0
  49. package/src/v3/tests/bigint.test.ts +55 -0
  50. package/src/v3/tests/branded.test.ts +53 -0
  51. package/src/v3/tests/catch.test.ts +220 -0
  52. package/src/v3/tests/coerce.test.ts +133 -0
  53. package/src/v3/tests/complex.test.ts +70 -0
  54. package/src/v3/tests/custom.test.ts +31 -0
  55. package/src/v3/tests/date.test.ts +32 -0
  56. package/src/v3/tests/deepmasking.test.ts +186 -0
  57. package/src/v3/tests/default.test.ts +112 -0
  58. package/src/v3/tests/description.test.ts +33 -0
  59. package/src/v3/tests/discriminated-unions.test.ts +315 -0
  60. package/src/v3/tests/enum.test.ts +80 -0
  61. package/src/v3/tests/error.test.ts +551 -0
  62. package/src/v3/tests/firstparty.test.ts +87 -0
  63. package/src/v3/tests/firstpartyschematypes.test.ts +21 -0
  64. package/src/v3/tests/function.test.ts +261 -0
  65. package/src/v3/tests/generics.test.ts +48 -0
  66. package/src/v3/tests/instanceof.test.ts +37 -0
  67. package/src/v3/tests/intersection.test.ts +110 -0
  68. package/src/v3/tests/language-server.source.ts +76 -0
  69. package/src/v3/tests/language-server.test.ts +207 -0
  70. package/src/v3/tests/literal.test.ts +36 -0
  71. package/src/v3/tests/map.test.ts +110 -0
  72. package/src/v3/tests/masking.test.ts +4 -0
  73. package/src/v3/tests/mocker.test.ts +19 -0
  74. package/src/v3/tests/nan.test.ts +24 -0
  75. package/src/v3/tests/nativeEnum.test.ts +87 -0
  76. package/src/v3/tests/nullable.test.ts +42 -0
  77. package/src/v3/tests/number.test.ts +176 -0
  78. package/src/v3/tests/object-augmentation.test.ts +29 -0
  79. package/src/v3/tests/object-in-es5-env.test.ts +29 -0
  80. package/src/v3/tests/object.test.ts +434 -0
  81. package/src/v3/tests/optional.test.ts +42 -0
  82. package/src/v3/tests/parseUtil.test.ts +23 -0
  83. package/src/v3/tests/parser.test.ts +41 -0
  84. package/src/v3/tests/partials.test.ts +243 -0
  85. package/src/v3/tests/pickomit.test.ts +111 -0
  86. package/src/v3/tests/pipeline.test.ts +29 -0
  87. package/src/v3/tests/preprocess.test.ts +186 -0
  88. package/src/v3/tests/primitive.test.ts +440 -0
  89. package/src/v3/tests/promise.test.ts +90 -0
  90. package/src/v3/tests/readonly.test.ts +194 -0
  91. package/src/v3/tests/record.test.ts +171 -0
  92. package/src/v3/tests/recursive.test.ts +197 -0
  93. package/src/v3/tests/refine.test.ts +313 -0
  94. package/src/v3/tests/safeparse.test.ts +27 -0
  95. package/src/v3/tests/set.test.ts +142 -0
  96. package/src/v3/tests/standard-schema.test.ts +83 -0
  97. package/src/v3/tests/string.test.ts +916 -0
  98. package/src/v3/tests/transformer.test.ts +233 -0
  99. package/src/v3/tests/tuple.test.ts +90 -0
  100. package/src/v3/tests/unions.test.ts +57 -0
  101. package/src/v3/tests/validations.test.ts +133 -0
  102. package/src/v3/tests/void.test.ts +15 -0
  103. package/src/v3/types.ts +5138 -0
  104. package/src/v4/classic/checks.ts +32 -0
  105. package/src/v4/classic/coerce.ts +27 -0
  106. package/src/v4/classic/compat.ts +70 -0
  107. package/src/v4/classic/errors.ts +82 -0
  108. package/src/v4/classic/external.ts +51 -0
  109. package/src/v4/classic/from-json-schema.ts +643 -0
  110. package/src/v4/classic/index.ts +5 -0
  111. package/src/v4/classic/iso.ts +90 -0
  112. package/src/v4/classic/parse.ts +82 -0
  113. package/src/v4/classic/schemas.ts +2409 -0
  114. package/src/v4/classic/tests/anyunknown.test.ts +26 -0
  115. package/src/v4/classic/tests/apply.test.ts +59 -0
  116. package/src/v4/classic/tests/array.test.ts +264 -0
  117. package/src/v4/classic/tests/assignability.test.ts +210 -0
  118. package/src/v4/classic/tests/async-parsing.test.ts +381 -0
  119. package/src/v4/classic/tests/async-refinements.test.ts +68 -0
  120. package/src/v4/classic/tests/base.test.ts +7 -0
  121. package/src/v4/classic/tests/bigint.test.ts +54 -0
  122. package/src/v4/classic/tests/brand.test.ts +106 -0
  123. package/src/v4/classic/tests/catch.test.ts +276 -0
  124. package/src/v4/classic/tests/coalesce.test.ts +20 -0
  125. package/src/v4/classic/tests/codec-examples.test.ts +573 -0
  126. package/src/v4/classic/tests/codec.test.ts +562 -0
  127. package/src/v4/classic/tests/coerce.test.ts +160 -0
  128. package/src/v4/classic/tests/continuability.test.ts +374 -0
  129. package/src/v4/classic/tests/custom.test.ts +40 -0
  130. package/src/v4/classic/tests/date.test.ts +62 -0
  131. package/src/v4/classic/tests/datetime.test.ts +302 -0
  132. package/src/v4/classic/tests/default.test.ts +365 -0
  133. package/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
  134. package/src/v4/classic/tests/description.test.ts +32 -0
  135. package/src/v4/classic/tests/discriminated-unions.test.ts +661 -0
  136. package/src/v4/classic/tests/enum.test.ts +285 -0
  137. package/src/v4/classic/tests/error-utils.test.ts +595 -0
  138. package/src/v4/classic/tests/error.test.ts +711 -0
  139. package/src/v4/classic/tests/file.test.ts +96 -0
  140. package/src/v4/classic/tests/firstparty.test.ts +179 -0
  141. package/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
  142. package/src/v4/classic/tests/from-json-schema.test.ts +734 -0
  143. package/src/v4/classic/tests/function.test.ts +360 -0
  144. package/src/v4/classic/tests/generics.test.ts +72 -0
  145. package/src/v4/classic/tests/hash.test.ts +68 -0
  146. package/src/v4/classic/tests/index.test.ts +939 -0
  147. package/src/v4/classic/tests/instanceof.test.ts +60 -0
  148. package/src/v4/classic/tests/intersection.test.ts +198 -0
  149. package/src/v4/classic/tests/json.test.ts +109 -0
  150. package/src/v4/classic/tests/lazy.test.ts +227 -0
  151. package/src/v4/classic/tests/literal.test.ts +117 -0
  152. package/src/v4/classic/tests/locales_ka.test.ts +29 -0
  153. package/src/v4/classic/tests/map.test.ts +330 -0
  154. package/src/v4/classic/tests/nan.test.ts +21 -0
  155. package/src/v4/classic/tests/nested-refine.test.ts +168 -0
  156. package/src/v4/classic/tests/nonoptional.test.ts +101 -0
  157. package/src/v4/classic/tests/nullable.test.ts +22 -0
  158. package/src/v4/classic/tests/number.test.ts +311 -0
  159. package/src/v4/classic/tests/object.test.ts +640 -0
  160. package/src/v4/classic/tests/optional.test.ts +223 -0
  161. package/src/v4/classic/tests/partial.test.ts +427 -0
  162. package/src/v4/classic/tests/pickomit.test.ts +211 -0
  163. package/src/v4/classic/tests/pipe.test.ts +101 -0
  164. package/src/v4/classic/tests/prefault.test.ts +74 -0
  165. package/src/v4/classic/tests/preprocess.test.ts +282 -0
  166. package/src/v4/classic/tests/primitive.test.ts +175 -0
  167. package/src/v4/classic/tests/promise.test.ts +81 -0
  168. package/src/v4/classic/tests/prototypes.test.ts +23 -0
  169. package/src/v4/classic/tests/readonly.test.ts +252 -0
  170. package/src/v4/classic/tests/record.test.ts +632 -0
  171. package/src/v4/classic/tests/recursive-types.test.ts +582 -0
  172. package/src/v4/classic/tests/refine.test.ts +570 -0
  173. package/src/v4/classic/tests/registries.test.ts +243 -0
  174. package/src/v4/classic/tests/set.test.ts +181 -0
  175. package/src/v4/classic/tests/standard-schema.test.ts +134 -0
  176. package/src/v4/classic/tests/string-formats.test.ts +125 -0
  177. package/src/v4/classic/tests/string.test.ts +1200 -0
  178. package/src/v4/classic/tests/stringbool.test.ts +106 -0
  179. package/src/v4/classic/tests/template-literal.test.ts +771 -0
  180. package/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  181. package/src/v4/classic/tests/to-json-schema.test.ts +2990 -0
  182. package/src/v4/classic/tests/transform.test.ts +361 -0
  183. package/src/v4/classic/tests/tuple.test.ts +183 -0
  184. package/src/v4/classic/tests/union.test.ts +219 -0
  185. package/src/v4/classic/tests/url.test.ts +13 -0
  186. package/src/v4/classic/tests/validations.test.ts +283 -0
  187. package/src/v4/classic/tests/void.test.ts +12 -0
  188. package/src/v4/core/api.ts +1798 -0
  189. package/src/v4/core/checks.ts +1293 -0
  190. package/src/v4/core/config.ts +15 -0
  191. package/src/v4/core/core.ts +138 -0
  192. package/src/v4/core/doc.ts +44 -0
  193. package/src/v4/core/errors.ts +448 -0
  194. package/src/v4/core/index.ts +16 -0
  195. package/src/v4/core/json-schema-generator.ts +126 -0
  196. package/src/v4/core/json-schema-processors.ts +667 -0
  197. package/src/v4/core/json-schema.ts +147 -0
  198. package/src/v4/core/parse.ts +195 -0
  199. package/src/v4/core/regexes.ts +185 -0
  200. package/src/v4/core/registries.ts +105 -0
  201. package/src/v4/core/schemas.ts +4562 -0
  202. package/src/v4/core/standard-schema.ts +159 -0
  203. package/src/v4/core/tests/extend.test.ts +59 -0
  204. package/src/v4/core/tests/index.test.ts +46 -0
  205. package/src/v4/core/tests/locales/be.test.ts +124 -0
  206. package/src/v4/core/tests/locales/en.test.ts +22 -0
  207. package/src/v4/core/tests/locales/es.test.ts +181 -0
  208. package/src/v4/core/tests/locales/he.test.ts +379 -0
  209. package/src/v4/core/tests/locales/hr.test.ts +163 -0
  210. package/src/v4/core/tests/locales/nl.test.ts +46 -0
  211. package/src/v4/core/tests/locales/ru.test.ts +128 -0
  212. package/src/v4/core/tests/locales/tr.test.ts +69 -0
  213. package/src/v4/core/tests/locales/uz.test.ts +105 -0
  214. package/src/v4/core/tests/record-constructor.test.ts +67 -0
  215. package/src/v4/core/tests/recursive-tuples.test.ts +45 -0
  216. package/src/v4/core/to-json-schema.ts +613 -0
  217. package/src/v4/core/util.ts +984 -0
  218. package/src/v4/core/versions.ts +5 -0
  219. package/src/v4/core/zsf.ts +323 -0
  220. package/src/v4/index.ts +4 -0
  221. package/src/v4/locales/ar.ts +115 -0
  222. package/src/v4/locales/az.ts +111 -0
  223. package/src/v4/locales/be.ts +176 -0
  224. package/src/v4/locales/bg.ts +128 -0
  225. package/src/v4/locales/ca.ts +116 -0
  226. package/src/v4/locales/cs.ts +118 -0
  227. package/src/v4/locales/da.ts +123 -0
  228. package/src/v4/locales/de.ts +116 -0
  229. package/src/v4/locales/en.ts +119 -0
  230. package/src/v4/locales/eo.ts +118 -0
  231. package/src/v4/locales/es.ts +141 -0
  232. package/src/v4/locales/fa.ts +126 -0
  233. package/src/v4/locales/fi.ts +121 -0
  234. package/src/v4/locales/fr-CA.ts +116 -0
  235. package/src/v4/locales/fr.ts +116 -0
  236. package/src/v4/locales/he.ts +246 -0
  237. package/src/v4/locales/hr.ts +131 -0
  238. package/src/v4/locales/hu.ts +117 -0
  239. package/src/v4/locales/hy.ts +164 -0
  240. package/src/v4/locales/id.ts +115 -0
  241. package/src/v4/locales/index.ts +50 -0
  242. package/src/v4/locales/is.ts +119 -0
  243. package/src/v4/locales/it.ts +116 -0
  244. package/src/v4/locales/ja.ts +114 -0
  245. package/src/v4/locales/ka.ts +123 -0
  246. package/src/v4/locales/kh.ts +7 -0
  247. package/src/v4/locales/km.ts +119 -0
  248. package/src/v4/locales/ko.ts +121 -0
  249. package/src/v4/locales/lt.ts +239 -0
  250. package/src/v4/locales/mk.ts +118 -0
  251. package/src/v4/locales/ms.ts +115 -0
  252. package/src/v4/locales/nl.ts +121 -0
  253. package/src/v4/locales/no.ts +116 -0
  254. package/src/v4/locales/ota.ts +117 -0
  255. package/src/v4/locales/pl.ts +118 -0
  256. package/src/v4/locales/ps.ts +126 -0
  257. package/src/v4/locales/pt.ts +116 -0
  258. package/src/v4/locales/ru.ts +176 -0
  259. package/src/v4/locales/sl.ts +118 -0
  260. package/src/v4/locales/sv.ts +119 -0
  261. package/src/v4/locales/ta.ts +118 -0
  262. package/src/v4/locales/th.ts +119 -0
  263. package/src/v4/locales/tr.ts +111 -0
  264. package/src/v4/locales/ua.ts +7 -0
  265. package/src/v4/locales/uk.ts +117 -0
  266. package/src/v4/locales/ur.ts +119 -0
  267. package/src/v4/locales/uz.ts +117 -0
  268. package/src/v4/locales/vi.ts +117 -0
  269. package/src/v4/locales/yo.ts +124 -0
  270. package/src/v4/locales/zh-CN.ts +116 -0
  271. package/src/v4/locales/zh-TW.ts +115 -0
  272. package/src/v4/mini/checks.ts +32 -0
  273. package/src/v4/mini/coerce.ts +27 -0
  274. package/src/v4/mini/external.ts +40 -0
  275. package/src/v4/mini/index.ts +3 -0
  276. package/src/v4/mini/iso.ts +66 -0
  277. package/src/v4/mini/parse.ts +14 -0
  278. package/src/v4/mini/schemas.ts +1916 -0
  279. package/src/v4/mini/tests/apply.test.ts +24 -0
  280. package/src/v4/mini/tests/assignability.test.ts +129 -0
  281. package/src/v4/mini/tests/brand.test.ts +94 -0
  282. package/src/v4/mini/tests/checks.test.ts +144 -0
  283. package/src/v4/mini/tests/codec.test.ts +529 -0
  284. package/src/v4/mini/tests/computed.test.ts +36 -0
  285. package/src/v4/mini/tests/error.test.ts +22 -0
  286. package/src/v4/mini/tests/functions.test.ts +5 -0
  287. package/src/v4/mini/tests/index.test.ts +963 -0
  288. package/src/v4/mini/tests/number.test.ts +95 -0
  289. package/src/v4/mini/tests/object.test.ts +227 -0
  290. package/src/v4/mini/tests/prototypes.test.ts +43 -0
  291. package/src/v4/mini/tests/recursive-types.test.ts +275 -0
  292. package/src/v4/mini/tests/standard-schema.test.ts +50 -0
  293. package/src/v4/mini/tests/string.test.ts +347 -0
  294. package/src/v4-mini/index.ts +3 -0
  295. package/v3/ZodError.cjs +138 -0
  296. package/v3/ZodError.d.cts +164 -0
  297. package/v3/ZodError.d.ts +164 -0
  298. package/v3/ZodError.js +133 -0
  299. package/v3/errors.cjs +17 -0
  300. package/v3/errors.d.cts +5 -0
  301. package/v3/errors.d.ts +5 -0
  302. package/v3/errors.js +9 -0
  303. package/v3/external.cjs +22 -0
  304. package/v3/external.d.cts +6 -0
  305. package/v3/external.d.ts +6 -0
  306. package/v3/external.js +6 -0
  307. package/v3/helpers/enumUtil.cjs +2 -0
  308. package/v3/helpers/enumUtil.d.cts +8 -0
  309. package/v3/helpers/enumUtil.d.ts +8 -0
  310. package/v3/helpers/enumUtil.js +1 -0
  311. package/v3/helpers/errorUtil.cjs +9 -0
  312. package/v3/helpers/errorUtil.d.cts +9 -0
  313. package/v3/helpers/errorUtil.d.ts +9 -0
  314. package/v3/helpers/errorUtil.js +6 -0
  315. package/v3/helpers/parseUtil.cjs +124 -0
  316. package/v3/helpers/parseUtil.d.cts +78 -0
  317. package/v3/helpers/parseUtil.d.ts +78 -0
  318. package/v3/helpers/parseUtil.js +109 -0
  319. package/v3/helpers/partialUtil.cjs +2 -0
  320. package/v3/helpers/partialUtil.d.cts +8 -0
  321. package/v3/helpers/partialUtil.d.ts +8 -0
  322. package/v3/helpers/partialUtil.js +1 -0
  323. package/v3/helpers/typeAliases.cjs +2 -0
  324. package/v3/helpers/typeAliases.d.cts +2 -0
  325. package/v3/helpers/typeAliases.d.ts +2 -0
  326. package/v3/helpers/typeAliases.js +1 -0
  327. package/v3/helpers/util.cjs +137 -0
  328. package/v3/helpers/util.d.cts +85 -0
  329. package/v3/helpers/util.d.ts +85 -0
  330. package/v3/helpers/util.js +133 -0
  331. package/v3/index.cjs +33 -0
  332. package/v3/index.d.cts +4 -0
  333. package/v3/index.d.ts +4 -0
  334. package/v3/index.js +4 -0
  335. package/v3/locales/en.cjs +112 -0
  336. package/v3/locales/en.d.cts +3 -0
  337. package/v3/locales/en.d.ts +3 -0
  338. package/v3/locales/en.js +109 -0
  339. package/v3/package.json +7 -0
  340. package/v3/standard-schema.cjs +2 -0
  341. package/v3/standard-schema.d.cts +102 -0
  342. package/v3/standard-schema.d.ts +102 -0
  343. package/v3/standard-schema.js +1 -0
  344. package/v3/types.cjs +3777 -0
  345. package/v3/types.d.cts +1034 -0
  346. package/v3/types.d.ts +1034 -0
  347. package/v3/types.js +3695 -0
  348. package/v4/classic/checks.cjs +33 -0
  349. package/v4/classic/checks.d.cts +1 -0
  350. package/v4/classic/checks.d.ts +1 -0
  351. package/v4/classic/checks.js +1 -0
  352. package/v4/classic/coerce.cjs +47 -0
  353. package/v4/classic/coerce.d.cts +17 -0
  354. package/v4/classic/coerce.d.ts +17 -0
  355. package/v4/classic/coerce.js +17 -0
  356. package/v4/classic/compat.cjs +61 -0
  357. package/v4/classic/compat.d.cts +50 -0
  358. package/v4/classic/compat.d.ts +50 -0
  359. package/v4/classic/compat.js +31 -0
  360. package/v4/classic/errors.cjs +74 -0
  361. package/v4/classic/errors.d.cts +30 -0
  362. package/v4/classic/errors.d.ts +30 -0
  363. package/v4/classic/errors.js +48 -0
  364. package/v4/classic/external.cjs +73 -0
  365. package/v4/classic/external.d.cts +15 -0
  366. package/v4/classic/external.d.ts +15 -0
  367. package/v4/classic/external.js +20 -0
  368. package/v4/classic/from-json-schema.cjs +610 -0
  369. package/v4/classic/from-json-schema.d.cts +12 -0
  370. package/v4/classic/from-json-schema.d.ts +12 -0
  371. package/v4/classic/from-json-schema.js +584 -0
  372. package/v4/classic/index.cjs +33 -0
  373. package/v4/classic/index.d.cts +4 -0
  374. package/v4/classic/index.d.ts +4 -0
  375. package/v4/classic/index.js +4 -0
  376. package/v4/classic/iso.cjs +60 -0
  377. package/v4/classic/iso.d.cts +22 -0
  378. package/v4/classic/iso.d.ts +22 -0
  379. package/v4/classic/iso.js +30 -0
  380. package/v4/classic/package.json +7 -0
  381. package/v4/classic/parse.cjs +41 -0
  382. package/v4/classic/parse.d.cts +31 -0
  383. package/v4/classic/parse.d.ts +31 -0
  384. package/v4/classic/parse.js +15 -0
  385. package/v4/classic/schemas.cjs +1272 -0
  386. package/v4/classic/schemas.d.cts +739 -0
  387. package/v4/classic/schemas.d.ts +739 -0
  388. package/v4/classic/schemas.js +1157 -0
  389. package/v4/core/api.cjs +1222 -0
  390. package/v4/core/api.d.cts +304 -0
  391. package/v4/core/api.d.ts +304 -0
  392. package/v4/core/api.js +1082 -0
  393. package/v4/core/checks.cjs +601 -0
  394. package/v4/core/checks.d.cts +278 -0
  395. package/v4/core/checks.d.ts +278 -0
  396. package/v4/core/checks.js +575 -0
  397. package/v4/core/core.cjs +83 -0
  398. package/v4/core/core.d.cts +70 -0
  399. package/v4/core/core.d.ts +70 -0
  400. package/v4/core/core.js +76 -0
  401. package/v4/core/doc.cjs +39 -0
  402. package/v4/core/doc.d.cts +14 -0
  403. package/v4/core/doc.d.ts +14 -0
  404. package/v4/core/doc.js +35 -0
  405. package/v4/core/errors.cjs +213 -0
  406. package/v4/core/errors.d.cts +220 -0
  407. package/v4/core/errors.d.ts +220 -0
  408. package/v4/core/errors.js +182 -0
  409. package/v4/core/index.cjs +47 -0
  410. package/v4/core/index.d.cts +16 -0
  411. package/v4/core/index.d.ts +16 -0
  412. package/v4/core/index.js +16 -0
  413. package/v4/core/json-schema-generator.cjs +99 -0
  414. package/v4/core/json-schema-generator.d.cts +65 -0
  415. package/v4/core/json-schema-generator.d.ts +65 -0
  416. package/v4/core/json-schema-generator.js +95 -0
  417. package/v4/core/json-schema-processors.cjs +648 -0
  418. package/v4/core/json-schema-processors.d.cts +49 -0
  419. package/v4/core/json-schema-processors.d.ts +49 -0
  420. package/v4/core/json-schema-processors.js +605 -0
  421. package/v4/core/json-schema.cjs +2 -0
  422. package/v4/core/json-schema.d.cts +88 -0
  423. package/v4/core/json-schema.d.ts +88 -0
  424. package/v4/core/json-schema.js +1 -0
  425. package/v4/core/package.json +7 -0
  426. package/v4/core/parse.cjs +131 -0
  427. package/v4/core/parse.d.cts +49 -0
  428. package/v4/core/parse.d.ts +49 -0
  429. package/v4/core/parse.js +93 -0
  430. package/v4/core/regexes.cjs +167 -0
  431. package/v4/core/regexes.d.cts +80 -0
  432. package/v4/core/regexes.d.ts +80 -0
  433. package/v4/core/regexes.js +134 -0
  434. package/v4/core/registries.cjs +56 -0
  435. package/v4/core/registries.d.cts +35 -0
  436. package/v4/core/registries.d.ts +35 -0
  437. package/v4/core/registries.js +51 -0
  438. package/v4/core/schemas.cjs +2147 -0
  439. package/v4/core/schemas.d.cts +1147 -0
  440. package/v4/core/schemas.d.ts +1147 -0
  441. package/v4/core/schemas.js +2115 -0
  442. package/v4/core/standard-schema.cjs +2 -0
  443. package/v4/core/standard-schema.d.cts +126 -0
  444. package/v4/core/standard-schema.d.ts +126 -0
  445. package/v4/core/standard-schema.js +1 -0
  446. package/v4/core/to-json-schema.cjs +446 -0
  447. package/v4/core/to-json-schema.d.cts +114 -0
  448. package/v4/core/to-json-schema.d.ts +114 -0
  449. package/v4/core/to-json-schema.js +437 -0
  450. package/v4/core/util.cjs +729 -0
  451. package/v4/core/util.d.cts +201 -0
  452. package/v4/core/util.d.ts +201 -0
  453. package/v4/core/util.js +668 -0
  454. package/v4/core/versions.cjs +8 -0
  455. package/v4/core/versions.d.cts +5 -0
  456. package/v4/core/versions.d.ts +5 -0
  457. package/v4/core/versions.js +5 -0
  458. package/v4/index.cjs +22 -0
  459. package/v4/index.d.cts +3 -0
  460. package/v4/index.d.ts +3 -0
  461. package/v4/index.js +3 -0
  462. package/v4/locales/ar.cjs +133 -0
  463. package/v4/locales/ar.d.cts +5 -0
  464. package/v4/locales/ar.d.ts +4 -0
  465. package/v4/locales/ar.js +106 -0
  466. package/v4/locales/az.cjs +132 -0
  467. package/v4/locales/az.d.cts +5 -0
  468. package/v4/locales/az.d.ts +4 -0
  469. package/v4/locales/az.js +105 -0
  470. package/v4/locales/be.cjs +183 -0
  471. package/v4/locales/be.d.cts +5 -0
  472. package/v4/locales/be.d.ts +4 -0
  473. package/v4/locales/be.js +156 -0
  474. package/v4/locales/bg.cjs +147 -0
  475. package/v4/locales/bg.d.cts +5 -0
  476. package/v4/locales/bg.d.ts +4 -0
  477. package/v4/locales/bg.js +120 -0
  478. package/v4/locales/ca.cjs +134 -0
  479. package/v4/locales/ca.d.cts +5 -0
  480. package/v4/locales/ca.d.ts +4 -0
  481. package/v4/locales/ca.js +107 -0
  482. package/v4/locales/cs.cjs +138 -0
  483. package/v4/locales/cs.d.cts +5 -0
  484. package/v4/locales/cs.d.ts +4 -0
  485. package/v4/locales/cs.js +111 -0
  486. package/v4/locales/da.cjs +142 -0
  487. package/v4/locales/da.d.cts +5 -0
  488. package/v4/locales/da.d.ts +4 -0
  489. package/v4/locales/da.js +115 -0
  490. package/v4/locales/de.cjs +135 -0
  491. package/v4/locales/de.d.cts +5 -0
  492. package/v4/locales/de.d.ts +4 -0
  493. package/v4/locales/de.js +108 -0
  494. package/v4/locales/en.cjs +136 -0
  495. package/v4/locales/en.d.cts +5 -0
  496. package/v4/locales/en.d.ts +4 -0
  497. package/v4/locales/en.js +109 -0
  498. package/v4/locales/eo.cjs +136 -0
  499. package/v4/locales/eo.d.cts +5 -0
  500. package/v4/locales/eo.d.ts +4 -0
  501. package/v4/locales/eo.js +109 -0
  502. package/v4/locales/es.cjs +159 -0
  503. package/v4/locales/es.d.cts +5 -0
  504. package/v4/locales/es.d.ts +4 -0
  505. package/v4/locales/es.js +132 -0
  506. package/v4/locales/fa.cjs +141 -0
  507. package/v4/locales/fa.d.cts +5 -0
  508. package/v4/locales/fa.d.ts +4 -0
  509. package/v4/locales/fa.js +114 -0
  510. package/v4/locales/fi.cjs +139 -0
  511. package/v4/locales/fi.d.cts +5 -0
  512. package/v4/locales/fi.d.ts +4 -0
  513. package/v4/locales/fi.js +112 -0
  514. package/v4/locales/fr-CA.cjs +134 -0
  515. package/v4/locales/fr-CA.d.cts +5 -0
  516. package/v4/locales/fr-CA.d.ts +4 -0
  517. package/v4/locales/fr-CA.js +107 -0
  518. package/v4/locales/fr.cjs +135 -0
  519. package/v4/locales/fr.d.cts +5 -0
  520. package/v4/locales/fr.d.ts +4 -0
  521. package/v4/locales/fr.js +108 -0
  522. package/v4/locales/he.cjs +241 -0
  523. package/v4/locales/he.d.cts +5 -0
  524. package/v4/locales/he.d.ts +4 -0
  525. package/v4/locales/he.js +214 -0
  526. package/v4/locales/hr.cjs +149 -0
  527. package/v4/locales/hr.d.cts +5 -0
  528. package/v4/locales/hr.d.ts +4 -0
  529. package/v4/locales/hr.js +122 -0
  530. package/v4/locales/hu.cjs +135 -0
  531. package/v4/locales/hu.d.cts +5 -0
  532. package/v4/locales/hu.d.ts +4 -0
  533. package/v4/locales/hu.js +108 -0
  534. package/v4/locales/hy.cjs +174 -0
  535. package/v4/locales/hy.d.cts +5 -0
  536. package/v4/locales/hy.d.ts +4 -0
  537. package/v4/locales/hy.js +147 -0
  538. package/v4/locales/id.cjs +133 -0
  539. package/v4/locales/id.d.cts +5 -0
  540. package/v4/locales/id.d.ts +4 -0
  541. package/v4/locales/id.js +106 -0
  542. package/v4/locales/index.cjs +106 -0
  543. package/v4/locales/index.d.cts +50 -0
  544. package/v4/locales/index.d.ts +50 -0
  545. package/v4/locales/index.js +50 -0
  546. package/v4/locales/is.cjs +136 -0
  547. package/v4/locales/is.d.cts +5 -0
  548. package/v4/locales/is.d.ts +4 -0
  549. package/v4/locales/is.js +109 -0
  550. package/v4/locales/it.cjs +135 -0
  551. package/v4/locales/it.d.cts +5 -0
  552. package/v4/locales/it.d.ts +4 -0
  553. package/v4/locales/it.js +108 -0
  554. package/v4/locales/ja.cjs +134 -0
  555. package/v4/locales/ja.d.cts +5 -0
  556. package/v4/locales/ja.d.ts +4 -0
  557. package/v4/locales/ja.js +107 -0
  558. package/v4/locales/ka.cjs +139 -0
  559. package/v4/locales/ka.d.cts +5 -0
  560. package/v4/locales/ka.d.ts +4 -0
  561. package/v4/locales/ka.js +112 -0
  562. package/v4/locales/kh.cjs +12 -0
  563. package/v4/locales/kh.d.cts +5 -0
  564. package/v4/locales/kh.d.ts +5 -0
  565. package/v4/locales/kh.js +5 -0
  566. package/v4/locales/km.cjs +137 -0
  567. package/v4/locales/km.d.cts +5 -0
  568. package/v4/locales/km.d.ts +4 -0
  569. package/v4/locales/km.js +110 -0
  570. package/v4/locales/ko.cjs +138 -0
  571. package/v4/locales/ko.d.cts +5 -0
  572. package/v4/locales/ko.d.ts +4 -0
  573. package/v4/locales/ko.js +111 -0
  574. package/v4/locales/lt.cjs +230 -0
  575. package/v4/locales/lt.d.cts +5 -0
  576. package/v4/locales/lt.d.ts +4 -0
  577. package/v4/locales/lt.js +203 -0
  578. package/v4/locales/mk.cjs +136 -0
  579. package/v4/locales/mk.d.cts +5 -0
  580. package/v4/locales/mk.d.ts +4 -0
  581. package/v4/locales/mk.js +109 -0
  582. package/v4/locales/ms.cjs +134 -0
  583. package/v4/locales/ms.d.cts +5 -0
  584. package/v4/locales/ms.d.ts +4 -0
  585. package/v4/locales/ms.js +107 -0
  586. package/v4/locales/nl.cjs +137 -0
  587. package/v4/locales/nl.d.cts +5 -0
  588. package/v4/locales/nl.d.ts +4 -0
  589. package/v4/locales/nl.js +110 -0
  590. package/v4/locales/no.cjs +135 -0
  591. package/v4/locales/no.d.cts +5 -0
  592. package/v4/locales/no.d.ts +4 -0
  593. package/v4/locales/no.js +108 -0
  594. package/v4/locales/ota.cjs +136 -0
  595. package/v4/locales/ota.d.cts +5 -0
  596. package/v4/locales/ota.d.ts +4 -0
  597. package/v4/locales/ota.js +109 -0
  598. package/v4/locales/package.json +7 -0
  599. package/v4/locales/pl.cjs +136 -0
  600. package/v4/locales/pl.d.cts +5 -0
  601. package/v4/locales/pl.d.ts +4 -0
  602. package/v4/locales/pl.js +109 -0
  603. package/v4/locales/ps.cjs +141 -0
  604. package/v4/locales/ps.d.cts +5 -0
  605. package/v4/locales/ps.d.ts +4 -0
  606. package/v4/locales/ps.js +114 -0
  607. package/v4/locales/pt.cjs +135 -0
  608. package/v4/locales/pt.d.cts +5 -0
  609. package/v4/locales/pt.d.ts +4 -0
  610. package/v4/locales/pt.js +108 -0
  611. package/v4/locales/ru.cjs +183 -0
  612. package/v4/locales/ru.d.cts +5 -0
  613. package/v4/locales/ru.d.ts +4 -0
  614. package/v4/locales/ru.js +156 -0
  615. package/v4/locales/sl.cjs +136 -0
  616. package/v4/locales/sl.d.cts +5 -0
  617. package/v4/locales/sl.d.ts +4 -0
  618. package/v4/locales/sl.js +109 -0
  619. package/v4/locales/sv.cjs +137 -0
  620. package/v4/locales/sv.d.cts +5 -0
  621. package/v4/locales/sv.d.ts +4 -0
  622. package/v4/locales/sv.js +110 -0
  623. package/v4/locales/ta.cjs +137 -0
  624. package/v4/locales/ta.d.cts +5 -0
  625. package/v4/locales/ta.d.ts +4 -0
  626. package/v4/locales/ta.js +110 -0
  627. package/v4/locales/th.cjs +137 -0
  628. package/v4/locales/th.d.cts +5 -0
  629. package/v4/locales/th.d.ts +4 -0
  630. package/v4/locales/th.js +110 -0
  631. package/v4/locales/tr.cjs +132 -0
  632. package/v4/locales/tr.d.cts +5 -0
  633. package/v4/locales/tr.d.ts +4 -0
  634. package/v4/locales/tr.js +105 -0
  635. package/v4/locales/ua.cjs +12 -0
  636. package/v4/locales/ua.d.cts +5 -0
  637. package/v4/locales/ua.d.ts +5 -0
  638. package/v4/locales/ua.js +5 -0
  639. package/v4/locales/uk.cjs +135 -0
  640. package/v4/locales/uk.d.cts +5 -0
  641. package/v4/locales/uk.d.ts +4 -0
  642. package/v4/locales/uk.js +108 -0
  643. package/v4/locales/ur.cjs +137 -0
  644. package/v4/locales/ur.d.cts +5 -0
  645. package/v4/locales/ur.d.ts +4 -0
  646. package/v4/locales/ur.js +110 -0
  647. package/v4/locales/uz.cjs +137 -0
  648. package/v4/locales/uz.d.cts +5 -0
  649. package/v4/locales/uz.d.ts +4 -0
  650. package/v4/locales/uz.js +110 -0
  651. package/v4/locales/vi.cjs +135 -0
  652. package/v4/locales/vi.d.cts +5 -0
  653. package/v4/locales/vi.d.ts +4 -0
  654. package/v4/locales/vi.js +108 -0
  655. package/v4/locales/yo.cjs +134 -0
  656. package/v4/locales/yo.d.cts +5 -0
  657. package/v4/locales/yo.d.ts +4 -0
  658. package/v4/locales/yo.js +107 -0
  659. package/v4/locales/zh-CN.cjs +136 -0
  660. package/v4/locales/zh-CN.d.cts +5 -0
  661. package/v4/locales/zh-CN.d.ts +4 -0
  662. package/v4/locales/zh-CN.js +109 -0
  663. package/v4/locales/zh-TW.cjs +134 -0
  664. package/v4/locales/zh-TW.d.cts +5 -0
  665. package/v4/locales/zh-TW.d.ts +4 -0
  666. package/v4/locales/zh-TW.js +107 -0
  667. package/v4/mini/checks.cjs +34 -0
  668. package/v4/mini/checks.d.cts +1 -0
  669. package/v4/mini/checks.d.ts +1 -0
  670. package/v4/mini/checks.js +1 -0
  671. package/v4/mini/coerce.cjs +52 -0
  672. package/v4/mini/coerce.d.cts +7 -0
  673. package/v4/mini/coerce.d.ts +7 -0
  674. package/v4/mini/coerce.js +22 -0
  675. package/v4/mini/external.cjs +63 -0
  676. package/v4/mini/external.d.cts +12 -0
  677. package/v4/mini/external.d.ts +12 -0
  678. package/v4/mini/external.js +14 -0
  679. package/v4/mini/index.cjs +32 -0
  680. package/v4/mini/index.d.cts +3 -0
  681. package/v4/mini/index.d.ts +3 -0
  682. package/v4/mini/index.js +3 -0
  683. package/v4/mini/iso.cjs +64 -0
  684. package/v4/mini/iso.d.cts +22 -0
  685. package/v4/mini/iso.d.ts +22 -0
  686. package/v4/mini/iso.js +34 -0
  687. package/v4/mini/package.json +7 -0
  688. package/v4/mini/parse.cjs +16 -0
  689. package/v4/mini/parse.d.cts +1 -0
  690. package/v4/mini/parse.d.ts +1 -0
  691. package/v4/mini/parse.js +1 -0
  692. package/v4/mini/schemas.cjs +1046 -0
  693. package/v4/mini/schemas.d.cts +427 -0
  694. package/v4/mini/schemas.d.ts +427 -0
  695. package/v4/mini/schemas.js +925 -0
  696. package/v4/package.json +7 -0
  697. package/v4-mini/index.cjs +32 -0
  698. package/v4-mini/index.d.cts +3 -0
  699. package/v4-mini/index.d.ts +3 -0
  700. package/v4-mini/index.js +3 -0
  701. package/v4-mini/package.json +7 -0
@@ -0,0 +1,2147 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = exports.$ZodXor = exports.$ZodUnion = exports.$ZodObjectJIT = exports.$ZodObject = exports.$ZodArray = exports.$ZodDate = exports.$ZodVoid = exports.$ZodNever = exports.$ZodUnknown = exports.$ZodAny = exports.$ZodNull = exports.$ZodUndefined = exports.$ZodSymbol = exports.$ZodBigIntFormat = exports.$ZodBigInt = exports.$ZodBoolean = exports.$ZodNumberFormat = exports.$ZodNumber = exports.$ZodCustomStringFormat = exports.$ZodJWT = exports.$ZodE164 = exports.$ZodBase64URL = exports.$ZodBase64 = exports.$ZodCIDRv6 = exports.$ZodCIDRv4 = exports.$ZodMAC = exports.$ZodIPv6 = exports.$ZodIPv4 = exports.$ZodISODuration = exports.$ZodISOTime = exports.$ZodISODate = exports.$ZodISODateTime = exports.$ZodKSUID = exports.$ZodXID = exports.$ZodULID = exports.$ZodCUID2 = exports.$ZodCUID = exports.$ZodNanoID = exports.$ZodEmoji = exports.$ZodURL = exports.$ZodEmail = exports.$ZodUUID = exports.$ZodGUID = exports.$ZodStringFormat = exports.$ZodString = exports.clone = exports.$ZodType = void 0;
27
+ exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodFunction = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodCodec = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodExactOptional = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = exports.$ZodSet = exports.$ZodMap = exports.$ZodRecord = void 0;
28
+ exports.setParseAdapter = setParseAdapter;
29
+ exports.isValidBase64 = isValidBase64;
30
+ exports.isValidBase64URL = isValidBase64URL;
31
+ exports.isValidJWT = isValidJWT;
32
+ const checks = __importStar(require("./checks.cjs"));
33
+ const core = __importStar(require("./core.cjs"));
34
+ const doc_js_1 = require("./doc.cjs");
35
+ const parse_js_1 = require("./parse.cjs");
36
+ const regexes = __importStar(require("./regexes.cjs"));
37
+ const util = __importStar(require("./util.cjs"));
38
+ const versions_js_1 = require("./versions.cjs");
39
+ let __parseAdapterFn;
40
+ function setParseAdapter(parseAdapterFn) {
41
+ __parseAdapterFn = parseAdapterFn;
42
+ }
43
+ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
44
+ var _a;
45
+ inst ?? (inst = {});
46
+ inst._zod.def = def; // set _def property
47
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
48
+ inst._zod.version = versions_js_1.version;
49
+ const checks = [...(inst._zod.def.checks ?? [])];
50
+ // if inst is itself a checks.$ZodCheck, run it as a check
51
+ if (inst._zod.traits.has("$ZodCheck")) {
52
+ checks.unshift(inst);
53
+ }
54
+ for (const ch of checks) {
55
+ for (const fn of ch._zod.onattach) {
56
+ fn(inst);
57
+ }
58
+ }
59
+ if (checks.length === 0) {
60
+ // deferred initializer
61
+ // inst._zod.parse is not yet defined
62
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
63
+ inst._zod.deferred?.push(() => {
64
+ inst._zod.run = __parseAdapterFn ? __parseAdapterFn(inst, inst._zod.parse) : inst._zod.parse;
65
+ });
66
+ }
67
+ else {
68
+ const runChecks = (payload, checks, ctx) => {
69
+ let isAborted = util.aborted(payload);
70
+ let asyncResult;
71
+ for (const ch of checks) {
72
+ if (ch._zod.def.when) {
73
+ if (util.explicitlyAborted(payload))
74
+ continue;
75
+ const shouldRun = ch._zod.def.when(payload);
76
+ if (!shouldRun)
77
+ continue;
78
+ }
79
+ else if (isAborted) {
80
+ continue;
81
+ }
82
+ const currLen = payload.issues.length;
83
+ const _ = ch._zod.check(payload);
84
+ if (_ instanceof Promise && ctx?.async === false) {
85
+ throw new core.$ZodAsyncError();
86
+ }
87
+ if (asyncResult || _ instanceof Promise) {
88
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
89
+ await _;
90
+ const nextLen = payload.issues.length;
91
+ if (nextLen === currLen)
92
+ return;
93
+ if (!isAborted)
94
+ isAborted = util.aborted(payload, currLen);
95
+ });
96
+ }
97
+ else {
98
+ const nextLen = payload.issues.length;
99
+ if (nextLen === currLen)
100
+ continue;
101
+ if (!isAborted)
102
+ isAborted = util.aborted(payload, currLen);
103
+ }
104
+ }
105
+ if (asyncResult) {
106
+ return asyncResult.then(() => {
107
+ return payload;
108
+ });
109
+ }
110
+ return payload;
111
+ };
112
+ const handleCanaryResult = (canary, payload, ctx) => {
113
+ // abort if the canary is aborted
114
+ if (util.aborted(canary)) {
115
+ canary.aborted = true;
116
+ return canary;
117
+ }
118
+ // run checks first, then
119
+ const checkResult = runChecks(payload, checks, ctx);
120
+ if (checkResult instanceof Promise) {
121
+ if (ctx.async === false)
122
+ throw new core.$ZodAsyncError();
123
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
124
+ }
125
+ return inst._zod.parse(checkResult, ctx);
126
+ };
127
+ const __run = (payload, ctx) => {
128
+ if (ctx.skipChecks) {
129
+ return inst._zod.parse(payload, ctx);
130
+ }
131
+ if (ctx.direction === "backward") {
132
+ // run canary
133
+ // initial pass (no checks)
134
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
135
+ if (canary instanceof Promise) {
136
+ return canary.then((canary) => {
137
+ return handleCanaryResult(canary, payload, ctx);
138
+ });
139
+ }
140
+ return handleCanaryResult(canary, payload, ctx);
141
+ }
142
+ // forward
143
+ const result = inst._zod.parse(payload, ctx);
144
+ if (result instanceof Promise) {
145
+ if (ctx.async === false)
146
+ throw new core.$ZodAsyncError();
147
+ return result.then((result) => runChecks(result, checks, ctx));
148
+ }
149
+ return runChecks(result, checks, ctx);
150
+ };
151
+ inst._zod.run = __parseAdapterFn ? __parseAdapterFn(inst, __run) : __run;
152
+ }
153
+ // Lazy initialize ~standard to avoid creating objects for every schema
154
+ util.defineLazy(inst, "~standard", () => ({
155
+ validate: (value) => {
156
+ try {
157
+ const r = (0, parse_js_1.safeParse)(inst, value);
158
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
159
+ }
160
+ catch (_) {
161
+ return (0, parse_js_1.safeParseAsync)(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
162
+ }
163
+ },
164
+ vendor: "zod",
165
+ version: 1,
166
+ }));
167
+ });
168
+ var util_js_1 = require("./util.cjs");
169
+ Object.defineProperty(exports, "clone", { enumerable: true, get: function () { return util_js_1.clone; } });
170
+ exports.$ZodString = core.$constructor("$ZodString", (inst, def) => {
171
+ exports.$ZodType.init(inst, def);
172
+ inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? regexes.string(inst._zod.bag);
173
+ inst._zod.parse = (payload, _) => {
174
+ if (def.coerce)
175
+ try {
176
+ payload.value = String(payload.value);
177
+ }
178
+ catch (_) { }
179
+ if (typeof payload.value === "string")
180
+ return payload;
181
+ payload.issues.push({
182
+ expected: "string",
183
+ code: "invalid_type",
184
+ input: payload.value,
185
+ inst,
186
+ });
187
+ return payload;
188
+ };
189
+ });
190
+ exports.$ZodStringFormat = core.$constructor("$ZodStringFormat", (inst, def) => {
191
+ // check initialization must come first
192
+ checks.$ZodCheckStringFormat.init(inst, def);
193
+ exports.$ZodString.init(inst, def);
194
+ });
195
+ exports.$ZodGUID = core.$constructor("$ZodGUID", (inst, def) => {
196
+ def.pattern ?? (def.pattern = regexes.guid);
197
+ exports.$ZodStringFormat.init(inst, def);
198
+ });
199
+ exports.$ZodUUID = core.$constructor("$ZodUUID", (inst, def) => {
200
+ if (def.version) {
201
+ const versionMap = {
202
+ v1: 1,
203
+ v2: 2,
204
+ v3: 3,
205
+ v4: 4,
206
+ v5: 5,
207
+ v6: 6,
208
+ v7: 7,
209
+ v8: 8,
210
+ };
211
+ const v = versionMap[def.version];
212
+ if (v === undefined)
213
+ throw new Error(`Invalid UUID version: "${def.version}"`);
214
+ def.pattern ?? (def.pattern = regexes.uuid(v));
215
+ }
216
+ else
217
+ def.pattern ?? (def.pattern = regexes.uuid());
218
+ exports.$ZodStringFormat.init(inst, def);
219
+ });
220
+ exports.$ZodEmail = core.$constructor("$ZodEmail", (inst, def) => {
221
+ def.pattern ?? (def.pattern = regexes.email);
222
+ exports.$ZodStringFormat.init(inst, def);
223
+ });
224
+ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
225
+ exports.$ZodStringFormat.init(inst, def);
226
+ inst._zod.check = (payload) => {
227
+ try {
228
+ // Trim whitespace from input
229
+ const trimmed = payload.value.trim();
230
+ // When normalize is off, require :// for http/https URLs
231
+ // This prevents strings like "http:example.com" or "https:/path" from being silently accepted
232
+ if (!def.normalize && def.protocol?.source === regexes.httpProtocol.source) {
233
+ if (!/^https?:\/\//i.test(trimmed)) {
234
+ payload.issues.push({
235
+ code: "invalid_format",
236
+ format: "url",
237
+ note: "Invalid URL format",
238
+ input: payload.value,
239
+ inst,
240
+ continue: !def.abort,
241
+ });
242
+ return;
243
+ }
244
+ }
245
+ // @ts-ignore
246
+ const url = new URL(trimmed);
247
+ if (def.hostname) {
248
+ def.hostname.lastIndex = 0;
249
+ if (!def.hostname.test(url.hostname)) {
250
+ payload.issues.push({
251
+ code: "invalid_format",
252
+ format: "url",
253
+ note: "Invalid hostname",
254
+ pattern: def.hostname.source,
255
+ input: payload.value,
256
+ inst,
257
+ continue: !def.abort,
258
+ });
259
+ }
260
+ }
261
+ if (def.protocol) {
262
+ def.protocol.lastIndex = 0;
263
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
264
+ payload.issues.push({
265
+ code: "invalid_format",
266
+ format: "url",
267
+ note: "Invalid protocol",
268
+ pattern: def.protocol.source,
269
+ input: payload.value,
270
+ inst,
271
+ continue: !def.abort,
272
+ });
273
+ }
274
+ }
275
+ // Set the output value based on normalize flag
276
+ if (def.normalize) {
277
+ // Use normalized URL
278
+ payload.value = url.href;
279
+ }
280
+ else {
281
+ // Preserve the original input (trimmed)
282
+ payload.value = trimmed;
283
+ }
284
+ return;
285
+ }
286
+ catch (_) {
287
+ payload.issues.push({
288
+ code: "invalid_format",
289
+ format: "url",
290
+ input: payload.value,
291
+ inst,
292
+ continue: !def.abort,
293
+ });
294
+ }
295
+ };
296
+ });
297
+ exports.$ZodEmoji = core.$constructor("$ZodEmoji", (inst, def) => {
298
+ def.pattern ?? (def.pattern = regexes.emoji());
299
+ exports.$ZodStringFormat.init(inst, def);
300
+ });
301
+ exports.$ZodNanoID = core.$constructor("$ZodNanoID", (inst, def) => {
302
+ def.pattern ?? (def.pattern = regexes.nanoid);
303
+ exports.$ZodStringFormat.init(inst, def);
304
+ });
305
+ exports.$ZodCUID = core.$constructor("$ZodCUID", (inst, def) => {
306
+ def.pattern ?? (def.pattern = regexes.cuid);
307
+ exports.$ZodStringFormat.init(inst, def);
308
+ });
309
+ exports.$ZodCUID2 = core.$constructor("$ZodCUID2", (inst, def) => {
310
+ def.pattern ?? (def.pattern = regexes.cuid2);
311
+ exports.$ZodStringFormat.init(inst, def);
312
+ });
313
+ exports.$ZodULID = core.$constructor("$ZodULID", (inst, def) => {
314
+ def.pattern ?? (def.pattern = regexes.ulid);
315
+ exports.$ZodStringFormat.init(inst, def);
316
+ });
317
+ exports.$ZodXID = core.$constructor("$ZodXID", (inst, def) => {
318
+ def.pattern ?? (def.pattern = regexes.xid);
319
+ exports.$ZodStringFormat.init(inst, def);
320
+ });
321
+ exports.$ZodKSUID = core.$constructor("$ZodKSUID", (inst, def) => {
322
+ def.pattern ?? (def.pattern = regexes.ksuid);
323
+ exports.$ZodStringFormat.init(inst, def);
324
+ });
325
+ exports.$ZodISODateTime = core.$constructor("$ZodISODateTime", (inst, def) => {
326
+ def.pattern ?? (def.pattern = regexes.datetime(def));
327
+ exports.$ZodStringFormat.init(inst, def);
328
+ });
329
+ exports.$ZodISODate = core.$constructor("$ZodISODate", (inst, def) => {
330
+ def.pattern ?? (def.pattern = regexes.date);
331
+ exports.$ZodStringFormat.init(inst, def);
332
+ });
333
+ exports.$ZodISOTime = core.$constructor("$ZodISOTime", (inst, def) => {
334
+ def.pattern ?? (def.pattern = regexes.time(def));
335
+ exports.$ZodStringFormat.init(inst, def);
336
+ });
337
+ exports.$ZodISODuration = core.$constructor("$ZodISODuration", (inst, def) => {
338
+ def.pattern ?? (def.pattern = regexes.duration);
339
+ exports.$ZodStringFormat.init(inst, def);
340
+ });
341
+ exports.$ZodIPv4 = core.$constructor("$ZodIPv4", (inst, def) => {
342
+ def.pattern ?? (def.pattern = regexes.ipv4);
343
+ exports.$ZodStringFormat.init(inst, def);
344
+ inst._zod.bag.format = `ipv4`;
345
+ });
346
+ exports.$ZodIPv6 = core.$constructor("$ZodIPv6", (inst, def) => {
347
+ def.pattern ?? (def.pattern = regexes.ipv6);
348
+ exports.$ZodStringFormat.init(inst, def);
349
+ inst._zod.bag.format = `ipv6`;
350
+ inst._zod.check = (payload) => {
351
+ try {
352
+ // @ts-ignore
353
+ new URL(`http://[${payload.value}]`);
354
+ // return;
355
+ }
356
+ catch {
357
+ payload.issues.push({
358
+ code: "invalid_format",
359
+ format: "ipv6",
360
+ input: payload.value,
361
+ inst,
362
+ continue: !def.abort,
363
+ });
364
+ }
365
+ };
366
+ });
367
+ exports.$ZodMAC = core.$constructor("$ZodMAC", (inst, def) => {
368
+ def.pattern ?? (def.pattern = regexes.mac(def.delimiter));
369
+ exports.$ZodStringFormat.init(inst, def);
370
+ inst._zod.bag.format = `mac`;
371
+ });
372
+ exports.$ZodCIDRv4 = core.$constructor("$ZodCIDRv4", (inst, def) => {
373
+ def.pattern ?? (def.pattern = regexes.cidrv4);
374
+ exports.$ZodStringFormat.init(inst, def);
375
+ });
376
+ exports.$ZodCIDRv6 = core.$constructor("$ZodCIDRv6", (inst, def) => {
377
+ def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
378
+ exports.$ZodStringFormat.init(inst, def);
379
+ inst._zod.check = (payload) => {
380
+ const parts = payload.value.split("/");
381
+ try {
382
+ if (parts.length !== 2)
383
+ throw new Error();
384
+ const [address, prefix] = parts;
385
+ if (!prefix)
386
+ throw new Error();
387
+ const prefixNum = Number(prefix);
388
+ if (`${prefixNum}` !== prefix)
389
+ throw new Error();
390
+ if (prefixNum < 0 || prefixNum > 128)
391
+ throw new Error();
392
+ // @ts-ignore
393
+ new URL(`http://[${address}]`);
394
+ }
395
+ catch {
396
+ payload.issues.push({
397
+ code: "invalid_format",
398
+ format: "cidrv6",
399
+ input: payload.value,
400
+ inst,
401
+ continue: !def.abort,
402
+ });
403
+ }
404
+ };
405
+ });
406
+ ////////////////////////////// ZodBase64 //////////////////////////////
407
+ function isValidBase64(data) {
408
+ if (data === "")
409
+ return true;
410
+ if (data.length % 4 !== 0)
411
+ return false;
412
+ try {
413
+ // @ts-ignore
414
+ atob(data);
415
+ return true;
416
+ }
417
+ catch {
418
+ return false;
419
+ }
420
+ }
421
+ exports.$ZodBase64 = core.$constructor("$ZodBase64", (inst, def) => {
422
+ def.pattern ?? (def.pattern = regexes.base64);
423
+ exports.$ZodStringFormat.init(inst, def);
424
+ inst._zod.bag.contentEncoding = "base64";
425
+ inst._zod.check = (payload) => {
426
+ if (isValidBase64(payload.value))
427
+ return;
428
+ payload.issues.push({
429
+ code: "invalid_format",
430
+ format: "base64",
431
+ input: payload.value,
432
+ inst,
433
+ continue: !def.abort,
434
+ });
435
+ };
436
+ });
437
+ ////////////////////////////// ZodBase64 //////////////////////////////
438
+ function isValidBase64URL(data) {
439
+ if (!regexes.base64url.test(data))
440
+ return false;
441
+ const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
442
+ const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
443
+ return isValidBase64(padded);
444
+ }
445
+ exports.$ZodBase64URL = core.$constructor("$ZodBase64URL", (inst, def) => {
446
+ def.pattern ?? (def.pattern = regexes.base64url);
447
+ exports.$ZodStringFormat.init(inst, def);
448
+ inst._zod.bag.contentEncoding = "base64url";
449
+ inst._zod.check = (payload) => {
450
+ if (isValidBase64URL(payload.value))
451
+ return;
452
+ payload.issues.push({
453
+ code: "invalid_format",
454
+ format: "base64url",
455
+ input: payload.value,
456
+ inst,
457
+ continue: !def.abort,
458
+ });
459
+ };
460
+ });
461
+ exports.$ZodE164 = core.$constructor("$ZodE164", (inst, def) => {
462
+ def.pattern ?? (def.pattern = regexes.e164);
463
+ exports.$ZodStringFormat.init(inst, def);
464
+ });
465
+ ////////////////////////////// ZodJWT //////////////////////////////
466
+ function isValidJWT(token, algorithm = null) {
467
+ try {
468
+ const tokensParts = token.split(".");
469
+ if (tokensParts.length !== 3)
470
+ return false;
471
+ const [header] = tokensParts;
472
+ if (!header)
473
+ return false;
474
+ // @ts-ignore
475
+ const parsedHeader = JSON.parse(atob(header));
476
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
477
+ return false;
478
+ if (!parsedHeader.alg)
479
+ return false;
480
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
481
+ return false;
482
+ return true;
483
+ }
484
+ catch {
485
+ return false;
486
+ }
487
+ }
488
+ exports.$ZodJWT = core.$constructor("$ZodJWT", (inst, def) => {
489
+ exports.$ZodStringFormat.init(inst, def);
490
+ inst._zod.check = (payload) => {
491
+ if (isValidJWT(payload.value, def.alg))
492
+ return;
493
+ payload.issues.push({
494
+ code: "invalid_format",
495
+ format: "jwt",
496
+ input: payload.value,
497
+ inst,
498
+ continue: !def.abort,
499
+ });
500
+ };
501
+ });
502
+ exports.$ZodCustomStringFormat = core.$constructor("$ZodCustomStringFormat", (inst, def) => {
503
+ exports.$ZodStringFormat.init(inst, def);
504
+ inst._zod.check = (payload) => {
505
+ if (def.fn(payload.value))
506
+ return;
507
+ payload.issues.push({
508
+ code: "invalid_format",
509
+ format: def.format,
510
+ input: payload.value,
511
+ inst,
512
+ continue: !def.abort,
513
+ });
514
+ };
515
+ });
516
+ exports.$ZodNumber = core.$constructor("$ZodNumber", (inst, def) => {
517
+ exports.$ZodType.init(inst, def);
518
+ inst._zod.pattern = inst._zod.bag.pattern ?? regexes.number;
519
+ inst._zod.parse = (payload, _ctx) => {
520
+ if (def.coerce)
521
+ try {
522
+ payload.value = Number(payload.value);
523
+ }
524
+ catch (_) { }
525
+ const input = payload.value;
526
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) {
527
+ return payload;
528
+ }
529
+ const received = typeof input === "number"
530
+ ? Number.isNaN(input)
531
+ ? "NaN"
532
+ : !Number.isFinite(input)
533
+ ? "Infinity"
534
+ : undefined
535
+ : undefined;
536
+ payload.issues.push({
537
+ expected: "number",
538
+ code: "invalid_type",
539
+ input,
540
+ inst,
541
+ ...(received ? { received } : {}),
542
+ });
543
+ return payload;
544
+ };
545
+ });
546
+ exports.$ZodNumberFormat = core.$constructor("$ZodNumberFormat", (inst, def) => {
547
+ checks.$ZodCheckNumberFormat.init(inst, def);
548
+ exports.$ZodNumber.init(inst, def); // no format checks
549
+ });
550
+ exports.$ZodBoolean = core.$constructor("$ZodBoolean", (inst, def) => {
551
+ exports.$ZodType.init(inst, def);
552
+ inst._zod.pattern = regexes.boolean;
553
+ inst._zod.parse = (payload, _ctx) => {
554
+ if (def.coerce)
555
+ try {
556
+ payload.value = Boolean(payload.value);
557
+ }
558
+ catch (_) { }
559
+ const input = payload.value;
560
+ if (typeof input === "boolean")
561
+ return payload;
562
+ payload.issues.push({
563
+ expected: "boolean",
564
+ code: "invalid_type",
565
+ input,
566
+ inst,
567
+ });
568
+ return payload;
569
+ };
570
+ });
571
+ exports.$ZodBigInt = core.$constructor("$ZodBigInt", (inst, def) => {
572
+ exports.$ZodType.init(inst, def);
573
+ inst._zod.pattern = regexes.bigint;
574
+ inst._zod.parse = (payload, _ctx) => {
575
+ if (def.coerce)
576
+ try {
577
+ payload.value = BigInt(payload.value);
578
+ }
579
+ catch (_) { }
580
+ if (typeof payload.value === "bigint")
581
+ return payload;
582
+ payload.issues.push({
583
+ expected: "bigint",
584
+ code: "invalid_type",
585
+ input: payload.value,
586
+ inst,
587
+ });
588
+ return payload;
589
+ };
590
+ });
591
+ exports.$ZodBigIntFormat = core.$constructor("$ZodBigIntFormat", (inst, def) => {
592
+ checks.$ZodCheckBigIntFormat.init(inst, def);
593
+ exports.$ZodBigInt.init(inst, def); // no format checks
594
+ });
595
+ exports.$ZodSymbol = core.$constructor("$ZodSymbol", (inst, def) => {
596
+ exports.$ZodType.init(inst, def);
597
+ inst._zod.parse = (payload, _ctx) => {
598
+ const input = payload.value;
599
+ if (typeof input === "symbol")
600
+ return payload;
601
+ payload.issues.push({
602
+ expected: "symbol",
603
+ code: "invalid_type",
604
+ input,
605
+ inst,
606
+ });
607
+ return payload;
608
+ };
609
+ });
610
+ exports.$ZodUndefined = core.$constructor("$ZodUndefined", (inst, def) => {
611
+ exports.$ZodType.init(inst, def);
612
+ inst._zod.pattern = regexes.undefined;
613
+ inst._zod.values = new Set([undefined]);
614
+ inst._zod.optin = "optional";
615
+ inst._zod.optout = "optional";
616
+ inst._zod.parse = (payload, _ctx) => {
617
+ const input = payload.value;
618
+ if (typeof input === "undefined")
619
+ return payload;
620
+ payload.issues.push({
621
+ expected: "undefined",
622
+ code: "invalid_type",
623
+ input,
624
+ inst,
625
+ });
626
+ return payload;
627
+ };
628
+ });
629
+ exports.$ZodNull = core.$constructor("$ZodNull", (inst, def) => {
630
+ exports.$ZodType.init(inst, def);
631
+ inst._zod.pattern = regexes.null;
632
+ inst._zod.values = new Set([null]);
633
+ inst._zod.parse = (payload, _ctx) => {
634
+ const input = payload.value;
635
+ if (input === null)
636
+ return payload;
637
+ payload.issues.push({
638
+ expected: "null",
639
+ code: "invalid_type",
640
+ input,
641
+ inst,
642
+ });
643
+ return payload;
644
+ };
645
+ });
646
+ exports.$ZodAny = core.$constructor("$ZodAny", (inst, def) => {
647
+ exports.$ZodType.init(inst, def);
648
+ inst._zod.parse = (payload) => payload;
649
+ });
650
+ exports.$ZodUnknown = core.$constructor("$ZodUnknown", (inst, def) => {
651
+ exports.$ZodType.init(inst, def);
652
+ inst._zod.parse = (payload) => payload;
653
+ });
654
+ exports.$ZodNever = core.$constructor("$ZodNever", (inst, def) => {
655
+ exports.$ZodType.init(inst, def);
656
+ inst._zod.parse = (payload, _ctx) => {
657
+ payload.issues.push({
658
+ expected: "never",
659
+ code: "invalid_type",
660
+ input: payload.value,
661
+ inst,
662
+ });
663
+ return payload;
664
+ };
665
+ });
666
+ exports.$ZodVoid = core.$constructor("$ZodVoid", (inst, def) => {
667
+ exports.$ZodType.init(inst, def);
668
+ inst._zod.parse = (payload, _ctx) => {
669
+ const input = payload.value;
670
+ if (typeof input === "undefined")
671
+ return payload;
672
+ payload.issues.push({
673
+ expected: "void",
674
+ code: "invalid_type",
675
+ input,
676
+ inst,
677
+ });
678
+ return payload;
679
+ };
680
+ });
681
+ exports.$ZodDate = core.$constructor("$ZodDate", (inst, def) => {
682
+ exports.$ZodType.init(inst, def);
683
+ inst._zod.parse = (payload, _ctx) => {
684
+ if (def.coerce) {
685
+ try {
686
+ payload.value = new Date(payload.value);
687
+ }
688
+ catch (_err) { }
689
+ }
690
+ const input = payload.value;
691
+ const isDate = input instanceof Date;
692
+ const isValidDate = isDate && !Number.isNaN(input.getTime());
693
+ if (isValidDate)
694
+ return payload;
695
+ payload.issues.push({
696
+ expected: "date",
697
+ code: "invalid_type",
698
+ input,
699
+ ...(isDate ? { received: "Invalid Date" } : {}),
700
+ inst,
701
+ });
702
+ return payload;
703
+ };
704
+ });
705
+ function handleArrayResult(result, final, index) {
706
+ if (result.issues.length) {
707
+ final.issues.push(...util.prefixIssues(index, result.issues));
708
+ }
709
+ final.value[index] = result.value;
710
+ }
711
+ exports.$ZodArray = core.$constructor("$ZodArray", (inst, def) => {
712
+ exports.$ZodType.init(inst, def);
713
+ inst._zod.parse = (payload, ctx) => {
714
+ const input = payload.value;
715
+ if (!Array.isArray(input)) {
716
+ payload.issues.push({
717
+ expected: "array",
718
+ code: "invalid_type",
719
+ input,
720
+ inst,
721
+ });
722
+ return payload;
723
+ }
724
+ payload.value = Array(input.length);
725
+ const proms = [];
726
+ for (let i = 0; i < input.length; i++) {
727
+ const item = input[i];
728
+ const result = def.element._zod.run({
729
+ value: item,
730
+ issues: [],
731
+ }, ctx);
732
+ if (result instanceof Promise) {
733
+ proms.push(result.then((result) => handleArrayResult(result, payload, i)));
734
+ }
735
+ else {
736
+ handleArrayResult(result, payload, i);
737
+ }
738
+ }
739
+ if (proms.length) {
740
+ return Promise.all(proms).then(() => payload);
741
+ }
742
+ return payload; //handleArrayResultsAsync(parseResults, final);
743
+ };
744
+ });
745
+ function handlePropertyResult(result, final, key, input, isOptionalOut) {
746
+ if (result.issues.length) {
747
+ // For optional-out schemas, ignore errors on absent keys
748
+ if (isOptionalOut && !(key in input)) {
749
+ return;
750
+ }
751
+ final.issues.push(...util.prefixIssues(key, result.issues));
752
+ }
753
+ if (result.value === undefined) {
754
+ if (key in input) {
755
+ final.value[key] = undefined;
756
+ }
757
+ }
758
+ else {
759
+ final.value[key] = result.value;
760
+ }
761
+ }
762
+ function normalizeDef(def) {
763
+ const keys = Object.keys(def.shape);
764
+ for (const k of keys) {
765
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
766
+ throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
767
+ }
768
+ }
769
+ const okeys = util.optionalKeys(def.shape);
770
+ return {
771
+ ...def,
772
+ keys,
773
+ keySet: new Set(keys),
774
+ numKeys: keys.length,
775
+ optionalKeys: new Set(okeys),
776
+ };
777
+ }
778
+ function handleCatchall(proms, input, payload, ctx, def, inst) {
779
+ const unrecognized = [];
780
+ // iterate over input keys
781
+ const keySet = def.keySet;
782
+ const _catchall = def.catchall._zod;
783
+ const t = _catchall.def.type;
784
+ const isOptionalOut = _catchall.optout === "optional";
785
+ for (const key in input) {
786
+ if (keySet.has(key))
787
+ continue;
788
+ if (t === "never") {
789
+ unrecognized.push(key);
790
+ continue;
791
+ }
792
+ const r = _catchall.run({ value: input[key], issues: [] }, ctx);
793
+ if (r instanceof Promise) {
794
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
795
+ }
796
+ else {
797
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
798
+ }
799
+ }
800
+ if (unrecognized.length) {
801
+ payload.issues.push({
802
+ code: "unrecognized_keys",
803
+ keys: unrecognized,
804
+ input,
805
+ inst,
806
+ });
807
+ }
808
+ if (!proms.length)
809
+ return payload;
810
+ return Promise.all(proms).then(() => {
811
+ return payload;
812
+ });
813
+ }
814
+ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
815
+ // requires cast because technically $ZodObject doesn't extend
816
+ exports.$ZodType.init(inst, def);
817
+ // const sh = def.shape;
818
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
819
+ if (!desc?.get) {
820
+ const sh = def.shape;
821
+ Object.defineProperty(def, "shape", {
822
+ get: () => {
823
+ const newSh = { ...sh };
824
+ Object.defineProperty(def, "shape", {
825
+ value: newSh,
826
+ });
827
+ return newSh;
828
+ },
829
+ });
830
+ }
831
+ const _normalized = util.cached(() => normalizeDef(def));
832
+ util.defineLazy(inst._zod, "propValues", () => {
833
+ const shape = def.shape;
834
+ const propValues = {};
835
+ for (const key in shape) {
836
+ const field = shape[key]._zod;
837
+ if (field.values) {
838
+ propValues[key] ?? (propValues[key] = new Set());
839
+ for (const v of field.values)
840
+ propValues[key].add(v);
841
+ }
842
+ }
843
+ return propValues;
844
+ });
845
+ const isObject = util.isObject;
846
+ const catchall = def.catchall;
847
+ let value;
848
+ inst._zod.parse = (payload, ctx) => {
849
+ value ?? (value = _normalized.value);
850
+ const input = payload.value;
851
+ if (!isObject(input)) {
852
+ payload.issues.push({
853
+ expected: "object",
854
+ code: "invalid_type",
855
+ input,
856
+ inst,
857
+ });
858
+ return payload;
859
+ }
860
+ payload.value = {};
861
+ const proms = [];
862
+ const shape = value.shape;
863
+ for (const key of value.keys) {
864
+ const el = shape[key];
865
+ const isOptionalOut = el._zod.optout === "optional";
866
+ const r = el._zod.run({ value: input[key], issues: [] }, ctx);
867
+ if (r instanceof Promise) {
868
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
869
+ }
870
+ else {
871
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
872
+ }
873
+ }
874
+ if (!catchall) {
875
+ return proms.length ? Promise.all(proms).then(() => payload) : payload;
876
+ }
877
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
878
+ };
879
+ });
880
+ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
881
+ // requires cast because technically $ZodObject doesn't extend
882
+ exports.$ZodObject.init(inst, def);
883
+ const superParse = inst._zod.parse;
884
+ const _normalized = util.cached(() => normalizeDef(def));
885
+ const generateFastpass = (shape) => {
886
+ const doc = new doc_js_1.Doc(["shape", "payload", "ctx"]);
887
+ const normalized = _normalized.value;
888
+ const parseStr = (key) => {
889
+ const k = util.esc(key);
890
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
891
+ };
892
+ doc.write(`const input = payload.value;`);
893
+ const ids = Object.create(null);
894
+ let counter = 0;
895
+ for (const key of normalized.keys) {
896
+ ids[key] = `key_${counter++}`;
897
+ }
898
+ // A: preserve key order {
899
+ doc.write(`const newResult = {};`);
900
+ for (const key of normalized.keys) {
901
+ const id = ids[key];
902
+ const k = util.esc(key);
903
+ const schema = shape[key];
904
+ const isOptionalOut = schema?._zod?.optout === "optional";
905
+ doc.write(`const ${id} = ${parseStr(key)};`);
906
+ if (isOptionalOut) {
907
+ // For optional-out schemas, ignore errors on absent keys
908
+ doc.write(`
909
+ if (${id}.issues.length) {
910
+ if (${k} in input) {
911
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
912
+ ...iss,
913
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
914
+ })));
915
+ }
916
+ }
917
+
918
+ if (${id}.value === undefined) {
919
+ if (${k} in input) {
920
+ newResult[${k}] = undefined;
921
+ }
922
+ } else {
923
+ newResult[${k}] = ${id}.value;
924
+ }
925
+
926
+ `);
927
+ }
928
+ else {
929
+ doc.write(`
930
+ if (${id}.issues.length) {
931
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
932
+ ...iss,
933
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
934
+ })));
935
+ }
936
+
937
+ if (${id}.value === undefined) {
938
+ if (${k} in input) {
939
+ newResult[${k}] = undefined;
940
+ }
941
+ } else {
942
+ newResult[${k}] = ${id}.value;
943
+ }
944
+
945
+ `);
946
+ }
947
+ }
948
+ doc.write(`payload.value = newResult;`);
949
+ doc.write(`return payload;`);
950
+ const fn = doc.compile();
951
+ return (payload, ctx) => fn(shape, payload, ctx);
952
+ };
953
+ let fastpass;
954
+ const isObject = util.isObject;
955
+ const jit = !core.globalConfig.jitless;
956
+ const allowsEval = util.allowsEval;
957
+ const fastEnabled = jit && allowsEval.value; // && !def.catchall;
958
+ const catchall = def.catchall;
959
+ let value;
960
+ inst._zod.parse = (payload, ctx) => {
961
+ value ?? (value = _normalized.value);
962
+ const input = payload.value;
963
+ if (!isObject(input)) {
964
+ payload.issues.push({
965
+ expected: "object",
966
+ code: "invalid_type",
967
+ input,
968
+ inst,
969
+ });
970
+ return payload;
971
+ }
972
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
973
+ // always synchronous
974
+ if (!fastpass)
975
+ fastpass = generateFastpass(def.shape);
976
+ payload = fastpass(payload, ctx);
977
+ if (!catchall)
978
+ return payload;
979
+ return handleCatchall([], input, payload, ctx, value, inst);
980
+ }
981
+ return superParse(payload, ctx);
982
+ };
983
+ });
984
+ function handleUnionResults(results, final, inst, ctx) {
985
+ for (const result of results) {
986
+ if (result.issues.length === 0) {
987
+ final.value = result.value;
988
+ return final;
989
+ }
990
+ }
991
+ const nonaborted = results.filter((r) => !util.aborted(r));
992
+ if (nonaborted.length === 1) {
993
+ final.value = nonaborted[0].value;
994
+ return nonaborted[0];
995
+ }
996
+ final.issues.push({
997
+ code: "invalid_union",
998
+ input: final.value,
999
+ inst,
1000
+ errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
1001
+ });
1002
+ return final;
1003
+ }
1004
+ exports.$ZodUnion = core.$constructor("$ZodUnion", (inst, def) => {
1005
+ exports.$ZodType.init(inst, def);
1006
+ util.defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined);
1007
+ util.defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined);
1008
+ util.defineLazy(inst._zod, "values", () => {
1009
+ if (def.options.every((o) => o._zod.values)) {
1010
+ return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1011
+ }
1012
+ return undefined;
1013
+ });
1014
+ util.defineLazy(inst._zod, "pattern", () => {
1015
+ if (def.options.every((o) => o._zod.pattern)) {
1016
+ const patterns = def.options.map((o) => o._zod.pattern);
1017
+ return new RegExp(`^(${patterns.map((p) => util.cleanRegex(p.source)).join("|")})$`);
1018
+ }
1019
+ return undefined;
1020
+ });
1021
+ const single = def.options.length === 1;
1022
+ const first = def.options[0]._zod.run;
1023
+ inst._zod.parse = (payload, ctx) => {
1024
+ if (single) {
1025
+ return first(payload, ctx);
1026
+ }
1027
+ let async = false;
1028
+ const results = [];
1029
+ for (const option of def.options) {
1030
+ const result = option._zod.run({
1031
+ value: payload.value,
1032
+ issues: [],
1033
+ }, ctx);
1034
+ if (result instanceof Promise) {
1035
+ results.push(result);
1036
+ async = true;
1037
+ }
1038
+ else {
1039
+ if (result.issues.length === 0)
1040
+ return result;
1041
+ results.push(result);
1042
+ }
1043
+ }
1044
+ if (!async)
1045
+ return handleUnionResults(results, payload, inst, ctx);
1046
+ return Promise.all(results).then((results) => {
1047
+ return handleUnionResults(results, payload, inst, ctx);
1048
+ });
1049
+ };
1050
+ });
1051
+ function handleExclusiveUnionResults(results, final, inst, ctx) {
1052
+ const successes = results.filter((r) => r.issues.length === 0);
1053
+ if (successes.length === 1) {
1054
+ final.value = successes[0].value;
1055
+ return final;
1056
+ }
1057
+ if (successes.length === 0) {
1058
+ // No matches - same as regular union
1059
+ final.issues.push({
1060
+ code: "invalid_union",
1061
+ input: final.value,
1062
+ inst,
1063
+ errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
1064
+ });
1065
+ }
1066
+ else {
1067
+ // Multiple matches - exclusive union failure
1068
+ final.issues.push({
1069
+ code: "invalid_union",
1070
+ input: final.value,
1071
+ inst,
1072
+ errors: [],
1073
+ inclusive: false,
1074
+ });
1075
+ }
1076
+ return final;
1077
+ }
1078
+ exports.$ZodXor = core.$constructor("$ZodXor", (inst, def) => {
1079
+ exports.$ZodUnion.init(inst, def);
1080
+ def.inclusive = false;
1081
+ const single = def.options.length === 1;
1082
+ const first = def.options[0]._zod.run;
1083
+ inst._zod.parse = (payload, ctx) => {
1084
+ if (single) {
1085
+ return first(payload, ctx);
1086
+ }
1087
+ let async = false;
1088
+ const results = [];
1089
+ for (const option of def.options) {
1090
+ const result = option._zod.run({
1091
+ value: payload.value,
1092
+ issues: [],
1093
+ }, ctx);
1094
+ if (result instanceof Promise) {
1095
+ results.push(result);
1096
+ async = true;
1097
+ }
1098
+ else {
1099
+ results.push(result);
1100
+ }
1101
+ }
1102
+ if (!async)
1103
+ return handleExclusiveUnionResults(results, payload, inst, ctx);
1104
+ return Promise.all(results).then((results) => {
1105
+ return handleExclusiveUnionResults(results, payload, inst, ctx);
1106
+ });
1107
+ };
1108
+ });
1109
+ exports.$ZodDiscriminatedUnion =
1110
+ /*@__PURE__*/
1111
+ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1112
+ def.inclusive = false;
1113
+ exports.$ZodUnion.init(inst, def);
1114
+ const _super = inst._zod.parse;
1115
+ util.defineLazy(inst._zod, "propValues", () => {
1116
+ const propValues = {};
1117
+ for (const option of def.options) {
1118
+ const pv = option._zod.propValues;
1119
+ if (!pv || Object.keys(pv).length === 0)
1120
+ throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
1121
+ for (const [k, v] of Object.entries(pv)) {
1122
+ if (!propValues[k])
1123
+ propValues[k] = new Set();
1124
+ for (const val of v) {
1125
+ propValues[k].add(val);
1126
+ }
1127
+ }
1128
+ }
1129
+ return propValues;
1130
+ });
1131
+ const disc = util.cached(() => {
1132
+ const opts = def.options;
1133
+ const map = new Map();
1134
+ for (const o of opts) {
1135
+ const values = o._zod.propValues?.[def.discriminator];
1136
+ if (!values || values.size === 0)
1137
+ throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
1138
+ for (const v of values) {
1139
+ if (map.has(v)) {
1140
+ throw new Error(`Duplicate discriminator value "${String(v)}"`);
1141
+ }
1142
+ map.set(v, o);
1143
+ }
1144
+ }
1145
+ return map;
1146
+ });
1147
+ inst._zod.parse = (payload, ctx) => {
1148
+ const input = payload.value;
1149
+ if (!util.isObject(input)) {
1150
+ payload.issues.push({
1151
+ code: "invalid_type",
1152
+ expected: "object",
1153
+ input,
1154
+ inst,
1155
+ });
1156
+ return payload;
1157
+ }
1158
+ const opt = disc.value.get(input?.[def.discriminator]);
1159
+ if (opt) {
1160
+ return opt._zod.run(payload, ctx);
1161
+ }
1162
+ if (def.unionFallback) {
1163
+ return _super(payload, ctx);
1164
+ }
1165
+ // no matching discriminator
1166
+ payload.issues.push({
1167
+ code: "invalid_union",
1168
+ errors: [],
1169
+ note: "No matching discriminator",
1170
+ discriminator: def.discriminator,
1171
+ input,
1172
+ path: [def.discriminator],
1173
+ inst,
1174
+ });
1175
+ return payload;
1176
+ };
1177
+ });
1178
+ exports.$ZodIntersection = core.$constructor("$ZodIntersection", (inst, def) => {
1179
+ exports.$ZodType.init(inst, def);
1180
+ inst._zod.parse = (payload, ctx) => {
1181
+ const input = payload.value;
1182
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
1183
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
1184
+ const async = left instanceof Promise || right instanceof Promise;
1185
+ if (async) {
1186
+ return Promise.all([left, right]).then(([left, right]) => {
1187
+ return handleIntersectionResults(payload, left, right);
1188
+ });
1189
+ }
1190
+ return handleIntersectionResults(payload, left, right);
1191
+ };
1192
+ });
1193
+ function mergeValues(a, b) {
1194
+ // const aType = parse.t(a);
1195
+ // const bType = parse.t(b);
1196
+ if (a === b) {
1197
+ return { valid: true, data: a };
1198
+ }
1199
+ if (a instanceof Date && b instanceof Date && +a === +b) {
1200
+ return { valid: true, data: a };
1201
+ }
1202
+ if (util.isPlainObject(a) && util.isPlainObject(b)) {
1203
+ const bKeys = Object.keys(b);
1204
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1205
+ const newObj = { ...a, ...b };
1206
+ for (const key of sharedKeys) {
1207
+ const sharedValue = mergeValues(a[key], b[key]);
1208
+ if (!sharedValue.valid) {
1209
+ return {
1210
+ valid: false,
1211
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
1212
+ };
1213
+ }
1214
+ newObj[key] = sharedValue.data;
1215
+ }
1216
+ return { valid: true, data: newObj };
1217
+ }
1218
+ if (Array.isArray(a) && Array.isArray(b)) {
1219
+ if (a.length !== b.length) {
1220
+ return { valid: false, mergeErrorPath: [] };
1221
+ }
1222
+ const newArray = [];
1223
+ for (let index = 0; index < a.length; index++) {
1224
+ const itemA = a[index];
1225
+ const itemB = b[index];
1226
+ const sharedValue = mergeValues(itemA, itemB);
1227
+ if (!sharedValue.valid) {
1228
+ return {
1229
+ valid: false,
1230
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
1231
+ };
1232
+ }
1233
+ newArray.push(sharedValue.data);
1234
+ }
1235
+ return { valid: true, data: newArray };
1236
+ }
1237
+ return { valid: false, mergeErrorPath: [] };
1238
+ }
1239
+ function handleIntersectionResults(result, left, right) {
1240
+ // Track which side(s) report each key as unrecognized
1241
+ const unrecKeys = new Map();
1242
+ let unrecIssue;
1243
+ for (const iss of left.issues) {
1244
+ if (iss.code === "unrecognized_keys") {
1245
+ unrecIssue ?? (unrecIssue = iss);
1246
+ for (const k of iss.keys) {
1247
+ if (!unrecKeys.has(k))
1248
+ unrecKeys.set(k, {});
1249
+ unrecKeys.get(k).l = true;
1250
+ }
1251
+ }
1252
+ else {
1253
+ result.issues.push(iss);
1254
+ }
1255
+ }
1256
+ for (const iss of right.issues) {
1257
+ if (iss.code === "unrecognized_keys") {
1258
+ for (const k of iss.keys) {
1259
+ if (!unrecKeys.has(k))
1260
+ unrecKeys.set(k, {});
1261
+ unrecKeys.get(k).r = true;
1262
+ }
1263
+ }
1264
+ else {
1265
+ result.issues.push(iss);
1266
+ }
1267
+ }
1268
+ // Report only keys unrecognized by BOTH sides
1269
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
1270
+ if (bothKeys.length && unrecIssue) {
1271
+ result.issues.push({ ...unrecIssue, keys: bothKeys });
1272
+ }
1273
+ if (util.aborted(result))
1274
+ return result;
1275
+ const merged = mergeValues(left.value, right.value);
1276
+ if (!merged.valid) {
1277
+ throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
1278
+ }
1279
+ result.value = merged.data;
1280
+ return result;
1281
+ }
1282
+ exports.$ZodTuple = core.$constructor("$ZodTuple", (inst, def) => {
1283
+ exports.$ZodType.init(inst, def);
1284
+ const items = def.items;
1285
+ inst._zod.parse = (payload, ctx) => {
1286
+ const input = payload.value;
1287
+ if (!Array.isArray(input)) {
1288
+ payload.issues.push({
1289
+ input,
1290
+ inst,
1291
+ expected: "tuple",
1292
+ code: "invalid_type",
1293
+ });
1294
+ return payload;
1295
+ }
1296
+ payload.value = [];
1297
+ const proms = [];
1298
+ const reversedIndex = [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
1299
+ const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;
1300
+ if (!def.rest) {
1301
+ const tooBig = input.length > items.length;
1302
+ const tooSmall = input.length < optStart - 1;
1303
+ if (tooBig || tooSmall) {
1304
+ payload.issues.push({
1305
+ ...(tooBig
1306
+ ? { code: "too_big", maximum: items.length, inclusive: true }
1307
+ : { code: "too_small", minimum: items.length }),
1308
+ input,
1309
+ inst,
1310
+ origin: "array",
1311
+ });
1312
+ return payload;
1313
+ }
1314
+ }
1315
+ let i = -1;
1316
+ for (const item of items) {
1317
+ i++;
1318
+ if (i >= input.length)
1319
+ if (i >= optStart)
1320
+ continue;
1321
+ const result = item._zod.run({
1322
+ value: input[i],
1323
+ issues: [],
1324
+ }, ctx);
1325
+ if (result instanceof Promise) {
1326
+ proms.push(result.then((result) => handleTupleResult(result, payload, i)));
1327
+ }
1328
+ else {
1329
+ handleTupleResult(result, payload, i);
1330
+ }
1331
+ }
1332
+ if (def.rest) {
1333
+ const rest = input.slice(items.length);
1334
+ for (const el of rest) {
1335
+ i++;
1336
+ const result = def.rest._zod.run({
1337
+ value: el,
1338
+ issues: [],
1339
+ }, ctx);
1340
+ if (result instanceof Promise) {
1341
+ proms.push(result.then((result) => handleTupleResult(result, payload, i)));
1342
+ }
1343
+ else {
1344
+ handleTupleResult(result, payload, i);
1345
+ }
1346
+ }
1347
+ }
1348
+ if (proms.length)
1349
+ return Promise.all(proms).then(() => payload);
1350
+ return payload;
1351
+ };
1352
+ });
1353
+ function handleTupleResult(result, final, index) {
1354
+ if (result.issues.length) {
1355
+ final.issues.push(...util.prefixIssues(index, result.issues));
1356
+ }
1357
+ final.value[index] = result.value;
1358
+ }
1359
+ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
1360
+ exports.$ZodType.init(inst, def);
1361
+ inst._zod.parse = (payload, ctx) => {
1362
+ const input = payload.value;
1363
+ if (!util.isPlainObject(input)) {
1364
+ payload.issues.push({
1365
+ expected: "record",
1366
+ code: "invalid_type",
1367
+ input,
1368
+ inst,
1369
+ });
1370
+ return payload;
1371
+ }
1372
+ const proms = [];
1373
+ const values = def.keyType._zod.values;
1374
+ if (values) {
1375
+ payload.value = {};
1376
+ const recordKeys = new Set();
1377
+ for (const key of values) {
1378
+ if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1379
+ recordKeys.add(typeof key === "number" ? key.toString() : key);
1380
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1381
+ if (result instanceof Promise) {
1382
+ proms.push(result.then((result) => {
1383
+ if (result.issues.length) {
1384
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1385
+ }
1386
+ payload.value[key] = result.value;
1387
+ }));
1388
+ }
1389
+ else {
1390
+ if (result.issues.length) {
1391
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1392
+ }
1393
+ payload.value[key] = result.value;
1394
+ }
1395
+ }
1396
+ }
1397
+ let unrecognized;
1398
+ for (const key in input) {
1399
+ if (!recordKeys.has(key)) {
1400
+ unrecognized = unrecognized ?? [];
1401
+ unrecognized.push(key);
1402
+ }
1403
+ }
1404
+ if (unrecognized && unrecognized.length > 0) {
1405
+ payload.issues.push({
1406
+ code: "unrecognized_keys",
1407
+ input,
1408
+ inst,
1409
+ keys: unrecognized,
1410
+ });
1411
+ }
1412
+ }
1413
+ else {
1414
+ payload.value = {};
1415
+ for (const key of Reflect.ownKeys(input)) {
1416
+ if (key === "__proto__")
1417
+ continue;
1418
+ let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1419
+ if (keyResult instanceof Promise) {
1420
+ throw new Error("Async schemas not supported in object keys currently");
1421
+ }
1422
+ // Numeric string fallback: if key is a numeric string and failed, retry with Number(key)
1423
+ // This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
1424
+ const checkNumericKey = typeof key === "string" && regexes.number.test(key) && keyResult.issues.length;
1425
+ if (checkNumericKey) {
1426
+ const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
1427
+ if (retryResult instanceof Promise) {
1428
+ throw new Error("Async schemas not supported in object keys currently");
1429
+ }
1430
+ if (retryResult.issues.length === 0) {
1431
+ keyResult = retryResult;
1432
+ }
1433
+ }
1434
+ if (keyResult.issues.length) {
1435
+ if (def.mode === "loose") {
1436
+ // Pass through unchanged
1437
+ payload.value[key] = input[key];
1438
+ }
1439
+ else {
1440
+ // Default "strict" behavior: error on invalid key
1441
+ payload.issues.push({
1442
+ code: "invalid_key",
1443
+ origin: "record",
1444
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1445
+ input: key,
1446
+ path: [key],
1447
+ inst,
1448
+ });
1449
+ }
1450
+ continue;
1451
+ }
1452
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1453
+ if (result instanceof Promise) {
1454
+ proms.push(result.then((result) => {
1455
+ if (result.issues.length) {
1456
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1457
+ }
1458
+ payload.value[keyResult.value] = result.value;
1459
+ }));
1460
+ }
1461
+ else {
1462
+ if (result.issues.length) {
1463
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1464
+ }
1465
+ payload.value[keyResult.value] = result.value;
1466
+ }
1467
+ }
1468
+ }
1469
+ if (proms.length) {
1470
+ return Promise.all(proms).then(() => payload);
1471
+ }
1472
+ return payload;
1473
+ };
1474
+ });
1475
+ exports.$ZodMap = core.$constructor("$ZodMap", (inst, def) => {
1476
+ exports.$ZodType.init(inst, def);
1477
+ inst._zod.parse = (payload, ctx) => {
1478
+ const input = payload.value;
1479
+ if (!(input instanceof Map)) {
1480
+ payload.issues.push({
1481
+ expected: "map",
1482
+ code: "invalid_type",
1483
+ input,
1484
+ inst,
1485
+ });
1486
+ return payload;
1487
+ }
1488
+ const proms = [];
1489
+ payload.value = new Map();
1490
+ for (const [key, value] of input) {
1491
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1492
+ const valueResult = def.valueType._zod.run({ value: value, issues: [] }, ctx);
1493
+ if (keyResult instanceof Promise || valueResult instanceof Promise) {
1494
+ proms.push(Promise.all([keyResult, valueResult]).then(([keyResult, valueResult]) => {
1495
+ handleMapResult(keyResult, valueResult, payload, key, input, inst, ctx);
1496
+ }));
1497
+ }
1498
+ else {
1499
+ handleMapResult(keyResult, valueResult, payload, key, input, inst, ctx);
1500
+ }
1501
+ }
1502
+ if (proms.length)
1503
+ return Promise.all(proms).then(() => payload);
1504
+ return payload;
1505
+ };
1506
+ });
1507
+ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1508
+ if (keyResult.issues.length) {
1509
+ if (util.propertyKeyTypes.has(typeof key)) {
1510
+ final.issues.push(...util.prefixIssues(key, keyResult.issues));
1511
+ }
1512
+ else {
1513
+ final.issues.push({
1514
+ code: "invalid_key",
1515
+ origin: "map",
1516
+ input,
1517
+ inst,
1518
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1519
+ });
1520
+ }
1521
+ }
1522
+ if (valueResult.issues.length) {
1523
+ if (util.propertyKeyTypes.has(typeof key)) {
1524
+ final.issues.push(...util.prefixIssues(key, valueResult.issues));
1525
+ }
1526
+ else {
1527
+ final.issues.push({
1528
+ origin: "map",
1529
+ code: "invalid_element",
1530
+ input,
1531
+ inst,
1532
+ key: key,
1533
+ issues: valueResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1534
+ });
1535
+ }
1536
+ }
1537
+ final.value.set(keyResult.value, valueResult.value);
1538
+ }
1539
+ exports.$ZodSet = core.$constructor("$ZodSet", (inst, def) => {
1540
+ exports.$ZodType.init(inst, def);
1541
+ inst._zod.parse = (payload, ctx) => {
1542
+ const input = payload.value;
1543
+ if (!(input instanceof Set)) {
1544
+ payload.issues.push({
1545
+ input,
1546
+ inst,
1547
+ expected: "set",
1548
+ code: "invalid_type",
1549
+ });
1550
+ return payload;
1551
+ }
1552
+ const proms = [];
1553
+ payload.value = new Set();
1554
+ for (const item of input) {
1555
+ const result = def.valueType._zod.run({ value: item, issues: [] }, ctx);
1556
+ if (result instanceof Promise) {
1557
+ proms.push(result.then((result) => handleSetResult(result, payload)));
1558
+ }
1559
+ else
1560
+ handleSetResult(result, payload);
1561
+ }
1562
+ if (proms.length)
1563
+ return Promise.all(proms).then(() => payload);
1564
+ return payload;
1565
+ };
1566
+ });
1567
+ function handleSetResult(result, final) {
1568
+ if (result.issues.length) {
1569
+ final.issues.push(...result.issues);
1570
+ }
1571
+ final.value.add(result.value);
1572
+ }
1573
+ exports.$ZodEnum = core.$constructor("$ZodEnum", (inst, def) => {
1574
+ exports.$ZodType.init(inst, def);
1575
+ const values = util.getEnumValues(def.entries);
1576
+ const valuesSet = new Set(values);
1577
+ inst._zod.values = valuesSet;
1578
+ inst._zod.pattern = new RegExp(`^(${values
1579
+ .filter((k) => util.propertyKeyTypes.has(typeof k))
1580
+ .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o.toString()))
1581
+ .join("|")})$`);
1582
+ inst._zod.parse = (payload, _ctx) => {
1583
+ const input = payload.value;
1584
+ if (valuesSet.has(input)) {
1585
+ return payload;
1586
+ }
1587
+ payload.issues.push({
1588
+ code: "invalid_value",
1589
+ values,
1590
+ input,
1591
+ inst,
1592
+ });
1593
+ return payload;
1594
+ };
1595
+ });
1596
+ exports.$ZodLiteral = core.$constructor("$ZodLiteral", (inst, def) => {
1597
+ exports.$ZodType.init(inst, def);
1598
+ if (def.values.length === 0) {
1599
+ throw new Error("Cannot create literal schema with no valid values");
1600
+ }
1601
+ const values = new Set(def.values);
1602
+ inst._zod.values = values;
1603
+ inst._zod.pattern = new RegExp(`^(${def.values
1604
+ .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
1605
+ .join("|")})$`);
1606
+ inst._zod.parse = (payload, _ctx) => {
1607
+ const input = payload.value;
1608
+ if (values.has(input)) {
1609
+ return payload;
1610
+ }
1611
+ payload.issues.push({
1612
+ code: "invalid_value",
1613
+ values: def.values,
1614
+ input,
1615
+ inst,
1616
+ });
1617
+ return payload;
1618
+ };
1619
+ });
1620
+ exports.$ZodFile = core.$constructor("$ZodFile", (inst, def) => {
1621
+ exports.$ZodType.init(inst, def);
1622
+ inst._zod.parse = (payload, _ctx) => {
1623
+ const input = payload.value;
1624
+ // @ts-ignore
1625
+ if (input instanceof File)
1626
+ return payload;
1627
+ payload.issues.push({
1628
+ expected: "file",
1629
+ code: "invalid_type",
1630
+ input,
1631
+ inst,
1632
+ });
1633
+ return payload;
1634
+ };
1635
+ });
1636
+ exports.$ZodTransform = core.$constructor("$ZodTransform", (inst, def) => {
1637
+ exports.$ZodType.init(inst, def);
1638
+ inst._zod.parse = (payload, ctx) => {
1639
+ if (ctx.direction === "backward") {
1640
+ throw new core.$ZodEncodeError(inst.constructor.name);
1641
+ }
1642
+ const _out = def.transform(payload.value, payload);
1643
+ if (ctx.async) {
1644
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
1645
+ return output.then((output) => {
1646
+ payload.value = output;
1647
+ return payload;
1648
+ });
1649
+ }
1650
+ if (_out instanceof Promise) {
1651
+ throw new core.$ZodAsyncError();
1652
+ }
1653
+ payload.value = _out;
1654
+ return payload;
1655
+ };
1656
+ });
1657
+ function handleOptionalResult(result, input) {
1658
+ if (result.issues.length && input === undefined) {
1659
+ return { issues: [], value: undefined };
1660
+ }
1661
+ return result;
1662
+ }
1663
+ exports.$ZodOptional = core.$constructor("$ZodOptional", (inst, def) => {
1664
+ exports.$ZodType.init(inst, def);
1665
+ inst._zod.optin = "optional";
1666
+ inst._zod.optout = "optional";
1667
+ util.defineLazy(inst._zod, "values", () => {
1668
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
1669
+ });
1670
+ util.defineLazy(inst._zod, "pattern", () => {
1671
+ const pattern = def.innerType._zod.pattern;
1672
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)})?$`) : undefined;
1673
+ });
1674
+ inst._zod.parse = (payload, ctx) => {
1675
+ if (def.innerType._zod.optin === "optional") {
1676
+ const result = def.innerType._zod.run(payload, ctx);
1677
+ if (result instanceof Promise)
1678
+ return result.then((r) => handleOptionalResult(r, payload.value));
1679
+ return handleOptionalResult(result, payload.value);
1680
+ }
1681
+ if (payload.value === undefined) {
1682
+ return payload;
1683
+ }
1684
+ return def.innerType._zod.run(payload, ctx);
1685
+ };
1686
+ });
1687
+ exports.$ZodExactOptional = core.$constructor("$ZodExactOptional", (inst, def) => {
1688
+ // Call parent init - inherits optin/optout = "optional"
1689
+ exports.$ZodOptional.init(inst, def);
1690
+ // Override values/pattern to NOT add undefined
1691
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1692
+ util.defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
1693
+ // Override parse to just delegate (no undefined handling)
1694
+ inst._zod.parse = (payload, ctx) => {
1695
+ return def.innerType._zod.run(payload, ctx);
1696
+ };
1697
+ });
1698
+ exports.$ZodNullable = core.$constructor("$ZodNullable", (inst, def) => {
1699
+ exports.$ZodType.init(inst, def);
1700
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1701
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1702
+ util.defineLazy(inst._zod, "pattern", () => {
1703
+ const pattern = def.innerType._zod.pattern;
1704
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)}|null)$`) : undefined;
1705
+ });
1706
+ util.defineLazy(inst._zod, "values", () => {
1707
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
1708
+ });
1709
+ inst._zod.parse = (payload, ctx) => {
1710
+ // Forward direction (decode): allow null to pass through
1711
+ if (payload.value === null)
1712
+ return payload;
1713
+ return def.innerType._zod.run(payload, ctx);
1714
+ };
1715
+ });
1716
+ exports.$ZodDefault = core.$constructor("$ZodDefault", (inst, def) => {
1717
+ exports.$ZodType.init(inst, def);
1718
+ // inst._zod.qin = "true";
1719
+ inst._zod.optin = "optional";
1720
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1721
+ inst._zod.parse = (payload, ctx) => {
1722
+ if (ctx.direction === "backward") {
1723
+ return def.innerType._zod.run(payload, ctx);
1724
+ }
1725
+ // Forward direction (decode): apply defaults for undefined input
1726
+ if (payload.value === undefined) {
1727
+ payload.value = def.defaultValue;
1728
+ /**
1729
+ * $ZodDefault returns the default value immediately in forward direction.
1730
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
1731
+ return payload;
1732
+ }
1733
+ // Forward direction: continue with default handling
1734
+ const result = def.innerType._zod.run(payload, ctx);
1735
+ if (result instanceof Promise) {
1736
+ return result.then((result) => handleDefaultResult(result, def));
1737
+ }
1738
+ return handleDefaultResult(result, def);
1739
+ };
1740
+ });
1741
+ function handleDefaultResult(payload, def) {
1742
+ if (payload.value === undefined) {
1743
+ payload.value = def.defaultValue;
1744
+ }
1745
+ return payload;
1746
+ }
1747
+ exports.$ZodPrefault = core.$constructor("$ZodPrefault", (inst, def) => {
1748
+ exports.$ZodType.init(inst, def);
1749
+ inst._zod.optin = "optional";
1750
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1751
+ inst._zod.parse = (payload, ctx) => {
1752
+ if (ctx.direction === "backward") {
1753
+ return def.innerType._zod.run(payload, ctx);
1754
+ }
1755
+ // Forward direction (decode): apply prefault for undefined input
1756
+ if (payload.value === undefined) {
1757
+ payload.value = def.defaultValue;
1758
+ }
1759
+ return def.innerType._zod.run(payload, ctx);
1760
+ };
1761
+ });
1762
+ exports.$ZodNonOptional = core.$constructor("$ZodNonOptional", (inst, def) => {
1763
+ exports.$ZodType.init(inst, def);
1764
+ util.defineLazy(inst._zod, "values", () => {
1765
+ const v = def.innerType._zod.values;
1766
+ return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
1767
+ });
1768
+ inst._zod.parse = (payload, ctx) => {
1769
+ const result = def.innerType._zod.run(payload, ctx);
1770
+ if (result instanceof Promise) {
1771
+ return result.then((result) => handleNonOptionalResult(result, inst));
1772
+ }
1773
+ return handleNonOptionalResult(result, inst);
1774
+ };
1775
+ });
1776
+ function handleNonOptionalResult(payload, inst) {
1777
+ if (!payload.issues.length && payload.value === undefined) {
1778
+ payload.issues.push({
1779
+ code: "invalid_type",
1780
+ expected: "nonoptional",
1781
+ input: payload.value,
1782
+ inst,
1783
+ });
1784
+ }
1785
+ return payload;
1786
+ }
1787
+ exports.$ZodSuccess = core.$constructor("$ZodSuccess", (inst, def) => {
1788
+ exports.$ZodType.init(inst, def);
1789
+ inst._zod.parse = (payload, ctx) => {
1790
+ if (ctx.direction === "backward") {
1791
+ throw new core.$ZodEncodeError("ZodSuccess");
1792
+ }
1793
+ const result = def.innerType._zod.run(payload, ctx);
1794
+ if (result instanceof Promise) {
1795
+ return result.then((result) => {
1796
+ payload.value = result.issues.length === 0;
1797
+ return payload;
1798
+ });
1799
+ }
1800
+ payload.value = result.issues.length === 0;
1801
+ return payload;
1802
+ };
1803
+ });
1804
+ exports.$ZodCatch = core.$constructor("$ZodCatch", (inst, def) => {
1805
+ exports.$ZodType.init(inst, def);
1806
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1807
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1808
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1809
+ inst._zod.parse = (payload, ctx) => {
1810
+ if (ctx.direction === "backward") {
1811
+ return def.innerType._zod.run(payload, ctx);
1812
+ }
1813
+ // Forward direction (decode): apply catch logic
1814
+ const result = def.innerType._zod.run(payload, ctx);
1815
+ if (result instanceof Promise) {
1816
+ return result.then((result) => {
1817
+ payload.value = result.value;
1818
+ if (result.issues.length) {
1819
+ payload.value = def.catchValue({
1820
+ ...payload,
1821
+ error: {
1822
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1823
+ },
1824
+ input: payload.value,
1825
+ });
1826
+ payload.issues = [];
1827
+ }
1828
+ return payload;
1829
+ });
1830
+ }
1831
+ payload.value = result.value;
1832
+ if (result.issues.length) {
1833
+ payload.value = def.catchValue({
1834
+ ...payload,
1835
+ error: {
1836
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1837
+ },
1838
+ input: payload.value,
1839
+ });
1840
+ payload.issues = [];
1841
+ }
1842
+ return payload;
1843
+ };
1844
+ });
1845
+ exports.$ZodNaN = core.$constructor("$ZodNaN", (inst, def) => {
1846
+ exports.$ZodType.init(inst, def);
1847
+ inst._zod.parse = (payload, _ctx) => {
1848
+ if (typeof payload.value !== "number" || !Number.isNaN(payload.value)) {
1849
+ payload.issues.push({
1850
+ input: payload.value,
1851
+ inst,
1852
+ expected: "nan",
1853
+ code: "invalid_type",
1854
+ });
1855
+ return payload;
1856
+ }
1857
+ return payload;
1858
+ };
1859
+ });
1860
+ exports.$ZodPipe = core.$constructor("$ZodPipe", (inst, def) => {
1861
+ exports.$ZodType.init(inst, def);
1862
+ util.defineLazy(inst._zod, "values", () => def.in._zod.values);
1863
+ util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1864
+ util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1865
+ util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
1866
+ inst._zod.parse = (payload, ctx) => {
1867
+ if (ctx.direction === "backward") {
1868
+ const right = def.out._zod.run(payload, ctx);
1869
+ if (right instanceof Promise) {
1870
+ return right.then((right) => handlePipeResult(right, def.in, ctx));
1871
+ }
1872
+ return handlePipeResult(right, def.in, ctx);
1873
+ }
1874
+ const left = def.in._zod.run(payload, ctx);
1875
+ if (left instanceof Promise) {
1876
+ return left.then((left) => handlePipeResult(left, def.out, ctx));
1877
+ }
1878
+ return handlePipeResult(left, def.out, ctx);
1879
+ };
1880
+ });
1881
+ function handlePipeResult(left, next, ctx) {
1882
+ if (left.issues.length) {
1883
+ // prevent further checks
1884
+ left.aborted = true;
1885
+ return left;
1886
+ }
1887
+ return next._zod.run({ value: left.value, issues: left.issues }, ctx);
1888
+ }
1889
+ exports.$ZodCodec = core.$constructor("$ZodCodec", (inst, def) => {
1890
+ exports.$ZodType.init(inst, def);
1891
+ util.defineLazy(inst._zod, "values", () => def.in._zod.values);
1892
+ util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1893
+ util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1894
+ util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
1895
+ inst._zod.parse = (payload, ctx) => {
1896
+ const direction = ctx.direction || "forward";
1897
+ if (direction === "forward") {
1898
+ const left = def.in._zod.run(payload, ctx);
1899
+ if (left instanceof Promise) {
1900
+ return left.then((left) => handleCodecAResult(left, def, ctx));
1901
+ }
1902
+ return handleCodecAResult(left, def, ctx);
1903
+ }
1904
+ else {
1905
+ const right = def.out._zod.run(payload, ctx);
1906
+ if (right instanceof Promise) {
1907
+ return right.then((right) => handleCodecAResult(right, def, ctx));
1908
+ }
1909
+ return handleCodecAResult(right, def, ctx);
1910
+ }
1911
+ };
1912
+ });
1913
+ function handleCodecAResult(result, def, ctx) {
1914
+ if (result.issues.length) {
1915
+ // prevent further checks
1916
+ result.aborted = true;
1917
+ return result;
1918
+ }
1919
+ const direction = ctx.direction || "forward";
1920
+ if (direction === "forward") {
1921
+ const transformed = def.transform(result.value, result);
1922
+ if (transformed instanceof Promise) {
1923
+ return transformed.then((value) => handleCodecTxResult(result, value, def.out, ctx));
1924
+ }
1925
+ return handleCodecTxResult(result, transformed, def.out, ctx);
1926
+ }
1927
+ else {
1928
+ const transformed = def.reverseTransform(result.value, result);
1929
+ if (transformed instanceof Promise) {
1930
+ return transformed.then((value) => handleCodecTxResult(result, value, def.in, ctx));
1931
+ }
1932
+ return handleCodecTxResult(result, transformed, def.in, ctx);
1933
+ }
1934
+ }
1935
+ function handleCodecTxResult(left, value, nextSchema, ctx) {
1936
+ // Check if transform added any issues
1937
+ if (left.issues.length) {
1938
+ left.aborted = true;
1939
+ return left;
1940
+ }
1941
+ return nextSchema._zod.run({ value, issues: left.issues }, ctx);
1942
+ }
1943
+ exports.$ZodReadonly = core.$constructor("$ZodReadonly", (inst, def) => {
1944
+ exports.$ZodType.init(inst, def);
1945
+ util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1946
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1947
+ util.defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
1948
+ util.defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
1949
+ inst._zod.parse = (payload, ctx) => {
1950
+ if (ctx.direction === "backward") {
1951
+ return def.innerType._zod.run(payload, ctx);
1952
+ }
1953
+ const result = def.innerType._zod.run(payload, ctx);
1954
+ if (result instanceof Promise) {
1955
+ return result.then(handleReadonlyResult);
1956
+ }
1957
+ return handleReadonlyResult(result);
1958
+ };
1959
+ });
1960
+ function handleReadonlyResult(payload) {
1961
+ payload.value = Object.freeze(payload.value);
1962
+ return payload;
1963
+ }
1964
+ exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, def) => {
1965
+ exports.$ZodType.init(inst, def);
1966
+ const regexParts = [];
1967
+ for (const part of def.parts) {
1968
+ if (typeof part === "object" && part !== null) {
1969
+ // is Zod schema
1970
+ if (!part._zod.pattern) {
1971
+ // if (!source)
1972
+ throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
1973
+ }
1974
+ const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;
1975
+ if (!source)
1976
+ throw new Error(`Invalid template literal part: ${part._zod.traits}`);
1977
+ const start = source.startsWith("^") ? 1 : 0;
1978
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
1979
+ regexParts.push(source.slice(start, end));
1980
+ }
1981
+ else if (part === null || util.primitiveTypes.has(typeof part)) {
1982
+ regexParts.push(util.escapeRegex(`${part}`));
1983
+ }
1984
+ else {
1985
+ throw new Error(`Invalid template literal part: ${part}`);
1986
+ }
1987
+ }
1988
+ inst._zod.pattern = new RegExp(`^${regexParts.join("")}$`);
1989
+ inst._zod.parse = (payload, _ctx) => {
1990
+ if (typeof payload.value !== "string") {
1991
+ payload.issues.push({
1992
+ input: payload.value,
1993
+ inst,
1994
+ expected: "string",
1995
+ code: "invalid_type",
1996
+ });
1997
+ return payload;
1998
+ }
1999
+ inst._zod.pattern.lastIndex = 0;
2000
+ if (!inst._zod.pattern.test(payload.value)) {
2001
+ payload.issues.push({
2002
+ input: payload.value,
2003
+ inst,
2004
+ code: "invalid_format",
2005
+ format: def.format ?? "template_literal",
2006
+ pattern: inst._zod.pattern.source,
2007
+ });
2008
+ return payload;
2009
+ }
2010
+ return payload;
2011
+ };
2012
+ });
2013
+ exports.$ZodFunction = core.$constructor("$ZodFunction", (inst, def) => {
2014
+ exports.$ZodType.init(inst, def);
2015
+ inst._def = def;
2016
+ inst._zod.def = def;
2017
+ inst.implement = (func) => {
2018
+ if (typeof func !== "function") {
2019
+ throw new Error("implement() must be called with a function");
2020
+ }
2021
+ return function (...args) {
2022
+ const parsedArgs = inst._def.input ? (0, parse_js_1.parse)(inst._def.input, args) : args;
2023
+ const result = Reflect.apply(func, this, parsedArgs);
2024
+ if (inst._def.output) {
2025
+ return (0, parse_js_1.parse)(inst._def.output, result);
2026
+ }
2027
+ return result;
2028
+ };
2029
+ };
2030
+ inst.implementAsync = (func) => {
2031
+ if (typeof func !== "function") {
2032
+ throw new Error("implementAsync() must be called with a function");
2033
+ }
2034
+ return async function (...args) {
2035
+ const parsedArgs = inst._def.input ? await (0, parse_js_1.parseAsync)(inst._def.input, args) : args;
2036
+ const result = await Reflect.apply(func, this, parsedArgs);
2037
+ if (inst._def.output) {
2038
+ return await (0, parse_js_1.parseAsync)(inst._def.output, result);
2039
+ }
2040
+ return result;
2041
+ };
2042
+ };
2043
+ inst._zod.parse = (payload, _ctx) => {
2044
+ if (typeof payload.value !== "function") {
2045
+ payload.issues.push({
2046
+ code: "invalid_type",
2047
+ expected: "function",
2048
+ input: payload.value,
2049
+ inst,
2050
+ });
2051
+ return payload;
2052
+ }
2053
+ // Check if output is a promise type to determine if we should use async implementation
2054
+ const hasPromiseOutput = inst._def.output && inst._def.output._zod.def.type === "promise";
2055
+ if (hasPromiseOutput) {
2056
+ payload.value = inst.implementAsync(payload.value);
2057
+ }
2058
+ else {
2059
+ payload.value = inst.implement(payload.value);
2060
+ }
2061
+ return payload;
2062
+ };
2063
+ inst.input = (...args) => {
2064
+ const F = inst.constructor;
2065
+ if (Array.isArray(args[0])) {
2066
+ return new F({
2067
+ type: "function",
2068
+ input: new exports.$ZodTuple({
2069
+ type: "tuple",
2070
+ items: args[0],
2071
+ rest: args[1],
2072
+ }),
2073
+ output: inst._def.output,
2074
+ });
2075
+ }
2076
+ return new F({
2077
+ type: "function",
2078
+ input: args[0],
2079
+ output: inst._def.output,
2080
+ });
2081
+ };
2082
+ inst.output = (output) => {
2083
+ const F = inst.constructor;
2084
+ return new F({
2085
+ type: "function",
2086
+ input: inst._def.input,
2087
+ output,
2088
+ });
2089
+ };
2090
+ return inst;
2091
+ });
2092
+ exports.$ZodPromise = core.$constructor("$ZodPromise", (inst, def) => {
2093
+ exports.$ZodType.init(inst, def);
2094
+ inst._zod.parse = (payload, ctx) => {
2095
+ return Promise.resolve(payload.value).then((inner) => def.innerType._zod.run({ value: inner, issues: [] }, ctx));
2096
+ };
2097
+ });
2098
+ exports.$ZodLazy = core.$constructor("$ZodLazy", (inst, def) => {
2099
+ exports.$ZodType.init(inst, def);
2100
+ // let _innerType!: any;
2101
+ // util.defineLazy(def, "getter", () => {
2102
+ // if (!_innerType) {
2103
+ // _innerType = def.getter();
2104
+ // }
2105
+ // return () => _innerType;
2106
+ // });
2107
+ util.defineLazy(inst._zod, "innerType", () => def.getter());
2108
+ util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod?.pattern);
2109
+ util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod?.propValues);
2110
+ util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod?.optin ?? undefined);
2111
+ util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod?.optout ?? undefined);
2112
+ inst._zod.parse = (payload, ctx) => {
2113
+ const inner = inst._zod.innerType;
2114
+ return inner._zod.run(payload, ctx);
2115
+ };
2116
+ });
2117
+ exports.$ZodCustom = core.$constructor("$ZodCustom", (inst, def) => {
2118
+ checks.$ZodCheck.init(inst, def);
2119
+ exports.$ZodType.init(inst, def);
2120
+ inst._zod.parse = (payload, _) => {
2121
+ return payload;
2122
+ };
2123
+ inst._zod.check = (payload) => {
2124
+ const input = payload.value;
2125
+ const r = def.fn(input);
2126
+ if (r instanceof Promise) {
2127
+ return r.then((r) => handleRefineResult(r, payload, input, inst));
2128
+ }
2129
+ handleRefineResult(r, payload, input, inst);
2130
+ return;
2131
+ };
2132
+ });
2133
+ function handleRefineResult(result, payload, input, inst) {
2134
+ if (!result) {
2135
+ const _iss = {
2136
+ code: "custom",
2137
+ input,
2138
+ inst, // incorporates params.error into issue reporting
2139
+ path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
2140
+ continue: !inst._zod.def.abort,
2141
+ // params: inst._zod.def.params,
2142
+ };
2143
+ if (inst._zod.def.params)
2144
+ _iss.params = inst._zod.def.params;
2145
+ payload.issues.push(util.issue(_iss));
2146
+ }
2147
+ }