makecoder 1.0.25

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 (656) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +281 -0
  3. package/claude/commands/dev/ultra-think.md +153 -0
  4. package/claude/commands/docs/generate-api-documentation.md +80 -0
  5. package/claude/commands/git/commit.md +63 -0
  6. package/claude/commands/git/status.md +39 -0
  7. package/claude/commands/setup/migrate-to-typescript.md +76 -0
  8. package/claude/commands/test/generate-test-cases.md +76 -0
  9. package/dist/cc.mjs +4654 -0
  10. package/dist/coder.js +201 -0
  11. package/dist/codex +0 -0
  12. package/dist/codex.exe +0 -0
  13. package/dist/codex.mjs +162 -0
  14. package/dist/gcli.mjs +3162 -0
  15. package/dist/vendor/claude-code-jetbrains-plugin/lib/annotations-23.0.0.jar +0 -0
  16. package/dist/vendor/claude-code-jetbrains-plugin/lib/claude-code-jetbrains-plugin-0.1.12-beta-searchableOptions.jar +0 -0
  17. package/dist/vendor/claude-code-jetbrains-plugin/lib/claude-code-jetbrains-plugin-0.1.12-beta.jar +0 -0
  18. package/dist/vendor/claude-code-jetbrains-plugin/lib/config-1.4.3.jar +0 -0
  19. package/dist/vendor/claude-code-jetbrains-plugin/lib/jansi-2.4.1.jar +0 -0
  20. package/dist/vendor/claude-code-jetbrains-plugin/lib/kotlin-logging-jvm-7.0.0.jar +0 -0
  21. package/dist/vendor/claude-code-jetbrains-plugin/lib/kotlin-reflect-2.0.21.jar +0 -0
  22. package/dist/vendor/claude-code-jetbrains-plugin/lib/kotlin-sdk-jvm-0.4.0.jar +0 -0
  23. package/dist/vendor/claude-code-jetbrains-plugin/lib/kotlin-stdlib-2.1.20.jar +0 -0
  24. package/dist/vendor/claude-code-jetbrains-plugin/lib/kotlinx-coroutines-core-jvm-1.9.0.jar +0 -0
  25. package/dist/vendor/claude-code-jetbrains-plugin/lib/kotlinx-coroutines-slf4j-1.9.0.jar +0 -0
  26. package/dist/vendor/claude-code-jetbrains-plugin/lib/kotlinx-io-bytestring-jvm-0.5.4.jar +0 -0
  27. package/dist/vendor/claude-code-jetbrains-plugin/lib/kotlinx-io-core-jvm-0.5.4.jar +0 -0
  28. package/dist/vendor/claude-code-jetbrains-plugin/lib/kotlinx-serialization-core-jvm-1.8.1.jar +0 -0
  29. package/dist/vendor/claude-code-jetbrains-plugin/lib/kotlinx-serialization-json-jvm-1.8.1.jar +0 -0
  30. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-client-cio-jvm-3.0.2.jar +0 -0
  31. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-client-core-jvm-3.0.2.jar +0 -0
  32. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-events-jvm-3.0.2.jar +0 -0
  33. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-http-cio-jvm-3.0.2.jar +0 -0
  34. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-http-jvm-3.0.2.jar +0 -0
  35. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-io-jvm-3.0.2.jar +0 -0
  36. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-network-jvm-3.0.2.jar +0 -0
  37. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-network-tls-jvm-3.0.2.jar +0 -0
  38. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-serialization-jvm-3.0.2.jar +0 -0
  39. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-server-cio-jvm-3.0.2.jar +0 -0
  40. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-server-core-jvm-3.0.2.jar +0 -0
  41. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-server-sse-jvm-3.0.2.jar +0 -0
  42. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-server-websockets-jvm-3.0.2.jar +0 -0
  43. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-sse-jvm-3.0.2.jar +0 -0
  44. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-utils-jvm-3.0.2.jar +0 -0
  45. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-websocket-serialization-jvm-3.0.2.jar +0 -0
  46. package/dist/vendor/claude-code-jetbrains-plugin/lib/ktor-websockets-jvm-3.0.2.jar +0 -0
  47. package/dist/vendor/claude-code-jetbrains-plugin/lib/slf4j-api-2.0.16.jar +0 -0
  48. package/dist/vendor/ripgrep/COPYING +3 -0
  49. package/dist/vendor/ripgrep/arm64-darwin/rg +0 -0
  50. package/dist/vendor/ripgrep/arm64-darwin/ripgrep.node +0 -0
  51. package/dist/vendor/ripgrep/arm64-linux/rg +0 -0
  52. package/dist/vendor/ripgrep/arm64-linux/ripgrep.node +0 -0
  53. package/dist/vendor/ripgrep/x64-darwin/rg +0 -0
  54. package/dist/vendor/ripgrep/x64-darwin/ripgrep.node +0 -0
  55. package/dist/vendor/ripgrep/x64-linux/rg +0 -0
  56. package/dist/vendor/ripgrep/x64-linux/ripgrep.node +0 -0
  57. package/dist/vendor/ripgrep/x64-win32/rg.exe +0 -0
  58. package/dist/vendor/ripgrep/x64-win32/ripgrep.node +0 -0
  59. package/dist/zod/LICENSE +21 -0
  60. package/dist/zod/README.md +208 -0
  61. package/dist/zod/index.cjs +33 -0
  62. package/dist/zod/index.d.cts +4 -0
  63. package/dist/zod/index.d.ts +4 -0
  64. package/dist/zod/index.js +4 -0
  65. package/dist/zod/package.json +118 -0
  66. package/dist/zod/src/index.ts +4 -0
  67. package/dist/zod/src/v3/ZodError.ts +330 -0
  68. package/dist/zod/src/v3/benchmarks/datetime.ts +58 -0
  69. package/dist/zod/src/v3/benchmarks/discriminatedUnion.ts +80 -0
  70. package/dist/zod/src/v3/benchmarks/index.ts +59 -0
  71. package/dist/zod/src/v3/benchmarks/ipv4.ts +57 -0
  72. package/dist/zod/src/v3/benchmarks/object.ts +69 -0
  73. package/dist/zod/src/v3/benchmarks/primitives.ts +162 -0
  74. package/dist/zod/src/v3/benchmarks/realworld.ts +63 -0
  75. package/dist/zod/src/v3/benchmarks/string.ts +55 -0
  76. package/dist/zod/src/v3/benchmarks/union.ts +80 -0
  77. package/dist/zod/src/v3/errors.ts +13 -0
  78. package/dist/zod/src/v3/external.ts +6 -0
  79. package/dist/zod/src/v3/helpers/enumUtil.ts +17 -0
  80. package/dist/zod/src/v3/helpers/errorUtil.ts +8 -0
  81. package/dist/zod/src/v3/helpers/parseUtil.ts +176 -0
  82. package/dist/zod/src/v3/helpers/partialUtil.ts +34 -0
  83. package/dist/zod/src/v3/helpers/typeAliases.ts +2 -0
  84. package/dist/zod/src/v3/helpers/util.ts +224 -0
  85. package/dist/zod/src/v3/index.ts +4 -0
  86. package/dist/zod/src/v3/locales/en.ts +124 -0
  87. package/dist/zod/src/v3/standard-schema.ts +113 -0
  88. package/dist/zod/src/v3/tests/Mocker.ts +54 -0
  89. package/dist/zod/src/v3/tests/all-errors.test.ts +157 -0
  90. package/dist/zod/src/v3/tests/anyunknown.test.ts +28 -0
  91. package/dist/zod/src/v3/tests/array.test.ts +71 -0
  92. package/dist/zod/src/v3/tests/async-parsing.test.ts +388 -0
  93. package/dist/zod/src/v3/tests/async-refinements.test.ts +46 -0
  94. package/dist/zod/src/v3/tests/base.test.ts +29 -0
  95. package/dist/zod/src/v3/tests/bigint.test.ts +55 -0
  96. package/dist/zod/src/v3/tests/branded.test.ts +53 -0
  97. package/dist/zod/src/v3/tests/catch.test.ts +220 -0
  98. package/dist/zod/src/v3/tests/coerce.test.ts +133 -0
  99. package/dist/zod/src/v3/tests/complex.test.ts +56 -0
  100. package/dist/zod/src/v3/tests/custom.test.ts +31 -0
  101. package/dist/zod/src/v3/tests/date.test.ts +32 -0
  102. package/dist/zod/src/v3/tests/deepmasking.test.ts +186 -0
  103. package/dist/zod/src/v3/tests/default.test.ts +112 -0
  104. package/dist/zod/src/v3/tests/description.test.ts +33 -0
  105. package/dist/zod/src/v3/tests/discriminated-unions.test.ts +315 -0
  106. package/dist/zod/src/v3/tests/enum.test.ts +80 -0
  107. package/dist/zod/src/v3/tests/error.test.ts +551 -0
  108. package/dist/zod/src/v3/tests/firstparty.test.ts +87 -0
  109. package/dist/zod/src/v3/tests/firstpartyschematypes.test.ts +21 -0
  110. package/dist/zod/src/v3/tests/function.test.ts +257 -0
  111. package/dist/zod/src/v3/tests/generics.test.ts +48 -0
  112. package/dist/zod/src/v3/tests/instanceof.test.ts +37 -0
  113. package/dist/zod/src/v3/tests/intersection.test.ts +110 -0
  114. package/dist/zod/src/v3/tests/language-server.source.ts +76 -0
  115. package/dist/zod/src/v3/tests/language-server.test.ts +207 -0
  116. package/dist/zod/src/v3/tests/literal.test.ts +36 -0
  117. package/dist/zod/src/v3/tests/map.test.ts +110 -0
  118. package/dist/zod/src/v3/tests/masking.test.ts +4 -0
  119. package/dist/zod/src/v3/tests/mocker.test.ts +19 -0
  120. package/dist/zod/src/v3/tests/nan.test.ts +21 -0
  121. package/dist/zod/src/v3/tests/nativeEnum.test.ts +87 -0
  122. package/dist/zod/src/v3/tests/nullable.test.ts +42 -0
  123. package/dist/zod/src/v3/tests/number.test.ts +176 -0
  124. package/dist/zod/src/v3/tests/object-augmentation.test.ts +29 -0
  125. package/dist/zod/src/v3/tests/object-in-es5-env.test.ts +29 -0
  126. package/dist/zod/src/v3/tests/object.test.ts +434 -0
  127. package/dist/zod/src/v3/tests/optional.test.ts +42 -0
  128. package/dist/zod/src/v3/tests/parseUtil.test.ts +23 -0
  129. package/dist/zod/src/v3/tests/parser.test.ts +41 -0
  130. package/dist/zod/src/v3/tests/partials.test.ts +243 -0
  131. package/dist/zod/src/v3/tests/pickomit.test.ts +111 -0
  132. package/dist/zod/src/v3/tests/pipeline.test.ts +29 -0
  133. package/dist/zod/src/v3/tests/preprocess.test.ts +186 -0
  134. package/dist/zod/src/v3/tests/primitive.test.ts +440 -0
  135. package/dist/zod/src/v3/tests/promise.test.ts +90 -0
  136. package/dist/zod/src/v3/tests/readonly.test.ts +194 -0
  137. package/dist/zod/src/v3/tests/record.test.ts +171 -0
  138. package/dist/zod/src/v3/tests/recursive.test.ts +197 -0
  139. package/dist/zod/src/v3/tests/refine.test.ts +313 -0
  140. package/dist/zod/src/v3/tests/safeparse.test.ts +27 -0
  141. package/dist/zod/src/v3/tests/set.test.ts +142 -0
  142. package/dist/zod/src/v3/tests/standard-schema.test.ts +83 -0
  143. package/dist/zod/src/v3/tests/string.test.ts +916 -0
  144. package/dist/zod/src/v3/tests/transformer.test.ts +233 -0
  145. package/dist/zod/src/v3/tests/tuple.test.ts +90 -0
  146. package/dist/zod/src/v3/tests/unions.test.ts +57 -0
  147. package/dist/zod/src/v3/tests/validations.test.ts +133 -0
  148. package/dist/zod/src/v3/tests/void.test.ts +15 -0
  149. package/dist/zod/src/v3/types.ts +5136 -0
  150. package/dist/zod/src/v4/classic/checks.ts +30 -0
  151. package/dist/zod/src/v4/classic/coerce.ts +27 -0
  152. package/dist/zod/src/v4/classic/compat.ts +66 -0
  153. package/dist/zod/src/v4/classic/errors.ts +75 -0
  154. package/dist/zod/src/v4/classic/external.ts +50 -0
  155. package/dist/zod/src/v4/classic/index.ts +5 -0
  156. package/dist/zod/src/v4/classic/iso.ts +90 -0
  157. package/dist/zod/src/v4/classic/parse.ts +33 -0
  158. package/dist/zod/src/v4/classic/schemas.ts +2054 -0
  159. package/dist/zod/src/v4/classic/tests/anyunknown.test.ts +26 -0
  160. package/dist/zod/src/v4/classic/tests/array.test.ts +264 -0
  161. package/dist/zod/src/v4/classic/tests/assignability.test.ts +210 -0
  162. package/dist/zod/src/v4/classic/tests/async-parsing.test.ts +381 -0
  163. package/dist/zod/src/v4/classic/tests/async-refinements.test.ts +68 -0
  164. package/dist/zod/src/v4/classic/tests/base.test.ts +7 -0
  165. package/dist/zod/src/v4/classic/tests/bigint.test.ts +54 -0
  166. package/dist/zod/src/v4/classic/tests/brand.test.ts +63 -0
  167. package/dist/zod/src/v4/classic/tests/catch.test.ts +252 -0
  168. package/dist/zod/src/v4/classic/tests/coalesce.test.ts +20 -0
  169. package/dist/zod/src/v4/classic/tests/coerce.test.ts +160 -0
  170. package/dist/zod/src/v4/classic/tests/continuability.test.ts +352 -0
  171. package/dist/zod/src/v4/classic/tests/custom.test.ts +40 -0
  172. package/dist/zod/src/v4/classic/tests/date.test.ts +31 -0
  173. package/dist/zod/src/v4/classic/tests/datetime.test.ts +296 -0
  174. package/dist/zod/src/v4/classic/tests/default.test.ts +313 -0
  175. package/dist/zod/src/v4/classic/tests/description.test.ts +32 -0
  176. package/dist/zod/src/v4/classic/tests/discriminated-unions.test.ts +619 -0
  177. package/dist/zod/src/v4/classic/tests/enum.test.ts +285 -0
  178. package/dist/zod/src/v4/classic/tests/error-utils.test.ts +527 -0
  179. package/dist/zod/src/v4/classic/tests/error.test.ts +711 -0
  180. package/dist/zod/src/v4/classic/tests/file.test.ts +91 -0
  181. package/dist/zod/src/v4/classic/tests/firstparty.test.ts +175 -0
  182. package/dist/zod/src/v4/classic/tests/function.test.ts +268 -0
  183. package/dist/zod/src/v4/classic/tests/generics.test.ts +72 -0
  184. package/dist/zod/src/v4/classic/tests/index.test.ts +829 -0
  185. package/dist/zod/src/v4/classic/tests/instanceof.test.ts +34 -0
  186. package/dist/zod/src/v4/classic/tests/intersection.test.ts +171 -0
  187. package/dist/zod/src/v4/classic/tests/json.test.ts +108 -0
  188. package/dist/zod/src/v4/classic/tests/lazy.test.ts +227 -0
  189. package/dist/zod/src/v4/classic/tests/literal.test.ts +92 -0
  190. package/dist/zod/src/v4/classic/tests/map.test.ts +196 -0
  191. package/dist/zod/src/v4/classic/tests/nan.test.ts +21 -0
  192. package/dist/zod/src/v4/classic/tests/nested-refine.test.ts +168 -0
  193. package/dist/zod/src/v4/classic/tests/nonoptional.test.ts +86 -0
  194. package/dist/zod/src/v4/classic/tests/nullable.test.ts +22 -0
  195. package/dist/zod/src/v4/classic/tests/number.test.ts +247 -0
  196. package/dist/zod/src/v4/classic/tests/object.test.ts +563 -0
  197. package/dist/zod/src/v4/classic/tests/optional.test.ts +123 -0
  198. package/dist/zod/src/v4/classic/tests/partial.test.ts +147 -0
  199. package/dist/zod/src/v4/classic/tests/pickomit.test.ts +127 -0
  200. package/dist/zod/src/v4/classic/tests/pipe.test.ts +81 -0
  201. package/dist/zod/src/v4/classic/tests/prefault.test.ts +37 -0
  202. package/dist/zod/src/v4/classic/tests/preprocess.test.ts +298 -0
  203. package/dist/zod/src/v4/classic/tests/primitive.test.ts +175 -0
  204. package/dist/zod/src/v4/classic/tests/promise.test.ts +81 -0
  205. package/dist/zod/src/v4/classic/tests/prototypes.test.ts +23 -0
  206. package/dist/zod/src/v4/classic/tests/readonly.test.ts +252 -0
  207. package/dist/zod/src/v4/classic/tests/record.test.ts +342 -0
  208. package/dist/zod/src/v4/classic/tests/recursive-types.test.ts +356 -0
  209. package/dist/zod/src/v4/classic/tests/refine.test.ts +532 -0
  210. package/dist/zod/src/v4/classic/tests/registries.test.ts +204 -0
  211. package/dist/zod/src/v4/classic/tests/set.test.ts +179 -0
  212. package/dist/zod/src/v4/classic/tests/standard-schema.test.ts +57 -0
  213. package/dist/zod/src/v4/classic/tests/string-formats.test.ts +109 -0
  214. package/dist/zod/src/v4/classic/tests/string.test.ts +881 -0
  215. package/dist/zod/src/v4/classic/tests/stringbool.test.ts +66 -0
  216. package/dist/zod/src/v4/classic/tests/template-literal.test.ts +758 -0
  217. package/dist/zod/src/v4/classic/tests/to-json-schema.test.ts +2314 -0
  218. package/dist/zod/src/v4/classic/tests/transform.test.ts +250 -0
  219. package/dist/zod/src/v4/classic/tests/tuple.test.ts +163 -0
  220. package/dist/zod/src/v4/classic/tests/union.test.ts +94 -0
  221. package/dist/zod/src/v4/classic/tests/validations.test.ts +283 -0
  222. package/dist/zod/src/v4/classic/tests/void.test.ts +12 -0
  223. package/dist/zod/src/v4/core/api.ts +1594 -0
  224. package/dist/zod/src/v4/core/checks.ts +1283 -0
  225. package/dist/zod/src/v4/core/config.ts +15 -0
  226. package/dist/zod/src/v4/core/core.ts +134 -0
  227. package/dist/zod/src/v4/core/doc.ts +44 -0
  228. package/dist/zod/src/v4/core/errors.ts +424 -0
  229. package/dist/zod/src/v4/core/function.ts +176 -0
  230. package/dist/zod/src/v4/core/index.ts +15 -0
  231. package/dist/zod/src/v4/core/json-schema.ts +143 -0
  232. package/dist/zod/src/v4/core/parse.ts +94 -0
  233. package/dist/zod/src/v4/core/regexes.ts +135 -0
  234. package/dist/zod/src/v4/core/registries.ts +96 -0
  235. package/dist/zod/src/v4/core/schemas.ts +3842 -0
  236. package/dist/zod/src/v4/core/standard-schema.ts +64 -0
  237. package/dist/zod/src/v4/core/tests/index.test.ts +46 -0
  238. package/dist/zod/src/v4/core/tests/locales/be.test.ts +124 -0
  239. package/dist/zod/src/v4/core/tests/locales/en.test.ts +22 -0
  240. package/dist/zod/src/v4/core/tests/locales/ru.test.ts +128 -0
  241. package/dist/zod/src/v4/core/tests/locales/tr.test.ts +69 -0
  242. package/dist/zod/src/v4/core/to-json-schema.ts +977 -0
  243. package/dist/zod/src/v4/core/util.ts +775 -0
  244. package/dist/zod/src/v4/core/versions.ts +5 -0
  245. package/dist/zod/src/v4/core/zsf.ts +323 -0
  246. package/dist/zod/src/v4/index.ts +4 -0
  247. package/dist/zod/src/v4/locales/ar.ts +125 -0
  248. package/dist/zod/src/v4/locales/az.ts +121 -0
  249. package/dist/zod/src/v4/locales/be.ts +184 -0
  250. package/dist/zod/src/v4/locales/ca.ts +127 -0
  251. package/dist/zod/src/v4/locales/cs.ts +142 -0
  252. package/dist/zod/src/v4/locales/de.ts +124 -0
  253. package/dist/zod/src/v4/locales/en.ts +127 -0
  254. package/dist/zod/src/v4/locales/eo.ts +125 -0
  255. package/dist/zod/src/v4/locales/es.ts +125 -0
  256. package/dist/zod/src/v4/locales/fa.ts +134 -0
  257. package/dist/zod/src/v4/locales/fi.ts +131 -0
  258. package/dist/zod/src/v4/locales/fr-CA.ts +126 -0
  259. package/dist/zod/src/v4/locales/fr.ts +124 -0
  260. package/dist/zod/src/v4/locales/he.ts +125 -0
  261. package/dist/zod/src/v4/locales/hu.ts +126 -0
  262. package/dist/zod/src/v4/locales/id.ts +125 -0
  263. package/dist/zod/src/v4/locales/index.ts +39 -0
  264. package/dist/zod/src/v4/locales/it.ts +125 -0
  265. package/dist/zod/src/v4/locales/ja.ts +122 -0
  266. package/dist/zod/src/v4/locales/kh.ts +126 -0
  267. package/dist/zod/src/v4/locales/ko.ts +131 -0
  268. package/dist/zod/src/v4/locales/mk.ts +127 -0
  269. package/dist/zod/src/v4/locales/ms.ts +124 -0
  270. package/dist/zod/src/v4/locales/nl.ts +126 -0
  271. package/dist/zod/src/v4/locales/no.ts +124 -0
  272. package/dist/zod/src/v4/locales/ota.ts +125 -0
  273. package/dist/zod/src/v4/locales/pl.ts +126 -0
  274. package/dist/zod/src/v4/locales/ps.ts +133 -0
  275. package/dist/zod/src/v4/locales/pt.ts +123 -0
  276. package/dist/zod/src/v4/locales/ru.ts +184 -0
  277. package/dist/zod/src/v4/locales/sl.ts +126 -0
  278. package/dist/zod/src/v4/locales/sv.ts +127 -0
  279. package/dist/zod/src/v4/locales/ta.ts +125 -0
  280. package/dist/zod/src/v4/locales/th.ts +126 -0
  281. package/dist/zod/src/v4/locales/tr.ts +121 -0
  282. package/dist/zod/src/v4/locales/ua.ts +126 -0
  283. package/dist/zod/src/v4/locales/ur.ts +126 -0
  284. package/dist/zod/src/v4/locales/vi.ts +125 -0
  285. package/dist/zod/src/v4/locales/zh-CN.ts +123 -0
  286. package/dist/zod/src/v4/locales/zh-TW.ts +125 -0
  287. package/dist/zod/src/v4/mini/checks.ts +32 -0
  288. package/dist/zod/src/v4/mini/coerce.ts +22 -0
  289. package/dist/zod/src/v4/mini/external.ts +40 -0
  290. package/dist/zod/src/v4/mini/index.ts +3 -0
  291. package/dist/zod/src/v4/mini/iso.ts +62 -0
  292. package/dist/zod/src/v4/mini/parse.ts +1 -0
  293. package/dist/zod/src/v4/mini/schemas.ts +1579 -0
  294. package/dist/zod/src/v4/mini/tests/assignability.test.ts +129 -0
  295. package/dist/zod/src/v4/mini/tests/brand.test.ts +51 -0
  296. package/dist/zod/src/v4/mini/tests/checks.test.ts +144 -0
  297. package/dist/zod/src/v4/mini/tests/computed.test.ts +36 -0
  298. package/dist/zod/src/v4/mini/tests/error.test.ts +22 -0
  299. package/dist/zod/src/v4/mini/tests/functions.test.ts +43 -0
  300. package/dist/zod/src/v4/mini/tests/index.test.ts +871 -0
  301. package/dist/zod/src/v4/mini/tests/number.test.ts +95 -0
  302. package/dist/zod/src/v4/mini/tests/object.test.ts +185 -0
  303. package/dist/zod/src/v4/mini/tests/prototypes.test.ts +43 -0
  304. package/dist/zod/src/v4/mini/tests/recursive-types.test.ts +275 -0
  305. package/dist/zod/src/v4/mini/tests/string.test.ts +299 -0
  306. package/dist/zod/src/v4-mini/index.ts +1 -0
  307. package/dist/zod/v3/ZodError.cjs +138 -0
  308. package/dist/zod/v3/ZodError.d.cts +164 -0
  309. package/dist/zod/v3/ZodError.d.ts +164 -0
  310. package/dist/zod/v3/ZodError.js +133 -0
  311. package/dist/zod/v3/errors.cjs +17 -0
  312. package/dist/zod/v3/errors.d.cts +5 -0
  313. package/dist/zod/v3/errors.d.ts +5 -0
  314. package/dist/zod/v3/errors.js +9 -0
  315. package/dist/zod/v3/external.cjs +22 -0
  316. package/dist/zod/v3/external.d.cts +6 -0
  317. package/dist/zod/v3/external.d.ts +6 -0
  318. package/dist/zod/v3/external.js +6 -0
  319. package/dist/zod/v3/helpers/enumUtil.cjs +2 -0
  320. package/dist/zod/v3/helpers/enumUtil.d.cts +8 -0
  321. package/dist/zod/v3/helpers/enumUtil.d.ts +8 -0
  322. package/dist/zod/v3/helpers/enumUtil.js +1 -0
  323. package/dist/zod/v3/helpers/errorUtil.cjs +9 -0
  324. package/dist/zod/v3/helpers/errorUtil.d.cts +9 -0
  325. package/dist/zod/v3/helpers/errorUtil.d.ts +9 -0
  326. package/dist/zod/v3/helpers/errorUtil.js +6 -0
  327. package/dist/zod/v3/helpers/parseUtil.cjs +124 -0
  328. package/dist/zod/v3/helpers/parseUtil.d.cts +78 -0
  329. package/dist/zod/v3/helpers/parseUtil.d.ts +78 -0
  330. package/dist/zod/v3/helpers/parseUtil.js +109 -0
  331. package/dist/zod/v3/helpers/partialUtil.cjs +2 -0
  332. package/dist/zod/v3/helpers/partialUtil.d.cts +8 -0
  333. package/dist/zod/v3/helpers/partialUtil.d.ts +8 -0
  334. package/dist/zod/v3/helpers/partialUtil.js +1 -0
  335. package/dist/zod/v3/helpers/typeAliases.cjs +2 -0
  336. package/dist/zod/v3/helpers/typeAliases.d.cts +2 -0
  337. package/dist/zod/v3/helpers/typeAliases.d.ts +2 -0
  338. package/dist/zod/v3/helpers/typeAliases.js +1 -0
  339. package/dist/zod/v3/helpers/util.cjs +137 -0
  340. package/dist/zod/v3/helpers/util.d.cts +85 -0
  341. package/dist/zod/v3/helpers/util.d.ts +85 -0
  342. package/dist/zod/v3/helpers/util.js +133 -0
  343. package/dist/zod/v3/index.cjs +33 -0
  344. package/dist/zod/v3/index.d.cts +4 -0
  345. package/dist/zod/v3/index.d.ts +4 -0
  346. package/dist/zod/v3/index.js +4 -0
  347. package/dist/zod/v3/locales/en.cjs +111 -0
  348. package/dist/zod/v3/locales/en.d.cts +3 -0
  349. package/dist/zod/v3/locales/en.d.ts +3 -0
  350. package/dist/zod/v3/locales/en.js +109 -0
  351. package/dist/zod/v3/standard-schema.cjs +2 -0
  352. package/dist/zod/v3/standard-schema.d.cts +102 -0
  353. package/dist/zod/v3/standard-schema.d.ts +102 -0
  354. package/dist/zod/v3/standard-schema.js +1 -0
  355. package/dist/zod/v3/types.cjs +3775 -0
  356. package/dist/zod/v3/types.d.cts +1031 -0
  357. package/dist/zod/v3/types.d.ts +1031 -0
  358. package/dist/zod/v3/types.js +3693 -0
  359. package/dist/zod/v4/classic/checks.cjs +32 -0
  360. package/dist/zod/v4/classic/checks.d.cts +1 -0
  361. package/dist/zod/v4/classic/checks.d.ts +1 -0
  362. package/dist/zod/v4/classic/checks.js +1 -0
  363. package/dist/zod/v4/classic/coerce.cjs +47 -0
  364. package/dist/zod/v4/classic/coerce.d.cts +17 -0
  365. package/dist/zod/v4/classic/coerce.d.ts +17 -0
  366. package/dist/zod/v4/classic/coerce.js +17 -0
  367. package/dist/zod/v4/classic/compat.cjs +57 -0
  368. package/dist/zod/v4/classic/compat.d.cts +46 -0
  369. package/dist/zod/v4/classic/compat.d.ts +46 -0
  370. package/dist/zod/v4/classic/compat.js +27 -0
  371. package/dist/zod/v4/classic/errors.cjs +67 -0
  372. package/dist/zod/v4/classic/errors.d.cts +30 -0
  373. package/dist/zod/v4/classic/errors.d.ts +30 -0
  374. package/dist/zod/v4/classic/errors.js +41 -0
  375. package/dist/zod/v4/classic/external.cjs +70 -0
  376. package/dist/zod/v4/classic/external.d.cts +13 -0
  377. package/dist/zod/v4/classic/external.d.ts +13 -0
  378. package/dist/zod/v4/classic/external.js +18 -0
  379. package/dist/zod/v4/classic/index.cjs +33 -0
  380. package/dist/zod/v4/classic/index.d.cts +4 -0
  381. package/dist/zod/v4/classic/index.d.ts +4 -0
  382. package/dist/zod/v4/classic/index.js +4 -0
  383. package/dist/zod/v4/classic/iso.cjs +60 -0
  384. package/dist/zod/v4/classic/iso.d.cts +22 -0
  385. package/dist/zod/v4/classic/iso.d.ts +22 -0
  386. package/dist/zod/v4/classic/iso.js +30 -0
  387. package/dist/zod/v4/classic/parse.cjs +32 -0
  388. package/dist/zod/v4/classic/parse.d.cts +23 -0
  389. package/dist/zod/v4/classic/parse.d.ts +23 -0
  390. package/dist/zod/v4/classic/parse.js +6 -0
  391. package/dist/zod/v4/classic/schemas.cjs +1109 -0
  392. package/dist/zod/v4/classic/schemas.d.cts +630 -0
  393. package/dist/zod/v4/classic/schemas.d.ts +630 -0
  394. package/dist/zod/v4/classic/schemas.js +1006 -0
  395. package/dist/zod/v4/core/api.cjs +1039 -0
  396. package/dist/zod/v4/core/api.d.cts +284 -0
  397. package/dist/zod/v4/core/api.d.ts +284 -0
  398. package/dist/zod/v4/core/api.js +906 -0
  399. package/dist/zod/v4/core/checks.cjs +591 -0
  400. package/dist/zod/v4/core/checks.d.cts +278 -0
  401. package/dist/zod/v4/core/checks.d.ts +278 -0
  402. package/dist/zod/v4/core/checks.js +565 -0
  403. package/dist/zod/v4/core/core.cjs +67 -0
  404. package/dist/zod/v4/core/core.d.cts +49 -0
  405. package/dist/zod/v4/core/core.d.ts +49 -0
  406. package/dist/zod/v4/core/core.js +61 -0
  407. package/dist/zod/v4/core/doc.cjs +39 -0
  408. package/dist/zod/v4/core/doc.d.cts +14 -0
  409. package/dist/zod/v4/core/doc.d.ts +14 -0
  410. package/dist/zod/v4/core/doc.js +35 -0
  411. package/dist/zod/v4/core/errors.cjs +226 -0
  412. package/dist/zod/v4/core/errors.d.cts +208 -0
  413. package/dist/zod/v4/core/errors.d.ts +208 -0
  414. package/dist/zod/v4/core/errors.js +195 -0
  415. package/dist/zod/v4/core/function.cjs +102 -0
  416. package/dist/zod/v4/core/function.d.cts +52 -0
  417. package/dist/zod/v4/core/function.d.ts +52 -0
  418. package/dist/zod/v4/core/function.js +75 -0
  419. package/dist/zod/v4/core/index.cjs +44 -0
  420. package/dist/zod/v4/core/index.d.cts +15 -0
  421. package/dist/zod/v4/core/index.d.ts +15 -0
  422. package/dist/zod/v4/core/index.js +15 -0
  423. package/dist/zod/v4/core/json-schema.cjs +2 -0
  424. package/dist/zod/v4/core/json-schema.d.cts +87 -0
  425. package/dist/zod/v4/core/json-schema.d.ts +87 -0
  426. package/dist/zod/v4/core/json-schema.js +1 -0
  427. package/dist/zod/v4/core/parse.cjs +87 -0
  428. package/dist/zod/v4/core/parse.d.cts +25 -0
  429. package/dist/zod/v4/core/parse.d.ts +25 -0
  430. package/dist/zod/v4/core/parse.js +57 -0
  431. package/dist/zod/v4/core/regexes.cjs +103 -0
  432. package/dist/zod/v4/core/regexes.d.cts +62 -0
  433. package/dist/zod/v4/core/regexes.d.ts +62 -0
  434. package/dist/zod/v4/core/regexes.js +95 -0
  435. package/dist/zod/v4/core/registries.cjs +56 -0
  436. package/dist/zod/v4/core/registries.d.cts +35 -0
  437. package/dist/zod/v4/core/registries.d.ts +35 -0
  438. package/dist/zod/v4/core/registries.js +51 -0
  439. package/dist/zod/v4/core/schemas.cjs +1748 -0
  440. package/dist/zod/v4/core/schemas.d.cts +1041 -0
  441. package/dist/zod/v4/core/schemas.d.ts +1041 -0
  442. package/dist/zod/v4/core/schemas.js +1717 -0
  443. package/dist/zod/v4/core/standard-schema.cjs +2 -0
  444. package/dist/zod/v4/core/standard-schema.d.cts +55 -0
  445. package/dist/zod/v4/core/standard-schema.d.ts +55 -0
  446. package/dist/zod/v4/core/standard-schema.js +1 -0
  447. package/dist/zod/v4/core/to-json-schema.cjs +854 -0
  448. package/dist/zod/v4/core/to-json-schema.d.cts +88 -0
  449. package/dist/zod/v4/core/to-json-schema.d.ts +88 -0
  450. package/dist/zod/v4/core/to-json-schema.js +849 -0
  451. package/dist/zod/v4/core/util.cjs +539 -0
  452. package/dist/zod/v4/core/util.d.cts +183 -0
  453. package/dist/zod/v4/core/util.d.ts +183 -0
  454. package/dist/zod/v4/core/util.js +493 -0
  455. package/dist/zod/v4/core/versions.cjs +8 -0
  456. package/dist/zod/v4/core/versions.d.cts +5 -0
  457. package/dist/zod/v4/core/versions.d.ts +5 -0
  458. package/dist/zod/v4/core/versions.js +5 -0
  459. package/dist/zod/v4/index.cjs +22 -0
  460. package/dist/zod/v4/index.d.cts +3 -0
  461. package/dist/zod/v4/index.d.ts +3 -0
  462. package/dist/zod/v4/index.js +3 -0
  463. package/dist/zod/v4/locales/ar.cjs +142 -0
  464. package/dist/zod/v4/locales/ar.d.cts +4 -0
  465. package/dist/zod/v4/locales/ar.d.ts +4 -0
  466. package/dist/zod/v4/locales/ar.js +116 -0
  467. package/dist/zod/v4/locales/az.cjs +141 -0
  468. package/dist/zod/v4/locales/az.d.cts +4 -0
  469. package/dist/zod/v4/locales/az.d.ts +4 -0
  470. package/dist/zod/v4/locales/az.js +115 -0
  471. package/dist/zod/v4/locales/be.cjs +190 -0
  472. package/dist/zod/v4/locales/be.d.cts +4 -0
  473. package/dist/zod/v4/locales/be.d.ts +4 -0
  474. package/dist/zod/v4/locales/be.js +164 -0
  475. package/dist/zod/v4/locales/ca.cjs +144 -0
  476. package/dist/zod/v4/locales/ca.d.cts +4 -0
  477. package/dist/zod/v4/locales/ca.d.ts +4 -0
  478. package/dist/zod/v4/locales/ca.js +118 -0
  479. package/dist/zod/v4/locales/cs.cjs +161 -0
  480. package/dist/zod/v4/locales/cs.d.cts +4 -0
  481. package/dist/zod/v4/locales/cs.d.ts +4 -0
  482. package/dist/zod/v4/locales/cs.js +135 -0
  483. package/dist/zod/v4/locales/de.cjs +142 -0
  484. package/dist/zod/v4/locales/de.d.cts +4 -0
  485. package/dist/zod/v4/locales/de.d.ts +4 -0
  486. package/dist/zod/v4/locales/de.js +116 -0
  487. package/dist/zod/v4/locales/en.cjs +145 -0
  488. package/dist/zod/v4/locales/en.d.cts +5 -0
  489. package/dist/zod/v4/locales/en.d.ts +5 -0
  490. package/dist/zod/v4/locales/en.js +117 -0
  491. package/dist/zod/v4/locales/eo.cjs +144 -0
  492. package/dist/zod/v4/locales/eo.d.cts +5 -0
  493. package/dist/zod/v4/locales/eo.d.ts +5 -0
  494. package/dist/zod/v4/locales/eo.js +116 -0
  495. package/dist/zod/v4/locales/es.cjs +143 -0
  496. package/dist/zod/v4/locales/es.d.cts +4 -0
  497. package/dist/zod/v4/locales/es.d.ts +4 -0
  498. package/dist/zod/v4/locales/es.js +117 -0
  499. package/dist/zod/v4/locales/fa.cjs +148 -0
  500. package/dist/zod/v4/locales/fa.d.cts +4 -0
  501. package/dist/zod/v4/locales/fa.d.ts +4 -0
  502. package/dist/zod/v4/locales/fa.js +122 -0
  503. package/dist/zod/v4/locales/fi.cjs +148 -0
  504. package/dist/zod/v4/locales/fi.d.cts +4 -0
  505. package/dist/zod/v4/locales/fi.d.ts +4 -0
  506. package/dist/zod/v4/locales/fi.js +122 -0
  507. package/dist/zod/v4/locales/fr-CA.cjs +143 -0
  508. package/dist/zod/v4/locales/fr-CA.d.cts +4 -0
  509. package/dist/zod/v4/locales/fr-CA.d.ts +4 -0
  510. package/dist/zod/v4/locales/fr-CA.js +117 -0
  511. package/dist/zod/v4/locales/fr.cjs +142 -0
  512. package/dist/zod/v4/locales/fr.d.cts +4 -0
  513. package/dist/zod/v4/locales/fr.d.ts +4 -0
  514. package/dist/zod/v4/locales/fr.js +116 -0
  515. package/dist/zod/v4/locales/he.cjs +143 -0
  516. package/dist/zod/v4/locales/he.d.cts +4 -0
  517. package/dist/zod/v4/locales/he.d.ts +4 -0
  518. package/dist/zod/v4/locales/he.js +117 -0
  519. package/dist/zod/v4/locales/hu.cjs +143 -0
  520. package/dist/zod/v4/locales/hu.d.cts +4 -0
  521. package/dist/zod/v4/locales/hu.d.ts +4 -0
  522. package/dist/zod/v4/locales/hu.js +117 -0
  523. package/dist/zod/v4/locales/id.cjs +142 -0
  524. package/dist/zod/v4/locales/id.d.cts +4 -0
  525. package/dist/zod/v4/locales/id.d.ts +4 -0
  526. package/dist/zod/v4/locales/id.js +116 -0
  527. package/dist/zod/v4/locales/index.cjs +84 -0
  528. package/dist/zod/v4/locales/index.d.cts +39 -0
  529. package/dist/zod/v4/locales/index.d.ts +39 -0
  530. package/dist/zod/v4/locales/index.js +39 -0
  531. package/dist/zod/v4/locales/it.cjs +143 -0
  532. package/dist/zod/v4/locales/it.d.cts +4 -0
  533. package/dist/zod/v4/locales/it.d.ts +4 -0
  534. package/dist/zod/v4/locales/it.js +117 -0
  535. package/dist/zod/v4/locales/ja.cjs +141 -0
  536. package/dist/zod/v4/locales/ja.d.cts +4 -0
  537. package/dist/zod/v4/locales/ja.d.ts +4 -0
  538. package/dist/zod/v4/locales/ja.js +115 -0
  539. package/dist/zod/v4/locales/kh.cjs +143 -0
  540. package/dist/zod/v4/locales/kh.d.cts +4 -0
  541. package/dist/zod/v4/locales/kh.d.ts +4 -0
  542. package/dist/zod/v4/locales/kh.js +117 -0
  543. package/dist/zod/v4/locales/ko.cjs +147 -0
  544. package/dist/zod/v4/locales/ko.d.cts +4 -0
  545. package/dist/zod/v4/locales/ko.d.ts +4 -0
  546. package/dist/zod/v4/locales/ko.js +121 -0
  547. package/dist/zod/v4/locales/mk.cjs +144 -0
  548. package/dist/zod/v4/locales/mk.d.cts +4 -0
  549. package/dist/zod/v4/locales/mk.d.ts +4 -0
  550. package/dist/zod/v4/locales/mk.js +118 -0
  551. package/dist/zod/v4/locales/ms.cjs +142 -0
  552. package/dist/zod/v4/locales/ms.d.cts +4 -0
  553. package/dist/zod/v4/locales/ms.d.ts +4 -0
  554. package/dist/zod/v4/locales/ms.js +116 -0
  555. package/dist/zod/v4/locales/nl.cjs +143 -0
  556. package/dist/zod/v4/locales/nl.d.cts +4 -0
  557. package/dist/zod/v4/locales/nl.d.ts +4 -0
  558. package/dist/zod/v4/locales/nl.js +117 -0
  559. package/dist/zod/v4/locales/no.cjs +142 -0
  560. package/dist/zod/v4/locales/no.d.cts +4 -0
  561. package/dist/zod/v4/locales/no.d.ts +4 -0
  562. package/dist/zod/v4/locales/no.js +116 -0
  563. package/dist/zod/v4/locales/ota.cjs +143 -0
  564. package/dist/zod/v4/locales/ota.d.cts +4 -0
  565. package/dist/zod/v4/locales/ota.d.ts +4 -0
  566. package/dist/zod/v4/locales/ota.js +117 -0
  567. package/dist/zod/v4/locales/pl.cjs +143 -0
  568. package/dist/zod/v4/locales/pl.d.cts +4 -0
  569. package/dist/zod/v4/locales/pl.d.ts +4 -0
  570. package/dist/zod/v4/locales/pl.js +117 -0
  571. package/dist/zod/v4/locales/ps.cjs +148 -0
  572. package/dist/zod/v4/locales/ps.d.cts +4 -0
  573. package/dist/zod/v4/locales/ps.d.ts +4 -0
  574. package/dist/zod/v4/locales/ps.js +122 -0
  575. package/dist/zod/v4/locales/pt.cjs +142 -0
  576. package/dist/zod/v4/locales/pt.d.cts +4 -0
  577. package/dist/zod/v4/locales/pt.d.ts +4 -0
  578. package/dist/zod/v4/locales/pt.js +116 -0
  579. package/dist/zod/v4/locales/ru.cjs +190 -0
  580. package/dist/zod/v4/locales/ru.d.cts +4 -0
  581. package/dist/zod/v4/locales/ru.d.ts +4 -0
  582. package/dist/zod/v4/locales/ru.js +164 -0
  583. package/dist/zod/v4/locales/sl.cjs +143 -0
  584. package/dist/zod/v4/locales/sl.d.cts +4 -0
  585. package/dist/zod/v4/locales/sl.d.ts +4 -0
  586. package/dist/zod/v4/locales/sl.js +117 -0
  587. package/dist/zod/v4/locales/sv.cjs +144 -0
  588. package/dist/zod/v4/locales/sv.d.cts +4 -0
  589. package/dist/zod/v4/locales/sv.d.ts +4 -0
  590. package/dist/zod/v4/locales/sv.js +118 -0
  591. package/dist/zod/v4/locales/ta.cjs +143 -0
  592. package/dist/zod/v4/locales/ta.d.cts +4 -0
  593. package/dist/zod/v4/locales/ta.d.ts +4 -0
  594. package/dist/zod/v4/locales/ta.js +117 -0
  595. package/dist/zod/v4/locales/th.cjs +143 -0
  596. package/dist/zod/v4/locales/th.d.cts +4 -0
  597. package/dist/zod/v4/locales/th.d.ts +4 -0
  598. package/dist/zod/v4/locales/th.js +117 -0
  599. package/dist/zod/v4/locales/tr.cjs +143 -0
  600. package/dist/zod/v4/locales/tr.d.cts +5 -0
  601. package/dist/zod/v4/locales/tr.d.ts +5 -0
  602. package/dist/zod/v4/locales/tr.js +115 -0
  603. package/dist/zod/v4/locales/ua.cjs +143 -0
  604. package/dist/zod/v4/locales/ua.d.cts +4 -0
  605. package/dist/zod/v4/locales/ua.d.ts +4 -0
  606. package/dist/zod/v4/locales/ua.js +117 -0
  607. package/dist/zod/v4/locales/ur.cjs +143 -0
  608. package/dist/zod/v4/locales/ur.d.cts +4 -0
  609. package/dist/zod/v4/locales/ur.d.ts +4 -0
  610. package/dist/zod/v4/locales/ur.js +117 -0
  611. package/dist/zod/v4/locales/vi.cjs +142 -0
  612. package/dist/zod/v4/locales/vi.d.cts +4 -0
  613. package/dist/zod/v4/locales/vi.d.ts +4 -0
  614. package/dist/zod/v4/locales/vi.js +116 -0
  615. package/dist/zod/v4/locales/zh-CN.cjs +142 -0
  616. package/dist/zod/v4/locales/zh-CN.d.cts +4 -0
  617. package/dist/zod/v4/locales/zh-CN.d.ts +4 -0
  618. package/dist/zod/v4/locales/zh-CN.js +116 -0
  619. package/dist/zod/v4/locales/zh-TW.cjs +143 -0
  620. package/dist/zod/v4/locales/zh-TW.d.cts +4 -0
  621. package/dist/zod/v4/locales/zh-TW.d.ts +4 -0
  622. package/dist/zod/v4/locales/zh-TW.js +117 -0
  623. package/dist/zod/v4/mini/checks.cjs +34 -0
  624. package/dist/zod/v4/mini/checks.d.cts +1 -0
  625. package/dist/zod/v4/mini/checks.d.ts +1 -0
  626. package/dist/zod/v4/mini/checks.js +1 -0
  627. package/dist/zod/v4/mini/coerce.cjs +47 -0
  628. package/dist/zod/v4/mini/coerce.d.cts +7 -0
  629. package/dist/zod/v4/mini/coerce.d.ts +7 -0
  630. package/dist/zod/v4/mini/coerce.js +17 -0
  631. package/dist/zod/v4/mini/external.cjs +62 -0
  632. package/dist/zod/v4/mini/external.d.cts +11 -0
  633. package/dist/zod/v4/mini/external.d.ts +11 -0
  634. package/dist/zod/v4/mini/external.js +13 -0
  635. package/dist/zod/v4/mini/index.cjs +32 -0
  636. package/dist/zod/v4/mini/index.d.cts +3 -0
  637. package/dist/zod/v4/mini/index.d.ts +3 -0
  638. package/dist/zod/v4/mini/index.js +3 -0
  639. package/dist/zod/v4/mini/iso.cjs +60 -0
  640. package/dist/zod/v4/mini/iso.d.cts +22 -0
  641. package/dist/zod/v4/mini/iso.d.ts +22 -0
  642. package/dist/zod/v4/mini/iso.js +30 -0
  643. package/dist/zod/v4/mini/parse.cjs +8 -0
  644. package/dist/zod/v4/mini/parse.d.cts +1 -0
  645. package/dist/zod/v4/mini/parse.d.ts +1 -0
  646. package/dist/zod/v4/mini/parse.js +1 -0
  647. package/dist/zod/v4/mini/schemas.cjs +839 -0
  648. package/dist/zod/v4/mini/schemas.d.cts +356 -0
  649. package/dist/zod/v4/mini/schemas.d.ts +356 -0
  650. package/dist/zod/v4/mini/schemas.js +732 -0
  651. package/dist/zod/v4-mini/index.cjs +17 -0
  652. package/dist/zod/v4-mini/index.d.cts +1 -0
  653. package/dist/zod/v4-mini/index.d.ts +1 -0
  654. package/dist/zod/v4-mini/index.js +1 -0
  655. package/package.json +42 -0
  656. package/scripts/postinstall.js +75 -0
@@ -0,0 +1,3775 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.discriminatedUnion = exports.date = exports.boolean = exports.bigint = exports.array = exports.any = exports.coerce = exports.ZodFirstPartyTypeKind = exports.late = exports.ZodSchema = exports.Schema = exports.ZodReadonly = exports.ZodPipeline = exports.ZodBranded = exports.BRAND = exports.ZodNaN = exports.ZodCatch = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransformer = exports.ZodEffects = exports.ZodPromise = exports.ZodNativeEnum = exports.ZodEnum = exports.ZodLiteral = exports.ZodLazy = exports.ZodFunction = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodDate = exports.ZodBoolean = exports.ZodBigInt = exports.ZodNumber = exports.ZodString = exports.ZodType = void 0;
4
+ exports.NEVER = exports.void = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.symbol = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.preprocess = exports.pipeline = exports.ostring = exports.optional = exports.onumber = exports.oboolean = exports.object = exports.number = exports.nullable = exports.null = exports.never = exports.nativeEnum = exports.nan = exports.map = exports.literal = exports.lazy = exports.intersection = exports.instanceof = exports.function = exports.enum = exports.effect = void 0;
5
+ exports.datetimeRegex = datetimeRegex;
6
+ exports.custom = custom;
7
+ const ZodError_js_1 = require("./ZodError.cjs");
8
+ const errors_js_1 = require("./errors.cjs");
9
+ const errorUtil_js_1 = require("./helpers/errorUtil.cjs");
10
+ const parseUtil_js_1 = require("./helpers/parseUtil.cjs");
11
+ const util_js_1 = require("./helpers/util.cjs");
12
+ class ParseInputLazyPath {
13
+ constructor(parent, value, path, key) {
14
+ this._cachedPath = [];
15
+ this.parent = parent;
16
+ this.data = value;
17
+ this._path = path;
18
+ this._key = key;
19
+ }
20
+ get path() {
21
+ if (!this._cachedPath.length) {
22
+ if (Array.isArray(this._key)) {
23
+ this._cachedPath.push(...this._path, ...this._key);
24
+ }
25
+ else {
26
+ this._cachedPath.push(...this._path, this._key);
27
+ }
28
+ }
29
+ return this._cachedPath;
30
+ }
31
+ }
32
+ const handleResult = (ctx, result) => {
33
+ if ((0, parseUtil_js_1.isValid)(result)) {
34
+ return { success: true, data: result.value };
35
+ }
36
+ else {
37
+ if (!ctx.common.issues.length) {
38
+ throw new Error("Validation failed but no issues detected.");
39
+ }
40
+ return {
41
+ success: false,
42
+ get error() {
43
+ if (this._error)
44
+ return this._error;
45
+ const error = new ZodError_js_1.ZodError(ctx.common.issues);
46
+ this._error = error;
47
+ return this._error;
48
+ },
49
+ };
50
+ }
51
+ };
52
+ function processCreateParams(params) {
53
+ if (!params)
54
+ return {};
55
+ const { errorMap, invalid_type_error, required_error, description } = params;
56
+ if (errorMap && (invalid_type_error || required_error)) {
57
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
58
+ }
59
+ if (errorMap)
60
+ return { errorMap: errorMap, description };
61
+ const customMap = (iss, ctx) => {
62
+ const { message } = params;
63
+ if (iss.code === "invalid_enum_value") {
64
+ return { message: message ?? ctx.defaultError };
65
+ }
66
+ if (typeof ctx.data === "undefined") {
67
+ return { message: message ?? required_error ?? ctx.defaultError };
68
+ }
69
+ if (iss.code !== "invalid_type")
70
+ return { message: ctx.defaultError };
71
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
72
+ };
73
+ return { errorMap: customMap, description };
74
+ }
75
+ class ZodType {
76
+ get description() {
77
+ return this._def.description;
78
+ }
79
+ _getType(input) {
80
+ return (0, util_js_1.getParsedType)(input.data);
81
+ }
82
+ _getOrReturnCtx(input, ctx) {
83
+ return (ctx || {
84
+ common: input.parent.common,
85
+ data: input.data,
86
+ parsedType: (0, util_js_1.getParsedType)(input.data),
87
+ schemaErrorMap: this._def.errorMap,
88
+ path: input.path,
89
+ parent: input.parent,
90
+ });
91
+ }
92
+ _processInputParams(input) {
93
+ return {
94
+ status: new parseUtil_js_1.ParseStatus(),
95
+ ctx: {
96
+ common: input.parent.common,
97
+ data: input.data,
98
+ parsedType: (0, util_js_1.getParsedType)(input.data),
99
+ schemaErrorMap: this._def.errorMap,
100
+ path: input.path,
101
+ parent: input.parent,
102
+ },
103
+ };
104
+ }
105
+ _parseSync(input) {
106
+ const result = this._parse(input);
107
+ if ((0, parseUtil_js_1.isAsync)(result)) {
108
+ throw new Error("Synchronous parse encountered promise.");
109
+ }
110
+ return result;
111
+ }
112
+ _parseAsync(input) {
113
+ const result = this._parse(input);
114
+ return Promise.resolve(result);
115
+ }
116
+ parse(data, params) {
117
+ const result = this.safeParse(data, params);
118
+ if (result.success)
119
+ return result.data;
120
+ throw result.error;
121
+ }
122
+ safeParse(data, params) {
123
+ const ctx = {
124
+ common: {
125
+ issues: [],
126
+ async: params?.async ?? false,
127
+ contextualErrorMap: params?.errorMap,
128
+ },
129
+ path: params?.path || [],
130
+ schemaErrorMap: this._def.errorMap,
131
+ parent: null,
132
+ data,
133
+ parsedType: (0, util_js_1.getParsedType)(data),
134
+ };
135
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
136
+ return handleResult(ctx, result);
137
+ }
138
+ "~validate"(data) {
139
+ const ctx = {
140
+ common: {
141
+ issues: [],
142
+ async: !!this["~standard"].async,
143
+ },
144
+ path: [],
145
+ schemaErrorMap: this._def.errorMap,
146
+ parent: null,
147
+ data,
148
+ parsedType: (0, util_js_1.getParsedType)(data),
149
+ };
150
+ if (!this["~standard"].async) {
151
+ try {
152
+ const result = this._parseSync({ data, path: [], parent: ctx });
153
+ return (0, parseUtil_js_1.isValid)(result)
154
+ ? {
155
+ value: result.value,
156
+ }
157
+ : {
158
+ issues: ctx.common.issues,
159
+ };
160
+ }
161
+ catch (err) {
162
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
163
+ this["~standard"].async = true;
164
+ }
165
+ ctx.common = {
166
+ issues: [],
167
+ async: true,
168
+ };
169
+ }
170
+ }
171
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => (0, parseUtil_js_1.isValid)(result)
172
+ ? {
173
+ value: result.value,
174
+ }
175
+ : {
176
+ issues: ctx.common.issues,
177
+ });
178
+ }
179
+ async parseAsync(data, params) {
180
+ const result = await this.safeParseAsync(data, params);
181
+ if (result.success)
182
+ return result.data;
183
+ throw result.error;
184
+ }
185
+ async safeParseAsync(data, params) {
186
+ const ctx = {
187
+ common: {
188
+ issues: [],
189
+ contextualErrorMap: params?.errorMap,
190
+ async: true,
191
+ },
192
+ path: params?.path || [],
193
+ schemaErrorMap: this._def.errorMap,
194
+ parent: null,
195
+ data,
196
+ parsedType: (0, util_js_1.getParsedType)(data),
197
+ };
198
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
199
+ const result = await ((0, parseUtil_js_1.isAsync)(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
200
+ return handleResult(ctx, result);
201
+ }
202
+ refine(check, message) {
203
+ const getIssueProperties = (val) => {
204
+ if (typeof message === "string" || typeof message === "undefined") {
205
+ return { message };
206
+ }
207
+ else if (typeof message === "function") {
208
+ return message(val);
209
+ }
210
+ else {
211
+ return message;
212
+ }
213
+ };
214
+ return this._refinement((val, ctx) => {
215
+ const result = check(val);
216
+ const setError = () => ctx.addIssue({
217
+ code: ZodError_js_1.ZodIssueCode.custom,
218
+ ...getIssueProperties(val),
219
+ });
220
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
221
+ return result.then((data) => {
222
+ if (!data) {
223
+ setError();
224
+ return false;
225
+ }
226
+ else {
227
+ return true;
228
+ }
229
+ });
230
+ }
231
+ if (!result) {
232
+ setError();
233
+ return false;
234
+ }
235
+ else {
236
+ return true;
237
+ }
238
+ });
239
+ }
240
+ refinement(check, refinementData) {
241
+ return this._refinement((val, ctx) => {
242
+ if (!check(val)) {
243
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
244
+ return false;
245
+ }
246
+ else {
247
+ return true;
248
+ }
249
+ });
250
+ }
251
+ _refinement(refinement) {
252
+ return new ZodEffects({
253
+ schema: this,
254
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
255
+ effect: { type: "refinement", refinement },
256
+ });
257
+ }
258
+ superRefine(refinement) {
259
+ return this._refinement(refinement);
260
+ }
261
+ constructor(def) {
262
+ /** Alias of safeParseAsync */
263
+ this.spa = this.safeParseAsync;
264
+ this._def = def;
265
+ this.parse = this.parse.bind(this);
266
+ this.safeParse = this.safeParse.bind(this);
267
+ this.parseAsync = this.parseAsync.bind(this);
268
+ this.safeParseAsync = this.safeParseAsync.bind(this);
269
+ this.spa = this.spa.bind(this);
270
+ this.refine = this.refine.bind(this);
271
+ this.refinement = this.refinement.bind(this);
272
+ this.superRefine = this.superRefine.bind(this);
273
+ this.optional = this.optional.bind(this);
274
+ this.nullable = this.nullable.bind(this);
275
+ this.nullish = this.nullish.bind(this);
276
+ this.array = this.array.bind(this);
277
+ this.promise = this.promise.bind(this);
278
+ this.or = this.or.bind(this);
279
+ this.and = this.and.bind(this);
280
+ this.transform = this.transform.bind(this);
281
+ this.brand = this.brand.bind(this);
282
+ this.default = this.default.bind(this);
283
+ this.catch = this.catch.bind(this);
284
+ this.describe = this.describe.bind(this);
285
+ this.pipe = this.pipe.bind(this);
286
+ this.readonly = this.readonly.bind(this);
287
+ this.isNullable = this.isNullable.bind(this);
288
+ this.isOptional = this.isOptional.bind(this);
289
+ this["~standard"] = {
290
+ version: 1,
291
+ vendor: "zod",
292
+ validate: (data) => this["~validate"](data),
293
+ };
294
+ }
295
+ optional() {
296
+ return ZodOptional.create(this, this._def);
297
+ }
298
+ nullable() {
299
+ return ZodNullable.create(this, this._def);
300
+ }
301
+ nullish() {
302
+ return this.nullable().optional();
303
+ }
304
+ array() {
305
+ return ZodArray.create(this);
306
+ }
307
+ promise() {
308
+ return ZodPromise.create(this, this._def);
309
+ }
310
+ or(option) {
311
+ return ZodUnion.create([this, option], this._def);
312
+ }
313
+ and(incoming) {
314
+ return ZodIntersection.create(this, incoming, this._def);
315
+ }
316
+ transform(transform) {
317
+ return new ZodEffects({
318
+ ...processCreateParams(this._def),
319
+ schema: this,
320
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
321
+ effect: { type: "transform", transform },
322
+ });
323
+ }
324
+ default(def) {
325
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
326
+ return new ZodDefault({
327
+ ...processCreateParams(this._def),
328
+ innerType: this,
329
+ defaultValue: defaultValueFunc,
330
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
331
+ });
332
+ }
333
+ brand() {
334
+ return new ZodBranded({
335
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
336
+ type: this,
337
+ ...processCreateParams(this._def),
338
+ });
339
+ }
340
+ catch(def) {
341
+ const catchValueFunc = typeof def === "function" ? def : () => def;
342
+ return new ZodCatch({
343
+ ...processCreateParams(this._def),
344
+ innerType: this,
345
+ catchValue: catchValueFunc,
346
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
347
+ });
348
+ }
349
+ describe(description) {
350
+ const This = this.constructor;
351
+ return new This({
352
+ ...this._def,
353
+ description,
354
+ });
355
+ }
356
+ pipe(target) {
357
+ return ZodPipeline.create(this, target);
358
+ }
359
+ readonly() {
360
+ return ZodReadonly.create(this);
361
+ }
362
+ isOptional() {
363
+ return this.safeParse(undefined).success;
364
+ }
365
+ isNullable() {
366
+ return this.safeParse(null).success;
367
+ }
368
+ }
369
+ exports.ZodType = ZodType;
370
+ exports.Schema = ZodType;
371
+ exports.ZodSchema = ZodType;
372
+ const cuidRegex = /^c[^\s-]{8,}$/i;
373
+ const cuid2Regex = /^[0-9a-z]+$/;
374
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
375
+ // const uuidRegex =
376
+ // /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
377
+ const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
378
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
379
+ const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
380
+ const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
381
+ // from https://stackoverflow.com/a/46181/1550155
382
+ // old version: too slow, didn't support unicode
383
+ // const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
384
+ //old email regex
385
+ // const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
386
+ // eslint-disable-next-line
387
+ // const emailRegex =
388
+ // /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
389
+ // const emailRegex =
390
+ // /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
391
+ // const emailRegex =
392
+ // /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
393
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
394
+ // const emailRegex =
395
+ // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
396
+ // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
397
+ const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
398
+ let emojiRegex;
399
+ // faster, simpler, safer
400
+ const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
401
+ const ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
402
+ // const ipv6Regex =
403
+ // /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
404
+ const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
405
+ const ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
406
+ // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
407
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
408
+ // https://base64.guru/standards/base64url
409
+ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
410
+ // simple
411
+ // const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
412
+ // no leap year validation
413
+ // const dateRegexSource = `\\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\\d|2\\d))`;
414
+ // with leap year validation
415
+ const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
416
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
417
+ function timeRegexSource(args) {
418
+ let secondsRegexSource = `[0-5]\\d`;
419
+ if (args.precision) {
420
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
421
+ }
422
+ else if (args.precision == null) {
423
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
424
+ }
425
+ const secondsQuantifier = args.precision ? "+" : "?"; // require seconds if precision is nonzero
426
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
427
+ }
428
+ function timeRegex(args) {
429
+ return new RegExp(`^${timeRegexSource(args)}$`);
430
+ }
431
+ // Adapted from https://stackoverflow.com/a/3143231
432
+ function datetimeRegex(args) {
433
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
434
+ const opts = [];
435
+ opts.push(args.local ? `Z?` : `Z`);
436
+ if (args.offset)
437
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
438
+ regex = `${regex}(${opts.join("|")})`;
439
+ return new RegExp(`^${regex}$`);
440
+ }
441
+ function isValidIP(ip, version) {
442
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
443
+ return true;
444
+ }
445
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
446
+ return true;
447
+ }
448
+ return false;
449
+ }
450
+ function isValidJWT(jwt, alg) {
451
+ if (!jwtRegex.test(jwt))
452
+ return false;
453
+ try {
454
+ const [header] = jwt.split(".");
455
+ if (!header)
456
+ return false;
457
+ // Convert base64url to base64
458
+ const base64 = header
459
+ .replace(/-/g, "+")
460
+ .replace(/_/g, "/")
461
+ .padEnd(header.length + ((4 - (header.length % 4)) % 4), "=");
462
+ const decoded = JSON.parse(atob(base64));
463
+ if (typeof decoded !== "object" || decoded === null)
464
+ return false;
465
+ if ("typ" in decoded && decoded?.typ !== "JWT")
466
+ return false;
467
+ if (!decoded.alg)
468
+ return false;
469
+ if (alg && decoded.alg !== alg)
470
+ return false;
471
+ return true;
472
+ }
473
+ catch {
474
+ return false;
475
+ }
476
+ }
477
+ function isValidCidr(ip, version) {
478
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
479
+ return true;
480
+ }
481
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
482
+ return true;
483
+ }
484
+ return false;
485
+ }
486
+ class ZodString extends ZodType {
487
+ _parse(input) {
488
+ if (this._def.coerce) {
489
+ input.data = String(input.data);
490
+ }
491
+ const parsedType = this._getType(input);
492
+ if (parsedType !== util_js_1.ZodParsedType.string) {
493
+ const ctx = this._getOrReturnCtx(input);
494
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
495
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
496
+ expected: util_js_1.ZodParsedType.string,
497
+ received: ctx.parsedType,
498
+ });
499
+ return parseUtil_js_1.INVALID;
500
+ }
501
+ const status = new parseUtil_js_1.ParseStatus();
502
+ let ctx = undefined;
503
+ for (const check of this._def.checks) {
504
+ if (check.kind === "min") {
505
+ if (input.data.length < check.value) {
506
+ ctx = this._getOrReturnCtx(input, ctx);
507
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
508
+ code: ZodError_js_1.ZodIssueCode.too_small,
509
+ minimum: check.value,
510
+ type: "string",
511
+ inclusive: true,
512
+ exact: false,
513
+ message: check.message,
514
+ });
515
+ status.dirty();
516
+ }
517
+ }
518
+ else if (check.kind === "max") {
519
+ if (input.data.length > check.value) {
520
+ ctx = this._getOrReturnCtx(input, ctx);
521
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
522
+ code: ZodError_js_1.ZodIssueCode.too_big,
523
+ maximum: check.value,
524
+ type: "string",
525
+ inclusive: true,
526
+ exact: false,
527
+ message: check.message,
528
+ });
529
+ status.dirty();
530
+ }
531
+ }
532
+ else if (check.kind === "length") {
533
+ const tooBig = input.data.length > check.value;
534
+ const tooSmall = input.data.length < check.value;
535
+ if (tooBig || tooSmall) {
536
+ ctx = this._getOrReturnCtx(input, ctx);
537
+ if (tooBig) {
538
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
539
+ code: ZodError_js_1.ZodIssueCode.too_big,
540
+ maximum: check.value,
541
+ type: "string",
542
+ inclusive: true,
543
+ exact: true,
544
+ message: check.message,
545
+ });
546
+ }
547
+ else if (tooSmall) {
548
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
549
+ code: ZodError_js_1.ZodIssueCode.too_small,
550
+ minimum: check.value,
551
+ type: "string",
552
+ inclusive: true,
553
+ exact: true,
554
+ message: check.message,
555
+ });
556
+ }
557
+ status.dirty();
558
+ }
559
+ }
560
+ else if (check.kind === "email") {
561
+ if (!emailRegex.test(input.data)) {
562
+ ctx = this._getOrReturnCtx(input, ctx);
563
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
564
+ validation: "email",
565
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
566
+ message: check.message,
567
+ });
568
+ status.dirty();
569
+ }
570
+ }
571
+ else if (check.kind === "emoji") {
572
+ if (!emojiRegex) {
573
+ emojiRegex = new RegExp(_emojiRegex, "u");
574
+ }
575
+ if (!emojiRegex.test(input.data)) {
576
+ ctx = this._getOrReturnCtx(input, ctx);
577
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
578
+ validation: "emoji",
579
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
580
+ message: check.message,
581
+ });
582
+ status.dirty();
583
+ }
584
+ }
585
+ else if (check.kind === "uuid") {
586
+ if (!uuidRegex.test(input.data)) {
587
+ ctx = this._getOrReturnCtx(input, ctx);
588
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
589
+ validation: "uuid",
590
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
591
+ message: check.message,
592
+ });
593
+ status.dirty();
594
+ }
595
+ }
596
+ else if (check.kind === "nanoid") {
597
+ if (!nanoidRegex.test(input.data)) {
598
+ ctx = this._getOrReturnCtx(input, ctx);
599
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
600
+ validation: "nanoid",
601
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
602
+ message: check.message,
603
+ });
604
+ status.dirty();
605
+ }
606
+ }
607
+ else if (check.kind === "cuid") {
608
+ if (!cuidRegex.test(input.data)) {
609
+ ctx = this._getOrReturnCtx(input, ctx);
610
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
611
+ validation: "cuid",
612
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
613
+ message: check.message,
614
+ });
615
+ status.dirty();
616
+ }
617
+ }
618
+ else if (check.kind === "cuid2") {
619
+ if (!cuid2Regex.test(input.data)) {
620
+ ctx = this._getOrReturnCtx(input, ctx);
621
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
622
+ validation: "cuid2",
623
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
624
+ message: check.message,
625
+ });
626
+ status.dirty();
627
+ }
628
+ }
629
+ else if (check.kind === "ulid") {
630
+ if (!ulidRegex.test(input.data)) {
631
+ ctx = this._getOrReturnCtx(input, ctx);
632
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
633
+ validation: "ulid",
634
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
635
+ message: check.message,
636
+ });
637
+ status.dirty();
638
+ }
639
+ }
640
+ else if (check.kind === "url") {
641
+ try {
642
+ new URL(input.data);
643
+ }
644
+ catch {
645
+ ctx = this._getOrReturnCtx(input, ctx);
646
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
647
+ validation: "url",
648
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
649
+ message: check.message,
650
+ });
651
+ status.dirty();
652
+ }
653
+ }
654
+ else if (check.kind === "regex") {
655
+ check.regex.lastIndex = 0;
656
+ const testResult = check.regex.test(input.data);
657
+ if (!testResult) {
658
+ ctx = this._getOrReturnCtx(input, ctx);
659
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
660
+ validation: "regex",
661
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
662
+ message: check.message,
663
+ });
664
+ status.dirty();
665
+ }
666
+ }
667
+ else if (check.kind === "trim") {
668
+ input.data = input.data.trim();
669
+ }
670
+ else if (check.kind === "includes") {
671
+ if (!input.data.includes(check.value, check.position)) {
672
+ ctx = this._getOrReturnCtx(input, ctx);
673
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
674
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
675
+ validation: { includes: check.value, position: check.position },
676
+ message: check.message,
677
+ });
678
+ status.dirty();
679
+ }
680
+ }
681
+ else if (check.kind === "toLowerCase") {
682
+ input.data = input.data.toLowerCase();
683
+ }
684
+ else if (check.kind === "toUpperCase") {
685
+ input.data = input.data.toUpperCase();
686
+ }
687
+ else if (check.kind === "startsWith") {
688
+ if (!input.data.startsWith(check.value)) {
689
+ ctx = this._getOrReturnCtx(input, ctx);
690
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
691
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
692
+ validation: { startsWith: check.value },
693
+ message: check.message,
694
+ });
695
+ status.dirty();
696
+ }
697
+ }
698
+ else if (check.kind === "endsWith") {
699
+ if (!input.data.endsWith(check.value)) {
700
+ ctx = this._getOrReturnCtx(input, ctx);
701
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
702
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
703
+ validation: { endsWith: check.value },
704
+ message: check.message,
705
+ });
706
+ status.dirty();
707
+ }
708
+ }
709
+ else if (check.kind === "datetime") {
710
+ const regex = datetimeRegex(check);
711
+ if (!regex.test(input.data)) {
712
+ ctx = this._getOrReturnCtx(input, ctx);
713
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
714
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
715
+ validation: "datetime",
716
+ message: check.message,
717
+ });
718
+ status.dirty();
719
+ }
720
+ }
721
+ else if (check.kind === "date") {
722
+ const regex = dateRegex;
723
+ if (!regex.test(input.data)) {
724
+ ctx = this._getOrReturnCtx(input, ctx);
725
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
726
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
727
+ validation: "date",
728
+ message: check.message,
729
+ });
730
+ status.dirty();
731
+ }
732
+ }
733
+ else if (check.kind === "time") {
734
+ const regex = timeRegex(check);
735
+ if (!regex.test(input.data)) {
736
+ ctx = this._getOrReturnCtx(input, ctx);
737
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
738
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
739
+ validation: "time",
740
+ message: check.message,
741
+ });
742
+ status.dirty();
743
+ }
744
+ }
745
+ else if (check.kind === "duration") {
746
+ if (!durationRegex.test(input.data)) {
747
+ ctx = this._getOrReturnCtx(input, ctx);
748
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
749
+ validation: "duration",
750
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
751
+ message: check.message,
752
+ });
753
+ status.dirty();
754
+ }
755
+ }
756
+ else if (check.kind === "ip") {
757
+ if (!isValidIP(input.data, check.version)) {
758
+ ctx = this._getOrReturnCtx(input, ctx);
759
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
760
+ validation: "ip",
761
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
762
+ message: check.message,
763
+ });
764
+ status.dirty();
765
+ }
766
+ }
767
+ else if (check.kind === "jwt") {
768
+ if (!isValidJWT(input.data, check.alg)) {
769
+ ctx = this._getOrReturnCtx(input, ctx);
770
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
771
+ validation: "jwt",
772
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
773
+ message: check.message,
774
+ });
775
+ status.dirty();
776
+ }
777
+ }
778
+ else if (check.kind === "cidr") {
779
+ if (!isValidCidr(input.data, check.version)) {
780
+ ctx = this._getOrReturnCtx(input, ctx);
781
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
782
+ validation: "cidr",
783
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
784
+ message: check.message,
785
+ });
786
+ status.dirty();
787
+ }
788
+ }
789
+ else if (check.kind === "base64") {
790
+ if (!base64Regex.test(input.data)) {
791
+ ctx = this._getOrReturnCtx(input, ctx);
792
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
793
+ validation: "base64",
794
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
795
+ message: check.message,
796
+ });
797
+ status.dirty();
798
+ }
799
+ }
800
+ else if (check.kind === "base64url") {
801
+ if (!base64urlRegex.test(input.data)) {
802
+ ctx = this._getOrReturnCtx(input, ctx);
803
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
804
+ validation: "base64url",
805
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
806
+ message: check.message,
807
+ });
808
+ status.dirty();
809
+ }
810
+ }
811
+ else {
812
+ util_js_1.util.assertNever(check);
813
+ }
814
+ }
815
+ return { status: status.value, value: input.data };
816
+ }
817
+ _regex(regex, validation, message) {
818
+ return this.refinement((data) => regex.test(data), {
819
+ validation,
820
+ code: ZodError_js_1.ZodIssueCode.invalid_string,
821
+ ...errorUtil_js_1.errorUtil.errToObj(message),
822
+ });
823
+ }
824
+ _addCheck(check) {
825
+ return new ZodString({
826
+ ...this._def,
827
+ checks: [...this._def.checks, check],
828
+ });
829
+ }
830
+ email(message) {
831
+ return this._addCheck({ kind: "email", ...errorUtil_js_1.errorUtil.errToObj(message) });
832
+ }
833
+ url(message) {
834
+ return this._addCheck({ kind: "url", ...errorUtil_js_1.errorUtil.errToObj(message) });
835
+ }
836
+ emoji(message) {
837
+ return this._addCheck({ kind: "emoji", ...errorUtil_js_1.errorUtil.errToObj(message) });
838
+ }
839
+ uuid(message) {
840
+ return this._addCheck({ kind: "uuid", ...errorUtil_js_1.errorUtil.errToObj(message) });
841
+ }
842
+ nanoid(message) {
843
+ return this._addCheck({ kind: "nanoid", ...errorUtil_js_1.errorUtil.errToObj(message) });
844
+ }
845
+ cuid(message) {
846
+ return this._addCheck({ kind: "cuid", ...errorUtil_js_1.errorUtil.errToObj(message) });
847
+ }
848
+ cuid2(message) {
849
+ return this._addCheck({ kind: "cuid2", ...errorUtil_js_1.errorUtil.errToObj(message) });
850
+ }
851
+ ulid(message) {
852
+ return this._addCheck({ kind: "ulid", ...errorUtil_js_1.errorUtil.errToObj(message) });
853
+ }
854
+ base64(message) {
855
+ return this._addCheck({ kind: "base64", ...errorUtil_js_1.errorUtil.errToObj(message) });
856
+ }
857
+ base64url(message) {
858
+ // base64url encoding is a modification of base64 that can safely be used in URLs and filenames
859
+ return this._addCheck({
860
+ kind: "base64url",
861
+ ...errorUtil_js_1.errorUtil.errToObj(message),
862
+ });
863
+ }
864
+ jwt(options) {
865
+ return this._addCheck({ kind: "jwt", ...errorUtil_js_1.errorUtil.errToObj(options) });
866
+ }
867
+ ip(options) {
868
+ return this._addCheck({ kind: "ip", ...errorUtil_js_1.errorUtil.errToObj(options) });
869
+ }
870
+ cidr(options) {
871
+ return this._addCheck({ kind: "cidr", ...errorUtil_js_1.errorUtil.errToObj(options) });
872
+ }
873
+ datetime(options) {
874
+ if (typeof options === "string") {
875
+ return this._addCheck({
876
+ kind: "datetime",
877
+ precision: null,
878
+ offset: false,
879
+ local: false,
880
+ message: options,
881
+ });
882
+ }
883
+ return this._addCheck({
884
+ kind: "datetime",
885
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
886
+ offset: options?.offset ?? false,
887
+ local: options?.local ?? false,
888
+ ...errorUtil_js_1.errorUtil.errToObj(options?.message),
889
+ });
890
+ }
891
+ date(message) {
892
+ return this._addCheck({ kind: "date", message });
893
+ }
894
+ time(options) {
895
+ if (typeof options === "string") {
896
+ return this._addCheck({
897
+ kind: "time",
898
+ precision: null,
899
+ message: options,
900
+ });
901
+ }
902
+ return this._addCheck({
903
+ kind: "time",
904
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
905
+ ...errorUtil_js_1.errorUtil.errToObj(options?.message),
906
+ });
907
+ }
908
+ duration(message) {
909
+ return this._addCheck({ kind: "duration", ...errorUtil_js_1.errorUtil.errToObj(message) });
910
+ }
911
+ regex(regex, message) {
912
+ return this._addCheck({
913
+ kind: "regex",
914
+ regex: regex,
915
+ ...errorUtil_js_1.errorUtil.errToObj(message),
916
+ });
917
+ }
918
+ includes(value, options) {
919
+ return this._addCheck({
920
+ kind: "includes",
921
+ value: value,
922
+ position: options?.position,
923
+ ...errorUtil_js_1.errorUtil.errToObj(options?.message),
924
+ });
925
+ }
926
+ startsWith(value, message) {
927
+ return this._addCheck({
928
+ kind: "startsWith",
929
+ value: value,
930
+ ...errorUtil_js_1.errorUtil.errToObj(message),
931
+ });
932
+ }
933
+ endsWith(value, message) {
934
+ return this._addCheck({
935
+ kind: "endsWith",
936
+ value: value,
937
+ ...errorUtil_js_1.errorUtil.errToObj(message),
938
+ });
939
+ }
940
+ min(minLength, message) {
941
+ return this._addCheck({
942
+ kind: "min",
943
+ value: minLength,
944
+ ...errorUtil_js_1.errorUtil.errToObj(message),
945
+ });
946
+ }
947
+ max(maxLength, message) {
948
+ return this._addCheck({
949
+ kind: "max",
950
+ value: maxLength,
951
+ ...errorUtil_js_1.errorUtil.errToObj(message),
952
+ });
953
+ }
954
+ length(len, message) {
955
+ return this._addCheck({
956
+ kind: "length",
957
+ value: len,
958
+ ...errorUtil_js_1.errorUtil.errToObj(message),
959
+ });
960
+ }
961
+ /**
962
+ * Equivalent to `.min(1)`
963
+ */
964
+ nonempty(message) {
965
+ return this.min(1, errorUtil_js_1.errorUtil.errToObj(message));
966
+ }
967
+ trim() {
968
+ return new ZodString({
969
+ ...this._def,
970
+ checks: [...this._def.checks, { kind: "trim" }],
971
+ });
972
+ }
973
+ toLowerCase() {
974
+ return new ZodString({
975
+ ...this._def,
976
+ checks: [...this._def.checks, { kind: "toLowerCase" }],
977
+ });
978
+ }
979
+ toUpperCase() {
980
+ return new ZodString({
981
+ ...this._def,
982
+ checks: [...this._def.checks, { kind: "toUpperCase" }],
983
+ });
984
+ }
985
+ get isDatetime() {
986
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
987
+ }
988
+ get isDate() {
989
+ return !!this._def.checks.find((ch) => ch.kind === "date");
990
+ }
991
+ get isTime() {
992
+ return !!this._def.checks.find((ch) => ch.kind === "time");
993
+ }
994
+ get isDuration() {
995
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
996
+ }
997
+ get isEmail() {
998
+ return !!this._def.checks.find((ch) => ch.kind === "email");
999
+ }
1000
+ get isURL() {
1001
+ return !!this._def.checks.find((ch) => ch.kind === "url");
1002
+ }
1003
+ get isEmoji() {
1004
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
1005
+ }
1006
+ get isUUID() {
1007
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
1008
+ }
1009
+ get isNANOID() {
1010
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1011
+ }
1012
+ get isCUID() {
1013
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
1014
+ }
1015
+ get isCUID2() {
1016
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1017
+ }
1018
+ get isULID() {
1019
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
1020
+ }
1021
+ get isIP() {
1022
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
1023
+ }
1024
+ get isCIDR() {
1025
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
1026
+ }
1027
+ get isBase64() {
1028
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
1029
+ }
1030
+ get isBase64url() {
1031
+ // base64url encoding is a modification of base64 that can safely be used in URLs and filenames
1032
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
1033
+ }
1034
+ get minLength() {
1035
+ let min = null;
1036
+ for (const ch of this._def.checks) {
1037
+ if (ch.kind === "min") {
1038
+ if (min === null || ch.value > min)
1039
+ min = ch.value;
1040
+ }
1041
+ }
1042
+ return min;
1043
+ }
1044
+ get maxLength() {
1045
+ let max = null;
1046
+ for (const ch of this._def.checks) {
1047
+ if (ch.kind === "max") {
1048
+ if (max === null || ch.value < max)
1049
+ max = ch.value;
1050
+ }
1051
+ }
1052
+ return max;
1053
+ }
1054
+ }
1055
+ exports.ZodString = ZodString;
1056
+ ZodString.create = (params) => {
1057
+ return new ZodString({
1058
+ checks: [],
1059
+ typeName: ZodFirstPartyTypeKind.ZodString,
1060
+ coerce: params?.coerce ?? false,
1061
+ ...processCreateParams(params),
1062
+ });
1063
+ };
1064
+ // https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
1065
+ function floatSafeRemainder(val, step) {
1066
+ const valDecCount = (val.toString().split(".")[1] || "").length;
1067
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
1068
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1069
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1070
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1071
+ return (valInt % stepInt) / 10 ** decCount;
1072
+ }
1073
+ class ZodNumber extends ZodType {
1074
+ constructor() {
1075
+ super(...arguments);
1076
+ this.min = this.gte;
1077
+ this.max = this.lte;
1078
+ this.step = this.multipleOf;
1079
+ }
1080
+ _parse(input) {
1081
+ if (this._def.coerce) {
1082
+ input.data = Number(input.data);
1083
+ }
1084
+ const parsedType = this._getType(input);
1085
+ if (parsedType !== util_js_1.ZodParsedType.number) {
1086
+ const ctx = this._getOrReturnCtx(input);
1087
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1088
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1089
+ expected: util_js_1.ZodParsedType.number,
1090
+ received: ctx.parsedType,
1091
+ });
1092
+ return parseUtil_js_1.INVALID;
1093
+ }
1094
+ let ctx = undefined;
1095
+ const status = new parseUtil_js_1.ParseStatus();
1096
+ for (const check of this._def.checks) {
1097
+ if (check.kind === "int") {
1098
+ if (!util_js_1.util.isInteger(input.data)) {
1099
+ ctx = this._getOrReturnCtx(input, ctx);
1100
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1101
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1102
+ expected: "integer",
1103
+ received: "float",
1104
+ message: check.message,
1105
+ });
1106
+ status.dirty();
1107
+ }
1108
+ }
1109
+ else if (check.kind === "min") {
1110
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1111
+ if (tooSmall) {
1112
+ ctx = this._getOrReturnCtx(input, ctx);
1113
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1114
+ code: ZodError_js_1.ZodIssueCode.too_small,
1115
+ minimum: check.value,
1116
+ type: "number",
1117
+ inclusive: check.inclusive,
1118
+ exact: false,
1119
+ message: check.message,
1120
+ });
1121
+ status.dirty();
1122
+ }
1123
+ }
1124
+ else if (check.kind === "max") {
1125
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1126
+ if (tooBig) {
1127
+ ctx = this._getOrReturnCtx(input, ctx);
1128
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1129
+ code: ZodError_js_1.ZodIssueCode.too_big,
1130
+ maximum: check.value,
1131
+ type: "number",
1132
+ inclusive: check.inclusive,
1133
+ exact: false,
1134
+ message: check.message,
1135
+ });
1136
+ status.dirty();
1137
+ }
1138
+ }
1139
+ else if (check.kind === "multipleOf") {
1140
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
1141
+ ctx = this._getOrReturnCtx(input, ctx);
1142
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1143
+ code: ZodError_js_1.ZodIssueCode.not_multiple_of,
1144
+ multipleOf: check.value,
1145
+ message: check.message,
1146
+ });
1147
+ status.dirty();
1148
+ }
1149
+ }
1150
+ else if (check.kind === "finite") {
1151
+ if (!Number.isFinite(input.data)) {
1152
+ ctx = this._getOrReturnCtx(input, ctx);
1153
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1154
+ code: ZodError_js_1.ZodIssueCode.not_finite,
1155
+ message: check.message,
1156
+ });
1157
+ status.dirty();
1158
+ }
1159
+ }
1160
+ else {
1161
+ util_js_1.util.assertNever(check);
1162
+ }
1163
+ }
1164
+ return { status: status.value, value: input.data };
1165
+ }
1166
+ gte(value, message) {
1167
+ return this.setLimit("min", value, true, errorUtil_js_1.errorUtil.toString(message));
1168
+ }
1169
+ gt(value, message) {
1170
+ return this.setLimit("min", value, false, errorUtil_js_1.errorUtil.toString(message));
1171
+ }
1172
+ lte(value, message) {
1173
+ return this.setLimit("max", value, true, errorUtil_js_1.errorUtil.toString(message));
1174
+ }
1175
+ lt(value, message) {
1176
+ return this.setLimit("max", value, false, errorUtil_js_1.errorUtil.toString(message));
1177
+ }
1178
+ setLimit(kind, value, inclusive, message) {
1179
+ return new ZodNumber({
1180
+ ...this._def,
1181
+ checks: [
1182
+ ...this._def.checks,
1183
+ {
1184
+ kind,
1185
+ value,
1186
+ inclusive,
1187
+ message: errorUtil_js_1.errorUtil.toString(message),
1188
+ },
1189
+ ],
1190
+ });
1191
+ }
1192
+ _addCheck(check) {
1193
+ return new ZodNumber({
1194
+ ...this._def,
1195
+ checks: [...this._def.checks, check],
1196
+ });
1197
+ }
1198
+ int(message) {
1199
+ return this._addCheck({
1200
+ kind: "int",
1201
+ message: errorUtil_js_1.errorUtil.toString(message),
1202
+ });
1203
+ }
1204
+ positive(message) {
1205
+ return this._addCheck({
1206
+ kind: "min",
1207
+ value: 0,
1208
+ inclusive: false,
1209
+ message: errorUtil_js_1.errorUtil.toString(message),
1210
+ });
1211
+ }
1212
+ negative(message) {
1213
+ return this._addCheck({
1214
+ kind: "max",
1215
+ value: 0,
1216
+ inclusive: false,
1217
+ message: errorUtil_js_1.errorUtil.toString(message),
1218
+ });
1219
+ }
1220
+ nonpositive(message) {
1221
+ return this._addCheck({
1222
+ kind: "max",
1223
+ value: 0,
1224
+ inclusive: true,
1225
+ message: errorUtil_js_1.errorUtil.toString(message),
1226
+ });
1227
+ }
1228
+ nonnegative(message) {
1229
+ return this._addCheck({
1230
+ kind: "min",
1231
+ value: 0,
1232
+ inclusive: true,
1233
+ message: errorUtil_js_1.errorUtil.toString(message),
1234
+ });
1235
+ }
1236
+ multipleOf(value, message) {
1237
+ return this._addCheck({
1238
+ kind: "multipleOf",
1239
+ value: value,
1240
+ message: errorUtil_js_1.errorUtil.toString(message),
1241
+ });
1242
+ }
1243
+ finite(message) {
1244
+ return this._addCheck({
1245
+ kind: "finite",
1246
+ message: errorUtil_js_1.errorUtil.toString(message),
1247
+ });
1248
+ }
1249
+ safe(message) {
1250
+ return this._addCheck({
1251
+ kind: "min",
1252
+ inclusive: true,
1253
+ value: Number.MIN_SAFE_INTEGER,
1254
+ message: errorUtil_js_1.errorUtil.toString(message),
1255
+ })._addCheck({
1256
+ kind: "max",
1257
+ inclusive: true,
1258
+ value: Number.MAX_SAFE_INTEGER,
1259
+ message: errorUtil_js_1.errorUtil.toString(message),
1260
+ });
1261
+ }
1262
+ get minValue() {
1263
+ let min = null;
1264
+ for (const ch of this._def.checks) {
1265
+ if (ch.kind === "min") {
1266
+ if (min === null || ch.value > min)
1267
+ min = ch.value;
1268
+ }
1269
+ }
1270
+ return min;
1271
+ }
1272
+ get maxValue() {
1273
+ let max = null;
1274
+ for (const ch of this._def.checks) {
1275
+ if (ch.kind === "max") {
1276
+ if (max === null || ch.value < max)
1277
+ max = ch.value;
1278
+ }
1279
+ }
1280
+ return max;
1281
+ }
1282
+ get isInt() {
1283
+ return !!this._def.checks.find((ch) => ch.kind === "int" || (ch.kind === "multipleOf" && util_js_1.util.isInteger(ch.value)));
1284
+ }
1285
+ get isFinite() {
1286
+ let max = null;
1287
+ let min = null;
1288
+ for (const ch of this._def.checks) {
1289
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
1290
+ return true;
1291
+ }
1292
+ else if (ch.kind === "min") {
1293
+ if (min === null || ch.value > min)
1294
+ min = ch.value;
1295
+ }
1296
+ else if (ch.kind === "max") {
1297
+ if (max === null || ch.value < max)
1298
+ max = ch.value;
1299
+ }
1300
+ }
1301
+ return Number.isFinite(min) && Number.isFinite(max);
1302
+ }
1303
+ }
1304
+ exports.ZodNumber = ZodNumber;
1305
+ ZodNumber.create = (params) => {
1306
+ return new ZodNumber({
1307
+ checks: [],
1308
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
1309
+ coerce: params?.coerce || false,
1310
+ ...processCreateParams(params),
1311
+ });
1312
+ };
1313
+ class ZodBigInt extends ZodType {
1314
+ constructor() {
1315
+ super(...arguments);
1316
+ this.min = this.gte;
1317
+ this.max = this.lte;
1318
+ }
1319
+ _parse(input) {
1320
+ if (this._def.coerce) {
1321
+ try {
1322
+ input.data = BigInt(input.data);
1323
+ }
1324
+ catch {
1325
+ return this._getInvalidInput(input);
1326
+ }
1327
+ }
1328
+ const parsedType = this._getType(input);
1329
+ if (parsedType !== util_js_1.ZodParsedType.bigint) {
1330
+ return this._getInvalidInput(input);
1331
+ }
1332
+ let ctx = undefined;
1333
+ const status = new parseUtil_js_1.ParseStatus();
1334
+ for (const check of this._def.checks) {
1335
+ if (check.kind === "min") {
1336
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1337
+ if (tooSmall) {
1338
+ ctx = this._getOrReturnCtx(input, ctx);
1339
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1340
+ code: ZodError_js_1.ZodIssueCode.too_small,
1341
+ type: "bigint",
1342
+ minimum: check.value,
1343
+ inclusive: check.inclusive,
1344
+ message: check.message,
1345
+ });
1346
+ status.dirty();
1347
+ }
1348
+ }
1349
+ else if (check.kind === "max") {
1350
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1351
+ if (tooBig) {
1352
+ ctx = this._getOrReturnCtx(input, ctx);
1353
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1354
+ code: ZodError_js_1.ZodIssueCode.too_big,
1355
+ type: "bigint",
1356
+ maximum: check.value,
1357
+ inclusive: check.inclusive,
1358
+ message: check.message,
1359
+ });
1360
+ status.dirty();
1361
+ }
1362
+ }
1363
+ else if (check.kind === "multipleOf") {
1364
+ if (input.data % check.value !== BigInt(0)) {
1365
+ ctx = this._getOrReturnCtx(input, ctx);
1366
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1367
+ code: ZodError_js_1.ZodIssueCode.not_multiple_of,
1368
+ multipleOf: check.value,
1369
+ message: check.message,
1370
+ });
1371
+ status.dirty();
1372
+ }
1373
+ }
1374
+ else {
1375
+ util_js_1.util.assertNever(check);
1376
+ }
1377
+ }
1378
+ return { status: status.value, value: input.data };
1379
+ }
1380
+ _getInvalidInput(input) {
1381
+ const ctx = this._getOrReturnCtx(input);
1382
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1383
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1384
+ expected: util_js_1.ZodParsedType.bigint,
1385
+ received: ctx.parsedType,
1386
+ });
1387
+ return parseUtil_js_1.INVALID;
1388
+ }
1389
+ gte(value, message) {
1390
+ return this.setLimit("min", value, true, errorUtil_js_1.errorUtil.toString(message));
1391
+ }
1392
+ gt(value, message) {
1393
+ return this.setLimit("min", value, false, errorUtil_js_1.errorUtil.toString(message));
1394
+ }
1395
+ lte(value, message) {
1396
+ return this.setLimit("max", value, true, errorUtil_js_1.errorUtil.toString(message));
1397
+ }
1398
+ lt(value, message) {
1399
+ return this.setLimit("max", value, false, errorUtil_js_1.errorUtil.toString(message));
1400
+ }
1401
+ setLimit(kind, value, inclusive, message) {
1402
+ return new ZodBigInt({
1403
+ ...this._def,
1404
+ checks: [
1405
+ ...this._def.checks,
1406
+ {
1407
+ kind,
1408
+ value,
1409
+ inclusive,
1410
+ message: errorUtil_js_1.errorUtil.toString(message),
1411
+ },
1412
+ ],
1413
+ });
1414
+ }
1415
+ _addCheck(check) {
1416
+ return new ZodBigInt({
1417
+ ...this._def,
1418
+ checks: [...this._def.checks, check],
1419
+ });
1420
+ }
1421
+ positive(message) {
1422
+ return this._addCheck({
1423
+ kind: "min",
1424
+ value: BigInt(0),
1425
+ inclusive: false,
1426
+ message: errorUtil_js_1.errorUtil.toString(message),
1427
+ });
1428
+ }
1429
+ negative(message) {
1430
+ return this._addCheck({
1431
+ kind: "max",
1432
+ value: BigInt(0),
1433
+ inclusive: false,
1434
+ message: errorUtil_js_1.errorUtil.toString(message),
1435
+ });
1436
+ }
1437
+ nonpositive(message) {
1438
+ return this._addCheck({
1439
+ kind: "max",
1440
+ value: BigInt(0),
1441
+ inclusive: true,
1442
+ message: errorUtil_js_1.errorUtil.toString(message),
1443
+ });
1444
+ }
1445
+ nonnegative(message) {
1446
+ return this._addCheck({
1447
+ kind: "min",
1448
+ value: BigInt(0),
1449
+ inclusive: true,
1450
+ message: errorUtil_js_1.errorUtil.toString(message),
1451
+ });
1452
+ }
1453
+ multipleOf(value, message) {
1454
+ return this._addCheck({
1455
+ kind: "multipleOf",
1456
+ value,
1457
+ message: errorUtil_js_1.errorUtil.toString(message),
1458
+ });
1459
+ }
1460
+ get minValue() {
1461
+ let min = null;
1462
+ for (const ch of this._def.checks) {
1463
+ if (ch.kind === "min") {
1464
+ if (min === null || ch.value > min)
1465
+ min = ch.value;
1466
+ }
1467
+ }
1468
+ return min;
1469
+ }
1470
+ get maxValue() {
1471
+ let max = null;
1472
+ for (const ch of this._def.checks) {
1473
+ if (ch.kind === "max") {
1474
+ if (max === null || ch.value < max)
1475
+ max = ch.value;
1476
+ }
1477
+ }
1478
+ return max;
1479
+ }
1480
+ }
1481
+ exports.ZodBigInt = ZodBigInt;
1482
+ ZodBigInt.create = (params) => {
1483
+ return new ZodBigInt({
1484
+ checks: [],
1485
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
1486
+ coerce: params?.coerce ?? false,
1487
+ ...processCreateParams(params),
1488
+ });
1489
+ };
1490
+ class ZodBoolean extends ZodType {
1491
+ _parse(input) {
1492
+ if (this._def.coerce) {
1493
+ input.data = Boolean(input.data);
1494
+ }
1495
+ const parsedType = this._getType(input);
1496
+ if (parsedType !== util_js_1.ZodParsedType.boolean) {
1497
+ const ctx = this._getOrReturnCtx(input);
1498
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1499
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1500
+ expected: util_js_1.ZodParsedType.boolean,
1501
+ received: ctx.parsedType,
1502
+ });
1503
+ return parseUtil_js_1.INVALID;
1504
+ }
1505
+ return (0, parseUtil_js_1.OK)(input.data);
1506
+ }
1507
+ }
1508
+ exports.ZodBoolean = ZodBoolean;
1509
+ ZodBoolean.create = (params) => {
1510
+ return new ZodBoolean({
1511
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
1512
+ coerce: params?.coerce || false,
1513
+ ...processCreateParams(params),
1514
+ });
1515
+ };
1516
+ class ZodDate extends ZodType {
1517
+ _parse(input) {
1518
+ if (this._def.coerce) {
1519
+ input.data = new Date(input.data);
1520
+ }
1521
+ const parsedType = this._getType(input);
1522
+ if (parsedType !== util_js_1.ZodParsedType.date) {
1523
+ const ctx = this._getOrReturnCtx(input);
1524
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1525
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1526
+ expected: util_js_1.ZodParsedType.date,
1527
+ received: ctx.parsedType,
1528
+ });
1529
+ return parseUtil_js_1.INVALID;
1530
+ }
1531
+ if (Number.isNaN(input.data.getTime())) {
1532
+ const ctx = this._getOrReturnCtx(input);
1533
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1534
+ code: ZodError_js_1.ZodIssueCode.invalid_date,
1535
+ });
1536
+ return parseUtil_js_1.INVALID;
1537
+ }
1538
+ const status = new parseUtil_js_1.ParseStatus();
1539
+ let ctx = undefined;
1540
+ for (const check of this._def.checks) {
1541
+ if (check.kind === "min") {
1542
+ if (input.data.getTime() < check.value) {
1543
+ ctx = this._getOrReturnCtx(input, ctx);
1544
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1545
+ code: ZodError_js_1.ZodIssueCode.too_small,
1546
+ message: check.message,
1547
+ inclusive: true,
1548
+ exact: false,
1549
+ minimum: check.value,
1550
+ type: "date",
1551
+ });
1552
+ status.dirty();
1553
+ }
1554
+ }
1555
+ else if (check.kind === "max") {
1556
+ if (input.data.getTime() > check.value) {
1557
+ ctx = this._getOrReturnCtx(input, ctx);
1558
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1559
+ code: ZodError_js_1.ZodIssueCode.too_big,
1560
+ message: check.message,
1561
+ inclusive: true,
1562
+ exact: false,
1563
+ maximum: check.value,
1564
+ type: "date",
1565
+ });
1566
+ status.dirty();
1567
+ }
1568
+ }
1569
+ else {
1570
+ util_js_1.util.assertNever(check);
1571
+ }
1572
+ }
1573
+ return {
1574
+ status: status.value,
1575
+ value: new Date(input.data.getTime()),
1576
+ };
1577
+ }
1578
+ _addCheck(check) {
1579
+ return new ZodDate({
1580
+ ...this._def,
1581
+ checks: [...this._def.checks, check],
1582
+ });
1583
+ }
1584
+ min(minDate, message) {
1585
+ return this._addCheck({
1586
+ kind: "min",
1587
+ value: minDate.getTime(),
1588
+ message: errorUtil_js_1.errorUtil.toString(message),
1589
+ });
1590
+ }
1591
+ max(maxDate, message) {
1592
+ return this._addCheck({
1593
+ kind: "max",
1594
+ value: maxDate.getTime(),
1595
+ message: errorUtil_js_1.errorUtil.toString(message),
1596
+ });
1597
+ }
1598
+ get minDate() {
1599
+ let min = null;
1600
+ for (const ch of this._def.checks) {
1601
+ if (ch.kind === "min") {
1602
+ if (min === null || ch.value > min)
1603
+ min = ch.value;
1604
+ }
1605
+ }
1606
+ return min != null ? new Date(min) : null;
1607
+ }
1608
+ get maxDate() {
1609
+ let max = null;
1610
+ for (const ch of this._def.checks) {
1611
+ if (ch.kind === "max") {
1612
+ if (max === null || ch.value < max)
1613
+ max = ch.value;
1614
+ }
1615
+ }
1616
+ return max != null ? new Date(max) : null;
1617
+ }
1618
+ }
1619
+ exports.ZodDate = ZodDate;
1620
+ ZodDate.create = (params) => {
1621
+ return new ZodDate({
1622
+ checks: [],
1623
+ coerce: params?.coerce || false,
1624
+ typeName: ZodFirstPartyTypeKind.ZodDate,
1625
+ ...processCreateParams(params),
1626
+ });
1627
+ };
1628
+ class ZodSymbol extends ZodType {
1629
+ _parse(input) {
1630
+ const parsedType = this._getType(input);
1631
+ if (parsedType !== util_js_1.ZodParsedType.symbol) {
1632
+ const ctx = this._getOrReturnCtx(input);
1633
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1634
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1635
+ expected: util_js_1.ZodParsedType.symbol,
1636
+ received: ctx.parsedType,
1637
+ });
1638
+ return parseUtil_js_1.INVALID;
1639
+ }
1640
+ return (0, parseUtil_js_1.OK)(input.data);
1641
+ }
1642
+ }
1643
+ exports.ZodSymbol = ZodSymbol;
1644
+ ZodSymbol.create = (params) => {
1645
+ return new ZodSymbol({
1646
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
1647
+ ...processCreateParams(params),
1648
+ });
1649
+ };
1650
+ class ZodUndefined extends ZodType {
1651
+ _parse(input) {
1652
+ const parsedType = this._getType(input);
1653
+ if (parsedType !== util_js_1.ZodParsedType.undefined) {
1654
+ const ctx = this._getOrReturnCtx(input);
1655
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1656
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1657
+ expected: util_js_1.ZodParsedType.undefined,
1658
+ received: ctx.parsedType,
1659
+ });
1660
+ return parseUtil_js_1.INVALID;
1661
+ }
1662
+ return (0, parseUtil_js_1.OK)(input.data);
1663
+ }
1664
+ }
1665
+ exports.ZodUndefined = ZodUndefined;
1666
+ ZodUndefined.create = (params) => {
1667
+ return new ZodUndefined({
1668
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
1669
+ ...processCreateParams(params),
1670
+ });
1671
+ };
1672
+ class ZodNull extends ZodType {
1673
+ _parse(input) {
1674
+ const parsedType = this._getType(input);
1675
+ if (parsedType !== util_js_1.ZodParsedType.null) {
1676
+ const ctx = this._getOrReturnCtx(input);
1677
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1678
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1679
+ expected: util_js_1.ZodParsedType.null,
1680
+ received: ctx.parsedType,
1681
+ });
1682
+ return parseUtil_js_1.INVALID;
1683
+ }
1684
+ return (0, parseUtil_js_1.OK)(input.data);
1685
+ }
1686
+ }
1687
+ exports.ZodNull = ZodNull;
1688
+ ZodNull.create = (params) => {
1689
+ return new ZodNull({
1690
+ typeName: ZodFirstPartyTypeKind.ZodNull,
1691
+ ...processCreateParams(params),
1692
+ });
1693
+ };
1694
+ class ZodAny extends ZodType {
1695
+ constructor() {
1696
+ super(...arguments);
1697
+ // to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
1698
+ this._any = true;
1699
+ }
1700
+ _parse(input) {
1701
+ return (0, parseUtil_js_1.OK)(input.data);
1702
+ }
1703
+ }
1704
+ exports.ZodAny = ZodAny;
1705
+ ZodAny.create = (params) => {
1706
+ return new ZodAny({
1707
+ typeName: ZodFirstPartyTypeKind.ZodAny,
1708
+ ...processCreateParams(params),
1709
+ });
1710
+ };
1711
+ class ZodUnknown extends ZodType {
1712
+ constructor() {
1713
+ super(...arguments);
1714
+ // required
1715
+ this._unknown = true;
1716
+ }
1717
+ _parse(input) {
1718
+ return (0, parseUtil_js_1.OK)(input.data);
1719
+ }
1720
+ }
1721
+ exports.ZodUnknown = ZodUnknown;
1722
+ ZodUnknown.create = (params) => {
1723
+ return new ZodUnknown({
1724
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
1725
+ ...processCreateParams(params),
1726
+ });
1727
+ };
1728
+ class ZodNever extends ZodType {
1729
+ _parse(input) {
1730
+ const ctx = this._getOrReturnCtx(input);
1731
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1732
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1733
+ expected: util_js_1.ZodParsedType.never,
1734
+ received: ctx.parsedType,
1735
+ });
1736
+ return parseUtil_js_1.INVALID;
1737
+ }
1738
+ }
1739
+ exports.ZodNever = ZodNever;
1740
+ ZodNever.create = (params) => {
1741
+ return new ZodNever({
1742
+ typeName: ZodFirstPartyTypeKind.ZodNever,
1743
+ ...processCreateParams(params),
1744
+ });
1745
+ };
1746
+ class ZodVoid extends ZodType {
1747
+ _parse(input) {
1748
+ const parsedType = this._getType(input);
1749
+ if (parsedType !== util_js_1.ZodParsedType.undefined) {
1750
+ const ctx = this._getOrReturnCtx(input);
1751
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1752
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1753
+ expected: util_js_1.ZodParsedType.void,
1754
+ received: ctx.parsedType,
1755
+ });
1756
+ return parseUtil_js_1.INVALID;
1757
+ }
1758
+ return (0, parseUtil_js_1.OK)(input.data);
1759
+ }
1760
+ }
1761
+ exports.ZodVoid = ZodVoid;
1762
+ ZodVoid.create = (params) => {
1763
+ return new ZodVoid({
1764
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
1765
+ ...processCreateParams(params),
1766
+ });
1767
+ };
1768
+ class ZodArray extends ZodType {
1769
+ _parse(input) {
1770
+ const { ctx, status } = this._processInputParams(input);
1771
+ const def = this._def;
1772
+ if (ctx.parsedType !== util_js_1.ZodParsedType.array) {
1773
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1774
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1775
+ expected: util_js_1.ZodParsedType.array,
1776
+ received: ctx.parsedType,
1777
+ });
1778
+ return parseUtil_js_1.INVALID;
1779
+ }
1780
+ if (def.exactLength !== null) {
1781
+ const tooBig = ctx.data.length > def.exactLength.value;
1782
+ const tooSmall = ctx.data.length < def.exactLength.value;
1783
+ if (tooBig || tooSmall) {
1784
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1785
+ code: tooBig ? ZodError_js_1.ZodIssueCode.too_big : ZodError_js_1.ZodIssueCode.too_small,
1786
+ minimum: (tooSmall ? def.exactLength.value : undefined),
1787
+ maximum: (tooBig ? def.exactLength.value : undefined),
1788
+ type: "array",
1789
+ inclusive: true,
1790
+ exact: true,
1791
+ message: def.exactLength.message,
1792
+ });
1793
+ status.dirty();
1794
+ }
1795
+ }
1796
+ if (def.minLength !== null) {
1797
+ if (ctx.data.length < def.minLength.value) {
1798
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1799
+ code: ZodError_js_1.ZodIssueCode.too_small,
1800
+ minimum: def.minLength.value,
1801
+ type: "array",
1802
+ inclusive: true,
1803
+ exact: false,
1804
+ message: def.minLength.message,
1805
+ });
1806
+ status.dirty();
1807
+ }
1808
+ }
1809
+ if (def.maxLength !== null) {
1810
+ if (ctx.data.length > def.maxLength.value) {
1811
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1812
+ code: ZodError_js_1.ZodIssueCode.too_big,
1813
+ maximum: def.maxLength.value,
1814
+ type: "array",
1815
+ inclusive: true,
1816
+ exact: false,
1817
+ message: def.maxLength.message,
1818
+ });
1819
+ status.dirty();
1820
+ }
1821
+ }
1822
+ if (ctx.common.async) {
1823
+ return Promise.all([...ctx.data].map((item, i) => {
1824
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
1825
+ })).then((result) => {
1826
+ return parseUtil_js_1.ParseStatus.mergeArray(status, result);
1827
+ });
1828
+ }
1829
+ const result = [...ctx.data].map((item, i) => {
1830
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
1831
+ });
1832
+ return parseUtil_js_1.ParseStatus.mergeArray(status, result);
1833
+ }
1834
+ get element() {
1835
+ return this._def.type;
1836
+ }
1837
+ min(minLength, message) {
1838
+ return new ZodArray({
1839
+ ...this._def,
1840
+ minLength: { value: minLength, message: errorUtil_js_1.errorUtil.toString(message) },
1841
+ });
1842
+ }
1843
+ max(maxLength, message) {
1844
+ return new ZodArray({
1845
+ ...this._def,
1846
+ maxLength: { value: maxLength, message: errorUtil_js_1.errorUtil.toString(message) },
1847
+ });
1848
+ }
1849
+ length(len, message) {
1850
+ return new ZodArray({
1851
+ ...this._def,
1852
+ exactLength: { value: len, message: errorUtil_js_1.errorUtil.toString(message) },
1853
+ });
1854
+ }
1855
+ nonempty(message) {
1856
+ return this.min(1, message);
1857
+ }
1858
+ }
1859
+ exports.ZodArray = ZodArray;
1860
+ ZodArray.create = (schema, params) => {
1861
+ return new ZodArray({
1862
+ type: schema,
1863
+ minLength: null,
1864
+ maxLength: null,
1865
+ exactLength: null,
1866
+ typeName: ZodFirstPartyTypeKind.ZodArray,
1867
+ ...processCreateParams(params),
1868
+ });
1869
+ };
1870
+ function deepPartialify(schema) {
1871
+ if (schema instanceof ZodObject) {
1872
+ const newShape = {};
1873
+ for (const key in schema.shape) {
1874
+ const fieldSchema = schema.shape[key];
1875
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
1876
+ }
1877
+ return new ZodObject({
1878
+ ...schema._def,
1879
+ shape: () => newShape,
1880
+ });
1881
+ }
1882
+ else if (schema instanceof ZodArray) {
1883
+ return new ZodArray({
1884
+ ...schema._def,
1885
+ type: deepPartialify(schema.element),
1886
+ });
1887
+ }
1888
+ else if (schema instanceof ZodOptional) {
1889
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
1890
+ }
1891
+ else if (schema instanceof ZodNullable) {
1892
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
1893
+ }
1894
+ else if (schema instanceof ZodTuple) {
1895
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
1896
+ }
1897
+ else {
1898
+ return schema;
1899
+ }
1900
+ }
1901
+ class ZodObject extends ZodType {
1902
+ constructor() {
1903
+ super(...arguments);
1904
+ this._cached = null;
1905
+ /**
1906
+ * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
1907
+ * If you want to pass through unknown properties, use `.passthrough()` instead.
1908
+ */
1909
+ this.nonstrict = this.passthrough;
1910
+ // extend<
1911
+ // Augmentation extends ZodRawShape,
1912
+ // NewOutput extends util.flatten<{
1913
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
1914
+ // ? Augmentation[k]["_output"]
1915
+ // : k extends keyof Output
1916
+ // ? Output[k]
1917
+ // : never;
1918
+ // }>,
1919
+ // NewInput extends util.flatten<{
1920
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
1921
+ // ? Augmentation[k]["_input"]
1922
+ // : k extends keyof Input
1923
+ // ? Input[k]
1924
+ // : never;
1925
+ // }>
1926
+ // >(
1927
+ // augmentation: Augmentation
1928
+ // ): ZodObject<
1929
+ // extendShape<T, Augmentation>,
1930
+ // UnknownKeys,
1931
+ // Catchall,
1932
+ // NewOutput,
1933
+ // NewInput
1934
+ // > {
1935
+ // return new ZodObject({
1936
+ // ...this._def,
1937
+ // shape: () => ({
1938
+ // ...this._def.shape(),
1939
+ // ...augmentation,
1940
+ // }),
1941
+ // }) as any;
1942
+ // }
1943
+ /**
1944
+ * @deprecated Use `.extend` instead
1945
+ * */
1946
+ this.augment = this.extend;
1947
+ }
1948
+ _getCached() {
1949
+ if (this._cached !== null)
1950
+ return this._cached;
1951
+ const shape = this._def.shape();
1952
+ const keys = util_js_1.util.objectKeys(shape);
1953
+ this._cached = { shape, keys };
1954
+ return this._cached;
1955
+ }
1956
+ _parse(input) {
1957
+ const parsedType = this._getType(input);
1958
+ if (parsedType !== util_js_1.ZodParsedType.object) {
1959
+ const ctx = this._getOrReturnCtx(input);
1960
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
1961
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
1962
+ expected: util_js_1.ZodParsedType.object,
1963
+ received: ctx.parsedType,
1964
+ });
1965
+ return parseUtil_js_1.INVALID;
1966
+ }
1967
+ const { status, ctx } = this._processInputParams(input);
1968
+ const { shape, keys: shapeKeys } = this._getCached();
1969
+ const extraKeys = [];
1970
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
1971
+ for (const key in ctx.data) {
1972
+ if (!shapeKeys.includes(key)) {
1973
+ extraKeys.push(key);
1974
+ }
1975
+ }
1976
+ }
1977
+ const pairs = [];
1978
+ for (const key of shapeKeys) {
1979
+ const keyValidator = shape[key];
1980
+ const value = ctx.data[key];
1981
+ pairs.push({
1982
+ key: { status: "valid", value: key },
1983
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
1984
+ alwaysSet: key in ctx.data,
1985
+ });
1986
+ }
1987
+ if (this._def.catchall instanceof ZodNever) {
1988
+ const unknownKeys = this._def.unknownKeys;
1989
+ if (unknownKeys === "passthrough") {
1990
+ for (const key of extraKeys) {
1991
+ pairs.push({
1992
+ key: { status: "valid", value: key },
1993
+ value: { status: "valid", value: ctx.data[key] },
1994
+ });
1995
+ }
1996
+ }
1997
+ else if (unknownKeys === "strict") {
1998
+ if (extraKeys.length > 0) {
1999
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2000
+ code: ZodError_js_1.ZodIssueCode.unrecognized_keys,
2001
+ keys: extraKeys,
2002
+ });
2003
+ status.dirty();
2004
+ }
2005
+ }
2006
+ else if (unknownKeys === "strip") {
2007
+ }
2008
+ else {
2009
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2010
+ }
2011
+ }
2012
+ else {
2013
+ // run catchall validation
2014
+ const catchall = this._def.catchall;
2015
+ for (const key of extraKeys) {
2016
+ const value = ctx.data[key];
2017
+ pairs.push({
2018
+ key: { status: "valid", value: key },
2019
+ value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
2020
+ ),
2021
+ alwaysSet: key in ctx.data,
2022
+ });
2023
+ }
2024
+ }
2025
+ if (ctx.common.async) {
2026
+ return Promise.resolve()
2027
+ .then(async () => {
2028
+ const syncPairs = [];
2029
+ for (const pair of pairs) {
2030
+ const key = await pair.key;
2031
+ const value = await pair.value;
2032
+ syncPairs.push({
2033
+ key,
2034
+ value,
2035
+ alwaysSet: pair.alwaysSet,
2036
+ });
2037
+ }
2038
+ return syncPairs;
2039
+ })
2040
+ .then((syncPairs) => {
2041
+ return parseUtil_js_1.ParseStatus.mergeObjectSync(status, syncPairs);
2042
+ });
2043
+ }
2044
+ else {
2045
+ return parseUtil_js_1.ParseStatus.mergeObjectSync(status, pairs);
2046
+ }
2047
+ }
2048
+ get shape() {
2049
+ return this._def.shape();
2050
+ }
2051
+ strict(message) {
2052
+ errorUtil_js_1.errorUtil.errToObj;
2053
+ return new ZodObject({
2054
+ ...this._def,
2055
+ unknownKeys: "strict",
2056
+ ...(message !== undefined
2057
+ ? {
2058
+ errorMap: (issue, ctx) => {
2059
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2060
+ if (issue.code === "unrecognized_keys")
2061
+ return {
2062
+ message: errorUtil_js_1.errorUtil.errToObj(message).message ?? defaultError,
2063
+ };
2064
+ return {
2065
+ message: defaultError,
2066
+ };
2067
+ },
2068
+ }
2069
+ : {}),
2070
+ });
2071
+ }
2072
+ strip() {
2073
+ return new ZodObject({
2074
+ ...this._def,
2075
+ unknownKeys: "strip",
2076
+ });
2077
+ }
2078
+ passthrough() {
2079
+ return new ZodObject({
2080
+ ...this._def,
2081
+ unknownKeys: "passthrough",
2082
+ });
2083
+ }
2084
+ // const AugmentFactory =
2085
+ // <Def extends ZodObjectDef>(def: Def) =>
2086
+ // <Augmentation extends ZodRawShape>(
2087
+ // augmentation: Augmentation
2088
+ // ): ZodObject<
2089
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2090
+ // Def["unknownKeys"],
2091
+ // Def["catchall"]
2092
+ // > => {
2093
+ // return new ZodObject({
2094
+ // ...def,
2095
+ // shape: () => ({
2096
+ // ...def.shape(),
2097
+ // ...augmentation,
2098
+ // }),
2099
+ // }) as any;
2100
+ // };
2101
+ extend(augmentation) {
2102
+ return new ZodObject({
2103
+ ...this._def,
2104
+ shape: () => ({
2105
+ ...this._def.shape(),
2106
+ ...augmentation,
2107
+ }),
2108
+ });
2109
+ }
2110
+ /**
2111
+ * Prior to zod@1.0.12 there was a bug in the
2112
+ * inferred type of merged objects. Please
2113
+ * upgrade if you are experiencing issues.
2114
+ */
2115
+ merge(merging) {
2116
+ const merged = new ZodObject({
2117
+ unknownKeys: merging._def.unknownKeys,
2118
+ catchall: merging._def.catchall,
2119
+ shape: () => ({
2120
+ ...this._def.shape(),
2121
+ ...merging._def.shape(),
2122
+ }),
2123
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2124
+ });
2125
+ return merged;
2126
+ }
2127
+ // merge<
2128
+ // Incoming extends AnyZodObject,
2129
+ // Augmentation extends Incoming["shape"],
2130
+ // NewOutput extends {
2131
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2132
+ // ? Augmentation[k]["_output"]
2133
+ // : k extends keyof Output
2134
+ // ? Output[k]
2135
+ // : never;
2136
+ // },
2137
+ // NewInput extends {
2138
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2139
+ // ? Augmentation[k]["_input"]
2140
+ // : k extends keyof Input
2141
+ // ? Input[k]
2142
+ // : never;
2143
+ // }
2144
+ // >(
2145
+ // merging: Incoming
2146
+ // ): ZodObject<
2147
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2148
+ // Incoming["_def"]["unknownKeys"],
2149
+ // Incoming["_def"]["catchall"],
2150
+ // NewOutput,
2151
+ // NewInput
2152
+ // > {
2153
+ // const merged: any = new ZodObject({
2154
+ // unknownKeys: merging._def.unknownKeys,
2155
+ // catchall: merging._def.catchall,
2156
+ // shape: () =>
2157
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2158
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2159
+ // }) as any;
2160
+ // return merged;
2161
+ // }
2162
+ setKey(key, schema) {
2163
+ return this.augment({ [key]: schema });
2164
+ }
2165
+ // merge<Incoming extends AnyZodObject>(
2166
+ // merging: Incoming
2167
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
2168
+ // ZodObject<
2169
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2170
+ // Incoming["_def"]["unknownKeys"],
2171
+ // Incoming["_def"]["catchall"]
2172
+ // > {
2173
+ // // const mergedShape = objectUtil.mergeShapes(
2174
+ // // this._def.shape(),
2175
+ // // merging._def.shape()
2176
+ // // );
2177
+ // const merged: any = new ZodObject({
2178
+ // unknownKeys: merging._def.unknownKeys,
2179
+ // catchall: merging._def.catchall,
2180
+ // shape: () =>
2181
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2182
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2183
+ // }) as any;
2184
+ // return merged;
2185
+ // }
2186
+ catchall(index) {
2187
+ return new ZodObject({
2188
+ ...this._def,
2189
+ catchall: index,
2190
+ });
2191
+ }
2192
+ pick(mask) {
2193
+ const shape = {};
2194
+ for (const key of util_js_1.util.objectKeys(mask)) {
2195
+ if (mask[key] && this.shape[key]) {
2196
+ shape[key] = this.shape[key];
2197
+ }
2198
+ }
2199
+ return new ZodObject({
2200
+ ...this._def,
2201
+ shape: () => shape,
2202
+ });
2203
+ }
2204
+ omit(mask) {
2205
+ const shape = {};
2206
+ for (const key of util_js_1.util.objectKeys(this.shape)) {
2207
+ if (!mask[key]) {
2208
+ shape[key] = this.shape[key];
2209
+ }
2210
+ }
2211
+ return new ZodObject({
2212
+ ...this._def,
2213
+ shape: () => shape,
2214
+ });
2215
+ }
2216
+ /**
2217
+ * @deprecated
2218
+ */
2219
+ deepPartial() {
2220
+ return deepPartialify(this);
2221
+ }
2222
+ partial(mask) {
2223
+ const newShape = {};
2224
+ for (const key of util_js_1.util.objectKeys(this.shape)) {
2225
+ const fieldSchema = this.shape[key];
2226
+ if (mask && !mask[key]) {
2227
+ newShape[key] = fieldSchema;
2228
+ }
2229
+ else {
2230
+ newShape[key] = fieldSchema.optional();
2231
+ }
2232
+ }
2233
+ return new ZodObject({
2234
+ ...this._def,
2235
+ shape: () => newShape,
2236
+ });
2237
+ }
2238
+ required(mask) {
2239
+ const newShape = {};
2240
+ for (const key of util_js_1.util.objectKeys(this.shape)) {
2241
+ if (mask && !mask[key]) {
2242
+ newShape[key] = this.shape[key];
2243
+ }
2244
+ else {
2245
+ const fieldSchema = this.shape[key];
2246
+ let newField = fieldSchema;
2247
+ while (newField instanceof ZodOptional) {
2248
+ newField = newField._def.innerType;
2249
+ }
2250
+ newShape[key] = newField;
2251
+ }
2252
+ }
2253
+ return new ZodObject({
2254
+ ...this._def,
2255
+ shape: () => newShape,
2256
+ });
2257
+ }
2258
+ keyof() {
2259
+ return createZodEnum(util_js_1.util.objectKeys(this.shape));
2260
+ }
2261
+ }
2262
+ exports.ZodObject = ZodObject;
2263
+ ZodObject.create = (shape, params) => {
2264
+ return new ZodObject({
2265
+ shape: () => shape,
2266
+ unknownKeys: "strip",
2267
+ catchall: ZodNever.create(),
2268
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2269
+ ...processCreateParams(params),
2270
+ });
2271
+ };
2272
+ ZodObject.strictCreate = (shape, params) => {
2273
+ return new ZodObject({
2274
+ shape: () => shape,
2275
+ unknownKeys: "strict",
2276
+ catchall: ZodNever.create(),
2277
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2278
+ ...processCreateParams(params),
2279
+ });
2280
+ };
2281
+ ZodObject.lazycreate = (shape, params) => {
2282
+ return new ZodObject({
2283
+ shape,
2284
+ unknownKeys: "strip",
2285
+ catchall: ZodNever.create(),
2286
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2287
+ ...processCreateParams(params),
2288
+ });
2289
+ };
2290
+ class ZodUnion extends ZodType {
2291
+ _parse(input) {
2292
+ const { ctx } = this._processInputParams(input);
2293
+ const options = this._def.options;
2294
+ function handleResults(results) {
2295
+ // return first issue-free validation if it exists
2296
+ for (const result of results) {
2297
+ if (result.result.status === "valid") {
2298
+ return result.result;
2299
+ }
2300
+ }
2301
+ for (const result of results) {
2302
+ if (result.result.status === "dirty") {
2303
+ // add issues from dirty option
2304
+ ctx.common.issues.push(...result.ctx.common.issues);
2305
+ return result.result;
2306
+ }
2307
+ }
2308
+ // return invalid
2309
+ const unionErrors = results.map((result) => new ZodError_js_1.ZodError(result.ctx.common.issues));
2310
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2311
+ code: ZodError_js_1.ZodIssueCode.invalid_union,
2312
+ unionErrors,
2313
+ });
2314
+ return parseUtil_js_1.INVALID;
2315
+ }
2316
+ if (ctx.common.async) {
2317
+ return Promise.all(options.map(async (option) => {
2318
+ const childCtx = {
2319
+ ...ctx,
2320
+ common: {
2321
+ ...ctx.common,
2322
+ issues: [],
2323
+ },
2324
+ parent: null,
2325
+ };
2326
+ return {
2327
+ result: await option._parseAsync({
2328
+ data: ctx.data,
2329
+ path: ctx.path,
2330
+ parent: childCtx,
2331
+ }),
2332
+ ctx: childCtx,
2333
+ };
2334
+ })).then(handleResults);
2335
+ }
2336
+ else {
2337
+ let dirty = undefined;
2338
+ const issues = [];
2339
+ for (const option of options) {
2340
+ const childCtx = {
2341
+ ...ctx,
2342
+ common: {
2343
+ ...ctx.common,
2344
+ issues: [],
2345
+ },
2346
+ parent: null,
2347
+ };
2348
+ const result = option._parseSync({
2349
+ data: ctx.data,
2350
+ path: ctx.path,
2351
+ parent: childCtx,
2352
+ });
2353
+ if (result.status === "valid") {
2354
+ return result;
2355
+ }
2356
+ else if (result.status === "dirty" && !dirty) {
2357
+ dirty = { result, ctx: childCtx };
2358
+ }
2359
+ if (childCtx.common.issues.length) {
2360
+ issues.push(childCtx.common.issues);
2361
+ }
2362
+ }
2363
+ if (dirty) {
2364
+ ctx.common.issues.push(...dirty.ctx.common.issues);
2365
+ return dirty.result;
2366
+ }
2367
+ const unionErrors = issues.map((issues) => new ZodError_js_1.ZodError(issues));
2368
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2369
+ code: ZodError_js_1.ZodIssueCode.invalid_union,
2370
+ unionErrors,
2371
+ });
2372
+ return parseUtil_js_1.INVALID;
2373
+ }
2374
+ }
2375
+ get options() {
2376
+ return this._def.options;
2377
+ }
2378
+ }
2379
+ exports.ZodUnion = ZodUnion;
2380
+ ZodUnion.create = (types, params) => {
2381
+ return new ZodUnion({
2382
+ options: types,
2383
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
2384
+ ...processCreateParams(params),
2385
+ });
2386
+ };
2387
+ /////////////////////////////////////////////////////
2388
+ /////////////////////////////////////////////////////
2389
+ ////////// //////////
2390
+ ////////// ZodDiscriminatedUnion //////////
2391
+ ////////// //////////
2392
+ /////////////////////////////////////////////////////
2393
+ /////////////////////////////////////////////////////
2394
+ const getDiscriminator = (type) => {
2395
+ if (type instanceof ZodLazy) {
2396
+ return getDiscriminator(type.schema);
2397
+ }
2398
+ else if (type instanceof ZodEffects) {
2399
+ return getDiscriminator(type.innerType());
2400
+ }
2401
+ else if (type instanceof ZodLiteral) {
2402
+ return [type.value];
2403
+ }
2404
+ else if (type instanceof ZodEnum) {
2405
+ return type.options;
2406
+ }
2407
+ else if (type instanceof ZodNativeEnum) {
2408
+ // eslint-disable-next-line ban/ban
2409
+ return util_js_1.util.objectValues(type.enum);
2410
+ }
2411
+ else if (type instanceof ZodDefault) {
2412
+ return getDiscriminator(type._def.innerType);
2413
+ }
2414
+ else if (type instanceof ZodUndefined) {
2415
+ return [undefined];
2416
+ }
2417
+ else if (type instanceof ZodNull) {
2418
+ return [null];
2419
+ }
2420
+ else if (type instanceof ZodOptional) {
2421
+ return [undefined, ...getDiscriminator(type.unwrap())];
2422
+ }
2423
+ else if (type instanceof ZodNullable) {
2424
+ return [null, ...getDiscriminator(type.unwrap())];
2425
+ }
2426
+ else if (type instanceof ZodBranded) {
2427
+ return getDiscriminator(type.unwrap());
2428
+ }
2429
+ else if (type instanceof ZodReadonly) {
2430
+ return getDiscriminator(type.unwrap());
2431
+ }
2432
+ else if (type instanceof ZodCatch) {
2433
+ return getDiscriminator(type._def.innerType);
2434
+ }
2435
+ else {
2436
+ return [];
2437
+ }
2438
+ };
2439
+ class ZodDiscriminatedUnion extends ZodType {
2440
+ _parse(input) {
2441
+ const { ctx } = this._processInputParams(input);
2442
+ if (ctx.parsedType !== util_js_1.ZodParsedType.object) {
2443
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2444
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
2445
+ expected: util_js_1.ZodParsedType.object,
2446
+ received: ctx.parsedType,
2447
+ });
2448
+ return parseUtil_js_1.INVALID;
2449
+ }
2450
+ const discriminator = this.discriminator;
2451
+ const discriminatorValue = ctx.data[discriminator];
2452
+ const option = this.optionsMap.get(discriminatorValue);
2453
+ if (!option) {
2454
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2455
+ code: ZodError_js_1.ZodIssueCode.invalid_union_discriminator,
2456
+ options: Array.from(this.optionsMap.keys()),
2457
+ path: [discriminator],
2458
+ });
2459
+ return parseUtil_js_1.INVALID;
2460
+ }
2461
+ if (ctx.common.async) {
2462
+ return option._parseAsync({
2463
+ data: ctx.data,
2464
+ path: ctx.path,
2465
+ parent: ctx,
2466
+ });
2467
+ }
2468
+ else {
2469
+ return option._parseSync({
2470
+ data: ctx.data,
2471
+ path: ctx.path,
2472
+ parent: ctx,
2473
+ });
2474
+ }
2475
+ }
2476
+ get discriminator() {
2477
+ return this._def.discriminator;
2478
+ }
2479
+ get options() {
2480
+ return this._def.options;
2481
+ }
2482
+ get optionsMap() {
2483
+ return this._def.optionsMap;
2484
+ }
2485
+ /**
2486
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
2487
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
2488
+ * have a different value for each object in the union.
2489
+ * @param discriminator the name of the discriminator property
2490
+ * @param types an array of object schemas
2491
+ * @param params
2492
+ */
2493
+ static create(discriminator, options, params) {
2494
+ // Get all the valid discriminator values
2495
+ const optionsMap = new Map();
2496
+ // try {
2497
+ for (const type of options) {
2498
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
2499
+ if (!discriminatorValues.length) {
2500
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
2501
+ }
2502
+ for (const value of discriminatorValues) {
2503
+ if (optionsMap.has(value)) {
2504
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
2505
+ }
2506
+ optionsMap.set(value, type);
2507
+ }
2508
+ }
2509
+ return new ZodDiscriminatedUnion({
2510
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
2511
+ discriminator,
2512
+ options,
2513
+ optionsMap,
2514
+ ...processCreateParams(params),
2515
+ });
2516
+ }
2517
+ }
2518
+ exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
2519
+ function mergeValues(a, b) {
2520
+ const aType = (0, util_js_1.getParsedType)(a);
2521
+ const bType = (0, util_js_1.getParsedType)(b);
2522
+ if (a === b) {
2523
+ return { valid: true, data: a };
2524
+ }
2525
+ else if (aType === util_js_1.ZodParsedType.object && bType === util_js_1.ZodParsedType.object) {
2526
+ const bKeys = util_js_1.util.objectKeys(b);
2527
+ const sharedKeys = util_js_1.util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
2528
+ const newObj = { ...a, ...b };
2529
+ for (const key of sharedKeys) {
2530
+ const sharedValue = mergeValues(a[key], b[key]);
2531
+ if (!sharedValue.valid) {
2532
+ return { valid: false };
2533
+ }
2534
+ newObj[key] = sharedValue.data;
2535
+ }
2536
+ return { valid: true, data: newObj };
2537
+ }
2538
+ else if (aType === util_js_1.ZodParsedType.array && bType === util_js_1.ZodParsedType.array) {
2539
+ if (a.length !== b.length) {
2540
+ return { valid: false };
2541
+ }
2542
+ const newArray = [];
2543
+ for (let index = 0; index < a.length; index++) {
2544
+ const itemA = a[index];
2545
+ const itemB = b[index];
2546
+ const sharedValue = mergeValues(itemA, itemB);
2547
+ if (!sharedValue.valid) {
2548
+ return { valid: false };
2549
+ }
2550
+ newArray.push(sharedValue.data);
2551
+ }
2552
+ return { valid: true, data: newArray };
2553
+ }
2554
+ else if (aType === util_js_1.ZodParsedType.date && bType === util_js_1.ZodParsedType.date && +a === +b) {
2555
+ return { valid: true, data: a };
2556
+ }
2557
+ else {
2558
+ return { valid: false };
2559
+ }
2560
+ }
2561
+ class ZodIntersection extends ZodType {
2562
+ _parse(input) {
2563
+ const { status, ctx } = this._processInputParams(input);
2564
+ const handleParsed = (parsedLeft, parsedRight) => {
2565
+ if ((0, parseUtil_js_1.isAborted)(parsedLeft) || (0, parseUtil_js_1.isAborted)(parsedRight)) {
2566
+ return parseUtil_js_1.INVALID;
2567
+ }
2568
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
2569
+ if (!merged.valid) {
2570
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2571
+ code: ZodError_js_1.ZodIssueCode.invalid_intersection_types,
2572
+ });
2573
+ return parseUtil_js_1.INVALID;
2574
+ }
2575
+ if ((0, parseUtil_js_1.isDirty)(parsedLeft) || (0, parseUtil_js_1.isDirty)(parsedRight)) {
2576
+ status.dirty();
2577
+ }
2578
+ return { status: status.value, value: merged.data };
2579
+ };
2580
+ if (ctx.common.async) {
2581
+ return Promise.all([
2582
+ this._def.left._parseAsync({
2583
+ data: ctx.data,
2584
+ path: ctx.path,
2585
+ parent: ctx,
2586
+ }),
2587
+ this._def.right._parseAsync({
2588
+ data: ctx.data,
2589
+ path: ctx.path,
2590
+ parent: ctx,
2591
+ }),
2592
+ ]).then(([left, right]) => handleParsed(left, right));
2593
+ }
2594
+ else {
2595
+ return handleParsed(this._def.left._parseSync({
2596
+ data: ctx.data,
2597
+ path: ctx.path,
2598
+ parent: ctx,
2599
+ }), this._def.right._parseSync({
2600
+ data: ctx.data,
2601
+ path: ctx.path,
2602
+ parent: ctx,
2603
+ }));
2604
+ }
2605
+ }
2606
+ }
2607
+ exports.ZodIntersection = ZodIntersection;
2608
+ ZodIntersection.create = (left, right, params) => {
2609
+ return new ZodIntersection({
2610
+ left: left,
2611
+ right: right,
2612
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
2613
+ ...processCreateParams(params),
2614
+ });
2615
+ };
2616
+ // type ZodTupleItems = [ZodTypeAny, ...ZodTypeAny[]];
2617
+ class ZodTuple extends ZodType {
2618
+ _parse(input) {
2619
+ const { status, ctx } = this._processInputParams(input);
2620
+ if (ctx.parsedType !== util_js_1.ZodParsedType.array) {
2621
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2622
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
2623
+ expected: util_js_1.ZodParsedType.array,
2624
+ received: ctx.parsedType,
2625
+ });
2626
+ return parseUtil_js_1.INVALID;
2627
+ }
2628
+ if (ctx.data.length < this._def.items.length) {
2629
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2630
+ code: ZodError_js_1.ZodIssueCode.too_small,
2631
+ minimum: this._def.items.length,
2632
+ inclusive: true,
2633
+ exact: false,
2634
+ type: "array",
2635
+ });
2636
+ return parseUtil_js_1.INVALID;
2637
+ }
2638
+ const rest = this._def.rest;
2639
+ if (!rest && ctx.data.length > this._def.items.length) {
2640
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2641
+ code: ZodError_js_1.ZodIssueCode.too_big,
2642
+ maximum: this._def.items.length,
2643
+ inclusive: true,
2644
+ exact: false,
2645
+ type: "array",
2646
+ });
2647
+ status.dirty();
2648
+ }
2649
+ const items = [...ctx.data]
2650
+ .map((item, itemIndex) => {
2651
+ const schema = this._def.items[itemIndex] || this._def.rest;
2652
+ if (!schema)
2653
+ return null;
2654
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
2655
+ })
2656
+ .filter((x) => !!x); // filter nulls
2657
+ if (ctx.common.async) {
2658
+ return Promise.all(items).then((results) => {
2659
+ return parseUtil_js_1.ParseStatus.mergeArray(status, results);
2660
+ });
2661
+ }
2662
+ else {
2663
+ return parseUtil_js_1.ParseStatus.mergeArray(status, items);
2664
+ }
2665
+ }
2666
+ get items() {
2667
+ return this._def.items;
2668
+ }
2669
+ rest(rest) {
2670
+ return new ZodTuple({
2671
+ ...this._def,
2672
+ rest,
2673
+ });
2674
+ }
2675
+ }
2676
+ exports.ZodTuple = ZodTuple;
2677
+ ZodTuple.create = (schemas, params) => {
2678
+ if (!Array.isArray(schemas)) {
2679
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2680
+ }
2681
+ return new ZodTuple({
2682
+ items: schemas,
2683
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
2684
+ rest: null,
2685
+ ...processCreateParams(params),
2686
+ });
2687
+ };
2688
+ class ZodRecord extends ZodType {
2689
+ get keySchema() {
2690
+ return this._def.keyType;
2691
+ }
2692
+ get valueSchema() {
2693
+ return this._def.valueType;
2694
+ }
2695
+ _parse(input) {
2696
+ const { status, ctx } = this._processInputParams(input);
2697
+ if (ctx.parsedType !== util_js_1.ZodParsedType.object) {
2698
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2699
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
2700
+ expected: util_js_1.ZodParsedType.object,
2701
+ received: ctx.parsedType,
2702
+ });
2703
+ return parseUtil_js_1.INVALID;
2704
+ }
2705
+ const pairs = [];
2706
+ const keyType = this._def.keyType;
2707
+ const valueType = this._def.valueType;
2708
+ for (const key in ctx.data) {
2709
+ pairs.push({
2710
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
2711
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
2712
+ alwaysSet: key in ctx.data,
2713
+ });
2714
+ }
2715
+ if (ctx.common.async) {
2716
+ return parseUtil_js_1.ParseStatus.mergeObjectAsync(status, pairs);
2717
+ }
2718
+ else {
2719
+ return parseUtil_js_1.ParseStatus.mergeObjectSync(status, pairs);
2720
+ }
2721
+ }
2722
+ get element() {
2723
+ return this._def.valueType;
2724
+ }
2725
+ static create(first, second, third) {
2726
+ if (second instanceof ZodType) {
2727
+ return new ZodRecord({
2728
+ keyType: first,
2729
+ valueType: second,
2730
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2731
+ ...processCreateParams(third),
2732
+ });
2733
+ }
2734
+ return new ZodRecord({
2735
+ keyType: ZodString.create(),
2736
+ valueType: first,
2737
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2738
+ ...processCreateParams(second),
2739
+ });
2740
+ }
2741
+ }
2742
+ exports.ZodRecord = ZodRecord;
2743
+ class ZodMap extends ZodType {
2744
+ get keySchema() {
2745
+ return this._def.keyType;
2746
+ }
2747
+ get valueSchema() {
2748
+ return this._def.valueType;
2749
+ }
2750
+ _parse(input) {
2751
+ const { status, ctx } = this._processInputParams(input);
2752
+ if (ctx.parsedType !== util_js_1.ZodParsedType.map) {
2753
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2754
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
2755
+ expected: util_js_1.ZodParsedType.map,
2756
+ received: ctx.parsedType,
2757
+ });
2758
+ return parseUtil_js_1.INVALID;
2759
+ }
2760
+ const keyType = this._def.keyType;
2761
+ const valueType = this._def.valueType;
2762
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
2763
+ return {
2764
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
2765
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
2766
+ };
2767
+ });
2768
+ if (ctx.common.async) {
2769
+ const finalMap = new Map();
2770
+ return Promise.resolve().then(async () => {
2771
+ for (const pair of pairs) {
2772
+ const key = await pair.key;
2773
+ const value = await pair.value;
2774
+ if (key.status === "aborted" || value.status === "aborted") {
2775
+ return parseUtil_js_1.INVALID;
2776
+ }
2777
+ if (key.status === "dirty" || value.status === "dirty") {
2778
+ status.dirty();
2779
+ }
2780
+ finalMap.set(key.value, value.value);
2781
+ }
2782
+ return { status: status.value, value: finalMap };
2783
+ });
2784
+ }
2785
+ else {
2786
+ const finalMap = new Map();
2787
+ for (const pair of pairs) {
2788
+ const key = pair.key;
2789
+ const value = pair.value;
2790
+ if (key.status === "aborted" || value.status === "aborted") {
2791
+ return parseUtil_js_1.INVALID;
2792
+ }
2793
+ if (key.status === "dirty" || value.status === "dirty") {
2794
+ status.dirty();
2795
+ }
2796
+ finalMap.set(key.value, value.value);
2797
+ }
2798
+ return { status: status.value, value: finalMap };
2799
+ }
2800
+ }
2801
+ }
2802
+ exports.ZodMap = ZodMap;
2803
+ ZodMap.create = (keyType, valueType, params) => {
2804
+ return new ZodMap({
2805
+ valueType,
2806
+ keyType,
2807
+ typeName: ZodFirstPartyTypeKind.ZodMap,
2808
+ ...processCreateParams(params),
2809
+ });
2810
+ };
2811
+ class ZodSet extends ZodType {
2812
+ _parse(input) {
2813
+ const { status, ctx } = this._processInputParams(input);
2814
+ if (ctx.parsedType !== util_js_1.ZodParsedType.set) {
2815
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2816
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
2817
+ expected: util_js_1.ZodParsedType.set,
2818
+ received: ctx.parsedType,
2819
+ });
2820
+ return parseUtil_js_1.INVALID;
2821
+ }
2822
+ const def = this._def;
2823
+ if (def.minSize !== null) {
2824
+ if (ctx.data.size < def.minSize.value) {
2825
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2826
+ code: ZodError_js_1.ZodIssueCode.too_small,
2827
+ minimum: def.minSize.value,
2828
+ type: "set",
2829
+ inclusive: true,
2830
+ exact: false,
2831
+ message: def.minSize.message,
2832
+ });
2833
+ status.dirty();
2834
+ }
2835
+ }
2836
+ if (def.maxSize !== null) {
2837
+ if (ctx.data.size > def.maxSize.value) {
2838
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2839
+ code: ZodError_js_1.ZodIssueCode.too_big,
2840
+ maximum: def.maxSize.value,
2841
+ type: "set",
2842
+ inclusive: true,
2843
+ exact: false,
2844
+ message: def.maxSize.message,
2845
+ });
2846
+ status.dirty();
2847
+ }
2848
+ }
2849
+ const valueType = this._def.valueType;
2850
+ function finalizeSet(elements) {
2851
+ const parsedSet = new Set();
2852
+ for (const element of elements) {
2853
+ if (element.status === "aborted")
2854
+ return parseUtil_js_1.INVALID;
2855
+ if (element.status === "dirty")
2856
+ status.dirty();
2857
+ parsedSet.add(element.value);
2858
+ }
2859
+ return { status: status.value, value: parsedSet };
2860
+ }
2861
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
2862
+ if (ctx.common.async) {
2863
+ return Promise.all(elements).then((elements) => finalizeSet(elements));
2864
+ }
2865
+ else {
2866
+ return finalizeSet(elements);
2867
+ }
2868
+ }
2869
+ min(minSize, message) {
2870
+ return new ZodSet({
2871
+ ...this._def,
2872
+ minSize: { value: minSize, message: errorUtil_js_1.errorUtil.toString(message) },
2873
+ });
2874
+ }
2875
+ max(maxSize, message) {
2876
+ return new ZodSet({
2877
+ ...this._def,
2878
+ maxSize: { value: maxSize, message: errorUtil_js_1.errorUtil.toString(message) },
2879
+ });
2880
+ }
2881
+ size(size, message) {
2882
+ return this.min(size, message).max(size, message);
2883
+ }
2884
+ nonempty(message) {
2885
+ return this.min(1, message);
2886
+ }
2887
+ }
2888
+ exports.ZodSet = ZodSet;
2889
+ ZodSet.create = (valueType, params) => {
2890
+ return new ZodSet({
2891
+ valueType,
2892
+ minSize: null,
2893
+ maxSize: null,
2894
+ typeName: ZodFirstPartyTypeKind.ZodSet,
2895
+ ...processCreateParams(params),
2896
+ });
2897
+ };
2898
+ class ZodFunction extends ZodType {
2899
+ constructor() {
2900
+ super(...arguments);
2901
+ this.validate = this.implement;
2902
+ }
2903
+ _parse(input) {
2904
+ const { ctx } = this._processInputParams(input);
2905
+ if (ctx.parsedType !== util_js_1.ZodParsedType.function) {
2906
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
2907
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
2908
+ expected: util_js_1.ZodParsedType.function,
2909
+ received: ctx.parsedType,
2910
+ });
2911
+ return parseUtil_js_1.INVALID;
2912
+ }
2913
+ function makeArgsIssue(args, error) {
2914
+ return (0, parseUtil_js_1.makeIssue)({
2915
+ data: args,
2916
+ path: ctx.path,
2917
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, (0, errors_js_1.getErrorMap)(), errors_js_1.defaultErrorMap].filter((x) => !!x),
2918
+ issueData: {
2919
+ code: ZodError_js_1.ZodIssueCode.invalid_arguments,
2920
+ argumentsError: error,
2921
+ },
2922
+ });
2923
+ }
2924
+ function makeReturnsIssue(returns, error) {
2925
+ return (0, parseUtil_js_1.makeIssue)({
2926
+ data: returns,
2927
+ path: ctx.path,
2928
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, (0, errors_js_1.getErrorMap)(), errors_js_1.defaultErrorMap].filter((x) => !!x),
2929
+ issueData: {
2930
+ code: ZodError_js_1.ZodIssueCode.invalid_return_type,
2931
+ returnTypeError: error,
2932
+ },
2933
+ });
2934
+ }
2935
+ const params = { errorMap: ctx.common.contextualErrorMap };
2936
+ const fn = ctx.data;
2937
+ if (this._def.returns instanceof ZodPromise) {
2938
+ // Would love a way to avoid disabling this rule, but we need
2939
+ // an alias (using an arrow function was what caused 2651).
2940
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
2941
+ const me = this;
2942
+ return (0, parseUtil_js_1.OK)(async function (...args) {
2943
+ const error = new ZodError_js_1.ZodError([]);
2944
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
2945
+ error.addIssue(makeArgsIssue(args, e));
2946
+ throw error;
2947
+ });
2948
+ const result = await Reflect.apply(fn, this, parsedArgs);
2949
+ const parsedReturns = await me._def.returns._def.type
2950
+ .parseAsync(result, params)
2951
+ .catch((e) => {
2952
+ error.addIssue(makeReturnsIssue(result, e));
2953
+ throw error;
2954
+ });
2955
+ return parsedReturns;
2956
+ });
2957
+ }
2958
+ else {
2959
+ // Would love a way to avoid disabling this rule, but we need
2960
+ // an alias (using an arrow function was what caused 2651).
2961
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
2962
+ const me = this;
2963
+ return (0, parseUtil_js_1.OK)(function (...args) {
2964
+ const parsedArgs = me._def.args.safeParse(args, params);
2965
+ if (!parsedArgs.success) {
2966
+ throw new ZodError_js_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
2967
+ }
2968
+ const result = Reflect.apply(fn, this, parsedArgs.data);
2969
+ const parsedReturns = me._def.returns.safeParse(result, params);
2970
+ if (!parsedReturns.success) {
2971
+ throw new ZodError_js_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
2972
+ }
2973
+ return parsedReturns.data;
2974
+ });
2975
+ }
2976
+ }
2977
+ parameters() {
2978
+ return this._def.args;
2979
+ }
2980
+ returnType() {
2981
+ return this._def.returns;
2982
+ }
2983
+ args(...items) {
2984
+ return new ZodFunction({
2985
+ ...this._def,
2986
+ args: ZodTuple.create(items).rest(ZodUnknown.create()),
2987
+ });
2988
+ }
2989
+ returns(returnType) {
2990
+ return new ZodFunction({
2991
+ ...this._def,
2992
+ returns: returnType,
2993
+ });
2994
+ }
2995
+ implement(func) {
2996
+ const validatedFunc = this.parse(func);
2997
+ return validatedFunc;
2998
+ }
2999
+ strictImplement(func) {
3000
+ const validatedFunc = this.parse(func);
3001
+ return validatedFunc;
3002
+ }
3003
+ static create(args, returns, params) {
3004
+ return new ZodFunction({
3005
+ args: (args ? args : ZodTuple.create([]).rest(ZodUnknown.create())),
3006
+ returns: returns || ZodUnknown.create(),
3007
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
3008
+ ...processCreateParams(params),
3009
+ });
3010
+ }
3011
+ }
3012
+ exports.ZodFunction = ZodFunction;
3013
+ class ZodLazy extends ZodType {
3014
+ get schema() {
3015
+ return this._def.getter();
3016
+ }
3017
+ _parse(input) {
3018
+ const { ctx } = this._processInputParams(input);
3019
+ const lazySchema = this._def.getter();
3020
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3021
+ }
3022
+ }
3023
+ exports.ZodLazy = ZodLazy;
3024
+ ZodLazy.create = (getter, params) => {
3025
+ return new ZodLazy({
3026
+ getter: getter,
3027
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3028
+ ...processCreateParams(params),
3029
+ });
3030
+ };
3031
+ class ZodLiteral extends ZodType {
3032
+ _parse(input) {
3033
+ if (input.data !== this._def.value) {
3034
+ const ctx = this._getOrReturnCtx(input);
3035
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
3036
+ received: ctx.data,
3037
+ code: ZodError_js_1.ZodIssueCode.invalid_literal,
3038
+ expected: this._def.value,
3039
+ });
3040
+ return parseUtil_js_1.INVALID;
3041
+ }
3042
+ return { status: "valid", value: input.data };
3043
+ }
3044
+ get value() {
3045
+ return this._def.value;
3046
+ }
3047
+ }
3048
+ exports.ZodLiteral = ZodLiteral;
3049
+ ZodLiteral.create = (value, params) => {
3050
+ return new ZodLiteral({
3051
+ value: value,
3052
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3053
+ ...processCreateParams(params),
3054
+ });
3055
+ };
3056
+ function createZodEnum(values, params) {
3057
+ return new ZodEnum({
3058
+ values,
3059
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
3060
+ ...processCreateParams(params),
3061
+ });
3062
+ }
3063
+ class ZodEnum extends ZodType {
3064
+ _parse(input) {
3065
+ if (typeof input.data !== "string") {
3066
+ const ctx = this._getOrReturnCtx(input);
3067
+ const expectedValues = this._def.values;
3068
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
3069
+ expected: util_js_1.util.joinValues(expectedValues),
3070
+ received: ctx.parsedType,
3071
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
3072
+ });
3073
+ return parseUtil_js_1.INVALID;
3074
+ }
3075
+ if (!this._cache) {
3076
+ this._cache = new Set(this._def.values);
3077
+ }
3078
+ if (!this._cache.has(input.data)) {
3079
+ const ctx = this._getOrReturnCtx(input);
3080
+ const expectedValues = this._def.values;
3081
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
3082
+ received: ctx.data,
3083
+ code: ZodError_js_1.ZodIssueCode.invalid_enum_value,
3084
+ options: expectedValues,
3085
+ });
3086
+ return parseUtil_js_1.INVALID;
3087
+ }
3088
+ return (0, parseUtil_js_1.OK)(input.data);
3089
+ }
3090
+ get options() {
3091
+ return this._def.values;
3092
+ }
3093
+ get enum() {
3094
+ const enumValues = {};
3095
+ for (const val of this._def.values) {
3096
+ enumValues[val] = val;
3097
+ }
3098
+ return enumValues;
3099
+ }
3100
+ get Values() {
3101
+ const enumValues = {};
3102
+ for (const val of this._def.values) {
3103
+ enumValues[val] = val;
3104
+ }
3105
+ return enumValues;
3106
+ }
3107
+ get Enum() {
3108
+ const enumValues = {};
3109
+ for (const val of this._def.values) {
3110
+ enumValues[val] = val;
3111
+ }
3112
+ return enumValues;
3113
+ }
3114
+ extract(values, newDef = this._def) {
3115
+ return ZodEnum.create(values, {
3116
+ ...this._def,
3117
+ ...newDef,
3118
+ });
3119
+ }
3120
+ exclude(values, newDef = this._def) {
3121
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3122
+ ...this._def,
3123
+ ...newDef,
3124
+ });
3125
+ }
3126
+ }
3127
+ exports.ZodEnum = ZodEnum;
3128
+ ZodEnum.create = createZodEnum;
3129
+ class ZodNativeEnum extends ZodType {
3130
+ _parse(input) {
3131
+ const nativeEnumValues = util_js_1.util.getValidEnumValues(this._def.values);
3132
+ const ctx = this._getOrReturnCtx(input);
3133
+ if (ctx.parsedType !== util_js_1.ZodParsedType.string && ctx.parsedType !== util_js_1.ZodParsedType.number) {
3134
+ const expectedValues = util_js_1.util.objectValues(nativeEnumValues);
3135
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
3136
+ expected: util_js_1.util.joinValues(expectedValues),
3137
+ received: ctx.parsedType,
3138
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
3139
+ });
3140
+ return parseUtil_js_1.INVALID;
3141
+ }
3142
+ if (!this._cache) {
3143
+ this._cache = new Set(util_js_1.util.getValidEnumValues(this._def.values));
3144
+ }
3145
+ if (!this._cache.has(input.data)) {
3146
+ const expectedValues = util_js_1.util.objectValues(nativeEnumValues);
3147
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
3148
+ received: ctx.data,
3149
+ code: ZodError_js_1.ZodIssueCode.invalid_enum_value,
3150
+ options: expectedValues,
3151
+ });
3152
+ return parseUtil_js_1.INVALID;
3153
+ }
3154
+ return (0, parseUtil_js_1.OK)(input.data);
3155
+ }
3156
+ get enum() {
3157
+ return this._def.values;
3158
+ }
3159
+ }
3160
+ exports.ZodNativeEnum = ZodNativeEnum;
3161
+ ZodNativeEnum.create = (values, params) => {
3162
+ return new ZodNativeEnum({
3163
+ values: values,
3164
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3165
+ ...processCreateParams(params),
3166
+ });
3167
+ };
3168
+ class ZodPromise extends ZodType {
3169
+ unwrap() {
3170
+ return this._def.type;
3171
+ }
3172
+ _parse(input) {
3173
+ const { ctx } = this._processInputParams(input);
3174
+ if (ctx.parsedType !== util_js_1.ZodParsedType.promise && ctx.common.async === false) {
3175
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
3176
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
3177
+ expected: util_js_1.ZodParsedType.promise,
3178
+ received: ctx.parsedType,
3179
+ });
3180
+ return parseUtil_js_1.INVALID;
3181
+ }
3182
+ const promisified = ctx.parsedType === util_js_1.ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3183
+ return (0, parseUtil_js_1.OK)(promisified.then((data) => {
3184
+ return this._def.type.parseAsync(data, {
3185
+ path: ctx.path,
3186
+ errorMap: ctx.common.contextualErrorMap,
3187
+ });
3188
+ }));
3189
+ }
3190
+ }
3191
+ exports.ZodPromise = ZodPromise;
3192
+ ZodPromise.create = (schema, params) => {
3193
+ return new ZodPromise({
3194
+ type: schema,
3195
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
3196
+ ...processCreateParams(params),
3197
+ });
3198
+ };
3199
+ class ZodEffects extends ZodType {
3200
+ innerType() {
3201
+ return this._def.schema;
3202
+ }
3203
+ sourceType() {
3204
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
3205
+ ? this._def.schema.sourceType()
3206
+ : this._def.schema;
3207
+ }
3208
+ _parse(input) {
3209
+ const { status, ctx } = this._processInputParams(input);
3210
+ const effect = this._def.effect || null;
3211
+ const checkCtx = {
3212
+ addIssue: (arg) => {
3213
+ (0, parseUtil_js_1.addIssueToContext)(ctx, arg);
3214
+ if (arg.fatal) {
3215
+ status.abort();
3216
+ }
3217
+ else {
3218
+ status.dirty();
3219
+ }
3220
+ },
3221
+ get path() {
3222
+ return ctx.path;
3223
+ },
3224
+ };
3225
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3226
+ if (effect.type === "preprocess") {
3227
+ const processed = effect.transform(ctx.data, checkCtx);
3228
+ if (ctx.common.async) {
3229
+ return Promise.resolve(processed).then(async (processed) => {
3230
+ if (status.value === "aborted")
3231
+ return parseUtil_js_1.INVALID;
3232
+ const result = await this._def.schema._parseAsync({
3233
+ data: processed,
3234
+ path: ctx.path,
3235
+ parent: ctx,
3236
+ });
3237
+ if (result.status === "aborted")
3238
+ return parseUtil_js_1.INVALID;
3239
+ if (result.status === "dirty")
3240
+ return (0, parseUtil_js_1.DIRTY)(result.value);
3241
+ if (status.value === "dirty")
3242
+ return (0, parseUtil_js_1.DIRTY)(result.value);
3243
+ return result;
3244
+ });
3245
+ }
3246
+ else {
3247
+ if (status.value === "aborted")
3248
+ return parseUtil_js_1.INVALID;
3249
+ const result = this._def.schema._parseSync({
3250
+ data: processed,
3251
+ path: ctx.path,
3252
+ parent: ctx,
3253
+ });
3254
+ if (result.status === "aborted")
3255
+ return parseUtil_js_1.INVALID;
3256
+ if (result.status === "dirty")
3257
+ return (0, parseUtil_js_1.DIRTY)(result.value);
3258
+ if (status.value === "dirty")
3259
+ return (0, parseUtil_js_1.DIRTY)(result.value);
3260
+ return result;
3261
+ }
3262
+ }
3263
+ if (effect.type === "refinement") {
3264
+ const executeRefinement = (acc) => {
3265
+ const result = effect.refinement(acc, checkCtx);
3266
+ if (ctx.common.async) {
3267
+ return Promise.resolve(result);
3268
+ }
3269
+ if (result instanceof Promise) {
3270
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3271
+ }
3272
+ return acc;
3273
+ };
3274
+ if (ctx.common.async === false) {
3275
+ const inner = this._def.schema._parseSync({
3276
+ data: ctx.data,
3277
+ path: ctx.path,
3278
+ parent: ctx,
3279
+ });
3280
+ if (inner.status === "aborted")
3281
+ return parseUtil_js_1.INVALID;
3282
+ if (inner.status === "dirty")
3283
+ status.dirty();
3284
+ // return value is ignored
3285
+ executeRefinement(inner.value);
3286
+ return { status: status.value, value: inner.value };
3287
+ }
3288
+ else {
3289
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
3290
+ if (inner.status === "aborted")
3291
+ return parseUtil_js_1.INVALID;
3292
+ if (inner.status === "dirty")
3293
+ status.dirty();
3294
+ return executeRefinement(inner.value).then(() => {
3295
+ return { status: status.value, value: inner.value };
3296
+ });
3297
+ });
3298
+ }
3299
+ }
3300
+ if (effect.type === "transform") {
3301
+ if (ctx.common.async === false) {
3302
+ const base = this._def.schema._parseSync({
3303
+ data: ctx.data,
3304
+ path: ctx.path,
3305
+ parent: ctx,
3306
+ });
3307
+ if (!(0, parseUtil_js_1.isValid)(base))
3308
+ return parseUtil_js_1.INVALID;
3309
+ const result = effect.transform(base.value, checkCtx);
3310
+ if (result instanceof Promise) {
3311
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3312
+ }
3313
+ return { status: status.value, value: result };
3314
+ }
3315
+ else {
3316
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
3317
+ if (!(0, parseUtil_js_1.isValid)(base))
3318
+ return parseUtil_js_1.INVALID;
3319
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
3320
+ status: status.value,
3321
+ value: result,
3322
+ }));
3323
+ });
3324
+ }
3325
+ }
3326
+ util_js_1.util.assertNever(effect);
3327
+ }
3328
+ }
3329
+ exports.ZodEffects = ZodEffects;
3330
+ exports.ZodTransformer = ZodEffects;
3331
+ ZodEffects.create = (schema, effect, params) => {
3332
+ return new ZodEffects({
3333
+ schema,
3334
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3335
+ effect,
3336
+ ...processCreateParams(params),
3337
+ });
3338
+ };
3339
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3340
+ return new ZodEffects({
3341
+ schema,
3342
+ effect: { type: "preprocess", transform: preprocess },
3343
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3344
+ ...processCreateParams(params),
3345
+ });
3346
+ };
3347
+ class ZodOptional extends ZodType {
3348
+ _parse(input) {
3349
+ const parsedType = this._getType(input);
3350
+ if (parsedType === util_js_1.ZodParsedType.undefined) {
3351
+ return (0, parseUtil_js_1.OK)(undefined);
3352
+ }
3353
+ return this._def.innerType._parse(input);
3354
+ }
3355
+ unwrap() {
3356
+ return this._def.innerType;
3357
+ }
3358
+ }
3359
+ exports.ZodOptional = ZodOptional;
3360
+ ZodOptional.create = (type, params) => {
3361
+ return new ZodOptional({
3362
+ innerType: type,
3363
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
3364
+ ...processCreateParams(params),
3365
+ });
3366
+ };
3367
+ class ZodNullable extends ZodType {
3368
+ _parse(input) {
3369
+ const parsedType = this._getType(input);
3370
+ if (parsedType === util_js_1.ZodParsedType.null) {
3371
+ return (0, parseUtil_js_1.OK)(null);
3372
+ }
3373
+ return this._def.innerType._parse(input);
3374
+ }
3375
+ unwrap() {
3376
+ return this._def.innerType;
3377
+ }
3378
+ }
3379
+ exports.ZodNullable = ZodNullable;
3380
+ ZodNullable.create = (type, params) => {
3381
+ return new ZodNullable({
3382
+ innerType: type,
3383
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
3384
+ ...processCreateParams(params),
3385
+ });
3386
+ };
3387
+ class ZodDefault extends ZodType {
3388
+ _parse(input) {
3389
+ const { ctx } = this._processInputParams(input);
3390
+ let data = ctx.data;
3391
+ if (ctx.parsedType === util_js_1.ZodParsedType.undefined) {
3392
+ data = this._def.defaultValue();
3393
+ }
3394
+ return this._def.innerType._parse({
3395
+ data,
3396
+ path: ctx.path,
3397
+ parent: ctx,
3398
+ });
3399
+ }
3400
+ removeDefault() {
3401
+ return this._def.innerType;
3402
+ }
3403
+ }
3404
+ exports.ZodDefault = ZodDefault;
3405
+ ZodDefault.create = (type, params) => {
3406
+ return new ZodDefault({
3407
+ innerType: type,
3408
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
3409
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
3410
+ ...processCreateParams(params),
3411
+ });
3412
+ };
3413
+ class ZodCatch extends ZodType {
3414
+ _parse(input) {
3415
+ const { ctx } = this._processInputParams(input);
3416
+ // newCtx is used to not collect issues from inner types in ctx
3417
+ const newCtx = {
3418
+ ...ctx,
3419
+ common: {
3420
+ ...ctx.common,
3421
+ issues: [],
3422
+ },
3423
+ };
3424
+ const result = this._def.innerType._parse({
3425
+ data: newCtx.data,
3426
+ path: newCtx.path,
3427
+ parent: {
3428
+ ...newCtx,
3429
+ },
3430
+ });
3431
+ if ((0, parseUtil_js_1.isAsync)(result)) {
3432
+ return result.then((result) => {
3433
+ return {
3434
+ status: "valid",
3435
+ value: result.status === "valid"
3436
+ ? result.value
3437
+ : this._def.catchValue({
3438
+ get error() {
3439
+ return new ZodError_js_1.ZodError(newCtx.common.issues);
3440
+ },
3441
+ input: newCtx.data,
3442
+ }),
3443
+ };
3444
+ });
3445
+ }
3446
+ else {
3447
+ return {
3448
+ status: "valid",
3449
+ value: result.status === "valid"
3450
+ ? result.value
3451
+ : this._def.catchValue({
3452
+ get error() {
3453
+ return new ZodError_js_1.ZodError(newCtx.common.issues);
3454
+ },
3455
+ input: newCtx.data,
3456
+ }),
3457
+ };
3458
+ }
3459
+ }
3460
+ removeCatch() {
3461
+ return this._def.innerType;
3462
+ }
3463
+ }
3464
+ exports.ZodCatch = ZodCatch;
3465
+ ZodCatch.create = (type, params) => {
3466
+ return new ZodCatch({
3467
+ innerType: type,
3468
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
3469
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3470
+ ...processCreateParams(params),
3471
+ });
3472
+ };
3473
+ class ZodNaN extends ZodType {
3474
+ _parse(input) {
3475
+ const parsedType = this._getType(input);
3476
+ if (parsedType !== util_js_1.ZodParsedType.nan) {
3477
+ const ctx = this._getOrReturnCtx(input);
3478
+ (0, parseUtil_js_1.addIssueToContext)(ctx, {
3479
+ code: ZodError_js_1.ZodIssueCode.invalid_type,
3480
+ expected: util_js_1.ZodParsedType.nan,
3481
+ received: ctx.parsedType,
3482
+ });
3483
+ return parseUtil_js_1.INVALID;
3484
+ }
3485
+ return { status: "valid", value: input.data };
3486
+ }
3487
+ }
3488
+ exports.ZodNaN = ZodNaN;
3489
+ ZodNaN.create = (params) => {
3490
+ return new ZodNaN({
3491
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
3492
+ ...processCreateParams(params),
3493
+ });
3494
+ };
3495
+ exports.BRAND = Symbol("zod_brand");
3496
+ class ZodBranded extends ZodType {
3497
+ _parse(input) {
3498
+ const { ctx } = this._processInputParams(input);
3499
+ const data = ctx.data;
3500
+ return this._def.type._parse({
3501
+ data,
3502
+ path: ctx.path,
3503
+ parent: ctx,
3504
+ });
3505
+ }
3506
+ unwrap() {
3507
+ return this._def.type;
3508
+ }
3509
+ }
3510
+ exports.ZodBranded = ZodBranded;
3511
+ class ZodPipeline extends ZodType {
3512
+ _parse(input) {
3513
+ const { status, ctx } = this._processInputParams(input);
3514
+ if (ctx.common.async) {
3515
+ const handleAsync = async () => {
3516
+ const inResult = await this._def.in._parseAsync({
3517
+ data: ctx.data,
3518
+ path: ctx.path,
3519
+ parent: ctx,
3520
+ });
3521
+ if (inResult.status === "aborted")
3522
+ return parseUtil_js_1.INVALID;
3523
+ if (inResult.status === "dirty") {
3524
+ status.dirty();
3525
+ return (0, parseUtil_js_1.DIRTY)(inResult.value);
3526
+ }
3527
+ else {
3528
+ return this._def.out._parseAsync({
3529
+ data: inResult.value,
3530
+ path: ctx.path,
3531
+ parent: ctx,
3532
+ });
3533
+ }
3534
+ };
3535
+ return handleAsync();
3536
+ }
3537
+ else {
3538
+ const inResult = this._def.in._parseSync({
3539
+ data: ctx.data,
3540
+ path: ctx.path,
3541
+ parent: ctx,
3542
+ });
3543
+ if (inResult.status === "aborted")
3544
+ return parseUtil_js_1.INVALID;
3545
+ if (inResult.status === "dirty") {
3546
+ status.dirty();
3547
+ return {
3548
+ status: "dirty",
3549
+ value: inResult.value,
3550
+ };
3551
+ }
3552
+ else {
3553
+ return this._def.out._parseSync({
3554
+ data: inResult.value,
3555
+ path: ctx.path,
3556
+ parent: ctx,
3557
+ });
3558
+ }
3559
+ }
3560
+ }
3561
+ static create(a, b) {
3562
+ return new ZodPipeline({
3563
+ in: a,
3564
+ out: b,
3565
+ typeName: ZodFirstPartyTypeKind.ZodPipeline,
3566
+ });
3567
+ }
3568
+ }
3569
+ exports.ZodPipeline = ZodPipeline;
3570
+ class ZodReadonly extends ZodType {
3571
+ _parse(input) {
3572
+ const result = this._def.innerType._parse(input);
3573
+ const freeze = (data) => {
3574
+ if ((0, parseUtil_js_1.isValid)(data)) {
3575
+ data.value = Object.freeze(data.value);
3576
+ }
3577
+ return data;
3578
+ };
3579
+ return (0, parseUtil_js_1.isAsync)(result) ? result.then((data) => freeze(data)) : freeze(result);
3580
+ }
3581
+ unwrap() {
3582
+ return this._def.innerType;
3583
+ }
3584
+ }
3585
+ exports.ZodReadonly = ZodReadonly;
3586
+ ZodReadonly.create = (type, params) => {
3587
+ return new ZodReadonly({
3588
+ innerType: type,
3589
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
3590
+ ...processCreateParams(params),
3591
+ });
3592
+ };
3593
+ ////////////////////////////////////////
3594
+ ////////////////////////////////////////
3595
+ ////////// //////////
3596
+ ////////// z.custom //////////
3597
+ ////////// //////////
3598
+ ////////////////////////////////////////
3599
+ ////////////////////////////////////////
3600
+ function cleanParams(params, data) {
3601
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
3602
+ const p2 = typeof p === "string" ? { message: p } : p;
3603
+ return p2;
3604
+ }
3605
+ function custom(check, _params = {},
3606
+ /**
3607
+ * @deprecated
3608
+ *
3609
+ * Pass `fatal` into the params object instead:
3610
+ *
3611
+ * ```ts
3612
+ * z.string().custom((val) => val.length > 5, { fatal: false })
3613
+ * ```
3614
+ *
3615
+ */
3616
+ fatal) {
3617
+ if (check)
3618
+ return ZodAny.create().superRefine((data, ctx) => {
3619
+ const r = check(data);
3620
+ if (r instanceof Promise) {
3621
+ return r.then((r) => {
3622
+ if (!r) {
3623
+ const params = cleanParams(_params, data);
3624
+ const _fatal = params.fatal ?? fatal ?? true;
3625
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
3626
+ }
3627
+ });
3628
+ }
3629
+ if (!r) {
3630
+ const params = cleanParams(_params, data);
3631
+ const _fatal = params.fatal ?? fatal ?? true;
3632
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
3633
+ }
3634
+ return;
3635
+ });
3636
+ return ZodAny.create();
3637
+ }
3638
+ exports.late = {
3639
+ object: ZodObject.lazycreate,
3640
+ };
3641
+ var ZodFirstPartyTypeKind;
3642
+ (function (ZodFirstPartyTypeKind) {
3643
+ ZodFirstPartyTypeKind["ZodString"] = "ZodString";
3644
+ ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
3645
+ ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
3646
+ ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
3647
+ ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
3648
+ ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
3649
+ ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
3650
+ ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
3651
+ ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
3652
+ ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
3653
+ ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
3654
+ ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
3655
+ ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
3656
+ ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
3657
+ ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
3658
+ ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
3659
+ ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3660
+ ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
3661
+ ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
3662
+ ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
3663
+ ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
3664
+ ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
3665
+ ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
3666
+ ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
3667
+ ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
3668
+ ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
3669
+ ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
3670
+ ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
3671
+ ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
3672
+ ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
3673
+ ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
3674
+ ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
3675
+ ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
3676
+ ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
3677
+ ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
3678
+ ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
3679
+ })(ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = ZodFirstPartyTypeKind = {}));
3680
+ // requires TS 4.4+
3681
+ class Class {
3682
+ constructor(..._) { }
3683
+ }
3684
+ const instanceOfType = (
3685
+ // const instanceOfType = <T extends new (...args: any[]) => any>(
3686
+ cls, params = {
3687
+ message: `Input not instance of ${cls.name}`,
3688
+ }) => custom((data) => data instanceof cls, params);
3689
+ exports.instanceof = instanceOfType;
3690
+ const stringType = ZodString.create;
3691
+ exports.string = stringType;
3692
+ const numberType = ZodNumber.create;
3693
+ exports.number = numberType;
3694
+ const nanType = ZodNaN.create;
3695
+ exports.nan = nanType;
3696
+ const bigIntType = ZodBigInt.create;
3697
+ exports.bigint = bigIntType;
3698
+ const booleanType = ZodBoolean.create;
3699
+ exports.boolean = booleanType;
3700
+ const dateType = ZodDate.create;
3701
+ exports.date = dateType;
3702
+ const symbolType = ZodSymbol.create;
3703
+ exports.symbol = symbolType;
3704
+ const undefinedType = ZodUndefined.create;
3705
+ exports.undefined = undefinedType;
3706
+ const nullType = ZodNull.create;
3707
+ exports.null = nullType;
3708
+ const anyType = ZodAny.create;
3709
+ exports.any = anyType;
3710
+ const unknownType = ZodUnknown.create;
3711
+ exports.unknown = unknownType;
3712
+ const neverType = ZodNever.create;
3713
+ exports.never = neverType;
3714
+ const voidType = ZodVoid.create;
3715
+ exports.void = voidType;
3716
+ const arrayType = ZodArray.create;
3717
+ exports.array = arrayType;
3718
+ const objectType = ZodObject.create;
3719
+ exports.object = objectType;
3720
+ const strictObjectType = ZodObject.strictCreate;
3721
+ exports.strictObject = strictObjectType;
3722
+ const unionType = ZodUnion.create;
3723
+ exports.union = unionType;
3724
+ const discriminatedUnionType = ZodDiscriminatedUnion.create;
3725
+ exports.discriminatedUnion = discriminatedUnionType;
3726
+ const intersectionType = ZodIntersection.create;
3727
+ exports.intersection = intersectionType;
3728
+ const tupleType = ZodTuple.create;
3729
+ exports.tuple = tupleType;
3730
+ const recordType = ZodRecord.create;
3731
+ exports.record = recordType;
3732
+ const mapType = ZodMap.create;
3733
+ exports.map = mapType;
3734
+ const setType = ZodSet.create;
3735
+ exports.set = setType;
3736
+ const functionType = ZodFunction.create;
3737
+ exports.function = functionType;
3738
+ const lazyType = ZodLazy.create;
3739
+ exports.lazy = lazyType;
3740
+ const literalType = ZodLiteral.create;
3741
+ exports.literal = literalType;
3742
+ const enumType = ZodEnum.create;
3743
+ exports.enum = enumType;
3744
+ const nativeEnumType = ZodNativeEnum.create;
3745
+ exports.nativeEnum = nativeEnumType;
3746
+ const promiseType = ZodPromise.create;
3747
+ exports.promise = promiseType;
3748
+ const effectsType = ZodEffects.create;
3749
+ exports.effect = effectsType;
3750
+ exports.transformer = effectsType;
3751
+ const optionalType = ZodOptional.create;
3752
+ exports.optional = optionalType;
3753
+ const nullableType = ZodNullable.create;
3754
+ exports.nullable = nullableType;
3755
+ const preprocessType = ZodEffects.createWithPreprocess;
3756
+ exports.preprocess = preprocessType;
3757
+ const pipelineType = ZodPipeline.create;
3758
+ exports.pipeline = pipelineType;
3759
+ const ostring = () => stringType().optional();
3760
+ exports.ostring = ostring;
3761
+ const onumber = () => numberType().optional();
3762
+ exports.onumber = onumber;
3763
+ const oboolean = () => booleanType().optional();
3764
+ exports.oboolean = oboolean;
3765
+ exports.coerce = {
3766
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
3767
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
3768
+ boolean: ((arg) => ZodBoolean.create({
3769
+ ...arg,
3770
+ coerce: true,
3771
+ })),
3772
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
3773
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
3774
+ };
3775
+ exports.NEVER = parseUtil_js_1.INVALID;