raindrop-ai 1.0.9 → 1.1.0

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