@storybook/addon-mcp 0.0.1

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