@watchguard-4331/agent 0.1.0

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