@coursebuilder/adapter-drizzle 0.1.1 → 0.1.3

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