@sisense/mcp-server 0.2.1

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