zod 3.25.0 → 3.25.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/dist/commonjs/index.d.ts +3 -0
  2. package/dist/commonjs/index.js +22 -0
  3. package/dist/commonjs/package.json +3 -0
  4. package/dist/commonjs/v3/ZodError.d.ts +164 -0
  5. package/dist/commonjs/v3/ZodError.js +137 -0
  6. package/dist/commonjs/v3/benchmarks/datetime.d.ts +5 -0
  7. package/dist/commonjs/v3/benchmarks/datetime.js +54 -0
  8. package/dist/commonjs/v3/benchmarks/discriminatedUnion.d.ts +5 -0
  9. package/dist/commonjs/v3/benchmarks/discriminatedUnion.js +79 -0
  10. package/dist/commonjs/v3/benchmarks/index.d.ts +1 -0
  11. package/dist/commonjs/v3/benchmarks/index.js +59 -0
  12. package/dist/commonjs/v3/benchmarks/ipv4.d.ts +5 -0
  13. package/dist/commonjs/v3/benchmarks/ipv4.js +54 -0
  14. package/dist/commonjs/v3/benchmarks/object.d.ts +5 -0
  15. package/dist/commonjs/v3/benchmarks/object.js +70 -0
  16. package/dist/commonjs/v3/benchmarks/primitives.d.ts +5 -0
  17. package/dist/commonjs/v3/benchmarks/primitives.js +159 -0
  18. package/dist/commonjs/v3/benchmarks/realworld.d.ts +5 -0
  19. package/dist/commonjs/v3/benchmarks/realworld.js +56 -0
  20. package/dist/commonjs/v3/benchmarks/string.d.ts +5 -0
  21. package/dist/commonjs/v3/benchmarks/string.js +55 -0
  22. package/dist/commonjs/v3/benchmarks/union.d.ts +5 -0
  23. package/dist/commonjs/v3/benchmarks/union.js +79 -0
  24. package/dist/commonjs/v3/errors.d.ts +5 -0
  25. package/dist/commonjs/v3/errors.js +17 -0
  26. package/dist/commonjs/v3/external.d.ts +6 -0
  27. package/dist/commonjs/v3/external.js +22 -0
  28. package/dist/commonjs/v3/helpers/enumUtil.d.ts +8 -0
  29. package/dist/commonjs/v3/helpers/enumUtil.js +2 -0
  30. package/dist/commonjs/v3/helpers/errorUtil.d.ts +9 -0
  31. package/dist/commonjs/v3/helpers/errorUtil.js +9 -0
  32. package/dist/commonjs/v3/helpers/parseUtil.d.ts +78 -0
  33. package/dist/commonjs/v3/helpers/parseUtil.js +124 -0
  34. package/dist/commonjs/v3/helpers/partialUtil.d.ts +8 -0
  35. package/dist/commonjs/v3/helpers/partialUtil.js +2 -0
  36. package/dist/commonjs/v3/helpers/typeAliases.d.ts +2 -0
  37. package/dist/commonjs/v3/helpers/typeAliases.js +2 -0
  38. package/dist/commonjs/v3/helpers/util.d.ts +85 -0
  39. package/dist/commonjs/v3/helpers/util.js +137 -0
  40. package/dist/commonjs/v3/index.d.ts +4 -0
  41. package/dist/commonjs/v3/index.js +43 -0
  42. package/dist/commonjs/v3/locales/en.d.ts +3 -0
  43. package/dist/commonjs/v3/locales/en.js +109 -0
  44. package/dist/commonjs/v3/standard-schema.d.ts +102 -0
  45. package/dist/commonjs/v3/standard-schema.js +2 -0
  46. package/dist/commonjs/v3/tests/Mocker.d.ts +17 -0
  47. package/dist/commonjs/v3/tests/Mocker.js +57 -0
  48. package/dist/commonjs/v3/tests/language-server.source.d.ts +70 -0
  49. package/dist/commonjs/v3/tests/language-server.source.js +81 -0
  50. package/dist/commonjs/v3/types.d.ts +1031 -0
  51. package/dist/commonjs/v3/types.js +3795 -0
  52. package/dist/commonjs/v4/classic/checks.d.ts +1 -0
  53. package/dist/commonjs/v4/classic/checks.js +32 -0
  54. package/dist/commonjs/v4/classic/coerce.d.ts +17 -0
  55. package/dist/commonjs/v4/classic/coerce.js +57 -0
  56. package/dist/commonjs/v4/classic/compat.d.ts +48 -0
  57. package/dist/commonjs/v4/classic/compat.js +73 -0
  58. package/dist/commonjs/v4/classic/errors.d.ts +30 -0
  59. package/dist/commonjs/v4/classic/errors.js +76 -0
  60. package/dist/commonjs/v4/classic/external.d.ts +8 -0
  61. package/dist/commonjs/v4/classic/external.js +68 -0
  62. package/dist/commonjs/v4/classic/index.d.ts +4 -0
  63. package/dist/commonjs/v4/classic/index.js +43 -0
  64. package/dist/commonjs/v4/classic/iso.d.ts +22 -0
  65. package/dist/commonjs/v4/classic/iso.js +70 -0
  66. package/dist/commonjs/v4/classic/parse.d.ts +23 -0
  67. package/dist/commonjs/v4/classic/parse.js +42 -0
  68. package/dist/commonjs/v4/classic/schemas.d.ts +653 -0
  69. package/dist/commonjs/v4/classic/schemas.js +1123 -0
  70. package/dist/commonjs/v4/core/api.d.ts +273 -0
  71. package/dist/commonjs/v4/core/api.js +1004 -0
  72. package/dist/commonjs/v4/core/checks.d.ts +277 -0
  73. package/dist/commonjs/v4/core/checks.js +571 -0
  74. package/dist/commonjs/v4/core/config.d.ts +9 -0
  75. package/dist/commonjs/v4/core/config.js +10 -0
  76. package/dist/commonjs/v4/core/core.d.ts +43 -0
  77. package/dist/commonjs/v4/core/core.js +59 -0
  78. package/dist/commonjs/v4/core/doc.d.ts +14 -0
  79. package/dist/commonjs/v4/core/doc.js +40 -0
  80. package/dist/commonjs/v4/core/errors.d.ts +204 -0
  81. package/dist/commonjs/v4/core/errors.js +203 -0
  82. package/dist/commonjs/v4/core/function.d.ts +35 -0
  83. package/dist/commonjs/v4/core/function.js +107 -0
  84. package/dist/commonjs/v4/core/index.d.ts +15 -0
  85. package/dist/commonjs/v4/core/index.js +54 -0
  86. package/dist/commonjs/v4/core/json-schema.d.ts +100 -0
  87. package/dist/commonjs/v4/core/json-schema.js +2 -0
  88. package/dist/commonjs/v4/core/parse.d.ts +25 -0
  89. package/dist/commonjs/v4/core/parse.js +97 -0
  90. package/dist/commonjs/v4/core/regexes.d.ts +62 -0
  91. package/dist/commonjs/v4/core/regexes.js +101 -0
  92. package/dist/commonjs/v4/core/registries.d.ts +32 -0
  93. package/dist/commonjs/v4/core/registries.js +47 -0
  94. package/dist/commonjs/v4/core/schemas.d.ts +975 -0
  95. package/dist/commonjs/v4/core/schemas.js +1781 -0
  96. package/dist/commonjs/v4/core/standard-schema.d.ts +55 -0
  97. package/dist/commonjs/v4/core/standard-schema.js +2 -0
  98. package/dist/commonjs/v4/core/to-json-schema.d.ts +84 -0
  99. package/dist/commonjs/v4/core/to-json-schema.js +670 -0
  100. package/dist/commonjs/v4/core/util.d.ts +186 -0
  101. package/dist/commonjs/v4/core/util.js +515 -0
  102. package/dist/commonjs/v4/core/versions.d.ts +5 -0
  103. package/dist/commonjs/v4/core/versions.js +8 -0
  104. package/dist/commonjs/v4/core/zsf.d.ts +91 -0
  105. package/dist/commonjs/v4/core/zsf.js +172 -0
  106. package/dist/commonjs/v4/index.d.ts +3 -0
  107. package/dist/commonjs/v4/index.js +22 -0
  108. package/dist/commonjs/v4/locales/ar.d.ts +7 -0
  109. package/dist/commonjs/v4/locales/ar.js +153 -0
  110. package/dist/commonjs/v4/locales/az.d.ts +7 -0
  111. package/dist/commonjs/v4/locales/az.js +152 -0
  112. package/dist/commonjs/v4/locales/be.d.ts +7 -0
  113. package/dist/commonjs/v4/locales/be.js +201 -0
  114. package/dist/commonjs/v4/locales/ca.d.ts +7 -0
  115. package/dist/commonjs/v4/locales/ca.js +155 -0
  116. package/dist/commonjs/v4/locales/cs.d.ts +7 -0
  117. package/dist/commonjs/v4/locales/cs.js +172 -0
  118. package/dist/commonjs/v4/locales/de.d.ts +7 -0
  119. package/dist/commonjs/v4/locales/de.js +153 -0
  120. package/dist/commonjs/v4/locales/en.d.ts +7 -0
  121. package/dist/commonjs/v4/locales/en.js +155 -0
  122. package/dist/commonjs/v4/locales/es.d.ts +7 -0
  123. package/dist/commonjs/v4/locales/es.js +154 -0
  124. package/dist/commonjs/v4/locales/fa.d.ts +7 -0
  125. package/dist/commonjs/v4/locales/fa.js +159 -0
  126. package/dist/commonjs/v4/locales/fi.d.ts +7 -0
  127. package/dist/commonjs/v4/locales/fi.js +159 -0
  128. package/dist/commonjs/v4/locales/fr.d.ts +7 -0
  129. package/dist/commonjs/v4/locales/fr.js +153 -0
  130. package/dist/commonjs/v4/locales/frCA.d.ts +7 -0
  131. package/dist/commonjs/v4/locales/frCA.js +154 -0
  132. package/dist/commonjs/v4/locales/he.d.ts +7 -0
  133. package/dist/commonjs/v4/locales/he.js +154 -0
  134. package/dist/commonjs/v4/locales/hu.d.ts +7 -0
  135. package/dist/commonjs/v4/locales/hu.js +154 -0
  136. package/dist/commonjs/v4/locales/id.d.ts +7 -0
  137. package/dist/commonjs/v4/locales/id.js +153 -0
  138. package/dist/commonjs/v4/locales/index.d.ts +34 -0
  139. package/dist/commonjs/v4/locales/index.js +74 -0
  140. package/dist/commonjs/v4/locales/it.d.ts +7 -0
  141. package/dist/commonjs/v4/locales/it.js +154 -0
  142. package/dist/commonjs/v4/locales/ja.d.ts +7 -0
  143. package/dist/commonjs/v4/locales/ja.js +152 -0
  144. package/dist/commonjs/v4/locales/ko.d.ts +7 -0
  145. package/dist/commonjs/v4/locales/ko.js +158 -0
  146. package/dist/commonjs/v4/locales/mk.d.ts +7 -0
  147. package/dist/commonjs/v4/locales/mk.js +155 -0
  148. package/dist/commonjs/v4/locales/ms.d.ts +7 -0
  149. package/dist/commonjs/v4/locales/ms.js +153 -0
  150. package/dist/commonjs/v4/locales/no.d.ts +7 -0
  151. package/dist/commonjs/v4/locales/no.js +153 -0
  152. package/dist/commonjs/v4/locales/ota.d.ts +7 -0
  153. package/dist/commonjs/v4/locales/ota.js +154 -0
  154. package/dist/commonjs/v4/locales/pl.d.ts +7 -0
  155. package/dist/commonjs/v4/locales/pl.js +154 -0
  156. package/dist/commonjs/v4/locales/pt.d.ts +7 -0
  157. package/dist/commonjs/v4/locales/pt.js +153 -0
  158. package/dist/commonjs/v4/locales/ru.d.ts +7 -0
  159. package/dist/commonjs/v4/locales/ru.js +201 -0
  160. package/dist/commonjs/v4/locales/sl.d.ts +7 -0
  161. package/dist/commonjs/v4/locales/sl.js +154 -0
  162. package/dist/commonjs/v4/locales/ta.d.ts +7 -0
  163. package/dist/commonjs/v4/locales/ta.js +154 -0
  164. package/dist/commonjs/v4/locales/th.d.ts +7 -0
  165. package/dist/commonjs/v4/locales/th.js +154 -0
  166. package/dist/commonjs/v4/locales/tr.d.ts +7 -0
  167. package/dist/commonjs/v4/locales/tr.js +152 -0
  168. package/dist/commonjs/v4/locales/ua.d.ts +7 -0
  169. package/dist/commonjs/v4/locales/ua.js +154 -0
  170. package/dist/commonjs/v4/locales/ur.d.ts +7 -0
  171. package/dist/commonjs/v4/locales/ur.js +154 -0
  172. package/dist/commonjs/v4/locales/vi.d.ts +7 -0
  173. package/dist/commonjs/v4/locales/vi.js +153 -0
  174. package/dist/commonjs/v4/locales/zh-CN.d.ts +7 -0
  175. package/dist/commonjs/v4/locales/zh-CN.js +153 -0
  176. package/dist/commonjs/v4/locales/zh-tw.d.ts +7 -0
  177. package/dist/commonjs/v4/locales/zh-tw.js +154 -0
  178. package/dist/commonjs/v4/mini/checks.d.ts +1 -0
  179. package/dist/commonjs/v4/mini/checks.js +34 -0
  180. package/dist/commonjs/v4/mini/coerce.d.ts +7 -0
  181. package/dist/commonjs/v4/mini/coerce.js +57 -0
  182. package/dist/commonjs/v4/mini/external.d.ts +7 -0
  183. package/dist/commonjs/v4/mini/external.js +61 -0
  184. package/dist/commonjs/v4/mini/index.d.ts +3 -0
  185. package/dist/commonjs/v4/mini/index.js +42 -0
  186. package/dist/commonjs/v4/mini/iso.d.ts +22 -0
  187. package/dist/commonjs/v4/mini/iso.js +70 -0
  188. package/dist/commonjs/v4/mini/parse.d.ts +1 -0
  189. package/dist/commonjs/v4/mini/parse.js +8 -0
  190. package/dist/commonjs/v4/mini/schemas.d.ts +405 -0
  191. package/dist/commonjs/v4/mini/schemas.js +852 -0
  192. package/dist/esm/index.d.ts +3 -0
  193. package/dist/esm/index.js +3 -0
  194. package/dist/esm/package.json +3 -0
  195. package/dist/esm/v3/ZodError.d.ts +164 -0
  196. package/dist/esm/v3/ZodError.js +132 -0
  197. package/dist/esm/v3/benchmarks/datetime.d.ts +5 -0
  198. package/dist/esm/v3/benchmarks/datetime.js +49 -0
  199. package/dist/esm/v3/benchmarks/discriminatedUnion.d.ts +5 -0
  200. package/dist/esm/v3/benchmarks/discriminatedUnion.js +74 -0
  201. package/dist/esm/v3/benchmarks/index.d.ts +1 -0
  202. package/dist/esm/v3/benchmarks/index.js +54 -0
  203. package/dist/esm/v3/benchmarks/ipv4.d.ts +5 -0
  204. package/dist/esm/v3/benchmarks/ipv4.js +49 -0
  205. package/dist/esm/v3/benchmarks/object.d.ts +5 -0
  206. package/dist/esm/v3/benchmarks/object.js +65 -0
  207. package/dist/esm/v3/benchmarks/primitives.d.ts +5 -0
  208. package/dist/esm/v3/benchmarks/primitives.js +154 -0
  209. package/dist/esm/v3/benchmarks/realworld.d.ts +5 -0
  210. package/dist/esm/v3/benchmarks/realworld.js +51 -0
  211. package/dist/esm/v3/benchmarks/string.d.ts +5 -0
  212. package/dist/esm/v3/benchmarks/string.js +50 -0
  213. package/dist/esm/v3/benchmarks/union.d.ts +5 -0
  214. package/dist/esm/v3/benchmarks/union.js +74 -0
  215. package/dist/esm/v3/errors.d.ts +5 -0
  216. package/dist/esm/v3/errors.js +9 -0
  217. package/dist/esm/v3/external.d.ts +6 -0
  218. package/dist/esm/v3/external.js +6 -0
  219. package/dist/esm/v3/helpers/enumUtil.d.ts +8 -0
  220. package/dist/esm/v3/helpers/enumUtil.js +1 -0
  221. package/dist/esm/v3/helpers/errorUtil.d.ts +9 -0
  222. package/dist/esm/v3/helpers/errorUtil.js +6 -0
  223. package/dist/esm/v3/helpers/parseUtil.d.ts +78 -0
  224. package/dist/esm/v3/helpers/parseUtil.js +109 -0
  225. package/dist/esm/v3/helpers/partialUtil.d.ts +8 -0
  226. package/dist/esm/v3/helpers/partialUtil.js +1 -0
  227. package/dist/esm/v3/helpers/typeAliases.d.ts +2 -0
  228. package/dist/esm/v3/helpers/typeAliases.js +1 -0
  229. package/dist/esm/v3/helpers/util.d.ts +85 -0
  230. package/dist/esm/v3/helpers/util.js +133 -0
  231. package/dist/esm/v3/index.d.ts +4 -0
  232. package/dist/esm/v3/index.js +4 -0
  233. package/dist/esm/v3/locales/en.d.ts +3 -0
  234. package/dist/esm/v3/locales/en.js +107 -0
  235. package/dist/esm/v3/standard-schema.d.ts +102 -0
  236. package/dist/esm/v3/standard-schema.js +1 -0
  237. package/dist/esm/v3/tests/Mocker.d.ts +17 -0
  238. package/dist/esm/v3/tests/Mocker.js +53 -0
  239. package/dist/esm/v3/tests/language-server.source.d.ts +70 -0
  240. package/dist/esm/v3/tests/language-server.source.js +45 -0
  241. package/dist/esm/v3/types.d.ts +1031 -0
  242. package/dist/esm/v3/types.js +3713 -0
  243. package/dist/esm/v4/classic/checks.d.ts +1 -0
  244. package/dist/esm/v4/classic/checks.js +1 -0
  245. package/dist/esm/v4/classic/coerce.d.ts +17 -0
  246. package/dist/esm/v4/classic/coerce.js +17 -0
  247. package/dist/esm/v4/classic/compat.d.ts +48 -0
  248. package/dist/esm/v4/classic/compat.js +33 -0
  249. package/dist/esm/v4/classic/errors.d.ts +30 -0
  250. package/dist/esm/v4/classic/errors.js +40 -0
  251. package/dist/esm/v4/classic/external.d.ts +8 -0
  252. package/dist/esm/v4/classic/external.js +11 -0
  253. package/dist/esm/v4/classic/index.d.ts +4 -0
  254. package/dist/esm/v4/classic/index.js +4 -0
  255. package/dist/esm/v4/classic/iso.d.ts +22 -0
  256. package/dist/esm/v4/classic/iso.js +30 -0
  257. package/dist/esm/v4/classic/parse.d.ts +23 -0
  258. package/dist/esm/v4/classic/parse.js +6 -0
  259. package/dist/esm/v4/classic/schemas.d.ts +653 -0
  260. package/dist/esm/v4/classic/schemas.js +1012 -0
  261. package/dist/esm/v4/core/api.d.ts +273 -0
  262. package/dist/esm/v4/core/api.js +867 -0
  263. package/dist/esm/v4/core/checks.d.ts +277 -0
  264. package/dist/esm/v4/core/checks.js +535 -0
  265. package/dist/esm/v4/core/config.d.ts +9 -0
  266. package/dist/esm/v4/core/config.js +6 -0
  267. package/dist/esm/v4/core/core.d.ts +43 -0
  268. package/dist/esm/v4/core/core.js +53 -0
  269. package/dist/esm/v4/core/doc.d.ts +14 -0
  270. package/dist/esm/v4/core/doc.js +36 -0
  271. package/dist/esm/v4/core/errors.d.ts +204 -0
  272. package/dist/esm/v4/core/errors.js +195 -0
  273. package/dist/esm/v4/core/function.d.ts +35 -0
  274. package/dist/esm/v4/core/function.js +70 -0
  275. package/dist/esm/v4/core/index.d.ts +15 -0
  276. package/dist/esm/v4/core/index.js +15 -0
  277. package/dist/esm/v4/core/json-schema.d.ts +100 -0
  278. package/dist/esm/v4/core/json-schema.js +1 -0
  279. package/dist/esm/v4/core/parse.d.ts +25 -0
  280. package/dist/esm/v4/core/parse.js +57 -0
  281. package/dist/esm/v4/core/regexes.d.ts +62 -0
  282. package/dist/esm/v4/core/regexes.js +93 -0
  283. package/dist/esm/v4/core/registries.d.ts +32 -0
  284. package/dist/esm/v4/core/registries.js +42 -0
  285. package/dist/esm/v4/core/schemas.d.ts +975 -0
  286. package/dist/esm/v4/core/schemas.js +1740 -0
  287. package/dist/esm/v4/core/standard-schema.d.ts +55 -0
  288. package/dist/esm/v4/core/standard-schema.js +1 -0
  289. package/dist/esm/v4/core/to-json-schema.d.ts +84 -0
  290. package/dist/esm/v4/core/to-json-schema.js +665 -0
  291. package/dist/esm/v4/core/util.d.ts +186 -0
  292. package/dist/esm/v4/core/util.js +469 -0
  293. package/dist/esm/v4/core/versions.d.ts +5 -0
  294. package/dist/esm/v4/core/versions.js +5 -0
  295. package/dist/esm/v4/core/zsf.d.ts +91 -0
  296. package/dist/esm/v4/core/zsf.js +171 -0
  297. package/dist/esm/v4/index.d.ts +3 -0
  298. package/dist/esm/v4/index.js +3 -0
  299. package/dist/esm/v4/locales/ar.d.ts +7 -0
  300. package/dist/esm/v4/locales/ar.js +115 -0
  301. package/dist/esm/v4/locales/az.d.ts +7 -0
  302. package/dist/esm/v4/locales/az.js +114 -0
  303. package/dist/esm/v4/locales/be.d.ts +7 -0
  304. package/dist/esm/v4/locales/be.js +163 -0
  305. package/dist/esm/v4/locales/ca.d.ts +7 -0
  306. package/dist/esm/v4/locales/ca.js +117 -0
  307. package/dist/esm/v4/locales/cs.d.ts +7 -0
  308. package/dist/esm/v4/locales/cs.js +134 -0
  309. package/dist/esm/v4/locales/de.d.ts +7 -0
  310. package/dist/esm/v4/locales/de.js +115 -0
  311. package/dist/esm/v4/locales/en.d.ts +7 -0
  312. package/dist/esm/v4/locales/en.js +117 -0
  313. package/dist/esm/v4/locales/es.d.ts +7 -0
  314. package/dist/esm/v4/locales/es.js +116 -0
  315. package/dist/esm/v4/locales/fa.d.ts +7 -0
  316. package/dist/esm/v4/locales/fa.js +121 -0
  317. package/dist/esm/v4/locales/fi.d.ts +7 -0
  318. package/dist/esm/v4/locales/fi.js +121 -0
  319. package/dist/esm/v4/locales/fr.d.ts +7 -0
  320. package/dist/esm/v4/locales/fr.js +115 -0
  321. package/dist/esm/v4/locales/frCA.d.ts +7 -0
  322. package/dist/esm/v4/locales/frCA.js +116 -0
  323. package/dist/esm/v4/locales/he.d.ts +7 -0
  324. package/dist/esm/v4/locales/he.js +116 -0
  325. package/dist/esm/v4/locales/hu.d.ts +7 -0
  326. package/dist/esm/v4/locales/hu.js +116 -0
  327. package/dist/esm/v4/locales/id.d.ts +7 -0
  328. package/dist/esm/v4/locales/id.js +115 -0
  329. package/dist/esm/v4/locales/index.d.ts +34 -0
  330. package/dist/esm/v4/locales/index.js +34 -0
  331. package/dist/esm/v4/locales/it.d.ts +7 -0
  332. package/dist/esm/v4/locales/it.js +116 -0
  333. package/dist/esm/v4/locales/ja.d.ts +7 -0
  334. package/dist/esm/v4/locales/ja.js +114 -0
  335. package/dist/esm/v4/locales/ko.d.ts +7 -0
  336. package/dist/esm/v4/locales/ko.js +120 -0
  337. package/dist/esm/v4/locales/mk.d.ts +7 -0
  338. package/dist/esm/v4/locales/mk.js +117 -0
  339. package/dist/esm/v4/locales/ms.d.ts +7 -0
  340. package/dist/esm/v4/locales/ms.js +115 -0
  341. package/dist/esm/v4/locales/no.d.ts +7 -0
  342. package/dist/esm/v4/locales/no.js +115 -0
  343. package/dist/esm/v4/locales/ota.d.ts +7 -0
  344. package/dist/esm/v4/locales/ota.js +116 -0
  345. package/dist/esm/v4/locales/pl.d.ts +7 -0
  346. package/dist/esm/v4/locales/pl.js +116 -0
  347. package/dist/esm/v4/locales/pt.d.ts +7 -0
  348. package/dist/esm/v4/locales/pt.js +115 -0
  349. package/dist/esm/v4/locales/ru.d.ts +7 -0
  350. package/dist/esm/v4/locales/ru.js +163 -0
  351. package/dist/esm/v4/locales/sl.d.ts +7 -0
  352. package/dist/esm/v4/locales/sl.js +116 -0
  353. package/dist/esm/v4/locales/ta.d.ts +7 -0
  354. package/dist/esm/v4/locales/ta.js +116 -0
  355. package/dist/esm/v4/locales/th.d.ts +7 -0
  356. package/dist/esm/v4/locales/th.js +116 -0
  357. package/dist/esm/v4/locales/tr.d.ts +7 -0
  358. package/dist/esm/v4/locales/tr.js +114 -0
  359. package/dist/esm/v4/locales/ua.d.ts +7 -0
  360. package/dist/esm/v4/locales/ua.js +116 -0
  361. package/dist/esm/v4/locales/ur.d.ts +7 -0
  362. package/dist/esm/v4/locales/ur.js +116 -0
  363. package/dist/esm/v4/locales/vi.d.ts +7 -0
  364. package/dist/esm/v4/locales/vi.js +115 -0
  365. package/dist/esm/v4/locales/zh-CN.d.ts +7 -0
  366. package/dist/esm/v4/locales/zh-CN.js +115 -0
  367. package/dist/esm/v4/locales/zh-tw.d.ts +7 -0
  368. package/dist/esm/v4/locales/zh-tw.js +116 -0
  369. package/dist/esm/v4/mini/checks.d.ts +1 -0
  370. package/dist/esm/v4/mini/checks.js +1 -0
  371. package/dist/esm/v4/mini/coerce.d.ts +7 -0
  372. package/dist/esm/v4/mini/coerce.js +17 -0
  373. package/dist/esm/v4/mini/external.d.ts +7 -0
  374. package/dist/esm/v4/mini/external.js +7 -0
  375. package/dist/esm/v4/mini/index.d.ts +3 -0
  376. package/dist/esm/v4/mini/index.js +3 -0
  377. package/dist/esm/v4/mini/iso.d.ts +22 -0
  378. package/dist/esm/v4/mini/iso.js +30 -0
  379. package/dist/esm/v4/mini/parse.d.ts +1 -0
  380. package/dist/esm/v4/mini/parse.js +1 -0
  381. package/dist/esm/v4/mini/schemas.d.ts +405 -0
  382. package/dist/esm/v4/mini/schemas.js +738 -0
  383. package/package.json +1 -1
  384. package/src/v4/core/schemas.ts +0 -2
  385. package/src/v4/core/to-json-schema.ts +1 -1
@@ -0,0 +1,1740 @@
1
+ import * as checks from "./checks.js";
2
+ import * as core from "./core.js";
3
+ import { Doc } from "./doc.js";
4
+ import { safeParse, safeParseAsync } from "./parse.js";
5
+ import * as regexes from "./regexes.js";
6
+ import * as util from "./util.js";
7
+ import { version } from "./versions.js";
8
+ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def) => {
9
+ var _a;
10
+ inst ?? (inst = {});
11
+ inst._zod.id = def.type + "_" + util.randomString(10);
12
+ inst._zod.def = def; // set _def property
13
+ inst._zod.bag = inst._zod.bag || {}; // initialize _bag object
14
+ inst._zod.version = version;
15
+ const checks = [...(inst._zod.def.checks ?? [])];
16
+ // if inst is itself a checks.$ZodCheck, run it as a check
17
+ if (inst._zod.traits.has("$ZodCheck")) {
18
+ checks.unshift(inst);
19
+ }
20
+ //
21
+ for (const ch of checks) {
22
+ for (const fn of ch._zod.onattach) {
23
+ fn(inst);
24
+ }
25
+ }
26
+ if (checks.length === 0) {
27
+ // deferred initializer
28
+ // inst._zod.parse is not yet defined
29
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
30
+ inst._zod.deferred?.push(() => {
31
+ inst._zod.run = inst._zod.parse;
32
+ });
33
+ }
34
+ else {
35
+ const runChecks = (payload, checks, ctx) => {
36
+ let isAborted = util.aborted(payload);
37
+ let asyncResult;
38
+ for (const ch of checks) {
39
+ if (ch._zod.when) {
40
+ const shouldRun = ch._zod.when(payload);
41
+ if (!shouldRun)
42
+ continue;
43
+ }
44
+ else {
45
+ if (isAborted) {
46
+ continue;
47
+ }
48
+ }
49
+ const currLen = payload.issues.length;
50
+ const _ = ch._zod.check(payload);
51
+ if (_ instanceof Promise && ctx?.async === false) {
52
+ throw new core.$ZodAsyncError();
53
+ }
54
+ if (asyncResult || _ instanceof Promise) {
55
+ asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
56
+ await _;
57
+ const nextLen = payload.issues.length;
58
+ if (nextLen === currLen)
59
+ return;
60
+ if (!isAborted)
61
+ isAborted = util.aborted(payload, currLen);
62
+ });
63
+ }
64
+ else {
65
+ const nextLen = payload.issues.length;
66
+ if (nextLen === currLen)
67
+ continue;
68
+ if (!isAborted)
69
+ isAborted = util.aborted(payload, currLen);
70
+ }
71
+ }
72
+ if (asyncResult) {
73
+ return asyncResult.then(() => {
74
+ return payload;
75
+ });
76
+ }
77
+ return payload;
78
+ };
79
+ inst._zod.run = (payload, ctx) => {
80
+ const result = inst._zod.parse(payload, ctx);
81
+ if (result instanceof Promise) {
82
+ if (ctx.async === false)
83
+ throw new core.$ZodAsyncError();
84
+ return result.then((result) => runChecks(result, checks, ctx));
85
+ }
86
+ return runChecks(result, checks, ctx);
87
+ };
88
+ }
89
+ inst["~standard"] = {
90
+ validate: (value) => {
91
+ try {
92
+ const r = safeParse(inst, value);
93
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
94
+ }
95
+ catch (_) {
96
+ return safeParseAsync(inst, value).then((r) => (r.success ? { value: r.data } : { issues: r.error?.issues }));
97
+ }
98
+ },
99
+ vendor: "zod",
100
+ version: 1,
101
+ };
102
+ });
103
+ export { clone } from "./util.js";
104
+ export const $ZodString = /*@__PURE__*/ core.$constructor("$ZodString", (inst, def) => {
105
+ $ZodType.init(inst, def);
106
+ inst._zod.pattern = inst?._zod.bag?.pattern ?? regexes.string(inst._zod.bag);
107
+ inst._zod.parse = (payload, _) => {
108
+ if (def.coerce)
109
+ try {
110
+ payload.value = String(payload.value);
111
+ }
112
+ catch (_) { }
113
+ if (typeof payload.value === "string")
114
+ return payload;
115
+ payload.issues.push({
116
+ expected: "string",
117
+ code: "invalid_type",
118
+ input: payload.value,
119
+ inst,
120
+ });
121
+ return payload;
122
+ };
123
+ });
124
+ export const $ZodStringFormat = /*@__PURE__*/ core.$constructor("$ZodStringFormat", (inst, def) => {
125
+ // check initialization must come first
126
+ checks.$ZodCheckStringFormat.init(inst, def);
127
+ $ZodString.init(inst, def);
128
+ });
129
+ export const $ZodGUID = /*@__PURE__*/ core.$constructor("$ZodGUID", (inst, def) => {
130
+ def.pattern ?? (def.pattern = regexes.guid);
131
+ $ZodStringFormat.init(inst, def);
132
+ });
133
+ export const $ZodUUID = /*@__PURE__*/ core.$constructor("$ZodUUID", (inst, def) => {
134
+ if (def.version) {
135
+ const versionMap = {
136
+ v1: 1,
137
+ v2: 2,
138
+ v3: 3,
139
+ v4: 4,
140
+ v5: 5,
141
+ v6: 6,
142
+ v7: 7,
143
+ v8: 8,
144
+ };
145
+ const v = versionMap[def.version];
146
+ if (v === undefined)
147
+ throw new Error(`Invalid UUID version: "${def.version}"`);
148
+ def.pattern ?? (def.pattern = regexes.uuid(v));
149
+ }
150
+ else
151
+ def.pattern ?? (def.pattern = regexes.uuid());
152
+ $ZodStringFormat.init(inst, def);
153
+ });
154
+ export const $ZodEmail = /*@__PURE__*/ core.$constructor("$ZodEmail", (inst, def) => {
155
+ def.pattern ?? (def.pattern = regexes.email);
156
+ $ZodStringFormat.init(inst, def);
157
+ });
158
+ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) => {
159
+ $ZodStringFormat.init(inst, def);
160
+ inst._zod.check = (payload) => {
161
+ try {
162
+ const url = new URL(payload.value);
163
+ regexes.hostname.lastIndex = 0;
164
+ if (!regexes.hostname.test(url.hostname)) {
165
+ payload.issues.push({
166
+ code: "invalid_format",
167
+ format: "url",
168
+ note: "Invalid hostname",
169
+ pattern: regexes.hostname.source,
170
+ input: payload.value,
171
+ inst,
172
+ });
173
+ }
174
+ if (def.hostname) {
175
+ def.hostname.lastIndex = 0;
176
+ if (!def.hostname.test(url.hostname)) {
177
+ payload.issues.push({
178
+ code: "invalid_format",
179
+ format: "url",
180
+ note: "Invalid hostname",
181
+ pattern: def.hostname.source,
182
+ input: payload.value,
183
+ inst,
184
+ });
185
+ }
186
+ }
187
+ if (def.protocol) {
188
+ def.protocol.lastIndex = 0;
189
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
190
+ payload.issues.push({
191
+ code: "invalid_format",
192
+ format: "url",
193
+ note: "Invalid protocol",
194
+ pattern: def.protocol.source,
195
+ input: payload.value,
196
+ inst,
197
+ });
198
+ }
199
+ }
200
+ return;
201
+ }
202
+ catch (_) {
203
+ payload.issues.push({
204
+ code: "invalid_format",
205
+ format: "url",
206
+ input: payload.value,
207
+ inst,
208
+ });
209
+ }
210
+ };
211
+ });
212
+ export const $ZodEmoji = /*@__PURE__*/ core.$constructor("$ZodEmoji", (inst, def) => {
213
+ def.pattern ?? (def.pattern = regexes.emoji());
214
+ $ZodStringFormat.init(inst, def);
215
+ });
216
+ export const $ZodNanoID = /*@__PURE__*/ core.$constructor("$ZodNanoID", (inst, def) => {
217
+ def.pattern ?? (def.pattern = regexes.nanoid);
218
+ $ZodStringFormat.init(inst, def);
219
+ });
220
+ export const $ZodCUID = /*@__PURE__*/ core.$constructor("$ZodCUID", (inst, def) => {
221
+ def.pattern ?? (def.pattern = regexes.cuid);
222
+ $ZodStringFormat.init(inst, def);
223
+ });
224
+ export const $ZodCUID2 = /*@__PURE__*/ core.$constructor("$ZodCUID2", (inst, def) => {
225
+ def.pattern ?? (def.pattern = regexes.cuid2);
226
+ $ZodStringFormat.init(inst, def);
227
+ });
228
+ export const $ZodULID = /*@__PURE__*/ core.$constructor("$ZodULID", (inst, def) => {
229
+ def.pattern ?? (def.pattern = regexes.ulid);
230
+ $ZodStringFormat.init(inst, def);
231
+ });
232
+ export const $ZodXID = /*@__PURE__*/ core.$constructor("$ZodXID", (inst, def) => {
233
+ def.pattern ?? (def.pattern = regexes.xid);
234
+ $ZodStringFormat.init(inst, def);
235
+ });
236
+ export const $ZodKSUID = /*@__PURE__*/ core.$constructor("$ZodKSUID", (inst, def) => {
237
+ def.pattern ?? (def.pattern = regexes.ksuid);
238
+ $ZodStringFormat.init(inst, def);
239
+ });
240
+ export const $ZodISODateTime = /*@__PURE__*/ core.$constructor("$ZodISODateTime", (inst, def) => {
241
+ def.pattern ?? (def.pattern = regexes.datetime(def));
242
+ $ZodStringFormat.init(inst, def);
243
+ });
244
+ export const $ZodISODate = /*@__PURE__*/ core.$constructor("$ZodISODate", (inst, def) => {
245
+ def.pattern ?? (def.pattern = regexes.date);
246
+ $ZodStringFormat.init(inst, def);
247
+ });
248
+ export const $ZodISOTime = /*@__PURE__*/ core.$constructor("$ZodISOTime", (inst, def) => {
249
+ def.pattern ?? (def.pattern = regexes.time(def));
250
+ $ZodStringFormat.init(inst, def);
251
+ });
252
+ export const $ZodISODuration = /*@__PURE__*/ core.$constructor("$ZodISODuration", (inst, def) => {
253
+ def.pattern ?? (def.pattern = regexes.duration);
254
+ $ZodStringFormat.init(inst, def);
255
+ });
256
+ export const $ZodIPv4 = /*@__PURE__*/ core.$constructor("$ZodIPv4", (inst, def) => {
257
+ def.pattern ?? (def.pattern = regexes.ipv4);
258
+ $ZodStringFormat.init(inst, def);
259
+ inst._zod.onattach.push((inst) => {
260
+ inst._zod.bag.format = `ipv4`;
261
+ });
262
+ });
263
+ export const $ZodIPv6 = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def) => {
264
+ def.pattern ?? (def.pattern = regexes.ipv6);
265
+ $ZodStringFormat.init(inst, def);
266
+ inst._zod.onattach.push((inst) => {
267
+ inst._zod.bag.format = `ipv6`;
268
+ });
269
+ inst._zod.check = (payload) => {
270
+ try {
271
+ new URL(`http://[${payload.value}]`);
272
+ // return;
273
+ }
274
+ catch {
275
+ payload.issues.push({
276
+ code: "invalid_format",
277
+ format: "ipv6",
278
+ input: payload.value,
279
+ inst,
280
+ });
281
+ }
282
+ };
283
+ });
284
+ export const $ZodCIDRv4 = /*@__PURE__*/ core.$constructor("$ZodCIDRv4", (inst, def) => {
285
+ def.pattern ?? (def.pattern = regexes.cidrv4);
286
+ $ZodStringFormat.init(inst, def);
287
+ });
288
+ export const $ZodCIDRv6 = /*@__PURE__*/ core.$constructor("$ZodCIDRv6", (inst, def) => {
289
+ def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
290
+ $ZodStringFormat.init(inst, def);
291
+ inst._zod.check = (payload) => {
292
+ const [address, prefix] = payload.value.split("/");
293
+ try {
294
+ if (!prefix)
295
+ throw new Error();
296
+ const prefixNum = Number(prefix);
297
+ if (`${prefixNum}` !== prefix)
298
+ throw new Error();
299
+ if (prefixNum < 0 || prefixNum > 128)
300
+ throw new Error();
301
+ new URL(`http://[${address}]`);
302
+ }
303
+ catch {
304
+ payload.issues.push({
305
+ code: "invalid_format",
306
+ format: "cidrv6",
307
+ input: payload.value,
308
+ inst,
309
+ });
310
+ }
311
+ };
312
+ });
313
+ ////////////////////////////// ZodIP //////////////////////////////
314
+ // export interface $ZodIPDef extends $ZodStringFormatDef<"ip"> {
315
+ // version?: "v4" | "v6";
316
+ // }
317
+ // export interface $ZodIPInternals extends $ZodStringFormatInternals<"ip"> {
318
+ // def: $ZodIPDef;
319
+ // }
320
+ // export interface $ZodIP extends $ZodType {
321
+ // _zod: $ZodIPInternals;
322
+ // }
323
+ // export const $ZodIP: core.$constructor<$ZodIP> = /*@__PURE__*/ core.$constructor("$ZodIP", (inst, def): void => {
324
+ // if (def.version === "v4") def.pattern ??= regexes.ipv4;
325
+ // else if (def.version === "v6") def.pattern ??= regexes.ipv6;
326
+ // else def.pattern ??= regexes.ip;
327
+ // $ZodStringFormat.init(inst, def);
328
+ // });
329
+ ////////////////////////////// ZodBase64 //////////////////////////////
330
+ export function isValidBase64(data) {
331
+ if (data === "")
332
+ return true;
333
+ if (data.length % 4 !== 0)
334
+ return false;
335
+ try {
336
+ atob(data);
337
+ return true;
338
+ }
339
+ catch {
340
+ return false;
341
+ }
342
+ }
343
+ export const $ZodBase64 = /*@__PURE__*/ core.$constructor("$ZodBase64", (inst, def) => {
344
+ def.pattern ?? (def.pattern = regexes.base64);
345
+ $ZodStringFormat.init(inst, def);
346
+ inst._zod.onattach.push((inst) => {
347
+ inst._zod.bag.contentEncoding = "base64";
348
+ });
349
+ inst._zod.check = (payload) => {
350
+ if (isValidBase64(payload.value))
351
+ return;
352
+ payload.issues.push({
353
+ code: "invalid_format",
354
+ format: "base64",
355
+ input: payload.value,
356
+ inst,
357
+ });
358
+ };
359
+ });
360
+ ////////////////////////////// ZodBase64 //////////////////////////////
361
+ export function isValidBase64URL(data) {
362
+ if (!regexes.base64url.test(data))
363
+ return false;
364
+ const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
365
+ const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
366
+ return isValidBase64(padded);
367
+ }
368
+ export const $ZodBase64URL = /*@__PURE__*/ core.$constructor("$ZodBase64URL", (inst, def) => {
369
+ def.pattern ?? (def.pattern = regexes.base64url);
370
+ $ZodStringFormat.init(inst, def);
371
+ inst._zod.onattach.push((inst) => {
372
+ inst._zod.bag.contentEncoding = "base64url";
373
+ });
374
+ inst._zod.check = (payload) => {
375
+ if (isValidBase64URL(payload.value))
376
+ return;
377
+ payload.issues.push({
378
+ code: "invalid_format",
379
+ format: "base64url",
380
+ input: payload.value,
381
+ inst,
382
+ });
383
+ };
384
+ });
385
+ export const $ZodE164 = /*@__PURE__*/ core.$constructor("$ZodE164", (inst, def) => {
386
+ def.pattern ?? (def.pattern = regexes.e164);
387
+ $ZodStringFormat.init(inst, def);
388
+ });
389
+ ////////////////////////////// ZodJWT //////////////////////////////
390
+ export function isValidJWT(token, algorithm = null) {
391
+ try {
392
+ const tokensParts = token.split(".");
393
+ if (tokensParts.length !== 3)
394
+ return false;
395
+ const [header] = tokensParts;
396
+ const parsedHeader = JSON.parse(atob(header));
397
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
398
+ return false;
399
+ if (!parsedHeader.alg)
400
+ return false;
401
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
402
+ return false;
403
+ return true;
404
+ }
405
+ catch {
406
+ return false;
407
+ }
408
+ }
409
+ export const $ZodJWT = /*@__PURE__*/ core.$constructor("$ZodJWT", (inst, def) => {
410
+ $ZodStringFormat.init(inst, def);
411
+ inst._zod.check = (payload) => {
412
+ if (isValidJWT(payload.value, def.alg))
413
+ return;
414
+ payload.issues.push({
415
+ code: "invalid_format",
416
+ format: "jwt",
417
+ input: payload.value,
418
+ inst,
419
+ });
420
+ };
421
+ });
422
+ export const $ZodNumber = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, def) => {
423
+ $ZodType.init(inst, def);
424
+ inst._zod.pattern = inst._zod.bag.pattern ?? regexes.number;
425
+ inst._zod.parse = (payload, _ctx) => {
426
+ if (def.coerce)
427
+ try {
428
+ payload.value = Number(payload.value);
429
+ }
430
+ catch (_) { }
431
+ const input = payload.value;
432
+ if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) {
433
+ return payload;
434
+ }
435
+ const received = typeof input === "number"
436
+ ? Number.isNaN(input)
437
+ ? "NaN"
438
+ : !Number.isFinite(input)
439
+ ? "Infinity"
440
+ : undefined
441
+ : undefined;
442
+ payload.issues.push({
443
+ expected: "number",
444
+ code: "invalid_type",
445
+ input,
446
+ inst,
447
+ ...(received ? { received } : {}),
448
+ });
449
+ return payload;
450
+ };
451
+ });
452
+ export const $ZodNumberFormat = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, def) => {
453
+ checks.$ZodCheckNumberFormat.init(inst, def);
454
+ $ZodNumber.init(inst, def); // no format checksp
455
+ });
456
+ export const $ZodBoolean = /*@__PURE__*/ core.$constructor("$ZodBoolean", (inst, def) => {
457
+ $ZodType.init(inst, def);
458
+ inst._zod.pattern = regexes.boolean;
459
+ inst._zod.parse = (payload, _ctx) => {
460
+ if (def.coerce)
461
+ try {
462
+ payload.value = Boolean(payload.value);
463
+ }
464
+ catch (_) { }
465
+ const input = payload.value;
466
+ if (typeof input === "boolean")
467
+ return payload;
468
+ payload.issues.push({
469
+ expected: "boolean",
470
+ code: "invalid_type",
471
+ input,
472
+ inst,
473
+ });
474
+ return payload;
475
+ };
476
+ });
477
+ export const $ZodBigInt = /*@__PURE__*/ core.$constructor("$ZodBigInt", (inst, def) => {
478
+ $ZodType.init(inst, def);
479
+ inst._zod.pattern = regexes.bigint;
480
+ inst._zod.parse = (payload, _ctx) => {
481
+ if (def.coerce)
482
+ try {
483
+ payload.value = BigInt(payload.value);
484
+ }
485
+ catch (_) { }
486
+ const { value: input } = payload;
487
+ if (typeof input === "bigint")
488
+ return payload;
489
+ payload.issues.push({
490
+ expected: "bigint",
491
+ code: "invalid_type",
492
+ input,
493
+ inst,
494
+ });
495
+ return payload;
496
+ };
497
+ });
498
+ export const $ZodBigIntFormat = /*@__PURE__*/ core.$constructor("$ZodBigInt", (inst, def) => {
499
+ checks.$ZodCheckBigIntFormat.init(inst, def);
500
+ $ZodBigInt.init(inst, def); // no format checks
501
+ });
502
+ export const $ZodSymbol = /*@__PURE__*/ core.$constructor("$ZodSymbol", (inst, def) => {
503
+ $ZodType.init(inst, def);
504
+ inst._zod.parse = (payload, _ctx) => {
505
+ const { value: input } = payload;
506
+ if (typeof input === "symbol")
507
+ return payload;
508
+ payload.issues.push({
509
+ expected: "symbol",
510
+ code: "invalid_type",
511
+ input,
512
+ inst,
513
+ });
514
+ return payload;
515
+ };
516
+ });
517
+ export const $ZodUndefined = /*@__PURE__*/ core.$constructor("$ZodUndefined", (inst, def) => {
518
+ $ZodType.init(inst, def);
519
+ inst._zod.pattern = regexes.undefined;
520
+ inst._zod.values = new Set([undefined]);
521
+ inst._zod.parse = (payload, _ctx) => {
522
+ const { value: input } = payload;
523
+ if (typeof input === "undefined")
524
+ return payload;
525
+ payload.issues.push({
526
+ expected: "undefined",
527
+ code: "invalid_type",
528
+ input,
529
+ inst,
530
+ });
531
+ return payload;
532
+ };
533
+ });
534
+ export const $ZodNull = /*@__PURE__*/ core.$constructor("$ZodNull", (inst, def) => {
535
+ $ZodType.init(inst, def);
536
+ inst._zod.pattern = regexes.null;
537
+ inst._zod.values = new Set([null]);
538
+ inst._zod.parse = (payload, _ctx) => {
539
+ const { value: input } = payload;
540
+ if (input === null)
541
+ return payload;
542
+ payload.issues.push({
543
+ expected: "null",
544
+ code: "invalid_type",
545
+ input,
546
+ inst,
547
+ });
548
+ return payload;
549
+ };
550
+ });
551
+ export const $ZodAny = /*@__PURE__*/ core.$constructor("$ZodAny", (inst, def) => {
552
+ $ZodType.init(inst, def);
553
+ inst._zod.parse = (payload) => payload;
554
+ });
555
+ export const $ZodUnknown = /*@__PURE__*/ core.$constructor("$ZodUnknown", (inst, def) => {
556
+ $ZodType.init(inst, def);
557
+ inst._zod.parse = (payload) => payload;
558
+ });
559
+ export const $ZodNever = /*@__PURE__*/ core.$constructor("$ZodNever", (inst, def) => {
560
+ $ZodType.init(inst, def);
561
+ inst._zod.parse = (payload, _ctx) => {
562
+ payload.issues.push({
563
+ expected: "never",
564
+ code: "invalid_type",
565
+ input: payload.value,
566
+ inst,
567
+ });
568
+ return payload;
569
+ };
570
+ });
571
+ export const $ZodVoid = /*@__PURE__*/ core.$constructor("$ZodVoid", (inst, def) => {
572
+ $ZodType.init(inst, def);
573
+ inst._zod.parse = (payload, _ctx) => {
574
+ const { value: input } = payload;
575
+ if (typeof input === "undefined")
576
+ return payload;
577
+ payload.issues.push({
578
+ expected: "void",
579
+ code: "invalid_type",
580
+ input,
581
+ inst,
582
+ });
583
+ return payload;
584
+ };
585
+ });
586
+ export const $ZodDate = /*@__PURE__*/ core.$constructor("$ZodDate", (inst, def) => {
587
+ $ZodType.init(inst, def);
588
+ inst._zod.parse = (payload, _ctx) => {
589
+ if (def.coerce) {
590
+ try {
591
+ payload.value = new Date(payload.value);
592
+ }
593
+ catch (_err) { }
594
+ }
595
+ const input = payload.value;
596
+ const isDate = input instanceof Date;
597
+ const isValidDate = isDate && !Number.isNaN(input.getTime());
598
+ if (isValidDate)
599
+ return payload;
600
+ payload.issues.push({
601
+ expected: "date",
602
+ code: "invalid_type",
603
+ input,
604
+ ...(isDate ? { received: "Invalid Date" } : {}),
605
+ inst,
606
+ });
607
+ return payload;
608
+ };
609
+ });
610
+ function handleArrayResult(result, final, index) {
611
+ if (result.issues.length) {
612
+ final.issues.push(...util.prefixIssues(index, result.issues));
613
+ }
614
+ final.value[index] = result.value;
615
+ }
616
+ export const $ZodArray = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def) => {
617
+ $ZodType.init(inst, def);
618
+ inst._zod.parse = (payload, ctx) => {
619
+ const input = payload.value;
620
+ if (!Array.isArray(input)) {
621
+ payload.issues.push({
622
+ expected: "array",
623
+ code: "invalid_type",
624
+ input,
625
+ inst,
626
+ });
627
+ return payload;
628
+ }
629
+ payload.value = Array(input.length);
630
+ const proms = [];
631
+ for (let i = 0; i < input.length; i++) {
632
+ const item = input[i];
633
+ const result = def.element._zod.run({
634
+ value: item,
635
+ issues: [],
636
+ }, ctx);
637
+ if (result instanceof Promise) {
638
+ proms.push(result.then((result) => handleArrayResult(result, payload, i)));
639
+ }
640
+ else {
641
+ handleArrayResult(result, payload, i);
642
+ }
643
+ }
644
+ if (proms.length) {
645
+ return Promise.all(proms).then(() => payload);
646
+ }
647
+ return payload; //handleArrayResultsAsync(parseResults, final);
648
+ };
649
+ });
650
+ function handleObjectResult(result, final, key) {
651
+ // if(isOptional)
652
+ if (result.issues.length) {
653
+ final.issues.push(...util.prefixIssues(key, result.issues));
654
+ }
655
+ final.value[key] = result.value;
656
+ }
657
+ function handleOptionalObjectResult(result, final, key, input) {
658
+ if (result.issues.length) {
659
+ // validation failed against value schema
660
+ if (input[key] === undefined) {
661
+ // if input was undefined, ignore the error
662
+ if (key in input) {
663
+ final.value[key] = undefined;
664
+ }
665
+ else {
666
+ final.value[key] = result.value;
667
+ }
668
+ }
669
+ else {
670
+ final.issues.push(...util.prefixIssues(key, result.issues));
671
+ }
672
+ }
673
+ else if (result.value === undefined) {
674
+ // validation returned `undefined`
675
+ if (key in input)
676
+ final.value[key] = undefined;
677
+ }
678
+ else {
679
+ // non-undefined value
680
+ final.value[key] = result.value;
681
+ }
682
+ }
683
+ export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
684
+ $ZodType.init(inst, def);
685
+ const _normalized = util.cached(() => {
686
+ const keys = Object.keys(def.shape);
687
+ const okeys = util.optionalKeys(def.shape);
688
+ return {
689
+ shape: def.shape,
690
+ keys,
691
+ keySet: new Set(keys),
692
+ numKeys: keys.length,
693
+ optionalKeys: new Set(okeys),
694
+ };
695
+ });
696
+ util.defineLazy(inst._zod, "disc", () => {
697
+ const shape = def.shape;
698
+ const discMap = new Map();
699
+ let hasDisc = false;
700
+ for (const key in shape) {
701
+ const field = shape[key]._zod;
702
+ if (field.values || field.disc) {
703
+ hasDisc = true;
704
+ const o = {
705
+ values: new Set(field.values ?? []),
706
+ maps: field.disc ? [field.disc] : [],
707
+ };
708
+ discMap.set(key, o);
709
+ }
710
+ }
711
+ if (!hasDisc) {
712
+ return undefined;
713
+ }
714
+ return discMap;
715
+ });
716
+ const generateFastpass = (shape) => {
717
+ const doc = new Doc(["shape", "payload", "ctx"]);
718
+ const { keys, optionalKeys } = _normalized.value;
719
+ const parseStr = (key) => {
720
+ const k = util.esc(key);
721
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
722
+ };
723
+ doc.write(`const input = payload.value;`);
724
+ const ids = Object.create(null);
725
+ for (const key of keys) {
726
+ ids[key] = util.randomString(15);
727
+ }
728
+ // A: preserve key order {
729
+ doc.write(`const newResult = {}`);
730
+ for (const key of keys) {
731
+ if (optionalKeys.has(key)) {
732
+ const id = ids[key];
733
+ doc.write(`const ${id} = ${parseStr(key)};`);
734
+ const k = util.esc(key);
735
+ doc.write(`
736
+ if (${id}.issues.length) {
737
+ if (input[${k}] === undefined) {
738
+ if (${k} in input) {
739
+ newResult[${k}] = undefined;
740
+ }
741
+ } else {
742
+ payload.issues = payload.issues.concat(
743
+ ${id}.issues.map((iss) => ({
744
+ ...iss,
745
+ path: iss.path ? [${k}, ...iss.path] : [${k}],
746
+ }))
747
+ );
748
+ }
749
+ } else if (${id}.value === undefined) {
750
+ if (${k} in input) newResult[${k}] = undefined;
751
+ } else {
752
+ newResult[${k}] = ${id}.value;
753
+ }
754
+ `);
755
+ }
756
+ else {
757
+ const id = ids[key];
758
+ // const id = ids[key];
759
+ doc.write(`const ${id} = ${parseStr(key)};`);
760
+ doc.write(`
761
+ if (${id}.issues.length) payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
762
+ ...iss,
763
+ path: iss.path ? [${util.esc(key)}, ...iss.path] : [${util.esc(key)}]
764
+ })));`);
765
+ doc.write(`newResult[${util.esc(key)}] = ${id}.value`);
766
+ }
767
+ }
768
+ doc.write(`payload.value = newResult;`);
769
+ doc.write(`return payload;`);
770
+ const fn = doc.compile();
771
+ return (payload, ctx) => fn(shape, payload, ctx);
772
+ };
773
+ let fastpass;
774
+ const isObject = util.isObject;
775
+ const jit = !core.globalConfig.jitless;
776
+ const allowsEval = util.allowsEval;
777
+ const fastEnabled = jit && allowsEval.value; // && !def.catchall;
778
+ const { catchall } = def;
779
+ let value;
780
+ inst._zod.parse = (payload, ctx) => {
781
+ value ?? (value = _normalized.value);
782
+ const input = payload.value;
783
+ if (!isObject(input)) {
784
+ payload.issues.push({
785
+ expected: "object",
786
+ code: "invalid_type",
787
+ input,
788
+ inst,
789
+ });
790
+ return payload;
791
+ }
792
+ const proms = [];
793
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
794
+ // always synchronous
795
+ if (!fastpass)
796
+ fastpass = generateFastpass(def.shape);
797
+ payload = fastpass(payload, ctx);
798
+ }
799
+ else {
800
+ payload.value = {};
801
+ const shape = value.shape;
802
+ for (const key of value.keys) {
803
+ const el = shape[key];
804
+ // do not add omitted optional keys
805
+ // if (!(key in input)) {
806
+ // if (optionalKeys.has(key)) continue;
807
+ // payload.issues.push({
808
+ // code: "invalid_type",
809
+ // path: [key],
810
+ // expected: "nonoptional",
811
+ // note: `Missing required key: "${key}"`,
812
+ // input,
813
+ // inst,
814
+ // });
815
+ // }
816
+ const r = el._zod.run({ value: input[key], issues: [] }, ctx);
817
+ const isOptional = el._zod.optin === "optional";
818
+ if (r instanceof Promise) {
819
+ proms.push(r.then((r) => isOptional ? handleOptionalObjectResult(r, payload, key, input) : handleObjectResult(r, payload, key)));
820
+ }
821
+ else {
822
+ if (isOptional) {
823
+ handleOptionalObjectResult(r, payload, key, input);
824
+ }
825
+ else {
826
+ handleObjectResult(r, payload, key);
827
+ }
828
+ }
829
+ }
830
+ }
831
+ if (!catchall) {
832
+ // return payload;
833
+ return proms.length ? Promise.all(proms).then(() => payload) : payload;
834
+ }
835
+ const unrecognized = [];
836
+ // iterate over input keys
837
+ const keySet = value.keySet;
838
+ const _catchall = catchall._zod;
839
+ const t = _catchall.def.type;
840
+ for (const key of Object.keys(input)) {
841
+ if (keySet.has(key))
842
+ continue;
843
+ if (t === "never") {
844
+ unrecognized.push(key);
845
+ continue;
846
+ }
847
+ const r = _catchall.run({ value: input[key], issues: [] }, ctx);
848
+ if (r instanceof Promise) {
849
+ proms.push(r.then((r) => handleObjectResult(r, payload, key)));
850
+ }
851
+ else {
852
+ handleObjectResult(r, payload, key);
853
+ }
854
+ }
855
+ if (unrecognized.length) {
856
+ payload.issues.push({
857
+ code: "unrecognized_keys",
858
+ keys: unrecognized,
859
+ input,
860
+ inst,
861
+ });
862
+ }
863
+ if (!proms.length)
864
+ return payload;
865
+ return Promise.all(proms).then(() => {
866
+ return payload;
867
+ });
868
+ };
869
+ });
870
+ function handleUnionResults(results, final, inst, ctx) {
871
+ for (const result of results) {
872
+ if (result.issues.length === 0) {
873
+ final.value = result.value;
874
+ return final;
875
+ }
876
+ }
877
+ final.issues.push({
878
+ code: "invalid_union",
879
+ input: final.value,
880
+ inst,
881
+ errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
882
+ });
883
+ return final;
884
+ }
885
+ export const $ZodUnion = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def) => {
886
+ $ZodType.init(inst, def);
887
+ util.defineLazy(inst._zod, "values", () => {
888
+ if (def.options.every((o) => o._zod.values)) {
889
+ return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
890
+ }
891
+ return undefined;
892
+ });
893
+ util.defineLazy(inst._zod, "pattern", () => {
894
+ if (def.options.every((o) => o._zod.pattern)) {
895
+ const patterns = def.options.map((o) => o._zod.pattern);
896
+ return new RegExp(`^(${patterns.map((p) => util.cleanRegex(p.source)).join("|")})$`);
897
+ }
898
+ return undefined;
899
+ });
900
+ inst._zod.parse = (payload, ctx) => {
901
+ let async = false;
902
+ const results = [];
903
+ for (const option of def.options) {
904
+ const result = option._zod.run({
905
+ value: payload.value,
906
+ issues: [],
907
+ }, ctx);
908
+ if (result instanceof Promise) {
909
+ results.push(result);
910
+ async = true;
911
+ }
912
+ else {
913
+ if (result.issues.length === 0)
914
+ return result;
915
+ results.push(result);
916
+ }
917
+ }
918
+ if (!async)
919
+ return handleUnionResults(results, payload, inst, ctx);
920
+ return Promise.all(results).then((results) => {
921
+ return handleUnionResults(results, payload, inst, ctx);
922
+ });
923
+ };
924
+ });
925
+ function matchDiscriminatorAtKey(input, key, disc) {
926
+ let matched = true;
927
+ const data = input?.[key];
928
+ if (disc.values.size && !disc.values.has(data)) {
929
+ matched = false;
930
+ }
931
+ if (disc.maps.length > 0) {
932
+ for (const m of disc.maps) {
933
+ if (!matchDiscriminators(data, m)) {
934
+ matched = false;
935
+ }
936
+ }
937
+ }
938
+ return matched;
939
+ }
940
+ function matchDiscriminators(input, discs) {
941
+ let matched = true;
942
+ for (const [key, value] of discs) {
943
+ if (!matchDiscriminatorAtKey(input, key, value)) {
944
+ matched = false;
945
+ }
946
+ }
947
+ return matched;
948
+ }
949
+ export const $ZodDiscriminatedUnion =
950
+ /*@__PURE__*/
951
+ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
952
+ $ZodUnion.init(inst, def);
953
+ const _super = inst._zod.parse;
954
+ util.defineLazy(inst._zod, "disc", () => {
955
+ const _disc = new Map();
956
+ for (const el of def.options) {
957
+ const subdisc = el._zod.disc;
958
+ if (!subdisc)
959
+ throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(el)}"`);
960
+ for (const [key, o] of subdisc) {
961
+ if (!_disc.has(key))
962
+ _disc.set(key, {
963
+ values: new Set(),
964
+ maps: [],
965
+ });
966
+ const _o = _disc.get(key);
967
+ for (const v of o.values) {
968
+ _o.values.add(v);
969
+ }
970
+ for (const m of o.maps)
971
+ _o.maps.push(m);
972
+ }
973
+ }
974
+ return _disc;
975
+ });
976
+ const _discmap = util.cached(() => {
977
+ const map = new Map();
978
+ for (const o of def.options) {
979
+ const discEl = o._zod.disc?.get(def.discriminator);
980
+ if (!discEl)
981
+ throw new Error("Invalid discriminated union option");
982
+ map.set(o, discEl);
983
+ }
984
+ return map;
985
+ });
986
+ inst._zod.parse = (payload, ctx) => {
987
+ const input = payload.value;
988
+ if (!util.isObject(input)) {
989
+ payload.issues.push({
990
+ code: "invalid_type",
991
+ expected: "object",
992
+ input,
993
+ inst,
994
+ });
995
+ return payload;
996
+ }
997
+ const filtered = [];
998
+ const discmap = _discmap.value;
999
+ for (const option of def.options) {
1000
+ const subdisc = discmap.get(option);
1001
+ if (matchDiscriminatorAtKey(input, def.discriminator, subdisc)) {
1002
+ filtered.push(option);
1003
+ }
1004
+ }
1005
+ if (filtered.length === 1)
1006
+ return filtered[0]._zod.run(payload, ctx);
1007
+ if (def.unionFallback) {
1008
+ return _super(payload, ctx);
1009
+ }
1010
+ // no matching discriminator
1011
+ payload.issues.push({
1012
+ code: "invalid_union",
1013
+ errors: [],
1014
+ note: "No matching discriminator",
1015
+ input,
1016
+ path: [def.discriminator],
1017
+ inst,
1018
+ });
1019
+ return payload;
1020
+ };
1021
+ });
1022
+ export const $ZodIntersection = /*@__PURE__*/ core.$constructor("$ZodIntersection", (inst, def) => {
1023
+ $ZodType.init(inst, def);
1024
+ inst._zod.parse = (payload, ctx) => {
1025
+ const { value: input } = payload;
1026
+ const left = def.left._zod.run({ value: input, issues: [] }, ctx);
1027
+ const right = def.right._zod.run({ value: input, issues: [] }, ctx);
1028
+ const async = left instanceof Promise || right instanceof Promise;
1029
+ if (async) {
1030
+ return Promise.all([left, right]).then(([left, right]) => {
1031
+ return handleIntersectionResults(payload, left, right);
1032
+ });
1033
+ }
1034
+ return handleIntersectionResults(payload, left, right);
1035
+ };
1036
+ });
1037
+ function mergeValues(a, b) {
1038
+ // const aType = parse.t(a);
1039
+ // const bType = parse.t(b);
1040
+ if (a === b) {
1041
+ return { valid: true, data: a };
1042
+ }
1043
+ if (a instanceof Date && b instanceof Date && +a === +b) {
1044
+ return { valid: true, data: a };
1045
+ }
1046
+ if (util.isPlainObject(a) && util.isPlainObject(b)) {
1047
+ const bKeys = Object.keys(b);
1048
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1049
+ const newObj = { ...a, ...b };
1050
+ for (const key of sharedKeys) {
1051
+ const sharedValue = mergeValues(a[key], b[key]);
1052
+ if (!sharedValue.valid) {
1053
+ return {
1054
+ valid: false,
1055
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath],
1056
+ };
1057
+ }
1058
+ newObj[key] = sharedValue.data;
1059
+ }
1060
+ return { valid: true, data: newObj };
1061
+ }
1062
+ if (Array.isArray(a) && Array.isArray(b)) {
1063
+ if (a.length !== b.length) {
1064
+ return { valid: false, mergeErrorPath: [] };
1065
+ }
1066
+ const newArray = [];
1067
+ for (let index = 0; index < a.length; index++) {
1068
+ const itemA = a[index];
1069
+ const itemB = b[index];
1070
+ const sharedValue = mergeValues(itemA, itemB);
1071
+ if (!sharedValue.valid) {
1072
+ return {
1073
+ valid: false,
1074
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath],
1075
+ };
1076
+ }
1077
+ newArray.push(sharedValue.data);
1078
+ }
1079
+ return { valid: true, data: newArray };
1080
+ }
1081
+ return { valid: false, mergeErrorPath: [] };
1082
+ }
1083
+ function handleIntersectionResults(result, left, right) {
1084
+ if (left.issues.length) {
1085
+ result.issues.push(...left.issues);
1086
+ }
1087
+ if (right.issues.length) {
1088
+ result.issues.push(...right.issues);
1089
+ }
1090
+ if (util.aborted(result))
1091
+ return result;
1092
+ const merged = mergeValues(left.value, right.value);
1093
+ if (!merged.valid) {
1094
+ throw new Error(`Unmergable intersection. Error path: ` + `${JSON.stringify(merged.mergeErrorPath)}`);
1095
+ }
1096
+ result.value = merged.data;
1097
+ return result;
1098
+ }
1099
+ export const $ZodTuple = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def) => {
1100
+ $ZodType.init(inst, def);
1101
+ const items = def.items;
1102
+ const optStart = items.length - [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
1103
+ inst._zod.parse = (payload, ctx) => {
1104
+ const input = payload.value;
1105
+ if (!Array.isArray(input)) {
1106
+ payload.issues.push({
1107
+ input,
1108
+ inst,
1109
+ expected: "tuple",
1110
+ code: "invalid_type",
1111
+ });
1112
+ return payload;
1113
+ }
1114
+ payload.value = [];
1115
+ const proms = [];
1116
+ if (!def.rest) {
1117
+ const tooBig = input.length > items.length;
1118
+ const tooSmall = input.length < optStart - 1;
1119
+ if (tooBig || tooSmall) {
1120
+ payload.issues.push({
1121
+ input,
1122
+ inst,
1123
+ origin: "array",
1124
+ ...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
1125
+ });
1126
+ return payload;
1127
+ }
1128
+ }
1129
+ let i = -1;
1130
+ for (const item of items) {
1131
+ i++;
1132
+ if (i >= input.length)
1133
+ if (i >= optStart)
1134
+ continue;
1135
+ const result = item._zod.run({
1136
+ value: input[i],
1137
+ issues: [],
1138
+ }, ctx);
1139
+ if (result instanceof Promise) {
1140
+ proms.push(result.then((result) => handleTupleResult(result, payload, i)));
1141
+ }
1142
+ else {
1143
+ handleTupleResult(result, payload, i);
1144
+ }
1145
+ }
1146
+ if (def.rest) {
1147
+ const rest = input.slice(items.length);
1148
+ for (const el of rest) {
1149
+ i++;
1150
+ const result = def.rest._zod.run({
1151
+ value: el,
1152
+ issues: [],
1153
+ }, ctx);
1154
+ if (result instanceof Promise) {
1155
+ proms.push(result.then((result) => handleTupleResult(result, payload, i)));
1156
+ }
1157
+ else {
1158
+ handleTupleResult(result, payload, i);
1159
+ }
1160
+ }
1161
+ }
1162
+ if (proms.length)
1163
+ return Promise.all(proms).then(() => payload);
1164
+ return payload;
1165
+ };
1166
+ });
1167
+ function handleTupleResult(result, final, index) {
1168
+ if (result.issues.length) {
1169
+ final.issues.push(...util.prefixIssues(index, result.issues));
1170
+ }
1171
+ final.value[index] = result.value;
1172
+ }
1173
+ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, def) => {
1174
+ $ZodType.init(inst, def);
1175
+ inst._zod.parse = (payload, ctx) => {
1176
+ const input = payload.value;
1177
+ if (!util.isPlainObject(input)) {
1178
+ payload.issues.push({
1179
+ expected: "record",
1180
+ code: "invalid_type",
1181
+ input,
1182
+ inst,
1183
+ });
1184
+ return payload;
1185
+ }
1186
+ const proms = [];
1187
+ if (def.keyType._zod.values) {
1188
+ const values = def.keyType._zod.values;
1189
+ payload.value = {};
1190
+ for (const key of values) {
1191
+ if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
1192
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1193
+ if (result instanceof Promise) {
1194
+ proms.push(result.then((result) => {
1195
+ if (result.issues.length) {
1196
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1197
+ }
1198
+ payload.value[key] = result.value;
1199
+ }));
1200
+ }
1201
+ else {
1202
+ if (result.issues.length) {
1203
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1204
+ }
1205
+ payload.value[key] = result.value;
1206
+ }
1207
+ }
1208
+ }
1209
+ let unrecognized;
1210
+ for (const key in input) {
1211
+ if (!values.has(key)) {
1212
+ unrecognized = unrecognized ?? [];
1213
+ unrecognized.push(key);
1214
+ }
1215
+ }
1216
+ if (unrecognized && unrecognized.length > 0) {
1217
+ payload.issues.push({
1218
+ code: "unrecognized_keys",
1219
+ input,
1220
+ inst,
1221
+ keys: unrecognized,
1222
+ });
1223
+ }
1224
+ }
1225
+ else {
1226
+ payload.value = {};
1227
+ for (const key of Reflect.ownKeys(input)) {
1228
+ if (key === "__proto__")
1229
+ continue;
1230
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1231
+ if (keyResult instanceof Promise) {
1232
+ throw new Error("Async schemas not supported in object keys currently");
1233
+ }
1234
+ if (keyResult.issues.length) {
1235
+ payload.issues.push({
1236
+ origin: "record",
1237
+ code: "invalid_key",
1238
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1239
+ input: key,
1240
+ path: [key],
1241
+ inst,
1242
+ });
1243
+ payload.value[keyResult.value] = keyResult.value;
1244
+ continue;
1245
+ }
1246
+ const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
1247
+ if (result instanceof Promise) {
1248
+ proms.push(result.then((result) => {
1249
+ if (result.issues.length) {
1250
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1251
+ }
1252
+ payload.value[keyResult.value] = result.value;
1253
+ }));
1254
+ }
1255
+ else {
1256
+ if (result.issues.length) {
1257
+ payload.issues.push(...util.prefixIssues(key, result.issues));
1258
+ }
1259
+ payload.value[keyResult.value] = result.value;
1260
+ }
1261
+ }
1262
+ }
1263
+ if (proms.length) {
1264
+ return Promise.all(proms).then(() => payload);
1265
+ }
1266
+ return payload;
1267
+ };
1268
+ });
1269
+ export const $ZodMap = /*@__PURE__*/ core.$constructor("$ZodMap", (inst, def) => {
1270
+ $ZodType.init(inst, def);
1271
+ inst._zod.parse = (payload, ctx) => {
1272
+ const input = payload.value;
1273
+ if (!(input instanceof Map)) {
1274
+ payload.issues.push({
1275
+ expected: "map",
1276
+ code: "invalid_type",
1277
+ input,
1278
+ inst,
1279
+ });
1280
+ return payload;
1281
+ }
1282
+ const proms = [];
1283
+ payload.value = new Map();
1284
+ for (const [key, value] of input) {
1285
+ const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1286
+ const valueResult = def.valueType._zod.run({ value: value, issues: [] }, ctx);
1287
+ if (keyResult instanceof Promise || valueResult instanceof Promise) {
1288
+ proms.push(Promise.all([keyResult, valueResult]).then(([keyResult, valueResult]) => {
1289
+ handleMapResult(keyResult, valueResult, payload, key, input, inst, ctx);
1290
+ }));
1291
+ }
1292
+ else {
1293
+ handleMapResult(keyResult, valueResult, payload, key, input, inst, ctx);
1294
+ }
1295
+ }
1296
+ if (proms.length)
1297
+ return Promise.all(proms).then(() => payload);
1298
+ return payload;
1299
+ };
1300
+ });
1301
+ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1302
+ if (keyResult.issues.length) {
1303
+ if (util.propertyKeyTypes.has(typeof key)) {
1304
+ final.issues.push(...util.prefixIssues(key, keyResult.issues));
1305
+ }
1306
+ else {
1307
+ final.issues.push({
1308
+ origin: "map",
1309
+ code: "invalid_key",
1310
+ input,
1311
+ inst,
1312
+ issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1313
+ });
1314
+ }
1315
+ }
1316
+ if (valueResult.issues.length) {
1317
+ if (util.propertyKeyTypes.has(typeof key)) {
1318
+ final.issues.push(...util.prefixIssues(key, valueResult.issues));
1319
+ }
1320
+ else {
1321
+ final.issues.push({
1322
+ origin: "map",
1323
+ code: "invalid_element",
1324
+ input,
1325
+ inst,
1326
+ key: key,
1327
+ issues: valueResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1328
+ });
1329
+ }
1330
+ }
1331
+ final.value.set(keyResult.value, valueResult.value);
1332
+ }
1333
+ export const $ZodSet = /*@__PURE__*/ core.$constructor("$ZodSet", (inst, def) => {
1334
+ $ZodType.init(inst, def);
1335
+ inst._zod.parse = (payload, ctx) => {
1336
+ const input = payload.value;
1337
+ if (!(input instanceof Set)) {
1338
+ payload.issues.push({
1339
+ input,
1340
+ inst,
1341
+ expected: "set",
1342
+ code: "invalid_type",
1343
+ });
1344
+ return payload;
1345
+ }
1346
+ const proms = [];
1347
+ payload.value = new Set();
1348
+ for (const item of input) {
1349
+ const result = def.valueType._zod.run({ value: item, issues: [] }, ctx);
1350
+ if (result instanceof Promise) {
1351
+ proms.push(result.then((result) => handleSetResult(result, payload)));
1352
+ }
1353
+ else
1354
+ handleSetResult(result, payload);
1355
+ }
1356
+ if (proms.length)
1357
+ return Promise.all(proms).then(() => payload);
1358
+ return payload;
1359
+ };
1360
+ });
1361
+ function handleSetResult(result, final) {
1362
+ if (result.issues.length) {
1363
+ final.issues.push(...result.issues);
1364
+ }
1365
+ final.value.add(result.value);
1366
+ }
1367
+ export const $ZodEnum = /*@__PURE__*/ core.$constructor("$ZodEnum", (inst, def) => {
1368
+ $ZodType.init(inst, def);
1369
+ const numericValues = Object.values(def.entries).filter((v) => typeof v === "number");
1370
+ const values = Object.entries(def.entries)
1371
+ .filter(([k, _]) => numericValues.indexOf(+k) === -1)
1372
+ .map(([_, v]) => v);
1373
+ inst._zod.values = new Set(values);
1374
+ inst._zod.pattern = new RegExp(`^(${values
1375
+ .filter((k) => util.propertyKeyTypes.has(typeof k))
1376
+ .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o.toString()))
1377
+ .join("|")})$`);
1378
+ inst._zod.parse = (payload, _ctx) => {
1379
+ const input = payload.value;
1380
+ if (inst._zod.values.has(input)) {
1381
+ return payload;
1382
+ }
1383
+ payload.issues.push({
1384
+ code: "invalid_value",
1385
+ values,
1386
+ input,
1387
+ inst,
1388
+ });
1389
+ return payload;
1390
+ };
1391
+ });
1392
+ export const $ZodLiteral = /*@__PURE__*/ core.$constructor("$ZodLiteral", (inst, def) => {
1393
+ $ZodType.init(inst, def);
1394
+ inst._zod.values = new Set(def.values);
1395
+ inst._zod.pattern = new RegExp(`^(${def.values
1396
+ .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? o.toString() : String(o)))
1397
+ .join("|")})$`);
1398
+ inst._zod.parse = (payload, _ctx) => {
1399
+ const input = payload.value;
1400
+ if (inst._zod.values.has(input)) {
1401
+ return payload;
1402
+ }
1403
+ payload.issues.push({
1404
+ code: "invalid_value",
1405
+ values: def.values,
1406
+ input,
1407
+ inst,
1408
+ });
1409
+ return payload;
1410
+ };
1411
+ });
1412
+ export const $ZodFile = /*@__PURE__*/ core.$constructor("$ZodFile", (inst, def) => {
1413
+ $ZodType.init(inst, def);
1414
+ inst._zod.parse = (payload, _ctx) => {
1415
+ const input = payload.value;
1416
+ if (input instanceof File)
1417
+ return payload;
1418
+ payload.issues.push({
1419
+ expected: "file",
1420
+ code: "invalid_type",
1421
+ input,
1422
+ inst,
1423
+ });
1424
+ return payload;
1425
+ };
1426
+ });
1427
+ export const $ZodTransform = /*@__PURE__*/ core.$constructor("$ZodTransform", (inst, def) => {
1428
+ $ZodType.init(inst, def);
1429
+ inst._zod.parse = (payload, _ctx) => {
1430
+ const _out = def.transform(payload.value, payload);
1431
+ if (_ctx.async) {
1432
+ const output = _out instanceof Promise ? _out : Promise.resolve(_out);
1433
+ return output.then((output) => {
1434
+ payload.value = output;
1435
+ return payload;
1436
+ });
1437
+ }
1438
+ if (_out instanceof Promise) {
1439
+ throw new core.$ZodAsyncError();
1440
+ }
1441
+ payload.value = _out;
1442
+ return payload;
1443
+ };
1444
+ });
1445
+ export const $ZodOptional = /*@__PURE__*/ core.$constructor("$ZodOptional", (inst, def) => {
1446
+ $ZodType.init(inst, def);
1447
+ inst._zod.optin = "optional";
1448
+ inst._zod.optout = "optional";
1449
+ util.defineLazy(inst._zod, "values", () => {
1450
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, undefined]) : undefined;
1451
+ });
1452
+ util.defineLazy(inst._zod, "pattern", () => {
1453
+ const pattern = def.innerType._zod.pattern;
1454
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)})?$`) : undefined;
1455
+ });
1456
+ inst._zod.parse = (payload, ctx) => {
1457
+ if (payload.value === undefined) {
1458
+ return payload;
1459
+ }
1460
+ return def.innerType._zod.run(payload, ctx);
1461
+ };
1462
+ });
1463
+ export const $ZodNullable = /*@__PURE__*/ core.$constructor("$ZodNullable", (inst, def) => {
1464
+ $ZodType.init(inst, def);
1465
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1466
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1467
+ util.defineLazy(inst._zod, "pattern", () => {
1468
+ const pattern = def.innerType._zod.pattern;
1469
+ return pattern ? new RegExp(`^(${util.cleanRegex(pattern.source)}|null)$`) : undefined;
1470
+ });
1471
+ util.defineLazy(inst._zod, "values", () => {
1472
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
1473
+ });
1474
+ inst._zod.parse = (payload, ctx) => {
1475
+ if (payload.value === null)
1476
+ return payload;
1477
+ return def.innerType._zod.run(payload, ctx);
1478
+ };
1479
+ });
1480
+ export const $ZodDefault = /*@__PURE__*/ core.$constructor("$ZodDefault", (inst, def) => {
1481
+ $ZodType.init(inst, def);
1482
+ // inst._zod.qin = "true";
1483
+ inst._zod.optin = "optional";
1484
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1485
+ inst._zod.parse = (payload, ctx) => {
1486
+ if (payload.value === undefined) {
1487
+ payload.value = def.defaultValue;
1488
+ /**
1489
+ * $ZodDefault always returns the default value immediately.
1490
+ * 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. */
1491
+ return payload;
1492
+ }
1493
+ const result = def.innerType._zod.run(payload, ctx);
1494
+ if (result instanceof Promise) {
1495
+ return result.then((result) => handleDefaultResult(result, def));
1496
+ }
1497
+ return handleDefaultResult(result, def);
1498
+ };
1499
+ });
1500
+ function handleDefaultResult(payload, def) {
1501
+ if (payload.value === undefined) {
1502
+ payload.value = def.defaultValue;
1503
+ }
1504
+ return payload;
1505
+ }
1506
+ export const $ZodPrefault = /*@__PURE__*/ core.$constructor("$ZodPrefault", (inst, def) => {
1507
+ $ZodType.init(inst, def);
1508
+ inst._zod.optin = "optional";
1509
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1510
+ inst._zod.parse = (payload, ctx) => {
1511
+ if (payload.value === undefined) {
1512
+ payload.value = def.defaultValue;
1513
+ }
1514
+ return def.innerType._zod.run(payload, ctx);
1515
+ };
1516
+ });
1517
+ export const $ZodNonOptional = /*@__PURE__*/ core.$constructor("$ZodNonOptional", (inst, def) => {
1518
+ $ZodType.init(inst, def);
1519
+ util.defineLazy(inst._zod, "values", () => {
1520
+ const v = def.innerType._zod.values;
1521
+ return v ? new Set([...v].filter((x) => x !== undefined)) : undefined;
1522
+ });
1523
+ inst._zod.parse = (payload, ctx) => {
1524
+ const result = def.innerType._zod.run(payload, ctx);
1525
+ if (result instanceof Promise) {
1526
+ return result.then((result) => handleNonOptionalResult(result, inst));
1527
+ }
1528
+ return handleNonOptionalResult(result, inst);
1529
+ };
1530
+ });
1531
+ function handleNonOptionalResult(payload, inst) {
1532
+ if (!payload.issues.length && payload.value === undefined) {
1533
+ payload.issues.push({
1534
+ code: "invalid_type",
1535
+ expected: "nonoptional",
1536
+ input: payload.value,
1537
+ inst,
1538
+ });
1539
+ }
1540
+ return payload;
1541
+ }
1542
+ export const $ZodSuccess = /*@__PURE__*/ core.$constructor("$ZodSuccess", (inst, def) => {
1543
+ $ZodType.init(inst, def);
1544
+ inst._zod.parse = (payload, ctx) => {
1545
+ const result = def.innerType._zod.run(payload, ctx);
1546
+ if (result instanceof Promise) {
1547
+ return result.then((result) => {
1548
+ payload.value = result.issues.length === 0;
1549
+ return payload;
1550
+ });
1551
+ }
1552
+ payload.value = result.issues.length === 0;
1553
+ return payload;
1554
+ };
1555
+ });
1556
+ export const $ZodCatch = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
1557
+ $ZodType.init(inst, def);
1558
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1559
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1560
+ util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1561
+ inst._zod.parse = (payload, ctx) => {
1562
+ const result = def.innerType._zod.run(payload, ctx);
1563
+ if (result instanceof Promise) {
1564
+ return result.then((result) => {
1565
+ payload.value = result.value;
1566
+ if (result.issues.length) {
1567
+ payload.value = def.catchValue({
1568
+ ...payload,
1569
+ error: {
1570
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1571
+ },
1572
+ input: payload.value,
1573
+ });
1574
+ payload.issues = [];
1575
+ }
1576
+ return payload;
1577
+ });
1578
+ }
1579
+ payload.value = result.value;
1580
+ if (result.issues.length) {
1581
+ payload.value = def.catchValue({
1582
+ ...payload,
1583
+ error: {
1584
+ issues: result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1585
+ },
1586
+ input: payload.value,
1587
+ });
1588
+ payload.issues = [];
1589
+ }
1590
+ return payload;
1591
+ };
1592
+ });
1593
+ export const $ZodNaN = /*@__PURE__*/ core.$constructor("$ZodNaN", (inst, def) => {
1594
+ $ZodType.init(inst, def);
1595
+ inst._zod.parse = (payload, _ctx) => {
1596
+ if (typeof payload.value !== "number" || !Number.isNaN(payload.value)) {
1597
+ payload.issues.push({
1598
+ input: payload.value,
1599
+ inst,
1600
+ expected: "nan",
1601
+ code: "invalid_type",
1602
+ });
1603
+ return payload;
1604
+ }
1605
+ return payload;
1606
+ };
1607
+ });
1608
+ export const $ZodPipe = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def) => {
1609
+ $ZodType.init(inst, def);
1610
+ util.defineLazy(inst._zod, "values", () => def.in._zod.values);
1611
+ util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1612
+ util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1613
+ inst._zod.parse = (payload, ctx) => {
1614
+ const left = def.in._zod.run(payload, ctx);
1615
+ if (left instanceof Promise) {
1616
+ return left.then((left) => handlePipeResult(left, def, ctx));
1617
+ }
1618
+ return handlePipeResult(left, def, ctx);
1619
+ };
1620
+ });
1621
+ function handlePipeResult(left, def, ctx) {
1622
+ if (util.aborted(left)) {
1623
+ return left;
1624
+ }
1625
+ return def.out._zod.run({ value: left.value, issues: left.issues }, ctx);
1626
+ }
1627
+ export const $ZodReadonly = /*@__PURE__*/ core.$constructor("$ZodReadonly", (inst, def) => {
1628
+ $ZodType.init(inst, def);
1629
+ util.defineLazy(inst._zod, "disc", () => def.innerType._zod.disc);
1630
+ util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1631
+ util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1632
+ inst._zod.parse = (payload, ctx) => {
1633
+ const result = def.innerType._zod.run(payload, ctx);
1634
+ if (result instanceof Promise) {
1635
+ return result.then(handleReadonlyResult);
1636
+ }
1637
+ return handleReadonlyResult(result);
1638
+ };
1639
+ });
1640
+ function handleReadonlyResult(payload) {
1641
+ payload.value = Object.freeze(payload.value);
1642
+ return payload;
1643
+ }
1644
+ export const $ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("$ZodTemplateLiteral", (inst, def) => {
1645
+ $ZodType.init(inst, def);
1646
+ const regexParts = [];
1647
+ for (const part of def.parts) {
1648
+ if (part instanceof $ZodType) {
1649
+ if (!part._zod.pattern) {
1650
+ // if (!source)
1651
+ throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
1652
+ }
1653
+ const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;
1654
+ if (!source)
1655
+ throw new Error(`Invalid template literal part: ${part._zod.traits}`);
1656
+ const start = source.startsWith("^") ? 1 : 0;
1657
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
1658
+ regexParts.push(source.slice(start, end));
1659
+ }
1660
+ else if (part === null || util.primitiveTypes.has(typeof part)) {
1661
+ regexParts.push(util.escapeRegex(`${part}`));
1662
+ }
1663
+ else {
1664
+ throw new Error(`Invalid template literal part: ${part}`);
1665
+ }
1666
+ }
1667
+ inst._zod.pattern = new RegExp(`^${regexParts.join("")}$`);
1668
+ inst._zod.parse = (payload, _ctx) => {
1669
+ if (typeof payload.value !== "string") {
1670
+ payload.issues.push({
1671
+ input: payload.value,
1672
+ inst,
1673
+ expected: "template_literal",
1674
+ code: "invalid_type",
1675
+ });
1676
+ return payload;
1677
+ }
1678
+ inst._zod.pattern.lastIndex = 0;
1679
+ if (!inst._zod.pattern.test(payload.value)) {
1680
+ payload.issues.push({
1681
+ input: payload.value,
1682
+ inst,
1683
+ code: "invalid_format",
1684
+ format: "template_literal",
1685
+ pattern: inst._zod.pattern.source,
1686
+ });
1687
+ return payload;
1688
+ }
1689
+ return payload;
1690
+ };
1691
+ });
1692
+ export const $ZodPromise = /*@__PURE__*/ core.$constructor("$ZodPromise", (inst, def) => {
1693
+ $ZodType.init(inst, def);
1694
+ inst._zod.parse = (payload, ctx) => {
1695
+ return Promise.resolve(payload.value).then((inner) => def.innerType._zod.run({ value: inner, issues: [] }, ctx));
1696
+ };
1697
+ });
1698
+ export const $ZodLazy = /*@__PURE__*/ core.$constructor("$ZodLazy", (inst, def) => {
1699
+ $ZodType.init(inst, def);
1700
+ util.defineLazy(inst._zod, "innerType", () => def.getter());
1701
+ util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType._zod.pattern);
1702
+ util.defineLazy(inst._zod, "disc", () => inst._zod.innerType._zod.disc);
1703
+ util.defineLazy(inst._zod, "optin", () => inst._zod.innerType._zod.optin);
1704
+ util.defineLazy(inst._zod, "optout", () => inst._zod.innerType._zod.optout);
1705
+ inst._zod.parse = (payload, ctx) => {
1706
+ const inner = inst._zod.innerType;
1707
+ return inner._zod.run(payload, ctx);
1708
+ };
1709
+ });
1710
+ export const $ZodCustom = /*@__PURE__*/ core.$constructor("$ZodCustom", (inst, def) => {
1711
+ checks.$ZodCheck.init(inst, def);
1712
+ $ZodType.init(inst, def);
1713
+ inst._zod.parse = (payload, _) => {
1714
+ return payload;
1715
+ };
1716
+ inst._zod.check = (payload) => {
1717
+ const input = payload.value;
1718
+ const r = def.fn(input);
1719
+ if (r instanceof Promise) {
1720
+ return r.then((r) => handleRefineResult(r, payload, input, inst));
1721
+ }
1722
+ handleRefineResult(r, payload, input, inst);
1723
+ return;
1724
+ };
1725
+ });
1726
+ function handleRefineResult(result, payload, input, inst) {
1727
+ if (!result) {
1728
+ const _iss = {
1729
+ code: "custom",
1730
+ input,
1731
+ inst, // incorporates params.error into issue reporting
1732
+ path: [...(inst._zod.def.path ?? [])], // incorporates params.error into issue reporting
1733
+ continue: !inst._zod.def.abort,
1734
+ // params: inst._zod.def.params,
1735
+ };
1736
+ if (inst._zod.def.params)
1737
+ _iss.params = inst._zod.def.params;
1738
+ payload.issues.push(util.issue(_iss));
1739
+ }
1740
+ }