@btc-embedded/cdk-extensions 0.10.5 → 0.11.1

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