zod 3.25.21 → 3.25.22

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