@learncard/claimable-boosts-plugin 1.0.30

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