@kevisual/router 0.0.21-beta → 0.0.22

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.
@@ -96,7 +96,7 @@ try {
96
96
 
97
97
  var util$1;
98
98
  (function (util) {
99
- util.assertEqual = (val) => val;
99
+ util.assertEqual = (_) => { };
100
100
  function assertIs(_arg) { }
101
101
  util.assertIs = assertIs;
102
102
  function assertNever(_x) {
@@ -143,11 +143,9 @@ var util$1;
143
143
  };
144
144
  util.isInteger = typeof Number.isInteger === "function"
145
145
  ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
146
- : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
146
+ : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
147
147
  function joinValues(array, separator = " | ") {
148
- return array
149
- .map((val) => (typeof val === "string" ? `'${val}'` : val))
150
- .join(separator);
148
+ return array.map((val) => (typeof val === "string" ? `'${val}'` : val)).join(separator);
151
149
  }
152
150
  util.joinValues = joinValues;
153
151
  util.jsonStringifyReplacer = (_, value) => {
@@ -196,7 +194,7 @@ const getParsedType = (data) => {
196
194
  case "string":
197
195
  return ZodParsedType.string;
198
196
  case "number":
199
- return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
197
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
200
198
  case "boolean":
201
199
  return ZodParsedType.boolean;
202
200
  case "function":
@@ -212,10 +210,7 @@ const getParsedType = (data) => {
212
210
  if (data === null) {
213
211
  return ZodParsedType.null;
214
212
  }
215
- if (data.then &&
216
- typeof data.then === "function" &&
217
- data.catch &&
218
- typeof data.catch === "function") {
213
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
219
214
  return ZodParsedType.promise;
220
215
  }
221
216
  if (typeof Map !== "undefined" && data instanceof Map) {
@@ -251,10 +246,6 @@ const ZodIssueCode = util$1.arrayToEnum([
251
246
  "not_multiple_of",
252
247
  "not_finite",
253
248
  ]);
254
- const quotelessJson = (obj) => {
255
- const json = JSON.stringify(obj, null, 2);
256
- return json.replace(/"([^"]+)":/g, "$1:");
257
- };
258
249
  class ZodError extends Error {
259
250
  get errors() {
260
251
  return this.issues;
@@ -431,17 +422,9 @@ const errorMap = (issue, _ctx) => {
431
422
  else if (issue.type === "string")
432
423
  message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
433
424
  else if (issue.type === "number")
434
- message = `Number must be ${issue.exact
435
- ? `exactly equal to `
436
- : issue.inclusive
437
- ? `greater than or equal to `
438
- : `greater than `}${issue.minimum}`;
425
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
439
426
  else if (issue.type === "date")
440
- message = `Date must be ${issue.exact
441
- ? `exactly equal to `
442
- : issue.inclusive
443
- ? `greater than or equal to `
444
- : `greater than `}${new Date(Number(issue.minimum))}`;
427
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
445
428
  else
446
429
  message = "Invalid input";
447
430
  break;
@@ -451,23 +434,11 @@ const errorMap = (issue, _ctx) => {
451
434
  else if (issue.type === "string")
452
435
  message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
453
436
  else if (issue.type === "number")
454
- message = `Number must be ${issue.exact
455
- ? `exactly`
456
- : issue.inclusive
457
- ? `less than or equal to`
458
- : `less than`} ${issue.maximum}`;
437
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
459
438
  else if (issue.type === "bigint")
460
- message = `BigInt must be ${issue.exact
461
- ? `exactly`
462
- : issue.inclusive
463
- ? `less than or equal to`
464
- : `less than`} ${issue.maximum}`;
439
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
465
440
  else if (issue.type === "date")
466
- message = `Date must be ${issue.exact
467
- ? `exactly`
468
- : issue.inclusive
469
- ? `smaller than or equal to`
470
- : `smaller than`} ${new Date(Number(issue.maximum))}`;
441
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
471
442
  else
472
443
  message = "Invalid input";
473
444
  break;
@@ -491,9 +462,6 @@ const errorMap = (issue, _ctx) => {
491
462
  };
492
463
 
493
464
  let overrideErrorMap = errorMap;
494
- function setErrorMap(map) {
495
- overrideErrorMap = map;
496
- }
497
465
  function getErrorMap() {
498
466
  return overrideErrorMap;
499
467
  }
@@ -526,7 +494,6 @@ const makeIssue = (params) => {
526
494
  message: errorMessage,
527
495
  };
528
496
  };
529
- const EMPTY_PATH = [];
530
497
  function addIssueToContext(ctx, issueData) {
531
498
  const overrideMap = getErrorMap();
532
499
  const issue = makeIssue({
@@ -589,8 +556,7 @@ class ParseStatus {
589
556
  status.dirty();
590
557
  if (value.status === "dirty")
591
558
  status.dirty();
592
- if (key.value !== "__proto__" &&
593
- (typeof value.value !== "undefined" || pair.alwaysSet)) {
559
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
594
560
  finalObject[key.value] = value.value;
595
561
  }
596
562
  }
@@ -607,43 +573,13 @@ const isDirty = (x) => x.status === "dirty";
607
573
  const isValid = (x) => x.status === "valid";
608
574
  const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
609
575
 
610
- /******************************************************************************
611
- Copyright (c) Microsoft Corporation.
612
-
613
- Permission to use, copy, modify, and/or distribute this software for any
614
- purpose with or without fee is hereby granted.
615
-
616
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
617
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
618
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
619
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
620
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
621
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
622
- PERFORMANCE OF THIS SOFTWARE.
623
- ***************************************************************************** */
624
-
625
- function __classPrivateFieldGet(receiver, state, kind, f) {
626
- if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
627
- return state.get(receiver);
628
- }
629
-
630
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
631
- if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
632
- return (state.set(receiver, value)), value;
633
- }
634
-
635
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
636
- var e = new Error(message);
637
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
638
- };
639
-
640
576
  var errorUtil;
641
577
  (function (errorUtil) {
642
578
  errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
643
- errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
579
+ // biome-ignore lint:
580
+ errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
644
581
  })(errorUtil || (errorUtil = {}));
645
582
 
646
- var _ZodEnum_cache, _ZodNativeEnum_cache;
647
583
  class ParseInputLazyPath {
648
584
  constructor(parent, value, path, key) {
649
585
  this._cachedPath = [];
@@ -654,7 +590,7 @@ class ParseInputLazyPath {
654
590
  }
655
591
  get path() {
656
592
  if (!this._cachedPath.length) {
657
- if (this._key instanceof Array) {
593
+ if (Array.isArray(this._key)) {
658
594
  this._cachedPath.push(...this._path, ...this._key);
659
595
  }
660
596
  else {
@@ -694,17 +630,16 @@ function processCreateParams(params) {
694
630
  if (errorMap)
695
631
  return { errorMap: errorMap, description };
696
632
  const customMap = (iss, ctx) => {
697
- var _a, _b;
698
633
  const { message } = params;
699
634
  if (iss.code === "invalid_enum_value") {
700
- return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
635
+ return { message: message ?? ctx.defaultError };
701
636
  }
702
637
  if (typeof ctx.data === "undefined") {
703
- return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
638
+ return { message: message ?? required_error ?? ctx.defaultError };
704
639
  }
705
640
  if (iss.code !== "invalid_type")
706
641
  return { message: ctx.defaultError };
707
- return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
642
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
708
643
  };
709
644
  return { errorMap: customMap, description };
710
645
  }
@@ -756,14 +691,13 @@ class ZodType {
756
691
  throw result.error;
757
692
  }
758
693
  safeParse(data, params) {
759
- var _a;
760
694
  const ctx = {
761
695
  common: {
762
696
  issues: [],
763
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
764
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
697
+ async: params?.async ?? false,
698
+ contextualErrorMap: params?.errorMap,
765
699
  },
766
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
700
+ path: params?.path || [],
767
701
  schemaErrorMap: this._def.errorMap,
768
702
  parent: null,
769
703
  data,
@@ -773,7 +707,6 @@ class ZodType {
773
707
  return handleResult(ctx, result);
774
708
  }
775
709
  "~validate"(data) {
776
- var _a, _b;
777
710
  const ctx = {
778
711
  common: {
779
712
  issues: [],
@@ -797,7 +730,7 @@ class ZodType {
797
730
  };
798
731
  }
799
732
  catch (err) {
800
- if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
733
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
801
734
  this["~standard"].async = true;
802
735
  }
803
736
  ctx.common = {
@@ -824,19 +757,17 @@ class ZodType {
824
757
  const ctx = {
825
758
  common: {
826
759
  issues: [],
827
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
760
+ contextualErrorMap: params?.errorMap,
828
761
  async: true,
829
762
  },
830
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
763
+ path: params?.path || [],
831
764
  schemaErrorMap: this._def.errorMap,
832
765
  parent: null,
833
766
  data,
834
767
  parsedType: getParsedType(data),
835
768
  };
836
769
  const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
837
- const result = await (isAsync(maybeAsyncResult)
838
- ? maybeAsyncResult
839
- : Promise.resolve(maybeAsyncResult));
770
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
840
771
  return handleResult(ctx, result);
841
772
  }
842
773
  refine(check, message) {
@@ -880,9 +811,7 @@ class ZodType {
880
811
  refinement(check, refinementData) {
881
812
  return this._refinement((val, ctx) => {
882
813
  if (!check(val)) {
883
- ctx.addIssue(typeof refinementData === "function"
884
- ? refinementData(val, ctx)
885
- : refinementData);
814
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
886
815
  return false;
887
816
  }
888
817
  else {
@@ -1099,13 +1028,15 @@ function isValidJWT(jwt, alg) {
1099
1028
  const decoded = JSON.parse(atob(base64));
1100
1029
  if (typeof decoded !== "object" || decoded === null)
1101
1030
  return false;
1102
- if (!decoded.typ || !decoded.alg)
1031
+ if ("typ" in decoded && decoded?.typ !== "JWT")
1032
+ return false;
1033
+ if (!decoded.alg)
1103
1034
  return false;
1104
1035
  if (alg && decoded.alg !== alg)
1105
1036
  return false;
1106
1037
  return true;
1107
1038
  }
1108
- catch (_a) {
1039
+ catch {
1109
1040
  return false;
1110
1041
  }
1111
1042
  }
@@ -1276,7 +1207,7 @@ class ZodString extends ZodType {
1276
1207
  try {
1277
1208
  new URL(input.data);
1278
1209
  }
1279
- catch (_a) {
1210
+ catch {
1280
1211
  ctx = this._getOrReturnCtx(input, ctx);
1281
1212
  addIssueToContext(ctx, {
1282
1213
  validation: "url",
@@ -1506,7 +1437,6 @@ class ZodString extends ZodType {
1506
1437
  return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1507
1438
  }
1508
1439
  datetime(options) {
1509
- var _a, _b;
1510
1440
  if (typeof options === "string") {
1511
1441
  return this._addCheck({
1512
1442
  kind: "datetime",
@@ -1518,10 +1448,10 @@ class ZodString extends ZodType {
1518
1448
  }
1519
1449
  return this._addCheck({
1520
1450
  kind: "datetime",
1521
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1522
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
1523
- local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
1524
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1451
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1452
+ offset: options?.offset ?? false,
1453
+ local: options?.local ?? false,
1454
+ ...errorUtil.errToObj(options?.message),
1525
1455
  });
1526
1456
  }
1527
1457
  date(message) {
@@ -1537,8 +1467,8 @@ class ZodString extends ZodType {
1537
1467
  }
1538
1468
  return this._addCheck({
1539
1469
  kind: "time",
1540
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1541
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1470
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1471
+ ...errorUtil.errToObj(options?.message),
1542
1472
  });
1543
1473
  }
1544
1474
  duration(message) {
@@ -1555,8 +1485,8 @@ class ZodString extends ZodType {
1555
1485
  return this._addCheck({
1556
1486
  kind: "includes",
1557
1487
  value: value,
1558
- position: options === null || options === void 0 ? void 0 : options.position,
1559
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1488
+ position: options?.position,
1489
+ ...errorUtil.errToObj(options?.message),
1560
1490
  });
1561
1491
  }
1562
1492
  startsWith(value, message) {
@@ -1689,11 +1619,10 @@ class ZodString extends ZodType {
1689
1619
  }
1690
1620
  }
1691
1621
  ZodString.create = (params) => {
1692
- var _a;
1693
1622
  return new ZodString({
1694
1623
  checks: [],
1695
1624
  typeName: ZodFirstPartyTypeKind.ZodString,
1696
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1625
+ coerce: params?.coerce ?? false,
1697
1626
  ...processCreateParams(params),
1698
1627
  });
1699
1628
  };
@@ -1702,9 +1631,9 @@ function floatSafeRemainder(val, step) {
1702
1631
  const valDecCount = (val.toString().split(".")[1] || "").length;
1703
1632
  const stepDecCount = (step.toString().split(".")[1] || "").length;
1704
1633
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1705
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
1706
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
1707
- return (valInt % stepInt) / Math.pow(10, decCount);
1634
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1635
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1636
+ return (valInt % stepInt) / 10 ** decCount;
1708
1637
  }
1709
1638
  class ZodNumber extends ZodType {
1710
1639
  constructor() {
@@ -1743,9 +1672,7 @@ class ZodNumber extends ZodType {
1743
1672
  }
1744
1673
  }
1745
1674
  else if (check.kind === "min") {
1746
- const tooSmall = check.inclusive
1747
- ? input.data < check.value
1748
- : input.data <= check.value;
1675
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1749
1676
  if (tooSmall) {
1750
1677
  ctx = this._getOrReturnCtx(input, ctx);
1751
1678
  addIssueToContext(ctx, {
@@ -1760,9 +1687,7 @@ class ZodNumber extends ZodType {
1760
1687
  }
1761
1688
  }
1762
1689
  else if (check.kind === "max") {
1763
- const tooBig = check.inclusive
1764
- ? input.data > check.value
1765
- : input.data >= check.value;
1690
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1766
1691
  if (tooBig) {
1767
1692
  ctx = this._getOrReturnCtx(input, ctx);
1768
1693
  addIssueToContext(ctx, {
@@ -1920,15 +1845,13 @@ class ZodNumber extends ZodType {
1920
1845
  return max;
1921
1846
  }
1922
1847
  get isInt() {
1923
- return !!this._def.checks.find((ch) => ch.kind === "int" ||
1924
- (ch.kind === "multipleOf" && util$1.isInteger(ch.value)));
1848
+ return !!this._def.checks.find((ch) => ch.kind === "int" || (ch.kind === "multipleOf" && util$1.isInteger(ch.value)));
1925
1849
  }
1926
1850
  get isFinite() {
1927
- let max = null, min = null;
1851
+ let max = null;
1852
+ let min = null;
1928
1853
  for (const ch of this._def.checks) {
1929
- if (ch.kind === "finite" ||
1930
- ch.kind === "int" ||
1931
- ch.kind === "multipleOf") {
1854
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
1932
1855
  return true;
1933
1856
  }
1934
1857
  else if (ch.kind === "min") {
@@ -1947,7 +1870,7 @@ ZodNumber.create = (params) => {
1947
1870
  return new ZodNumber({
1948
1871
  checks: [],
1949
1872
  typeName: ZodFirstPartyTypeKind.ZodNumber,
1950
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1873
+ coerce: params?.coerce || false,
1951
1874
  ...processCreateParams(params),
1952
1875
  });
1953
1876
  };
@@ -1962,7 +1885,7 @@ class ZodBigInt extends ZodType {
1962
1885
  try {
1963
1886
  input.data = BigInt(input.data);
1964
1887
  }
1965
- catch (_a) {
1888
+ catch {
1966
1889
  return this._getInvalidInput(input);
1967
1890
  }
1968
1891
  }
@@ -1974,9 +1897,7 @@ class ZodBigInt extends ZodType {
1974
1897
  const status = new ParseStatus();
1975
1898
  for (const check of this._def.checks) {
1976
1899
  if (check.kind === "min") {
1977
- const tooSmall = check.inclusive
1978
- ? input.data < check.value
1979
- : input.data <= check.value;
1900
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1980
1901
  if (tooSmall) {
1981
1902
  ctx = this._getOrReturnCtx(input, ctx);
1982
1903
  addIssueToContext(ctx, {
@@ -1990,9 +1911,7 @@ class ZodBigInt extends ZodType {
1990
1911
  }
1991
1912
  }
1992
1913
  else if (check.kind === "max") {
1993
- const tooBig = check.inclusive
1994
- ? input.data > check.value
1995
- : input.data >= check.value;
1914
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1996
1915
  if (tooBig) {
1997
1916
  ctx = this._getOrReturnCtx(input, ctx);
1998
1917
  addIssueToContext(ctx, {
@@ -2124,11 +2043,10 @@ class ZodBigInt extends ZodType {
2124
2043
  }
2125
2044
  }
2126
2045
  ZodBigInt.create = (params) => {
2127
- var _a;
2128
2046
  return new ZodBigInt({
2129
2047
  checks: [],
2130
2048
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
2131
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
2049
+ coerce: params?.coerce ?? false,
2132
2050
  ...processCreateParams(params),
2133
2051
  });
2134
2052
  };
@@ -2153,7 +2071,7 @@ class ZodBoolean extends ZodType {
2153
2071
  ZodBoolean.create = (params) => {
2154
2072
  return new ZodBoolean({
2155
2073
  typeName: ZodFirstPartyTypeKind.ZodBoolean,
2156
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2074
+ coerce: params?.coerce || false,
2157
2075
  ...processCreateParams(params),
2158
2076
  });
2159
2077
  };
@@ -2172,7 +2090,7 @@ class ZodDate extends ZodType {
2172
2090
  });
2173
2091
  return INVALID;
2174
2092
  }
2175
- if (isNaN(input.data.getTime())) {
2093
+ if (Number.isNaN(input.data.getTime())) {
2176
2094
  const ctx = this._getOrReturnCtx(input);
2177
2095
  addIssueToContext(ctx, {
2178
2096
  code: ZodIssueCode.invalid_date,
@@ -2263,7 +2181,7 @@ class ZodDate extends ZodType {
2263
2181
  ZodDate.create = (params) => {
2264
2182
  return new ZodDate({
2265
2183
  checks: [],
2266
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2184
+ coerce: params?.coerce || false,
2267
2185
  typeName: ZodFirstPartyTypeKind.ZodDate,
2268
2186
  ...processCreateParams(params),
2269
2187
  });
@@ -2585,7 +2503,8 @@ class ZodObject extends ZodType {
2585
2503
  return this._cached;
2586
2504
  const shape = this._def.shape();
2587
2505
  const keys = util$1.objectKeys(shape);
2588
- return (this._cached = { shape, keys });
2506
+ this._cached = { shape, keys };
2507
+ return this._cached;
2589
2508
  }
2590
2509
  _parse(input) {
2591
2510
  const parsedType = this._getType(input);
@@ -2601,8 +2520,7 @@ class ZodObject extends ZodType {
2601
2520
  const { status, ctx } = this._processInputParams(input);
2602
2521
  const { shape, keys: shapeKeys } = this._getCached();
2603
2522
  const extraKeys = [];
2604
- if (!(this._def.catchall instanceof ZodNever &&
2605
- this._def.unknownKeys === "strip")) {
2523
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2606
2524
  for (const key in ctx.data) {
2607
2525
  if (!shapeKeys.includes(key)) {
2608
2526
  extraKeys.push(key);
@@ -2690,11 +2608,10 @@ class ZodObject extends ZodType {
2690
2608
  ...(message !== undefined
2691
2609
  ? {
2692
2610
  errorMap: (issue, ctx) => {
2693
- var _a, _b, _c, _d;
2694
- const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
2611
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2695
2612
  if (issue.code === "unrecognized_keys")
2696
2613
  return {
2697
- message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
2614
+ message: errorUtil.errToObj(message).message ?? defaultError,
2698
2615
  };
2699
2616
  return {
2700
2617
  message: defaultError,
@@ -2826,11 +2743,11 @@ class ZodObject extends ZodType {
2826
2743
  }
2827
2744
  pick(mask) {
2828
2745
  const shape = {};
2829
- util$1.objectKeys(mask).forEach((key) => {
2746
+ for (const key of util$1.objectKeys(mask)) {
2830
2747
  if (mask[key] && this.shape[key]) {
2831
2748
  shape[key] = this.shape[key];
2832
2749
  }
2833
- });
2750
+ }
2834
2751
  return new ZodObject({
2835
2752
  ...this._def,
2836
2753
  shape: () => shape,
@@ -2838,11 +2755,11 @@ class ZodObject extends ZodType {
2838
2755
  }
2839
2756
  omit(mask) {
2840
2757
  const shape = {};
2841
- util$1.objectKeys(this.shape).forEach((key) => {
2758
+ for (const key of util$1.objectKeys(this.shape)) {
2842
2759
  if (!mask[key]) {
2843
2760
  shape[key] = this.shape[key];
2844
2761
  }
2845
- });
2762
+ }
2846
2763
  return new ZodObject({
2847
2764
  ...this._def,
2848
2765
  shape: () => shape,
@@ -2856,7 +2773,7 @@ class ZodObject extends ZodType {
2856
2773
  }
2857
2774
  partial(mask) {
2858
2775
  const newShape = {};
2859
- util$1.objectKeys(this.shape).forEach((key) => {
2776
+ for (const key of util$1.objectKeys(this.shape)) {
2860
2777
  const fieldSchema = this.shape[key];
2861
2778
  if (mask && !mask[key]) {
2862
2779
  newShape[key] = fieldSchema;
@@ -2864,7 +2781,7 @@ class ZodObject extends ZodType {
2864
2781
  else {
2865
2782
  newShape[key] = fieldSchema.optional();
2866
2783
  }
2867
- });
2784
+ }
2868
2785
  return new ZodObject({
2869
2786
  ...this._def,
2870
2787
  shape: () => newShape,
@@ -2872,7 +2789,7 @@ class ZodObject extends ZodType {
2872
2789
  }
2873
2790
  required(mask) {
2874
2791
  const newShape = {};
2875
- util$1.objectKeys(this.shape).forEach((key) => {
2792
+ for (const key of util$1.objectKeys(this.shape)) {
2876
2793
  if (mask && !mask[key]) {
2877
2794
  newShape[key] = this.shape[key];
2878
2795
  }
@@ -2884,7 +2801,7 @@ class ZodObject extends ZodType {
2884
2801
  }
2885
2802
  newShape[key] = newField;
2886
2803
  }
2887
- });
2804
+ }
2888
2805
  return new ZodObject({
2889
2806
  ...this._def,
2890
2807
  shape: () => newShape,
@@ -3017,137 +2934,6 @@ ZodUnion.create = (types, params) => {
3017
2934
  ...processCreateParams(params),
3018
2935
  });
3019
2936
  };
3020
- /////////////////////////////////////////////////////
3021
- /////////////////////////////////////////////////////
3022
- ////////// //////////
3023
- ////////// ZodDiscriminatedUnion //////////
3024
- ////////// //////////
3025
- /////////////////////////////////////////////////////
3026
- /////////////////////////////////////////////////////
3027
- const getDiscriminator = (type) => {
3028
- if (type instanceof ZodLazy) {
3029
- return getDiscriminator(type.schema);
3030
- }
3031
- else if (type instanceof ZodEffects) {
3032
- return getDiscriminator(type.innerType());
3033
- }
3034
- else if (type instanceof ZodLiteral) {
3035
- return [type.value];
3036
- }
3037
- else if (type instanceof ZodEnum) {
3038
- return type.options;
3039
- }
3040
- else if (type instanceof ZodNativeEnum) {
3041
- // eslint-disable-next-line ban/ban
3042
- return util$1.objectValues(type.enum);
3043
- }
3044
- else if (type instanceof ZodDefault) {
3045
- return getDiscriminator(type._def.innerType);
3046
- }
3047
- else if (type instanceof ZodUndefined) {
3048
- return [undefined];
3049
- }
3050
- else if (type instanceof ZodNull) {
3051
- return [null];
3052
- }
3053
- else if (type instanceof ZodOptional) {
3054
- return [undefined, ...getDiscriminator(type.unwrap())];
3055
- }
3056
- else if (type instanceof ZodNullable) {
3057
- return [null, ...getDiscriminator(type.unwrap())];
3058
- }
3059
- else if (type instanceof ZodBranded) {
3060
- return getDiscriminator(type.unwrap());
3061
- }
3062
- else if (type instanceof ZodReadonly) {
3063
- return getDiscriminator(type.unwrap());
3064
- }
3065
- else if (type instanceof ZodCatch) {
3066
- return getDiscriminator(type._def.innerType);
3067
- }
3068
- else {
3069
- return [];
3070
- }
3071
- };
3072
- class ZodDiscriminatedUnion extends ZodType {
3073
- _parse(input) {
3074
- const { ctx } = this._processInputParams(input);
3075
- if (ctx.parsedType !== ZodParsedType.object) {
3076
- addIssueToContext(ctx, {
3077
- code: ZodIssueCode.invalid_type,
3078
- expected: ZodParsedType.object,
3079
- received: ctx.parsedType,
3080
- });
3081
- return INVALID;
3082
- }
3083
- const discriminator = this.discriminator;
3084
- const discriminatorValue = ctx.data[discriminator];
3085
- const option = this.optionsMap.get(discriminatorValue);
3086
- if (!option) {
3087
- addIssueToContext(ctx, {
3088
- code: ZodIssueCode.invalid_union_discriminator,
3089
- options: Array.from(this.optionsMap.keys()),
3090
- path: [discriminator],
3091
- });
3092
- return INVALID;
3093
- }
3094
- if (ctx.common.async) {
3095
- return option._parseAsync({
3096
- data: ctx.data,
3097
- path: ctx.path,
3098
- parent: ctx,
3099
- });
3100
- }
3101
- else {
3102
- return option._parseSync({
3103
- data: ctx.data,
3104
- path: ctx.path,
3105
- parent: ctx,
3106
- });
3107
- }
3108
- }
3109
- get discriminator() {
3110
- return this._def.discriminator;
3111
- }
3112
- get options() {
3113
- return this._def.options;
3114
- }
3115
- get optionsMap() {
3116
- return this._def.optionsMap;
3117
- }
3118
- /**
3119
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
3120
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
3121
- * have a different value for each object in the union.
3122
- * @param discriminator the name of the discriminator property
3123
- * @param types an array of object schemas
3124
- * @param params
3125
- */
3126
- static create(discriminator, options, params) {
3127
- // Get all the valid discriminator values
3128
- const optionsMap = new Map();
3129
- // try {
3130
- for (const type of options) {
3131
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3132
- if (!discriminatorValues.length) {
3133
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3134
- }
3135
- for (const value of discriminatorValues) {
3136
- if (optionsMap.has(value)) {
3137
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
3138
- }
3139
- optionsMap.set(value, type);
3140
- }
3141
- }
3142
- return new ZodDiscriminatedUnion({
3143
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
3144
- discriminator,
3145
- options,
3146
- optionsMap,
3147
- ...processCreateParams(params),
3148
- });
3149
- }
3150
- }
3151
2937
  function mergeValues(a, b) {
3152
2938
  const aType = getParsedType(a);
3153
2939
  const bType = getParsedType(b);
@@ -3156,9 +2942,7 @@ function mergeValues(a, b) {
3156
2942
  }
3157
2943
  else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
3158
2944
  const bKeys = util$1.objectKeys(b);
3159
- const sharedKeys = util$1
3160
- .objectKeys(a)
3161
- .filter((key) => bKeys.indexOf(key) !== -1);
2945
+ const sharedKeys = util$1.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
3162
2946
  const newObj = { ...a, ...b };
3163
2947
  for (const key of sharedKeys) {
3164
2948
  const sharedValue = mergeValues(a[key], b[key]);
@@ -3185,9 +2969,7 @@ function mergeValues(a, b) {
3185
2969
  }
3186
2970
  return { valid: true, data: newArray };
3187
2971
  }
3188
- else if (aType === ZodParsedType.date &&
3189
- bType === ZodParsedType.date &&
3190
- +a === +b) {
2972
+ else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
3191
2973
  return { valid: true, data: a };
3192
2974
  }
3193
2975
  else {
@@ -3248,6 +3030,7 @@ ZodIntersection.create = (left, right, params) => {
3248
3030
  ...processCreateParams(params),
3249
3031
  });
3250
3032
  };
3033
+ // type ZodTupleItems = [ZodTypeAny, ...ZodTypeAny[]];
3251
3034
  class ZodTuple extends ZodType {
3252
3035
  _parse(input) {
3253
3036
  const { status, ctx } = this._processInputParams(input);
@@ -3318,60 +3101,6 @@ ZodTuple.create = (schemas, params) => {
3318
3101
  ...processCreateParams(params),
3319
3102
  });
3320
3103
  };
3321
- class ZodRecord extends ZodType {
3322
- get keySchema() {
3323
- return this._def.keyType;
3324
- }
3325
- get valueSchema() {
3326
- return this._def.valueType;
3327
- }
3328
- _parse(input) {
3329
- const { status, ctx } = this._processInputParams(input);
3330
- if (ctx.parsedType !== ZodParsedType.object) {
3331
- addIssueToContext(ctx, {
3332
- code: ZodIssueCode.invalid_type,
3333
- expected: ZodParsedType.object,
3334
- received: ctx.parsedType,
3335
- });
3336
- return INVALID;
3337
- }
3338
- const pairs = [];
3339
- const keyType = this._def.keyType;
3340
- const valueType = this._def.valueType;
3341
- for (const key in ctx.data) {
3342
- pairs.push({
3343
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3344
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3345
- alwaysSet: key in ctx.data,
3346
- });
3347
- }
3348
- if (ctx.common.async) {
3349
- return ParseStatus.mergeObjectAsync(status, pairs);
3350
- }
3351
- else {
3352
- return ParseStatus.mergeObjectSync(status, pairs);
3353
- }
3354
- }
3355
- get element() {
3356
- return this._def.valueType;
3357
- }
3358
- static create(first, second, third) {
3359
- if (second instanceof ZodType) {
3360
- return new ZodRecord({
3361
- keyType: first,
3362
- valueType: second,
3363
- typeName: ZodFirstPartyTypeKind.ZodRecord,
3364
- ...processCreateParams(third),
3365
- });
3366
- }
3367
- return new ZodRecord({
3368
- keyType: ZodString.create(),
3369
- valueType: first,
3370
- typeName: ZodFirstPartyTypeKind.ZodRecord,
3371
- ...processCreateParams(second),
3372
- });
3373
- }
3374
- }
3375
3104
  class ZodMap extends ZodType {
3376
3105
  get keySchema() {
3377
3106
  return this._def.keyType;
@@ -3525,134 +3254,6 @@ ZodSet.create = (valueType, params) => {
3525
3254
  ...processCreateParams(params),
3526
3255
  });
3527
3256
  };
3528
- class ZodFunction extends ZodType {
3529
- constructor() {
3530
- super(...arguments);
3531
- this.validate = this.implement;
3532
- }
3533
- _parse(input) {
3534
- const { ctx } = this._processInputParams(input);
3535
- if (ctx.parsedType !== ZodParsedType.function) {
3536
- addIssueToContext(ctx, {
3537
- code: ZodIssueCode.invalid_type,
3538
- expected: ZodParsedType.function,
3539
- received: ctx.parsedType,
3540
- });
3541
- return INVALID;
3542
- }
3543
- function makeArgsIssue(args, error) {
3544
- return makeIssue({
3545
- data: args,
3546
- path: ctx.path,
3547
- errorMaps: [
3548
- ctx.common.contextualErrorMap,
3549
- ctx.schemaErrorMap,
3550
- getErrorMap(),
3551
- errorMap,
3552
- ].filter((x) => !!x),
3553
- issueData: {
3554
- code: ZodIssueCode.invalid_arguments,
3555
- argumentsError: error,
3556
- },
3557
- });
3558
- }
3559
- function makeReturnsIssue(returns, error) {
3560
- return makeIssue({
3561
- data: returns,
3562
- path: ctx.path,
3563
- errorMaps: [
3564
- ctx.common.contextualErrorMap,
3565
- ctx.schemaErrorMap,
3566
- getErrorMap(),
3567
- errorMap,
3568
- ].filter((x) => !!x),
3569
- issueData: {
3570
- code: ZodIssueCode.invalid_return_type,
3571
- returnTypeError: error,
3572
- },
3573
- });
3574
- }
3575
- const params = { errorMap: ctx.common.contextualErrorMap };
3576
- const fn = ctx.data;
3577
- if (this._def.returns instanceof ZodPromise) {
3578
- // Would love a way to avoid disabling this rule, but we need
3579
- // an alias (using an arrow function was what caused 2651).
3580
- // eslint-disable-next-line @typescript-eslint/no-this-alias
3581
- const me = this;
3582
- return OK(async function (...args) {
3583
- const error = new ZodError([]);
3584
- const parsedArgs = await me._def.args
3585
- .parseAsync(args, params)
3586
- .catch((e) => {
3587
- error.addIssue(makeArgsIssue(args, e));
3588
- throw error;
3589
- });
3590
- const result = await Reflect.apply(fn, this, parsedArgs);
3591
- const parsedReturns = await me._def.returns._def.type
3592
- .parseAsync(result, params)
3593
- .catch((e) => {
3594
- error.addIssue(makeReturnsIssue(result, e));
3595
- throw error;
3596
- });
3597
- return parsedReturns;
3598
- });
3599
- }
3600
- else {
3601
- // Would love a way to avoid disabling this rule, but we need
3602
- // an alias (using an arrow function was what caused 2651).
3603
- // eslint-disable-next-line @typescript-eslint/no-this-alias
3604
- const me = this;
3605
- return OK(function (...args) {
3606
- const parsedArgs = me._def.args.safeParse(args, params);
3607
- if (!parsedArgs.success) {
3608
- throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3609
- }
3610
- const result = Reflect.apply(fn, this, parsedArgs.data);
3611
- const parsedReturns = me._def.returns.safeParse(result, params);
3612
- if (!parsedReturns.success) {
3613
- throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3614
- }
3615
- return parsedReturns.data;
3616
- });
3617
- }
3618
- }
3619
- parameters() {
3620
- return this._def.args;
3621
- }
3622
- returnType() {
3623
- return this._def.returns;
3624
- }
3625
- args(...items) {
3626
- return new ZodFunction({
3627
- ...this._def,
3628
- args: ZodTuple.create(items).rest(ZodUnknown.create()),
3629
- });
3630
- }
3631
- returns(returnType) {
3632
- return new ZodFunction({
3633
- ...this._def,
3634
- returns: returnType,
3635
- });
3636
- }
3637
- implement(func) {
3638
- const validatedFunc = this.parse(func);
3639
- return validatedFunc;
3640
- }
3641
- strictImplement(func) {
3642
- const validatedFunc = this.parse(func);
3643
- return validatedFunc;
3644
- }
3645
- static create(args, returns, params) {
3646
- return new ZodFunction({
3647
- args: (args
3648
- ? args
3649
- : ZodTuple.create([]).rest(ZodUnknown.create())),
3650
- returns: returns || ZodUnknown.create(),
3651
- typeName: ZodFirstPartyTypeKind.ZodFunction,
3652
- ...processCreateParams(params),
3653
- });
3654
- }
3655
- }
3656
3257
  class ZodLazy extends ZodType {
3657
3258
  get schema() {
3658
3259
  return this._def.getter();
@@ -3702,10 +3303,6 @@ function createZodEnum(values, params) {
3702
3303
  });
3703
3304
  }
3704
3305
  class ZodEnum extends ZodType {
3705
- constructor() {
3706
- super(...arguments);
3707
- _ZodEnum_cache.set(this, void 0);
3708
- }
3709
3306
  _parse(input) {
3710
3307
  if (typeof input.data !== "string") {
3711
3308
  const ctx = this._getOrReturnCtx(input);
@@ -3717,10 +3314,10 @@ class ZodEnum extends ZodType {
3717
3314
  });
3718
3315
  return INVALID;
3719
3316
  }
3720
- if (!__classPrivateFieldGet(this, _ZodEnum_cache)) {
3721
- __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values));
3317
+ if (!this._cache) {
3318
+ this._cache = new Set(this._def.values);
3722
3319
  }
3723
- if (!__classPrivateFieldGet(this, _ZodEnum_cache).has(input.data)) {
3320
+ if (!this._cache.has(input.data)) {
3724
3321
  const ctx = this._getOrReturnCtx(input);
3725
3322
  const expectedValues = this._def.values;
3726
3323
  addIssueToContext(ctx, {
@@ -3769,18 +3366,12 @@ class ZodEnum extends ZodType {
3769
3366
  });
3770
3367
  }
3771
3368
  }
3772
- _ZodEnum_cache = new WeakMap();
3773
3369
  ZodEnum.create = createZodEnum;
3774
3370
  class ZodNativeEnum extends ZodType {
3775
- constructor() {
3776
- super(...arguments);
3777
- _ZodNativeEnum_cache.set(this, void 0);
3778
- }
3779
3371
  _parse(input) {
3780
3372
  const nativeEnumValues = util$1.getValidEnumValues(this._def.values);
3781
3373
  const ctx = this._getOrReturnCtx(input);
3782
- if (ctx.parsedType !== ZodParsedType.string &&
3783
- ctx.parsedType !== ZodParsedType.number) {
3374
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3784
3375
  const expectedValues = util$1.objectValues(nativeEnumValues);
3785
3376
  addIssueToContext(ctx, {
3786
3377
  expected: util$1.joinValues(expectedValues),
@@ -3789,10 +3380,10 @@ class ZodNativeEnum extends ZodType {
3789
3380
  });
3790
3381
  return INVALID;
3791
3382
  }
3792
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache)) {
3793
- __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util$1.getValidEnumValues(this._def.values)));
3383
+ if (!this._cache) {
3384
+ this._cache = new Set(util$1.getValidEnumValues(this._def.values));
3794
3385
  }
3795
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache).has(input.data)) {
3386
+ if (!this._cache.has(input.data)) {
3796
3387
  const expectedValues = util$1.objectValues(nativeEnumValues);
3797
3388
  addIssueToContext(ctx, {
3798
3389
  received: ctx.data,
@@ -3807,7 +3398,6 @@ class ZodNativeEnum extends ZodType {
3807
3398
  return this._def.values;
3808
3399
  }
3809
3400
  }
3810
- _ZodNativeEnum_cache = new WeakMap();
3811
3401
  ZodNativeEnum.create = (values, params) => {
3812
3402
  return new ZodNativeEnum({
3813
3403
  values: values,
@@ -3821,8 +3411,7 @@ class ZodPromise extends ZodType {
3821
3411
  }
3822
3412
  _parse(input) {
3823
3413
  const { ctx } = this._processInputParams(input);
3824
- if (ctx.parsedType !== ZodParsedType.promise &&
3825
- ctx.common.async === false) {
3414
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3826
3415
  addIssueToContext(ctx, {
3827
3416
  code: ZodIssueCode.invalid_type,
3828
3417
  expected: ZodParsedType.promise,
@@ -3830,9 +3419,7 @@ class ZodPromise extends ZodType {
3830
3419
  });
3831
3420
  return INVALID;
3832
3421
  }
3833
- const promisified = ctx.parsedType === ZodParsedType.promise
3834
- ? ctx.data
3835
- : Promise.resolve(ctx.data);
3422
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3836
3423
  return OK(promisified.then((data) => {
3837
3424
  return this._def.type.parseAsync(data, {
3838
3425
  path: ctx.path,
@@ -3938,9 +3525,7 @@ class ZodEffects extends ZodType {
3938
3525
  return { status: status.value, value: inner.value };
3939
3526
  }
3940
3527
  else {
3941
- return this._def.schema
3942
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3943
- .then((inner) => {
3528
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
3944
3529
  if (inner.status === "aborted")
3945
3530
  return INVALID;
3946
3531
  if (inner.status === "dirty")
@@ -3959,7 +3544,7 @@ class ZodEffects extends ZodType {
3959
3544
  parent: ctx,
3960
3545
  });
3961
3546
  if (!isValid(base))
3962
- return base;
3547
+ return INVALID;
3963
3548
  const result = effect.transform(base.value, checkCtx);
3964
3549
  if (result instanceof Promise) {
3965
3550
  throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
@@ -3967,12 +3552,13 @@ class ZodEffects extends ZodType {
3967
3552
  return { status: status.value, value: result };
3968
3553
  }
3969
3554
  else {
3970
- return this._def.schema
3971
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3972
- .then((base) => {
3555
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
3973
3556
  if (!isValid(base))
3974
- return base;
3975
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
3557
+ return INVALID;
3558
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
3559
+ status: status.value,
3560
+ value: result,
3561
+ }));
3976
3562
  });
3977
3563
  }
3978
3564
  }
@@ -4054,9 +3640,7 @@ ZodDefault.create = (type, params) => {
4054
3640
  return new ZodDefault({
4055
3641
  innerType: type,
4056
3642
  typeName: ZodFirstPartyTypeKind.ZodDefault,
4057
- defaultValue: typeof params.default === "function"
4058
- ? params.default
4059
- : () => params.default,
3643
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
4060
3644
  ...processCreateParams(params),
4061
3645
  });
4062
3646
  };
@@ -4140,7 +3724,6 @@ ZodNaN.create = (params) => {
4140
3724
  ...processCreateParams(params),
4141
3725
  });
4142
3726
  };
4143
- const BRAND = Symbol("zod_brand");
4144
3727
  class ZodBranded extends ZodType {
4145
3728
  _parse(input) {
4146
3729
  const { ctx } = this._processInputParams(input);
@@ -4222,9 +3805,7 @@ class ZodReadonly extends ZodType {
4222
3805
  }
4223
3806
  return data;
4224
3807
  };
4225
- return isAsync(result)
4226
- ? result.then((data) => freeze(data))
4227
- : freeze(result);
3808
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
4228
3809
  }
4229
3810
  unwrap() {
4230
3811
  return this._def.innerType;
@@ -4237,60 +3818,9 @@ ZodReadonly.create = (type, params) => {
4237
3818
  ...processCreateParams(params),
4238
3819
  });
4239
3820
  };
4240
- ////////////////////////////////////////
4241
- ////////////////////////////////////////
4242
- ////////// //////////
4243
- ////////// z.custom //////////
4244
- ////////// //////////
4245
- ////////////////////////////////////////
4246
- ////////////////////////////////////////
4247
- function cleanParams(params, data) {
4248
- const p = typeof params === "function"
4249
- ? params(data)
4250
- : typeof params === "string"
4251
- ? { message: params }
4252
- : params;
4253
- const p2 = typeof p === "string" ? { message: p } : p;
4254
- return p2;
4255
- }
4256
- function custom(check, _params = {},
4257
- /**
4258
- * @deprecated
4259
- *
4260
- * Pass `fatal` into the params object instead:
4261
- *
4262
- * ```ts
4263
- * z.string().custom((val) => val.length > 5, { fatal: false })
4264
- * ```
4265
- *
4266
- */
4267
- fatal) {
4268
- if (check)
4269
- return ZodAny.create().superRefine((data, ctx) => {
4270
- var _a, _b;
4271
- const r = check(data);
4272
- if (r instanceof Promise) {
4273
- return r.then((r) => {
4274
- var _a, _b;
4275
- if (!r) {
4276
- const params = cleanParams(_params, data);
4277
- const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
4278
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
4279
- }
4280
- });
4281
- }
4282
- if (!r) {
4283
- const params = cleanParams(_params, data);
4284
- const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
4285
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
4286
- }
4287
- return;
4288
- });
4289
- return ZodAny.create();
4290
- }
4291
- const late = {
3821
+ ({
4292
3822
  object: ZodObject.lazycreate,
4293
- };
3823
+ });
4294
3824
  var ZodFirstPartyTypeKind;
4295
3825
  (function (ZodFirstPartyTypeKind) {
4296
3826
  ZodFirstPartyTypeKind["ZodString"] = "ZodString";
@@ -4330,197 +3860,63 @@ var ZodFirstPartyTypeKind;
4330
3860
  ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
4331
3861
  ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
4332
3862
  })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4333
- const instanceOfType = (
4334
- // const instanceOfType = <T extends new (...args: any[]) => any>(
4335
- cls, params = {
4336
- message: `Input not instance of ${cls.name}`,
4337
- }) => custom((data) => data instanceof cls, params);
4338
3863
  const stringType = ZodString.create;
4339
3864
  const numberType = ZodNumber.create;
4340
- const nanType = ZodNaN.create;
4341
- const bigIntType = ZodBigInt.create;
3865
+ ZodNaN.create;
3866
+ ZodBigInt.create;
4342
3867
  const booleanType = ZodBoolean.create;
4343
- const dateType = ZodDate.create;
4344
- const symbolType = ZodSymbol.create;
4345
- const undefinedType = ZodUndefined.create;
4346
- const nullType = ZodNull.create;
3868
+ ZodDate.create;
3869
+ ZodSymbol.create;
3870
+ ZodUndefined.create;
3871
+ ZodNull.create;
4347
3872
  const anyType = ZodAny.create;
4348
- const unknownType = ZodUnknown.create;
4349
- const neverType = ZodNever.create;
4350
- const voidType = ZodVoid.create;
3873
+ ZodUnknown.create;
3874
+ ZodNever.create;
3875
+ ZodVoid.create;
4351
3876
  const arrayType = ZodArray.create;
4352
3877
  const objectType = ZodObject.create;
4353
- const strictObjectType = ZodObject.strictCreate;
4354
- const unionType = ZodUnion.create;
4355
- const discriminatedUnionType = ZodDiscriminatedUnion.create;
4356
- const intersectionType = ZodIntersection.create;
4357
- const tupleType = ZodTuple.create;
4358
- const recordType = ZodRecord.create;
4359
- const mapType = ZodMap.create;
4360
- const setType = ZodSet.create;
4361
- const functionType = ZodFunction.create;
4362
- const lazyType = ZodLazy.create;
4363
- const literalType = ZodLiteral.create;
4364
- const enumType = ZodEnum.create;
4365
- const nativeEnumType = ZodNativeEnum.create;
4366
- const promiseType = ZodPromise.create;
4367
- const effectsType = ZodEffects.create;
4368
- const optionalType = ZodOptional.create;
4369
- const nullableType = ZodNullable.create;
4370
- const preprocessType = ZodEffects.createWithPreprocess;
4371
- const pipelineType = ZodPipeline.create;
4372
- const ostring = () => stringType().optional();
4373
- const onumber = () => numberType().optional();
4374
- const oboolean = () => booleanType().optional();
4375
- const coerce = {
4376
- string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4377
- number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4378
- boolean: ((arg) => ZodBoolean.create({
4379
- ...arg,
4380
- coerce: true,
4381
- })),
4382
- bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4383
- date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
4384
- };
4385
- const NEVER = INVALID;
4386
-
4387
- var z = /*#__PURE__*/Object.freeze({
4388
- __proto__: null,
4389
- defaultErrorMap: errorMap,
4390
- setErrorMap: setErrorMap,
4391
- getErrorMap: getErrorMap,
4392
- makeIssue: makeIssue,
4393
- EMPTY_PATH: EMPTY_PATH,
4394
- addIssueToContext: addIssueToContext,
4395
- ParseStatus: ParseStatus,
4396
- INVALID: INVALID,
4397
- DIRTY: DIRTY,
4398
- OK: OK,
4399
- isAborted: isAborted,
4400
- isDirty: isDirty,
4401
- isValid: isValid,
4402
- isAsync: isAsync,
4403
- get util () { return util$1; },
4404
- get objectUtil () { return objectUtil; },
4405
- ZodParsedType: ZodParsedType,
4406
- getParsedType: getParsedType,
4407
- ZodType: ZodType,
4408
- datetimeRegex: datetimeRegex,
4409
- ZodString: ZodString,
4410
- ZodNumber: ZodNumber,
4411
- ZodBigInt: ZodBigInt,
4412
- ZodBoolean: ZodBoolean,
4413
- ZodDate: ZodDate,
4414
- ZodSymbol: ZodSymbol,
4415
- ZodUndefined: ZodUndefined,
4416
- ZodNull: ZodNull,
4417
- ZodAny: ZodAny,
4418
- ZodUnknown: ZodUnknown,
4419
- ZodNever: ZodNever,
4420
- ZodVoid: ZodVoid,
4421
- ZodArray: ZodArray,
4422
- ZodObject: ZodObject,
4423
- ZodUnion: ZodUnion,
4424
- ZodDiscriminatedUnion: ZodDiscriminatedUnion,
4425
- ZodIntersection: ZodIntersection,
4426
- ZodTuple: ZodTuple,
4427
- ZodRecord: ZodRecord,
4428
- ZodMap: ZodMap,
4429
- ZodSet: ZodSet,
4430
- ZodFunction: ZodFunction,
4431
- ZodLazy: ZodLazy,
4432
- ZodLiteral: ZodLiteral,
4433
- ZodEnum: ZodEnum,
4434
- ZodNativeEnum: ZodNativeEnum,
4435
- ZodPromise: ZodPromise,
4436
- ZodEffects: ZodEffects,
4437
- ZodTransformer: ZodEffects,
4438
- ZodOptional: ZodOptional,
4439
- ZodNullable: ZodNullable,
4440
- ZodDefault: ZodDefault,
4441
- ZodCatch: ZodCatch,
4442
- ZodNaN: ZodNaN,
4443
- BRAND: BRAND,
4444
- ZodBranded: ZodBranded,
4445
- ZodPipeline: ZodPipeline,
4446
- ZodReadonly: ZodReadonly,
4447
- custom: custom,
4448
- Schema: ZodType,
4449
- ZodSchema: ZodType,
4450
- late: late,
4451
- get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
4452
- coerce: coerce,
4453
- any: anyType,
4454
- array: arrayType,
4455
- bigint: bigIntType,
4456
- boolean: booleanType,
4457
- date: dateType,
4458
- discriminatedUnion: discriminatedUnionType,
4459
- effect: effectsType,
4460
- 'enum': enumType,
4461
- 'function': functionType,
4462
- 'instanceof': instanceOfType,
4463
- intersection: intersectionType,
4464
- lazy: lazyType,
4465
- literal: literalType,
4466
- map: mapType,
4467
- nan: nanType,
4468
- nativeEnum: nativeEnumType,
4469
- never: neverType,
4470
- 'null': nullType,
4471
- nullable: nullableType,
4472
- number: numberType,
4473
- object: objectType,
4474
- oboolean: oboolean,
4475
- onumber: onumber,
4476
- optional: optionalType,
4477
- ostring: ostring,
4478
- pipeline: pipelineType,
4479
- preprocess: preprocessType,
4480
- promise: promiseType,
4481
- record: recordType,
4482
- set: setType,
4483
- strictObject: strictObjectType,
4484
- string: stringType,
4485
- symbol: symbolType,
4486
- transformer: effectsType,
4487
- tuple: tupleType,
4488
- 'undefined': undefinedType,
4489
- union: unionType,
4490
- unknown: unknownType,
4491
- 'void': voidType,
4492
- NEVER: NEVER,
4493
- ZodIssueCode: ZodIssueCode,
4494
- quotelessJson: quotelessJson,
4495
- ZodError: ZodError
4496
- });
3878
+ ZodObject.strictCreate;
3879
+ ZodUnion.create;
3880
+ ZodIntersection.create;
3881
+ ZodTuple.create;
3882
+ ZodMap.create;
3883
+ ZodSet.create;
3884
+ ZodLazy.create;
3885
+ ZodLiteral.create;
3886
+ ZodEnum.create;
3887
+ ZodNativeEnum.create;
3888
+ ZodPromise.create;
3889
+ ZodEffects.create;
3890
+ ZodOptional.create;
3891
+ ZodNullable.create;
3892
+ ZodEffects.createWithPreprocess;
4497
3893
 
4498
3894
  const schemaFormRule = (rule) => {
4499
3895
  switch (rule.type) {
4500
3896
  case 'string':
4501
- let stringSchema = z.string();
4502
- if (rule.minLength)
4503
- stringSchema = stringSchema.min(rule.minLength, `String must be at least ${rule.minLength} characters long.`);
4504
- if (rule.maxLength)
4505
- stringSchema = stringSchema.max(rule.maxLength, `String must not exceed ${rule.maxLength} characters.`);
3897
+ let stringSchema = stringType();
3898
+ if (rule.min)
3899
+ stringSchema = stringSchema.min(rule.min, `String must be at least ${rule.min} characters long.`);
3900
+ if (rule.max)
3901
+ stringSchema = stringSchema.max(rule.max, `String must not exceed ${rule.max} characters.`);
4506
3902
  if (rule.regex)
4507
3903
  stringSchema = stringSchema.regex(new RegExp(rule.regex), 'Invalid format');
4508
3904
  return stringSchema;
4509
3905
  case 'number':
4510
- let numberSchema = z.number();
3906
+ let numberSchema = numberType();
4511
3907
  if (rule.min)
4512
3908
  numberSchema = numberSchema.min(rule.min, `Number must be at least ${rule.min}.`);
4513
3909
  if (rule.max)
4514
3910
  numberSchema = numberSchema.max(rule.max, `Number must not exceed ${rule.max}.`);
4515
3911
  return numberSchema;
4516
3912
  case 'boolean':
4517
- return z.boolean();
3913
+ return booleanType();
4518
3914
  case 'array':
4519
- return z.array(createSchema(rule.items));
3915
+ return arrayType(createSchema(rule.items));
4520
3916
  case 'object':
4521
- return z.object(Object.fromEntries(Object.entries(rule.properties).map(([key, value]) => [key, createSchema(value)])));
3917
+ return objectType(Object.fromEntries(Object.entries(rule.properties).map(([key, value]) => [key, createSchema(value)])));
4522
3918
  case 'any':
4523
- return z.any();
3919
+ return anyType();
4524
3920
  default:
4525
3921
  throw new Error(`Unknown rule type: ${rule?.type}`);
4526
3922
  }
@@ -4564,7 +3960,7 @@ var freeSelf = typeof self == 'object' && self && self.Object === Object && self
4564
3960
  var root = freeGlobal || freeSelf || Function('return this')();
4565
3961
 
4566
3962
  /** Built-in value references. */
4567
- var Symbol$1 = root.Symbol;
3963
+ var Symbol = root.Symbol;
4568
3964
 
4569
3965
  /** Used for built-in method references. */
4570
3966
  var objectProto$4 = Object.prototype;
@@ -4580,7 +3976,7 @@ var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
4580
3976
  var nativeObjectToString$1 = objectProto$4.toString;
4581
3977
 
4582
3978
  /** Built-in value references. */
4583
- var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined;
3979
+ var symToStringTag$1 = Symbol ? Symbol.toStringTag : undefined;
4584
3980
 
4585
3981
  /**
4586
3982
  * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
@@ -4635,7 +4031,7 @@ var nullTag = '[object Null]',
4635
4031
  undefinedTag = '[object Undefined]';
4636
4032
 
4637
4033
  /** Built-in value references. */
4638
- var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined;
4034
+ var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
4639
4035
 
4640
4036
  /**
4641
4037
  * The base implementation of `getTag` without fallbacks for buggy environments.
@@ -4752,7 +4148,7 @@ function arrayMap(array, iteratee) {
4752
4148
  var isArray = Array.isArray;
4753
4149
 
4754
4150
  /** Used to convert symbols to primitives and strings. */
4755
- var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
4151
+ var symbolProto = Symbol ? Symbol.prototype : undefined,
4756
4152
  symbolToString = symbolProto ? symbolProto.toString : undefined;
4757
4153
 
4758
4154
  /**