@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,4562 @@
1
+ import type { $ZodTypeDiscriminable } from "./api.js";
2
+ import * as checks from "./checks.js";
3
+ import * as core from "./core.js";
4
+ import { Doc } from "./doc.js";
5
+ import type * as errors from "./errors.js";
6
+ import type * as JSONSchema from "./json-schema.js";
7
+ import { parse, parseAsync, safeParse, safeParseAsync } from "./parse.js";
8
+ import * as regexes from "./regexes.js";
9
+ import type { StandardSchemaV1 } from "./standard-schema.js";
10
+ import type { ProcessParams, ToJSONSchemaContext } from "./to-json-schema.js";
11
+ import * as util from "./util.js";
12
+ import { version } from "./versions.js";
13
+
14
+ ///////////////////////////// PARSE //////////////////////////////
15
+
16
+ export interface ParseContext<T extends errors.$ZodIssueBase = never> {
17
+ /** Customize error messages. */
18
+ readonly error?: errors.$ZodErrorMap<T>;
19
+ /** Include the `input` field in issue objects. Default `false`. */
20
+ readonly reportInput?: boolean;
21
+ /** Skip eval-based fast path. Default `false`. */
22
+ readonly jitless?: boolean;
23
+ /** Abort validation after the first error. Default `false`. */
24
+ // readonly abortEarly?: boolean;
25
+ }
26
+
27
+ /** @internal */
28
+ export interface ParseContextInternal<T extends errors.$ZodIssueBase = never> extends ParseContext<T> {
29
+ readonly async?: boolean | undefined;
30
+ readonly direction?: "forward" | "backward";
31
+ readonly skipChecks?: boolean;
32
+ }
33
+
34
+ export interface ParsePayload<T = unknown> {
35
+ value: T;
36
+ issues: errors.$ZodRawIssue[];
37
+ /** A way to mark a whole payload as aborted. Used in codecs/pipes. */
38
+ aborted?: boolean;
39
+ }
40
+
41
+ export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>;
42
+
43
+ ///////////////////////////// SCHEMAS //////////////////////////////
44
+
45
+ export interface $ZodTypeDef {
46
+ type:
47
+ | "string"
48
+ | "number"
49
+ | "int"
50
+ | "boolean"
51
+ | "bigint"
52
+ | "symbol"
53
+ | "null"
54
+ | "undefined"
55
+ | "void" // merge with undefined?
56
+ | "never"
57
+ | "any"
58
+ | "unknown"
59
+ | "date"
60
+ | "object"
61
+ | "record"
62
+ | "file"
63
+ | "array"
64
+ | "tuple"
65
+ | "union"
66
+ | "intersection"
67
+ | "map"
68
+ | "set"
69
+ | "enum"
70
+ | "literal"
71
+ | "nullable"
72
+ | "optional"
73
+ | "nonoptional"
74
+ | "success"
75
+ | "transform"
76
+ | "default"
77
+ | "prefault"
78
+ | "catch"
79
+ | "nan"
80
+ | "pipe"
81
+ | "readonly"
82
+ | "template_literal"
83
+ | "promise"
84
+ | "lazy"
85
+ | "function"
86
+ | "custom";
87
+ error?: errors.$ZodErrorMap<never> | undefined;
88
+ checks?: checks.$ZodCheck<never>[];
89
+ }
90
+
91
+ export interface _$ZodTypeInternals {
92
+ /** The `@zod/core` version of this schema */
93
+ version: typeof version;
94
+
95
+ /** Schema definition. */
96
+ def: $ZodTypeDef;
97
+ // types: Types;
98
+
99
+ /** @internal Randomly generated ID for this schema. */
100
+ // id: string;
101
+
102
+ /** @internal List of deferred initializers. */
103
+ deferred: util.AnyFunc[] | undefined;
104
+
105
+ /** @internal Parses input and runs all checks (refinements). */
106
+ run(payload: ParsePayload<any>, ctx: ParseContextInternal): util.MaybeAsync<ParsePayload>;
107
+
108
+ /** @internal Parses input, doesn't run checks. */
109
+ parse(payload: ParsePayload<any>, ctx: ParseContextInternal): util.MaybeAsync<ParsePayload>;
110
+
111
+ /** @internal Stores identifiers for the set of traits implemented by this schema. */
112
+ traits: Set<string>;
113
+
114
+ /** @internal Indicates that a schema output type should be considered optional inside objects.
115
+ * @default Required
116
+ */
117
+
118
+ /** @internal */
119
+ optin?: "optional" | undefined;
120
+ /** @internal */
121
+ optout?: "optional" | undefined;
122
+
123
+ /** @internal The set of literal values that will pass validation. Must be an exhaustive set. Used to determine optionality in z.record().
124
+ *
125
+ * Defined on: enum, const, literal, null, undefined
126
+ * Passthrough: optional, nullable, branded, default, catch, pipe
127
+ * Todo: unions?
128
+ */
129
+ values?: util.PrimitiveSet | undefined;
130
+
131
+ /** Default value bubbled up from */
132
+ // default?: unknown | undefined;
133
+
134
+ /** @internal A set of literal discriminators used for the fast path in discriminated unions. */
135
+ propValues?: util.PropValues | undefined;
136
+
137
+ /** @internal This flag indicates that a schema validation can be represented with a regular expression. Used to determine allowable schemas in z.templateLiteral(). */
138
+ pattern: RegExp | undefined;
139
+
140
+ /** @internal The constructor function of this schema. */
141
+ constr: new (
142
+ def: any
143
+ ) => $ZodType;
144
+
145
+ /** @internal A catchall object for bag metadata related to this schema. Commonly modified by checks using `onattach`. */
146
+ bag: Record<string, unknown>;
147
+
148
+ /** @internal The set of issues this schema might throw during type checking. */
149
+ isst: errors.$ZodIssueBase;
150
+
151
+ /** @internal Subject to change, not a public API. */
152
+ processJSONSchema?:
153
+ | ((ctx: ToJSONSchemaContext, json: JSONSchema.BaseSchema, params: ProcessParams) => void)
154
+ | undefined;
155
+
156
+ /** An optional method used to override `toJSONSchema` logic. */
157
+ toJSONSchema?: () => unknown;
158
+
159
+ /** @internal The parent of this schema. Only set during certain clone operations. */
160
+ parent?: $ZodType | undefined;
161
+ }
162
+ /** @internal */
163
+ export interface $ZodTypeInternals<out O = unknown, out I = unknown> extends _$ZodTypeInternals {
164
+ /** @internal The inferred output type */
165
+ output: O; //extends { $out: infer O } ? O : Out;
166
+ /** @internal The inferred input type */
167
+ input: I; //extends { $in: infer I } ? I : In;
168
+ }
169
+
170
+ export type $ZodStandardSchema<T> = StandardSchemaV1.Props<core.input<T>, core.output<T>>;
171
+
172
+ export type SomeType = { _zod: _$ZodTypeInternals };
173
+
174
+ export interface $ZodType<
175
+ O = unknown,
176
+ I = unknown,
177
+ Internals extends $ZodTypeInternals<O, I> = $ZodTypeInternals<O, I>,
178
+ > {
179
+ _zod: Internals;
180
+ "~standard": $ZodStandardSchema<this>;
181
+ }
182
+ export interface _$ZodType<T extends $ZodTypeInternals = $ZodTypeInternals>
183
+ extends $ZodType<T["output"], T["input"], T> {}
184
+
185
+ let __parseAdapterFn: any;
186
+ export function setParseAdapter(parseAdapterFn: any) {
187
+ __parseAdapterFn = parseAdapterFn;
188
+ }
189
+
190
+ export const $ZodType: core.$constructor<$ZodType> = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def) => {
191
+ inst ??= {} as any;
192
+
193
+ inst._zod.def = def; // set _def property
194
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
195
+ inst._zod.version = version;
196
+
197
+ const checks = [...(inst._zod.def.checks ?? [])];
198
+
199
+ // if inst is itself a checks.$ZodCheck, run it as a check
200
+ if (inst._zod.traits.has("$ZodCheck")) {
201
+ checks.unshift(inst as any);
202
+ }
203
+
204
+ for (const ch of checks) {
205
+ for (const fn of ch._zod.onattach) {
206
+ fn(inst);
207
+ }
208
+ }
209
+
210
+ if (checks.length === 0) {
211
+ // deferred initializer
212
+ // inst._zod.parse is not yet defined
213
+ inst._zod.deferred ??= [];
214
+ inst._zod.deferred?.push(() => {
215
+ inst._zod.run = __parseAdapterFn ? __parseAdapterFn(inst, inst._zod.parse) : inst._zod.parse;
216
+ });
217
+ } else {
218
+ const runChecks = (
219
+ payload: ParsePayload,
220
+ checks: checks.$ZodCheck<never>[],
221
+ ctx?: ParseContextInternal | undefined
222
+ ): util.MaybeAsync<ParsePayload> => {
223
+ let isAborted = util.aborted(payload);
224
+
225
+ let asyncResult!: Promise<unknown> | undefined;
226
+ for (const ch of checks) {
227
+ if (ch._zod.def.when) {
228
+ if (util.explicitlyAborted(payload)) continue;
229
+ const shouldRun = ch._zod.def.when(payload);
230
+ if (!shouldRun) continue;
231
+ } else if (isAborted) {
232
+ continue;
233
+ }
234
+ const currLen = payload.issues.length;
235
+ const _ = ch._zod.check(payload as any) as any as ParsePayload;
236
+
237
+ if (_ instanceof Promise && ctx?.async === false) {
238
+ throw new core.$ZodAsyncError();
239
+ }
240
+ if (asyncResult || _ instanceof Promise) {
241
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
242
+ await _;
243
+ const nextLen = payload.issues.length;
244
+ if (nextLen === currLen) return;
245
+ if (!isAborted) isAborted = util.aborted(payload, currLen);
246
+ });
247
+ } else {
248
+ const nextLen = payload.issues.length;
249
+ if (nextLen === currLen) continue;
250
+ if (!isAborted) isAborted = util.aborted(payload, currLen);
251
+ }
252
+ }
253
+
254
+ if (asyncResult) {
255
+ return asyncResult.then(() => {
256
+ return payload;
257
+ });
258
+ }
259
+ return payload;
260
+ };
261
+
262
+ const handleCanaryResult = (canary: ParsePayload, payload: ParsePayload, ctx: ParseContextInternal) => {
263
+ // abort if the canary is aborted
264
+ if (util.aborted(canary)) {
265
+ canary.aborted = true;
266
+ return canary;
267
+ }
268
+
269
+ // run checks first, then
270
+ const checkResult = runChecks(payload, checks, ctx);
271
+ if (checkResult instanceof Promise) {
272
+ if (ctx.async === false) throw new core.$ZodAsyncError();
273
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
274
+ }
275
+ return inst._zod.parse(checkResult, ctx);
276
+ };
277
+
278
+ const __run = (payload: ParsePayload, ctx: ParseContextInternal) => {
279
+ if (ctx.skipChecks) {
280
+ return inst._zod.parse(payload, ctx);
281
+ }
282
+ if (ctx.direction === "backward") {
283
+ // run canary
284
+ // initial pass (no checks)
285
+ const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
286
+
287
+ if (canary instanceof Promise) {
288
+ return canary.then((canary) => {
289
+ return handleCanaryResult(canary, payload, ctx);
290
+ });
291
+ }
292
+
293
+ return handleCanaryResult(canary, payload, ctx);
294
+ }
295
+
296
+ // forward
297
+ const result = inst._zod.parse(payload, ctx);
298
+ if (result instanceof Promise) {
299
+ if (ctx.async === false) throw new core.$ZodAsyncError();
300
+ return result.then((result) => runChecks(result, checks, ctx));
301
+ }
302
+
303
+ return runChecks(result, checks, ctx);
304
+ };
305
+ inst._zod.run = __parseAdapterFn ? __parseAdapterFn(inst, __run) : __run;
306
+ }
307
+
308
+ // Lazy initialize ~standard to avoid creating objects for every schema
309
+ util.defineLazy(inst, "~standard", () => ({
310
+ validate: (value: unknown) => {
311
+ try {
312
+ const r = safeParse(inst, value);
313
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
314
+ } catch (_) {
315
+ return safeParseAsync(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
316
+ }
317
+ },
318
+ vendor: "zod",
319
+ version: 1 as const,
320
+ }));
321
+ });
322
+
323
+ export { clone } from "./util.js";
324
+
325
+ //////////////////////////////////////////
326
+ //////////////////////////////////////////
327
+ ////////// //////////
328
+ ////////// $ZodString //////////
329
+ ////////// //////////
330
+ //////////////////////////////////////////
331
+ //////////////////////////////////////////
332
+ export interface $ZodStringDef extends $ZodTypeDef {
333
+ type: "string";
334
+ coerce?: boolean;
335
+ checks?: checks.$ZodCheck<string>[];
336
+ }
337
+
338
+ export interface $ZodStringInternals<Input> extends $ZodTypeInternals<string, Input> {
339
+ def: $ZodStringDef;
340
+ /** @deprecated Internal API, use with caution (not deprecated) */
341
+ pattern: RegExp;
342
+
343
+ /** @deprecated Internal API, use with caution (not deprecated) */
344
+ isst: errors.$ZodIssueInvalidType;
345
+ bag: util.LoosePartial<{
346
+ minimum: number;
347
+ maximum: number;
348
+ patterns: Set<RegExp>;
349
+ format: string;
350
+ contentEncoding: string;
351
+ }>;
352
+ }
353
+
354
+ export interface $ZodString<Input = unknown> extends _$ZodType<$ZodStringInternals<Input>> {
355
+ // _zod: $ZodStringInternals<Input>;
356
+ }
357
+
358
+ export const $ZodString: core.$constructor<$ZodString> = /*@__PURE__*/ core.$constructor("$ZodString", (inst, def) => {
359
+ $ZodType.init(inst, def);
360
+ inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? regexes.string(inst._zod.bag);
361
+ inst._zod.parse = (payload, _) => {
362
+ if (def.coerce)
363
+ try {
364
+ payload.value = String(payload.value);
365
+ } catch (_) {}
366
+
367
+ if (typeof payload.value === "string") return payload;
368
+
369
+ payload.issues.push({
370
+ expected: "string",
371
+ code: "invalid_type",
372
+
373
+ input: payload.value,
374
+ inst,
375
+ });
376
+ return payload;
377
+ };
378
+ });
379
+
380
+ ////////////////////////////// ZodStringFormat //////////////////////////////
381
+
382
+ export interface $ZodStringFormatDef<Format extends string = string>
383
+ extends $ZodStringDef,
384
+ checks.$ZodCheckStringFormatDef<Format> {}
385
+
386
+ export interface $ZodStringFormatInternals<Format extends string = string>
387
+ extends $ZodStringInternals<string>,
388
+ checks.$ZodCheckStringFormatInternals {
389
+ def: $ZodStringFormatDef<Format>;
390
+ }
391
+ export interface $ZodStringFormat<Format extends string = string> extends $ZodType {
392
+ _zod: $ZodStringFormatInternals<Format>;
393
+ }
394
+
395
+ export const $ZodStringFormat: core.$constructor<$ZodStringFormat> = /*@__PURE__*/ core.$constructor(
396
+ "$ZodStringFormat",
397
+ (inst, def): void => {
398
+ // check initialization must come first
399
+ checks.$ZodCheckStringFormat.init(inst, def);
400
+ $ZodString.init(inst, def);
401
+ }
402
+ );
403
+
404
+ ////////////////////////////// ZodGUID //////////////////////////////
405
+ export interface $ZodGUIDDef extends $ZodStringFormatDef<"guid"> {}
406
+ export interface $ZodGUIDInternals extends $ZodStringFormatInternals<"guid"> {}
407
+
408
+ export interface $ZodGUID extends $ZodType {
409
+ _zod: $ZodGUIDInternals;
410
+ }
411
+
412
+ export const $ZodGUID: core.$constructor<$ZodGUID> = /*@__PURE__*/ core.$constructor("$ZodGUID", (inst, def): void => {
413
+ def.pattern ??= regexes.guid;
414
+ $ZodStringFormat.init(inst, def);
415
+ });
416
+
417
+ ////////////////////////////// ZodUUID //////////////////////////////
418
+
419
+ export interface $ZodUUIDDef extends $ZodStringFormatDef<"uuid"> {
420
+ version?: "v1" | "v2" | "v3" | "v4" | "v5" | "v6" | "v7" | "v8";
421
+ }
422
+
423
+ export interface $ZodUUIDInternals extends $ZodStringFormatInternals<"uuid"> {
424
+ def: $ZodUUIDDef;
425
+ }
426
+
427
+ export interface $ZodUUID extends $ZodType {
428
+ _zod: $ZodUUIDInternals;
429
+ }
430
+
431
+ export const $ZodUUID: core.$constructor<$ZodUUID> = /*@__PURE__*/ core.$constructor("$ZodUUID", (inst, def): void => {
432
+ if (def.version) {
433
+ const versionMap: Record<string, number> = {
434
+ v1: 1,
435
+ v2: 2,
436
+ v3: 3,
437
+ v4: 4,
438
+ v5: 5,
439
+ v6: 6,
440
+ v7: 7,
441
+ v8: 8,
442
+ };
443
+ const v = versionMap[def.version];
444
+ if (v === undefined) throw new Error(`Invalid UUID version: "${def.version}"`);
445
+ def.pattern ??= regexes.uuid(v);
446
+ } else def.pattern ??= regexes.uuid();
447
+ $ZodStringFormat.init(inst, def);
448
+ });
449
+
450
+ ////////////////////////////// ZodEmail //////////////////////////////
451
+
452
+ export interface $ZodEmailDef extends $ZodStringFormatDef<"email"> {}
453
+ export interface $ZodEmailInternals extends $ZodStringFormatInternals<"email"> {}
454
+ export interface $ZodEmail extends $ZodType {
455
+ _zod: $ZodEmailInternals;
456
+ }
457
+
458
+ export const $ZodEmail: core.$constructor<$ZodEmail> = /*@__PURE__*/ core.$constructor(
459
+ "$ZodEmail",
460
+ (inst, def): void => {
461
+ def.pattern ??= regexes.email;
462
+ $ZodStringFormat.init(inst, def);
463
+ }
464
+ );
465
+
466
+ ////////////////////////////// ZodURL //////////////////////////////
467
+
468
+ export interface $ZodURLDef extends $ZodStringFormatDef<"url"> {
469
+ hostname?: RegExp | undefined;
470
+ protocol?: RegExp | undefined;
471
+ normalize?: boolean | undefined;
472
+ }
473
+ export interface $ZodURLInternals extends $ZodStringFormatInternals<"url"> {
474
+ def: $ZodURLDef;
475
+ }
476
+
477
+ export interface $ZodURL extends $ZodType {
478
+ _zod: $ZodURLInternals;
479
+ }
480
+
481
+ export const $ZodURL: core.$constructor<$ZodURL> = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) => {
482
+ $ZodStringFormat.init(inst, def);
483
+ inst._zod.check = (payload) => {
484
+ try {
485
+ // Trim whitespace from input
486
+ const trimmed = payload.value.trim();
487
+
488
+ // When normalize is off, require :// for http/https URLs
489
+ // This prevents strings like "http:example.com" or "https:/path" from being silently accepted
490
+ if (!def.normalize && def.protocol?.source === regexes.httpProtocol.source) {
491
+ if (!/^https?:\/\//i.test(trimmed)) {
492
+ payload.issues.push({
493
+ code: "invalid_format",
494
+ format: "url",
495
+ note: "Invalid URL format",
496
+ input: payload.value,
497
+ inst,
498
+ continue: !def.abort,
499
+ });
500
+ return;
501
+ }
502
+ }
503
+
504
+ // @ts-ignore
505
+ const url = new URL(trimmed);
506
+
507
+ if (def.hostname) {
508
+ def.hostname.lastIndex = 0;
509
+ if (!def.hostname.test(url.hostname)) {
510
+ payload.issues.push({
511
+ code: "invalid_format",
512
+ format: "url",
513
+ note: "Invalid hostname",
514
+ pattern: def.hostname.source,
515
+ input: payload.value,
516
+ inst,
517
+ continue: !def.abort,
518
+ });
519
+ }
520
+ }
521
+
522
+ if (def.protocol) {
523
+ def.protocol.lastIndex = 0;
524
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
525
+ payload.issues.push({
526
+ code: "invalid_format",
527
+ format: "url",
528
+ note: "Invalid protocol",
529
+ pattern: def.protocol.source,
530
+ input: payload.value,
531
+ inst,
532
+ continue: !def.abort,
533
+ });
534
+ }
535
+ }
536
+
537
+ // Set the output value based on normalize flag
538
+ if (def.normalize) {
539
+ // Use normalized URL
540
+ payload.value = url.href;
541
+ } else {
542
+ // Preserve the original input (trimmed)
543
+ payload.value = trimmed;
544
+ }
545
+
546
+ return;
547
+ } catch (_) {
548
+ payload.issues.push({
549
+ code: "invalid_format",
550
+ format: "url",
551
+ input: payload.value,
552
+ inst,
553
+ continue: !def.abort,
554
+ });
555
+ }
556
+ };
557
+ });
558
+
559
+ ////////////////////////////// ZodEmoji //////////////////////////////
560
+
561
+ export interface $ZodEmojiDef extends $ZodStringFormatDef<"emoji"> {}
562
+ export interface $ZodEmojiInternals extends $ZodStringFormatInternals<"emoji"> {}
563
+
564
+ export interface $ZodEmoji extends $ZodType {
565
+ _zod: $ZodEmojiInternals;
566
+ }
567
+
568
+ export const $ZodEmoji: core.$constructor<$ZodEmoji> = /*@__PURE__*/ core.$constructor(
569
+ "$ZodEmoji",
570
+ (inst, def): void => {
571
+ def.pattern ??= regexes.emoji();
572
+ $ZodStringFormat.init(inst, def);
573
+ }
574
+ );
575
+
576
+ ////////////////////////////// ZodNanoID //////////////////////////////
577
+
578
+ export interface $ZodNanoIDDef extends $ZodStringFormatDef<"nanoid"> {}
579
+ export interface $ZodNanoIDInternals extends $ZodStringFormatInternals<"nanoid"> {}
580
+
581
+ export interface $ZodNanoID extends $ZodType {
582
+ _zod: $ZodNanoIDInternals;
583
+ }
584
+
585
+ export const $ZodNanoID: core.$constructor<$ZodNanoID> = /*@__PURE__*/ core.$constructor(
586
+ "$ZodNanoID",
587
+ (inst, def): void => {
588
+ def.pattern ??= regexes.nanoid;
589
+ $ZodStringFormat.init(inst, def);
590
+ }
591
+ );
592
+
593
+ ////////////////////////////// ZodCUID //////////////////////////////
594
+
595
+ export interface $ZodCUIDDef extends $ZodStringFormatDef<"cuid"> {}
596
+ export interface $ZodCUIDInternals extends $ZodStringFormatInternals<"cuid"> {}
597
+
598
+ export interface $ZodCUID extends $ZodType {
599
+ _zod: $ZodCUIDInternals;
600
+ }
601
+
602
+ export const $ZodCUID: core.$constructor<$ZodCUID> = /*@__PURE__*/ core.$constructor("$ZodCUID", (inst, def): void => {
603
+ def.pattern ??= regexes.cuid;
604
+ $ZodStringFormat.init(inst, def);
605
+ });
606
+
607
+ ////////////////////////////// ZodCUID2 //////////////////////////////
608
+
609
+ export interface $ZodCUID2Def extends $ZodStringFormatDef<"cuid2"> {}
610
+ export interface $ZodCUID2Internals extends $ZodStringFormatInternals<"cuid2"> {}
611
+
612
+ export interface $ZodCUID2 extends $ZodType {
613
+ _zod: $ZodCUID2Internals;
614
+ }
615
+
616
+ export const $ZodCUID2: core.$constructor<$ZodCUID2> = /*@__PURE__*/ core.$constructor(
617
+ "$ZodCUID2",
618
+ (inst, def): void => {
619
+ def.pattern ??= regexes.cuid2;
620
+ $ZodStringFormat.init(inst, def);
621
+ }
622
+ );
623
+
624
+ ////////////////////////////// ZodULID //////////////////////////////
625
+
626
+ export interface $ZodULIDDef extends $ZodStringFormatDef<"ulid"> {}
627
+ export interface $ZodULIDInternals extends $ZodStringFormatInternals<"ulid"> {}
628
+
629
+ export interface $ZodULID extends $ZodType {
630
+ _zod: $ZodULIDInternals;
631
+ }
632
+
633
+ export const $ZodULID: core.$constructor<$ZodULID> = /*@__PURE__*/ core.$constructor("$ZodULID", (inst, def): void => {
634
+ def.pattern ??= regexes.ulid;
635
+ $ZodStringFormat.init(inst, def);
636
+ });
637
+
638
+ ////////////////////////////// ZodXID //////////////////////////////
639
+
640
+ export interface $ZodXIDDef extends $ZodStringFormatDef<"xid"> {}
641
+ export interface $ZodXIDInternals extends $ZodStringFormatInternals<"xid"> {}
642
+
643
+ export interface $ZodXID extends $ZodType {
644
+ _zod: $ZodXIDInternals;
645
+ }
646
+
647
+ export const $ZodXID: core.$constructor<$ZodXID> = /*@__PURE__*/ core.$constructor("$ZodXID", (inst, def): void => {
648
+ def.pattern ??= regexes.xid;
649
+ $ZodStringFormat.init(inst, def);
650
+ });
651
+
652
+ ////////////////////////////// ZodKSUID //////////////////////////////
653
+
654
+ export interface $ZodKSUIDDef extends $ZodStringFormatDef<"ksuid"> {}
655
+ export interface $ZodKSUIDInternals extends $ZodStringFormatInternals<"ksuid"> {}
656
+
657
+ export interface $ZodKSUID extends $ZodType {
658
+ _zod: $ZodKSUIDInternals;
659
+ }
660
+
661
+ export const $ZodKSUID: core.$constructor<$ZodKSUID> = /*@__PURE__*/ core.$constructor(
662
+ "$ZodKSUID",
663
+ (inst, def): void => {
664
+ def.pattern ??= regexes.ksuid;
665
+ $ZodStringFormat.init(inst, def);
666
+ }
667
+ );
668
+
669
+ ////////////////////////////// ZodISODateTime //////////////////////////////
670
+
671
+ export interface $ZodISODateTimeDef extends $ZodStringFormatDef<"datetime"> {
672
+ precision: number | null;
673
+ offset: boolean;
674
+ local: boolean;
675
+ }
676
+
677
+ export interface $ZodISODateTimeInternals extends $ZodStringFormatInternals {
678
+ def: $ZodISODateTimeDef;
679
+ }
680
+
681
+ export interface $ZodISODateTime extends $ZodType {
682
+ _zod: $ZodISODateTimeInternals;
683
+ }
684
+
685
+ export const $ZodISODateTime: core.$constructor<$ZodISODateTime> = /*@__PURE__*/ core.$constructor(
686
+ "$ZodISODateTime",
687
+ (inst, def): void => {
688
+ def.pattern ??= regexes.datetime(def);
689
+ $ZodStringFormat.init(inst, def);
690
+ }
691
+ );
692
+
693
+ ////////////////////////////// ZodISODate //////////////////////////////
694
+
695
+ export interface $ZodISODateDef extends $ZodStringFormatDef<"date"> {}
696
+ export interface $ZodISODateInternals extends $ZodStringFormatInternals<"date"> {}
697
+
698
+ export interface $ZodISODate extends $ZodType {
699
+ _zod: $ZodISODateInternals;
700
+ }
701
+
702
+ export const $ZodISODate: core.$constructor<$ZodISODate> = /*@__PURE__*/ core.$constructor(
703
+ "$ZodISODate",
704
+ (inst, def): void => {
705
+ def.pattern ??= regexes.date;
706
+ $ZodStringFormat.init(inst, def);
707
+ }
708
+ );
709
+
710
+ ////////////////////////////// ZodISOTime //////////////////////////////
711
+
712
+ export interface $ZodISOTimeDef extends $ZodStringFormatDef<"time"> {
713
+ precision?: number | null;
714
+ }
715
+
716
+ export interface $ZodISOTimeInternals extends $ZodStringFormatInternals<"time"> {
717
+ def: $ZodISOTimeDef;
718
+ }
719
+
720
+ export interface $ZodISOTime extends $ZodType {
721
+ _zod: $ZodISOTimeInternals;
722
+ }
723
+
724
+ export const $ZodISOTime: core.$constructor<$ZodISOTime> = /*@__PURE__*/ core.$constructor(
725
+ "$ZodISOTime",
726
+ (inst, def): void => {
727
+ def.pattern ??= regexes.time(def);
728
+ $ZodStringFormat.init(inst, def);
729
+ }
730
+ );
731
+
732
+ ////////////////////////////// ZodISODuration //////////////////////////////
733
+
734
+ export interface $ZodISODurationDef extends $ZodStringFormatDef<"duration"> {}
735
+ export interface $ZodISODurationInternals extends $ZodStringFormatInternals<"duration"> {}
736
+
737
+ export interface $ZodISODuration extends $ZodType {
738
+ _zod: $ZodISODurationInternals;
739
+ }
740
+
741
+ export const $ZodISODuration: core.$constructor<$ZodISODuration> = /*@__PURE__*/ core.$constructor(
742
+ "$ZodISODuration",
743
+ (inst, def): void => {
744
+ def.pattern ??= regexes.duration;
745
+ $ZodStringFormat.init(inst, def);
746
+ }
747
+ );
748
+
749
+ ////////////////////////////// ZodIPv4 //////////////////////////////
750
+
751
+ export interface $ZodIPv4Def extends $ZodStringFormatDef<"ipv4"> {
752
+ version?: "v4";
753
+ }
754
+
755
+ export interface $ZodIPv4Internals extends $ZodStringFormatInternals<"ipv4"> {
756
+ def: $ZodIPv4Def;
757
+ }
758
+
759
+ export interface $ZodIPv4 extends $ZodType {
760
+ _zod: $ZodIPv4Internals;
761
+ }
762
+
763
+ export const $ZodIPv4: core.$constructor<$ZodIPv4> = /*@__PURE__*/ core.$constructor("$ZodIPv4", (inst, def): void => {
764
+ def.pattern ??= regexes.ipv4;
765
+ $ZodStringFormat.init(inst, def);
766
+
767
+ inst._zod.bag.format = `ipv4`;
768
+ });
769
+
770
+ ////////////////////////////// ZodIPv6 //////////////////////////////
771
+
772
+ export interface $ZodIPv6Def extends $ZodStringFormatDef<"ipv6"> {
773
+ version?: "v6";
774
+ }
775
+
776
+ export interface $ZodIPv6Internals extends $ZodStringFormatInternals<"ipv6"> {
777
+ def: $ZodIPv6Def;
778
+ }
779
+
780
+ export interface $ZodIPv6 extends $ZodType {
781
+ _zod: $ZodIPv6Internals;
782
+ }
783
+
784
+ export const $ZodIPv6: core.$constructor<$ZodIPv6> = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def): void => {
785
+ def.pattern ??= regexes.ipv6;
786
+ $ZodStringFormat.init(inst, def);
787
+
788
+ inst._zod.bag.format = `ipv6`;
789
+
790
+ inst._zod.check = (payload) => {
791
+ try {
792
+ // @ts-ignore
793
+ new URL(`http://[${payload.value}]`);
794
+ // return;
795
+ } catch {
796
+ payload.issues.push({
797
+ code: "invalid_format",
798
+ format: "ipv6",
799
+ input: payload.value,
800
+ inst,
801
+ continue: !def.abort,
802
+ });
803
+ }
804
+ };
805
+ });
806
+
807
+ ////////////////////////////// ZodMAC //////////////////////////////
808
+ export interface $ZodMACDef extends $ZodStringFormatDef<"mac"> {
809
+ delimiter?: string;
810
+ }
811
+
812
+ export interface $ZodMACInternals extends $ZodStringFormatInternals<"mac"> {
813
+ def: $ZodMACDef;
814
+ }
815
+
816
+ export interface $ZodMAC extends $ZodType {
817
+ _zod: $ZodMACInternals;
818
+ }
819
+
820
+ export const $ZodMAC: core.$constructor<$ZodMAC> = /*@__PURE__*/ core.$constructor("$ZodMAC", (inst, def): void => {
821
+ def.pattern ??= regexes.mac(def.delimiter);
822
+ $ZodStringFormat.init(inst, def);
823
+
824
+ inst._zod.bag.format = `mac`;
825
+ });
826
+
827
+ ////////////////////////////// ZodCIDRv4 //////////////////////////////
828
+
829
+ export interface $ZodCIDRv4Def extends $ZodStringFormatDef<"cidrv4"> {
830
+ version?: "v4";
831
+ }
832
+
833
+ export interface $ZodCIDRv4Internals extends $ZodStringFormatInternals<"cidrv4"> {
834
+ def: $ZodCIDRv4Def;
835
+ }
836
+
837
+ export interface $ZodCIDRv4 extends $ZodType {
838
+ _zod: $ZodCIDRv4Internals;
839
+ }
840
+
841
+ export const $ZodCIDRv4: core.$constructor<$ZodCIDRv4> = /*@__PURE__*/ core.$constructor(
842
+ "$ZodCIDRv4",
843
+ (inst, def): void => {
844
+ def.pattern ??= regexes.cidrv4;
845
+ $ZodStringFormat.init(inst, def);
846
+ }
847
+ );
848
+
849
+ ////////////////////////////// ZodCIDRv6 //////////////////////////////
850
+
851
+ export interface $ZodCIDRv6Def extends $ZodStringFormatDef<"cidrv6"> {
852
+ version?: "v6";
853
+ }
854
+
855
+ export interface $ZodCIDRv6Internals extends $ZodStringFormatInternals<"cidrv6"> {
856
+ def: $ZodCIDRv6Def;
857
+ }
858
+
859
+ export interface $ZodCIDRv6 extends $ZodType {
860
+ _zod: $ZodCIDRv6Internals;
861
+ }
862
+
863
+ export const $ZodCIDRv6: core.$constructor<$ZodCIDRv6> = /*@__PURE__*/ core.$constructor(
864
+ "$ZodCIDRv6",
865
+ (inst, def): void => {
866
+ def.pattern ??= regexes.cidrv6; // not used for validation
867
+ $ZodStringFormat.init(inst, def);
868
+
869
+ inst._zod.check = (payload) => {
870
+ const parts = payload.value.split("/");
871
+ try {
872
+ if (parts.length !== 2) throw new Error();
873
+ const [address, prefix] = parts;
874
+ if (!prefix) throw new Error();
875
+ const prefixNum = Number(prefix);
876
+ if (`${prefixNum}` !== prefix) throw new Error();
877
+ if (prefixNum < 0 || prefixNum > 128) throw new Error();
878
+ // @ts-ignore
879
+ new URL(`http://[${address}]`);
880
+ } catch {
881
+ payload.issues.push({
882
+ code: "invalid_format",
883
+ format: "cidrv6",
884
+ input: payload.value,
885
+ inst,
886
+ continue: !def.abort,
887
+ });
888
+ }
889
+ };
890
+ }
891
+ );
892
+
893
+ ////////////////////////////// ZodBase64 //////////////////////////////
894
+ export function isValidBase64(data: string): boolean {
895
+ if (data === "") return true;
896
+ if (data.length % 4 !== 0) return false;
897
+ try {
898
+ // @ts-ignore
899
+ atob(data);
900
+ return true;
901
+ } catch {
902
+ return false;
903
+ }
904
+ }
905
+
906
+ export interface $ZodBase64Def extends $ZodStringFormatDef<"base64"> {}
907
+ export interface $ZodBase64Internals extends $ZodStringFormatInternals<"base64"> {}
908
+
909
+ export interface $ZodBase64 extends $ZodType {
910
+ _zod: $ZodBase64Internals;
911
+ }
912
+
913
+ export const $ZodBase64: core.$constructor<$ZodBase64> = /*@__PURE__*/ core.$constructor(
914
+ "$ZodBase64",
915
+ (inst, def): void => {
916
+ def.pattern ??= regexes.base64;
917
+ $ZodStringFormat.init(inst, def);
918
+
919
+ inst._zod.bag.contentEncoding = "base64";
920
+
921
+ inst._zod.check = (payload) => {
922
+ if (isValidBase64(payload.value)) return;
923
+
924
+ payload.issues.push({
925
+ code: "invalid_format",
926
+ format: "base64",
927
+ input: payload.value,
928
+ inst,
929
+ continue: !def.abort,
930
+ });
931
+ };
932
+ }
933
+ );
934
+
935
+ ////////////////////////////// ZodBase64 //////////////////////////////
936
+ export function isValidBase64URL(data: string): boolean {
937
+ if (!regexes.base64url.test(data)) return false;
938
+ const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
939
+ const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
940
+ return isValidBase64(padded);
941
+ }
942
+
943
+ export interface $ZodBase64URLDef extends $ZodStringFormatDef<"base64url"> {}
944
+ export interface $ZodBase64URLInternals extends $ZodStringFormatInternals<"base64url"> {}
945
+
946
+ export interface $ZodBase64URL extends $ZodType {
947
+ _zod: $ZodBase64URLInternals;
948
+ }
949
+
950
+ export const $ZodBase64URL: core.$constructor<$ZodBase64URL> = /*@__PURE__*/ core.$constructor(
951
+ "$ZodBase64URL",
952
+ (inst, def): void => {
953
+ def.pattern ??= regexes.base64url;
954
+ $ZodStringFormat.init(inst, def);
955
+
956
+ inst._zod.bag.contentEncoding = "base64url";
957
+
958
+ inst._zod.check = (payload) => {
959
+ if (isValidBase64URL(payload.value)) return;
960
+
961
+ payload.issues.push({
962
+ code: "invalid_format",
963
+ format: "base64url",
964
+ input: payload.value,
965
+ inst,
966
+ continue: !def.abort,
967
+ });
968
+ };
969
+ }
970
+ );
971
+
972
+ ////////////////////////////// ZodE164 //////////////////////////////
973
+
974
+ export interface $ZodE164Def extends $ZodStringFormatDef<"e164"> {}
975
+ export interface $ZodE164Internals extends $ZodStringFormatInternals<"e164"> {}
976
+
977
+ export interface $ZodE164 extends $ZodType {
978
+ _zod: $ZodE164Internals;
979
+ }
980
+
981
+ export const $ZodE164: core.$constructor<$ZodE164> = /*@__PURE__*/ core.$constructor("$ZodE164", (inst, def): void => {
982
+ def.pattern ??= regexes.e164;
983
+ $ZodStringFormat.init(inst, def);
984
+ });
985
+
986
+ ////////////////////////////// ZodJWT //////////////////////////////
987
+
988
+ export function isValidJWT(token: string, algorithm: util.JWTAlgorithm | null = null): boolean {
989
+ try {
990
+ const tokensParts = token.split(".");
991
+ if (tokensParts.length !== 3) return false;
992
+ const [header] = tokensParts;
993
+ if (!header) return false;
994
+ // @ts-ignore
995
+ const parsedHeader = JSON.parse(atob(header));
996
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
997
+ if (!parsedHeader.alg) return false;
998
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
999
+ return true;
1000
+ } catch {
1001
+ return false;
1002
+ }
1003
+ }
1004
+
1005
+ export interface $ZodJWTDef extends $ZodStringFormatDef<"jwt"> {
1006
+ alg?: util.JWTAlgorithm | undefined;
1007
+ }
1008
+
1009
+ export interface $ZodJWTInternals extends $ZodStringFormatInternals<"jwt"> {
1010
+ def: $ZodJWTDef;
1011
+ }
1012
+
1013
+ export interface $ZodJWT extends $ZodType {
1014
+ _zod: $ZodJWTInternals;
1015
+ }
1016
+
1017
+ export const $ZodJWT: core.$constructor<$ZodJWT> = /*@__PURE__*/ core.$constructor("$ZodJWT", (inst, def): void => {
1018
+ $ZodStringFormat.init(inst, def);
1019
+ inst._zod.check = (payload) => {
1020
+ if (isValidJWT(payload.value, def.alg)) return;
1021
+
1022
+ payload.issues.push({
1023
+ code: "invalid_format",
1024
+ format: "jwt",
1025
+ input: payload.value,
1026
+ inst,
1027
+ continue: !def.abort,
1028
+ });
1029
+ };
1030
+ });
1031
+
1032
+ ////////////////////////////// ZodCustomStringFormat //////////////////////////////
1033
+
1034
+ export interface $ZodCustomStringFormatDef<Format extends string = string> extends $ZodStringFormatDef<Format> {
1035
+ fn: (val: string) => unknown;
1036
+ }
1037
+
1038
+ export interface $ZodCustomStringFormatInternals<Format extends string = string>
1039
+ extends $ZodStringFormatInternals<Format> {
1040
+ def: $ZodCustomStringFormatDef<Format>;
1041
+ }
1042
+
1043
+ export interface $ZodCustomStringFormat<Format extends string = string> extends $ZodStringFormat<Format> {
1044
+ _zod: $ZodCustomStringFormatInternals<Format>;
1045
+ }
1046
+
1047
+ export const $ZodCustomStringFormat: core.$constructor<$ZodCustomStringFormat> = /*@__PURE__*/ core.$constructor(
1048
+ "$ZodCustomStringFormat",
1049
+ (inst, def): void => {
1050
+ $ZodStringFormat.init(inst, def);
1051
+ inst._zod.check = (payload) => {
1052
+ if (def.fn(payload.value)) return;
1053
+
1054
+ payload.issues.push({
1055
+ code: "invalid_format",
1056
+ format: def.format,
1057
+ input: payload.value,
1058
+ inst,
1059
+ continue: !def.abort,
1060
+ });
1061
+ };
1062
+ }
1063
+ );
1064
+
1065
+ /////////////////////////////////////////
1066
+ /////////////////////////////////////////
1067
+ ////////// //////////
1068
+ ////////// ZodNumber //////////
1069
+ ////////// //////////
1070
+ /////////////////////////////////////////
1071
+ /////////////////////////////////////////
1072
+
1073
+ export interface $ZodNumberDef extends $ZodTypeDef {
1074
+ type: "number";
1075
+ coerce?: boolean;
1076
+ // checks: checks.$ZodCheck<number>[];
1077
+ }
1078
+
1079
+ export interface $ZodNumberInternals<Input = unknown> extends $ZodTypeInternals<number, Input> {
1080
+ def: $ZodNumberDef;
1081
+ /** @deprecated Internal API, use with caution (not deprecated) */
1082
+ pattern: RegExp;
1083
+ /** @deprecated Internal API, use with caution (not deprecated) */
1084
+ isst: errors.$ZodIssueInvalidType;
1085
+ bag: util.LoosePartial<{
1086
+ minimum: number;
1087
+ maximum: number;
1088
+ exclusiveMinimum: number;
1089
+ exclusiveMaximum: number;
1090
+ format: string;
1091
+ pattern: RegExp;
1092
+ }>;
1093
+ }
1094
+
1095
+ export interface $ZodNumber<Input = unknown> extends $ZodType {
1096
+ _zod: $ZodNumberInternals<Input>;
1097
+ }
1098
+
1099
+ export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, def) => {
1100
+ $ZodType.init(inst, def);
1101
+
1102
+ inst._zod.pattern = inst._zod.bag.pattern ?? regexes.number;
1103
+ inst._zod.parse = (payload, _ctx) => {
1104
+ if (def.coerce)
1105
+ try {
1106
+ payload.value = Number(payload.value);
1107
+ } catch (_) {}
1108
+ const input = payload.value;
1109
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) {
1110
+ return payload;
1111
+ }
1112
+
1113
+ const received =
1114
+ typeof input === "number"
1115
+ ? Number.isNaN(input)
1116
+ ? "NaN"
1117
+ : !Number.isFinite(input)
1118
+ ? "Infinity"
1119
+ : undefined
1120
+ : undefined;
1121
+
1122
+ payload.issues.push({
1123
+ expected: "number",
1124
+ code: "invalid_type",
1125
+
1126
+ input,
1127
+ inst,
1128
+ ...(received ? { received } : {}),
1129
+ });
1130
+ return payload;
1131
+ };
1132
+ });
1133
+
1134
+ ///////////////////////////////////////////////
1135
+ ////////// ZodNumberFormat //////////
1136
+ ///////////////////////////////////////////////
1137
+ export interface $ZodNumberFormatDef extends $ZodNumberDef, checks.$ZodCheckNumberFormatDef {}
1138
+
1139
+ export interface $ZodNumberFormatInternals extends $ZodNumberInternals<number>, checks.$ZodCheckNumberFormatInternals {
1140
+ def: $ZodNumberFormatDef;
1141
+ isst: errors.$ZodIssueInvalidType;
1142
+ }
1143
+
1144
+ export interface $ZodNumberFormat extends $ZodType {
1145
+ _zod: $ZodNumberFormatInternals;
1146
+ }
1147
+
1148
+ export const $ZodNumberFormat: core.$constructor<$ZodNumberFormat> = /*@__PURE__*/ core.$constructor(
1149
+ "$ZodNumberFormat",
1150
+ (inst, def) => {
1151
+ checks.$ZodCheckNumberFormat.init(inst, def);
1152
+ $ZodNumber.init(inst, def); // no format checks
1153
+ }
1154
+ );
1155
+
1156
+ ///////////////////////////////////////////
1157
+ ///////////////////////////////////////////
1158
+ ////////// ///////////
1159
+ ////////// $ZodBoolean //////////
1160
+ ////////// ///////////
1161
+ ///////////////////////////////////////////
1162
+ ///////////////////////////////////////////
1163
+
1164
+ export interface $ZodBooleanDef extends $ZodTypeDef {
1165
+ type: "boolean";
1166
+ coerce?: boolean;
1167
+ checks?: checks.$ZodCheck<boolean>[];
1168
+ }
1169
+
1170
+ export interface $ZodBooleanInternals<T = unknown> extends $ZodTypeInternals<boolean, T> {
1171
+ pattern: RegExp;
1172
+ def: $ZodBooleanDef;
1173
+ isst: errors.$ZodIssueInvalidType;
1174
+ }
1175
+
1176
+ export interface $ZodBoolean<T = unknown> extends $ZodType {
1177
+ _zod: $ZodBooleanInternals<T>;
1178
+ }
1179
+
1180
+ export const $ZodBoolean: core.$constructor<$ZodBoolean> = /*@__PURE__*/ core.$constructor(
1181
+ "$ZodBoolean",
1182
+ (inst, def) => {
1183
+ $ZodType.init(inst, def);
1184
+ inst._zod.pattern = regexes.boolean;
1185
+
1186
+ inst._zod.parse = (payload, _ctx) => {
1187
+ if (def.coerce)
1188
+ try {
1189
+ payload.value = Boolean(payload.value);
1190
+ } catch (_) {}
1191
+ const input = payload.value;
1192
+ if (typeof input === "boolean") return payload;
1193
+ payload.issues.push({
1194
+ expected: "boolean",
1195
+ code: "invalid_type",
1196
+
1197
+ input,
1198
+ inst,
1199
+ });
1200
+ return payload;
1201
+ };
1202
+ }
1203
+ );
1204
+
1205
+ //////////////////////////////////////////
1206
+ //////////////////////////////////////////
1207
+ ////////// //////////
1208
+ ////////// $ZodBigInt //////////
1209
+ ////////// //////////
1210
+ //////////////////////////////////////////
1211
+ //////////////////////////////////////////
1212
+
1213
+ export interface $ZodBigIntDef extends $ZodTypeDef {
1214
+ type: "bigint";
1215
+ coerce?: boolean;
1216
+ // checks: checks.$ZodCheck<bigint>[];
1217
+ }
1218
+
1219
+ export interface $ZodBigIntInternals<T = unknown> extends $ZodTypeInternals<bigint, T> {
1220
+ pattern: RegExp;
1221
+ /** @internal Internal API, use with caution */
1222
+ def: $ZodBigIntDef;
1223
+ isst: errors.$ZodIssueInvalidType;
1224
+ bag: util.LoosePartial<{
1225
+ minimum: bigint;
1226
+ maximum: bigint;
1227
+ format: string;
1228
+ }>;
1229
+ }
1230
+
1231
+ export interface $ZodBigInt<T = unknown> extends $ZodType {
1232
+ _zod: $ZodBigIntInternals<T>;
1233
+ }
1234
+
1235
+ export const $ZodBigInt: core.$constructor<$ZodBigInt> = /*@__PURE__*/ core.$constructor("$ZodBigInt", (inst, def) => {
1236
+ $ZodType.init(inst, def);
1237
+ inst._zod.pattern = regexes.bigint;
1238
+
1239
+ inst._zod.parse = (payload, _ctx) => {
1240
+ if (def.coerce)
1241
+ try {
1242
+ payload.value = BigInt(payload.value);
1243
+ } catch (_) {}
1244
+
1245
+ if (typeof payload.value === "bigint") return payload;
1246
+ payload.issues.push({
1247
+ expected: "bigint",
1248
+ code: "invalid_type",
1249
+
1250
+ input: payload.value,
1251
+ inst,
1252
+ });
1253
+ return payload;
1254
+ };
1255
+ });
1256
+
1257
+ ///////////////////////////////////////////////
1258
+ ////////// ZodBigIntFormat //////////
1259
+ ///////////////////////////////////////////////
1260
+ export interface $ZodBigIntFormatDef extends $ZodBigIntDef, checks.$ZodCheckBigIntFormatDef {
1261
+ check: "bigint_format";
1262
+ }
1263
+
1264
+ export interface $ZodBigIntFormatInternals extends $ZodBigIntInternals<bigint>, checks.$ZodCheckBigIntFormatInternals {
1265
+ def: $ZodBigIntFormatDef;
1266
+ }
1267
+
1268
+ export interface $ZodBigIntFormat extends $ZodType {
1269
+ _zod: $ZodBigIntFormatInternals;
1270
+ }
1271
+
1272
+ export const $ZodBigIntFormat: core.$constructor<$ZodBigIntFormat> = /*@__PURE__*/ core.$constructor(
1273
+ "$ZodBigIntFormat",
1274
+ (inst, def) => {
1275
+ checks.$ZodCheckBigIntFormat.init(inst, def);
1276
+ $ZodBigInt.init(inst, def); // no format checks
1277
+ }
1278
+ );
1279
+
1280
+ ////////////////////////////////////////////
1281
+ ////////////////////////////////////////////
1282
+ ////////// //////////
1283
+ ////////// $ZodSymbol //////////
1284
+ ////////// //////////
1285
+ ////////////////////////////////////////////
1286
+ ////////////////////////////////////////////
1287
+ export interface $ZodSymbolDef extends $ZodTypeDef {
1288
+ type: "symbol";
1289
+ }
1290
+
1291
+ export interface $ZodSymbolInternals extends $ZodTypeInternals<symbol, symbol> {
1292
+ def: $ZodSymbolDef;
1293
+ isst: errors.$ZodIssueInvalidType;
1294
+ }
1295
+
1296
+ export interface $ZodSymbol extends $ZodType {
1297
+ _zod: $ZodSymbolInternals;
1298
+ }
1299
+
1300
+ export const $ZodSymbol: core.$constructor<$ZodSymbol> = /*@__PURE__*/ core.$constructor("$ZodSymbol", (inst, def) => {
1301
+ $ZodType.init(inst, def);
1302
+
1303
+ inst._zod.parse = (payload, _ctx) => {
1304
+ const input = payload.value;
1305
+ if (typeof input === "symbol") return payload;
1306
+ payload.issues.push({
1307
+ expected: "symbol",
1308
+ code: "invalid_type",
1309
+
1310
+ input,
1311
+ inst,
1312
+ });
1313
+ return payload;
1314
+ };
1315
+ });
1316
+
1317
+ ////////////////////////////////////////////
1318
+ ////////////////////////////////////////////
1319
+ ////////// //////////
1320
+ ////////// $ZodUndefined //////////
1321
+ ////////// //////////
1322
+ ////////////////////////////////////////////
1323
+ ////////////////////////////////////////////
1324
+ export interface $ZodUndefinedDef extends $ZodTypeDef {
1325
+ type: "undefined";
1326
+ }
1327
+
1328
+ export interface $ZodUndefinedInternals extends $ZodTypeInternals<undefined, undefined> {
1329
+ pattern: RegExp;
1330
+ def: $ZodUndefinedDef;
1331
+ values: util.PrimitiveSet;
1332
+ isst: errors.$ZodIssueInvalidType;
1333
+ }
1334
+
1335
+ export interface $ZodUndefined extends $ZodType {
1336
+ _zod: $ZodUndefinedInternals;
1337
+ }
1338
+
1339
+ export const $ZodUndefined: core.$constructor<$ZodUndefined> = /*@__PURE__*/ core.$constructor(
1340
+ "$ZodUndefined",
1341
+ (inst, def) => {
1342
+ $ZodType.init(inst, def);
1343
+ inst._zod.pattern = regexes.undefined;
1344
+ inst._zod.values = new Set([undefined]);
1345
+ inst._zod.optin = "optional";
1346
+ inst._zod.optout = "optional";
1347
+
1348
+ inst._zod.parse = (payload, _ctx) => {
1349
+ const input = payload.value;
1350
+ if (typeof input === "undefined") return payload;
1351
+ payload.issues.push({
1352
+ expected: "undefined",
1353
+ code: "invalid_type",
1354
+
1355
+ input,
1356
+ inst,
1357
+ });
1358
+ return payload;
1359
+ };
1360
+ }
1361
+ );
1362
+
1363
+ ///////////////////////////////////////
1364
+ ///////////////////////////////////////
1365
+ ////////// //////////
1366
+ ////////// $ZodNull /////////
1367
+ ////////// //////////
1368
+ ///////////////////////////////////////
1369
+ ///////////////////////////////////////
1370
+
1371
+ export interface $ZodNullDef extends $ZodTypeDef {
1372
+ type: "null";
1373
+ }
1374
+
1375
+ export interface $ZodNullInternals extends $ZodTypeInternals<null, null> {
1376
+ pattern: RegExp;
1377
+ def: $ZodNullDef;
1378
+ values: util.PrimitiveSet;
1379
+ isst: errors.$ZodIssueInvalidType;
1380
+ }
1381
+
1382
+ export interface $ZodNull extends $ZodType {
1383
+ _zod: $ZodNullInternals;
1384
+ }
1385
+
1386
+ export const $ZodNull: core.$constructor<$ZodNull> = /*@__PURE__*/ core.$constructor("$ZodNull", (inst, def) => {
1387
+ $ZodType.init(inst, def);
1388
+ inst._zod.pattern = regexes.null;
1389
+ inst._zod.values = new Set([null]);
1390
+
1391
+ inst._zod.parse = (payload, _ctx) => {
1392
+ const input = payload.value;
1393
+ if (input === null) return payload;
1394
+ payload.issues.push({
1395
+ expected: "null",
1396
+ code: "invalid_type",
1397
+
1398
+ input,
1399
+ inst,
1400
+ });
1401
+ return payload;
1402
+ };
1403
+ });
1404
+
1405
+ //////////////////////////////////////
1406
+ //////////////////////////////////////
1407
+ ////////// //////////
1408
+ ////////// $ZodAny //////////
1409
+ ////////// //////////
1410
+ //////////////////////////////////////
1411
+ //////////////////////////////////////
1412
+
1413
+ export interface $ZodAnyDef extends $ZodTypeDef {
1414
+ type: "any";
1415
+ }
1416
+
1417
+ export interface $ZodAnyInternals extends $ZodTypeInternals<any, any> {
1418
+ def: $ZodAnyDef;
1419
+ isst: never;
1420
+ }
1421
+
1422
+ export interface $ZodAny extends $ZodType {
1423
+ _zod: $ZodAnyInternals;
1424
+ }
1425
+
1426
+ export const $ZodAny: core.$constructor<$ZodAny> = /*@__PURE__*/ core.$constructor("$ZodAny", (inst, def) => {
1427
+ $ZodType.init(inst, def);
1428
+
1429
+ inst._zod.parse = (payload) => payload;
1430
+ });
1431
+
1432
+ //////////////////////////////////////////
1433
+ //////////////////////////////////////////
1434
+ ////////// //////////
1435
+ ////////// $ZodUnknown //////////
1436
+ ////////// //////////
1437
+ //////////////////////////////////////////
1438
+ //////////////////////////////////////////
1439
+
1440
+ export interface $ZodUnknownDef extends $ZodTypeDef {
1441
+ type: "unknown";
1442
+ }
1443
+
1444
+ export interface $ZodUnknownInternals extends $ZodTypeInternals<unknown, unknown> {
1445
+ def: $ZodUnknownDef;
1446
+ isst: never;
1447
+ }
1448
+
1449
+ export interface $ZodUnknown extends $ZodType {
1450
+ _zod: $ZodUnknownInternals;
1451
+ }
1452
+
1453
+ export const $ZodUnknown: core.$constructor<$ZodUnknown> = /*@__PURE__*/ core.$constructor(
1454
+ "$ZodUnknown",
1455
+ (inst, def) => {
1456
+ $ZodType.init(inst, def);
1457
+
1458
+ inst._zod.parse = (payload) => payload;
1459
+ }
1460
+ );
1461
+
1462
+ /////////////////////////////////////////
1463
+ /////////////////////////////////////////
1464
+ ////////// //////////
1465
+ ////////// $ZodNever //////////
1466
+ ////////// //////////
1467
+ /////////////////////////////////////////
1468
+ /////////////////////////////////////////
1469
+
1470
+ export interface $ZodNeverDef extends $ZodTypeDef {
1471
+ type: "never";
1472
+ }
1473
+
1474
+ export interface $ZodNeverInternals extends $ZodTypeInternals<never, never> {
1475
+ def: $ZodNeverDef;
1476
+ isst: errors.$ZodIssueInvalidType;
1477
+ }
1478
+
1479
+ export interface $ZodNever extends $ZodType {
1480
+ _zod: $ZodNeverInternals;
1481
+ }
1482
+
1483
+ export const $ZodNever: core.$constructor<$ZodNever> = /*@__PURE__*/ core.$constructor("$ZodNever", (inst, def) => {
1484
+ $ZodType.init(inst, def);
1485
+ inst._zod.parse = (payload, _ctx) => {
1486
+ payload.issues.push({
1487
+ expected: "never",
1488
+ code: "invalid_type",
1489
+
1490
+ input: payload.value,
1491
+ inst,
1492
+ });
1493
+ return payload;
1494
+ };
1495
+ });
1496
+
1497
+ ////////////////////////////////////////
1498
+ ////////////////////////////////////////
1499
+ ////////// //////////
1500
+ ////////// $ZodVoid //////////
1501
+ ////////// //////////
1502
+ ////////////////////////////////////////
1503
+ ////////////////////////////////////////
1504
+
1505
+ export interface $ZodVoidDef extends $ZodTypeDef {
1506
+ type: "void";
1507
+ }
1508
+
1509
+ export interface $ZodVoidInternals extends $ZodTypeInternals<void, void> {
1510
+ def: $ZodVoidDef;
1511
+ isst: errors.$ZodIssueInvalidType;
1512
+ }
1513
+
1514
+ export interface $ZodVoid extends $ZodType {
1515
+ _zod: $ZodVoidInternals;
1516
+ }
1517
+
1518
+ export const $ZodVoid: core.$constructor<$ZodVoid> = /*@__PURE__*/ core.$constructor("$ZodVoid", (inst, def) => {
1519
+ $ZodType.init(inst, def);
1520
+
1521
+ inst._zod.parse = (payload, _ctx) => {
1522
+ const input = payload.value;
1523
+ if (typeof input === "undefined") return payload;
1524
+ payload.issues.push({
1525
+ expected: "void",
1526
+ code: "invalid_type",
1527
+
1528
+ input,
1529
+ inst,
1530
+ });
1531
+ return payload;
1532
+ };
1533
+ });
1534
+
1535
+ ///////////////////////////////////////
1536
+ ///////////////////////////////////////
1537
+ ////////// ////////
1538
+ ////////// $ZodDate ////////
1539
+ ////////// ////////
1540
+ ///////////////////////////////////////
1541
+ ///////////////////////////////////////
1542
+ export interface $ZodDateDef extends $ZodTypeDef {
1543
+ type: "date";
1544
+ coerce?: boolean;
1545
+ }
1546
+
1547
+ export interface $ZodDateInternals<T = unknown> extends $ZodTypeInternals<Date, T> {
1548
+ def: $ZodDateDef;
1549
+ isst: errors.$ZodIssueInvalidType; // | errors.$ZodIssueInvalidDate;
1550
+ bag: util.LoosePartial<{
1551
+ minimum: Date;
1552
+ maximum: Date;
1553
+ format: string;
1554
+ }>;
1555
+ }
1556
+
1557
+ export interface $ZodDate<T = unknown> extends $ZodType {
1558
+ _zod: $ZodDateInternals<T>;
1559
+ }
1560
+
1561
+ export const $ZodDate: core.$constructor<$ZodDate> = /*@__PURE__*/ core.$constructor("$ZodDate", (inst, def) => {
1562
+ $ZodType.init(inst, def);
1563
+
1564
+ inst._zod.parse = (payload, _ctx) => {
1565
+ if (def.coerce) {
1566
+ try {
1567
+ payload.value = new Date(payload.value as string | number | Date);
1568
+ } catch (_err: any) {}
1569
+ }
1570
+ const input = payload.value;
1571
+
1572
+ const isDate = input instanceof Date;
1573
+ const isValidDate = isDate && !Number.isNaN(input.getTime());
1574
+ if (isValidDate) return payload;
1575
+ payload.issues.push({
1576
+ expected: "date",
1577
+ code: "invalid_type",
1578
+
1579
+ input,
1580
+ ...(isDate ? { received: "Invalid Date" } : {}),
1581
+ inst,
1582
+ });
1583
+
1584
+ return payload;
1585
+ };
1586
+ });
1587
+
1588
+ /////////////////////////////////////////
1589
+ /////////////////////////////////////////
1590
+ ////////// //////////
1591
+ ////////// $ZodArray //////////
1592
+ ////////// //////////
1593
+ /////////////////////////////////////////
1594
+ /////////////////////////////////////////
1595
+
1596
+ export interface $ZodArrayDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
1597
+ type: "array";
1598
+ element: T;
1599
+ }
1600
+
1601
+ export interface $ZodArrayInternals<T extends SomeType = $ZodType> extends _$ZodTypeInternals {
1602
+ //$ZodTypeInternals<core.output<T>[], core.input<T>[]> {
1603
+ def: $ZodArrayDef<T>;
1604
+ isst: errors.$ZodIssueInvalidType;
1605
+ output: core.output<T>[];
1606
+ input: core.input<T>[];
1607
+ }
1608
+
1609
+ export interface $ZodArray<T extends SomeType = $ZodType> extends $ZodType<any, any, $ZodArrayInternals<T>> {}
1610
+
1611
+ function handleArrayResult(result: ParsePayload<any>, final: ParsePayload<any[]>, index: number) {
1612
+ if (result.issues.length) {
1613
+ final.issues.push(...util.prefixIssues(index, result.issues));
1614
+ }
1615
+ final.value[index] = result.value;
1616
+ }
1617
+
1618
+ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def) => {
1619
+ $ZodType.init(inst, def);
1620
+
1621
+ inst._zod.parse = (payload, ctx) => {
1622
+ const input = payload.value;
1623
+
1624
+ if (!Array.isArray(input)) {
1625
+ payload.issues.push({
1626
+ expected: "array",
1627
+ code: "invalid_type",
1628
+
1629
+ input,
1630
+ inst,
1631
+ });
1632
+ return payload;
1633
+ }
1634
+
1635
+ payload.value = Array(input.length);
1636
+ const proms: Promise<any>[] = [];
1637
+ for (let i = 0; i < input.length; i++) {
1638
+ const item = input[i];
1639
+ const result = def.element._zod.run(
1640
+ {
1641
+ value: item,
1642
+ issues: [],
1643
+ },
1644
+ ctx
1645
+ );
1646
+
1647
+ if (result instanceof Promise) {
1648
+ proms.push(result.then((result) => handleArrayResult(result, payload, i)));
1649
+ } else {
1650
+ handleArrayResult(result, payload, i);
1651
+ }
1652
+ }
1653
+
1654
+ if (proms.length) {
1655
+ return Promise.all(proms).then(() => payload);
1656
+ }
1657
+
1658
+ return payload; //handleArrayResultsAsync(parseResults, final);
1659
+ };
1660
+ });
1661
+
1662
+ //////////////////////////////////////////
1663
+ //////////////////////////////////////////
1664
+ ////////// //////////
1665
+ ////////// $ZodObject //////////
1666
+ ////////// //////////
1667
+ //////////////////////////////////////////
1668
+ //////////////////////////////////////////
1669
+
1670
+ type OptionalOutSchema = { _zod: { optout: "optional" } };
1671
+ type OptionalInSchema = { _zod: { optin: "optional" } };
1672
+
1673
+ export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T
1674
+ ? util.IsAny<T[keyof T]> extends true
1675
+ ? Record<string, unknown>
1676
+ : Record<string, core.output<T[keyof T]>>
1677
+ : keyof (T & Extra) extends never
1678
+ ? Record<string, never>
1679
+ : util.Prettify<
1680
+ {
1681
+ -readonly [k in keyof T as T[k] extends OptionalOutSchema ? never : k]: T[k]["_zod"]["output"];
1682
+ } & {
1683
+ -readonly [k in keyof T as T[k] extends OptionalOutSchema ? k : never]?: T[k]["_zod"]["output"];
1684
+ } & Extra
1685
+ >;
1686
+
1687
+ // experimental
1688
+ // export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = keyof (T &
1689
+ // Extra) extends never
1690
+ // ? Record<string, never>
1691
+ // : string extends keyof T
1692
+ // ? util.Prettify<
1693
+ // {
1694
+ // [k: string]: util.IsAny<T[string]["_zod"]["output"]> extends true ? unknown : T[string]["_zod"]["output"];
1695
+ // } & $InferObjectOutputNoIndex<util.OmitIndexSignature<T>, Extra>
1696
+ // >
1697
+ // : util.Prettify<$InferObjectOutputNoIndex<T, Extra>>;
1698
+
1699
+ // export type $InferObjectOutputNoIndex<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = {
1700
+ // [k in keyof T as string extends k
1701
+ // ? never
1702
+ // : k extends string
1703
+ // ? T[k] extends OptionalOutSchema
1704
+ // ? never
1705
+ // : k
1706
+ // : never]: T[k]["_zod"]["output"];
1707
+ // } & {
1708
+ // [k in keyof T as string extends k
1709
+ // ? never
1710
+ // : k extends string
1711
+ // ? T[k] extends OptionalOutSchema
1712
+ // ? k
1713
+ // : never
1714
+ // : never]?: T[k]["_zod"]["output"];
1715
+ // } & Extra;
1716
+
1717
+ export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T
1718
+ ? util.IsAny<T[keyof T]> extends true
1719
+ ? Record<string, unknown>
1720
+ : Record<string, core.input<T[keyof T]>>
1721
+ : keyof (T & Extra) extends never
1722
+ ? Record<string, never>
1723
+ : util.Prettify<
1724
+ {
1725
+ -readonly [k in keyof T as T[k] extends OptionalInSchema ? never : k]: T[k]["_zod"]["input"];
1726
+ } & {
1727
+ -readonly [k in keyof T as T[k] extends OptionalInSchema ? k : never]?: T[k]["_zod"]["input"];
1728
+ } & Extra
1729
+ >;
1730
+
1731
+ function handlePropertyResult(
1732
+ result: ParsePayload,
1733
+ final: ParsePayload,
1734
+ key: PropertyKey,
1735
+ input: any,
1736
+ isOptionalOut: boolean
1737
+ ) {
1738
+ if (result.issues.length) {
1739
+ // For optional-out schemas, ignore errors on absent keys
1740
+ if (isOptionalOut && !(key in input)) {
1741
+ return;
1742
+ }
1743
+ final.issues.push(...util.prefixIssues(key, result.issues));
1744
+ }
1745
+
1746
+ if (result.value === undefined) {
1747
+ if (key in input) {
1748
+ (final.value as any)[key] = undefined;
1749
+ }
1750
+ } else {
1751
+ (final.value as any)[key] = result.value;
1752
+ }
1753
+ }
1754
+
1755
+ export type $ZodObjectConfig = { out: Record<string, unknown>; in: Record<string, unknown> };
1756
+
1757
+ export type $loose = {
1758
+ out: Record<string, unknown>;
1759
+ in: Record<string, unknown>;
1760
+ };
1761
+ export type $strict = {
1762
+ out: {};
1763
+ in: {};
1764
+ };
1765
+ export type $strip = {
1766
+ out: {};
1767
+ in: {};
1768
+ };
1769
+
1770
+ export type $catchall<T extends SomeType> = {
1771
+ out: { [k: string]: core.output<T> };
1772
+ in: { [k: string]: core.input<T> };
1773
+ };
1774
+
1775
+ export type $ZodShape = Readonly<{ [k: string]: $ZodType }>;
1776
+
1777
+ export interface $ZodObjectDef<Shape extends $ZodShape = $ZodShape> extends $ZodTypeDef {
1778
+ type: "object";
1779
+ shape: Shape;
1780
+ catchall?: $ZodType | undefined;
1781
+ }
1782
+
1783
+ export interface $ZodObjectInternals<
1784
+ /** @ts-ignore Cast variance */
1785
+ out Shape extends $ZodShape = $ZodShape,
1786
+ out Config extends $ZodObjectConfig = $ZodObjectConfig,
1787
+ > extends _$ZodTypeInternals {
1788
+ def: $ZodObjectDef<Shape>;
1789
+ config: Config;
1790
+ isst: errors.$ZodIssueInvalidType | errors.$ZodIssueUnrecognizedKeys;
1791
+ propValues: util.PropValues;
1792
+ output: $InferObjectOutput<Shape, Config["out"]>;
1793
+ input: $InferObjectInput<Shape, Config["in"]>;
1794
+ optin?: "optional" | undefined;
1795
+ optout?: "optional" | undefined;
1796
+ }
1797
+ export type $ZodLooseShape = Record<string, any>;
1798
+
1799
+ export interface $ZodObject<
1800
+ /** @ts-ignore Cast variance */
1801
+ out Shape extends Readonly<$ZodShape> = Readonly<$ZodShape>,
1802
+ out Params extends $ZodObjectConfig = $ZodObjectConfig,
1803
+ > extends $ZodType<any, any, $ZodObjectInternals<Shape, Params>> {}
1804
+
1805
+ function normalizeDef(def: $ZodObjectDef) {
1806
+ const keys = Object.keys(def.shape);
1807
+ for (const k of keys) {
1808
+ if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
1809
+ throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1810
+ }
1811
+ }
1812
+ const okeys = util.optionalKeys(def.shape);
1813
+
1814
+ return {
1815
+ ...def,
1816
+ keys,
1817
+ keySet: new Set(keys),
1818
+ numKeys: keys.length,
1819
+ optionalKeys: new Set(okeys),
1820
+ };
1821
+ }
1822
+
1823
+ function handleCatchall(
1824
+ proms: Promise<any>[],
1825
+ input: any,
1826
+ payload: ParsePayload,
1827
+ ctx: ParseContext,
1828
+ def: ReturnType<typeof normalizeDef>,
1829
+ inst: $ZodObject
1830
+ ) {
1831
+ const unrecognized: string[] = [];
1832
+ // iterate over input keys
1833
+ const keySet = def.keySet;
1834
+ const _catchall = def.catchall!._zod;
1835
+ const t = _catchall.def.type;
1836
+ const isOptionalOut = _catchall.optout === "optional";
1837
+ for (const key in input) {
1838
+ if (keySet.has(key)) continue;
1839
+ if (t === "never") {
1840
+ unrecognized.push(key);
1841
+ continue;
1842
+ }
1843
+ const r = _catchall.run({ value: input[key], issues: [] }, ctx);
1844
+
1845
+ if (r instanceof Promise) {
1846
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
1847
+ } else {
1848
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
1849
+ }
1850
+ }
1851
+
1852
+ if (unrecognized.length) {
1853
+ payload.issues.push({
1854
+ code: "unrecognized_keys",
1855
+ keys: unrecognized,
1856
+ input,
1857
+ inst,
1858
+ });
1859
+ }
1860
+
1861
+ if (!proms.length) return payload;
1862
+ return Promise.all(proms).then(() => {
1863
+ return payload;
1864
+ });
1865
+ }
1866
+
1867
+ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
1868
+ // requires cast because technically $ZodObject doesn't extend
1869
+ $ZodType.init(inst, def);
1870
+ // const sh = def.shape;
1871
+ const desc = Object.getOwnPropertyDescriptor(def, "shape");
1872
+ if (!desc?.get) {
1873
+ const sh = def.shape;
1874
+ Object.defineProperty(def, "shape", {
1875
+ get: () => {
1876
+ const newSh = { ...sh };
1877
+ Object.defineProperty(def, "shape", {
1878
+ value: newSh,
1879
+ });
1880
+
1881
+ return newSh;
1882
+ },
1883
+ });
1884
+ }
1885
+
1886
+ const _normalized = util.cached(() => normalizeDef(def));
1887
+
1888
+ util.defineLazy(inst._zod, "propValues", () => {
1889
+ const shape = def.shape;
1890
+ const propValues: util.PropValues = {};
1891
+ for (const key in shape) {
1892
+ const field = shape[key]!._zod;
1893
+ if (field.values) {
1894
+ propValues[key] ??= new Set();
1895
+ for (const v of field.values) propValues[key].add(v);
1896
+ }
1897
+ }
1898
+ return propValues;
1899
+ });
1900
+
1901
+ const isObject = util.isObject;
1902
+ const catchall = def.catchall;
1903
+
1904
+ let value!: typeof _normalized.value;
1905
+
1906
+ inst._zod.parse = (payload, ctx) => {
1907
+ value ??= _normalized.value;
1908
+ const input = payload.value;
1909
+ if (!isObject(input)) {
1910
+ payload.issues.push({
1911
+ expected: "object",
1912
+ code: "invalid_type",
1913
+ input,
1914
+ inst,
1915
+ });
1916
+ return payload;
1917
+ }
1918
+
1919
+ payload.value = {};
1920
+
1921
+ const proms: Promise<any>[] = [];
1922
+ const shape = value.shape;
1923
+
1924
+ for (const key of value.keys) {
1925
+ const el = shape[key]!;
1926
+ const isOptionalOut = el._zod.optout === "optional";
1927
+
1928
+ const r = el._zod.run({ value: input[key], issues: [] }, ctx);
1929
+ if (r instanceof Promise) {
1930
+ proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
1931
+ } else {
1932
+ handlePropertyResult(r, payload, key, input, isOptionalOut);
1933
+ }
1934
+ }
1935
+
1936
+ if (!catchall) {
1937
+ return proms.length ? Promise.all(proms).then(() => payload) : payload;
1938
+ }
1939
+
1940
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
1941
+ };
1942
+ });
1943
+
1944
+ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$constructor(
1945
+ "$ZodObjectJIT",
1946
+ (inst, def) => {
1947
+ // requires cast because technically $ZodObject doesn't extend
1948
+ $ZodObject.init(inst, def);
1949
+
1950
+ const superParse = inst._zod.parse;
1951
+ const _normalized = util.cached(() => normalizeDef(def));
1952
+
1953
+ const generateFastpass = (shape: any) => {
1954
+ const doc = new Doc(["shape", "payload", "ctx"]);
1955
+ const normalized = _normalized.value;
1956
+
1957
+ const parseStr = (key: string) => {
1958
+ const k = util.esc(key);
1959
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1960
+ };
1961
+
1962
+ doc.write(`const input = payload.value;`);
1963
+
1964
+ const ids: any = Object.create(null);
1965
+ let counter = 0;
1966
+ for (const key of normalized.keys) {
1967
+ ids[key] = `key_${counter++}`;
1968
+ }
1969
+
1970
+ // A: preserve key order {
1971
+ doc.write(`const newResult = {};`);
1972
+ for (const key of normalized.keys) {
1973
+ const id = ids[key];
1974
+ const k = util.esc(key);
1975
+ const schema = shape[key];
1976
+ const isOptionalOut = schema?._zod?.optout === "optional";
1977
+
1978
+ doc.write(`const ${id} = ${parseStr(key)};`);
1979
+
1980
+ if (isOptionalOut) {
1981
+ // For optional-out schemas, ignore errors on absent keys
1982
+ doc.write(`
1983
+ if (${id}.issues.length) {
1984
+ if (${k} in input) {
1985
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1986
+ ...iss,
1987
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
1988
+ })));
1989
+ }
1990
+ }
1991
+
1992
+ if (${id}.value === undefined) {
1993
+ if (${k} in input) {
1994
+ newResult[${k}] = undefined;
1995
+ }
1996
+ } else {
1997
+ newResult[${k}] = ${id}.value;
1998
+ }
1999
+
2000
+ `);
2001
+ } else {
2002
+ doc.write(`
2003
+ if (${id}.issues.length) {
2004
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
2005
+ ...iss,
2006
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
2007
+ })));
2008
+ }
2009
+
2010
+ if (${id}.value === undefined) {
2011
+ if (${k} in input) {
2012
+ newResult[${k}] = undefined;
2013
+ }
2014
+ } else {
2015
+ newResult[${k}] = ${id}.value;
2016
+ }
2017
+
2018
+ `);
2019
+ }
2020
+ }
2021
+
2022
+ doc.write(`payload.value = newResult;`);
2023
+ doc.write(`return payload;`);
2024
+ const fn = doc.compile();
2025
+ return (payload: any, ctx: any) => fn(shape, payload, ctx);
2026
+ };
2027
+
2028
+ let fastpass!: ReturnType<typeof generateFastpass>;
2029
+
2030
+ const isObject = util.isObject;
2031
+ const jit = !core.globalConfig.jitless;
2032
+ const allowsEval = util.allowsEval;
2033
+
2034
+ const fastEnabled = jit && allowsEval.value; // && !def.catchall;
2035
+ const catchall = def.catchall;
2036
+
2037
+ let value!: typeof _normalized.value;
2038
+
2039
+ inst._zod.parse = (payload, ctx) => {
2040
+ value ??= _normalized.value;
2041
+ const input = payload.value;
2042
+ if (!isObject(input)) {
2043
+ payload.issues.push({
2044
+ expected: "object",
2045
+ code: "invalid_type",
2046
+ input,
2047
+ inst,
2048
+ });
2049
+ return payload;
2050
+ }
2051
+
2052
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
2053
+ // always synchronous
2054
+ if (!fastpass) fastpass = generateFastpass(def.shape);
2055
+ payload = fastpass(payload, ctx);
2056
+
2057
+ if (!catchall) return payload;
2058
+ return handleCatchall([], input, payload, ctx, value, inst);
2059
+ }
2060
+
2061
+ return superParse(payload, ctx);
2062
+ };
2063
+ }
2064
+ );
2065
+
2066
+ /////////////////////////////////////////
2067
+ /////////////////////////////////////////
2068
+ ////////// ///////////
2069
+ ////////// $ZodUnion //////////
2070
+ ////////// ///////////
2071
+ /////////////////////////////////////////
2072
+ /////////////////////////////////////////
2073
+ // use generic to distribute union types
2074
+ export type $InferUnionOutput<T extends SomeType> = T extends any ? core.output<T> : never;
2075
+ export type $InferUnionInput<T extends SomeType> = T extends any ? core.input<T> : never;
2076
+ export interface $ZodUnionDef<Options extends readonly SomeType[] = readonly $ZodType[]> extends $ZodTypeDef {
2077
+ type: "union";
2078
+ options: Options;
2079
+ inclusive?: boolean;
2080
+ }
2081
+
2082
+ type IsOptionalIn<T extends SomeType> = T extends OptionalInSchema ? true : false;
2083
+ type IsOptionalOut<T extends SomeType> = T extends OptionalOutSchema ? true : false;
2084
+
2085
+ export interface $ZodUnionInternals<T extends readonly SomeType[] = readonly $ZodType[]> extends _$ZodTypeInternals {
2086
+ def: $ZodUnionDef<T>;
2087
+ isst: errors.$ZodIssueInvalidUnion;
2088
+ pattern: T[number]["_zod"]["pattern"];
2089
+ values: T[number]["_zod"]["values"]; //GetValues<T[number]>;
2090
+ output: $InferUnionOutput<T[number]>;
2091
+ input: $InferUnionInput<T[number]>;
2092
+ // if any element in the union is optional, then the union is optional
2093
+ optin: IsOptionalIn<T[number]> extends false ? "optional" | undefined : "optional";
2094
+ optout: IsOptionalOut<T[number]> extends false ? "optional" | undefined : "optional";
2095
+ }
2096
+
2097
+ export interface $ZodUnion<T extends readonly SomeType[] = readonly $ZodType[]>
2098
+ extends $ZodType<any, any, $ZodUnionInternals<T>> {
2099
+ _zod: $ZodUnionInternals<T>;
2100
+ }
2101
+
2102
+ function handleUnionResults(results: ParsePayload[], final: ParsePayload, inst: $ZodUnion, ctx?: ParseContext) {
2103
+ for (const result of results) {
2104
+ if (result.issues.length === 0) {
2105
+ final.value = result.value;
2106
+ return final;
2107
+ }
2108
+ }
2109
+
2110
+ const nonaborted = results.filter((r) => !util.aborted(r));
2111
+ if (nonaborted.length === 1) {
2112
+ final.value = nonaborted[0].value;
2113
+ return nonaborted[0];
2114
+ }
2115
+
2116
+ final.issues.push({
2117
+ code: "invalid_union",
2118
+
2119
+ input: final.value,
2120
+ inst,
2121
+ errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
2122
+ });
2123
+
2124
+ return final;
2125
+ }
2126
+
2127
+ export const $ZodUnion: core.$constructor<$ZodUnion> = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def) => {
2128
+ $ZodType.init(inst, def);
2129
+
2130
+ util.defineLazy(inst._zod, "optin", () =>
2131
+ def.options.some((o) => o._zod.optin === "optional") ? "optional" : undefined
2132
+ );
2133
+
2134
+ util.defineLazy(inst._zod, "optout", () =>
2135
+ def.options.some((o) => o._zod.optout === "optional") ? "optional" : undefined
2136
+ );
2137
+
2138
+ util.defineLazy(inst._zod, "values", () => {
2139
+ if (def.options.every((o) => o._zod.values)) {
2140
+ return new Set<util.Primitive>(def.options.flatMap((option) => Array.from(option._zod.values!)));
2141
+ }
2142
+ return undefined;
2143
+ });
2144
+
2145
+ util.defineLazy(inst._zod, "pattern", () => {
2146
+ if (def.options.every((o) => o._zod.pattern)) {
2147
+ const patterns = def.options.map((o) => o._zod.pattern);
2148
+ return new RegExp(`^(${patterns.map((p) => util.cleanRegex(p!.source)).join("|")})$`);
2149
+ }
2150
+ return undefined;
2151
+ });
2152
+
2153
+ const single = def.options.length === 1;
2154
+ const first = def.options[0]._zod.run;
2155
+
2156
+ inst._zod.parse = (payload, ctx) => {
2157
+ if (single) {
2158
+ return first(payload, ctx);
2159
+ }
2160
+ let async = false;
2161
+
2162
+ const results: util.MaybeAsync<ParsePayload>[] = [];
2163
+ for (const option of def.options) {
2164
+ const result = option._zod.run(
2165
+ {
2166
+ value: payload.value,
2167
+ issues: [],
2168
+ },
2169
+ ctx
2170
+ );
2171
+ if (result instanceof Promise) {
2172
+ results.push(result);
2173
+ async = true;
2174
+ } else {
2175
+ if (result.issues.length === 0) return result;
2176
+ results.push(result);
2177
+ }
2178
+ }
2179
+
2180
+ if (!async) return handleUnionResults(results as ParsePayload[], payload, inst, ctx);
2181
+ return Promise.all(results).then((results) => {
2182
+ return handleUnionResults(results as ParsePayload[], payload, inst, ctx);
2183
+ });
2184
+ };
2185
+ });
2186
+
2187
+ function handleExclusiveUnionResults(
2188
+ results: ParsePayload[],
2189
+ final: ParsePayload,
2190
+ inst: $ZodUnion,
2191
+ ctx?: ParseContext
2192
+ ) {
2193
+ const successes = results.filter((r) => r.issues.length === 0);
2194
+
2195
+ if (successes.length === 1) {
2196
+ final.value = successes[0].value;
2197
+ return final;
2198
+ }
2199
+
2200
+ if (successes.length === 0) {
2201
+ // No matches - same as regular union
2202
+ final.issues.push({
2203
+ code: "invalid_union",
2204
+ input: final.value,
2205
+ inst,
2206
+ errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
2207
+ });
2208
+ } else {
2209
+ // Multiple matches - exclusive union failure
2210
+ final.issues.push({
2211
+ code: "invalid_union",
2212
+ input: final.value,
2213
+ inst,
2214
+ errors: [],
2215
+ inclusive: false,
2216
+ });
2217
+ }
2218
+
2219
+ return final;
2220
+ }
2221
+
2222
+ export interface $ZodXorInternals<T extends readonly SomeType[] = readonly $ZodType[]> extends $ZodUnionInternals<T> {}
2223
+
2224
+ export interface $ZodXor<T extends readonly SomeType[] = readonly $ZodType[]>
2225
+ extends $ZodType<any, any, $ZodXorInternals<T>> {
2226
+ _zod: $ZodXorInternals<T>;
2227
+ }
2228
+
2229
+ export const $ZodXor: core.$constructor<$ZodXor> = /*@__PURE__*/ core.$constructor("$ZodXor", (inst, def) => {
2230
+ $ZodUnion.init(inst, def);
2231
+ def.inclusive = false;
2232
+
2233
+ const single = def.options.length === 1;
2234
+ const first = def.options[0]._zod.run;
2235
+
2236
+ inst._zod.parse = (payload, ctx) => {
2237
+ if (single) {
2238
+ return first(payload, ctx);
2239
+ }
2240
+ let async = false;
2241
+
2242
+ const results: util.MaybeAsync<ParsePayload>[] = [];
2243
+ for (const option of def.options) {
2244
+ const result = option._zod.run(
2245
+ {
2246
+ value: payload.value,
2247
+ issues: [],
2248
+ },
2249
+ ctx
2250
+ );
2251
+ if (result instanceof Promise) {
2252
+ results.push(result);
2253
+ async = true;
2254
+ } else {
2255
+ results.push(result);
2256
+ }
2257
+ }
2258
+
2259
+ if (!async) return handleExclusiveUnionResults(results as ParsePayload[], payload, inst, ctx);
2260
+ return Promise.all(results).then((results) => {
2261
+ return handleExclusiveUnionResults(results as ParsePayload[], payload, inst, ctx);
2262
+ });
2263
+ };
2264
+ });
2265
+
2266
+ //////////////////////////////////////////////////////
2267
+ //////////////////////////////////////////////////////
2268
+ ////////// //////////
2269
+ ////////// $ZodDiscriminatedUnion //////////
2270
+ ////////// //////////
2271
+ //////////////////////////////////////////////////////
2272
+ //////////////////////////////////////////////////////
2273
+
2274
+ export interface $ZodDiscriminatedUnionDef<
2275
+ Options extends readonly SomeType[] = readonly $ZodType[],
2276
+ Disc extends string = string,
2277
+ > extends $ZodUnionDef<Options> {
2278
+ discriminator: Disc;
2279
+ unionFallback?: boolean;
2280
+ }
2281
+
2282
+ export interface $ZodDiscriminatedUnionInternals<
2283
+ Options extends readonly SomeType[] = readonly $ZodType[],
2284
+ Disc extends string = string,
2285
+ > extends $ZodUnionInternals<Options> {
2286
+ def: $ZodDiscriminatedUnionDef<Options, Disc>;
2287
+ propValues: util.PropValues;
2288
+ }
2289
+
2290
+ export interface $ZodDiscriminatedUnion<
2291
+ Options extends readonly SomeType[] = readonly $ZodType[],
2292
+ Disc extends string = string,
2293
+ > extends $ZodType {
2294
+ _zod: $ZodDiscriminatedUnionInternals<Options, Disc>;
2295
+ }
2296
+
2297
+ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
2298
+ /*@__PURE__*/
2299
+ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
2300
+ def.inclusive = false;
2301
+
2302
+ $ZodUnion.init(inst, def);
2303
+
2304
+ const _super = inst._zod.parse;
2305
+ util.defineLazy(inst._zod, "propValues", () => {
2306
+ const propValues: util.PropValues = {};
2307
+ for (const option of def.options) {
2308
+ const pv = option._zod.propValues;
2309
+ if (!pv || Object.keys(pv).length === 0)
2310
+ throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
2311
+ for (const [k, v] of Object.entries(pv!)) {
2312
+ if (!propValues[k]) propValues[k] = new Set();
2313
+ for (const val of v) {
2314
+ propValues[k].add(val);
2315
+ }
2316
+ }
2317
+ }
2318
+ return propValues;
2319
+ });
2320
+
2321
+ const disc = util.cached(() => {
2322
+ const opts = def.options as $ZodTypeDiscriminable[];
2323
+ const map: Map<util.Primitive, $ZodType> = new Map();
2324
+ for (const o of opts) {
2325
+ const values = o._zod.propValues?.[def.discriminator];
2326
+ if (!values || values.size === 0)
2327
+ throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
2328
+ for (const v of values) {
2329
+ if (map.has(v)) {
2330
+ throw new Error(`Duplicate discriminator value "${String(v)}"`);
2331
+ }
2332
+ map.set(v, o);
2333
+ }
2334
+ }
2335
+ return map;
2336
+ });
2337
+
2338
+ inst._zod.parse = (payload, ctx) => {
2339
+ const input = payload.value;
2340
+ if (!util.isObject(input)) {
2341
+ payload.issues.push({
2342
+ code: "invalid_type",
2343
+
2344
+ expected: "object",
2345
+ input,
2346
+ inst,
2347
+ });
2348
+ return payload;
2349
+ }
2350
+
2351
+ const opt = disc.value.get(input?.[def.discriminator] as any);
2352
+ if (opt) {
2353
+ return opt._zod.run(payload, ctx) as any;
2354
+ }
2355
+
2356
+ if (def.unionFallback) {
2357
+ return _super(payload, ctx);
2358
+ }
2359
+
2360
+ // no matching discriminator
2361
+ payload.issues.push({
2362
+ code: "invalid_union",
2363
+
2364
+ errors: [],
2365
+ note: "No matching discriminator",
2366
+ discriminator: def.discriminator,
2367
+ input,
2368
+ path: [def.discriminator],
2369
+ inst,
2370
+ });
2371
+
2372
+ return payload;
2373
+ };
2374
+ });
2375
+
2376
+ ////////////////////////////////////////////////
2377
+ ////////////////////////////////////////////////
2378
+ ////////// //////////
2379
+ ////////// $ZodIntersection //////////
2380
+ ////////// //////////
2381
+ ////////////////////////////////////////////////
2382
+ ////////////////////////////////////////////////
2383
+
2384
+ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right extends SomeType = $ZodType>
2385
+ extends $ZodTypeDef {
2386
+ type: "intersection";
2387
+ left: Left;
2388
+ right: Right;
2389
+ }
2390
+
2391
+ export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType>
2392
+ extends _$ZodTypeInternals {
2393
+ // $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>>
2394
+ def: $ZodIntersectionDef<A, B>;
2395
+ isst: never;
2396
+ optin: A["_zod"]["optin"] | B["_zod"]["optin"];
2397
+ optout: A["_zod"]["optout"] | B["_zod"]["optout"];
2398
+ output: core.output<A> & core.output<B>;
2399
+ input: core.input<A> & core.input<B>;
2400
+ }
2401
+
2402
+ export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
2403
+ _zod: $ZodIntersectionInternals<A, B>;
2404
+ }
2405
+
2406
+ export const $ZodIntersection: core.$constructor<$ZodIntersection> = /*@__PURE__*/ core.$constructor(
2407
+ "$ZodIntersection",
2408
+ (inst, def) => {
2409
+ $ZodType.init(inst, def);
2410
+
2411
+ inst._zod.parse = (payload, ctx) => {
2412
+ const input = payload.value;
2413
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
2414
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
2415
+ const async = left instanceof Promise || right instanceof Promise;
2416
+
2417
+ if (async) {
2418
+ return Promise.all([left, right]).then(([left, right]) => {
2419
+ return handleIntersectionResults(payload, left, right);
2420
+ });
2421
+ }
2422
+
2423
+ return handleIntersectionResults(payload, left, right);
2424
+ };
2425
+ }
2426
+ );
2427
+
2428
+ function mergeValues(
2429
+ a: any,
2430
+ b: any
2431
+ ): { valid: true; data: any } | { valid: false; mergeErrorPath: (string | number)[] } {
2432
+ // const aType = parse.t(a);
2433
+ // const bType = parse.t(b);
2434
+
2435
+ if (a === b) {
2436
+ return { valid: true, data: a };
2437
+ }
2438
+ if (a instanceof Date && b instanceof Date && +a === +b) {
2439
+ return { valid: true, data: a };
2440
+ }
2441
+ if (util.isPlainObject(a) && util.isPlainObject(b)) {
2442
+ const bKeys = Object.keys(b);
2443
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
2444
+
2445
+ const newObj: any = { ...a, ...b };
2446
+ for (const key of sharedKeys) {
2447
+ const sharedValue = mergeValues(a[key], b[key]);
2448
+ if (!sharedValue.valid) {
2449
+ return {
2450
+ valid: false,
2451
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
2452
+ };
2453
+ }
2454
+ newObj[key] = sharedValue.data;
2455
+ }
2456
+
2457
+ return { valid: true, data: newObj };
2458
+ }
2459
+ if (Array.isArray(a) && Array.isArray(b)) {
2460
+ if (a.length !== b.length) {
2461
+ return { valid: false, mergeErrorPath: [] };
2462
+ }
2463
+
2464
+ const newArray: unknown[] = [];
2465
+ for (let index = 0; index < a.length; index++) {
2466
+ const itemA = a[index];
2467
+ const itemB = b[index];
2468
+ const sharedValue = mergeValues(itemA, itemB);
2469
+
2470
+ if (!sharedValue.valid) {
2471
+ return {
2472
+ valid: false,
2473
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
2474
+ };
2475
+ }
2476
+
2477
+ newArray.push(sharedValue.data);
2478
+ }
2479
+
2480
+ return { valid: true, data: newArray };
2481
+ }
2482
+
2483
+ return { valid: false, mergeErrorPath: [] };
2484
+ }
2485
+
2486
+ function handleIntersectionResults(result: ParsePayload, left: ParsePayload, right: ParsePayload): ParsePayload {
2487
+ // Track which side(s) report each key as unrecognized
2488
+ const unrecKeys = new Map<string, { l?: true; r?: true }>();
2489
+ let unrecIssue: errors.$ZodRawIssue | undefined;
2490
+
2491
+ for (const iss of left.issues) {
2492
+ if (iss.code === "unrecognized_keys") {
2493
+ unrecIssue ??= iss;
2494
+ for (const k of iss.keys) {
2495
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
2496
+ unrecKeys.get(k)!.l = true;
2497
+ }
2498
+ } else {
2499
+ result.issues.push(iss);
2500
+ }
2501
+ }
2502
+
2503
+ for (const iss of right.issues) {
2504
+ if (iss.code === "unrecognized_keys") {
2505
+ for (const k of iss.keys) {
2506
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
2507
+ unrecKeys.get(k)!.r = true;
2508
+ }
2509
+ } else {
2510
+ result.issues.push(iss);
2511
+ }
2512
+ }
2513
+
2514
+ // Report only keys unrecognized by BOTH sides
2515
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
2516
+ if (bothKeys.length && unrecIssue) {
2517
+ result.issues.push({ ...unrecIssue, keys: bothKeys });
2518
+ }
2519
+
2520
+ if (util.aborted(result)) return result;
2521
+
2522
+ const merged = mergeValues(left.value, right.value);
2523
+
2524
+ if (!merged.valid) {
2525
+ throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
2526
+ }
2527
+
2528
+ result.value = merged.data;
2529
+ return result;
2530
+ }
2531
+
2532
+ /////////////////////////////////////////
2533
+ /////////////////////////////////////////
2534
+ ////////// //////////
2535
+ ////////// $ZodTuple //////////
2536
+ ////////// //////////
2537
+ /////////////////////////////////////////
2538
+ /////////////////////////////////////////
2539
+
2540
+ export interface $ZodTupleDef<
2541
+ T extends util.TupleItems = readonly $ZodType[],
2542
+ Rest extends SomeType | null = $ZodType | null,
2543
+ > extends $ZodTypeDef {
2544
+ type: "tuple";
2545
+ items: T;
2546
+ rest: Rest;
2547
+ }
2548
+
2549
+ export type $InferTupleInputType<T extends util.TupleItems, Rest extends SomeType | null> = [
2550
+ ...TupleInputTypeWithOptionals<T>,
2551
+ ...(Rest extends SomeType ? core.input<Rest>[] : []),
2552
+ ];
2553
+ type TupleInputTypeNoOptionals<T extends util.TupleItems> = {
2554
+ [k in keyof T]: core.input<T[k]>;
2555
+ };
2556
+ type TupleInputTypeWithOptionals<T extends util.TupleItems> = T extends readonly [
2557
+ ...infer Prefix extends SomeType[],
2558
+ infer Tail extends SomeType,
2559
+ ]
2560
+ ? Tail["_zod"]["optin"] extends "optional"
2561
+ ? [...TupleInputTypeWithOptionals<Prefix>, core.input<Tail>?]
2562
+ : TupleInputTypeNoOptionals<T>
2563
+ : [];
2564
+
2565
+ export type $InferTupleOutputType<T extends util.TupleItems, Rest extends SomeType | null> = [
2566
+ ...TupleOutputTypeWithOptionals<T>,
2567
+ ...(Rest extends SomeType ? core.output<Rest>[] : []),
2568
+ ];
2569
+ type TupleOutputTypeNoOptionals<T extends util.TupleItems> = {
2570
+ [k in keyof T]: core.output<T[k]>;
2571
+ };
2572
+ type TupleOutputTypeWithOptionals<T extends util.TupleItems> = T extends readonly [
2573
+ ...infer Prefix extends SomeType[],
2574
+ infer Tail extends SomeType,
2575
+ ]
2576
+ ? Tail["_zod"]["optout"] extends "optional"
2577
+ ? [...TupleOutputTypeWithOptionals<Prefix>, core.output<Tail>?]
2578
+ : TupleOutputTypeNoOptionals<T>
2579
+ : [];
2580
+
2581
+ export interface $ZodTupleInternals<
2582
+ T extends util.TupleItems = readonly $ZodType[],
2583
+ Rest extends SomeType | null = $ZodType | null,
2584
+ > extends _$ZodTypeInternals {
2585
+ def: $ZodTupleDef<T, Rest>;
2586
+ isst: errors.$ZodIssueInvalidType | errors.$ZodIssueTooBig<unknown[]> | errors.$ZodIssueTooSmall<unknown[]>;
2587
+ // $ZodTypeInternals<$InferTupleOutputType<T, Rest>, $InferTupleInputType<T, Rest>>
2588
+ output: $InferTupleOutputType<T, Rest>;
2589
+ input: $InferTupleInputType<T, Rest>;
2590
+ }
2591
+
2592
+ export interface $ZodTuple<
2593
+ T extends util.TupleItems = readonly $ZodType[],
2594
+ Rest extends SomeType | null = $ZodType | null,
2595
+ > extends $ZodType {
2596
+ _zod: $ZodTupleInternals<T, Rest>;
2597
+ }
2598
+
2599
+ export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def) => {
2600
+ $ZodType.init(inst, def);
2601
+ const items = def.items;
2602
+
2603
+ inst._zod.parse = (payload, ctx) => {
2604
+ const input = payload.value;
2605
+ if (!Array.isArray(input)) {
2606
+ payload.issues.push({
2607
+ input,
2608
+ inst,
2609
+ expected: "tuple",
2610
+ code: "invalid_type",
2611
+ });
2612
+ return payload;
2613
+ }
2614
+
2615
+ payload.value = [];
2616
+ const proms: Promise<any>[] = [];
2617
+
2618
+ const reversedIndex = [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
2619
+ const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;
2620
+
2621
+ if (!def.rest) {
2622
+ const tooBig = input.length > items.length;
2623
+ const tooSmall = input.length < optStart - 1;
2624
+ if (tooBig || tooSmall) {
2625
+ payload.issues.push({
2626
+ ...(tooBig
2627
+ ? { code: "too_big", maximum: items.length, inclusive: true }
2628
+ : { code: "too_small", minimum: items.length }),
2629
+
2630
+ input,
2631
+ inst,
2632
+ origin: "array" as const,
2633
+ });
2634
+ return payload;
2635
+ }
2636
+ }
2637
+
2638
+ let i = -1;
2639
+ for (const item of items) {
2640
+ i++;
2641
+ if (i >= input.length) if (i >= optStart) continue;
2642
+ const result = item._zod.run(
2643
+ {
2644
+ value: input[i],
2645
+ issues: [],
2646
+ },
2647
+ ctx
2648
+ );
2649
+
2650
+ if (result instanceof Promise) {
2651
+ proms.push(result.then((result) => handleTupleResult(result, payload, i)));
2652
+ } else {
2653
+ handleTupleResult(result, payload, i);
2654
+ }
2655
+ }
2656
+
2657
+ if (def.rest) {
2658
+ const rest = input.slice(items.length);
2659
+ for (const el of rest) {
2660
+ i++;
2661
+ const result = def.rest._zod.run(
2662
+ {
2663
+ value: el,
2664
+ issues: [],
2665
+ },
2666
+ ctx
2667
+ );
2668
+
2669
+ if (result instanceof Promise) {
2670
+ proms.push(result.then((result) => handleTupleResult(result, payload, i)));
2671
+ } else {
2672
+ handleTupleResult(result, payload, i);
2673
+ }
2674
+ }
2675
+ }
2676
+
2677
+ if (proms.length) return Promise.all(proms).then(() => payload);
2678
+ return payload;
2679
+ };
2680
+ });
2681
+
2682
+ function handleTupleResult(result: ParsePayload, final: ParsePayload<any[]>, index: number) {
2683
+ if (result.issues.length) {
2684
+ final.issues.push(...util.prefixIssues(index, result.issues));
2685
+ }
2686
+ final.value[index] = result.value;
2687
+ }
2688
+
2689
+ //////////////////////////////////////////
2690
+ //////////////////////////////////////////
2691
+ ////////// //////////
2692
+ ////////// $ZodRecord //////////
2693
+ ////////// //////////
2694
+ //////////////////////////////////////////
2695
+ //////////////////////////////////////////
2696
+
2697
+ export type $ZodRecordKey = $ZodType<string | number | symbol, unknown>; // $HasValues | $HasPattern;
2698
+ export interface $ZodRecordDef<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType>
2699
+ extends $ZodTypeDef {
2700
+ type: "record";
2701
+ keyType: Key;
2702
+ valueType: Value;
2703
+ /** @default "strict" - errors on keys not matching keyType. "loose" passes through non-matching keys unchanged. */
2704
+ mode?: "strict" | "loose";
2705
+ }
2706
+
2707
+ // export type $InferZodRecordOutput<
2708
+ // Key extends $ZodRecordKey = $ZodRecordKey,
2709
+ // Value extends SomeType = $ZodType,
2710
+ // > = undefined extends Key["_zod"]["values"]
2711
+ // ? string extends core.output<Key>
2712
+ // ? Record<core.output<Key>, core.output<Value>>
2713
+ // : number extends core.output<Key>
2714
+ // ? Record<core.output<Key>, core.output<Value>>
2715
+ // : symbol extends core.output<Key>
2716
+ // ? Record<core.output<Key>, core.output<Value>>
2717
+ // : Record<core.output<Key>, core.output<Value>>
2718
+ // : Record<core.output<Key>, core.output<Value>>;
2719
+ export type $InferZodRecordOutput<
2720
+ Key extends $ZodRecordKey = $ZodRecordKey,
2721
+ Value extends SomeType = $ZodType,
2722
+ > = Key extends $partial
2723
+ ? Partial<Record<core.output<Key>, core.output<Value>>>
2724
+ : Record<core.output<Key>, core.output<Value>>;
2725
+
2726
+ // export type $InferZodRecordInput<
2727
+ // Key extends $ZodRecordKey = $ZodRecordKey,
2728
+ // Value extends SomeType = $ZodType,
2729
+ // > = undefined extends Key["_zod"]["values"]
2730
+ // ? string extends core.input<Key>
2731
+ // ? Record<core.input<Key>, core.input<Value>>
2732
+ // : number extends core.input<Key>
2733
+ // ? Record<core.input<Key>, core.input<Value>>
2734
+ // : symbol extends core.input<Key>
2735
+ // ? Record<core.input<Key>, core.input<Value>>
2736
+ // : Record<core.input<Key>, core.input<Value>>
2737
+ // : Record<core.input<Key>, core.input<Value>>;
2738
+
2739
+ export type $InferZodRecordInput<
2740
+ Key extends $ZodRecordKey = $ZodRecordKey,
2741
+ Value extends SomeType = $ZodType,
2742
+ > = Key extends $partial
2743
+ ? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>>
2744
+ : Record<core.input<Key> & PropertyKey, core.input<Value>>;
2745
+
2746
+ export interface $ZodRecordInternals<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType>
2747
+ extends $ZodTypeInternals<$InferZodRecordOutput<Key, Value>, $InferZodRecordInput<Key, Value>> {
2748
+ def: $ZodRecordDef<Key, Value>;
2749
+ isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey<Record<PropertyKey, unknown>>;
2750
+ optin?: "optional" | undefined;
2751
+ optout?: "optional" | undefined;
2752
+ }
2753
+
2754
+ export type $partial = { "~~partial": true };
2755
+ export interface $ZodRecord<Key extends $ZodRecordKey = $ZodRecordKey, Value extends SomeType = $ZodType>
2756
+ extends $ZodType {
2757
+ _zod: $ZodRecordInternals<Key, Value>;
2758
+ }
2759
+
2760
+ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, def) => {
2761
+ $ZodType.init(inst, def);
2762
+
2763
+ inst._zod.parse = (payload, ctx) => {
2764
+ const input = payload.value;
2765
+
2766
+ if (!util.isPlainObject(input)) {
2767
+ payload.issues.push({
2768
+ expected: "record",
2769
+ code: "invalid_type",
2770
+
2771
+ input,
2772
+ inst,
2773
+ });
2774
+ return payload;
2775
+ }
2776
+
2777
+ const proms: Promise<any>[] = [];
2778
+
2779
+ const values = def.keyType._zod.values;
2780
+ if (values) {
2781
+ payload.value = {};
2782
+ const recordKeys = new Set<string | symbol>();
2783
+ for (const key of values) {
2784
+ if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
2785
+ recordKeys.add(typeof key === "number" ? key.toString() : key);
2786
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
2787
+
2788
+ if (result instanceof Promise) {
2789
+ proms.push(
2790
+ result.then((result) => {
2791
+ if (result.issues.length) {
2792
+ payload.issues.push(...util.prefixIssues(key, result.issues));
2793
+ }
2794
+ payload.value[key] = result.value;
2795
+ })
2796
+ );
2797
+ } else {
2798
+ if (result.issues.length) {
2799
+ payload.issues.push(...util.prefixIssues(key, result.issues));
2800
+ }
2801
+ payload.value[key] = result.value;
2802
+ }
2803
+ }
2804
+ }
2805
+
2806
+ let unrecognized!: string[];
2807
+ for (const key in input) {
2808
+ if (!recordKeys.has(key)) {
2809
+ unrecognized = unrecognized ?? [];
2810
+ unrecognized.push(key);
2811
+ }
2812
+ }
2813
+ if (unrecognized && unrecognized.length > 0) {
2814
+ payload.issues.push({
2815
+ code: "unrecognized_keys",
2816
+
2817
+ input,
2818
+ inst,
2819
+ keys: unrecognized,
2820
+ });
2821
+ }
2822
+ } else {
2823
+ payload.value = {};
2824
+ for (const key of Reflect.ownKeys(input)) {
2825
+ if (key === "__proto__") continue;
2826
+ let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
2827
+ if (keyResult instanceof Promise) {
2828
+ throw new Error("Async schemas not supported in object keys currently");
2829
+ }
2830
+
2831
+ // Numeric string fallback: if key is a numeric string and failed, retry with Number(key)
2832
+ // This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
2833
+ const checkNumericKey = typeof key === "string" && regexes.number.test(key) && keyResult.issues.length;
2834
+ if (checkNumericKey) {
2835
+ const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
2836
+ if (retryResult instanceof Promise) {
2837
+ throw new Error("Async schemas not supported in object keys currently");
2838
+ }
2839
+ if (retryResult.issues.length === 0) {
2840
+ keyResult = retryResult;
2841
+ }
2842
+ }
2843
+
2844
+ if (keyResult.issues.length) {
2845
+ if (def.mode === "loose") {
2846
+ // Pass through unchanged
2847
+ payload.value[key] = input[key];
2848
+ } else {
2849
+ // Default "strict" behavior: error on invalid key
2850
+ payload.issues.push({
2851
+ code: "invalid_key",
2852
+ origin: "record",
2853
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
2854
+ input: key,
2855
+ path: [key],
2856
+ inst,
2857
+ });
2858
+ }
2859
+ continue;
2860
+ }
2861
+
2862
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
2863
+
2864
+ if (result instanceof Promise) {
2865
+ proms.push(
2866
+ result.then((result) => {
2867
+ if (result.issues.length) {
2868
+ payload.issues.push(...util.prefixIssues(key, result.issues));
2869
+ }
2870
+ payload.value[keyResult.value as PropertyKey] = result.value;
2871
+ })
2872
+ );
2873
+ } else {
2874
+ if (result.issues.length) {
2875
+ payload.issues.push(...util.prefixIssues(key, result.issues));
2876
+ }
2877
+ payload.value[keyResult.value as PropertyKey] = result.value;
2878
+ }
2879
+ }
2880
+ }
2881
+
2882
+ if (proms.length) {
2883
+ return Promise.all(proms).then(() => payload);
2884
+ }
2885
+ return payload;
2886
+ };
2887
+ });
2888
+
2889
+ ///////////////////////////////////////
2890
+ ///////////////////////////////////////
2891
+ ////////// //////////
2892
+ ////////// $ZodMap //////////
2893
+ ////////// //////////
2894
+ ///////////////////////////////////////
2895
+ ///////////////////////////////////////
2896
+ export interface $ZodMapDef<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodTypeDef {
2897
+ type: "map";
2898
+ keyType: Key;
2899
+ valueType: Value;
2900
+ }
2901
+
2902
+ export interface $ZodMapInternals<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType>
2903
+ extends $ZodTypeInternals<Map<core.output<Key>, core.output<Value>>, Map<core.input<Key>, core.input<Value>>> {
2904
+ def: $ZodMapDef<Key, Value>;
2905
+ isst: errors.$ZodIssueInvalidType | errors.$ZodIssueInvalidKey | errors.$ZodIssueInvalidElement<unknown>;
2906
+ optin?: "optional" | undefined;
2907
+ optout?: "optional" | undefined;
2908
+ }
2909
+
2910
+ export interface $ZodMap<Key extends SomeType = $ZodType, Value extends SomeType = $ZodType> extends $ZodType {
2911
+ _zod: $ZodMapInternals<Key, Value>;
2912
+ }
2913
+
2914
+ export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$constructor("$ZodMap", (inst, def) => {
2915
+ $ZodType.init(inst, def);
2916
+
2917
+ inst._zod.parse = (payload, ctx) => {
2918
+ const input = payload.value;
2919
+ if (!(input instanceof Map)) {
2920
+ payload.issues.push({
2921
+ expected: "map",
2922
+ code: "invalid_type",
2923
+
2924
+ input,
2925
+ inst,
2926
+ });
2927
+ return payload;
2928
+ }
2929
+
2930
+ const proms: Promise<any>[] = [];
2931
+ payload.value = new Map();
2932
+
2933
+ for (const [key, value] of input) {
2934
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
2935
+ const valueResult = def.valueType._zod.run({ value: value, issues: [] }, ctx);
2936
+
2937
+ if (keyResult instanceof Promise || valueResult instanceof Promise) {
2938
+ proms.push(
2939
+ Promise.all([keyResult, valueResult]).then(([keyResult, valueResult]) => {
2940
+ handleMapResult(keyResult, valueResult, payload, key, input, inst, ctx);
2941
+ })
2942
+ );
2943
+ } else {
2944
+ handleMapResult(keyResult as ParsePayload, valueResult as ParsePayload, payload, key, input, inst, ctx);
2945
+ }
2946
+ }
2947
+
2948
+ if (proms.length) return Promise.all(proms).then(() => payload);
2949
+ return payload;
2950
+ };
2951
+ });
2952
+
2953
+ function handleMapResult(
2954
+ keyResult: ParsePayload,
2955
+ valueResult: ParsePayload,
2956
+ final: ParsePayload<Map<unknown, unknown>>,
2957
+ key: unknown,
2958
+ input: Map<any, any>,
2959
+ inst: $ZodMap,
2960
+ ctx?: ParseContext | undefined
2961
+ ): void {
2962
+ if (keyResult.issues.length) {
2963
+ if (util.propertyKeyTypes.has(typeof key)) {
2964
+ final.issues.push(...util.prefixIssues(key as PropertyKey, keyResult.issues));
2965
+ } else {
2966
+ final.issues.push({
2967
+ code: "invalid_key",
2968
+
2969
+ origin: "map",
2970
+ input,
2971
+ inst,
2972
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
2973
+ });
2974
+ }
2975
+ }
2976
+ if (valueResult.issues.length) {
2977
+ if (util.propertyKeyTypes.has(typeof key)) {
2978
+ final.issues.push(...util.prefixIssues(key as PropertyKey, valueResult.issues));
2979
+ } else {
2980
+ final.issues.push({
2981
+ origin: "map",
2982
+ code: "invalid_element",
2983
+
2984
+ input,
2985
+ inst,
2986
+ key: key,
2987
+ issues: valueResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
2988
+ });
2989
+ }
2990
+ }
2991
+ final.value.set(keyResult.value, valueResult.value);
2992
+ }
2993
+
2994
+ ///////////////////////////////////////
2995
+ ///////////////////////////////////////
2996
+ ////////// //////////
2997
+ ////////// $ZodSet //////////
2998
+ ////////// //////////
2999
+ ///////////////////////////////////////
3000
+ ///////////////////////////////////////
3001
+ export interface $ZodSetDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
3002
+ type: "set";
3003
+ valueType: T;
3004
+ }
3005
+
3006
+ export interface $ZodSetInternals<T extends SomeType = $ZodType>
3007
+ extends $ZodTypeInternals<Set<core.output<T>>, Set<core.input<T>>> {
3008
+ def: $ZodSetDef<T>;
3009
+ isst: errors.$ZodIssueInvalidType;
3010
+ optin?: "optional" | undefined;
3011
+ optout?: "optional" | undefined;
3012
+ }
3013
+
3014
+ export interface $ZodSet<T extends SomeType = $ZodType> extends $ZodType {
3015
+ _zod: $ZodSetInternals<T>;
3016
+ }
3017
+
3018
+ export const $ZodSet: core.$constructor<$ZodSet> = /*@__PURE__*/ core.$constructor("$ZodSet", (inst, def) => {
3019
+ $ZodType.init(inst, def);
3020
+
3021
+ inst._zod.parse = (payload, ctx) => {
3022
+ const input = payload.value;
3023
+ if (!(input instanceof Set)) {
3024
+ payload.issues.push({
3025
+ input,
3026
+ inst,
3027
+ expected: "set",
3028
+ code: "invalid_type",
3029
+ });
3030
+ return payload;
3031
+ }
3032
+
3033
+ const proms: Promise<any>[] = [];
3034
+ payload.value = new Set();
3035
+ for (const item of input) {
3036
+ const result = def.valueType._zod.run({ value: item, issues: [] }, ctx);
3037
+ if (result instanceof Promise) {
3038
+ proms.push(result.then((result) => handleSetResult(result, payload)));
3039
+ } else handleSetResult(result, payload);
3040
+ }
3041
+
3042
+ if (proms.length) return Promise.all(proms).then(() => payload);
3043
+ return payload;
3044
+ };
3045
+ });
3046
+
3047
+ function handleSetResult(result: ParsePayload, final: ParsePayload<Set<any>>) {
3048
+ if (result.issues.length) {
3049
+ final.issues.push(...result.issues);
3050
+ }
3051
+ final.value.add(result.value);
3052
+ }
3053
+
3054
+ ////////////////////////////////////////
3055
+ ////////////////////////////////////////
3056
+ ////////// //////////
3057
+ ////////// $ZodEnum //////////
3058
+ ////////// //////////
3059
+ ////////////////////////////////////////
3060
+ ////////////////////////////////////////
3061
+ export type $InferEnumOutput<T extends util.EnumLike> = T[keyof T] & {};
3062
+ export type $InferEnumInput<T extends util.EnumLike> = T[keyof T] & {};
3063
+
3064
+ export interface $ZodEnumDef<T extends util.EnumLike = util.EnumLike> extends $ZodTypeDef {
3065
+ type: "enum";
3066
+ entries: T;
3067
+ }
3068
+
3069
+ export interface $ZodEnumInternals<
3070
+ /** @ts-ignore Cast variance */
3071
+ out T extends util.EnumLike = util.EnumLike,
3072
+ > extends $ZodTypeInternals<$InferEnumOutput<T>, $InferEnumInput<T>> {
3073
+ // enum: T;
3074
+
3075
+ def: $ZodEnumDef<T>;
3076
+ /** @deprecated Internal API, use with caution (not deprecated) */
3077
+ values: util.PrimitiveSet;
3078
+ /** @deprecated Internal API, use with caution (not deprecated) */
3079
+ pattern: RegExp;
3080
+ isst: errors.$ZodIssueInvalidValue;
3081
+ }
3082
+
3083
+ export interface $ZodEnum<T extends util.EnumLike = util.EnumLike> extends $ZodType {
3084
+ _zod: $ZodEnumInternals<T>;
3085
+ }
3086
+
3087
+ export const $ZodEnum: core.$constructor<$ZodEnum> = /*@__PURE__*/ core.$constructor("$ZodEnum", (inst, def) => {
3088
+ $ZodType.init(inst, def);
3089
+
3090
+ const values = util.getEnumValues(def.entries);
3091
+ const valuesSet = new Set<util.Primitive>(values);
3092
+ inst._zod.values = valuesSet;
3093
+
3094
+ inst._zod.pattern = new RegExp(
3095
+ `^(${values
3096
+ .filter((k) => util.propertyKeyTypes.has(typeof k))
3097
+ .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o.toString()))
3098
+ .join("|")})$`
3099
+ );
3100
+
3101
+ inst._zod.parse = (payload, _ctx) => {
3102
+ const input = payload.value;
3103
+ if (valuesSet.has(input)) {
3104
+ return payload;
3105
+ }
3106
+ payload.issues.push({
3107
+ code: "invalid_value",
3108
+
3109
+ values,
3110
+ input,
3111
+ inst,
3112
+ });
3113
+ return payload;
3114
+ };
3115
+ });
3116
+
3117
+ ////////////////////////////////////////
3118
+ ////////////////////////////////////////
3119
+ ////////// //////////
3120
+ ////////// $ZodLiteral //////////
3121
+ ////////// //////////
3122
+ ////////////////////////////////////////
3123
+ ////////////////////////////////////////
3124
+
3125
+ export interface $ZodLiteralDef<T extends util.Literal> extends $ZodTypeDef {
3126
+ type: "literal";
3127
+ values: T[];
3128
+ }
3129
+
3130
+ export interface $ZodLiteralInternals<T extends util.Literal = util.Literal> extends $ZodTypeInternals<T, T> {
3131
+ def: $ZodLiteralDef<T>;
3132
+ values: Set<T>;
3133
+ pattern: RegExp;
3134
+ isst: errors.$ZodIssueInvalidValue;
3135
+ }
3136
+
3137
+ export interface $ZodLiteral<T extends util.Literal = util.Literal> extends $ZodType {
3138
+ _zod: $ZodLiteralInternals<T>;
3139
+ }
3140
+
3141
+ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$constructor(
3142
+ "$ZodLiteral",
3143
+ (inst, def) => {
3144
+ $ZodType.init(inst, def);
3145
+ if (def.values.length === 0) {
3146
+ throw new Error("Cannot create literal schema with no valid values");
3147
+ }
3148
+
3149
+ const values = new Set<util.Literal>(def.values);
3150
+ inst._zod.values = values;
3151
+ inst._zod.pattern = new RegExp(
3152
+ `^(${def.values
3153
+
3154
+ .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
3155
+ .join("|")})$`
3156
+ );
3157
+
3158
+ inst._zod.parse = (payload, _ctx) => {
3159
+ const input = payload.value;
3160
+ if (values.has(input)) {
3161
+ return payload;
3162
+ }
3163
+ payload.issues.push({
3164
+ code: "invalid_value",
3165
+
3166
+ values: def.values,
3167
+ input,
3168
+ inst,
3169
+ });
3170
+ return payload;
3171
+ };
3172
+ }
3173
+ );
3174
+
3175
+ ////////////////////////////////////////
3176
+ ////////////////////////////////////////
3177
+ ////////// //////////
3178
+ ////////// $ZodConst //////////
3179
+ ////////// //////////
3180
+ ////////////////////////////////////////
3181
+ ////////////////////////////////////////
3182
+
3183
+ // export interface $ZodConstDef extends $ZodTypeDef {
3184
+ // type: "const";
3185
+ // value: unknown;
3186
+ // }
3187
+
3188
+ // export _interface $ZodConstInternals<T extends util.Literal = util.Literal> extends $ZodTypeInternals<T, T> {
3189
+ // _def: $ZodConstDef;
3190
+ // _values: util.PrimitiveSet;
3191
+ // _pattern: RegExp;
3192
+ // _isst: errors.$ZodIssueInvalidValue;
3193
+ // }
3194
+
3195
+ // export const $ZodConst: core.$constructor<{_zod: $ZodConstInternals}> = /*@__PURE__*/ core.$constructor("$ZodConst", (inst, def) => {
3196
+ // $ZodType.init(inst, def);
3197
+
3198
+ // if (util.primitiveTypes.has(typeof def.value) || def.value === null) {
3199
+ // inst._zod.values = new Set<util.Primitive>(def.value as any);
3200
+ // }
3201
+
3202
+ // if (util.propertyKeyTypes.has(typeof def.value)) {
3203
+ // inst._zod.pattern = new RegExp(
3204
+ // `^(${typeof def.value === "string" ? util.escapeRegex(def.value) : (def.value as any).toString()})$`
3205
+ // );
3206
+ // } else {
3207
+ // throw new Error("Const value cannot be converted to regex");
3208
+ // }
3209
+
3210
+ // inst._zod.parse = (payload, _ctx) => {
3211
+ // payload.value = def.value; // always override
3212
+ // return payload;
3213
+ // };
3214
+ // });
3215
+
3216
+ //////////////////////////////////////////
3217
+ //////////////////////////////////////////
3218
+ ////////// //////////
3219
+ ////////// $ZodFile //////////
3220
+ ////////// //////////
3221
+ //////////////////////////////////////////
3222
+ //////////////////////////////////////////
3223
+
3224
+ // provide a fallback in case the File interface isn't provided in the environment
3225
+ type _File = typeof globalThis extends { File: infer F extends new (...args: any[]) => any } ? InstanceType<F> : {};
3226
+ /** Do not reference this directly. */
3227
+ export interface File extends _File {
3228
+ readonly type: string;
3229
+ readonly size: number;
3230
+ }
3231
+
3232
+ export interface $ZodFileDef extends $ZodTypeDef {
3233
+ type: "file";
3234
+ }
3235
+
3236
+ export interface $ZodFileInternals extends $ZodTypeInternals<File, File> {
3237
+ def: $ZodFileDef;
3238
+ isst: errors.$ZodIssueInvalidType;
3239
+ bag: util.LoosePartial<{
3240
+ minimum: number;
3241
+ maximum: number;
3242
+ mime: util.MimeTypes[];
3243
+ }>;
3244
+ }
3245
+
3246
+ export interface $ZodFile extends $ZodType {
3247
+ _zod: $ZodFileInternals;
3248
+ }
3249
+
3250
+ export const $ZodFile: core.$constructor<$ZodFile> = /*@__PURE__*/ core.$constructor("$ZodFile", (inst, def) => {
3251
+ $ZodType.init(inst, def);
3252
+
3253
+ inst._zod.parse = (payload, _ctx) => {
3254
+ const input = payload.value;
3255
+ // @ts-ignore
3256
+ if (input instanceof File) return payload;
3257
+ payload.issues.push({
3258
+ expected: "file",
3259
+ code: "invalid_type",
3260
+
3261
+ input,
3262
+ inst,
3263
+ });
3264
+ return payload;
3265
+ };
3266
+ });
3267
+
3268
+ //////////////////////////////////////////////
3269
+ //////////////////////////////////////////////
3270
+ ////////// //////////
3271
+ ////////// $ZodTransform //////////
3272
+ ////////// //////////
3273
+ //////////////////////////////////////////////
3274
+ //////////////////////////////////////////////
3275
+ export interface $ZodTransformDef extends $ZodTypeDef {
3276
+ type: "transform";
3277
+ transform: (input: unknown, payload: ParsePayload<unknown>) => util.MaybeAsync<unknown>;
3278
+ }
3279
+ export interface $ZodTransformInternals<O = unknown, I = unknown> extends $ZodTypeInternals<O, I> {
3280
+ def: $ZodTransformDef;
3281
+ isst: never;
3282
+ }
3283
+
3284
+ export interface $ZodTransform<O = unknown, I = unknown> extends $ZodType {
3285
+ _zod: $ZodTransformInternals<O, I>;
3286
+ }
3287
+
3288
+ export const $ZodTransform: core.$constructor<$ZodTransform> = /*@__PURE__*/ core.$constructor(
3289
+ "$ZodTransform",
3290
+ (inst, def) => {
3291
+ $ZodType.init(inst, def);
3292
+ inst._zod.parse = (payload, ctx) => {
3293
+ if (ctx.direction === "backward") {
3294
+ throw new core.$ZodEncodeError(inst.constructor.name);
3295
+ }
3296
+
3297
+ const _out = def.transform(payload.value, payload);
3298
+ if (ctx.async) {
3299
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
3300
+ return output.then((output) => {
3301
+ payload.value = output;
3302
+ return payload;
3303
+ });
3304
+ }
3305
+
3306
+ if (_out instanceof Promise) {
3307
+ throw new core.$ZodAsyncError();
3308
+ }
3309
+
3310
+ payload.value = _out;
3311
+ return payload;
3312
+ };
3313
+ }
3314
+ );
3315
+
3316
+ ////////////////////////////////////////////
3317
+ ////////////////////////////////////////////
3318
+ ////////// //////////
3319
+ ////////// $ZodOptional //////////
3320
+ ////////// //////////
3321
+ ////////////////////////////////////////////
3322
+ ////////////////////////////////////////////
3323
+ export interface $ZodOptionalDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
3324
+ type: "optional";
3325
+ innerType: T;
3326
+ }
3327
+
3328
+ export interface $ZodOptionalInternals<T extends SomeType = $ZodType>
3329
+ extends $ZodTypeInternals<core.output<T> | undefined, core.input<T> | undefined> {
3330
+ def: $ZodOptionalDef<T>;
3331
+ optin: "optional";
3332
+ optout: "optional";
3333
+ isst: never;
3334
+ values: T["_zod"]["values"];
3335
+ pattern: T["_zod"]["pattern"];
3336
+ }
3337
+
3338
+ export interface $ZodOptional<T extends SomeType = $ZodType> extends $ZodType {
3339
+ _zod: $ZodOptionalInternals<T>;
3340
+ }
3341
+
3342
+ function handleOptionalResult(result: ParsePayload, input: unknown) {
3343
+ if (result.issues.length && input === undefined) {
3344
+ return { issues: [], value: undefined };
3345
+ }
3346
+ return result;
3347
+ }
3348
+
3349
+ export const $ZodOptional: core.$constructor<$ZodOptional> = /*@__PURE__*/ core.$constructor(
3350
+ "$ZodOptional",
3351
+ (inst, def) => {
3352
+ $ZodType.init(inst, def);
3353
+ inst._zod.optin = "optional";
3354
+ inst._zod.optout = "optional";
3355
+
3356
+ util.defineLazy(inst._zod, "values", () => {
3357
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
3358
+ });
3359
+ util.defineLazy(inst._zod, "pattern", () => {
3360
+ const pattern = def.innerType._zod.pattern;
3361
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)})?$`) : undefined;
3362
+ });
3363
+
3364
+ inst._zod.parse = (payload, ctx) => {
3365
+ if (def.innerType._zod.optin === "optional") {
3366
+ const result = def.innerType._zod.run(payload, ctx);
3367
+ if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, payload.value));
3368
+ return handleOptionalResult(result, payload.value);
3369
+ }
3370
+ if (payload.value === undefined) {
3371
+ return payload;
3372
+ }
3373
+ return def.innerType._zod.run(payload, ctx);
3374
+ };
3375
+ }
3376
+ );
3377
+
3378
+ ////////////////////////////////////////////////
3379
+ ////////////////////////////////////////////////
3380
+ ////////// //////////
3381
+ ////////// $ZodExactOptional //////////
3382
+ ////////// //////////
3383
+ ////////////////////////////////////////////////
3384
+ ////////////////////////////////////////////////
3385
+
3386
+ // Def extends $ZodOptionalDef (no additional fields needed)
3387
+ export interface $ZodExactOptionalDef<T extends SomeType = $ZodType> extends $ZodOptionalDef<T> {}
3388
+
3389
+ // Internals extends $ZodOptionalInternals but narrows output/input types (removes | undefined)
3390
+ export interface $ZodExactOptionalInternals<T extends SomeType = $ZodType> extends $ZodOptionalInternals<T> {
3391
+ def: $ZodExactOptionalDef<T>;
3392
+ output: core.output<T>; // NO | undefined (narrowed from parent)
3393
+ input: core.input<T>; // NO | undefined (narrowed from parent)
3394
+ }
3395
+
3396
+ export interface $ZodExactOptional<T extends SomeType = $ZodType> extends $ZodType {
3397
+ _zod: $ZodExactOptionalInternals<T>;
3398
+ }
3399
+
3400
+ export const $ZodExactOptional: core.$constructor<$ZodExactOptional> = /*@__PURE__*/ core.$constructor(
3401
+ "$ZodExactOptional",
3402
+ (inst, def) => {
3403
+ // Call parent init - inherits optin/optout = "optional"
3404
+ $ZodOptional.init(inst, def);
3405
+
3406
+ // Override values/pattern to NOT add undefined
3407
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
3408
+ util.defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
3409
+
3410
+ // Override parse to just delegate (no undefined handling)
3411
+ inst._zod.parse = (payload, ctx) => {
3412
+ return def.innerType._zod.run(payload, ctx);
3413
+ };
3414
+ }
3415
+ );
3416
+
3417
+ ////////////////////////////////////////////
3418
+ ////////////////////////////////////////////
3419
+ ////////// //////////
3420
+ ////////// $ZodNullable //////////
3421
+ ////////// //////////
3422
+ ////////////////////////////////////////////
3423
+ ////////////////////////////////////////////
3424
+ export interface $ZodNullableDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
3425
+ type: "nullable";
3426
+ innerType: T;
3427
+ }
3428
+
3429
+ export interface $ZodNullableInternals<T extends SomeType = $ZodType>
3430
+ extends $ZodTypeInternals<core.output<T> | null, core.input<T> | null> {
3431
+ def: $ZodNullableDef<T>;
3432
+ optin: T["_zod"]["optin"];
3433
+ optout: T["_zod"]["optout"];
3434
+ isst: never;
3435
+ values: T["_zod"]["values"];
3436
+ pattern: T["_zod"]["pattern"];
3437
+ }
3438
+
3439
+ export interface $ZodNullable<T extends SomeType = $ZodType> extends $ZodType {
3440
+ _zod: $ZodNullableInternals<T>;
3441
+ }
3442
+
3443
+ export const $ZodNullable: core.$constructor<$ZodNullable> = /*@__PURE__*/ core.$constructor(
3444
+ "$ZodNullable",
3445
+ (inst, def) => {
3446
+ $ZodType.init(inst, def);
3447
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
3448
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
3449
+
3450
+ util.defineLazy(inst._zod, "pattern", () => {
3451
+ const pattern = def.innerType._zod.pattern;
3452
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)}|null)$`) : undefined;
3453
+ });
3454
+
3455
+ util.defineLazy(inst._zod, "values", () => {
3456
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
3457
+ });
3458
+
3459
+ inst._zod.parse = (payload, ctx) => {
3460
+ // Forward direction (decode): allow null to pass through
3461
+ if (payload.value === null) return payload;
3462
+ return def.innerType._zod.run(payload, ctx);
3463
+ };
3464
+ }
3465
+ );
3466
+ // );
3467
+
3468
+ ////////////////////////////////////////////
3469
+ ////////////////////////////////////////////
3470
+ ////////// //////////
3471
+ ////////// $ZodDefault //////////
3472
+ ////////// //////////
3473
+ ////////////////////////////////////////////
3474
+ ////////////////////////////////////////////
3475
+ export interface $ZodDefaultDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
3476
+ type: "default";
3477
+ innerType: T;
3478
+ /** The default value. May be a getter. */
3479
+ defaultValue: util.NoUndefined<core.output<T>>;
3480
+ }
3481
+
3482
+ export interface $ZodDefaultInternals<T extends SomeType = $ZodType>
3483
+ extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
3484
+ def: $ZodDefaultDef<T>;
3485
+ optin: "optional";
3486
+ optout?: "optional" | undefined; // required
3487
+ isst: never;
3488
+ values: T["_zod"]["values"];
3489
+ }
3490
+
3491
+ export interface $ZodDefault<T extends SomeType = $ZodType> extends $ZodType {
3492
+ _zod: $ZodDefaultInternals<T>;
3493
+ }
3494
+
3495
+ export const $ZodDefault: core.$constructor<$ZodDefault> = /*@__PURE__*/ core.$constructor(
3496
+ "$ZodDefault",
3497
+ (inst, def) => {
3498
+ $ZodType.init(inst, def);
3499
+
3500
+ // inst._zod.qin = "true";
3501
+ inst._zod.optin = "optional";
3502
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
3503
+
3504
+ inst._zod.parse = (payload, ctx) => {
3505
+ if (ctx.direction === "backward") {
3506
+ return def.innerType._zod.run(payload, ctx);
3507
+ }
3508
+
3509
+ // Forward direction (decode): apply defaults for undefined input
3510
+ if (payload.value === undefined) {
3511
+ payload.value = def.defaultValue;
3512
+ /**
3513
+ * $ZodDefault returns the default value immediately in forward direction.
3514
+ * 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. */
3515
+ return payload;
3516
+ }
3517
+ // Forward direction: continue with default handling
3518
+ const result = def.innerType._zod.run(payload, ctx);
3519
+ if (result instanceof Promise) {
3520
+ return result.then((result) => handleDefaultResult(result, def));
3521
+ }
3522
+ return handleDefaultResult(result, def);
3523
+ };
3524
+ }
3525
+ );
3526
+
3527
+ function handleDefaultResult(payload: ParsePayload, def: $ZodDefaultDef) {
3528
+ if (payload.value === undefined) {
3529
+ payload.value = def.defaultValue;
3530
+ }
3531
+ return payload;
3532
+ }
3533
+
3534
+ ////////////////////////////////////////////
3535
+ ////////////////////////////////////////////
3536
+ ////////// //////////
3537
+ ////////// $ZodPrefault //////////
3538
+ ////////// //////////
3539
+ ////////////////////////////////////////////
3540
+ ////////////////////////////////////////////
3541
+
3542
+ export interface $ZodPrefaultDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
3543
+ type: "prefault";
3544
+ innerType: T;
3545
+ /** The default value. May be a getter. */
3546
+ defaultValue: core.input<T>;
3547
+ }
3548
+
3549
+ export interface $ZodPrefaultInternals<T extends SomeType = $ZodType>
3550
+ extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, core.input<T> | undefined> {
3551
+ def: $ZodPrefaultDef<T>;
3552
+ optin: "optional";
3553
+ optout?: "optional" | undefined;
3554
+ isst: never;
3555
+ values: T["_zod"]["values"];
3556
+ }
3557
+
3558
+ export interface $ZodPrefault<T extends SomeType = $ZodType> extends $ZodType {
3559
+ _zod: $ZodPrefaultInternals<T>;
3560
+ }
3561
+
3562
+ export const $ZodPrefault: core.$constructor<$ZodPrefault> = /*@__PURE__*/ core.$constructor(
3563
+ "$ZodPrefault",
3564
+ (inst, def) => {
3565
+ $ZodType.init(inst, def);
3566
+
3567
+ inst._zod.optin = "optional";
3568
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
3569
+
3570
+ inst._zod.parse = (payload, ctx) => {
3571
+ if (ctx.direction === "backward") {
3572
+ return def.innerType._zod.run(payload, ctx);
3573
+ }
3574
+
3575
+ // Forward direction (decode): apply prefault for undefined input
3576
+ if (payload.value === undefined) {
3577
+ payload.value = def.defaultValue;
3578
+ }
3579
+ return def.innerType._zod.run(payload, ctx);
3580
+ };
3581
+ }
3582
+ );
3583
+
3584
+ ///////////////////////////////////////////////
3585
+ ///////////////////////////////////////////////
3586
+ ////////// //////////
3587
+ ////////// $ZodNonOptional //////////
3588
+ ////////// //////////
3589
+ ///////////////////////////////////////////////
3590
+ ///////////////////////////////////////////////
3591
+ export interface $ZodNonOptionalDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
3592
+ type: "nonoptional";
3593
+ innerType: T;
3594
+ }
3595
+
3596
+ export interface $ZodNonOptionalInternals<T extends SomeType = $ZodType>
3597
+ extends $ZodTypeInternals<util.NoUndefined<core.output<T>>, util.NoUndefined<core.input<T>>> {
3598
+ def: $ZodNonOptionalDef<T>;
3599
+ isst: errors.$ZodIssueInvalidType;
3600
+ values: T["_zod"]["values"];
3601
+ optin: "optional" | undefined;
3602
+ optout: "optional" | undefined;
3603
+ }
3604
+
3605
+ export interface $ZodNonOptional<T extends SomeType = $ZodType> extends $ZodType {
3606
+ _zod: $ZodNonOptionalInternals<T>;
3607
+ }
3608
+
3609
+ export const $ZodNonOptional: core.$constructor<$ZodNonOptional> = /*@__PURE__*/ core.$constructor(
3610
+ "$ZodNonOptional",
3611
+ (inst, def) => {
3612
+ $ZodType.init(inst, def);
3613
+
3614
+ util.defineLazy(inst._zod, "values", () => {
3615
+ const v = def.innerType._zod.values;
3616
+ return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
3617
+ });
3618
+
3619
+ inst._zod.parse = (payload, ctx) => {
3620
+ const result = def.innerType._zod.run(payload, ctx);
3621
+ if (result instanceof Promise) {
3622
+ return result.then((result) => handleNonOptionalResult(result, inst));
3623
+ }
3624
+ return handleNonOptionalResult(result, inst);
3625
+ };
3626
+ }
3627
+ );
3628
+
3629
+ function handleNonOptionalResult(payload: ParsePayload, inst: $ZodNonOptional) {
3630
+ if (!payload.issues.length && payload.value === undefined) {
3631
+ payload.issues.push({
3632
+ code: "invalid_type",
3633
+ expected: "nonoptional",
3634
+ input: payload.value,
3635
+ inst,
3636
+ });
3637
+ }
3638
+ return payload;
3639
+ }
3640
+
3641
+ ////////////////////////////////////////////
3642
+ ////////////////////////////////////////////
3643
+ ////////// //////////
3644
+ ////////// $ZodCoalesce //////////
3645
+ ////////// //////////
3646
+ ////////////////////////////////////////////
3647
+ ////////////////////////////////////////////
3648
+ // export interface $ZodCoalesceDef<T extends $ZodType = $ZodType> extends $ZodTypeDef {
3649
+ // type: "coalesce";
3650
+ // innerType: T;
3651
+ // defaultValue: () => NonNullable<T['_zod']["output"]>;
3652
+ // }
3653
+
3654
+ // export _interface $ZodCoalesceInternals<T extends $ZodType = $ZodType>
3655
+ // extends $ZodTypeInternals<NonNullable<T['_zod']["output"]>, T['_zod']["input"] | undefined | null> {
3656
+ // _def: $ZodCoalesceDef<T>;
3657
+ // _isst: errors.$ZodIssueInvalidType;
3658
+ // _qin: "true";
3659
+ // }
3660
+
3661
+ // function handleCoalesceResult(payload: ParsePayload, def: $ZodCoalesceDef) {
3662
+ // payload.value ??= def.defaultValue();
3663
+ // return payload;
3664
+ // }
3665
+
3666
+ // export const $ZodCoalesce: core.$constructor<{_zod: $ZodCoalesceInternals}> = /*@__PURE__*/ core.$constructor(
3667
+ // "$ZodCoalesce",
3668
+ // (inst, def) => {
3669
+ // $ZodType.init(inst, def);
3670
+ // inst._zod.qin = "true";
3671
+ // inst._zod.parse = (payload, ctx) => {
3672
+ // const result = def.innerType._zod.run(payload, ctx);
3673
+ // if (result instanceof Promise) {
3674
+ // return result.then((result) => handleCoalesceResult(result, def));
3675
+ // }
3676
+ // return handleCoalesceResult(result, def);
3677
+ // };
3678
+ // }
3679
+ // );
3680
+
3681
+ /////////////////////////////////////////////
3682
+ /////////////////////////////////////////////
3683
+ ////////// //////////
3684
+ ////////// $ZodSuccess //////////
3685
+ ////////// //////////
3686
+ /////////////////////////////////////////////
3687
+ /////////////////////////////////////////////
3688
+ export interface $ZodSuccessDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
3689
+ type: "success";
3690
+ innerType: T;
3691
+ }
3692
+
3693
+ export interface $ZodSuccessInternals<T extends SomeType = $ZodType> extends $ZodTypeInternals<boolean, core.input<T>> {
3694
+ def: $ZodSuccessDef<T>;
3695
+ isst: never;
3696
+ optin: T["_zod"]["optin"];
3697
+ optout: "optional" | undefined;
3698
+ }
3699
+
3700
+ export interface $ZodSuccess<T extends SomeType = $ZodType> extends $ZodType {
3701
+ _zod: $ZodSuccessInternals<T>;
3702
+ }
3703
+
3704
+ export const $ZodSuccess: core.$constructor<$ZodSuccess> = /*@__PURE__*/ core.$constructor(
3705
+ "$ZodSuccess",
3706
+ (inst, def) => {
3707
+ $ZodType.init(inst, def);
3708
+
3709
+ inst._zod.parse = (payload, ctx) => {
3710
+ if (ctx.direction === "backward") {
3711
+ throw new core.$ZodEncodeError("ZodSuccess");
3712
+ }
3713
+
3714
+ const result = def.innerType._zod.run(payload, ctx);
3715
+ if (result instanceof Promise) {
3716
+ return result.then((result) => {
3717
+ payload.value = result.issues.length === 0;
3718
+ return payload;
3719
+ });
3720
+ }
3721
+ payload.value = result.issues.length === 0;
3722
+ return payload;
3723
+ };
3724
+ }
3725
+ );
3726
+
3727
+ ////////////////////////////////////////////
3728
+ ////////////////////////////////////////////
3729
+ ////////// //////////
3730
+ ////////// $ZodCatch //////////
3731
+ ////////// //////////
3732
+ ////////////////////////////////////////////
3733
+ ////////////////////////////////////////////
3734
+ export interface $ZodCatchCtx extends ParsePayload {
3735
+ /** @deprecated Use `ctx.issues` */
3736
+ error: { issues: errors.$ZodIssue[] };
3737
+ /** @deprecated Use `ctx.value` */
3738
+ input: unknown;
3739
+ }
3740
+ export interface $ZodCatchDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
3741
+ type: "catch";
3742
+ innerType: T;
3743
+ catchValue: (ctx: $ZodCatchCtx) => unknown;
3744
+ }
3745
+
3746
+ export interface $ZodCatchInternals<T extends SomeType = $ZodType>
3747
+ extends $ZodTypeInternals<core.output<T>, core.input<T>> {
3748
+ def: $ZodCatchDef<T>;
3749
+ optin: T["_zod"]["optin"];
3750
+ optout: T["_zod"]["optout"];
3751
+ isst: never;
3752
+ values: T["_zod"]["values"];
3753
+ }
3754
+
3755
+ export interface $ZodCatch<T extends SomeType = $ZodType> extends $ZodType {
3756
+ _zod: $ZodCatchInternals<T>;
3757
+ }
3758
+
3759
+ export const $ZodCatch: core.$constructor<$ZodCatch> = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
3760
+ $ZodType.init(inst, def);
3761
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
3762
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
3763
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
3764
+
3765
+ inst._zod.parse = (payload, ctx) => {
3766
+ if (ctx.direction === "backward") {
3767
+ return def.innerType._zod.run(payload, ctx);
3768
+ }
3769
+
3770
+ // Forward direction (decode): apply catch logic
3771
+ const result = def.innerType._zod.run(payload, ctx);
3772
+ if (result instanceof Promise) {
3773
+ return result.then((result) => {
3774
+ payload.value = result.value;
3775
+ if (result.issues.length) {
3776
+ payload.value = def.catchValue({
3777
+ ...payload,
3778
+ error: {
3779
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
3780
+ },
3781
+ input: payload.value,
3782
+ });
3783
+ payload.issues = [];
3784
+ }
3785
+
3786
+ return payload;
3787
+ });
3788
+ }
3789
+
3790
+ payload.value = result.value;
3791
+ if (result.issues.length) {
3792
+ payload.value = def.catchValue({
3793
+ ...payload,
3794
+ error: {
3795
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
3796
+ },
3797
+ input: payload.value,
3798
+ });
3799
+
3800
+ payload.issues = [];
3801
+ }
3802
+
3803
+ return payload;
3804
+ };
3805
+ });
3806
+
3807
+ ////////////////////////////////////////////
3808
+ ////////////////////////////////////////////
3809
+ ////////// //////////
3810
+ ////////// $ZodNaN //////////
3811
+ ////////// //////////
3812
+ ////////////////////////////////////////////
3813
+ ////////////////////////////////////////////
3814
+ export interface $ZodNaNDef extends $ZodTypeDef {
3815
+ type: "nan";
3816
+ }
3817
+
3818
+ export interface $ZodNaNInternals extends $ZodTypeInternals<number, number> {
3819
+ def: $ZodNaNDef;
3820
+ isst: errors.$ZodIssueInvalidType;
3821
+ }
3822
+
3823
+ export interface $ZodNaN extends $ZodType {
3824
+ _zod: $ZodNaNInternals;
3825
+ }
3826
+
3827
+ export const $ZodNaN: core.$constructor<$ZodNaN> = /*@__PURE__*/ core.$constructor("$ZodNaN", (inst, def) => {
3828
+ $ZodType.init(inst, def);
3829
+
3830
+ inst._zod.parse = (payload, _ctx) => {
3831
+ if (typeof payload.value !== "number" || !Number.isNaN(payload.value)) {
3832
+ payload.issues.push({
3833
+ input: payload.value,
3834
+ inst,
3835
+ expected: "nan",
3836
+ code: "invalid_type",
3837
+ });
3838
+ return payload;
3839
+ }
3840
+ return payload;
3841
+ };
3842
+ });
3843
+
3844
+ ////////////////////////////////////////////
3845
+ ////////////////////////////////////////////
3846
+ ////////// //////////
3847
+ ////////// $ZodPipe //////////
3848
+ ////////// //////////
3849
+ ////////////////////////////////////////////
3850
+ ////////////////////////////////////////////
3851
+ export interface $ZodPipeDef<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeDef {
3852
+ type: "pipe";
3853
+ in: A;
3854
+ out: B;
3855
+ /** Only defined inside $ZodCodec instances. */
3856
+ transform?: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
3857
+ /** Only defined inside $ZodCodec instances. */
3858
+ reverseTransform?: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
3859
+ }
3860
+
3861
+ export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType>
3862
+ extends $ZodTypeInternals<core.output<B>, core.input<A>> {
3863
+ def: $ZodPipeDef<A, B>;
3864
+ isst: never;
3865
+ values: A["_zod"]["values"];
3866
+ optin: A["_zod"]["optin"];
3867
+ optout: B["_zod"]["optout"];
3868
+ propValues: A["_zod"]["propValues"];
3869
+ }
3870
+
3871
+ export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
3872
+ _zod: $ZodPipeInternals<A, B>;
3873
+ }
3874
+
3875
+ export const $ZodPipe: core.$constructor<$ZodPipe> = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def) => {
3876
+ $ZodType.init(inst, def);
3877
+ util.defineLazy(inst._zod, "values", () => def.in._zod.values);
3878
+ util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
3879
+ util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
3880
+ util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
3881
+
3882
+ inst._zod.parse = (payload, ctx) => {
3883
+ if (ctx.direction === "backward") {
3884
+ const right = def.out._zod.run(payload, ctx);
3885
+ if (right instanceof Promise) {
3886
+ return right.then((right) => handlePipeResult(right, def.in, ctx));
3887
+ }
3888
+ return handlePipeResult(right, def.in, ctx);
3889
+ }
3890
+
3891
+ const left = def.in._zod.run(payload, ctx);
3892
+ if (left instanceof Promise) {
3893
+ return left.then((left) => handlePipeResult(left, def.out, ctx));
3894
+ }
3895
+ return handlePipeResult(left, def.out, ctx);
3896
+ };
3897
+ });
3898
+
3899
+ function handlePipeResult(left: ParsePayload, next: $ZodType, ctx: ParseContextInternal) {
3900
+ if (left.issues.length) {
3901
+ // prevent further checks
3902
+ left.aborted = true;
3903
+ return left;
3904
+ }
3905
+ return next._zod.run({ value: left.value, issues: left.issues }, ctx);
3906
+ }
3907
+
3908
+ ////////////////////////////////////////////
3909
+ ////////////////////////////////////////////
3910
+ ////////// //////////
3911
+ ////////// $ZodCodec //////////
3912
+ ////////// //////////
3913
+ ////////////////////////////////////////////
3914
+ ////////////////////////////////////////////
3915
+ export interface $ZodCodecDef<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodPipeDef<A, B> {
3916
+ transform: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
3917
+ reverseTransform: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
3918
+ }
3919
+
3920
+ export interface $ZodCodecInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType>
3921
+ extends $ZodTypeInternals<core.output<B>, core.input<A>> {
3922
+ def: $ZodCodecDef<A, B>;
3923
+ isst: never;
3924
+ values: A["_zod"]["values"];
3925
+ optin: A["_zod"]["optin"];
3926
+ optout: B["_zod"]["optout"];
3927
+ propValues: A["_zod"]["propValues"];
3928
+ }
3929
+
3930
+ export interface $ZodCodec<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
3931
+ _zod: $ZodCodecInternals<A, B>;
3932
+ }
3933
+
3934
+ export const $ZodCodec: core.$constructor<$ZodCodec> = /*@__PURE__*/ core.$constructor("$ZodCodec", (inst, def) => {
3935
+ $ZodType.init(inst, def);
3936
+ util.defineLazy(inst._zod, "values", () => def.in._zod.values);
3937
+ util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
3938
+ util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
3939
+ util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
3940
+
3941
+ inst._zod.parse = (payload, ctx) => {
3942
+ const direction = ctx.direction || "forward";
3943
+ if (direction === "forward") {
3944
+ const left = def.in._zod.run(payload, ctx);
3945
+ if (left instanceof Promise) {
3946
+ return left.then((left) => handleCodecAResult(left, def, ctx));
3947
+ }
3948
+ return handleCodecAResult(left, def, ctx);
3949
+ } else {
3950
+ const right = def.out._zod.run(payload, ctx);
3951
+ if (right instanceof Promise) {
3952
+ return right.then((right) => handleCodecAResult(right, def, ctx));
3953
+ }
3954
+ return handleCodecAResult(right, def, ctx);
3955
+ }
3956
+ };
3957
+ });
3958
+
3959
+ function handleCodecAResult(result: ParsePayload, def: $ZodCodecDef, ctx: ParseContextInternal) {
3960
+ if (result.issues.length) {
3961
+ // prevent further checks
3962
+ result.aborted = true;
3963
+ return result;
3964
+ }
3965
+
3966
+ const direction = ctx.direction || "forward";
3967
+
3968
+ if (direction === "forward") {
3969
+ const transformed = def.transform(result.value, result);
3970
+ if (transformed instanceof Promise) {
3971
+ return transformed.then((value) => handleCodecTxResult(result, value, def.out, ctx));
3972
+ }
3973
+ return handleCodecTxResult(result, transformed, def.out, ctx);
3974
+ } else {
3975
+ const transformed = def.reverseTransform(result.value, result);
3976
+ if (transformed instanceof Promise) {
3977
+ return transformed.then((value) => handleCodecTxResult(result, value, def.in, ctx));
3978
+ }
3979
+ return handleCodecTxResult(result, transformed, def.in, ctx);
3980
+ }
3981
+ }
3982
+
3983
+ function handleCodecTxResult(left: ParsePayload, value: any, nextSchema: SomeType, ctx: ParseContextInternal) {
3984
+ // Check if transform added any issues
3985
+ if (left.issues.length) {
3986
+ left.aborted = true;
3987
+ return left;
3988
+ }
3989
+
3990
+ return nextSchema._zod.run({ value, issues: left.issues }, ctx);
3991
+ }
3992
+
3993
+ ////////////////////////////////////////////
3994
+ ////////////////////////////////////////////
3995
+ ////////// //////////
3996
+ ////////// $ZodReadonly //////////
3997
+ ////////// //////////
3998
+ ////////////////////////////////////////////
3999
+ ////////////////////////////////////////////
4000
+
4001
+ export interface $ZodReadonlyDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
4002
+ type: "readonly";
4003
+ innerType: T;
4004
+ }
4005
+
4006
+ export interface $ZodReadonlyInternals<T extends SomeType = $ZodType>
4007
+ extends $ZodTypeInternals<util.MakeReadonly<core.output<T>>, util.MakeReadonly<core.input<T>>> {
4008
+ def: $ZodReadonlyDef<T>;
4009
+ optin: T["_zod"]["optin"];
4010
+ optout: T["_zod"]["optout"];
4011
+ isst: never;
4012
+ propValues: T["_zod"]["propValues"];
4013
+ values: T["_zod"]["values"];
4014
+ }
4015
+
4016
+ export interface $ZodReadonly<T extends SomeType = $ZodType> extends $ZodType {
4017
+ _zod: $ZodReadonlyInternals<T>;
4018
+ }
4019
+
4020
+ export const $ZodReadonly: core.$constructor<$ZodReadonly> = /*@__PURE__*/ core.$constructor(
4021
+ "$ZodReadonly",
4022
+ (inst, def) => {
4023
+ $ZodType.init(inst, def);
4024
+ util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
4025
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
4026
+ util.defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
4027
+ util.defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
4028
+
4029
+ inst._zod.parse = (payload, ctx) => {
4030
+ if (ctx.direction === "backward") {
4031
+ return def.innerType._zod.run(payload, ctx);
4032
+ }
4033
+ const result = def.innerType._zod.run(payload, ctx);
4034
+ if (result instanceof Promise) {
4035
+ return result.then(handleReadonlyResult);
4036
+ }
4037
+ return handleReadonlyResult(result);
4038
+ };
4039
+ }
4040
+ );
4041
+
4042
+ function handleReadonlyResult(payload: ParsePayload): ParsePayload {
4043
+ payload.value = Object.freeze(payload.value);
4044
+ return payload;
4045
+ }
4046
+
4047
+ /////////////////////////////////////////////
4048
+ /////////////////////////////////////////////
4049
+ ////////// //////////
4050
+ ////////// $ZodTemplateLiteral //////////
4051
+ ////////// //////////
4052
+ /////////////////////////////////////////////
4053
+ /////////////////////////////////////////////
4054
+
4055
+ export interface $ZodTemplateLiteralDef extends $ZodTypeDef {
4056
+ type: "template_literal";
4057
+ parts: $ZodTemplateLiteralPart[];
4058
+ format?: string | undefined;
4059
+ }
4060
+ export interface $ZodTemplateLiteralInternals<Template extends string = string>
4061
+ extends $ZodTypeInternals<Template, Template> {
4062
+ pattern: RegExp;
4063
+ def: $ZodTemplateLiteralDef;
4064
+ isst: errors.$ZodIssueInvalidType;
4065
+ }
4066
+
4067
+ export interface $ZodTemplateLiteral<Template extends string = string> extends $ZodType {
4068
+ _zod: $ZodTemplateLiteralInternals<Template>;
4069
+ }
4070
+
4071
+ type LiteralPart = Exclude<util.Literal, symbol>; //string | number | boolean | null | undefined;
4072
+ interface SchemaPartInternals extends $ZodTypeInternals<LiteralPart, LiteralPart> {
4073
+ pattern: RegExp;
4074
+ }
4075
+ interface SchemaPart extends $ZodType {
4076
+ _zod: SchemaPartInternals;
4077
+ }
4078
+ export type $ZodTemplateLiteralPart = LiteralPart | SchemaPart;
4079
+
4080
+ type UndefinedToEmptyString<T> = T extends undefined ? "" : T;
4081
+ type AppendToTemplateLiteral<
4082
+ Template extends string,
4083
+ Suffix extends LiteralPart | $ZodType,
4084
+ > = Suffix extends LiteralPart
4085
+ ? `${Template}${UndefinedToEmptyString<Suffix>}`
4086
+ : Suffix extends $ZodType
4087
+ ? `${Template}${core.output<Suffix> extends infer T extends LiteralPart ? UndefinedToEmptyString<T> : never}`
4088
+ : never;
4089
+
4090
+ export type ConcatenateTupleOfStrings<T extends string[]> = T extends [
4091
+ infer First extends string,
4092
+ ...infer Rest extends string[],
4093
+ ]
4094
+ ? Rest extends string[]
4095
+ ? First extends ""
4096
+ ? ConcatenateTupleOfStrings<Rest>
4097
+ : `${First}${ConcatenateTupleOfStrings<Rest>}`
4098
+ : never
4099
+ : "";
4100
+ export type ConvertPartsToStringTuple<Parts extends $ZodTemplateLiteralPart[]> = {
4101
+ [K in keyof Parts]: Parts[K] extends LiteralPart
4102
+ ? `${UndefinedToEmptyString<Parts[K]>}`
4103
+ : Parts[K] extends $ZodType
4104
+ ? `${core.output<Parts[K]> extends infer T extends LiteralPart ? UndefinedToEmptyString<T> : never}`
4105
+ : never;
4106
+ };
4107
+
4108
+ export type ToTemplateLiteral<Parts extends $ZodTemplateLiteralPart[]> = ConcatenateTupleOfStrings<
4109
+ ConvertPartsToStringTuple<Parts>
4110
+ >;
4111
+ // type lkjasd = ConcatenateTupleOfStrings<["Hello", " ", "World", "!"]>; // "Hello World!"
4112
+ export type $PartsToTemplateLiteral<Parts extends $ZodTemplateLiteralPart[]> = [] extends Parts
4113
+ ? ``
4114
+ : Parts extends [...infer Rest, infer Last extends $ZodTemplateLiteralPart]
4115
+ ? Rest extends $ZodTemplateLiteralPart[]
4116
+ ? AppendToTemplateLiteral<$PartsToTemplateLiteral<Rest>, Last>
4117
+ : never
4118
+ : never;
4119
+
4120
+ export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__PURE__*/ core.$constructor(
4121
+ "$ZodTemplateLiteral",
4122
+ (inst, def) => {
4123
+ $ZodType.init(inst, def);
4124
+ const regexParts: string[] = [];
4125
+ for (const part of def.parts) {
4126
+ if (typeof part === "object" && part !== null) {
4127
+ // is Zod schema
4128
+ if (!part._zod.pattern) {
4129
+ // if (!source)
4130
+ throw new Error(`Invalid template literal part, no pattern found: ${[...(part as any)._zod.traits].shift()}`);
4131
+ }
4132
+
4133
+ const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;
4134
+
4135
+ if (!source) throw new Error(`Invalid template literal part: ${part._zod.traits}`);
4136
+
4137
+ const start = source.startsWith("^") ? 1 : 0;
4138
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
4139
+ regexParts.push(source.slice(start, end));
4140
+ } else if (part === null || util.primitiveTypes.has(typeof part)) {
4141
+ regexParts.push(util.escapeRegex(`${part}`));
4142
+ } else {
4143
+ throw new Error(`Invalid template literal part: ${part}`);
4144
+ }
4145
+ }
4146
+ inst._zod.pattern = new RegExp(`^${regexParts.join("")}$`);
4147
+
4148
+ inst._zod.parse = (payload, _ctx) => {
4149
+ if (typeof payload.value !== "string") {
4150
+ payload.issues.push({
4151
+ input: payload.value,
4152
+ inst,
4153
+ expected: "string",
4154
+ code: "invalid_type",
4155
+ });
4156
+ return payload;
4157
+ }
4158
+
4159
+ inst._zod.pattern.lastIndex = 0;
4160
+
4161
+ if (!inst._zod.pattern.test(payload.value)) {
4162
+ payload.issues.push({
4163
+ input: payload.value,
4164
+ inst,
4165
+
4166
+ code: "invalid_format",
4167
+ format: def.format ?? "template_literal",
4168
+ pattern: inst._zod.pattern.source,
4169
+ });
4170
+ return payload;
4171
+ }
4172
+
4173
+ return payload;
4174
+ };
4175
+ }
4176
+ );
4177
+
4178
+ //////////////////////////////////////////
4179
+ //////////////////////////////////////////
4180
+ ////////// //////////
4181
+ ////////// $ZodFunction //////////
4182
+ ////////// //////////
4183
+ //////////////////////////////////////////
4184
+ //////////////////////////////////////////
4185
+ export type $ZodFunctionArgs = $ZodType<unknown[], unknown[]>;
4186
+ export type $ZodFunctionIn = $ZodFunctionArgs;
4187
+ export type $ZodFunctionOut = $ZodType;
4188
+
4189
+ export type $InferInnerFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (
4190
+ ...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>
4191
+ ) => core.input<Returns>;
4192
+
4193
+ export type $InferInnerFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (
4194
+ ...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>
4195
+ ) => util.MaybeAsync<core.input<Returns>>;
4196
+
4197
+ export type $InferOuterFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (
4198
+ ...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>
4199
+ ) => core.output<Returns>;
4200
+
4201
+ export type $InferOuterFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (
4202
+ ...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>
4203
+ ) => Promise<core.output<Returns>>;
4204
+
4205
+ export interface $ZodFunctionDef<
4206
+ In extends $ZodFunctionIn = $ZodFunctionIn,
4207
+ Out extends $ZodFunctionOut = $ZodFunctionOut,
4208
+ > extends $ZodTypeDef {
4209
+ type: "function";
4210
+ input: In;
4211
+ output: Out;
4212
+ }
4213
+
4214
+ export interface $ZodFunctionInternals<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut>
4215
+ extends $ZodTypeInternals<$InferOuterFunctionType<Args, Returns>, $InferInnerFunctionType<Args, Returns>> {
4216
+ def: $ZodFunctionDef<Args, Returns>;
4217
+ isst: errors.$ZodIssueInvalidType;
4218
+ }
4219
+
4220
+ export interface $ZodFunction<
4221
+ Args extends $ZodFunctionIn = $ZodFunctionIn,
4222
+ Returns extends $ZodFunctionOut = $ZodFunctionOut,
4223
+ > extends $ZodType<any, any, $ZodFunctionInternals<Args, Returns>> {
4224
+ /** @deprecated */
4225
+ _def: $ZodFunctionDef<Args, Returns>;
4226
+ _input: $InferInnerFunctionType<Args, Returns>;
4227
+ _output: $InferOuterFunctionType<Args, Returns>;
4228
+
4229
+ implement<F extends $InferInnerFunctionType<Args, Returns>>(
4230
+ func: F
4231
+ ): // allow for return type inference
4232
+ (
4233
+ ...args: Parameters<this["_output"]>
4234
+ ) => ReturnType<F> extends ReturnType<this["_output"]> ? ReturnType<F> : ReturnType<this["_output"]>;
4235
+
4236
+ implementAsync<F extends $InferInnerFunctionTypeAsync<Args, Returns>>(
4237
+ func: F
4238
+ ): F extends $InferOuterFunctionTypeAsync<Args, Returns> ? F : $InferOuterFunctionTypeAsync<Args, Returns>;
4239
+
4240
+ input<const Items extends util.TupleItems, const Rest extends $ZodFunctionOut = $ZodFunctionOut>(
4241
+ args: Items,
4242
+ rest?: Rest
4243
+ ): $ZodFunction<$ZodTuple<Items, Rest>, Returns>;
4244
+ input<NewArgs extends $ZodFunctionIn>(args: NewArgs): $ZodFunction<NewArgs, Returns>;
4245
+ input(...args: any[]): $ZodFunction<any, Returns>;
4246
+
4247
+ output<NewReturns extends $ZodType>(output: NewReturns): $ZodFunction<Args, NewReturns>;
4248
+ }
4249
+
4250
+ export interface $ZodFunctionParams<I extends $ZodFunctionIn, O extends $ZodType> {
4251
+ input?: I;
4252
+ output?: O;
4253
+ }
4254
+
4255
+ export const $ZodFunction: core.$constructor<$ZodFunction> = /*@__PURE__*/ core.$constructor(
4256
+ "$ZodFunction",
4257
+ (inst, def) => {
4258
+ $ZodType.init(inst, def);
4259
+ inst._def = def;
4260
+ inst._zod.def = def;
4261
+
4262
+ inst.implement = (func) => {
4263
+ if (typeof func !== "function") {
4264
+ throw new Error("implement() must be called with a function");
4265
+ }
4266
+ return function (this: any, ...args: never[]) {
4267
+ const parsedArgs = inst._def.input ? parse(inst._def.input, args) : args;
4268
+ const result = Reflect.apply(func, this, parsedArgs as never[]);
4269
+ if (inst._def.output) {
4270
+ return parse(inst._def.output, result);
4271
+ }
4272
+ return result as any;
4273
+ };
4274
+ };
4275
+
4276
+ inst.implementAsync = (func) => {
4277
+ if (typeof func !== "function") {
4278
+ throw new Error("implementAsync() must be called with a function");
4279
+ }
4280
+ return async function (this: any, ...args: never[]) {
4281
+ const parsedArgs = inst._def.input ? await parseAsync(inst._def.input, args) : args;
4282
+ const result = await Reflect.apply(func, this, parsedArgs as never[]);
4283
+ if (inst._def.output) {
4284
+ return await parseAsync(inst._def.output, result);
4285
+ }
4286
+ return result;
4287
+ } as any;
4288
+ };
4289
+
4290
+ inst._zod.parse = (payload, _ctx) => {
4291
+ if (typeof payload.value !== "function") {
4292
+ payload.issues.push({
4293
+ code: "invalid_type",
4294
+ expected: "function",
4295
+ input: payload.value,
4296
+ inst,
4297
+ });
4298
+ return payload;
4299
+ }
4300
+
4301
+ // Check if output is a promise type to determine if we should use async implementation
4302
+ const hasPromiseOutput = inst._def.output && inst._def.output._zod.def.type === "promise";
4303
+
4304
+ if (hasPromiseOutput) {
4305
+ payload.value = inst.implementAsync(payload.value);
4306
+ } else {
4307
+ payload.value = inst.implement(payload.value);
4308
+ }
4309
+ return payload;
4310
+ };
4311
+
4312
+ inst.input = (...args: any[]): $ZodFunction<any, any> => {
4313
+ const F: any = inst.constructor;
4314
+ if (Array.isArray(args[0])) {
4315
+ return new F({
4316
+ type: "function",
4317
+ input: new $ZodTuple({
4318
+ type: "tuple",
4319
+ items: args[0],
4320
+ rest: args[1],
4321
+ }),
4322
+ output: inst._def.output,
4323
+ });
4324
+ }
4325
+
4326
+ return new F({
4327
+ type: "function",
4328
+ input: args[0],
4329
+ output: inst._def.output,
4330
+ });
4331
+ };
4332
+
4333
+ inst.output = (output) => {
4334
+ const F: any = inst.constructor;
4335
+ return new F({
4336
+ type: "function",
4337
+ input: inst._def.input,
4338
+ output,
4339
+ });
4340
+ };
4341
+
4342
+ return inst;
4343
+ }
4344
+ );
4345
+
4346
+ /////////////////////////////////////////
4347
+ /////////////////////////////////////////
4348
+ ////////// //////////
4349
+ ////////// $ZodPromise //////////
4350
+ ////////// //////////
4351
+ /////////////////////////////////////////
4352
+ /////////////////////////////////////////
4353
+ export interface $ZodPromiseDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
4354
+ type: "promise";
4355
+ innerType: T;
4356
+ }
4357
+
4358
+ export interface $ZodPromiseInternals<T extends SomeType = $ZodType>
4359
+ extends $ZodTypeInternals<Promise<core.output<T>>, util.MaybeAsync<core.input<T>>> {
4360
+ def: $ZodPromiseDef<T>;
4361
+ isst: never;
4362
+ }
4363
+
4364
+ export interface $ZodPromise<T extends SomeType = $ZodType> extends $ZodType {
4365
+ _zod: $ZodPromiseInternals<T>;
4366
+ }
4367
+
4368
+ export const $ZodPromise: core.$constructor<$ZodPromise> = /*@__PURE__*/ core.$constructor(
4369
+ "$ZodPromise",
4370
+ (inst, def) => {
4371
+ $ZodType.init(inst, def);
4372
+
4373
+ inst._zod.parse = (payload, ctx) => {
4374
+ return Promise.resolve(payload.value).then((inner) => def.innerType._zod.run({ value: inner, issues: [] }, ctx));
4375
+ };
4376
+ }
4377
+ );
4378
+
4379
+ //////////////////////////////////////////
4380
+ //////////////////////////////////////////
4381
+ ////////// //////////
4382
+ ////////// $ZodLazy //////////
4383
+ ////////// //////////
4384
+ //////////////////////////////////////////
4385
+ //////////////////////////////////////////
4386
+
4387
+ export interface $ZodLazyDef<T extends SomeType = $ZodType> extends $ZodTypeDef {
4388
+ type: "lazy";
4389
+ getter: () => T;
4390
+ }
4391
+
4392
+ export interface $ZodLazyInternals<T extends SomeType = $ZodType>
4393
+ extends $ZodTypeInternals<core.output<T>, core.input<T>> {
4394
+ def: $ZodLazyDef<T>;
4395
+ isst: never;
4396
+ /** Auto-cached way to retrieve the inner schema */
4397
+ innerType: T;
4398
+ pattern: T["_zod"]["pattern"];
4399
+ propValues: T["_zod"]["propValues"];
4400
+ optin: T["_zod"]["optin"];
4401
+ optout: T["_zod"]["optout"];
4402
+ }
4403
+
4404
+ export interface $ZodLazy<T extends SomeType = $ZodType> extends $ZodType {
4405
+ _zod: $ZodLazyInternals<T>;
4406
+ }
4407
+
4408
+ export const $ZodLazy: core.$constructor<$ZodLazy> = /*@__PURE__*/ core.$constructor("$ZodLazy", (inst, def) => {
4409
+ $ZodType.init(inst, def);
4410
+
4411
+ // let _innerType!: any;
4412
+ // util.defineLazy(def, "getter", () => {
4413
+ // if (!_innerType) {
4414
+ // _innerType = def.getter();
4415
+ // }
4416
+ // return () => _innerType;
4417
+ // });
4418
+ util.defineLazy(inst._zod, "innerType", () => def.getter() as $ZodType);
4419
+ util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod?.pattern);
4420
+ util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod?.propValues);
4421
+ util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod?.optin ?? undefined);
4422
+ util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod?.optout ?? undefined);
4423
+ inst._zod.parse = (payload, ctx) => {
4424
+ const inner = inst._zod.innerType;
4425
+ return inner._zod.run(payload, ctx);
4426
+ };
4427
+ });
4428
+
4429
+ ////////////////////////////////////////
4430
+ ////////////////////////////////////////
4431
+ ////////// //////////
4432
+ ////////// $ZodCustom //////////
4433
+ ////////// //////////
4434
+ ////////////////////////////////////////
4435
+ ////////////////////////////////////////
4436
+ export interface $ZodCustomDef<O = unknown> extends $ZodTypeDef, checks.$ZodCheckDef {
4437
+ type: "custom";
4438
+ check: "custom";
4439
+ path?: PropertyKey[] | undefined;
4440
+ error?: errors.$ZodErrorMap | undefined;
4441
+ params?: Record<string, any> | undefined;
4442
+ fn: (arg: O) => unknown;
4443
+ }
4444
+
4445
+ export interface $ZodCustomInternals<O = unknown, I = unknown>
4446
+ extends $ZodTypeInternals<O, I>,
4447
+ checks.$ZodCheckInternals<O> {
4448
+ def: $ZodCustomDef;
4449
+ issc: errors.$ZodIssue;
4450
+ isst: never;
4451
+ bag: util.LoosePartial<{
4452
+ Class: typeof util.Class;
4453
+ }>;
4454
+ }
4455
+
4456
+ export interface $ZodCustom<O = unknown, I = unknown> extends $ZodType {
4457
+ _zod: $ZodCustomInternals<O, I>;
4458
+ }
4459
+
4460
+ export const $ZodCustom: core.$constructor<$ZodCustom> = /*@__PURE__*/ core.$constructor("$ZodCustom", (inst, def) => {
4461
+ checks.$ZodCheck.init(inst, def);
4462
+ $ZodType.init(inst, def);
4463
+
4464
+ inst._zod.parse = (payload, _) => {
4465
+ return payload;
4466
+ };
4467
+
4468
+ inst._zod.check = (payload) => {
4469
+ const input = payload.value;
4470
+ const r = def.fn(input as any);
4471
+ if (r instanceof Promise) {
4472
+ return r.then((r) => handleRefineResult(r, payload, input, inst));
4473
+ }
4474
+ handleRefineResult(r, payload, input, inst);
4475
+ return;
4476
+ };
4477
+ });
4478
+
4479
+ function handleRefineResult(result: unknown, payload: ParsePayload, input: unknown, inst: $ZodCustom): void {
4480
+ if (!result) {
4481
+ const _iss: any = {
4482
+ code: "custom",
4483
+ input,
4484
+ inst, // incorporates params.error into issue reporting
4485
+ path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
4486
+ continue: !inst._zod.def.abort,
4487
+ // params: inst._zod.def.params,
4488
+ };
4489
+ if (inst._zod.def.params) _iss.params = inst._zod.def.params;
4490
+ payload.issues.push(util.issue(_iss));
4491
+ }
4492
+ }
4493
+
4494
+ export type $ZodTypes =
4495
+ | $ZodString
4496
+ | $ZodNumber
4497
+ | $ZodBigInt
4498
+ | $ZodBoolean
4499
+ | $ZodDate
4500
+ | $ZodSymbol
4501
+ | $ZodUndefined
4502
+ | $ZodNullable
4503
+ | $ZodNull
4504
+ | $ZodAny
4505
+ | $ZodUnknown
4506
+ | $ZodNever
4507
+ | $ZodVoid
4508
+ | $ZodArray
4509
+ | $ZodObject
4510
+ | $ZodUnion
4511
+ | $ZodIntersection
4512
+ | $ZodTuple
4513
+ | $ZodRecord
4514
+ | $ZodMap
4515
+ | $ZodSet
4516
+ | $ZodLiteral
4517
+ | $ZodEnum
4518
+ | $ZodFunction
4519
+ | $ZodPromise
4520
+ | $ZodLazy
4521
+ | $ZodOptional
4522
+ | $ZodDefault
4523
+ | $ZodPrefault
4524
+ | $ZodTemplateLiteral
4525
+ | $ZodCustom
4526
+ | $ZodTransform
4527
+ | $ZodNonOptional
4528
+ | $ZodReadonly
4529
+ | $ZodNaN
4530
+ | $ZodPipe
4531
+ | $ZodSuccess
4532
+ | $ZodCatch
4533
+ | $ZodFile;
4534
+
4535
+ export type $ZodStringFormatTypes =
4536
+ | $ZodGUID
4537
+ | $ZodUUID
4538
+ | $ZodEmail
4539
+ | $ZodURL
4540
+ | $ZodEmoji
4541
+ | $ZodNanoID
4542
+ | $ZodCUID
4543
+ | $ZodCUID2
4544
+ | $ZodULID
4545
+ | $ZodXID
4546
+ | $ZodKSUID
4547
+ | $ZodISODateTime
4548
+ | $ZodISODate
4549
+ | $ZodISOTime
4550
+ | $ZodISODuration
4551
+ | $ZodIPv4
4552
+ | $ZodIPv6
4553
+ | $ZodMAC
4554
+ | $ZodCIDRv4
4555
+ | $ZodCIDRv6
4556
+ | $ZodBase64
4557
+ | $ZodBase64URL
4558
+ | $ZodE164
4559
+ | $ZodJWT
4560
+ | $ZodCustomStringFormat<"hex">
4561
+ | $ZodCustomStringFormat<util.HashFormat>
4562
+ | $ZodCustomStringFormat<"hostname">;