vessels 0.3.0 → 0.7.0

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