@coursebuilder/adapter-drizzle 2.0.1-canary.cd34f124e → 2.1.0

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