@coursebuilder/adapter-drizzle 0.0.3 → 0.0.5

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