ccusage 15.9.2 → 15.9.4

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.
@@ -6,40 +6,31 @@ var util;
6
6
  function assertNever(_x) {
7
7
  throw new Error();
8
8
  }
9
- util$1.assertNever = assertNever;
10
- util$1.arrayToEnum = (items) => {
9
+ util$1.assertNever = assertNever, util$1.arrayToEnum = (items) => {
11
10
  const obj = {};
12
11
  for (const item of items) obj[item] = item;
13
12
  return obj;
14
- };
15
- util$1.getValidEnumValues = (obj) => {
16
- const validKeys = util$1.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
17
- const filtered = {};
13
+ }, util$1.getValidEnumValues = (obj) => {
14
+ const validKeys = util$1.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number"), filtered = {};
18
15
  for (const k of validKeys) filtered[k] = obj[k];
19
16
  return util$1.objectValues(filtered);
20
- };
21
- util$1.objectValues = (obj) => {
17
+ }, util$1.objectValues = (obj) => {
22
18
  return util$1.objectKeys(obj).map(function(e) {
23
19
  return obj[e];
24
20
  });
25
- };
26
- util$1.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
21
+ }, util$1.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
27
22
  const keys = [];
28
23
  for (const key in object) if (Object.prototype.hasOwnProperty.call(object, key)) keys.push(key);
29
24
  return keys;
30
- };
31
- util$1.find = (arr, checker) => {
25
+ }, util$1.find = (arr, checker) => {
32
26
  for (const item of arr) if (checker(item)) return item;
33
27
  return void 0;
34
- };
35
- util$1.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
28
+ }, util$1.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
36
29
  function joinValues(array, separator = " | ") {
37
30
  return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
38
31
  }
39
- util$1.joinValues = joinValues;
40
- util$1.jsonStringifyReplacer = (_, value) => {
41
- if (typeof value === "bigint") return value.toString();
42
- return value;
32
+ util$1.joinValues = joinValues, util$1.jsonStringifyReplacer = (_, value) => {
33
+ return typeof value === "bigint" ? value.toString() : value;
43
34
  };
44
35
  })(util || (util = {}));
45
36
  var objectUtil;
@@ -72,8 +63,7 @@ const ZodParsedType = util.arrayToEnum([
72
63
  "never",
73
64
  "map",
74
65
  "set"
75
- ]);
76
- const getParsedType = (data) => {
66
+ ]), getParsedType = (data) => {
77
67
  const t = typeof data;
78
68
  switch (t) {
79
69
  case "undefined": return ZodParsedType.undefined;
@@ -83,18 +73,10 @@ const getParsedType = (data) => {
83
73
  case "function": return ZodParsedType.function;
84
74
  case "bigint": return ZodParsedType.bigint;
85
75
  case "symbol": return ZodParsedType.symbol;
86
- case "object":
87
- if (Array.isArray(data)) return ZodParsedType.array;
88
- if (data === null) return ZodParsedType.null;
89
- if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") return ZodParsedType.promise;
90
- if (typeof Map !== "undefined" && data instanceof Map) return ZodParsedType.map;
91
- if (typeof Set !== "undefined" && data instanceof Set) return ZodParsedType.set;
92
- if (typeof Date !== "undefined" && data instanceof Date) return ZodParsedType.date;
93
- return ZodParsedType.object;
76
+ case "object": return Array.isArray(data) ? ZodParsedType.array : data === null ? ZodParsedType.null : data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function" ? ZodParsedType.promise : typeof Map !== "undefined" && data instanceof Map ? ZodParsedType.map : typeof Set !== "undefined" && data instanceof Set ? ZodParsedType.set : typeof Date !== "undefined" && data instanceof Date ? ZodParsedType.date : ZodParsedType.object;
94
77
  default: return ZodParsedType.unknown;
95
78
  }
96
- };
97
- const ZodIssueCode = util.arrayToEnum([
79
+ }, ZodIssueCode = util.arrayToEnum([
98
80
  "invalid_type",
99
81
  "invalid_literal",
100
82
  "custom",
@@ -117,48 +99,35 @@ var ZodError = class ZodError extends Error {
117
99
  return this.issues;
118
100
  }
119
101
  constructor(issues) {
120
- super();
121
- this.issues = [];
122
- this.addIssue = (sub) => {
102
+ super(), this.issues = [], this.addIssue = (sub) => {
123
103
  this.issues = [...this.issues, sub];
124
- };
125
- this.addIssues = (subs = []) => {
104
+ }, this.addIssues = (subs = []) => {
126
105
  this.issues = [...this.issues, ...subs];
127
106
  };
128
107
  const actualProto = new.target.prototype;
129
108
  if (Object.setPrototypeOf) Object.setPrototypeOf(this, actualProto);
130
109
  else this.__proto__ = actualProto;
131
- this.name = "ZodError";
132
- this.issues = issues;
110
+ this.name = "ZodError", this.issues = issues;
133
111
  }
134
112
  format(_mapper) {
135
113
  const mapper = _mapper || function(issue) {
136
114
  return issue.message;
137
- };
138
- const fieldErrors = { _errors: [] };
139
- const processError = (error) => {
115
+ }, fieldErrors = { _errors: [] }, processError = (error) => {
140
116
  for (const issue of error.issues) if (issue.code === "invalid_union") issue.unionErrors.map(processError);
141
117
  else if (issue.code === "invalid_return_type") processError(issue.returnTypeError);
142
118
  else if (issue.code === "invalid_arguments") processError(issue.argumentsError);
143
119
  else if (issue.path.length === 0) fieldErrors._errors.push(mapper(issue));
144
120
  else {
145
- let curr = fieldErrors;
146
- let i = 0;
121
+ let curr = fieldErrors, i = 0;
147
122
  while (i < issue.path.length) {
148
- const el = issue.path[i];
149
- const terminal = i === issue.path.length - 1;
123
+ const el = issue.path[i], terminal = i === issue.path.length - 1;
150
124
  if (!terminal) curr[el] = curr[el] || { _errors: [] };
151
- else {
152
- curr[el] = curr[el] || { _errors: [] };
153
- curr[el]._errors.push(mapper(issue));
154
- }
155
- curr = curr[el];
156
- i++;
125
+ else curr[el] = curr[el] || { _errors: [] }, curr[el]._errors.push(mapper(issue));
126
+ curr = curr[el], i++;
157
127
  }
158
128
  }
159
129
  };
160
- processError(this);
161
- return fieldErrors;
130
+ return processError(this), fieldErrors;
162
131
  }
163
132
  static assert(value) {
164
133
  if (!(value instanceof ZodError)) throw new Error(`Not a ZodError: ${value}`);
@@ -173,12 +142,9 @@ var ZodError = class ZodError extends Error {
173
142
  return this.issues.length === 0;
174
143
  }
175
144
  flatten(mapper = (issue) => issue.message) {
176
- const fieldErrors = {};
177
- const formErrors = [];
178
- for (const sub of this.issues) if (sub.path.length > 0) {
179
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
180
- fieldErrors[sub.path[0]].push(mapper(sub));
181
- } else formErrors.push(mapper(sub));
145
+ const fieldErrors = {}, formErrors = [];
146
+ for (const sub of this.issues) if (sub.path.length > 0) fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [], fieldErrors[sub.path[0]].push(mapper(sub));
147
+ else formErrors.push(mapper(sub));
182
148
  return {
183
149
  formErrors,
184
150
  fieldErrors
@@ -225,8 +191,7 @@ const errorMap = (issue, _ctx) => {
225
191
  break;
226
192
  case ZodIssueCode.invalid_string:
227
193
  if (typeof issue.validation === "object") if ("includes" in issue.validation) {
228
- message = `Invalid input: must include "${issue.validation.includes}"`;
229
- if (typeof issue.validation.position === "number") message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
194
+ if (message = `Invalid input: must include "${issue.validation.includes}"`, typeof issue.validation.position === "number") message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
230
195
  } else if ("startsWith" in issue.validation) message = `Invalid input: must start with "${issue.validation.startsWith}"`;
231
196
  else if ("endsWith" in issue.validation) message = `Invalid input: must end with "${issue.validation.endsWith}"`;
232
197
  else util.assertNever(issue.validation);
@@ -260,9 +225,7 @@ const errorMap = (issue, _ctx) => {
260
225
  case ZodIssueCode.not_finite:
261
226
  message = "Number must be finite";
262
227
  break;
263
- default:
264
- message = _ctx.defaultError;
265
- util.assertNever(issue);
228
+ default: message = _ctx.defaultError, util.assertNever(issue);
266
229
  }
267
230
  return { message };
268
231
  };
@@ -272,9 +235,7 @@ function getErrorMap() {
272
235
  return overrideErrorMap;
273
236
  }
274
237
  const makeIssue = (params) => {
275
- const { data, path, errorMaps, issueData } = params;
276
- const fullPath = [...path, ...issueData.path || []];
277
- const fullIssue = {
238
+ const { data, path, errorMaps, issueData } = params, fullPath = [...path, ...issueData.path || []], fullIssue = {
278
239
  ...issueData,
279
240
  path: fullPath
280
241
  };
@@ -296,8 +257,7 @@ const makeIssue = (params) => {
296
257
  };
297
258
  };
298
259
  function addIssueToContext(ctx, issueData) {
299
- const overrideMap = getErrorMap();
300
- const issue = makeIssue({
260
+ const overrideMap = getErrorMap(), issue = makeIssue({
301
261
  issueData,
302
262
  data: ctx.data,
303
263
  path: ctx.path,
@@ -335,8 +295,7 @@ var ParseStatus = class ParseStatus {
335
295
  static async mergeObjectAsync(status, pairs) {
336
296
  const syncPairs = [];
337
297
  for (const pair of pairs) {
338
- const key = await pair.key;
339
- const value = await pair.value;
298
+ const key = await pair.key, value = await pair.value;
340
299
  syncPairs.push({
341
300
  key,
342
301
  value
@@ -348,8 +307,7 @@ var ParseStatus = class ParseStatus {
348
307
  const finalObject = {};
349
308
  for (const pair of pairs) {
350
309
  const { key, value } = pair;
351
- if (key.status === "aborted") return INVALID;
352
- if (value.status === "aborted") return INVALID;
310
+ if (key.status === "aborted" || value.status === "aborted") return INVALID;
353
311
  if (key.status === "dirty") status.dirty();
354
312
  if (value.status === "dirty") status.dirty();
355
313
  if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) finalObject[key.value] = value.value;
@@ -360,31 +318,20 @@ var ParseStatus = class ParseStatus {
360
318
  };
361
319
  }
362
320
  };
363
- const INVALID = Object.freeze({ status: "aborted" });
364
- const DIRTY = (value) => ({
321
+ const INVALID = Object.freeze({ status: "aborted" }), DIRTY = (value) => ({
365
322
  status: "dirty",
366
323
  value
367
- });
368
- const OK = (value) => ({
324
+ }), OK = (value) => ({
369
325
  status: "valid",
370
326
  value
371
- });
372
- const isAborted = (x) => x.status === "aborted";
373
- const isDirty = (x) => x.status === "dirty";
374
- const isValid = (x) => x.status === "valid";
375
- const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
327
+ }), isAborted = (x) => x.status === "aborted", isDirty = (x) => x.status === "dirty", isValid = (x) => x.status === "valid", isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
376
328
  var errorUtil;
377
329
  (function(errorUtil$1) {
378
- errorUtil$1.errToObj = (message) => typeof message === "string" ? { message } : message || {};
379
- errorUtil$1.toString = (message) => typeof message === "string" ? message : message?.message;
330
+ errorUtil$1.errToObj = (message) => typeof message === "string" ? { message } : message || {}, errorUtil$1.toString = (message) => typeof message === "string" ? message : message?.message;
380
331
  })(errorUtil || (errorUtil = {}));
381
332
  var ParseInputLazyPath = class {
382
333
  constructor(parent, value, path, key) {
383
- this._cachedPath = [];
384
- this.parent = parent;
385
- this.data = value;
386
- this._path = path;
387
- this._key = key;
334
+ this._cachedPath = [], this.parent = parent, this.data = value, this._path = path, this._key = key;
388
335
  }
389
336
  get path() {
390
337
  if (!this._cachedPath.length) if (Array.isArray(this._key)) this._cachedPath.push(...this._path, ...this._key);
@@ -397,18 +344,15 @@ const handleResult = (ctx, result) => {
397
344
  success: true,
398
345
  data: result.value
399
346
  };
400
- else {
401
- if (!ctx.common.issues.length) throw new Error("Validation failed but no issues detected.");
402
- return {
403
- success: false,
404
- get error() {
405
- if (this._error) return this._error;
406
- const error = new ZodError(ctx.common.issues);
407
- this._error = error;
408
- return this._error;
409
- }
410
- };
411
- }
347
+ if (!ctx.common.issues.length) throw new Error("Validation failed but no issues detected.");
348
+ return {
349
+ success: false,
350
+ get error() {
351
+ if (this._error) return this._error;
352
+ const error = new ZodError(ctx.common.issues);
353
+ return this._error = error, this._error;
354
+ }
355
+ };
412
356
  };
413
357
  function processCreateParams(params) {
414
358
  if (!params) return {};
@@ -420,10 +364,7 @@ function processCreateParams(params) {
420
364
  };
421
365
  const customMap = (iss, ctx) => {
422
366
  const { message } = params;
423
- if (iss.code === "invalid_enum_value") return { message: message ?? ctx.defaultError };
424
- if (typeof ctx.data === "undefined") return { message: message ?? required_error ?? ctx.defaultError };
425
- if (iss.code !== "invalid_type") return { message: ctx.defaultError };
426
- return { message: message ?? invalid_type_error ?? ctx.defaultError };
367
+ return iss.code === "invalid_enum_value" ? { message: message ?? ctx.defaultError } : typeof ctx.data === "undefined" ? { message: message ?? required_error ?? ctx.defaultError } : iss.code === "invalid_type" ? { message: message ?? invalid_type_error ?? ctx.defaultError } : { message: ctx.defaultError };
427
368
  };
428
369
  return {
429
370
  errorMap: customMap,
@@ -486,8 +427,7 @@ var ZodType = class {
486
427
  parent: null,
487
428
  data,
488
429
  parsedType: getParsedType(data)
489
- };
490
- const result = this._parseSync({
430
+ }, result = this._parseSync({
491
431
  data,
492
432
  path: ctx.path,
493
433
  parent: ctx
@@ -543,45 +483,30 @@ var ZodType = class {
543
483
  parent: null,
544
484
  data,
545
485
  parsedType: getParsedType(data)
546
- };
547
- const maybeAsyncResult = this._parse({
486
+ }, maybeAsyncResult = this._parse({
548
487
  data,
549
488
  path: ctx.path,
550
489
  parent: ctx
551
- });
552
- const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
490
+ }), result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
553
491
  return handleResult(ctx, result);
554
492
  }
555
493
  refine(check, message) {
556
494
  const getIssueProperties = (val) => {
557
- if (typeof message === "string" || typeof message === "undefined") return { message };
558
- else if (typeof message === "function") return message(val);
559
- else return message;
495
+ return typeof message === "string" || typeof message === "undefined" ? { message } : typeof message === "function" ? message(val) : message;
560
496
  };
561
497
  return this._refinement((val, ctx) => {
562
- const result = check(val);
563
- const setError = () => ctx.addIssue({
498
+ const result = check(val), setError = () => ctx.addIssue({
564
499
  code: ZodIssueCode.custom,
565
500
  ...getIssueProperties(val)
566
501
  });
567
- if (typeof Promise !== "undefined" && result instanceof Promise) return result.then((data) => {
568
- if (!data) {
569
- setError();
570
- return false;
571
- } else return true;
572
- });
573
- if (!result) {
574
- setError();
575
- return false;
576
- } else return true;
502
+ return typeof Promise !== "undefined" && result instanceof Promise ? result.then((data) => {
503
+ return data ? true : (setError(), false);
504
+ }) : result ? true : (setError(), false);
577
505
  });
578
506
  }
579
507
  refinement(check, refinementData) {
580
508
  return this._refinement((val, ctx) => {
581
- if (!check(val)) {
582
- ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
583
- return false;
584
- } else return true;
509
+ return check(val) ? true : (ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData), false);
585
510
  });
586
511
  }
587
512
  _refinement(refinement) {
@@ -598,34 +523,7 @@ var ZodType = class {
598
523
  return this._refinement(refinement);
599
524
  }
600
525
  constructor(def) {
601
- /** Alias of safeParseAsync */
602
- this.spa = this.safeParseAsync;
603
- this._def = def;
604
- this.parse = this.parse.bind(this);
605
- this.safeParse = this.safeParse.bind(this);
606
- this.parseAsync = this.parseAsync.bind(this);
607
- this.safeParseAsync = this.safeParseAsync.bind(this);
608
- this.spa = this.spa.bind(this);
609
- this.refine = this.refine.bind(this);
610
- this.refinement = this.refinement.bind(this);
611
- this.superRefine = this.superRefine.bind(this);
612
- this.optional = this.optional.bind(this);
613
- this.nullable = this.nullable.bind(this);
614
- this.nullish = this.nullish.bind(this);
615
- this.array = this.array.bind(this);
616
- this.promise = this.promise.bind(this);
617
- this.or = this.or.bind(this);
618
- this.and = this.and.bind(this);
619
- this.transform = this.transform.bind(this);
620
- this.brand = this.brand.bind(this);
621
- this.default = this.default.bind(this);
622
- this.catch = this.catch.bind(this);
623
- this.describe = this.describe.bind(this);
624
- this.pipe = this.pipe.bind(this);
625
- this.readonly = this.readonly.bind(this);
626
- this.isNullable = this.isNullable.bind(this);
627
- this.isOptional = this.isOptional.bind(this);
628
- this["~standard"] = {
526
+ this.spa = this.safeParseAsync, this._def = def, this.parse = this.parse.bind(this), this.safeParse = this.safeParse.bind(this), this.parseAsync = this.parseAsync.bind(this), this.safeParseAsync = this.safeParseAsync.bind(this), this.spa = this.spa.bind(this), this.refine = this.refine.bind(this), this.refinement = this.refinement.bind(this), this.superRefine = this.superRefine.bind(this), this.optional = this.optional.bind(this), this.nullable = this.nullable.bind(this), this.nullish = this.nullish.bind(this), this.array = this.array.bind(this), this.promise = this.promise.bind(this), this.or = this.or.bind(this), this.and = this.and.bind(this), this.transform = this.transform.bind(this), this.brand = this.brand.bind(this), this.default = this.default.bind(this), this.catch = this.catch.bind(this), this.describe = this.describe.bind(this), this.pipe = this.pipe.bind(this), this.readonly = this.readonly.bind(this), this.isNullable = this.isNullable.bind(this), this.isOptional = this.isOptional.bind(this), this["~standard"] = {
629
527
  version: 1,
630
528
  vendor: "zod",
631
529
  validate: (data) => this["~validate"](data)
@@ -708,24 +606,9 @@ var ZodType = class {
708
606
  return this.safeParse(null).success;
709
607
  }
710
608
  };
711
- const cuidRegex = /^c[^\s-]{8,}$/i;
712
- const cuid2Regex = /^[0-9a-z]+$/;
713
- const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
714
- const 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;
715
- const nanoidRegex = /^[a-z0-9_-]{21}$/i;
716
- const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
717
- const 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)?)??$/;
718
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
719
- const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
609
+ const cuidRegex = /^c[^\s-]{8,}$/i, cuid2Regex = /^[0-9a-z]+$/, ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i, 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, nanoidRegex = /^[a-z0-9_-]{21}$/i, jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/, 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)?)??$/, emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i, _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
720
610
  let emojiRegex;
721
- const 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])$/;
722
- const 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])$/;
723
- const 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]))$/;
724
- const 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])$/;
725
- const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
726
- const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
727
- const 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])))`;
728
- const dateRegex = new RegExp(`^${dateRegexSource}$`);
611
+ const 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])$/, 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])$/, 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]))$/, 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])$/, base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/, 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])))`, dateRegex = /* @__PURE__ */ new RegExp(`^${dateRegexSource}$`);
729
612
  function timeRegexSource(args) {
730
613
  let secondsRegexSource = `[0-5]\\d`;
731
614
  if (args.precision) secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
@@ -734,40 +617,28 @@ function timeRegexSource(args) {
734
617
  return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
735
618
  }
736
619
  function timeRegex(args) {
737
- return new RegExp(`^${timeRegexSource(args)}$`);
620
+ return /* @__PURE__ */ new RegExp(`^${timeRegexSource(args)}$`);
738
621
  }
739
622
  function datetimeRegex(args) {
740
623
  let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
741
624
  const opts = [];
742
- opts.push(args.local ? `Z?` : `Z`);
743
- if (args.offset) opts.push(`([+-]\\d{2}:?\\d{2})`);
744
- regex = `${regex}(${opts.join("|")})`;
745
- return new RegExp(`^${regex}$`);
625
+ if (opts.push(args.local ? `Z?` : `Z`), args.offset) opts.push(`([+-]\\d{2}:?\\d{2})`);
626
+ return regex = `${regex}(${opts.join("|")})`, /* @__PURE__ */ new RegExp(`^${regex}$`);
746
627
  }
747
628
  function isValidIP(ip, version) {
748
- if ((version === "v4" || !version) && ipv4Regex.test(ip)) return true;
749
- if ((version === "v6" || !version) && ipv6Regex.test(ip)) return true;
750
- return false;
629
+ return !!((version === "v4" || !version) && ipv4Regex.test(ip) || (version === "v6" || !version) && ipv6Regex.test(ip));
751
630
  }
752
631
  function isValidJWT(jwt, alg) {
753
632
  if (!jwtRegex.test(jwt)) return false;
754
633
  try {
755
- const [header] = jwt.split(".");
756
- const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
757
- const decoded = JSON.parse(atob(base64));
758
- if (typeof decoded !== "object" || decoded === null) return false;
759
- if ("typ" in decoded && decoded?.typ !== "JWT") return false;
760
- if (!decoded.alg) return false;
761
- if (alg && decoded.alg !== alg) return false;
762
- return true;
634
+ const [header] = jwt.split("."), base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "="), decoded = JSON.parse(atob(base64));
635
+ return !(typeof decoded !== "object" || decoded === null || "typ" in decoded && decoded?.typ !== "JWT" || !decoded.alg || alg && decoded.alg !== alg);
763
636
  } catch {
764
637
  return false;
765
638
  }
766
639
  }
767
640
  function isValidCidr(ip, version) {
768
- if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) return true;
769
- if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) return true;
770
- return false;
641
+ return !!((version === "v4" || !version) && ipv4CidrRegex.test(ip) || (version === "v6" || !version) && ipv6CidrRegex.test(ip));
771
642
  }
772
643
  var ZodString = class ZodString extends ZodType {
773
644
  _parse(input) {
@@ -775,47 +646,36 @@ var ZodString = class ZodString extends ZodType {
775
646
  const parsedType = this._getType(input);
776
647
  if (parsedType !== ZodParsedType.string) {
777
648
  const ctx$1 = this._getOrReturnCtx(input);
778
- addIssueToContext(ctx$1, {
649
+ return addIssueToContext(ctx$1, {
779
650
  code: ZodIssueCode.invalid_type,
780
651
  expected: ZodParsedType.string,
781
652
  received: ctx$1.parsedType
782
- });
783
- return INVALID;
653
+ }), INVALID;
784
654
  }
785
655
  const status = new ParseStatus();
786
656
  let ctx = void 0;
787
657
  for (const check of this._def.checks) if (check.kind === "min") {
788
- if (input.data.length < check.value) {
789
- ctx = this._getOrReturnCtx(input, ctx);
790
- addIssueToContext(ctx, {
791
- code: ZodIssueCode.too_small,
792
- minimum: check.value,
793
- type: "string",
794
- inclusive: true,
795
- exact: false,
796
- message: check.message
797
- });
798
- status.dirty();
799
- }
658
+ if (input.data.length < check.value) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
659
+ code: ZodIssueCode.too_small,
660
+ minimum: check.value,
661
+ type: "string",
662
+ inclusive: true,
663
+ exact: false,
664
+ message: check.message
665
+ }), status.dirty();
800
666
  } else if (check.kind === "max") {
801
- if (input.data.length > check.value) {
802
- ctx = this._getOrReturnCtx(input, ctx);
803
- addIssueToContext(ctx, {
804
- code: ZodIssueCode.too_big,
805
- maximum: check.value,
806
- type: "string",
807
- inclusive: true,
808
- exact: false,
809
- message: check.message
810
- });
811
- status.dirty();
812
- }
667
+ if (input.data.length > check.value) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
668
+ code: ZodIssueCode.too_big,
669
+ maximum: check.value,
670
+ type: "string",
671
+ inclusive: true,
672
+ exact: false,
673
+ message: check.message
674
+ }), status.dirty();
813
675
  } else if (check.kind === "length") {
814
- const tooBig = input.data.length > check.value;
815
- const tooSmall = input.data.length < check.value;
676
+ const tooBig = input.data.length > check.value, tooSmall = input.data.length < check.value;
816
677
  if (tooBig || tooSmall) {
817
- ctx = this._getOrReturnCtx(input, ctx);
818
- if (tooBig) addIssueToContext(ctx, {
678
+ if (ctx = this._getOrReturnCtx(input, ctx), tooBig) addIssueToContext(ctx, {
819
679
  code: ZodIssueCode.too_big,
820
680
  maximum: check.value,
821
681
  type: "string",
@@ -834,228 +694,146 @@ var ZodString = class ZodString extends ZodType {
834
694
  status.dirty();
835
695
  }
836
696
  } else if (check.kind === "email") {
837
- if (!emailRegex.test(input.data)) {
838
- ctx = this._getOrReturnCtx(input, ctx);
839
- addIssueToContext(ctx, {
840
- validation: "email",
841
- code: ZodIssueCode.invalid_string,
842
- message: check.message
843
- });
844
- status.dirty();
845
- }
697
+ if (!emailRegex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
698
+ validation: "email",
699
+ code: ZodIssueCode.invalid_string,
700
+ message: check.message
701
+ }), status.dirty();
846
702
  } else if (check.kind === "emoji") {
847
703
  if (!emojiRegex) emojiRegex = new RegExp(_emojiRegex, "u");
848
- if (!emojiRegex.test(input.data)) {
849
- ctx = this._getOrReturnCtx(input, ctx);
850
- addIssueToContext(ctx, {
851
- validation: "emoji",
852
- code: ZodIssueCode.invalid_string,
853
- message: check.message
854
- });
855
- status.dirty();
856
- }
704
+ if (!emojiRegex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
705
+ validation: "emoji",
706
+ code: ZodIssueCode.invalid_string,
707
+ message: check.message
708
+ }), status.dirty();
857
709
  } else if (check.kind === "uuid") {
858
- if (!uuidRegex.test(input.data)) {
859
- ctx = this._getOrReturnCtx(input, ctx);
860
- addIssueToContext(ctx, {
861
- validation: "uuid",
862
- code: ZodIssueCode.invalid_string,
863
- message: check.message
864
- });
865
- status.dirty();
866
- }
710
+ if (!uuidRegex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
711
+ validation: "uuid",
712
+ code: ZodIssueCode.invalid_string,
713
+ message: check.message
714
+ }), status.dirty();
867
715
  } else if (check.kind === "nanoid") {
868
- if (!nanoidRegex.test(input.data)) {
869
- ctx = this._getOrReturnCtx(input, ctx);
870
- addIssueToContext(ctx, {
871
- validation: "nanoid",
872
- code: ZodIssueCode.invalid_string,
873
- message: check.message
874
- });
875
- status.dirty();
876
- }
716
+ if (!nanoidRegex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
717
+ validation: "nanoid",
718
+ code: ZodIssueCode.invalid_string,
719
+ message: check.message
720
+ }), status.dirty();
877
721
  } else if (check.kind === "cuid") {
878
- if (!cuidRegex.test(input.data)) {
879
- ctx = this._getOrReturnCtx(input, ctx);
880
- addIssueToContext(ctx, {
881
- validation: "cuid",
882
- code: ZodIssueCode.invalid_string,
883
- message: check.message
884
- });
885
- status.dirty();
886
- }
722
+ if (!cuidRegex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
723
+ validation: "cuid",
724
+ code: ZodIssueCode.invalid_string,
725
+ message: check.message
726
+ }), status.dirty();
887
727
  } else if (check.kind === "cuid2") {
888
- if (!cuid2Regex.test(input.data)) {
889
- ctx = this._getOrReturnCtx(input, ctx);
890
- addIssueToContext(ctx, {
891
- validation: "cuid2",
892
- code: ZodIssueCode.invalid_string,
893
- message: check.message
894
- });
895
- status.dirty();
896
- }
728
+ if (!cuid2Regex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
729
+ validation: "cuid2",
730
+ code: ZodIssueCode.invalid_string,
731
+ message: check.message
732
+ }), status.dirty();
897
733
  } else if (check.kind === "ulid") {
898
- if (!ulidRegex.test(input.data)) {
899
- ctx = this._getOrReturnCtx(input, ctx);
900
- addIssueToContext(ctx, {
901
- validation: "ulid",
902
- code: ZodIssueCode.invalid_string,
903
- message: check.message
904
- });
905
- status.dirty();
906
- }
734
+ if (!ulidRegex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
735
+ validation: "ulid",
736
+ code: ZodIssueCode.invalid_string,
737
+ message: check.message
738
+ }), status.dirty();
907
739
  } else if (check.kind === "url") try {
908
740
  new URL(input.data);
909
741
  } catch {
910
- ctx = this._getOrReturnCtx(input, ctx);
911
- addIssueToContext(ctx, {
742
+ ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
912
743
  validation: "url",
913
744
  code: ZodIssueCode.invalid_string,
914
745
  message: check.message
915
- });
916
- status.dirty();
746
+ }), status.dirty();
917
747
  }
918
748
  else if (check.kind === "regex") {
919
749
  check.regex.lastIndex = 0;
920
750
  const testResult = check.regex.test(input.data);
921
- if (!testResult) {
922
- ctx = this._getOrReturnCtx(input, ctx);
923
- addIssueToContext(ctx, {
924
- validation: "regex",
925
- code: ZodIssueCode.invalid_string,
926
- message: check.message
927
- });
928
- status.dirty();
929
- }
751
+ if (!testResult) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
752
+ validation: "regex",
753
+ code: ZodIssueCode.invalid_string,
754
+ message: check.message
755
+ }), status.dirty();
930
756
  } else if (check.kind === "trim") input.data = input.data.trim();
931
757
  else if (check.kind === "includes") {
932
- if (!input.data.includes(check.value, check.position)) {
933
- ctx = this._getOrReturnCtx(input, ctx);
934
- addIssueToContext(ctx, {
935
- code: ZodIssueCode.invalid_string,
936
- validation: {
937
- includes: check.value,
938
- position: check.position
939
- },
940
- message: check.message
941
- });
942
- status.dirty();
943
- }
758
+ if (!input.data.includes(check.value, check.position)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
759
+ code: ZodIssueCode.invalid_string,
760
+ validation: {
761
+ includes: check.value,
762
+ position: check.position
763
+ },
764
+ message: check.message
765
+ }), status.dirty();
944
766
  } else if (check.kind === "toLowerCase") input.data = input.data.toLowerCase();
945
767
  else if (check.kind === "toUpperCase") input.data = input.data.toUpperCase();
946
768
  else if (check.kind === "startsWith") {
947
- if (!input.data.startsWith(check.value)) {
948
- ctx = this._getOrReturnCtx(input, ctx);
949
- addIssueToContext(ctx, {
950
- code: ZodIssueCode.invalid_string,
951
- validation: { startsWith: check.value },
952
- message: check.message
953
- });
954
- status.dirty();
955
- }
769
+ if (!input.data.startsWith(check.value)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
770
+ code: ZodIssueCode.invalid_string,
771
+ validation: { startsWith: check.value },
772
+ message: check.message
773
+ }), status.dirty();
956
774
  } else if (check.kind === "endsWith") {
957
- if (!input.data.endsWith(check.value)) {
958
- ctx = this._getOrReturnCtx(input, ctx);
959
- addIssueToContext(ctx, {
960
- code: ZodIssueCode.invalid_string,
961
- validation: { endsWith: check.value },
962
- message: check.message
963
- });
964
- status.dirty();
965
- }
775
+ if (!input.data.endsWith(check.value)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
776
+ code: ZodIssueCode.invalid_string,
777
+ validation: { endsWith: check.value },
778
+ message: check.message
779
+ }), status.dirty();
966
780
  } else if (check.kind === "datetime") {
967
781
  const regex = datetimeRegex(check);
968
- if (!regex.test(input.data)) {
969
- ctx = this._getOrReturnCtx(input, ctx);
970
- addIssueToContext(ctx, {
971
- code: ZodIssueCode.invalid_string,
972
- validation: "datetime",
973
- message: check.message
974
- });
975
- status.dirty();
976
- }
782
+ if (!regex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
783
+ code: ZodIssueCode.invalid_string,
784
+ validation: "datetime",
785
+ message: check.message
786
+ }), status.dirty();
977
787
  } else if (check.kind === "date") {
978
788
  const regex = dateRegex;
979
- if (!regex.test(input.data)) {
980
- ctx = this._getOrReturnCtx(input, ctx);
981
- addIssueToContext(ctx, {
982
- code: ZodIssueCode.invalid_string,
983
- validation: "date",
984
- message: check.message
985
- });
986
- status.dirty();
987
- }
789
+ if (!regex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
790
+ code: ZodIssueCode.invalid_string,
791
+ validation: "date",
792
+ message: check.message
793
+ }), status.dirty();
988
794
  } else if (check.kind === "time") {
989
795
  const regex = timeRegex(check);
990
- if (!regex.test(input.data)) {
991
- ctx = this._getOrReturnCtx(input, ctx);
992
- addIssueToContext(ctx, {
993
- code: ZodIssueCode.invalid_string,
994
- validation: "time",
995
- message: check.message
996
- });
997
- status.dirty();
998
- }
796
+ if (!regex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
797
+ code: ZodIssueCode.invalid_string,
798
+ validation: "time",
799
+ message: check.message
800
+ }), status.dirty();
999
801
  } else if (check.kind === "duration") {
1000
- if (!durationRegex.test(input.data)) {
1001
- ctx = this._getOrReturnCtx(input, ctx);
1002
- addIssueToContext(ctx, {
1003
- validation: "duration",
1004
- code: ZodIssueCode.invalid_string,
1005
- message: check.message
1006
- });
1007
- status.dirty();
1008
- }
802
+ if (!durationRegex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
803
+ validation: "duration",
804
+ code: ZodIssueCode.invalid_string,
805
+ message: check.message
806
+ }), status.dirty();
1009
807
  } else if (check.kind === "ip") {
1010
- if (!isValidIP(input.data, check.version)) {
1011
- ctx = this._getOrReturnCtx(input, ctx);
1012
- addIssueToContext(ctx, {
1013
- validation: "ip",
1014
- code: ZodIssueCode.invalid_string,
1015
- message: check.message
1016
- });
1017
- status.dirty();
1018
- }
808
+ if (!isValidIP(input.data, check.version)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
809
+ validation: "ip",
810
+ code: ZodIssueCode.invalid_string,
811
+ message: check.message
812
+ }), status.dirty();
1019
813
  } else if (check.kind === "jwt") {
1020
- if (!isValidJWT(input.data, check.alg)) {
1021
- ctx = this._getOrReturnCtx(input, ctx);
1022
- addIssueToContext(ctx, {
1023
- validation: "jwt",
1024
- code: ZodIssueCode.invalid_string,
1025
- message: check.message
1026
- });
1027
- status.dirty();
1028
- }
814
+ if (!isValidJWT(input.data, check.alg)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
815
+ validation: "jwt",
816
+ code: ZodIssueCode.invalid_string,
817
+ message: check.message
818
+ }), status.dirty();
1029
819
  } else if (check.kind === "cidr") {
1030
- if (!isValidCidr(input.data, check.version)) {
1031
- ctx = this._getOrReturnCtx(input, ctx);
1032
- addIssueToContext(ctx, {
1033
- validation: "cidr",
1034
- code: ZodIssueCode.invalid_string,
1035
- message: check.message
1036
- });
1037
- status.dirty();
1038
- }
820
+ if (!isValidCidr(input.data, check.version)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
821
+ validation: "cidr",
822
+ code: ZodIssueCode.invalid_string,
823
+ message: check.message
824
+ }), status.dirty();
1039
825
  } else if (check.kind === "base64") {
1040
- if (!base64Regex.test(input.data)) {
1041
- ctx = this._getOrReturnCtx(input, ctx);
1042
- addIssueToContext(ctx, {
1043
- validation: "base64",
1044
- code: ZodIssueCode.invalid_string,
1045
- message: check.message
1046
- });
1047
- status.dirty();
1048
- }
826
+ if (!base64Regex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
827
+ validation: "base64",
828
+ code: ZodIssueCode.invalid_string,
829
+ message: check.message
830
+ }), status.dirty();
1049
831
  } else if (check.kind === "base64url") {
1050
- if (!base64urlRegex.test(input.data)) {
1051
- ctx = this._getOrReturnCtx(input, ctx);
1052
- addIssueToContext(ctx, {
1053
- validation: "base64url",
1054
- code: ZodIssueCode.invalid_string,
1055
- message: check.message
1056
- });
1057
- status.dirty();
1058
- }
832
+ if (!base64urlRegex.test(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
833
+ validation: "base64url",
834
+ code: ZodIssueCode.invalid_string,
835
+ message: check.message
836
+ }), status.dirty();
1059
837
  } else util.assertNever(check);
1060
838
  return {
1061
839
  status: status.value,
@@ -1154,14 +932,13 @@ var ZodString = class ZodString extends ZodType {
1154
932
  });
1155
933
  }
1156
934
  datetime(options) {
1157
- if (typeof options === "string") return this._addCheck({
935
+ return typeof options === "string" ? this._addCheck({
1158
936
  kind: "datetime",
1159
937
  precision: null,
1160
938
  offset: false,
1161
939
  local: false,
1162
940
  message: options
1163
- });
1164
- return this._addCheck({
941
+ }) : this._addCheck({
1165
942
  kind: "datetime",
1166
943
  precision: typeof options?.precision === "undefined" ? null : options?.precision,
1167
944
  offset: options?.offset ?? false,
@@ -1176,12 +953,11 @@ var ZodString = class ZodString extends ZodType {
1176
953
  });
1177
954
  }
1178
955
  time(options) {
1179
- if (typeof options === "string") return this._addCheck({
956
+ return typeof options === "string" ? this._addCheck({
1180
957
  kind: "time",
1181
958
  precision: null,
1182
959
  message: options
1183
- });
1184
- return this._addCheck({
960
+ }) : this._addCheck({
1185
961
  kind: "time",
1186
962
  precision: typeof options?.precision === "undefined" ? null : options?.precision,
1187
963
  ...errorUtil.errToObj(options?.message)
@@ -1243,9 +1019,6 @@ var ZodString = class ZodString extends ZodType {
1243
1019
  ...errorUtil.errToObj(message)
1244
1020
  });
1245
1021
  }
1246
- /**
1247
- * Equivalent to `.min(1)`
1248
- */
1249
1022
  nonempty(message) {
1250
1023
  return this.min(1, errorUtil.errToObj(message));
1251
1024
  }
@@ -1339,92 +1112,64 @@ ZodString.create = (params) => {
1339
1112
  });
1340
1113
  };
1341
1114
  function floatSafeRemainder(val, step) {
1342
- const valDecCount = (val.toString().split(".")[1] || "").length;
1343
- const stepDecCount = (step.toString().split(".")[1] || "").length;
1344
- const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1345
- const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1346
- const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1115
+ const valDecCount = (val.toString().split(".")[1] || "").length, stepDecCount = (step.toString().split(".")[1] || "").length, decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount, valInt = Number.parseInt(val.toFixed(decCount).replace(".", "")), stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1347
1116
  return valInt % stepInt / 10 ** decCount;
1348
1117
  }
1349
1118
  var ZodNumber = class ZodNumber extends ZodType {
1350
1119
  constructor() {
1351
- super(...arguments);
1352
- this.min = this.gte;
1353
- this.max = this.lte;
1354
- this.step = this.multipleOf;
1120
+ super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf;
1355
1121
  }
1356
1122
  _parse(input) {
1357
1123
  if (this._def.coerce) input.data = Number(input.data);
1358
1124
  const parsedType = this._getType(input);
1359
1125
  if (parsedType !== ZodParsedType.number) {
1360
1126
  const ctx$1 = this._getOrReturnCtx(input);
1361
- addIssueToContext(ctx$1, {
1127
+ return addIssueToContext(ctx$1, {
1362
1128
  code: ZodIssueCode.invalid_type,
1363
1129
  expected: ZodParsedType.number,
1364
1130
  received: ctx$1.parsedType
1365
- });
1366
- return INVALID;
1131
+ }), INVALID;
1367
1132
  }
1368
1133
  let ctx = void 0;
1369
1134
  const status = new ParseStatus();
1370
1135
  for (const check of this._def.checks) if (check.kind === "int") {
1371
- if (!util.isInteger(input.data)) {
1372
- ctx = this._getOrReturnCtx(input, ctx);
1373
- addIssueToContext(ctx, {
1374
- code: ZodIssueCode.invalid_type,
1375
- expected: "integer",
1376
- received: "float",
1377
- message: check.message
1378
- });
1379
- status.dirty();
1380
- }
1136
+ if (!util.isInteger(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
1137
+ code: ZodIssueCode.invalid_type,
1138
+ expected: "integer",
1139
+ received: "float",
1140
+ message: check.message
1141
+ }), status.dirty();
1381
1142
  } else if (check.kind === "min") {
1382
1143
  const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1383
- if (tooSmall) {
1384
- ctx = this._getOrReturnCtx(input, ctx);
1385
- addIssueToContext(ctx, {
1386
- code: ZodIssueCode.too_small,
1387
- minimum: check.value,
1388
- type: "number",
1389
- inclusive: check.inclusive,
1390
- exact: false,
1391
- message: check.message
1392
- });
1393
- status.dirty();
1394
- }
1144
+ if (tooSmall) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
1145
+ code: ZodIssueCode.too_small,
1146
+ minimum: check.value,
1147
+ type: "number",
1148
+ inclusive: check.inclusive,
1149
+ exact: false,
1150
+ message: check.message
1151
+ }), status.dirty();
1395
1152
  } else if (check.kind === "max") {
1396
1153
  const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1397
- if (tooBig) {
1398
- ctx = this._getOrReturnCtx(input, ctx);
1399
- addIssueToContext(ctx, {
1400
- code: ZodIssueCode.too_big,
1401
- maximum: check.value,
1402
- type: "number",
1403
- inclusive: check.inclusive,
1404
- exact: false,
1405
- message: check.message
1406
- });
1407
- status.dirty();
1408
- }
1154
+ if (tooBig) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
1155
+ code: ZodIssueCode.too_big,
1156
+ maximum: check.value,
1157
+ type: "number",
1158
+ inclusive: check.inclusive,
1159
+ exact: false,
1160
+ message: check.message
1161
+ }), status.dirty();
1409
1162
  } else if (check.kind === "multipleOf") {
1410
- if (floatSafeRemainder(input.data, check.value) !== 0) {
1411
- ctx = this._getOrReturnCtx(input, ctx);
1412
- addIssueToContext(ctx, {
1413
- code: ZodIssueCode.not_multiple_of,
1414
- multipleOf: check.value,
1415
- message: check.message
1416
- });
1417
- status.dirty();
1418
- }
1163
+ if (floatSafeRemainder(input.data, check.value) !== 0) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
1164
+ code: ZodIssueCode.not_multiple_of,
1165
+ multipleOf: check.value,
1166
+ message: check.message
1167
+ }), status.dirty();
1419
1168
  } else if (check.kind === "finite") {
1420
- if (!Number.isFinite(input.data)) {
1421
- ctx = this._getOrReturnCtx(input, ctx);
1422
- addIssueToContext(ctx, {
1423
- code: ZodIssueCode.not_finite,
1424
- message: check.message
1425
- });
1426
- status.dirty();
1427
- }
1169
+ if (!Number.isFinite(input.data)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
1170
+ code: ZodIssueCode.not_finite,
1171
+ message: check.message
1172
+ }), status.dirty();
1428
1173
  } else util.assertNever(check);
1429
1174
  return {
1430
1175
  status: status.value,
@@ -1542,8 +1287,7 @@ var ZodNumber = class ZodNumber extends ZodType {
1542
1287
  return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
1543
1288
  }
1544
1289
  get isFinite() {
1545
- let max = null;
1546
- let min = null;
1290
+ let max = null, min = null;
1547
1291
  for (const ch of this._def.checks) if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") return true;
1548
1292
  else if (ch.kind === "min") {
1549
1293
  if (min === null || ch.value > min) min = ch.value;
@@ -1563,9 +1307,7 @@ ZodNumber.create = (params) => {
1563
1307
  };
1564
1308
  var ZodBigInt = class ZodBigInt extends ZodType {
1565
1309
  constructor() {
1566
- super(...arguments);
1567
- this.min = this.gte;
1568
- this.max = this.lte;
1310
+ super(...arguments), this.min = this.gte, this.max = this.lte;
1569
1311
  }
1570
1312
  _parse(input) {
1571
1313
  if (this._def.coerce) try {
@@ -1579,40 +1321,28 @@ var ZodBigInt = class ZodBigInt extends ZodType {
1579
1321
  const status = new ParseStatus();
1580
1322
  for (const check of this._def.checks) if (check.kind === "min") {
1581
1323
  const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1582
- if (tooSmall) {
1583
- ctx = this._getOrReturnCtx(input, ctx);
1584
- addIssueToContext(ctx, {
1585
- code: ZodIssueCode.too_small,
1586
- type: "bigint",
1587
- minimum: check.value,
1588
- inclusive: check.inclusive,
1589
- message: check.message
1590
- });
1591
- status.dirty();
1592
- }
1324
+ if (tooSmall) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
1325
+ code: ZodIssueCode.too_small,
1326
+ type: "bigint",
1327
+ minimum: check.value,
1328
+ inclusive: check.inclusive,
1329
+ message: check.message
1330
+ }), status.dirty();
1593
1331
  } else if (check.kind === "max") {
1594
1332
  const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1595
- if (tooBig) {
1596
- ctx = this._getOrReturnCtx(input, ctx);
1597
- addIssueToContext(ctx, {
1598
- code: ZodIssueCode.too_big,
1599
- type: "bigint",
1600
- maximum: check.value,
1601
- inclusive: check.inclusive,
1602
- message: check.message
1603
- });
1604
- status.dirty();
1605
- }
1333
+ if (tooBig) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
1334
+ code: ZodIssueCode.too_big,
1335
+ type: "bigint",
1336
+ maximum: check.value,
1337
+ inclusive: check.inclusive,
1338
+ message: check.message
1339
+ }), status.dirty();
1606
1340
  } else if (check.kind === "multipleOf") {
1607
- if (input.data % check.value !== BigInt(0)) {
1608
- ctx = this._getOrReturnCtx(input, ctx);
1609
- addIssueToContext(ctx, {
1610
- code: ZodIssueCode.not_multiple_of,
1611
- multipleOf: check.value,
1612
- message: check.message
1613
- });
1614
- status.dirty();
1615
- }
1341
+ if (input.data % check.value !== BigInt(0)) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
1342
+ code: ZodIssueCode.not_multiple_of,
1343
+ multipleOf: check.value,
1344
+ message: check.message
1345
+ }), status.dirty();
1616
1346
  } else util.assertNever(check);
1617
1347
  return {
1618
1348
  status: status.value,
@@ -1621,12 +1351,11 @@ var ZodBigInt = class ZodBigInt extends ZodType {
1621
1351
  }
1622
1352
  _getInvalidInput(input) {
1623
1353
  const ctx = this._getOrReturnCtx(input);
1624
- addIssueToContext(ctx, {
1354
+ return addIssueToContext(ctx, {
1625
1355
  code: ZodIssueCode.invalid_type,
1626
1356
  expected: ZodParsedType.bigint,
1627
1357
  received: ctx.parsedType
1628
- });
1629
- return INVALID;
1358
+ }), INVALID;
1630
1359
  }
1631
1360
  gte(value, message) {
1632
1361
  return this.setLimit("min", value, true, errorUtil.toString(message));
@@ -1725,12 +1454,11 @@ var ZodBoolean = class extends ZodType {
1725
1454
  const parsedType = this._getType(input);
1726
1455
  if (parsedType !== ZodParsedType.boolean) {
1727
1456
  const ctx = this._getOrReturnCtx(input);
1728
- addIssueToContext(ctx, {
1457
+ return addIssueToContext(ctx, {
1729
1458
  code: ZodIssueCode.invalid_type,
1730
1459
  expected: ZodParsedType.boolean,
1731
1460
  received: ctx.parsedType
1732
- });
1733
- return INVALID;
1461
+ }), INVALID;
1734
1462
  }
1735
1463
  return OK(input.data);
1736
1464
  }
@@ -1748,46 +1476,36 @@ var ZodDate = class ZodDate extends ZodType {
1748
1476
  const parsedType = this._getType(input);
1749
1477
  if (parsedType !== ZodParsedType.date) {
1750
1478
  const ctx$1 = this._getOrReturnCtx(input);
1751
- addIssueToContext(ctx$1, {
1479
+ return addIssueToContext(ctx$1, {
1752
1480
  code: ZodIssueCode.invalid_type,
1753
1481
  expected: ZodParsedType.date,
1754
1482
  received: ctx$1.parsedType
1755
- });
1756
- return INVALID;
1483
+ }), INVALID;
1757
1484
  }
1758
1485
  if (Number.isNaN(input.data.getTime())) {
1759
1486
  const ctx$1 = this._getOrReturnCtx(input);
1760
- addIssueToContext(ctx$1, { code: ZodIssueCode.invalid_date });
1761
- return INVALID;
1487
+ return addIssueToContext(ctx$1, { code: ZodIssueCode.invalid_date }), INVALID;
1762
1488
  }
1763
1489
  const status = new ParseStatus();
1764
1490
  let ctx = void 0;
1765
1491
  for (const check of this._def.checks) if (check.kind === "min") {
1766
- if (input.data.getTime() < check.value) {
1767
- ctx = this._getOrReturnCtx(input, ctx);
1768
- addIssueToContext(ctx, {
1769
- code: ZodIssueCode.too_small,
1770
- message: check.message,
1771
- inclusive: true,
1772
- exact: false,
1773
- minimum: check.value,
1774
- type: "date"
1775
- });
1776
- status.dirty();
1777
- }
1492
+ if (input.data.getTime() < check.value) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
1493
+ code: ZodIssueCode.too_small,
1494
+ message: check.message,
1495
+ inclusive: true,
1496
+ exact: false,
1497
+ minimum: check.value,
1498
+ type: "date"
1499
+ }), status.dirty();
1778
1500
  } else if (check.kind === "max") {
1779
- if (input.data.getTime() > check.value) {
1780
- ctx = this._getOrReturnCtx(input, ctx);
1781
- addIssueToContext(ctx, {
1782
- code: ZodIssueCode.too_big,
1783
- message: check.message,
1784
- inclusive: true,
1785
- exact: false,
1786
- maximum: check.value,
1787
- type: "date"
1788
- });
1789
- status.dirty();
1790
- }
1501
+ if (input.data.getTime() > check.value) ctx = this._getOrReturnCtx(input, ctx), addIssueToContext(ctx, {
1502
+ code: ZodIssueCode.too_big,
1503
+ message: check.message,
1504
+ inclusive: true,
1505
+ exact: false,
1506
+ maximum: check.value,
1507
+ type: "date"
1508
+ }), status.dirty();
1791
1509
  } else util.assertNever(check);
1792
1510
  return {
1793
1511
  status: status.value,
@@ -1842,12 +1560,11 @@ var ZodSymbol = class extends ZodType {
1842
1560
  const parsedType = this._getType(input);
1843
1561
  if (parsedType !== ZodParsedType.symbol) {
1844
1562
  const ctx = this._getOrReturnCtx(input);
1845
- addIssueToContext(ctx, {
1563
+ return addIssueToContext(ctx, {
1846
1564
  code: ZodIssueCode.invalid_type,
1847
1565
  expected: ZodParsedType.symbol,
1848
1566
  received: ctx.parsedType
1849
- });
1850
- return INVALID;
1567
+ }), INVALID;
1851
1568
  }
1852
1569
  return OK(input.data);
1853
1570
  }
@@ -1863,12 +1580,11 @@ var ZodUndefined = class extends ZodType {
1863
1580
  const parsedType = this._getType(input);
1864
1581
  if (parsedType !== ZodParsedType.undefined) {
1865
1582
  const ctx = this._getOrReturnCtx(input);
1866
- addIssueToContext(ctx, {
1583
+ return addIssueToContext(ctx, {
1867
1584
  code: ZodIssueCode.invalid_type,
1868
1585
  expected: ZodParsedType.undefined,
1869
1586
  received: ctx.parsedType
1870
- });
1871
- return INVALID;
1587
+ }), INVALID;
1872
1588
  }
1873
1589
  return OK(input.data);
1874
1590
  }
@@ -1884,12 +1600,11 @@ var ZodNull = class extends ZodType {
1884
1600
  const parsedType = this._getType(input);
1885
1601
  if (parsedType !== ZodParsedType.null) {
1886
1602
  const ctx = this._getOrReturnCtx(input);
1887
- addIssueToContext(ctx, {
1603
+ return addIssueToContext(ctx, {
1888
1604
  code: ZodIssueCode.invalid_type,
1889
1605
  expected: ZodParsedType.null,
1890
1606
  received: ctx.parsedType
1891
- });
1892
- return INVALID;
1607
+ }), INVALID;
1893
1608
  }
1894
1609
  return OK(input.data);
1895
1610
  }
@@ -1902,8 +1617,7 @@ ZodNull.create = (params) => {
1902
1617
  };
1903
1618
  var ZodAny = class extends ZodType {
1904
1619
  constructor() {
1905
- super(...arguments);
1906
- this._any = true;
1620
+ super(...arguments), this._any = true;
1907
1621
  }
1908
1622
  _parse(input) {
1909
1623
  return OK(input.data);
@@ -1917,8 +1631,7 @@ ZodAny.create = (params) => {
1917
1631
  };
1918
1632
  var ZodUnknown = class extends ZodType {
1919
1633
  constructor() {
1920
- super(...arguments);
1921
- this._unknown = true;
1634
+ super(...arguments), this._unknown = true;
1922
1635
  }
1923
1636
  _parse(input) {
1924
1637
  return OK(input.data);
@@ -1933,12 +1646,11 @@ ZodUnknown.create = (params) => {
1933
1646
  var ZodNever = class extends ZodType {
1934
1647
  _parse(input) {
1935
1648
  const ctx = this._getOrReturnCtx(input);
1936
- addIssueToContext(ctx, {
1649
+ return addIssueToContext(ctx, {
1937
1650
  code: ZodIssueCode.invalid_type,
1938
1651
  expected: ZodParsedType.never,
1939
1652
  received: ctx.parsedType
1940
- });
1941
- return INVALID;
1653
+ }), INVALID;
1942
1654
  }
1943
1655
  };
1944
1656
  ZodNever.create = (params) => {
@@ -1952,12 +1664,11 @@ var ZodVoid = class extends ZodType {
1952
1664
  const parsedType = this._getType(input);
1953
1665
  if (parsedType !== ZodParsedType.undefined) {
1954
1666
  const ctx = this._getOrReturnCtx(input);
1955
- addIssueToContext(ctx, {
1667
+ return addIssueToContext(ctx, {
1956
1668
  code: ZodIssueCode.invalid_type,
1957
1669
  expected: ZodParsedType.void,
1958
1670
  received: ctx.parsedType
1959
- });
1960
- return INVALID;
1671
+ }), INVALID;
1961
1672
  }
1962
1673
  return OK(input.data);
1963
1674
  }
@@ -1970,57 +1681,43 @@ ZodVoid.create = (params) => {
1970
1681
  };
1971
1682
  var ZodArray = class ZodArray extends ZodType {
1972
1683
  _parse(input) {
1973
- const { ctx, status } = this._processInputParams(input);
1974
- const def = this._def;
1975
- if (ctx.parsedType !== ZodParsedType.array) {
1976
- addIssueToContext(ctx, {
1977
- code: ZodIssueCode.invalid_type,
1978
- expected: ZodParsedType.array,
1979
- received: ctx.parsedType
1980
- });
1981
- return INVALID;
1982
- }
1684
+ const { ctx, status } = this._processInputParams(input), def = this._def;
1685
+ if (ctx.parsedType !== ZodParsedType.array) return addIssueToContext(ctx, {
1686
+ code: ZodIssueCode.invalid_type,
1687
+ expected: ZodParsedType.array,
1688
+ received: ctx.parsedType
1689
+ }), INVALID;
1983
1690
  if (def.exactLength !== null) {
1984
- const tooBig = ctx.data.length > def.exactLength.value;
1985
- const tooSmall = ctx.data.length < def.exactLength.value;
1986
- if (tooBig || tooSmall) {
1987
- addIssueToContext(ctx, {
1988
- code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
1989
- minimum: tooSmall ? def.exactLength.value : void 0,
1990
- maximum: tooBig ? def.exactLength.value : void 0,
1991
- type: "array",
1992
- inclusive: true,
1993
- exact: true,
1994
- message: def.exactLength.message
1995
- });
1996
- status.dirty();
1997
- }
1691
+ const tooBig = ctx.data.length > def.exactLength.value, tooSmall = ctx.data.length < def.exactLength.value;
1692
+ if (tooBig || tooSmall) addIssueToContext(ctx, {
1693
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
1694
+ minimum: tooSmall ? def.exactLength.value : void 0,
1695
+ maximum: tooBig ? def.exactLength.value : void 0,
1696
+ type: "array",
1697
+ inclusive: true,
1698
+ exact: true,
1699
+ message: def.exactLength.message
1700
+ }), status.dirty();
1998
1701
  }
1999
1702
  if (def.minLength !== null) {
2000
- if (ctx.data.length < def.minLength.value) {
2001
- addIssueToContext(ctx, {
2002
- code: ZodIssueCode.too_small,
2003
- minimum: def.minLength.value,
2004
- type: "array",
2005
- inclusive: true,
2006
- exact: false,
2007
- message: def.minLength.message
2008
- });
2009
- status.dirty();
2010
- }
1703
+ if (ctx.data.length < def.minLength.value) addIssueToContext(ctx, {
1704
+ code: ZodIssueCode.too_small,
1705
+ minimum: def.minLength.value,
1706
+ type: "array",
1707
+ inclusive: true,
1708
+ exact: false,
1709
+ message: def.minLength.message
1710
+ }), status.dirty();
2011
1711
  }
2012
1712
  if (def.maxLength !== null) {
2013
- if (ctx.data.length > def.maxLength.value) {
2014
- addIssueToContext(ctx, {
2015
- code: ZodIssueCode.too_big,
2016
- maximum: def.maxLength.value,
2017
- type: "array",
2018
- inclusive: true,
2019
- exact: false,
2020
- message: def.maxLength.message
2021
- });
2022
- status.dirty();
2023
- }
1713
+ if (ctx.data.length > def.maxLength.value) addIssueToContext(ctx, {
1714
+ code: ZodIssueCode.too_big,
1715
+ maximum: def.maxLength.value,
1716
+ type: "array",
1717
+ inclusive: true,
1718
+ exact: false,
1719
+ message: def.maxLength.message
1720
+ }), status.dirty();
2024
1721
  }
2025
1722
  if (ctx.common.async) return Promise.all([...ctx.data].map((item, i) => {
2026
1723
  return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
@@ -2098,49 +1795,33 @@ function deepPartialify(schema) {
2098
1795
  }
2099
1796
  var ZodObject = class ZodObject extends ZodType {
2100
1797
  constructor() {
2101
- super(...arguments);
2102
- this._cached = null;
2103
- /**
2104
- * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
2105
- * If you want to pass through unknown properties, use `.passthrough()` instead.
2106
- */
2107
- this.nonstrict = this.passthrough;
2108
- /**
2109
- * @deprecated Use `.extend` instead
2110
- * */
2111
- this.augment = this.extend;
1798
+ super(...arguments), this._cached = null, this.nonstrict = this.passthrough, this.augment = this.extend;
2112
1799
  }
2113
1800
  _getCached() {
2114
1801
  if (this._cached !== null) return this._cached;
2115
- const shape = this._def.shape();
2116
- const keys = util.objectKeys(shape);
2117
- this._cached = {
1802
+ const shape = this._def.shape(), keys = util.objectKeys(shape);
1803
+ return this._cached = {
2118
1804
  shape,
2119
1805
  keys
2120
- };
2121
- return this._cached;
1806
+ }, this._cached;
2122
1807
  }
2123
1808
  _parse(input) {
2124
1809
  const parsedType = this._getType(input);
2125
1810
  if (parsedType !== ZodParsedType.object) {
2126
1811
  const ctx$1 = this._getOrReturnCtx(input);
2127
- addIssueToContext(ctx$1, {
1812
+ return addIssueToContext(ctx$1, {
2128
1813
  code: ZodIssueCode.invalid_type,
2129
1814
  expected: ZodParsedType.object,
2130
1815
  received: ctx$1.parsedType
2131
- });
2132
- return INVALID;
1816
+ }), INVALID;
2133
1817
  }
2134
- const { status, ctx } = this._processInputParams(input);
2135
- const { shape, keys: shapeKeys } = this._getCached();
2136
- const extraKeys = [];
1818
+ const { status, ctx } = this._processInputParams(input), { shape, keys: shapeKeys } = this._getCached(), extraKeys = [];
2137
1819
  if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2138
1820
  for (const key in ctx.data) if (!shapeKeys.includes(key)) extraKeys.push(key);
2139
1821
  }
2140
1822
  const pairs = [];
2141
1823
  for (const key of shapeKeys) {
2142
- const keyValidator = shape[key];
2143
- const value = ctx.data[key];
1824
+ const keyValidator = shape[key], value = ctx.data[key];
2144
1825
  pairs.push({
2145
1826
  key: {
2146
1827
  status: "valid",
@@ -2163,13 +1844,10 @@ var ZodObject = class ZodObject extends ZodType {
2163
1844
  }
2164
1845
  });
2165
1846
  else if (unknownKeys === "strict") {
2166
- if (extraKeys.length > 0) {
2167
- addIssueToContext(ctx, {
2168
- code: ZodIssueCode.unrecognized_keys,
2169
- keys: extraKeys
2170
- });
2171
- status.dirty();
2172
- }
1847
+ if (extraKeys.length > 0) addIssueToContext(ctx, {
1848
+ code: ZodIssueCode.unrecognized_keys,
1849
+ keys: extraKeys
1850
+ }), status.dirty();
2173
1851
  } else if (unknownKeys === "strip") {} else throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2174
1852
  } else {
2175
1853
  const catchall = this._def.catchall;
@@ -2185,11 +1863,10 @@ var ZodObject = class ZodObject extends ZodType {
2185
1863
  });
2186
1864
  }
2187
1865
  }
2188
- if (ctx.common.async) return Promise.resolve().then(async () => {
1866
+ return ctx.common.async ? Promise.resolve().then(async () => {
2189
1867
  const syncPairs = [];
2190
1868
  for (const pair of pairs) {
2191
- const key = await pair.key;
2192
- const value = await pair.value;
1869
+ const key = await pair.key, value = await pair.value;
2193
1870
  syncPairs.push({
2194
1871
  key,
2195
1872
  value,
@@ -2199,21 +1876,18 @@ var ZodObject = class ZodObject extends ZodType {
2199
1876
  return syncPairs;
2200
1877
  }).then((syncPairs) => {
2201
1878
  return ParseStatus.mergeObjectSync(status, syncPairs);
2202
- });
2203
- else return ParseStatus.mergeObjectSync(status, pairs);
1879
+ }) : ParseStatus.mergeObjectSync(status, pairs);
2204
1880
  }
2205
1881
  get shape() {
2206
1882
  return this._def.shape();
2207
1883
  }
2208
1884
  strict(message) {
2209
- errorUtil.errToObj;
2210
- return new ZodObject({
1885
+ return errorUtil.errToObj, new ZodObject({
2211
1886
  ...this._def,
2212
1887
  unknownKeys: "strict",
2213
1888
  ...message !== void 0 ? { errorMap: (issue, ctx) => {
2214
1889
  const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2215
- if (issue.code === "unrecognized_keys") return { message: errorUtil.errToObj(message).message ?? defaultError };
2216
- return { message: defaultError };
1890
+ return issue.code === "unrecognized_keys" ? { message: errorUtil.errToObj(message).message ?? defaultError } : { message: defaultError };
2217
1891
  } } : {}
2218
1892
  });
2219
1893
  }
@@ -2238,11 +1912,6 @@ var ZodObject = class ZodObject extends ZodType {
2238
1912
  })
2239
1913
  });
2240
1914
  }
2241
- /**
2242
- * Prior to zod@1.0.12 there was a bug in the
2243
- * inferred type of merged objects. Please
2244
- * upgrade if you are experiencing issues.
2245
- */
2246
1915
  merge(merging) {
2247
1916
  const merged = new ZodObject({
2248
1917
  unknownKeys: merging._def.unknownKeys,
@@ -2280,9 +1949,6 @@ var ZodObject = class ZodObject extends ZodType {
2280
1949
  shape: () => shape
2281
1950
  });
2282
1951
  }
2283
- /**
2284
- * @deprecated
2285
- */
2286
1952
  deepPartial() {
2287
1953
  return deepPartialify(this);
2288
1954
  }
@@ -2324,8 +1990,7 @@ ZodObject.create = (shape, params) => {
2324
1990
  typeName: ZodFirstPartyTypeKind.ZodObject,
2325
1991
  ...processCreateParams(params)
2326
1992
  });
2327
- };
2328
- ZodObject.strictCreate = (shape, params) => {
1993
+ }, ZodObject.strictCreate = (shape, params) => {
2329
1994
  return new ZodObject({
2330
1995
  shape: () => shape,
2331
1996
  unknownKeys: "strict",
@@ -2333,8 +1998,7 @@ ZodObject.strictCreate = (shape, params) => {
2333
1998
  typeName: ZodFirstPartyTypeKind.ZodObject,
2334
1999
  ...processCreateParams(params)
2335
2000
  });
2336
- };
2337
- ZodObject.lazycreate = (shape, params) => {
2001
+ }, ZodObject.lazycreate = (shape, params) => {
2338
2002
  return new ZodObject({
2339
2003
  shape,
2340
2004
  unknownKeys: "strip",
@@ -2345,20 +2009,15 @@ ZodObject.lazycreate = (shape, params) => {
2345
2009
  };
2346
2010
  var ZodUnion = class extends ZodType {
2347
2011
  _parse(input) {
2348
- const { ctx } = this._processInputParams(input);
2349
- const options = this._def.options;
2012
+ const { ctx } = this._processInputParams(input), options = this._def.options;
2350
2013
  function handleResults(results) {
2351
2014
  for (const result of results) if (result.result.status === "valid") return result.result;
2352
- for (const result of results) if (result.result.status === "dirty") {
2353
- ctx.common.issues.push(...result.ctx.common.issues);
2354
- return result.result;
2355
- }
2015
+ for (const result of results) if (result.result.status === "dirty") return ctx.common.issues.push(...result.ctx.common.issues), result.result;
2356
2016
  const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
2357
- addIssueToContext(ctx, {
2017
+ return addIssueToContext(ctx, {
2358
2018
  code: ZodIssueCode.invalid_union,
2359
2019
  unionErrors
2360
- });
2361
- return INVALID;
2020
+ }), INVALID;
2362
2021
  }
2363
2022
  if (ctx.common.async) return Promise.all(options.map(async (option) => {
2364
2023
  const childCtx = {
@@ -2378,7 +2037,7 @@ var ZodUnion = class extends ZodType {
2378
2037
  ctx: childCtx
2379
2038
  };
2380
2039
  })).then(handleResults);
2381
- else {
2040
+ {
2382
2041
  let dirty = void 0;
2383
2042
  const issues = [];
2384
2043
  for (const option of options) {
@@ -2389,29 +2048,24 @@ var ZodUnion = class extends ZodType {
2389
2048
  issues: []
2390
2049
  },
2391
2050
  parent: null
2392
- };
2393
- const result = option._parseSync({
2051
+ }, result = option._parseSync({
2394
2052
  data: ctx.data,
2395
2053
  path: ctx.path,
2396
2054
  parent: childCtx
2397
2055
  });
2398
2056
  if (result.status === "valid") return result;
2399
- else if (result.status === "dirty" && !dirty) dirty = {
2057
+ if (result.status === "dirty" && !dirty) dirty = {
2400
2058
  result,
2401
2059
  ctx: childCtx
2402
2060
  };
2403
2061
  if (childCtx.common.issues.length) issues.push(childCtx.common.issues);
2404
2062
  }
2405
- if (dirty) {
2406
- ctx.common.issues.push(...dirty.ctx.common.issues);
2407
- return dirty.result;
2408
- }
2063
+ if (dirty) return ctx.common.issues.push(...dirty.ctx.common.issues), dirty.result;
2409
2064
  const unionErrors = issues.map((issues$1) => new ZodError(issues$1));
2410
- addIssueToContext(ctx, {
2065
+ return addIssueToContext(ctx, {
2411
2066
  code: ZodIssueCode.invalid_union,
2412
2067
  unionErrors
2413
- });
2414
- return INVALID;
2068
+ }), INVALID;
2415
2069
  }
2416
2070
  }
2417
2071
  get options() {
@@ -2426,53 +2080,30 @@ ZodUnion.create = (types, params) => {
2426
2080
  });
2427
2081
  };
2428
2082
  const getDiscriminator = (type) => {
2429
- if (type instanceof ZodLazy) return getDiscriminator(type.schema);
2430
- else if (type instanceof ZodEffects) return getDiscriminator(type.innerType());
2431
- else if (type instanceof ZodLiteral) return [type.value];
2432
- else if (type instanceof ZodEnum) return type.options;
2433
- else if (type instanceof ZodNativeEnum) return util.objectValues(type.enum);
2434
- else if (type instanceof ZodDefault) return getDiscriminator(type._def.innerType);
2435
- else if (type instanceof ZodUndefined) return [void 0];
2436
- else if (type instanceof ZodNull) return [null];
2437
- else if (type instanceof ZodOptional) return [void 0, ...getDiscriminator(type.unwrap())];
2438
- else if (type instanceof ZodNullable) return [null, ...getDiscriminator(type.unwrap())];
2439
- else if (type instanceof ZodBranded) return getDiscriminator(type.unwrap());
2440
- else if (type instanceof ZodReadonly) return getDiscriminator(type.unwrap());
2441
- else if (type instanceof ZodCatch) return getDiscriminator(type._def.innerType);
2442
- else return [];
2083
+ return type instanceof ZodLazy ? getDiscriminator(type.schema) : type instanceof ZodEffects ? getDiscriminator(type.innerType()) : type instanceof ZodLiteral ? [type.value] : type instanceof ZodEnum ? type.options : type instanceof ZodNativeEnum ? util.objectValues(type.enum) : type instanceof ZodDefault ? getDiscriminator(type._def.innerType) : type instanceof ZodUndefined ? [void 0] : type instanceof ZodNull ? [null] : type instanceof ZodOptional ? [void 0, ...getDiscriminator(type.unwrap())] : type instanceof ZodNullable ? [null, ...getDiscriminator(type.unwrap())] : type instanceof ZodBranded || type instanceof ZodReadonly ? getDiscriminator(type.unwrap()) : type instanceof ZodCatch ? getDiscriminator(type._def.innerType) : [];
2443
2084
  };
2444
2085
  var ZodDiscriminatedUnion = class ZodDiscriminatedUnion extends ZodType {
2445
2086
  _parse(input) {
2446
2087
  const { ctx } = this._processInputParams(input);
2447
- if (ctx.parsedType !== ZodParsedType.object) {
2448
- addIssueToContext(ctx, {
2449
- code: ZodIssueCode.invalid_type,
2450
- expected: ZodParsedType.object,
2451
- received: ctx.parsedType
2452
- });
2453
- return INVALID;
2454
- }
2455
- const discriminator = this.discriminator;
2456
- const discriminatorValue = ctx.data[discriminator];
2457
- const option = this.optionsMap.get(discriminatorValue);
2458
- if (!option) {
2459
- addIssueToContext(ctx, {
2460
- code: ZodIssueCode.invalid_union_discriminator,
2461
- options: Array.from(this.optionsMap.keys()),
2462
- path: [discriminator]
2463
- });
2464
- return INVALID;
2465
- }
2466
- if (ctx.common.async) return option._parseAsync({
2088
+ if (ctx.parsedType !== ZodParsedType.object) return addIssueToContext(ctx, {
2089
+ code: ZodIssueCode.invalid_type,
2090
+ expected: ZodParsedType.object,
2091
+ received: ctx.parsedType
2092
+ }), INVALID;
2093
+ const discriminator = this.discriminator, discriminatorValue = ctx.data[discriminator], option = this.optionsMap.get(discriminatorValue);
2094
+ return option ? ctx.common.async ? option._parseAsync({
2467
2095
  data: ctx.data,
2468
2096
  path: ctx.path,
2469
2097
  parent: ctx
2470
- });
2471
- else return option._parseSync({
2098
+ }) : option._parseSync({
2472
2099
  data: ctx.data,
2473
2100
  path: ctx.path,
2474
2101
  parent: ctx
2475
- });
2102
+ }) : (addIssueToContext(ctx, {
2103
+ code: ZodIssueCode.invalid_union_discriminator,
2104
+ options: Array.from(this.optionsMap.keys()),
2105
+ path: [discriminator]
2106
+ }), INVALID);
2476
2107
  }
2477
2108
  get discriminator() {
2478
2109
  return this._def.discriminator;
@@ -2483,16 +2114,8 @@ var ZodDiscriminatedUnion = class ZodDiscriminatedUnion extends ZodType {
2483
2114
  get optionsMap() {
2484
2115
  return this._def.optionsMap;
2485
2116
  }
2486
- /**
2487
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
2488
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
2489
- * have a different value for each object in the union.
2490
- * @param discriminator the name of the discriminator property
2491
- * @param types an array of object schemas
2492
- * @param params
2493
- */
2494
2117
  static create(discriminator, options, params) {
2495
- const optionsMap = new Map();
2118
+ const optionsMap = /* @__PURE__ */ new Map();
2496
2119
  for (const type of options) {
2497
2120
  const discriminatorValues = getDiscriminator(type.shape[discriminator]);
2498
2121
  if (!discriminatorValues.length) throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
@@ -2511,16 +2134,13 @@ var ZodDiscriminatedUnion = class ZodDiscriminatedUnion extends ZodType {
2511
2134
  }
2512
2135
  };
2513
2136
  function mergeValues(a, b) {
2514
- const aType = getParsedType(a);
2515
- const bType = getParsedType(b);
2137
+ const aType = getParsedType(a), bType = getParsedType(b);
2516
2138
  if (a === b) return {
2517
2139
  valid: true,
2518
2140
  data: a
2519
2141
  };
2520
- else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2521
- const bKeys = util.objectKeys(b);
2522
- const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
2523
- const newObj = {
2142
+ if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2143
+ const bKeys = util.objectKeys(b), sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1), newObj = {
2524
2144
  ...a,
2525
2145
  ...b
2526
2146
  };
@@ -2537,9 +2157,7 @@ function mergeValues(a, b) {
2537
2157
  if (a.length !== b.length) return { valid: false };
2538
2158
  const newArray = [];
2539
2159
  for (let index = 0; index < a.length; index++) {
2540
- const itemA = a[index];
2541
- const itemB = b[index];
2542
- const sharedValue = mergeValues(itemA, itemB);
2160
+ const itemA = a[index], itemB = b[index], sharedValue = mergeValues(itemA, itemB);
2543
2161
  if (!sharedValue.valid) return { valid: false };
2544
2162
  newArray.push(sharedValue.data);
2545
2163
  }
@@ -2555,21 +2173,17 @@ function mergeValues(a, b) {
2555
2173
  }
2556
2174
  var ZodIntersection = class extends ZodType {
2557
2175
  _parse(input) {
2558
- const { status, ctx } = this._processInputParams(input);
2559
- const handleParsed = (parsedLeft, parsedRight) => {
2176
+ const { status, ctx } = this._processInputParams(input), handleParsed = (parsedLeft, parsedRight) => {
2560
2177
  if (isAborted(parsedLeft) || isAborted(parsedRight)) return INVALID;
2561
2178
  const merged = mergeValues(parsedLeft.value, parsedRight.value);
2562
- if (!merged.valid) {
2563
- addIssueToContext(ctx, { code: ZodIssueCode.invalid_intersection_types });
2564
- return INVALID;
2565
- }
2179
+ if (!merged.valid) return addIssueToContext(ctx, { code: ZodIssueCode.invalid_intersection_types }), INVALID;
2566
2180
  if (isDirty(parsedLeft) || isDirty(parsedRight)) status.dirty();
2567
2181
  return {
2568
2182
  status: status.value,
2569
2183
  value: merged.data
2570
2184
  };
2571
2185
  };
2572
- if (ctx.common.async) return Promise.all([this._def.left._parseAsync({
2186
+ return ctx.common.async ? Promise.all([this._def.left._parseAsync({
2573
2187
  data: ctx.data,
2574
2188
  path: ctx.path,
2575
2189
  parent: ctx
@@ -2577,8 +2191,7 @@ var ZodIntersection = class extends ZodType {
2577
2191
  data: ctx.data,
2578
2192
  path: ctx.path,
2579
2193
  parent: ctx
2580
- })]).then(([left, right]) => handleParsed(left, right));
2581
- else return handleParsed(this._def.left._parseSync({
2194
+ })]).then(([left, right]) => handleParsed(left, right)) : handleParsed(this._def.left._parseSync({
2582
2195
  data: ctx.data,
2583
2196
  path: ctx.path,
2584
2197
  parent: ctx
@@ -2600,44 +2213,33 @@ ZodIntersection.create = (left, right, params) => {
2600
2213
  var ZodTuple = class ZodTuple extends ZodType {
2601
2214
  _parse(input) {
2602
2215
  const { status, ctx } = this._processInputParams(input);
2603
- if (ctx.parsedType !== ZodParsedType.array) {
2604
- addIssueToContext(ctx, {
2605
- code: ZodIssueCode.invalid_type,
2606
- expected: ZodParsedType.array,
2607
- received: ctx.parsedType
2608
- });
2609
- return INVALID;
2610
- }
2611
- if (ctx.data.length < this._def.items.length) {
2612
- addIssueToContext(ctx, {
2613
- code: ZodIssueCode.too_small,
2614
- minimum: this._def.items.length,
2615
- inclusive: true,
2616
- exact: false,
2617
- type: "array"
2618
- });
2619
- return INVALID;
2620
- }
2216
+ if (ctx.parsedType !== ZodParsedType.array) return addIssueToContext(ctx, {
2217
+ code: ZodIssueCode.invalid_type,
2218
+ expected: ZodParsedType.array,
2219
+ received: ctx.parsedType
2220
+ }), INVALID;
2221
+ if (ctx.data.length < this._def.items.length) return addIssueToContext(ctx, {
2222
+ code: ZodIssueCode.too_small,
2223
+ minimum: this._def.items.length,
2224
+ inclusive: true,
2225
+ exact: false,
2226
+ type: "array"
2227
+ }), INVALID;
2621
2228
  const rest = this._def.rest;
2622
- if (!rest && ctx.data.length > this._def.items.length) {
2623
- addIssueToContext(ctx, {
2624
- code: ZodIssueCode.too_big,
2625
- maximum: this._def.items.length,
2626
- inclusive: true,
2627
- exact: false,
2628
- type: "array"
2629
- });
2630
- status.dirty();
2631
- }
2229
+ if (!rest && ctx.data.length > this._def.items.length) addIssueToContext(ctx, {
2230
+ code: ZodIssueCode.too_big,
2231
+ maximum: this._def.items.length,
2232
+ inclusive: true,
2233
+ exact: false,
2234
+ type: "array"
2235
+ }), status.dirty();
2632
2236
  const items = [...ctx.data].map((item, itemIndex) => {
2633
2237
  const schema = this._def.items[itemIndex] || this._def.rest;
2634
- if (!schema) return null;
2635
- return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
2238
+ return schema ? schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex)) : null;
2636
2239
  }).filter((x) => !!x);
2637
- if (ctx.common.async) return Promise.all(items).then((results) => {
2240
+ return ctx.common.async ? Promise.all(items).then((results) => {
2638
2241
  return ParseStatus.mergeArray(status, results);
2639
- });
2640
- else return ParseStatus.mergeArray(status, items);
2242
+ }) : ParseStatus.mergeArray(status, items);
2641
2243
  }
2642
2244
  get items() {
2643
2245
  return this._def.items;
@@ -2667,44 +2269,36 @@ var ZodRecord = class ZodRecord extends ZodType {
2667
2269
  }
2668
2270
  _parse(input) {
2669
2271
  const { status, ctx } = this._processInputParams(input);
2670
- if (ctx.parsedType !== ZodParsedType.object) {
2671
- addIssueToContext(ctx, {
2672
- code: ZodIssueCode.invalid_type,
2673
- expected: ZodParsedType.object,
2674
- received: ctx.parsedType
2675
- });
2676
- return INVALID;
2677
- }
2678
- const pairs = [];
2679
- const keyType = this._def.keyType;
2680
- const valueType = this._def.valueType;
2272
+ if (ctx.parsedType !== ZodParsedType.object) return addIssueToContext(ctx, {
2273
+ code: ZodIssueCode.invalid_type,
2274
+ expected: ZodParsedType.object,
2275
+ received: ctx.parsedType
2276
+ }), INVALID;
2277
+ const pairs = [], keyType = this._def.keyType, valueType = this._def.valueType;
2681
2278
  for (const key in ctx.data) pairs.push({
2682
2279
  key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
2683
2280
  value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
2684
2281
  alwaysSet: key in ctx.data
2685
2282
  });
2686
- if (ctx.common.async) return ParseStatus.mergeObjectAsync(status, pairs);
2687
- else return ParseStatus.mergeObjectSync(status, pairs);
2283
+ return ctx.common.async ? ParseStatus.mergeObjectAsync(status, pairs) : ParseStatus.mergeObjectSync(status, pairs);
2688
2284
  }
2689
2285
  get element() {
2690
2286
  return this._def.valueType;
2691
2287
  }
2692
2288
  static create(first, second, third) {
2693
- if (second instanceof ZodType) return new ZodRecord({
2289
+ return second instanceof ZodType ? new ZodRecord({
2694
2290
  keyType: first,
2695
2291
  valueType: second,
2696
2292
  typeName: ZodFirstPartyTypeKind.ZodRecord,
2697
2293
  ...processCreateParams(third)
2698
- });
2699
- return new ZodRecord({
2294
+ }) : new ZodRecord({
2700
2295
  keyType: ZodString.create(),
2701
2296
  valueType: first,
2702
2297
  typeName: ZodFirstPartyTypeKind.ZodRecord,
2703
2298
  ...processCreateParams(second)
2704
2299
  });
2705
2300
  }
2706
- };
2707
- var ZodMap = class extends ZodType {
2301
+ }, ZodMap = class extends ZodType {
2708
2302
  get keySchema() {
2709
2303
  return this._def.keyType;
2710
2304
  }
@@ -2713,28 +2307,22 @@ var ZodMap = class extends ZodType {
2713
2307
  }
2714
2308
  _parse(input) {
2715
2309
  const { status, ctx } = this._processInputParams(input);
2716
- if (ctx.parsedType !== ZodParsedType.map) {
2717
- addIssueToContext(ctx, {
2718
- code: ZodIssueCode.invalid_type,
2719
- expected: ZodParsedType.map,
2720
- received: ctx.parsedType
2721
- });
2722
- return INVALID;
2723
- }
2724
- const keyType = this._def.keyType;
2725
- const valueType = this._def.valueType;
2726
- const pairs = [...ctx.data.entries()].map(([key, value], index) => {
2310
+ if (ctx.parsedType !== ZodParsedType.map) return addIssueToContext(ctx, {
2311
+ code: ZodIssueCode.invalid_type,
2312
+ expected: ZodParsedType.map,
2313
+ received: ctx.parsedType
2314
+ }), INVALID;
2315
+ const keyType = this._def.keyType, valueType = this._def.valueType, pairs = [...ctx.data.entries()].map(([key, value], index) => {
2727
2316
  return {
2728
2317
  key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
2729
2318
  value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
2730
2319
  };
2731
2320
  });
2732
2321
  if (ctx.common.async) {
2733
- const finalMap = new Map();
2322
+ const finalMap = /* @__PURE__ */ new Map();
2734
2323
  return Promise.resolve().then(async () => {
2735
2324
  for (const pair of pairs) {
2736
- const key = await pair.key;
2737
- const value = await pair.value;
2325
+ const key = await pair.key, value = await pair.value;
2738
2326
  if (key.status === "aborted" || value.status === "aborted") return INVALID;
2739
2327
  if (key.status === "dirty" || value.status === "dirty") status.dirty();
2740
2328
  finalMap.set(key.value, value.value);
@@ -2745,10 +2333,9 @@ var ZodMap = class extends ZodType {
2745
2333
  };
2746
2334
  });
2747
2335
  } else {
2748
- const finalMap = new Map();
2336
+ const finalMap = /* @__PURE__ */ new Map();
2749
2337
  for (const pair of pairs) {
2750
- const key = pair.key;
2751
- const value = pair.value;
2338
+ const key = pair.key, value = pair.value;
2752
2339
  if (key.status === "aborted" || value.status === "aborted") return INVALID;
2753
2340
  if (key.status === "dirty" || value.status === "dirty") status.dirty();
2754
2341
  finalMap.set(key.value, value.value);
@@ -2771,44 +2358,35 @@ ZodMap.create = (keyType, valueType, params) => {
2771
2358
  var ZodSet = class ZodSet extends ZodType {
2772
2359
  _parse(input) {
2773
2360
  const { status, ctx } = this._processInputParams(input);
2774
- if (ctx.parsedType !== ZodParsedType.set) {
2775
- addIssueToContext(ctx, {
2776
- code: ZodIssueCode.invalid_type,
2777
- expected: ZodParsedType.set,
2778
- received: ctx.parsedType
2779
- });
2780
- return INVALID;
2781
- }
2361
+ if (ctx.parsedType !== ZodParsedType.set) return addIssueToContext(ctx, {
2362
+ code: ZodIssueCode.invalid_type,
2363
+ expected: ZodParsedType.set,
2364
+ received: ctx.parsedType
2365
+ }), INVALID;
2782
2366
  const def = this._def;
2783
2367
  if (def.minSize !== null) {
2784
- if (ctx.data.size < def.minSize.value) {
2785
- addIssueToContext(ctx, {
2786
- code: ZodIssueCode.too_small,
2787
- minimum: def.minSize.value,
2788
- type: "set",
2789
- inclusive: true,
2790
- exact: false,
2791
- message: def.minSize.message
2792
- });
2793
- status.dirty();
2794
- }
2368
+ if (ctx.data.size < def.minSize.value) addIssueToContext(ctx, {
2369
+ code: ZodIssueCode.too_small,
2370
+ minimum: def.minSize.value,
2371
+ type: "set",
2372
+ inclusive: true,
2373
+ exact: false,
2374
+ message: def.minSize.message
2375
+ }), status.dirty();
2795
2376
  }
2796
2377
  if (def.maxSize !== null) {
2797
- if (ctx.data.size > def.maxSize.value) {
2798
- addIssueToContext(ctx, {
2799
- code: ZodIssueCode.too_big,
2800
- maximum: def.maxSize.value,
2801
- type: "set",
2802
- inclusive: true,
2803
- exact: false,
2804
- message: def.maxSize.message
2805
- });
2806
- status.dirty();
2807
- }
2378
+ if (ctx.data.size > def.maxSize.value) addIssueToContext(ctx, {
2379
+ code: ZodIssueCode.too_big,
2380
+ maximum: def.maxSize.value,
2381
+ type: "set",
2382
+ inclusive: true,
2383
+ exact: false,
2384
+ message: def.maxSize.message
2385
+ }), status.dirty();
2808
2386
  }
2809
2387
  const valueType = this._def.valueType;
2810
2388
  function finalizeSet(elements$1) {
2811
- const parsedSet = new Set();
2389
+ const parsedSet = /* @__PURE__ */ new Set();
2812
2390
  for (const element of elements$1) {
2813
2391
  if (element.status === "aborted") return INVALID;
2814
2392
  if (element.status === "dirty") status.dirty();
@@ -2820,8 +2398,7 @@ var ZodSet = class ZodSet extends ZodType {
2820
2398
  };
2821
2399
  }
2822
2400
  const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
2823
- if (ctx.common.async) return Promise.all(elements).then((elements$1) => finalizeSet(elements$1));
2824
- else return finalizeSet(elements);
2401
+ return ctx.common.async ? Promise.all(elements).then((elements$1) => finalizeSet(elements$1)) : finalizeSet(elements);
2825
2402
  }
2826
2403
  min(minSize, message) {
2827
2404
  return new ZodSet({
@@ -2859,19 +2436,15 @@ ZodSet.create = (valueType, params) => {
2859
2436
  };
2860
2437
  var ZodFunction = class ZodFunction extends ZodType {
2861
2438
  constructor() {
2862
- super(...arguments);
2863
- this.validate = this.implement;
2439
+ super(...arguments), this.validate = this.implement;
2864
2440
  }
2865
2441
  _parse(input) {
2866
2442
  const { ctx } = this._processInputParams(input);
2867
- if (ctx.parsedType !== ZodParsedType.function) {
2868
- addIssueToContext(ctx, {
2869
- code: ZodIssueCode.invalid_type,
2870
- expected: ZodParsedType.function,
2871
- received: ctx.parsedType
2872
- });
2873
- return INVALID;
2874
- }
2443
+ if (ctx.parsedType !== ZodParsedType.function) return addIssueToContext(ctx, {
2444
+ code: ZodIssueCode.invalid_type,
2445
+ expected: ZodParsedType.function,
2446
+ received: ctx.parsedType
2447
+ }), INVALID;
2875
2448
  function makeArgsIssue(args, error) {
2876
2449
  return makeIssue({
2877
2450
  data: args,
@@ -2904,20 +2477,14 @@ var ZodFunction = class ZodFunction extends ZodType {
2904
2477
  }
2905
2478
  });
2906
2479
  }
2907
- const params = { errorMap: ctx.common.contextualErrorMap };
2908
- const fn = ctx.data;
2480
+ const params = { errorMap: ctx.common.contextualErrorMap }, fn = ctx.data;
2909
2481
  if (this._def.returns instanceof ZodPromise) {
2910
2482
  const me = this;
2911
2483
  return OK(async function(...args) {
2912
- const error = new ZodError([]);
2913
- const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
2914
- error.addIssue(makeArgsIssue(args, e));
2915
- throw error;
2916
- });
2917
- const result = await Reflect.apply(fn, this, parsedArgs);
2918
- const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
2919
- error.addIssue(makeReturnsIssue(result, e));
2920
- throw error;
2484
+ const error = new ZodError([]), parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
2485
+ throw error.addIssue(makeArgsIssue(args, e)), error;
2486
+ }), result = await Reflect.apply(fn, this, parsedArgs), parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
2487
+ throw error.addIssue(makeReturnsIssue(result, e)), error;
2921
2488
  });
2922
2489
  return parsedReturns;
2923
2490
  });
@@ -2926,8 +2493,7 @@ var ZodFunction = class ZodFunction extends ZodType {
2926
2493
  return OK(function(...args) {
2927
2494
  const parsedArgs = me._def.args.safeParse(args, params);
2928
2495
  if (!parsedArgs.success) throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
2929
- const result = Reflect.apply(fn, this, parsedArgs.data);
2930
- const parsedReturns = me._def.returns.safeParse(result, params);
2496
+ const result = Reflect.apply(fn, this, parsedArgs.data), parsedReturns = me._def.returns.safeParse(result, params);
2931
2497
  if (!parsedReturns.success) throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
2932
2498
  return parsedReturns.data;
2933
2499
  });
@@ -2967,14 +2533,12 @@ var ZodFunction = class ZodFunction extends ZodType {
2967
2533
  ...processCreateParams(params)
2968
2534
  });
2969
2535
  }
2970
- };
2971
- var ZodLazy = class extends ZodType {
2536
+ }, ZodLazy = class extends ZodType {
2972
2537
  get schema() {
2973
2538
  return this._def.getter();
2974
2539
  }
2975
2540
  _parse(input) {
2976
- const { ctx } = this._processInputParams(input);
2977
- const lazySchema = this._def.getter();
2541
+ const { ctx } = this._processInputParams(input), lazySchema = this._def.getter();
2978
2542
  return lazySchema._parse({
2979
2543
  data: ctx.data,
2980
2544
  path: ctx.path,
@@ -2993,12 +2557,11 @@ var ZodLiteral = class extends ZodType {
2993
2557
  _parse(input) {
2994
2558
  if (input.data !== this._def.value) {
2995
2559
  const ctx = this._getOrReturnCtx(input);
2996
- addIssueToContext(ctx, {
2560
+ return addIssueToContext(ctx, {
2997
2561
  received: ctx.data,
2998
2562
  code: ZodIssueCode.invalid_literal,
2999
2563
  expected: this._def.value
3000
- });
3001
- return INVALID;
2564
+ }), INVALID;
3002
2565
  }
3003
2566
  return {
3004
2567
  status: "valid",
@@ -3026,25 +2589,21 @@ function createZodEnum(values, params) {
3026
2589
  var ZodEnum = class ZodEnum extends ZodType {
3027
2590
  _parse(input) {
3028
2591
  if (typeof input.data !== "string") {
3029
- const ctx = this._getOrReturnCtx(input);
3030
- const expectedValues = this._def.values;
3031
- addIssueToContext(ctx, {
2592
+ const ctx = this._getOrReturnCtx(input), expectedValues = this._def.values;
2593
+ return addIssueToContext(ctx, {
3032
2594
  expected: util.joinValues(expectedValues),
3033
2595
  received: ctx.parsedType,
3034
2596
  code: ZodIssueCode.invalid_type
3035
- });
3036
- return INVALID;
2597
+ }), INVALID;
3037
2598
  }
3038
2599
  if (!this._cache) this._cache = new Set(this._def.values);
3039
2600
  if (!this._cache.has(input.data)) {
3040
- const ctx = this._getOrReturnCtx(input);
3041
- const expectedValues = this._def.values;
3042
- addIssueToContext(ctx, {
2601
+ const ctx = this._getOrReturnCtx(input), expectedValues = this._def.values;
2602
+ return addIssueToContext(ctx, {
3043
2603
  received: ctx.data,
3044
2604
  code: ZodIssueCode.invalid_enum_value,
3045
2605
  options: expectedValues
3046
- });
3047
- return INVALID;
2606
+ }), INVALID;
3048
2607
  }
3049
2608
  return OK(input.data);
3050
2609
  }
@@ -3082,26 +2641,23 @@ var ZodEnum = class ZodEnum extends ZodType {
3082
2641
  ZodEnum.create = createZodEnum;
3083
2642
  var ZodNativeEnum = class extends ZodType {
3084
2643
  _parse(input) {
3085
- const nativeEnumValues = util.getValidEnumValues(this._def.values);
3086
- const ctx = this._getOrReturnCtx(input);
2644
+ const nativeEnumValues = util.getValidEnumValues(this._def.values), ctx = this._getOrReturnCtx(input);
3087
2645
  if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3088
2646
  const expectedValues = util.objectValues(nativeEnumValues);
3089
- addIssueToContext(ctx, {
2647
+ return addIssueToContext(ctx, {
3090
2648
  expected: util.joinValues(expectedValues),
3091
2649
  received: ctx.parsedType,
3092
2650
  code: ZodIssueCode.invalid_type
3093
- });
3094
- return INVALID;
2651
+ }), INVALID;
3095
2652
  }
3096
2653
  if (!this._cache) this._cache = new Set(util.getValidEnumValues(this._def.values));
3097
2654
  if (!this._cache.has(input.data)) {
3098
2655
  const expectedValues = util.objectValues(nativeEnumValues);
3099
- addIssueToContext(ctx, {
2656
+ return addIssueToContext(ctx, {
3100
2657
  received: ctx.data,
3101
2658
  code: ZodIssueCode.invalid_enum_value,
3102
2659
  options: expectedValues
3103
- });
3104
- return INVALID;
2660
+ }), INVALID;
3105
2661
  }
3106
2662
  return OK(input.data);
3107
2663
  }
@@ -3122,14 +2678,11 @@ var ZodPromise = class extends ZodType {
3122
2678
  }
3123
2679
  _parse(input) {
3124
2680
  const { ctx } = this._processInputParams(input);
3125
- if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3126
- addIssueToContext(ctx, {
3127
- code: ZodIssueCode.invalid_type,
3128
- expected: ZodParsedType.promise,
3129
- received: ctx.parsedType
3130
- });
3131
- return INVALID;
3132
- }
2681
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) return addIssueToContext(ctx, {
2682
+ code: ZodIssueCode.invalid_type,
2683
+ expected: ZodParsedType.promise,
2684
+ received: ctx.parsedType
2685
+ }), INVALID;
3133
2686
  const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3134
2687
  return OK(promisified.then((data) => {
3135
2688
  return this._def.type.parseAsync(data, {
@@ -3154,20 +2707,16 @@ var ZodEffects = class extends ZodType {
3154
2707
  return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
3155
2708
  }
3156
2709
  _parse(input) {
3157
- const { status, ctx } = this._processInputParams(input);
3158
- const effect = this._def.effect || null;
3159
- const checkCtx = {
2710
+ const { status, ctx } = this._processInputParams(input), effect = this._def.effect || null, checkCtx = {
3160
2711
  addIssue: (arg) => {
3161
- addIssueToContext(ctx, arg);
3162
- if (arg.fatal) status.abort();
2712
+ if (addIssueToContext(ctx, arg), arg.fatal) status.abort();
3163
2713
  else status.dirty();
3164
2714
  },
3165
2715
  get path() {
3166
2716
  return ctx.path;
3167
2717
  }
3168
2718
  };
3169
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3170
- if (effect.type === "preprocess") {
2719
+ if (checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx), effect.type === "preprocess") {
3171
2720
  const processed = effect.transform(ctx.data, checkCtx);
3172
2721
  if (ctx.common.async) return Promise.resolve(processed).then(async (processed$1) => {
3173
2722
  if (status.value === "aborted") return INVALID;
@@ -3176,22 +2725,16 @@ var ZodEffects = class extends ZodType {
3176
2725
  path: ctx.path,
3177
2726
  parent: ctx
3178
2727
  });
3179
- if (result.status === "aborted") return INVALID;
3180
- if (result.status === "dirty") return DIRTY(result.value);
3181
- if (status.value === "dirty") return DIRTY(result.value);
3182
- return result;
2728
+ return result.status === "aborted" ? INVALID : result.status === "dirty" || status.value === "dirty" ? DIRTY(result.value) : result;
3183
2729
  });
3184
- else {
2730
+ {
3185
2731
  if (status.value === "aborted") return INVALID;
3186
2732
  const result = this._def.schema._parseSync({
3187
2733
  data: processed,
3188
2734
  path: ctx.path,
3189
2735
  parent: ctx
3190
2736
  });
3191
- if (result.status === "aborted") return INVALID;
3192
- if (result.status === "dirty") return DIRTY(result.value);
3193
- if (status.value === "dirty") return DIRTY(result.value);
3194
- return result;
2737
+ return result.status === "aborted" ? INVALID : result.status === "dirty" || status.value === "dirty" ? DIRTY(result.value) : result;
3195
2738
  }
3196
2739
  }
3197
2740
  if (effect.type === "refinement") {
@@ -3209,8 +2752,7 @@ var ZodEffects = class extends ZodType {
3209
2752
  });
3210
2753
  if (inner.status === "aborted") return INVALID;
3211
2754
  if (inner.status === "dirty") status.dirty();
3212
- executeRefinement(inner.value);
3213
- return {
2755
+ return executeRefinement(inner.value), {
3214
2756
  status: status.value,
3215
2757
  value: inner.value
3216
2758
  };
@@ -3247,11 +2789,10 @@ var ZodEffects = class extends ZodType {
3247
2789
  path: ctx.path,
3248
2790
  parent: ctx
3249
2791
  }).then((base) => {
3250
- if (!isValid(base)) return INVALID;
3251
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
2792
+ return isValid(base) ? Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
3252
2793
  status: status.value,
3253
2794
  value: result
3254
- }));
2795
+ })) : INVALID;
3255
2796
  });
3256
2797
  util.assertNever(effect);
3257
2798
  }
@@ -3263,8 +2804,7 @@ ZodEffects.create = (schema, effect, params) => {
3263
2804
  effect,
3264
2805
  ...processCreateParams(params)
3265
2806
  });
3266
- };
3267
- ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
2807
+ }, ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3268
2808
  return new ZodEffects({
3269
2809
  schema,
3270
2810
  effect: {
@@ -3278,8 +2818,7 @@ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3278
2818
  var ZodOptional = class extends ZodType {
3279
2819
  _parse(input) {
3280
2820
  const parsedType = this._getType(input);
3281
- if (parsedType === ZodParsedType.undefined) return OK(void 0);
3282
- return this._def.innerType._parse(input);
2821
+ return parsedType === ZodParsedType.undefined ? OK(void 0) : this._def.innerType._parse(input);
3283
2822
  }
3284
2823
  unwrap() {
3285
2824
  return this._def.innerType;
@@ -3295,8 +2834,7 @@ ZodOptional.create = (type, params) => {
3295
2834
  var ZodNullable = class extends ZodType {
3296
2835
  _parse(input) {
3297
2836
  const parsedType = this._getType(input);
3298
- if (parsedType === ZodParsedType.null) return OK(null);
3299
- return this._def.innerType._parse(input);
2837
+ return parsedType === ZodParsedType.null ? OK(null) : this._def.innerType._parse(input);
3300
2838
  }
3301
2839
  unwrap() {
3302
2840
  return this._def.innerType;
@@ -3334,20 +2872,18 @@ ZodDefault.create = (type, params) => {
3334
2872
  };
3335
2873
  var ZodCatch = class extends ZodType {
3336
2874
  _parse(input) {
3337
- const { ctx } = this._processInputParams(input);
3338
- const newCtx = {
2875
+ const { ctx } = this._processInputParams(input), newCtx = {
3339
2876
  ...ctx,
3340
2877
  common: {
3341
2878
  ...ctx.common,
3342
2879
  issues: []
3343
2880
  }
3344
- };
3345
- const result = this._def.innerType._parse({
2881
+ }, result = this._def.innerType._parse({
3346
2882
  data: newCtx.data,
3347
2883
  path: newCtx.path,
3348
2884
  parent: { ...newCtx }
3349
2885
  });
3350
- if (isAsync(result)) return result.then((result$1) => {
2886
+ return isAsync(result) ? result.then((result$1) => {
3351
2887
  return {
3352
2888
  status: "valid",
3353
2889
  value: result$1.status === "valid" ? result$1.value : this._def.catchValue({
@@ -3357,8 +2893,7 @@ var ZodCatch = class extends ZodType {
3357
2893
  input: newCtx.data
3358
2894
  })
3359
2895
  };
3360
- });
3361
- else return {
2896
+ }) : {
3362
2897
  status: "valid",
3363
2898
  value: result.status === "valid" ? result.value : this._def.catchValue({
3364
2899
  get error() {
@@ -3385,12 +2920,11 @@ var ZodNaN = class extends ZodType {
3385
2920
  const parsedType = this._getType(input);
3386
2921
  if (parsedType !== ZodParsedType.nan) {
3387
2922
  const ctx = this._getOrReturnCtx(input);
3388
- addIssueToContext(ctx, {
2923
+ return addIssueToContext(ctx, {
3389
2924
  code: ZodIssueCode.invalid_type,
3390
2925
  expected: ZodParsedType.nan,
3391
2926
  received: ctx.parsedType
3392
- });
3393
- return INVALID;
2927
+ }), INVALID;
3394
2928
  }
3395
2929
  return {
3396
2930
  status: "valid",
@@ -3407,8 +2941,7 @@ ZodNaN.create = (params) => {
3407
2941
  const BRAND = Symbol("zod_brand");
3408
2942
  var ZodBranded = class extends ZodType {
3409
2943
  _parse(input) {
3410
- const { ctx } = this._processInputParams(input);
3411
- const data = ctx.data;
2944
+ const { ctx } = this._processInputParams(input), data = ctx.data;
3412
2945
  return this._def.type._parse({
3413
2946
  data,
3414
2947
  path: ctx.path,
@@ -3418,8 +2951,7 @@ var ZodBranded = class extends ZodType {
3418
2951
  unwrap() {
3419
2952
  return this._def.type;
3420
2953
  }
3421
- };
3422
- var ZodPipeline = class ZodPipeline extends ZodType {
2954
+ }, ZodPipeline = class ZodPipeline extends ZodType {
3423
2955
  _parse(input) {
3424
2956
  const { status, ctx } = this._processInputParams(input);
3425
2957
  if (ctx.common.async) {
@@ -3429,11 +2961,7 @@ var ZodPipeline = class ZodPipeline extends ZodType {
3429
2961
  path: ctx.path,
3430
2962
  parent: ctx
3431
2963
  });
3432
- if (inResult.status === "aborted") return INVALID;
3433
- if (inResult.status === "dirty") {
3434
- status.dirty();
3435
- return DIRTY(inResult.value);
3436
- } else return this._def.out._parseAsync({
2964
+ return inResult.status === "aborted" ? INVALID : inResult.status === "dirty" ? (status.dirty(), DIRTY(inResult.value)) : this._def.out._parseAsync({
3437
2965
  data: inResult.value,
3438
2966
  path: ctx.path,
3439
2967
  parent: ctx
@@ -3446,14 +2974,10 @@ var ZodPipeline = class ZodPipeline extends ZodType {
3446
2974
  path: ctx.path,
3447
2975
  parent: ctx
3448
2976
  });
3449
- if (inResult.status === "aborted") return INVALID;
3450
- if (inResult.status === "dirty") {
3451
- status.dirty();
3452
- return {
3453
- status: "dirty",
3454
- value: inResult.value
3455
- };
3456
- } else return this._def.out._parseSync({
2977
+ return inResult.status === "aborted" ? INVALID : inResult.status === "dirty" ? (status.dirty(), {
2978
+ status: "dirty",
2979
+ value: inResult.value
2980
+ }) : this._def.out._parseSync({
3457
2981
  data: inResult.value,
3458
2982
  path: ctx.path,
3459
2983
  parent: ctx
@@ -3467,11 +2991,9 @@ var ZodPipeline = class ZodPipeline extends ZodType {
3467
2991
  typeName: ZodFirstPartyTypeKind.ZodPipeline
3468
2992
  });
3469
2993
  }
3470
- };
3471
- var ZodReadonly = class extends ZodType {
2994
+ }, ZodReadonly = class extends ZodType {
3472
2995
  _parse(input) {
3473
- const result = this._def.innerType._parse(input);
3474
- const freeze = (data) => {
2996
+ const result = this._def.innerType._parse(input), freeze = (data) => {
3475
2997
  if (isValid(data)) data.value = Object.freeze(data.value);
3476
2998
  return data;
3477
2999
  };
@@ -3491,129 +3013,22 @@ ZodReadonly.create = (type, params) => {
3491
3013
  const late = { object: ZodObject.lazycreate };
3492
3014
  var ZodFirstPartyTypeKind;
3493
3015
  (function(ZodFirstPartyTypeKind$1) {
3494
- ZodFirstPartyTypeKind$1["ZodString"] = "ZodString";
3495
- ZodFirstPartyTypeKind$1["ZodNumber"] = "ZodNumber";
3496
- ZodFirstPartyTypeKind$1["ZodNaN"] = "ZodNaN";
3497
- ZodFirstPartyTypeKind$1["ZodBigInt"] = "ZodBigInt";
3498
- ZodFirstPartyTypeKind$1["ZodBoolean"] = "ZodBoolean";
3499
- ZodFirstPartyTypeKind$1["ZodDate"] = "ZodDate";
3500
- ZodFirstPartyTypeKind$1["ZodSymbol"] = "ZodSymbol";
3501
- ZodFirstPartyTypeKind$1["ZodUndefined"] = "ZodUndefined";
3502
- ZodFirstPartyTypeKind$1["ZodNull"] = "ZodNull";
3503
- ZodFirstPartyTypeKind$1["ZodAny"] = "ZodAny";
3504
- ZodFirstPartyTypeKind$1["ZodUnknown"] = "ZodUnknown";
3505
- ZodFirstPartyTypeKind$1["ZodNever"] = "ZodNever";
3506
- ZodFirstPartyTypeKind$1["ZodVoid"] = "ZodVoid";
3507
- ZodFirstPartyTypeKind$1["ZodArray"] = "ZodArray";
3508
- ZodFirstPartyTypeKind$1["ZodObject"] = "ZodObject";
3509
- ZodFirstPartyTypeKind$1["ZodUnion"] = "ZodUnion";
3510
- ZodFirstPartyTypeKind$1["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3511
- ZodFirstPartyTypeKind$1["ZodIntersection"] = "ZodIntersection";
3512
- ZodFirstPartyTypeKind$1["ZodTuple"] = "ZodTuple";
3513
- ZodFirstPartyTypeKind$1["ZodRecord"] = "ZodRecord";
3514
- ZodFirstPartyTypeKind$1["ZodMap"] = "ZodMap";
3515
- ZodFirstPartyTypeKind$1["ZodSet"] = "ZodSet";
3516
- ZodFirstPartyTypeKind$1["ZodFunction"] = "ZodFunction";
3517
- ZodFirstPartyTypeKind$1["ZodLazy"] = "ZodLazy";
3518
- ZodFirstPartyTypeKind$1["ZodLiteral"] = "ZodLiteral";
3519
- ZodFirstPartyTypeKind$1["ZodEnum"] = "ZodEnum";
3520
- ZodFirstPartyTypeKind$1["ZodEffects"] = "ZodEffects";
3521
- ZodFirstPartyTypeKind$1["ZodNativeEnum"] = "ZodNativeEnum";
3522
- ZodFirstPartyTypeKind$1["ZodOptional"] = "ZodOptional";
3523
- ZodFirstPartyTypeKind$1["ZodNullable"] = "ZodNullable";
3524
- ZodFirstPartyTypeKind$1["ZodDefault"] = "ZodDefault";
3525
- ZodFirstPartyTypeKind$1["ZodCatch"] = "ZodCatch";
3526
- ZodFirstPartyTypeKind$1["ZodPromise"] = "ZodPromise";
3527
- ZodFirstPartyTypeKind$1["ZodBranded"] = "ZodBranded";
3528
- ZodFirstPartyTypeKind$1["ZodPipeline"] = "ZodPipeline";
3529
- ZodFirstPartyTypeKind$1["ZodReadonly"] = "ZodReadonly";
3016
+ ZodFirstPartyTypeKind$1["ZodString"] = "ZodString", ZodFirstPartyTypeKind$1["ZodNumber"] = "ZodNumber", ZodFirstPartyTypeKind$1["ZodNaN"] = "ZodNaN", ZodFirstPartyTypeKind$1["ZodBigInt"] = "ZodBigInt", ZodFirstPartyTypeKind$1["ZodBoolean"] = "ZodBoolean", ZodFirstPartyTypeKind$1["ZodDate"] = "ZodDate", ZodFirstPartyTypeKind$1["ZodSymbol"] = "ZodSymbol", ZodFirstPartyTypeKind$1["ZodUndefined"] = "ZodUndefined", ZodFirstPartyTypeKind$1["ZodNull"] = "ZodNull", ZodFirstPartyTypeKind$1["ZodAny"] = "ZodAny", ZodFirstPartyTypeKind$1["ZodUnknown"] = "ZodUnknown", ZodFirstPartyTypeKind$1["ZodNever"] = "ZodNever", ZodFirstPartyTypeKind$1["ZodVoid"] = "ZodVoid", ZodFirstPartyTypeKind$1["ZodArray"] = "ZodArray", ZodFirstPartyTypeKind$1["ZodObject"] = "ZodObject", ZodFirstPartyTypeKind$1["ZodUnion"] = "ZodUnion", ZodFirstPartyTypeKind$1["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion", ZodFirstPartyTypeKind$1["ZodIntersection"] = "ZodIntersection", ZodFirstPartyTypeKind$1["ZodTuple"] = "ZodTuple", ZodFirstPartyTypeKind$1["ZodRecord"] = "ZodRecord", ZodFirstPartyTypeKind$1["ZodMap"] = "ZodMap", ZodFirstPartyTypeKind$1["ZodSet"] = "ZodSet", ZodFirstPartyTypeKind$1["ZodFunction"] = "ZodFunction", ZodFirstPartyTypeKind$1["ZodLazy"] = "ZodLazy", ZodFirstPartyTypeKind$1["ZodLiteral"] = "ZodLiteral", ZodFirstPartyTypeKind$1["ZodEnum"] = "ZodEnum", ZodFirstPartyTypeKind$1["ZodEffects"] = "ZodEffects", ZodFirstPartyTypeKind$1["ZodNativeEnum"] = "ZodNativeEnum", ZodFirstPartyTypeKind$1["ZodOptional"] = "ZodOptional", ZodFirstPartyTypeKind$1["ZodNullable"] = "ZodNullable", ZodFirstPartyTypeKind$1["ZodDefault"] = "ZodDefault", ZodFirstPartyTypeKind$1["ZodCatch"] = "ZodCatch", ZodFirstPartyTypeKind$1["ZodPromise"] = "ZodPromise", ZodFirstPartyTypeKind$1["ZodBranded"] = "ZodBranded", ZodFirstPartyTypeKind$1["ZodPipeline"] = "ZodPipeline", ZodFirstPartyTypeKind$1["ZodReadonly"] = "ZodReadonly";
3530
3017
  })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
3531
- const stringType = ZodString.create;
3532
- const numberType = ZodNumber.create;
3533
- const nanType = ZodNaN.create;
3534
- const bigIntType = ZodBigInt.create;
3535
- const booleanType = ZodBoolean.create;
3536
- const dateType = ZodDate.create;
3537
- const symbolType = ZodSymbol.create;
3538
- const undefinedType = ZodUndefined.create;
3539
- const nullType = ZodNull.create;
3540
- const anyType = ZodAny.create;
3541
- const unknownType = ZodUnknown.create;
3542
- const neverType = ZodNever.create;
3543
- const voidType = ZodVoid.create;
3544
- const arrayType = ZodArray.create;
3545
- const objectType = ZodObject.create;
3546
- const strictObjectType = ZodObject.strictCreate;
3547
- const unionType = ZodUnion.create;
3548
- const discriminatedUnionType = ZodDiscriminatedUnion.create;
3549
- const intersectionType = ZodIntersection.create;
3550
- const tupleType = ZodTuple.create;
3551
- const recordType = ZodRecord.create;
3552
- const mapType = ZodMap.create;
3553
- const setType = ZodSet.create;
3554
- const functionType = ZodFunction.create;
3555
- const lazyType = ZodLazy.create;
3556
- const literalType = ZodLiteral.create;
3557
- const enumType = ZodEnum.create;
3558
- const nativeEnumType = ZodNativeEnum.create;
3559
- const promiseType = ZodPromise.create;
3560
- const effectsType = ZodEffects.create;
3561
- const optionalType = ZodOptional.create;
3562
- const nullableType = ZodNullable.create;
3563
- const preprocessType = ZodEffects.createWithPreprocess;
3564
- const pipelineType = ZodPipeline.create;
3565
- /**
3566
- * Branded Zod schemas for type safety using Zod's built-in brand functionality
3567
- */
3568
- const modelNameSchema = stringType().min(1, "Model name cannot be empty").brand();
3569
- const sessionIdSchema = stringType().min(1, "Session ID cannot be empty").brand();
3570
- const requestIdSchema = stringType().min(1, "Request ID cannot be empty").brand();
3571
- const messageIdSchema = stringType().min(1, "Message ID cannot be empty").brand();
3572
- const isoTimestampSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/, "Invalid ISO timestamp").brand();
3573
- const dailyDateSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format").brand();
3574
- const activityDateSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format").brand();
3575
- const monthlyDateSchema = stringType().regex(/^\d{4}-\d{2}$/, "Date must be in YYYY-MM format").brand();
3576
- const weeklyDateSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format").brand();
3577
- const filterDateSchema = stringType().regex(/^\d{8}$/, "Date must be in YYYYMMDD format").brand();
3578
- const projectPathSchema = stringType().min(1, "Project path cannot be empty").brand();
3579
- const versionSchema = stringType().regex(/^\d+\.\d+\.\d+/, "Invalid version format").brand();
3580
- const createSessionId = (value) => sessionIdSchema.parse(value);
3581
- const createDailyDate = (value) => dailyDateSchema.parse(value);
3582
- const createMonthlyDate = (value) => monthlyDateSchema.parse(value);
3583
- const createWeeklyDate = (value) => weeklyDateSchema.parse(value);
3584
- const createProjectPath = (value) => projectPathSchema.parse(value);
3018
+ const stringType = ZodString.create, numberType = ZodNumber.create, nanType = ZodNaN.create, bigIntType = ZodBigInt.create, booleanType = ZodBoolean.create, dateType = ZodDate.create, symbolType = ZodSymbol.create, undefinedType = ZodUndefined.create, nullType = ZodNull.create, anyType = ZodAny.create, unknownType = ZodUnknown.create, neverType = ZodNever.create, voidType = ZodVoid.create, arrayType = ZodArray.create, objectType = ZodObject.create, strictObjectType = ZodObject.strictCreate, unionType = ZodUnion.create, discriminatedUnionType = ZodDiscriminatedUnion.create, intersectionType = ZodIntersection.create, tupleType = ZodTuple.create, recordType = ZodRecord.create, mapType = ZodMap.create, setType = ZodSet.create, functionType = ZodFunction.create, lazyType = ZodLazy.create, literalType = ZodLiteral.create, enumType = ZodEnum.create, nativeEnumType = ZodNativeEnum.create, promiseType = ZodPromise.create, effectsType = ZodEffects.create, optionalType = ZodOptional.create, nullableType = ZodNullable.create, preprocessType = ZodEffects.createWithPreprocess, pipelineType = ZodPipeline.create, modelNameSchema = stringType().min(1, "Model name cannot be empty").brand(), sessionIdSchema = stringType().min(1, "Session ID cannot be empty").brand(), requestIdSchema = stringType().min(1, "Request ID cannot be empty").brand(), messageIdSchema = stringType().min(1, "Message ID cannot be empty").brand(), isoTimestampSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/, "Invalid ISO timestamp").brand(), dailyDateSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format").brand(), activityDateSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format").brand(), monthlyDateSchema = stringType().regex(/^\d{4}-\d{2}$/, "Date must be in YYYY-MM format").brand(), weeklyDateSchema = stringType().regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be in YYYY-MM-DD format").brand(), filterDateSchema = stringType().regex(/^\d{8}$/, "Date must be in YYYYMMDD format").brand(), projectPathSchema = stringType().min(1, "Project path cannot be empty").brand(), versionSchema = stringType().regex(/^\d+\.\d+\.\d+/, "Invalid version format").brand(), createSessionId = (value) => sessionIdSchema.parse(value), createDailyDate = (value) => dailyDateSchema.parse(value), createMonthlyDate = (value) => monthlyDateSchema.parse(value), createWeeklyDate = (value) => weeklyDateSchema.parse(value), createProjectPath = (value) => projectPathSchema.parse(value);
3585
3019
  function createBucket(value) {
3586
- if (weeklyDateSchema.safeParse(value).success) return createWeeklyDate(value);
3587
- return createMonthlyDate(value);
3020
+ return weeklyDateSchema.safeParse(value).success ? createWeeklyDate(value) : createMonthlyDate(value);
3588
3021
  }
3589
- /**
3590
- * Available cost calculation modes
3591
- * - auto: Use pre-calculated costs when available, otherwise calculate from tokens
3592
- * - calculate: Always calculate costs from token counts using model pricing
3593
- * - display: Always use pre-calculated costs, show 0 for missing costs
3594
- */
3595
3022
  const CostModes = [
3596
3023
  "auto",
3597
3024
  "calculate",
3598
3025
  "display"
3599
- ];
3600
- /**
3601
- * Available sort orders for data presentation
3602
- */
3603
- const SortOrders = ["desc", "asc"];
3604
- /**
3605
- * Zod schema for model pricing information from LiteLLM
3606
- */
3607
- const modelPricingSchema = objectType({
3026
+ ], SortOrders = ["desc", "asc"], modelPricingSchema = objectType({
3608
3027
  input_cost_per_token: numberType().optional(),
3609
3028
  output_cost_per_token: numberType().optional(),
3610
3029
  cache_creation_input_token_cost: numberType().optional(),
3611
3030
  cache_read_input_token_cost: numberType().optional()
3612
- });
3613
- /**
3614
- * Zod schema for Claude Code statusline hook JSON data
3615
- */
3616
- const statuslineHookJsonSchema = objectType({
3031
+ }), statuslineHookJsonSchema = objectType({
3617
3032
  session_id: stringType(),
3618
3033
  transcript_path: stringType(),
3619
3034
  cwd: stringType(),