@elizaos/plugin-telegram 1.0.0-alpha.44 → 1.0.0-alpha.46

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