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