@sortipei/api-contracts 0.1.0

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