@schoolai/shipyard 0.1.0-nightly.20260217

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