@mastra/observability 1.0.0-beta.3 → 1.0.0-beta.5

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