@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.
package/dist/router.js CHANGED
@@ -118,7 +118,7 @@ try {
118
118
 
119
119
  var util$1;
120
120
  (function (util) {
121
- util.assertEqual = (val) => val;
121
+ util.assertEqual = (_) => { };
122
122
  function assertIs(_arg) { }
123
123
  util.assertIs = assertIs;
124
124
  function assertNever(_x) {
@@ -165,11 +165,9 @@ var util$1;
165
165
  };
166
166
  util.isInteger = typeof Number.isInteger === "function"
167
167
  ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
168
- : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
168
+ : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
169
169
  function joinValues(array, separator = " | ") {
170
- return array
171
- .map((val) => (typeof val === "string" ? `'${val}'` : val))
172
- .join(separator);
170
+ return array.map((val) => (typeof val === "string" ? `'${val}'` : val)).join(separator);
173
171
  }
174
172
  util.joinValues = joinValues;
175
173
  util.jsonStringifyReplacer = (_, value) => {
@@ -218,7 +216,7 @@ const getParsedType = (data) => {
218
216
  case "string":
219
217
  return ZodParsedType.string;
220
218
  case "number":
221
- return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
219
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
222
220
  case "boolean":
223
221
  return ZodParsedType.boolean;
224
222
  case "function":
@@ -234,10 +232,7 @@ const getParsedType = (data) => {
234
232
  if (data === null) {
235
233
  return ZodParsedType.null;
236
234
  }
237
- if (data.then &&
238
- typeof data.then === "function" &&
239
- data.catch &&
240
- typeof data.catch === "function") {
235
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
241
236
  return ZodParsedType.promise;
242
237
  }
243
238
  if (typeof Map !== "undefined" && data instanceof Map) {
@@ -273,10 +268,6 @@ const ZodIssueCode = util$1.arrayToEnum([
273
268
  "not_multiple_of",
274
269
  "not_finite",
275
270
  ]);
276
- const quotelessJson = (obj) => {
277
- const json = JSON.stringify(obj, null, 2);
278
- return json.replace(/"([^"]+)":/g, "$1:");
279
- };
280
271
  class ZodError extends Error {
281
272
  get errors() {
282
273
  return this.issues;
@@ -453,17 +444,9 @@ const errorMap = (issue, _ctx) => {
453
444
  else if (issue.type === "string")
454
445
  message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
455
446
  else if (issue.type === "number")
456
- message = `Number must be ${issue.exact
457
- ? `exactly equal to `
458
- : issue.inclusive
459
- ? `greater than or equal to `
460
- : `greater than `}${issue.minimum}`;
447
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
461
448
  else if (issue.type === "date")
462
- message = `Date must be ${issue.exact
463
- ? `exactly equal to `
464
- : issue.inclusive
465
- ? `greater than or equal to `
466
- : `greater than `}${new Date(Number(issue.minimum))}`;
449
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
467
450
  else
468
451
  message = "Invalid input";
469
452
  break;
@@ -473,23 +456,11 @@ const errorMap = (issue, _ctx) => {
473
456
  else if (issue.type === "string")
474
457
  message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
475
458
  else if (issue.type === "number")
476
- message = `Number must be ${issue.exact
477
- ? `exactly`
478
- : issue.inclusive
479
- ? `less than or equal to`
480
- : `less than`} ${issue.maximum}`;
459
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
481
460
  else if (issue.type === "bigint")
482
- message = `BigInt must be ${issue.exact
483
- ? `exactly`
484
- : issue.inclusive
485
- ? `less than or equal to`
486
- : `less than`} ${issue.maximum}`;
461
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
487
462
  else if (issue.type === "date")
488
- message = `Date must be ${issue.exact
489
- ? `exactly`
490
- : issue.inclusive
491
- ? `smaller than or equal to`
492
- : `smaller than`} ${new Date(Number(issue.maximum))}`;
463
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
493
464
  else
494
465
  message = "Invalid input";
495
466
  break;
@@ -513,9 +484,6 @@ const errorMap = (issue, _ctx) => {
513
484
  };
514
485
 
515
486
  let overrideErrorMap = errorMap;
516
- function setErrorMap(map) {
517
- overrideErrorMap = map;
518
- }
519
487
  function getErrorMap() {
520
488
  return overrideErrorMap;
521
489
  }
@@ -548,7 +516,6 @@ const makeIssue = (params) => {
548
516
  message: errorMessage,
549
517
  };
550
518
  };
551
- const EMPTY_PATH = [];
552
519
  function addIssueToContext(ctx, issueData) {
553
520
  const overrideMap = getErrorMap();
554
521
  const issue = makeIssue({
@@ -611,8 +578,7 @@ class ParseStatus {
611
578
  status.dirty();
612
579
  if (value.status === "dirty")
613
580
  status.dirty();
614
- if (key.value !== "__proto__" &&
615
- (typeof value.value !== "undefined" || pair.alwaysSet)) {
581
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
616
582
  finalObject[key.value] = value.value;
617
583
  }
618
584
  }
@@ -629,43 +595,13 @@ const isDirty = (x) => x.status === "dirty";
629
595
  const isValid = (x) => x.status === "valid";
630
596
  const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
631
597
 
632
- /******************************************************************************
633
- Copyright (c) Microsoft Corporation.
634
-
635
- Permission to use, copy, modify, and/or distribute this software for any
636
- purpose with or without fee is hereby granted.
637
-
638
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
639
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
640
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
641
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
642
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
643
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
644
- PERFORMANCE OF THIS SOFTWARE.
645
- ***************************************************************************** */
646
-
647
- function __classPrivateFieldGet(receiver, state, kind, f) {
648
- 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");
649
- return state.get(receiver);
650
- }
651
-
652
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
653
- 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");
654
- return (state.set(receiver, value)), value;
655
- }
656
-
657
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
658
- var e = new Error(message);
659
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
660
- };
661
-
662
598
  var errorUtil;
663
599
  (function (errorUtil) {
664
600
  errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
665
- errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
601
+ // biome-ignore lint:
602
+ errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
666
603
  })(errorUtil || (errorUtil = {}));
667
604
 
668
- var _ZodEnum_cache, _ZodNativeEnum_cache;
669
605
  class ParseInputLazyPath {
670
606
  constructor(parent, value, path, key) {
671
607
  this._cachedPath = [];
@@ -676,7 +612,7 @@ class ParseInputLazyPath {
676
612
  }
677
613
  get path() {
678
614
  if (!this._cachedPath.length) {
679
- if (this._key instanceof Array) {
615
+ if (Array.isArray(this._key)) {
680
616
  this._cachedPath.push(...this._path, ...this._key);
681
617
  }
682
618
  else {
@@ -716,17 +652,16 @@ function processCreateParams(params) {
716
652
  if (errorMap)
717
653
  return { errorMap: errorMap, description };
718
654
  const customMap = (iss, ctx) => {
719
- var _a, _b;
720
655
  const { message } = params;
721
656
  if (iss.code === "invalid_enum_value") {
722
- return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
657
+ return { message: message ?? ctx.defaultError };
723
658
  }
724
659
  if (typeof ctx.data === "undefined") {
725
- return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
660
+ return { message: message ?? required_error ?? ctx.defaultError };
726
661
  }
727
662
  if (iss.code !== "invalid_type")
728
663
  return { message: ctx.defaultError };
729
- return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
664
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
730
665
  };
731
666
  return { errorMap: customMap, description };
732
667
  }
@@ -778,14 +713,13 @@ class ZodType {
778
713
  throw result.error;
779
714
  }
780
715
  safeParse(data, params) {
781
- var _a;
782
716
  const ctx = {
783
717
  common: {
784
718
  issues: [],
785
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
786
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
719
+ async: params?.async ?? false,
720
+ contextualErrorMap: params?.errorMap,
787
721
  },
788
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
722
+ path: params?.path || [],
789
723
  schemaErrorMap: this._def.errorMap,
790
724
  parent: null,
791
725
  data,
@@ -795,7 +729,6 @@ class ZodType {
795
729
  return handleResult(ctx, result);
796
730
  }
797
731
  "~validate"(data) {
798
- var _a, _b;
799
732
  const ctx = {
800
733
  common: {
801
734
  issues: [],
@@ -819,7 +752,7 @@ class ZodType {
819
752
  };
820
753
  }
821
754
  catch (err) {
822
- 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")) {
755
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
823
756
  this["~standard"].async = true;
824
757
  }
825
758
  ctx.common = {
@@ -846,19 +779,17 @@ class ZodType {
846
779
  const ctx = {
847
780
  common: {
848
781
  issues: [],
849
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
782
+ contextualErrorMap: params?.errorMap,
850
783
  async: true,
851
784
  },
852
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
785
+ path: params?.path || [],
853
786
  schemaErrorMap: this._def.errorMap,
854
787
  parent: null,
855
788
  data,
856
789
  parsedType: getParsedType(data),
857
790
  };
858
791
  const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
859
- const result = await (isAsync(maybeAsyncResult)
860
- ? maybeAsyncResult
861
- : Promise.resolve(maybeAsyncResult));
792
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
862
793
  return handleResult(ctx, result);
863
794
  }
864
795
  refine(check, message) {
@@ -902,9 +833,7 @@ class ZodType {
902
833
  refinement(check, refinementData) {
903
834
  return this._refinement((val, ctx) => {
904
835
  if (!check(val)) {
905
- ctx.addIssue(typeof refinementData === "function"
906
- ? refinementData(val, ctx)
907
- : refinementData);
836
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
908
837
  return false;
909
838
  }
910
839
  else {
@@ -1121,13 +1050,15 @@ function isValidJWT(jwt, alg) {
1121
1050
  const decoded = JSON.parse(atob(base64));
1122
1051
  if (typeof decoded !== "object" || decoded === null)
1123
1052
  return false;
1124
- if (!decoded.typ || !decoded.alg)
1053
+ if ("typ" in decoded && decoded?.typ !== "JWT")
1054
+ return false;
1055
+ if (!decoded.alg)
1125
1056
  return false;
1126
1057
  if (alg && decoded.alg !== alg)
1127
1058
  return false;
1128
1059
  return true;
1129
1060
  }
1130
- catch (_a) {
1061
+ catch {
1131
1062
  return false;
1132
1063
  }
1133
1064
  }
@@ -1298,7 +1229,7 @@ class ZodString extends ZodType {
1298
1229
  try {
1299
1230
  new URL(input.data);
1300
1231
  }
1301
- catch (_a) {
1232
+ catch {
1302
1233
  ctx = this._getOrReturnCtx(input, ctx);
1303
1234
  addIssueToContext(ctx, {
1304
1235
  validation: "url",
@@ -1528,7 +1459,6 @@ class ZodString extends ZodType {
1528
1459
  return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1529
1460
  }
1530
1461
  datetime(options) {
1531
- var _a, _b;
1532
1462
  if (typeof options === "string") {
1533
1463
  return this._addCheck({
1534
1464
  kind: "datetime",
@@ -1540,10 +1470,10 @@ class ZodString extends ZodType {
1540
1470
  }
1541
1471
  return this._addCheck({
1542
1472
  kind: "datetime",
1543
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1544
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
1545
- local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
1546
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1473
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1474
+ offset: options?.offset ?? false,
1475
+ local: options?.local ?? false,
1476
+ ...errorUtil.errToObj(options?.message),
1547
1477
  });
1548
1478
  }
1549
1479
  date(message) {
@@ -1559,8 +1489,8 @@ class ZodString extends ZodType {
1559
1489
  }
1560
1490
  return this._addCheck({
1561
1491
  kind: "time",
1562
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1563
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1492
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1493
+ ...errorUtil.errToObj(options?.message),
1564
1494
  });
1565
1495
  }
1566
1496
  duration(message) {
@@ -1577,8 +1507,8 @@ class ZodString extends ZodType {
1577
1507
  return this._addCheck({
1578
1508
  kind: "includes",
1579
1509
  value: value,
1580
- position: options === null || options === void 0 ? void 0 : options.position,
1581
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1510
+ position: options?.position,
1511
+ ...errorUtil.errToObj(options?.message),
1582
1512
  });
1583
1513
  }
1584
1514
  startsWith(value, message) {
@@ -1711,11 +1641,10 @@ class ZodString extends ZodType {
1711
1641
  }
1712
1642
  }
1713
1643
  ZodString.create = (params) => {
1714
- var _a;
1715
1644
  return new ZodString({
1716
1645
  checks: [],
1717
1646
  typeName: ZodFirstPartyTypeKind.ZodString,
1718
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1647
+ coerce: params?.coerce ?? false,
1719
1648
  ...processCreateParams(params),
1720
1649
  });
1721
1650
  };
@@ -1724,9 +1653,9 @@ function floatSafeRemainder(val, step) {
1724
1653
  const valDecCount = (val.toString().split(".")[1] || "").length;
1725
1654
  const stepDecCount = (step.toString().split(".")[1] || "").length;
1726
1655
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1727
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
1728
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
1729
- return (valInt % stepInt) / Math.pow(10, decCount);
1656
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1657
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1658
+ return (valInt % stepInt) / 10 ** decCount;
1730
1659
  }
1731
1660
  class ZodNumber extends ZodType {
1732
1661
  constructor() {
@@ -1765,9 +1694,7 @@ class ZodNumber extends ZodType {
1765
1694
  }
1766
1695
  }
1767
1696
  else if (check.kind === "min") {
1768
- const tooSmall = check.inclusive
1769
- ? input.data < check.value
1770
- : input.data <= check.value;
1697
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1771
1698
  if (tooSmall) {
1772
1699
  ctx = this._getOrReturnCtx(input, ctx);
1773
1700
  addIssueToContext(ctx, {
@@ -1782,9 +1709,7 @@ class ZodNumber extends ZodType {
1782
1709
  }
1783
1710
  }
1784
1711
  else if (check.kind === "max") {
1785
- const tooBig = check.inclusive
1786
- ? input.data > check.value
1787
- : input.data >= check.value;
1712
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1788
1713
  if (tooBig) {
1789
1714
  ctx = this._getOrReturnCtx(input, ctx);
1790
1715
  addIssueToContext(ctx, {
@@ -1942,15 +1867,13 @@ class ZodNumber extends ZodType {
1942
1867
  return max;
1943
1868
  }
1944
1869
  get isInt() {
1945
- return !!this._def.checks.find((ch) => ch.kind === "int" ||
1946
- (ch.kind === "multipleOf" && util$1.isInteger(ch.value)));
1870
+ return !!this._def.checks.find((ch) => ch.kind === "int" || (ch.kind === "multipleOf" && util$1.isInteger(ch.value)));
1947
1871
  }
1948
1872
  get isFinite() {
1949
- let max = null, min = null;
1873
+ let max = null;
1874
+ let min = null;
1950
1875
  for (const ch of this._def.checks) {
1951
- if (ch.kind === "finite" ||
1952
- ch.kind === "int" ||
1953
- ch.kind === "multipleOf") {
1876
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
1954
1877
  return true;
1955
1878
  }
1956
1879
  else if (ch.kind === "min") {
@@ -1969,7 +1892,7 @@ ZodNumber.create = (params) => {
1969
1892
  return new ZodNumber({
1970
1893
  checks: [],
1971
1894
  typeName: ZodFirstPartyTypeKind.ZodNumber,
1972
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1895
+ coerce: params?.coerce || false,
1973
1896
  ...processCreateParams(params),
1974
1897
  });
1975
1898
  };
@@ -1984,7 +1907,7 @@ class ZodBigInt extends ZodType {
1984
1907
  try {
1985
1908
  input.data = BigInt(input.data);
1986
1909
  }
1987
- catch (_a) {
1910
+ catch {
1988
1911
  return this._getInvalidInput(input);
1989
1912
  }
1990
1913
  }
@@ -1996,9 +1919,7 @@ class ZodBigInt extends ZodType {
1996
1919
  const status = new ParseStatus();
1997
1920
  for (const check of this._def.checks) {
1998
1921
  if (check.kind === "min") {
1999
- const tooSmall = check.inclusive
2000
- ? input.data < check.value
2001
- : input.data <= check.value;
1922
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2002
1923
  if (tooSmall) {
2003
1924
  ctx = this._getOrReturnCtx(input, ctx);
2004
1925
  addIssueToContext(ctx, {
@@ -2012,9 +1933,7 @@ class ZodBigInt extends ZodType {
2012
1933
  }
2013
1934
  }
2014
1935
  else if (check.kind === "max") {
2015
- const tooBig = check.inclusive
2016
- ? input.data > check.value
2017
- : input.data >= check.value;
1936
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2018
1937
  if (tooBig) {
2019
1938
  ctx = this._getOrReturnCtx(input, ctx);
2020
1939
  addIssueToContext(ctx, {
@@ -2146,11 +2065,10 @@ class ZodBigInt extends ZodType {
2146
2065
  }
2147
2066
  }
2148
2067
  ZodBigInt.create = (params) => {
2149
- var _a;
2150
2068
  return new ZodBigInt({
2151
2069
  checks: [],
2152
2070
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
2153
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
2071
+ coerce: params?.coerce ?? false,
2154
2072
  ...processCreateParams(params),
2155
2073
  });
2156
2074
  };
@@ -2175,7 +2093,7 @@ class ZodBoolean extends ZodType {
2175
2093
  ZodBoolean.create = (params) => {
2176
2094
  return new ZodBoolean({
2177
2095
  typeName: ZodFirstPartyTypeKind.ZodBoolean,
2178
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2096
+ coerce: params?.coerce || false,
2179
2097
  ...processCreateParams(params),
2180
2098
  });
2181
2099
  };
@@ -2194,7 +2112,7 @@ class ZodDate extends ZodType {
2194
2112
  });
2195
2113
  return INVALID;
2196
2114
  }
2197
- if (isNaN(input.data.getTime())) {
2115
+ if (Number.isNaN(input.data.getTime())) {
2198
2116
  const ctx = this._getOrReturnCtx(input);
2199
2117
  addIssueToContext(ctx, {
2200
2118
  code: ZodIssueCode.invalid_date,
@@ -2285,7 +2203,7 @@ class ZodDate extends ZodType {
2285
2203
  ZodDate.create = (params) => {
2286
2204
  return new ZodDate({
2287
2205
  checks: [],
2288
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2206
+ coerce: params?.coerce || false,
2289
2207
  typeName: ZodFirstPartyTypeKind.ZodDate,
2290
2208
  ...processCreateParams(params),
2291
2209
  });
@@ -2607,7 +2525,8 @@ class ZodObject extends ZodType {
2607
2525
  return this._cached;
2608
2526
  const shape = this._def.shape();
2609
2527
  const keys = util$1.objectKeys(shape);
2610
- return (this._cached = { shape, keys });
2528
+ this._cached = { shape, keys };
2529
+ return this._cached;
2611
2530
  }
2612
2531
  _parse(input) {
2613
2532
  const parsedType = this._getType(input);
@@ -2623,8 +2542,7 @@ class ZodObject extends ZodType {
2623
2542
  const { status, ctx } = this._processInputParams(input);
2624
2543
  const { shape, keys: shapeKeys } = this._getCached();
2625
2544
  const extraKeys = [];
2626
- if (!(this._def.catchall instanceof ZodNever &&
2627
- this._def.unknownKeys === "strip")) {
2545
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2628
2546
  for (const key in ctx.data) {
2629
2547
  if (!shapeKeys.includes(key)) {
2630
2548
  extraKeys.push(key);
@@ -2712,11 +2630,10 @@ class ZodObject extends ZodType {
2712
2630
  ...(message !== undefined
2713
2631
  ? {
2714
2632
  errorMap: (issue, ctx) => {
2715
- var _a, _b, _c, _d;
2716
- 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;
2633
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2717
2634
  if (issue.code === "unrecognized_keys")
2718
2635
  return {
2719
- message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
2636
+ message: errorUtil.errToObj(message).message ?? defaultError,
2720
2637
  };
2721
2638
  return {
2722
2639
  message: defaultError,
@@ -2848,11 +2765,11 @@ class ZodObject extends ZodType {
2848
2765
  }
2849
2766
  pick(mask) {
2850
2767
  const shape = {};
2851
- util$1.objectKeys(mask).forEach((key) => {
2768
+ for (const key of util$1.objectKeys(mask)) {
2852
2769
  if (mask[key] && this.shape[key]) {
2853
2770
  shape[key] = this.shape[key];
2854
2771
  }
2855
- });
2772
+ }
2856
2773
  return new ZodObject({
2857
2774
  ...this._def,
2858
2775
  shape: () => shape,
@@ -2860,11 +2777,11 @@ class ZodObject extends ZodType {
2860
2777
  }
2861
2778
  omit(mask) {
2862
2779
  const shape = {};
2863
- util$1.objectKeys(this.shape).forEach((key) => {
2780
+ for (const key of util$1.objectKeys(this.shape)) {
2864
2781
  if (!mask[key]) {
2865
2782
  shape[key] = this.shape[key];
2866
2783
  }
2867
- });
2784
+ }
2868
2785
  return new ZodObject({
2869
2786
  ...this._def,
2870
2787
  shape: () => shape,
@@ -2878,7 +2795,7 @@ class ZodObject extends ZodType {
2878
2795
  }
2879
2796
  partial(mask) {
2880
2797
  const newShape = {};
2881
- util$1.objectKeys(this.shape).forEach((key) => {
2798
+ for (const key of util$1.objectKeys(this.shape)) {
2882
2799
  const fieldSchema = this.shape[key];
2883
2800
  if (mask && !mask[key]) {
2884
2801
  newShape[key] = fieldSchema;
@@ -2886,7 +2803,7 @@ class ZodObject extends ZodType {
2886
2803
  else {
2887
2804
  newShape[key] = fieldSchema.optional();
2888
2805
  }
2889
- });
2806
+ }
2890
2807
  return new ZodObject({
2891
2808
  ...this._def,
2892
2809
  shape: () => newShape,
@@ -2894,7 +2811,7 @@ class ZodObject extends ZodType {
2894
2811
  }
2895
2812
  required(mask) {
2896
2813
  const newShape = {};
2897
- util$1.objectKeys(this.shape).forEach((key) => {
2814
+ for (const key of util$1.objectKeys(this.shape)) {
2898
2815
  if (mask && !mask[key]) {
2899
2816
  newShape[key] = this.shape[key];
2900
2817
  }
@@ -2906,7 +2823,7 @@ class ZodObject extends ZodType {
2906
2823
  }
2907
2824
  newShape[key] = newField;
2908
2825
  }
2909
- });
2826
+ }
2910
2827
  return new ZodObject({
2911
2828
  ...this._def,
2912
2829
  shape: () => newShape,
@@ -3039,137 +2956,6 @@ ZodUnion.create = (types, params) => {
3039
2956
  ...processCreateParams(params),
3040
2957
  });
3041
2958
  };
3042
- /////////////////////////////////////////////////////
3043
- /////////////////////////////////////////////////////
3044
- ////////// //////////
3045
- ////////// ZodDiscriminatedUnion //////////
3046
- ////////// //////////
3047
- /////////////////////////////////////////////////////
3048
- /////////////////////////////////////////////////////
3049
- const getDiscriminator = (type) => {
3050
- if (type instanceof ZodLazy) {
3051
- return getDiscriminator(type.schema);
3052
- }
3053
- else if (type instanceof ZodEffects) {
3054
- return getDiscriminator(type.innerType());
3055
- }
3056
- else if (type instanceof ZodLiteral) {
3057
- return [type.value];
3058
- }
3059
- else if (type instanceof ZodEnum) {
3060
- return type.options;
3061
- }
3062
- else if (type instanceof ZodNativeEnum) {
3063
- // eslint-disable-next-line ban/ban
3064
- return util$1.objectValues(type.enum);
3065
- }
3066
- else if (type instanceof ZodDefault) {
3067
- return getDiscriminator(type._def.innerType);
3068
- }
3069
- else if (type instanceof ZodUndefined) {
3070
- return [undefined];
3071
- }
3072
- else if (type instanceof ZodNull) {
3073
- return [null];
3074
- }
3075
- else if (type instanceof ZodOptional) {
3076
- return [undefined, ...getDiscriminator(type.unwrap())];
3077
- }
3078
- else if (type instanceof ZodNullable) {
3079
- return [null, ...getDiscriminator(type.unwrap())];
3080
- }
3081
- else if (type instanceof ZodBranded) {
3082
- return getDiscriminator(type.unwrap());
3083
- }
3084
- else if (type instanceof ZodReadonly) {
3085
- return getDiscriminator(type.unwrap());
3086
- }
3087
- else if (type instanceof ZodCatch) {
3088
- return getDiscriminator(type._def.innerType);
3089
- }
3090
- else {
3091
- return [];
3092
- }
3093
- };
3094
- class ZodDiscriminatedUnion extends ZodType {
3095
- _parse(input) {
3096
- const { ctx } = this._processInputParams(input);
3097
- if (ctx.parsedType !== ZodParsedType.object) {
3098
- addIssueToContext(ctx, {
3099
- code: ZodIssueCode.invalid_type,
3100
- expected: ZodParsedType.object,
3101
- received: ctx.parsedType,
3102
- });
3103
- return INVALID;
3104
- }
3105
- const discriminator = this.discriminator;
3106
- const discriminatorValue = ctx.data[discriminator];
3107
- const option = this.optionsMap.get(discriminatorValue);
3108
- if (!option) {
3109
- addIssueToContext(ctx, {
3110
- code: ZodIssueCode.invalid_union_discriminator,
3111
- options: Array.from(this.optionsMap.keys()),
3112
- path: [discriminator],
3113
- });
3114
- return INVALID;
3115
- }
3116
- if (ctx.common.async) {
3117
- return option._parseAsync({
3118
- data: ctx.data,
3119
- path: ctx.path,
3120
- parent: ctx,
3121
- });
3122
- }
3123
- else {
3124
- return option._parseSync({
3125
- data: ctx.data,
3126
- path: ctx.path,
3127
- parent: ctx,
3128
- });
3129
- }
3130
- }
3131
- get discriminator() {
3132
- return this._def.discriminator;
3133
- }
3134
- get options() {
3135
- return this._def.options;
3136
- }
3137
- get optionsMap() {
3138
- return this._def.optionsMap;
3139
- }
3140
- /**
3141
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
3142
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
3143
- * have a different value for each object in the union.
3144
- * @param discriminator the name of the discriminator property
3145
- * @param types an array of object schemas
3146
- * @param params
3147
- */
3148
- static create(discriminator, options, params) {
3149
- // Get all the valid discriminator values
3150
- const optionsMap = new Map();
3151
- // try {
3152
- for (const type of options) {
3153
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3154
- if (!discriminatorValues.length) {
3155
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3156
- }
3157
- for (const value of discriminatorValues) {
3158
- if (optionsMap.has(value)) {
3159
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
3160
- }
3161
- optionsMap.set(value, type);
3162
- }
3163
- }
3164
- return new ZodDiscriminatedUnion({
3165
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
3166
- discriminator,
3167
- options,
3168
- optionsMap,
3169
- ...processCreateParams(params),
3170
- });
3171
- }
3172
- }
3173
2959
  function mergeValues(a, b) {
3174
2960
  const aType = getParsedType(a);
3175
2961
  const bType = getParsedType(b);
@@ -3178,9 +2964,7 @@ function mergeValues(a, b) {
3178
2964
  }
3179
2965
  else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
3180
2966
  const bKeys = util$1.objectKeys(b);
3181
- const sharedKeys = util$1
3182
- .objectKeys(a)
3183
- .filter((key) => bKeys.indexOf(key) !== -1);
2967
+ const sharedKeys = util$1.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
3184
2968
  const newObj = { ...a, ...b };
3185
2969
  for (const key of sharedKeys) {
3186
2970
  const sharedValue = mergeValues(a[key], b[key]);
@@ -3207,9 +2991,7 @@ function mergeValues(a, b) {
3207
2991
  }
3208
2992
  return { valid: true, data: newArray };
3209
2993
  }
3210
- else if (aType === ZodParsedType.date &&
3211
- bType === ZodParsedType.date &&
3212
- +a === +b) {
2994
+ else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
3213
2995
  return { valid: true, data: a };
3214
2996
  }
3215
2997
  else {
@@ -3270,6 +3052,7 @@ ZodIntersection.create = (left, right, params) => {
3270
3052
  ...processCreateParams(params),
3271
3053
  });
3272
3054
  };
3055
+ // type ZodTupleItems = [ZodTypeAny, ...ZodTypeAny[]];
3273
3056
  class ZodTuple extends ZodType {
3274
3057
  _parse(input) {
3275
3058
  const { status, ctx } = this._processInputParams(input);
@@ -3340,60 +3123,6 @@ ZodTuple.create = (schemas, params) => {
3340
3123
  ...processCreateParams(params),
3341
3124
  });
3342
3125
  };
3343
- class ZodRecord extends ZodType {
3344
- get keySchema() {
3345
- return this._def.keyType;
3346
- }
3347
- get valueSchema() {
3348
- return this._def.valueType;
3349
- }
3350
- _parse(input) {
3351
- const { status, ctx } = this._processInputParams(input);
3352
- if (ctx.parsedType !== ZodParsedType.object) {
3353
- addIssueToContext(ctx, {
3354
- code: ZodIssueCode.invalid_type,
3355
- expected: ZodParsedType.object,
3356
- received: ctx.parsedType,
3357
- });
3358
- return INVALID;
3359
- }
3360
- const pairs = [];
3361
- const keyType = this._def.keyType;
3362
- const valueType = this._def.valueType;
3363
- for (const key in ctx.data) {
3364
- pairs.push({
3365
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3366
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3367
- alwaysSet: key in ctx.data,
3368
- });
3369
- }
3370
- if (ctx.common.async) {
3371
- return ParseStatus.mergeObjectAsync(status, pairs);
3372
- }
3373
- else {
3374
- return ParseStatus.mergeObjectSync(status, pairs);
3375
- }
3376
- }
3377
- get element() {
3378
- return this._def.valueType;
3379
- }
3380
- static create(first, second, third) {
3381
- if (second instanceof ZodType) {
3382
- return new ZodRecord({
3383
- keyType: first,
3384
- valueType: second,
3385
- typeName: ZodFirstPartyTypeKind.ZodRecord,
3386
- ...processCreateParams(third),
3387
- });
3388
- }
3389
- return new ZodRecord({
3390
- keyType: ZodString.create(),
3391
- valueType: first,
3392
- typeName: ZodFirstPartyTypeKind.ZodRecord,
3393
- ...processCreateParams(second),
3394
- });
3395
- }
3396
- }
3397
3126
  class ZodMap extends ZodType {
3398
3127
  get keySchema() {
3399
3128
  return this._def.keyType;
@@ -3547,134 +3276,6 @@ ZodSet.create = (valueType, params) => {
3547
3276
  ...processCreateParams(params),
3548
3277
  });
3549
3278
  };
3550
- class ZodFunction extends ZodType {
3551
- constructor() {
3552
- super(...arguments);
3553
- this.validate = this.implement;
3554
- }
3555
- _parse(input) {
3556
- const { ctx } = this._processInputParams(input);
3557
- if (ctx.parsedType !== ZodParsedType.function) {
3558
- addIssueToContext(ctx, {
3559
- code: ZodIssueCode.invalid_type,
3560
- expected: ZodParsedType.function,
3561
- received: ctx.parsedType,
3562
- });
3563
- return INVALID;
3564
- }
3565
- function makeArgsIssue(args, error) {
3566
- return makeIssue({
3567
- data: args,
3568
- path: ctx.path,
3569
- errorMaps: [
3570
- ctx.common.contextualErrorMap,
3571
- ctx.schemaErrorMap,
3572
- getErrorMap(),
3573
- errorMap,
3574
- ].filter((x) => !!x),
3575
- issueData: {
3576
- code: ZodIssueCode.invalid_arguments,
3577
- argumentsError: error,
3578
- },
3579
- });
3580
- }
3581
- function makeReturnsIssue(returns, error) {
3582
- return makeIssue({
3583
- data: returns,
3584
- path: ctx.path,
3585
- errorMaps: [
3586
- ctx.common.contextualErrorMap,
3587
- ctx.schemaErrorMap,
3588
- getErrorMap(),
3589
- errorMap,
3590
- ].filter((x) => !!x),
3591
- issueData: {
3592
- code: ZodIssueCode.invalid_return_type,
3593
- returnTypeError: error,
3594
- },
3595
- });
3596
- }
3597
- const params = { errorMap: ctx.common.contextualErrorMap };
3598
- const fn = ctx.data;
3599
- if (this._def.returns instanceof ZodPromise) {
3600
- // Would love a way to avoid disabling this rule, but we need
3601
- // an alias (using an arrow function was what caused 2651).
3602
- // eslint-disable-next-line @typescript-eslint/no-this-alias
3603
- const me = this;
3604
- return OK(async function (...args) {
3605
- const error = new ZodError([]);
3606
- const parsedArgs = await me._def.args
3607
- .parseAsync(args, params)
3608
- .catch((e) => {
3609
- error.addIssue(makeArgsIssue(args, e));
3610
- throw error;
3611
- });
3612
- const result = await Reflect.apply(fn, this, parsedArgs);
3613
- const parsedReturns = await me._def.returns._def.type
3614
- .parseAsync(result, params)
3615
- .catch((e) => {
3616
- error.addIssue(makeReturnsIssue(result, e));
3617
- throw error;
3618
- });
3619
- return parsedReturns;
3620
- });
3621
- }
3622
- else {
3623
- // Would love a way to avoid disabling this rule, but we need
3624
- // an alias (using an arrow function was what caused 2651).
3625
- // eslint-disable-next-line @typescript-eslint/no-this-alias
3626
- const me = this;
3627
- return OK(function (...args) {
3628
- const parsedArgs = me._def.args.safeParse(args, params);
3629
- if (!parsedArgs.success) {
3630
- throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3631
- }
3632
- const result = Reflect.apply(fn, this, parsedArgs.data);
3633
- const parsedReturns = me._def.returns.safeParse(result, params);
3634
- if (!parsedReturns.success) {
3635
- throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3636
- }
3637
- return parsedReturns.data;
3638
- });
3639
- }
3640
- }
3641
- parameters() {
3642
- return this._def.args;
3643
- }
3644
- returnType() {
3645
- return this._def.returns;
3646
- }
3647
- args(...items) {
3648
- return new ZodFunction({
3649
- ...this._def,
3650
- args: ZodTuple.create(items).rest(ZodUnknown.create()),
3651
- });
3652
- }
3653
- returns(returnType) {
3654
- return new ZodFunction({
3655
- ...this._def,
3656
- returns: returnType,
3657
- });
3658
- }
3659
- implement(func) {
3660
- const validatedFunc = this.parse(func);
3661
- return validatedFunc;
3662
- }
3663
- strictImplement(func) {
3664
- const validatedFunc = this.parse(func);
3665
- return validatedFunc;
3666
- }
3667
- static create(args, returns, params) {
3668
- return new ZodFunction({
3669
- args: (args
3670
- ? args
3671
- : ZodTuple.create([]).rest(ZodUnknown.create())),
3672
- returns: returns || ZodUnknown.create(),
3673
- typeName: ZodFirstPartyTypeKind.ZodFunction,
3674
- ...processCreateParams(params),
3675
- });
3676
- }
3677
- }
3678
3279
  class ZodLazy extends ZodType {
3679
3280
  get schema() {
3680
3281
  return this._def.getter();
@@ -3724,10 +3325,6 @@ function createZodEnum(values, params) {
3724
3325
  });
3725
3326
  }
3726
3327
  class ZodEnum extends ZodType {
3727
- constructor() {
3728
- super(...arguments);
3729
- _ZodEnum_cache.set(this, void 0);
3730
- }
3731
3328
  _parse(input) {
3732
3329
  if (typeof input.data !== "string") {
3733
3330
  const ctx = this._getOrReturnCtx(input);
@@ -3739,10 +3336,10 @@ class ZodEnum extends ZodType {
3739
3336
  });
3740
3337
  return INVALID;
3741
3338
  }
3742
- if (!__classPrivateFieldGet(this, _ZodEnum_cache)) {
3743
- __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values));
3339
+ if (!this._cache) {
3340
+ this._cache = new Set(this._def.values);
3744
3341
  }
3745
- if (!__classPrivateFieldGet(this, _ZodEnum_cache).has(input.data)) {
3342
+ if (!this._cache.has(input.data)) {
3746
3343
  const ctx = this._getOrReturnCtx(input);
3747
3344
  const expectedValues = this._def.values;
3748
3345
  addIssueToContext(ctx, {
@@ -3791,18 +3388,12 @@ class ZodEnum extends ZodType {
3791
3388
  });
3792
3389
  }
3793
3390
  }
3794
- _ZodEnum_cache = new WeakMap();
3795
3391
  ZodEnum.create = createZodEnum;
3796
3392
  class ZodNativeEnum extends ZodType {
3797
- constructor() {
3798
- super(...arguments);
3799
- _ZodNativeEnum_cache.set(this, void 0);
3800
- }
3801
3393
  _parse(input) {
3802
3394
  const nativeEnumValues = util$1.getValidEnumValues(this._def.values);
3803
3395
  const ctx = this._getOrReturnCtx(input);
3804
- if (ctx.parsedType !== ZodParsedType.string &&
3805
- ctx.parsedType !== ZodParsedType.number) {
3396
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3806
3397
  const expectedValues = util$1.objectValues(nativeEnumValues);
3807
3398
  addIssueToContext(ctx, {
3808
3399
  expected: util$1.joinValues(expectedValues),
@@ -3811,10 +3402,10 @@ class ZodNativeEnum extends ZodType {
3811
3402
  });
3812
3403
  return INVALID;
3813
3404
  }
3814
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache)) {
3815
- __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util$1.getValidEnumValues(this._def.values)));
3405
+ if (!this._cache) {
3406
+ this._cache = new Set(util$1.getValidEnumValues(this._def.values));
3816
3407
  }
3817
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache).has(input.data)) {
3408
+ if (!this._cache.has(input.data)) {
3818
3409
  const expectedValues = util$1.objectValues(nativeEnumValues);
3819
3410
  addIssueToContext(ctx, {
3820
3411
  received: ctx.data,
@@ -3829,7 +3420,6 @@ class ZodNativeEnum extends ZodType {
3829
3420
  return this._def.values;
3830
3421
  }
3831
3422
  }
3832
- _ZodNativeEnum_cache = new WeakMap();
3833
3423
  ZodNativeEnum.create = (values, params) => {
3834
3424
  return new ZodNativeEnum({
3835
3425
  values: values,
@@ -3843,8 +3433,7 @@ class ZodPromise extends ZodType {
3843
3433
  }
3844
3434
  _parse(input) {
3845
3435
  const { ctx } = this._processInputParams(input);
3846
- if (ctx.parsedType !== ZodParsedType.promise &&
3847
- ctx.common.async === false) {
3436
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3848
3437
  addIssueToContext(ctx, {
3849
3438
  code: ZodIssueCode.invalid_type,
3850
3439
  expected: ZodParsedType.promise,
@@ -3852,9 +3441,7 @@ class ZodPromise extends ZodType {
3852
3441
  });
3853
3442
  return INVALID;
3854
3443
  }
3855
- const promisified = ctx.parsedType === ZodParsedType.promise
3856
- ? ctx.data
3857
- : Promise.resolve(ctx.data);
3444
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3858
3445
  return OK(promisified.then((data) => {
3859
3446
  return this._def.type.parseAsync(data, {
3860
3447
  path: ctx.path,
@@ -3960,9 +3547,7 @@ class ZodEffects extends ZodType {
3960
3547
  return { status: status.value, value: inner.value };
3961
3548
  }
3962
3549
  else {
3963
- return this._def.schema
3964
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3965
- .then((inner) => {
3550
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
3966
3551
  if (inner.status === "aborted")
3967
3552
  return INVALID;
3968
3553
  if (inner.status === "dirty")
@@ -3981,7 +3566,7 @@ class ZodEffects extends ZodType {
3981
3566
  parent: ctx,
3982
3567
  });
3983
3568
  if (!isValid(base))
3984
- return base;
3569
+ return INVALID;
3985
3570
  const result = effect.transform(base.value, checkCtx);
3986
3571
  if (result instanceof Promise) {
3987
3572
  throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
@@ -3989,12 +3574,13 @@ class ZodEffects extends ZodType {
3989
3574
  return { status: status.value, value: result };
3990
3575
  }
3991
3576
  else {
3992
- return this._def.schema
3993
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3994
- .then((base) => {
3577
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
3995
3578
  if (!isValid(base))
3996
- return base;
3997
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
3579
+ return INVALID;
3580
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
3581
+ status: status.value,
3582
+ value: result,
3583
+ }));
3998
3584
  });
3999
3585
  }
4000
3586
  }
@@ -4076,9 +3662,7 @@ ZodDefault.create = (type, params) => {
4076
3662
  return new ZodDefault({
4077
3663
  innerType: type,
4078
3664
  typeName: ZodFirstPartyTypeKind.ZodDefault,
4079
- defaultValue: typeof params.default === "function"
4080
- ? params.default
4081
- : () => params.default,
3665
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
4082
3666
  ...processCreateParams(params),
4083
3667
  });
4084
3668
  };
@@ -4162,7 +3746,6 @@ ZodNaN.create = (params) => {
4162
3746
  ...processCreateParams(params),
4163
3747
  });
4164
3748
  };
4165
- const BRAND = Symbol("zod_brand");
4166
3749
  class ZodBranded extends ZodType {
4167
3750
  _parse(input) {
4168
3751
  const { ctx } = this._processInputParams(input);
@@ -4244,9 +3827,7 @@ class ZodReadonly extends ZodType {
4244
3827
  }
4245
3828
  return data;
4246
3829
  };
4247
- return isAsync(result)
4248
- ? result.then((data) => freeze(data))
4249
- : freeze(result);
3830
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
4250
3831
  }
4251
3832
  unwrap() {
4252
3833
  return this._def.innerType;
@@ -4259,60 +3840,9 @@ ZodReadonly.create = (type, params) => {
4259
3840
  ...processCreateParams(params),
4260
3841
  });
4261
3842
  };
4262
- ////////////////////////////////////////
4263
- ////////////////////////////////////////
4264
- ////////// //////////
4265
- ////////// z.custom //////////
4266
- ////////// //////////
4267
- ////////////////////////////////////////
4268
- ////////////////////////////////////////
4269
- function cleanParams(params, data) {
4270
- const p = typeof params === "function"
4271
- ? params(data)
4272
- : typeof params === "string"
4273
- ? { message: params }
4274
- : params;
4275
- const p2 = typeof p === "string" ? { message: p } : p;
4276
- return p2;
4277
- }
4278
- function custom(check, _params = {},
4279
- /**
4280
- * @deprecated
4281
- *
4282
- * Pass `fatal` into the params object instead:
4283
- *
4284
- * ```ts
4285
- * z.string().custom((val) => val.length > 5, { fatal: false })
4286
- * ```
4287
- *
4288
- */
4289
- fatal) {
4290
- if (check)
4291
- return ZodAny.create().superRefine((data, ctx) => {
4292
- var _a, _b;
4293
- const r = check(data);
4294
- if (r instanceof Promise) {
4295
- return r.then((r) => {
4296
- var _a, _b;
4297
- if (!r) {
4298
- const params = cleanParams(_params, data);
4299
- const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
4300
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
4301
- }
4302
- });
4303
- }
4304
- if (!r) {
4305
- const params = cleanParams(_params, data);
4306
- const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
4307
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
4308
- }
4309
- return;
4310
- });
4311
- return ZodAny.create();
4312
- }
4313
- const late = {
3843
+ ({
4314
3844
  object: ZodObject.lazycreate,
4315
- };
3845
+ });
4316
3846
  var ZodFirstPartyTypeKind;
4317
3847
  (function (ZodFirstPartyTypeKind) {
4318
3848
  ZodFirstPartyTypeKind["ZodString"] = "ZodString";
@@ -4352,197 +3882,63 @@ var ZodFirstPartyTypeKind;
4352
3882
  ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
4353
3883
  ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
4354
3884
  })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4355
- const instanceOfType = (
4356
- // const instanceOfType = <T extends new (...args: any[]) => any>(
4357
- cls, params = {
4358
- message: `Input not instance of ${cls.name}`,
4359
- }) => custom((data) => data instanceof cls, params);
4360
3885
  const stringType = ZodString.create;
4361
3886
  const numberType = ZodNumber.create;
4362
- const nanType = ZodNaN.create;
4363
- const bigIntType = ZodBigInt.create;
3887
+ ZodNaN.create;
3888
+ ZodBigInt.create;
4364
3889
  const booleanType = ZodBoolean.create;
4365
- const dateType = ZodDate.create;
4366
- const symbolType = ZodSymbol.create;
4367
- const undefinedType = ZodUndefined.create;
4368
- const nullType = ZodNull.create;
3890
+ ZodDate.create;
3891
+ ZodSymbol.create;
3892
+ ZodUndefined.create;
3893
+ ZodNull.create;
4369
3894
  const anyType = ZodAny.create;
4370
- const unknownType = ZodUnknown.create;
4371
- const neverType = ZodNever.create;
4372
- const voidType = ZodVoid.create;
3895
+ ZodUnknown.create;
3896
+ ZodNever.create;
3897
+ ZodVoid.create;
4373
3898
  const arrayType = ZodArray.create;
4374
3899
  const objectType = ZodObject.create;
4375
- const strictObjectType = ZodObject.strictCreate;
4376
- const unionType = ZodUnion.create;
4377
- const discriminatedUnionType = ZodDiscriminatedUnion.create;
4378
- const intersectionType = ZodIntersection.create;
4379
- const tupleType = ZodTuple.create;
4380
- const recordType = ZodRecord.create;
4381
- const mapType = ZodMap.create;
4382
- const setType = ZodSet.create;
4383
- const functionType = ZodFunction.create;
4384
- const lazyType = ZodLazy.create;
4385
- const literalType = ZodLiteral.create;
4386
- const enumType = ZodEnum.create;
4387
- const nativeEnumType = ZodNativeEnum.create;
4388
- const promiseType = ZodPromise.create;
4389
- const effectsType = ZodEffects.create;
4390
- const optionalType = ZodOptional.create;
4391
- const nullableType = ZodNullable.create;
4392
- const preprocessType = ZodEffects.createWithPreprocess;
4393
- const pipelineType = ZodPipeline.create;
4394
- const ostring = () => stringType().optional();
4395
- const onumber = () => numberType().optional();
4396
- const oboolean = () => booleanType().optional();
4397
- const coerce = {
4398
- string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4399
- number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4400
- boolean: ((arg) => ZodBoolean.create({
4401
- ...arg,
4402
- coerce: true,
4403
- })),
4404
- bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4405
- date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
4406
- };
4407
- const NEVER = INVALID;
4408
-
4409
- var z = /*#__PURE__*/Object.freeze({
4410
- __proto__: null,
4411
- defaultErrorMap: errorMap,
4412
- setErrorMap: setErrorMap,
4413
- getErrorMap: getErrorMap,
4414
- makeIssue: makeIssue,
4415
- EMPTY_PATH: EMPTY_PATH,
4416
- addIssueToContext: addIssueToContext,
4417
- ParseStatus: ParseStatus,
4418
- INVALID: INVALID,
4419
- DIRTY: DIRTY,
4420
- OK: OK,
4421
- isAborted: isAborted,
4422
- isDirty: isDirty,
4423
- isValid: isValid,
4424
- isAsync: isAsync,
4425
- get util () { return util$1; },
4426
- get objectUtil () { return objectUtil; },
4427
- ZodParsedType: ZodParsedType,
4428
- getParsedType: getParsedType,
4429
- ZodType: ZodType,
4430
- datetimeRegex: datetimeRegex,
4431
- ZodString: ZodString,
4432
- ZodNumber: ZodNumber,
4433
- ZodBigInt: ZodBigInt,
4434
- ZodBoolean: ZodBoolean,
4435
- ZodDate: ZodDate,
4436
- ZodSymbol: ZodSymbol,
4437
- ZodUndefined: ZodUndefined,
4438
- ZodNull: ZodNull,
4439
- ZodAny: ZodAny,
4440
- ZodUnknown: ZodUnknown,
4441
- ZodNever: ZodNever,
4442
- ZodVoid: ZodVoid,
4443
- ZodArray: ZodArray,
4444
- ZodObject: ZodObject,
4445
- ZodUnion: ZodUnion,
4446
- ZodDiscriminatedUnion: ZodDiscriminatedUnion,
4447
- ZodIntersection: ZodIntersection,
4448
- ZodTuple: ZodTuple,
4449
- ZodRecord: ZodRecord,
4450
- ZodMap: ZodMap,
4451
- ZodSet: ZodSet,
4452
- ZodFunction: ZodFunction,
4453
- ZodLazy: ZodLazy,
4454
- ZodLiteral: ZodLiteral,
4455
- ZodEnum: ZodEnum,
4456
- ZodNativeEnum: ZodNativeEnum,
4457
- ZodPromise: ZodPromise,
4458
- ZodEffects: ZodEffects,
4459
- ZodTransformer: ZodEffects,
4460
- ZodOptional: ZodOptional,
4461
- ZodNullable: ZodNullable,
4462
- ZodDefault: ZodDefault,
4463
- ZodCatch: ZodCatch,
4464
- ZodNaN: ZodNaN,
4465
- BRAND: BRAND,
4466
- ZodBranded: ZodBranded,
4467
- ZodPipeline: ZodPipeline,
4468
- ZodReadonly: ZodReadonly,
4469
- custom: custom,
4470
- Schema: ZodType,
4471
- ZodSchema: ZodType,
4472
- late: late,
4473
- get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
4474
- coerce: coerce,
4475
- any: anyType,
4476
- array: arrayType,
4477
- bigint: bigIntType,
4478
- boolean: booleanType,
4479
- date: dateType,
4480
- discriminatedUnion: discriminatedUnionType,
4481
- effect: effectsType,
4482
- 'enum': enumType,
4483
- 'function': functionType,
4484
- 'instanceof': instanceOfType,
4485
- intersection: intersectionType,
4486
- lazy: lazyType,
4487
- literal: literalType,
4488
- map: mapType,
4489
- nan: nanType,
4490
- nativeEnum: nativeEnumType,
4491
- never: neverType,
4492
- 'null': nullType,
4493
- nullable: nullableType,
4494
- number: numberType,
4495
- object: objectType,
4496
- oboolean: oboolean,
4497
- onumber: onumber,
4498
- optional: optionalType,
4499
- ostring: ostring,
4500
- pipeline: pipelineType,
4501
- preprocess: preprocessType,
4502
- promise: promiseType,
4503
- record: recordType,
4504
- set: setType,
4505
- strictObject: strictObjectType,
4506
- string: stringType,
4507
- symbol: symbolType,
4508
- transformer: effectsType,
4509
- tuple: tupleType,
4510
- 'undefined': undefinedType,
4511
- union: unionType,
4512
- unknown: unknownType,
4513
- 'void': voidType,
4514
- NEVER: NEVER,
4515
- ZodIssueCode: ZodIssueCode,
4516
- quotelessJson: quotelessJson,
4517
- ZodError: ZodError
4518
- });
3900
+ ZodObject.strictCreate;
3901
+ ZodUnion.create;
3902
+ ZodIntersection.create;
3903
+ ZodTuple.create;
3904
+ ZodMap.create;
3905
+ ZodSet.create;
3906
+ ZodLazy.create;
3907
+ ZodLiteral.create;
3908
+ ZodEnum.create;
3909
+ ZodNativeEnum.create;
3910
+ ZodPromise.create;
3911
+ ZodEffects.create;
3912
+ ZodOptional.create;
3913
+ ZodNullable.create;
3914
+ ZodEffects.createWithPreprocess;
4519
3915
 
4520
3916
  const schemaFormRule = (rule) => {
4521
3917
  switch (rule.type) {
4522
3918
  case 'string':
4523
- let stringSchema = z.string();
4524
- if (rule.minLength)
4525
- stringSchema = stringSchema.min(rule.minLength, `String must be at least ${rule.minLength} characters long.`);
4526
- if (rule.maxLength)
4527
- stringSchema = stringSchema.max(rule.maxLength, `String must not exceed ${rule.maxLength} characters.`);
3919
+ let stringSchema = stringType();
3920
+ if (rule.min)
3921
+ stringSchema = stringSchema.min(rule.min, `String must be at least ${rule.min} characters long.`);
3922
+ if (rule.max)
3923
+ stringSchema = stringSchema.max(rule.max, `String must not exceed ${rule.max} characters.`);
4528
3924
  if (rule.regex)
4529
3925
  stringSchema = stringSchema.regex(new RegExp(rule.regex), 'Invalid format');
4530
3926
  return stringSchema;
4531
3927
  case 'number':
4532
- let numberSchema = z.number();
3928
+ let numberSchema = numberType();
4533
3929
  if (rule.min)
4534
3930
  numberSchema = numberSchema.min(rule.min, `Number must be at least ${rule.min}.`);
4535
3931
  if (rule.max)
4536
3932
  numberSchema = numberSchema.max(rule.max, `Number must not exceed ${rule.max}.`);
4537
3933
  return numberSchema;
4538
3934
  case 'boolean':
4539
- return z.boolean();
3935
+ return booleanType();
4540
3936
  case 'array':
4541
- return z.array(createSchema(rule.items));
3937
+ return arrayType(createSchema(rule.items));
4542
3938
  case 'object':
4543
- return z.object(Object.fromEntries(Object.entries(rule.properties).map(([key, value]) => [key, createSchema(value)])));
3939
+ return objectType(Object.fromEntries(Object.entries(rule.properties).map(([key, value]) => [key, createSchema(value)])));
4544
3940
  case 'any':
4545
- return z.any();
3941
+ return anyType();
4546
3942
  default:
4547
3943
  throw new Error(`Unknown rule type: ${rule?.type}`);
4548
3944
  }
@@ -12169,6 +11565,9 @@ class App {
12169
11565
  throw(...args) {
12170
11566
  throw new CustomError(...args);
12171
11567
  }
11568
+ static handleRequest(req, res) {
11569
+ return handleServer(req, res);
11570
+ }
12172
11571
  }
12173
11572
 
12174
11573
  export { App, Connect, CustomError, QueryConnect, QueryRouter, QueryRouterServer, QueryUtil, Route, ZodType as Schema, Server, createSchema, define, handleServer, util };