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