@coursebuilder/adapter-drizzle 0.0.7 → 0.1.1

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