integrate-sdk 0.8.41-dev.0 → 0.8.42

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