@thirstie/thirstievalidators 1.5.0 → 1.5.2

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/bundle.cjs CHANGED
@@ -174,7 +174,7 @@ const trustedEmailDomains = [
174
174
 
175
175
  var util;
176
176
  (function (util) {
177
- util.assertEqual = (val) => val;
177
+ util.assertEqual = (_) => { };
178
178
  function assertIs(_arg) { }
179
179
  util.assertIs = assertIs;
180
180
  function assertNever(_x) {
@@ -221,11 +221,9 @@ var util;
221
221
  };
222
222
  util.isInteger = typeof Number.isInteger === "function"
223
223
  ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
224
- : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
224
+ : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
225
225
  function joinValues(array, separator = " | ") {
226
- return array
227
- .map((val) => (typeof val === "string" ? `'${val}'` : val))
228
- .join(separator);
226
+ return array.map((val) => (typeof val === "string" ? `'${val}'` : val)).join(separator);
229
227
  }
230
228
  util.joinValues = joinValues;
231
229
  util.jsonStringifyReplacer = (_, value) => {
@@ -274,7 +272,7 @@ const getParsedType = (data) => {
274
272
  case "string":
275
273
  return ZodParsedType.string;
276
274
  case "number":
277
- return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
275
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
278
276
  case "boolean":
279
277
  return ZodParsedType.boolean;
280
278
  case "function":
@@ -290,10 +288,7 @@ const getParsedType = (data) => {
290
288
  if (data === null) {
291
289
  return ZodParsedType.null;
292
290
  }
293
- if (data.then &&
294
- typeof data.then === "function" &&
295
- data.catch &&
296
- typeof data.catch === "function") {
291
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
297
292
  return ZodParsedType.promise;
298
293
  }
299
294
  if (typeof Map !== "undefined" && data instanceof Map) {
@@ -329,10 +324,6 @@ const ZodIssueCode = util.arrayToEnum([
329
324
  "not_multiple_of",
330
325
  "not_finite",
331
326
  ]);
332
- const quotelessJson = (obj) => {
333
- const json = JSON.stringify(obj, null, 2);
334
- return json.replace(/"([^"]+)":/g, "$1:");
335
- };
336
327
  class ZodError extends Error {
337
328
  get errors() {
338
329
  return this.issues;
@@ -425,8 +416,9 @@ class ZodError extends Error {
425
416
  const formErrors = [];
426
417
  for (const sub of this.issues) {
427
418
  if (sub.path.length > 0) {
428
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
429
- fieldErrors[sub.path[0]].push(mapper(sub));
419
+ const firstEl = sub.path[0];
420
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
421
+ fieldErrors[firstEl].push(mapper(sub));
430
422
  }
431
423
  else {
432
424
  formErrors.push(mapper(sub));
@@ -509,17 +501,11 @@ const errorMap = (issue, _ctx) => {
509
501
  else if (issue.type === "string")
510
502
  message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
511
503
  else if (issue.type === "number")
512
- message = `Number must be ${issue.exact
513
- ? `exactly equal to `
514
- : issue.inclusive
515
- ? `greater than or equal to `
516
- : `greater than `}${issue.minimum}`;
504
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
505
+ else if (issue.type === "bigint")
506
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
517
507
  else if (issue.type === "date")
518
- message = `Date must be ${issue.exact
519
- ? `exactly equal to `
520
- : issue.inclusive
521
- ? `greater than or equal to `
522
- : `greater than `}${new Date(Number(issue.minimum))}`;
508
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
523
509
  else
524
510
  message = "Invalid input";
525
511
  break;
@@ -529,23 +515,11 @@ const errorMap = (issue, _ctx) => {
529
515
  else if (issue.type === "string")
530
516
  message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
531
517
  else if (issue.type === "number")
532
- message = `Number must be ${issue.exact
533
- ? `exactly`
534
- : issue.inclusive
535
- ? `less than or equal to`
536
- : `less than`} ${issue.maximum}`;
518
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
537
519
  else if (issue.type === "bigint")
538
- message = `BigInt must be ${issue.exact
539
- ? `exactly`
540
- : issue.inclusive
541
- ? `less than or equal to`
542
- : `less than`} ${issue.maximum}`;
520
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
543
521
  else if (issue.type === "date")
544
- message = `Date must be ${issue.exact
545
- ? `exactly`
546
- : issue.inclusive
547
- ? `smaller than or equal to`
548
- : `smaller than`} ${new Date(Number(issue.maximum))}`;
522
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
549
523
  else
550
524
  message = "Invalid input";
551
525
  break;
@@ -569,9 +543,6 @@ const errorMap = (issue, _ctx) => {
569
543
  };
570
544
 
571
545
  let overrideErrorMap = errorMap;
572
- function setErrorMap(map) {
573
- overrideErrorMap = map;
574
- }
575
546
  function getErrorMap() {
576
547
  return overrideErrorMap;
577
548
  }
@@ -604,7 +575,6 @@ const makeIssue = (params) => {
604
575
  message: errorMessage,
605
576
  };
606
577
  };
607
- const EMPTY_PATH = [];
608
578
  function addIssueToContext(ctx, issueData) {
609
579
  const overrideMap = getErrorMap();
610
580
  const issue = makeIssue({
@@ -667,8 +637,7 @@ class ParseStatus {
667
637
  status.dirty();
668
638
  if (value.status === "dirty")
669
639
  status.dirty();
670
- if (key.value !== "__proto__" &&
671
- (typeof value.value !== "undefined" || pair.alwaysSet)) {
640
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
672
641
  finalObject[key.value] = value.value;
673
642
  }
674
643
  }
@@ -685,43 +654,13 @@ const isDirty = (x) => x.status === "dirty";
685
654
  const isValid = (x) => x.status === "valid";
686
655
  const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
687
656
 
688
- /******************************************************************************
689
- Copyright (c) Microsoft Corporation.
690
-
691
- Permission to use, copy, modify, and/or distribute this software for any
692
- purpose with or without fee is hereby granted.
693
-
694
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
695
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
696
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
697
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
698
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
699
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
700
- PERFORMANCE OF THIS SOFTWARE.
701
- ***************************************************************************** */
702
-
703
- function __classPrivateFieldGet(receiver, state, kind, f) {
704
- 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");
705
- return state.get(receiver);
706
- }
707
-
708
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
709
- 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");
710
- return (state.set(receiver, value)), value;
711
- }
712
-
713
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
714
- var e = new Error(message);
715
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
716
- };
717
-
718
657
  var errorUtil;
719
658
  (function (errorUtil) {
720
659
  errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
721
- errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
660
+ // biome-ignore lint:
661
+ errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
722
662
  })(errorUtil || (errorUtil = {}));
723
663
 
724
- var _ZodEnum_cache, _ZodNativeEnum_cache;
725
664
  class ParseInputLazyPath {
726
665
  constructor(parent, value, path, key) {
727
666
  this._cachedPath = [];
@@ -732,7 +671,7 @@ class ParseInputLazyPath {
732
671
  }
733
672
  get path() {
734
673
  if (!this._cachedPath.length) {
735
- if (this._key instanceof Array) {
674
+ if (Array.isArray(this._key)) {
736
675
  this._cachedPath.push(...this._path, ...this._key);
737
676
  }
738
677
  else {
@@ -772,17 +711,16 @@ function processCreateParams(params) {
772
711
  if (errorMap)
773
712
  return { errorMap: errorMap, description };
774
713
  const customMap = (iss, ctx) => {
775
- var _a, _b;
776
714
  const { message } = params;
777
715
  if (iss.code === "invalid_enum_value") {
778
- return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
716
+ return { message: message ?? ctx.defaultError };
779
717
  }
780
718
  if (typeof ctx.data === "undefined") {
781
- return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
719
+ return { message: message ?? required_error ?? ctx.defaultError };
782
720
  }
783
721
  if (iss.code !== "invalid_type")
784
722
  return { message: ctx.defaultError };
785
- return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
723
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
786
724
  };
787
725
  return { errorMap: customMap, description };
788
726
  }
@@ -834,14 +772,13 @@ class ZodType {
834
772
  throw result.error;
835
773
  }
836
774
  safeParse(data, params) {
837
- var _a;
838
775
  const ctx = {
839
776
  common: {
840
777
  issues: [],
841
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
842
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
778
+ async: params?.async ?? false,
779
+ contextualErrorMap: params?.errorMap,
843
780
  },
844
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
781
+ path: params?.path || [],
845
782
  schemaErrorMap: this._def.errorMap,
846
783
  parent: null,
847
784
  data,
@@ -851,7 +788,6 @@ class ZodType {
851
788
  return handleResult(ctx, result);
852
789
  }
853
790
  "~validate"(data) {
854
- var _a, _b;
855
791
  const ctx = {
856
792
  common: {
857
793
  issues: [],
@@ -875,7 +811,7 @@ class ZodType {
875
811
  };
876
812
  }
877
813
  catch (err) {
878
- 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")) {
814
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
879
815
  this["~standard"].async = true;
880
816
  }
881
817
  ctx.common = {
@@ -902,19 +838,17 @@ class ZodType {
902
838
  const ctx = {
903
839
  common: {
904
840
  issues: [],
905
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
841
+ contextualErrorMap: params?.errorMap,
906
842
  async: true,
907
843
  },
908
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
844
+ path: params?.path || [],
909
845
  schemaErrorMap: this._def.errorMap,
910
846
  parent: null,
911
847
  data,
912
848
  parsedType: getParsedType(data),
913
849
  };
914
850
  const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
915
- const result = await (isAsync(maybeAsyncResult)
916
- ? maybeAsyncResult
917
- : Promise.resolve(maybeAsyncResult));
851
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
918
852
  return handleResult(ctx, result);
919
853
  }
920
854
  refine(check, message) {
@@ -958,9 +892,7 @@ class ZodType {
958
892
  refinement(check, refinementData) {
959
893
  return this._refinement((val, ctx) => {
960
894
  if (!check(val)) {
961
- ctx.addIssue(typeof refinementData === "function"
962
- ? refinementData(val, ctx)
963
- : refinementData);
895
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
964
896
  return false;
965
897
  }
966
898
  else {
@@ -1132,15 +1064,15 @@ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z
1132
1064
  const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
1133
1065
  const dateRegex = new RegExp(`^${dateRegexSource}$`);
1134
1066
  function timeRegexSource(args) {
1135
- // let regex = `\\d{2}:\\d{2}:\\d{2}`;
1136
- let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
1067
+ let secondsRegexSource = `[0-5]\\d`;
1137
1068
  if (args.precision) {
1138
- regex = `${regex}\\.\\d{${args.precision}}`;
1069
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
1139
1070
  }
1140
1071
  else if (args.precision == null) {
1141
- regex = `${regex}(\\.\\d+)?`;
1072
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
1142
1073
  }
1143
- return regex;
1074
+ const secondsQuantifier = args.precision ? "+" : "?"; // require seconds if precision is nonzero
1075
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
1144
1076
  }
1145
1077
  function timeRegex(args) {
1146
1078
  return new RegExp(`^${timeRegexSource(args)}$`);
@@ -1169,6 +1101,8 @@ function isValidJWT(jwt, alg) {
1169
1101
  return false;
1170
1102
  try {
1171
1103
  const [header] = jwt.split(".");
1104
+ if (!header)
1105
+ return false;
1172
1106
  // Convert base64url to base64
1173
1107
  const base64 = header
1174
1108
  .replace(/-/g, "+")
@@ -1177,13 +1111,15 @@ function isValidJWT(jwt, alg) {
1177
1111
  const decoded = JSON.parse(atob(base64));
1178
1112
  if (typeof decoded !== "object" || decoded === null)
1179
1113
  return false;
1180
- if (!decoded.typ || !decoded.alg)
1114
+ if ("typ" in decoded && decoded?.typ !== "JWT")
1115
+ return false;
1116
+ if (!decoded.alg)
1181
1117
  return false;
1182
1118
  if (alg && decoded.alg !== alg)
1183
1119
  return false;
1184
1120
  return true;
1185
1121
  }
1186
- catch (_a) {
1122
+ catch {
1187
1123
  return false;
1188
1124
  }
1189
1125
  }
@@ -1354,7 +1290,7 @@ class ZodString extends ZodType {
1354
1290
  try {
1355
1291
  new URL(input.data);
1356
1292
  }
1357
- catch (_a) {
1293
+ catch {
1358
1294
  ctx = this._getOrReturnCtx(input, ctx);
1359
1295
  addIssueToContext(ctx, {
1360
1296
  validation: "url",
@@ -1584,7 +1520,6 @@ class ZodString extends ZodType {
1584
1520
  return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1585
1521
  }
1586
1522
  datetime(options) {
1587
- var _a, _b;
1588
1523
  if (typeof options === "string") {
1589
1524
  return this._addCheck({
1590
1525
  kind: "datetime",
@@ -1596,10 +1531,10 @@ class ZodString extends ZodType {
1596
1531
  }
1597
1532
  return this._addCheck({
1598
1533
  kind: "datetime",
1599
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1600
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
1601
- local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
1602
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1534
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1535
+ offset: options?.offset ?? false,
1536
+ local: options?.local ?? false,
1537
+ ...errorUtil.errToObj(options?.message),
1603
1538
  });
1604
1539
  }
1605
1540
  date(message) {
@@ -1615,8 +1550,8 @@ class ZodString extends ZodType {
1615
1550
  }
1616
1551
  return this._addCheck({
1617
1552
  kind: "time",
1618
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1619
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1553
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1554
+ ...errorUtil.errToObj(options?.message),
1620
1555
  });
1621
1556
  }
1622
1557
  duration(message) {
@@ -1633,8 +1568,8 @@ class ZodString extends ZodType {
1633
1568
  return this._addCheck({
1634
1569
  kind: "includes",
1635
1570
  value: value,
1636
- position: options === null || options === void 0 ? void 0 : options.position,
1637
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1571
+ position: options?.position,
1572
+ ...errorUtil.errToObj(options?.message),
1638
1573
  });
1639
1574
  }
1640
1575
  startsWith(value, message) {
@@ -1767,11 +1702,10 @@ class ZodString extends ZodType {
1767
1702
  }
1768
1703
  }
1769
1704
  ZodString.create = (params) => {
1770
- var _a;
1771
1705
  return new ZodString({
1772
1706
  checks: [],
1773
1707
  typeName: ZodFirstPartyTypeKind.ZodString,
1774
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1708
+ coerce: params?.coerce ?? false,
1775
1709
  ...processCreateParams(params),
1776
1710
  });
1777
1711
  };
@@ -1780,9 +1714,9 @@ function floatSafeRemainder(val, step) {
1780
1714
  const valDecCount = (val.toString().split(".")[1] || "").length;
1781
1715
  const stepDecCount = (step.toString().split(".")[1] || "").length;
1782
1716
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1783
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
1784
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
1785
- return (valInt % stepInt) / Math.pow(10, decCount);
1717
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1718
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1719
+ return (valInt % stepInt) / 10 ** decCount;
1786
1720
  }
1787
1721
  class ZodNumber extends ZodType {
1788
1722
  constructor() {
@@ -1821,9 +1755,7 @@ class ZodNumber extends ZodType {
1821
1755
  }
1822
1756
  }
1823
1757
  else if (check.kind === "min") {
1824
- const tooSmall = check.inclusive
1825
- ? input.data < check.value
1826
- : input.data <= check.value;
1758
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1827
1759
  if (tooSmall) {
1828
1760
  ctx = this._getOrReturnCtx(input, ctx);
1829
1761
  addIssueToContext(ctx, {
@@ -1838,9 +1770,7 @@ class ZodNumber extends ZodType {
1838
1770
  }
1839
1771
  }
1840
1772
  else if (check.kind === "max") {
1841
- const tooBig = check.inclusive
1842
- ? input.data > check.value
1843
- : input.data >= check.value;
1773
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1844
1774
  if (tooBig) {
1845
1775
  ctx = this._getOrReturnCtx(input, ctx);
1846
1776
  addIssueToContext(ctx, {
@@ -1998,15 +1928,13 @@ class ZodNumber extends ZodType {
1998
1928
  return max;
1999
1929
  }
2000
1930
  get isInt() {
2001
- return !!this._def.checks.find((ch) => ch.kind === "int" ||
2002
- (ch.kind === "multipleOf" && util.isInteger(ch.value)));
1931
+ return !!this._def.checks.find((ch) => ch.kind === "int" || (ch.kind === "multipleOf" && util.isInteger(ch.value)));
2003
1932
  }
2004
1933
  get isFinite() {
2005
- let max = null, min = null;
1934
+ let max = null;
1935
+ let min = null;
2006
1936
  for (const ch of this._def.checks) {
2007
- if (ch.kind === "finite" ||
2008
- ch.kind === "int" ||
2009
- ch.kind === "multipleOf") {
1937
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
2010
1938
  return true;
2011
1939
  }
2012
1940
  else if (ch.kind === "min") {
@@ -2025,7 +1953,7 @@ ZodNumber.create = (params) => {
2025
1953
  return new ZodNumber({
2026
1954
  checks: [],
2027
1955
  typeName: ZodFirstPartyTypeKind.ZodNumber,
2028
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1956
+ coerce: params?.coerce || false,
2029
1957
  ...processCreateParams(params),
2030
1958
  });
2031
1959
  };
@@ -2040,7 +1968,7 @@ class ZodBigInt extends ZodType {
2040
1968
  try {
2041
1969
  input.data = BigInt(input.data);
2042
1970
  }
2043
- catch (_a) {
1971
+ catch {
2044
1972
  return this._getInvalidInput(input);
2045
1973
  }
2046
1974
  }
@@ -2052,9 +1980,7 @@ class ZodBigInt extends ZodType {
2052
1980
  const status = new ParseStatus();
2053
1981
  for (const check of this._def.checks) {
2054
1982
  if (check.kind === "min") {
2055
- const tooSmall = check.inclusive
2056
- ? input.data < check.value
2057
- : input.data <= check.value;
1983
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2058
1984
  if (tooSmall) {
2059
1985
  ctx = this._getOrReturnCtx(input, ctx);
2060
1986
  addIssueToContext(ctx, {
@@ -2068,9 +1994,7 @@ class ZodBigInt extends ZodType {
2068
1994
  }
2069
1995
  }
2070
1996
  else if (check.kind === "max") {
2071
- const tooBig = check.inclusive
2072
- ? input.data > check.value
2073
- : input.data >= check.value;
1997
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2074
1998
  if (tooBig) {
2075
1999
  ctx = this._getOrReturnCtx(input, ctx);
2076
2000
  addIssueToContext(ctx, {
@@ -2202,11 +2126,10 @@ class ZodBigInt extends ZodType {
2202
2126
  }
2203
2127
  }
2204
2128
  ZodBigInt.create = (params) => {
2205
- var _a;
2206
2129
  return new ZodBigInt({
2207
2130
  checks: [],
2208
2131
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
2209
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
2132
+ coerce: params?.coerce ?? false,
2210
2133
  ...processCreateParams(params),
2211
2134
  });
2212
2135
  };
@@ -2231,7 +2154,7 @@ class ZodBoolean extends ZodType {
2231
2154
  ZodBoolean.create = (params) => {
2232
2155
  return new ZodBoolean({
2233
2156
  typeName: ZodFirstPartyTypeKind.ZodBoolean,
2234
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2157
+ coerce: params?.coerce || false,
2235
2158
  ...processCreateParams(params),
2236
2159
  });
2237
2160
  };
@@ -2250,7 +2173,7 @@ class ZodDate extends ZodType {
2250
2173
  });
2251
2174
  return INVALID;
2252
2175
  }
2253
- if (isNaN(input.data.getTime())) {
2176
+ if (Number.isNaN(input.data.getTime())) {
2254
2177
  const ctx = this._getOrReturnCtx(input);
2255
2178
  addIssueToContext(ctx, {
2256
2179
  code: ZodIssueCode.invalid_date,
@@ -2341,7 +2264,7 @@ class ZodDate extends ZodType {
2341
2264
  ZodDate.create = (params) => {
2342
2265
  return new ZodDate({
2343
2266
  checks: [],
2344
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2267
+ coerce: params?.coerce || false,
2345
2268
  typeName: ZodFirstPartyTypeKind.ZodDate,
2346
2269
  ...processCreateParams(params),
2347
2270
  });
@@ -2663,7 +2586,8 @@ class ZodObject extends ZodType {
2663
2586
  return this._cached;
2664
2587
  const shape = this._def.shape();
2665
2588
  const keys = util.objectKeys(shape);
2666
- return (this._cached = { shape, keys });
2589
+ this._cached = { shape, keys };
2590
+ return this._cached;
2667
2591
  }
2668
2592
  _parse(input) {
2669
2593
  const parsedType = this._getType(input);
@@ -2679,8 +2603,7 @@ class ZodObject extends ZodType {
2679
2603
  const { status, ctx } = this._processInputParams(input);
2680
2604
  const { shape, keys: shapeKeys } = this._getCached();
2681
2605
  const extraKeys = [];
2682
- if (!(this._def.catchall instanceof ZodNever &&
2683
- this._def.unknownKeys === "strip")) {
2606
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2684
2607
  for (const key in ctx.data) {
2685
2608
  if (!shapeKeys.includes(key)) {
2686
2609
  extraKeys.push(key);
@@ -2768,11 +2691,10 @@ class ZodObject extends ZodType {
2768
2691
  ...(message !== undefined
2769
2692
  ? {
2770
2693
  errorMap: (issue, ctx) => {
2771
- var _a, _b, _c, _d;
2772
- 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;
2694
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2773
2695
  if (issue.code === "unrecognized_keys")
2774
2696
  return {
2775
- message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
2697
+ message: errorUtil.errToObj(message).message ?? defaultError,
2776
2698
  };
2777
2699
  return {
2778
2700
  message: defaultError,
@@ -2904,11 +2826,11 @@ class ZodObject extends ZodType {
2904
2826
  }
2905
2827
  pick(mask) {
2906
2828
  const shape = {};
2907
- util.objectKeys(mask).forEach((key) => {
2829
+ for (const key of util.objectKeys(mask)) {
2908
2830
  if (mask[key] && this.shape[key]) {
2909
2831
  shape[key] = this.shape[key];
2910
2832
  }
2911
- });
2833
+ }
2912
2834
  return new ZodObject({
2913
2835
  ...this._def,
2914
2836
  shape: () => shape,
@@ -2916,11 +2838,11 @@ class ZodObject extends ZodType {
2916
2838
  }
2917
2839
  omit(mask) {
2918
2840
  const shape = {};
2919
- util.objectKeys(this.shape).forEach((key) => {
2841
+ for (const key of util.objectKeys(this.shape)) {
2920
2842
  if (!mask[key]) {
2921
2843
  shape[key] = this.shape[key];
2922
2844
  }
2923
- });
2845
+ }
2924
2846
  return new ZodObject({
2925
2847
  ...this._def,
2926
2848
  shape: () => shape,
@@ -2934,7 +2856,7 @@ class ZodObject extends ZodType {
2934
2856
  }
2935
2857
  partial(mask) {
2936
2858
  const newShape = {};
2937
- util.objectKeys(this.shape).forEach((key) => {
2859
+ for (const key of util.objectKeys(this.shape)) {
2938
2860
  const fieldSchema = this.shape[key];
2939
2861
  if (mask && !mask[key]) {
2940
2862
  newShape[key] = fieldSchema;
@@ -2942,7 +2864,7 @@ class ZodObject extends ZodType {
2942
2864
  else {
2943
2865
  newShape[key] = fieldSchema.optional();
2944
2866
  }
2945
- });
2867
+ }
2946
2868
  return new ZodObject({
2947
2869
  ...this._def,
2948
2870
  shape: () => newShape,
@@ -2950,7 +2872,7 @@ class ZodObject extends ZodType {
2950
2872
  }
2951
2873
  required(mask) {
2952
2874
  const newShape = {};
2953
- util.objectKeys(this.shape).forEach((key) => {
2875
+ for (const key of util.objectKeys(this.shape)) {
2954
2876
  if (mask && !mask[key]) {
2955
2877
  newShape[key] = this.shape[key];
2956
2878
  }
@@ -2962,7 +2884,7 @@ class ZodObject extends ZodType {
2962
2884
  }
2963
2885
  newShape[key] = newField;
2964
2886
  }
2965
- });
2887
+ }
2966
2888
  return new ZodObject({
2967
2889
  ...this._def,
2968
2890
  shape: () => newShape,
@@ -3095,137 +3017,6 @@ ZodUnion.create = (types, params) => {
3095
3017
  ...processCreateParams(params),
3096
3018
  });
3097
3019
  };
3098
- /////////////////////////////////////////////////////
3099
- /////////////////////////////////////////////////////
3100
- ////////// //////////
3101
- ////////// ZodDiscriminatedUnion //////////
3102
- ////////// //////////
3103
- /////////////////////////////////////////////////////
3104
- /////////////////////////////////////////////////////
3105
- const getDiscriminator = (type) => {
3106
- if (type instanceof ZodLazy) {
3107
- return getDiscriminator(type.schema);
3108
- }
3109
- else if (type instanceof ZodEffects) {
3110
- return getDiscriminator(type.innerType());
3111
- }
3112
- else if (type instanceof ZodLiteral) {
3113
- return [type.value];
3114
- }
3115
- else if (type instanceof ZodEnum) {
3116
- return type.options;
3117
- }
3118
- else if (type instanceof ZodNativeEnum) {
3119
- // eslint-disable-next-line ban/ban
3120
- return util.objectValues(type.enum);
3121
- }
3122
- else if (type instanceof ZodDefault) {
3123
- return getDiscriminator(type._def.innerType);
3124
- }
3125
- else if (type instanceof ZodUndefined) {
3126
- return [undefined];
3127
- }
3128
- else if (type instanceof ZodNull) {
3129
- return [null];
3130
- }
3131
- else if (type instanceof ZodOptional) {
3132
- return [undefined, ...getDiscriminator(type.unwrap())];
3133
- }
3134
- else if (type instanceof ZodNullable) {
3135
- return [null, ...getDiscriminator(type.unwrap())];
3136
- }
3137
- else if (type instanceof ZodBranded) {
3138
- return getDiscriminator(type.unwrap());
3139
- }
3140
- else if (type instanceof ZodReadonly) {
3141
- return getDiscriminator(type.unwrap());
3142
- }
3143
- else if (type instanceof ZodCatch) {
3144
- return getDiscriminator(type._def.innerType);
3145
- }
3146
- else {
3147
- return [];
3148
- }
3149
- };
3150
- class ZodDiscriminatedUnion extends ZodType {
3151
- _parse(input) {
3152
- const { ctx } = this._processInputParams(input);
3153
- if (ctx.parsedType !== ZodParsedType.object) {
3154
- addIssueToContext(ctx, {
3155
- code: ZodIssueCode.invalid_type,
3156
- expected: ZodParsedType.object,
3157
- received: ctx.parsedType,
3158
- });
3159
- return INVALID;
3160
- }
3161
- const discriminator = this.discriminator;
3162
- const discriminatorValue = ctx.data[discriminator];
3163
- const option = this.optionsMap.get(discriminatorValue);
3164
- if (!option) {
3165
- addIssueToContext(ctx, {
3166
- code: ZodIssueCode.invalid_union_discriminator,
3167
- options: Array.from(this.optionsMap.keys()),
3168
- path: [discriminator],
3169
- });
3170
- return INVALID;
3171
- }
3172
- if (ctx.common.async) {
3173
- return option._parseAsync({
3174
- data: ctx.data,
3175
- path: ctx.path,
3176
- parent: ctx,
3177
- });
3178
- }
3179
- else {
3180
- return option._parseSync({
3181
- data: ctx.data,
3182
- path: ctx.path,
3183
- parent: ctx,
3184
- });
3185
- }
3186
- }
3187
- get discriminator() {
3188
- return this._def.discriminator;
3189
- }
3190
- get options() {
3191
- return this._def.options;
3192
- }
3193
- get optionsMap() {
3194
- return this._def.optionsMap;
3195
- }
3196
- /**
3197
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
3198
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
3199
- * have a different value for each object in the union.
3200
- * @param discriminator the name of the discriminator property
3201
- * @param types an array of object schemas
3202
- * @param params
3203
- */
3204
- static create(discriminator, options, params) {
3205
- // Get all the valid discriminator values
3206
- const optionsMap = new Map();
3207
- // try {
3208
- for (const type of options) {
3209
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3210
- if (!discriminatorValues.length) {
3211
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3212
- }
3213
- for (const value of discriminatorValues) {
3214
- if (optionsMap.has(value)) {
3215
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
3216
- }
3217
- optionsMap.set(value, type);
3218
- }
3219
- }
3220
- return new ZodDiscriminatedUnion({
3221
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
3222
- discriminator,
3223
- options,
3224
- optionsMap,
3225
- ...processCreateParams(params),
3226
- });
3227
- }
3228
- }
3229
3020
  function mergeValues(a, b) {
3230
3021
  const aType = getParsedType(a);
3231
3022
  const bType = getParsedType(b);
@@ -3234,9 +3025,7 @@ function mergeValues(a, b) {
3234
3025
  }
3235
3026
  else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
3236
3027
  const bKeys = util.objectKeys(b);
3237
- const sharedKeys = util
3238
- .objectKeys(a)
3239
- .filter((key) => bKeys.indexOf(key) !== -1);
3028
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
3240
3029
  const newObj = { ...a, ...b };
3241
3030
  for (const key of sharedKeys) {
3242
3031
  const sharedValue = mergeValues(a[key], b[key]);
@@ -3263,9 +3052,7 @@ function mergeValues(a, b) {
3263
3052
  }
3264
3053
  return { valid: true, data: newArray };
3265
3054
  }
3266
- else if (aType === ZodParsedType.date &&
3267
- bType === ZodParsedType.date &&
3268
- +a === +b) {
3055
+ else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
3269
3056
  return { valid: true, data: a };
3270
3057
  }
3271
3058
  else {
@@ -3326,6 +3113,7 @@ ZodIntersection.create = (left, right, params) => {
3326
3113
  ...processCreateParams(params),
3327
3114
  });
3328
3115
  };
3116
+ // type ZodTupleItems = [ZodTypeAny, ...ZodTypeAny[]];
3329
3117
  class ZodTuple extends ZodType {
3330
3118
  _parse(input) {
3331
3119
  const { status, ctx } = this._processInputParams(input);
@@ -3396,60 +3184,6 @@ ZodTuple.create = (schemas, params) => {
3396
3184
  ...processCreateParams(params),
3397
3185
  });
3398
3186
  };
3399
- class ZodRecord extends ZodType {
3400
- get keySchema() {
3401
- return this._def.keyType;
3402
- }
3403
- get valueSchema() {
3404
- return this._def.valueType;
3405
- }
3406
- _parse(input) {
3407
- const { status, ctx } = this._processInputParams(input);
3408
- if (ctx.parsedType !== ZodParsedType.object) {
3409
- addIssueToContext(ctx, {
3410
- code: ZodIssueCode.invalid_type,
3411
- expected: ZodParsedType.object,
3412
- received: ctx.parsedType,
3413
- });
3414
- return INVALID;
3415
- }
3416
- const pairs = [];
3417
- const keyType = this._def.keyType;
3418
- const valueType = this._def.valueType;
3419
- for (const key in ctx.data) {
3420
- pairs.push({
3421
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3422
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3423
- alwaysSet: key in ctx.data,
3424
- });
3425
- }
3426
- if (ctx.common.async) {
3427
- return ParseStatus.mergeObjectAsync(status, pairs);
3428
- }
3429
- else {
3430
- return ParseStatus.mergeObjectSync(status, pairs);
3431
- }
3432
- }
3433
- get element() {
3434
- return this._def.valueType;
3435
- }
3436
- static create(first, second, third) {
3437
- if (second instanceof ZodType) {
3438
- return new ZodRecord({
3439
- keyType: first,
3440
- valueType: second,
3441
- typeName: ZodFirstPartyTypeKind.ZodRecord,
3442
- ...processCreateParams(third),
3443
- });
3444
- }
3445
- return new ZodRecord({
3446
- keyType: ZodString.create(),
3447
- valueType: first,
3448
- typeName: ZodFirstPartyTypeKind.ZodRecord,
3449
- ...processCreateParams(second),
3450
- });
3451
- }
3452
- }
3453
3187
  class ZodMap extends ZodType {
3454
3188
  get keySchema() {
3455
3189
  return this._def.keyType;
@@ -3603,134 +3337,6 @@ ZodSet.create = (valueType, params) => {
3603
3337
  ...processCreateParams(params),
3604
3338
  });
3605
3339
  };
3606
- class ZodFunction extends ZodType {
3607
- constructor() {
3608
- super(...arguments);
3609
- this.validate = this.implement;
3610
- }
3611
- _parse(input) {
3612
- const { ctx } = this._processInputParams(input);
3613
- if (ctx.parsedType !== ZodParsedType.function) {
3614
- addIssueToContext(ctx, {
3615
- code: ZodIssueCode.invalid_type,
3616
- expected: ZodParsedType.function,
3617
- received: ctx.parsedType,
3618
- });
3619
- return INVALID;
3620
- }
3621
- function makeArgsIssue(args, error) {
3622
- return makeIssue({
3623
- data: args,
3624
- path: ctx.path,
3625
- errorMaps: [
3626
- ctx.common.contextualErrorMap,
3627
- ctx.schemaErrorMap,
3628
- getErrorMap(),
3629
- errorMap,
3630
- ].filter((x) => !!x),
3631
- issueData: {
3632
- code: ZodIssueCode.invalid_arguments,
3633
- argumentsError: error,
3634
- },
3635
- });
3636
- }
3637
- function makeReturnsIssue(returns, error) {
3638
- return makeIssue({
3639
- data: returns,
3640
- path: ctx.path,
3641
- errorMaps: [
3642
- ctx.common.contextualErrorMap,
3643
- ctx.schemaErrorMap,
3644
- getErrorMap(),
3645
- errorMap,
3646
- ].filter((x) => !!x),
3647
- issueData: {
3648
- code: ZodIssueCode.invalid_return_type,
3649
- returnTypeError: error,
3650
- },
3651
- });
3652
- }
3653
- const params = { errorMap: ctx.common.contextualErrorMap };
3654
- const fn = ctx.data;
3655
- if (this._def.returns instanceof ZodPromise) {
3656
- // Would love a way to avoid disabling this rule, but we need
3657
- // an alias (using an arrow function was what caused 2651).
3658
- // eslint-disable-next-line @typescript-eslint/no-this-alias
3659
- const me = this;
3660
- return OK(async function (...args) {
3661
- const error = new ZodError([]);
3662
- const parsedArgs = await me._def.args
3663
- .parseAsync(args, params)
3664
- .catch((e) => {
3665
- error.addIssue(makeArgsIssue(args, e));
3666
- throw error;
3667
- });
3668
- const result = await Reflect.apply(fn, this, parsedArgs);
3669
- const parsedReturns = await me._def.returns._def.type
3670
- .parseAsync(result, params)
3671
- .catch((e) => {
3672
- error.addIssue(makeReturnsIssue(result, e));
3673
- throw error;
3674
- });
3675
- return parsedReturns;
3676
- });
3677
- }
3678
- else {
3679
- // Would love a way to avoid disabling this rule, but we need
3680
- // an alias (using an arrow function was what caused 2651).
3681
- // eslint-disable-next-line @typescript-eslint/no-this-alias
3682
- const me = this;
3683
- return OK(function (...args) {
3684
- const parsedArgs = me._def.args.safeParse(args, params);
3685
- if (!parsedArgs.success) {
3686
- throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3687
- }
3688
- const result = Reflect.apply(fn, this, parsedArgs.data);
3689
- const parsedReturns = me._def.returns.safeParse(result, params);
3690
- if (!parsedReturns.success) {
3691
- throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3692
- }
3693
- return parsedReturns.data;
3694
- });
3695
- }
3696
- }
3697
- parameters() {
3698
- return this._def.args;
3699
- }
3700
- returnType() {
3701
- return this._def.returns;
3702
- }
3703
- args(...items) {
3704
- return new ZodFunction({
3705
- ...this._def,
3706
- args: ZodTuple.create(items).rest(ZodUnknown.create()),
3707
- });
3708
- }
3709
- returns(returnType) {
3710
- return new ZodFunction({
3711
- ...this._def,
3712
- returns: returnType,
3713
- });
3714
- }
3715
- implement(func) {
3716
- const validatedFunc = this.parse(func);
3717
- return validatedFunc;
3718
- }
3719
- strictImplement(func) {
3720
- const validatedFunc = this.parse(func);
3721
- return validatedFunc;
3722
- }
3723
- static create(args, returns, params) {
3724
- return new ZodFunction({
3725
- args: (args
3726
- ? args
3727
- : ZodTuple.create([]).rest(ZodUnknown.create())),
3728
- returns: returns || ZodUnknown.create(),
3729
- typeName: ZodFirstPartyTypeKind.ZodFunction,
3730
- ...processCreateParams(params),
3731
- });
3732
- }
3733
- }
3734
3340
  class ZodLazy extends ZodType {
3735
3341
  get schema() {
3736
3342
  return this._def.getter();
@@ -3780,10 +3386,6 @@ function createZodEnum(values, params) {
3780
3386
  });
3781
3387
  }
3782
3388
  class ZodEnum extends ZodType {
3783
- constructor() {
3784
- super(...arguments);
3785
- _ZodEnum_cache.set(this, void 0);
3786
- }
3787
3389
  _parse(input) {
3788
3390
  if (typeof input.data !== "string") {
3789
3391
  const ctx = this._getOrReturnCtx(input);
@@ -3795,10 +3397,10 @@ class ZodEnum extends ZodType {
3795
3397
  });
3796
3398
  return INVALID;
3797
3399
  }
3798
- if (!__classPrivateFieldGet(this, _ZodEnum_cache)) {
3799
- __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values));
3400
+ if (!this._cache) {
3401
+ this._cache = new Set(this._def.values);
3800
3402
  }
3801
- if (!__classPrivateFieldGet(this, _ZodEnum_cache).has(input.data)) {
3403
+ if (!this._cache.has(input.data)) {
3802
3404
  const ctx = this._getOrReturnCtx(input);
3803
3405
  const expectedValues = this._def.values;
3804
3406
  addIssueToContext(ctx, {
@@ -3847,18 +3449,12 @@ class ZodEnum extends ZodType {
3847
3449
  });
3848
3450
  }
3849
3451
  }
3850
- _ZodEnum_cache = new WeakMap();
3851
3452
  ZodEnum.create = createZodEnum;
3852
3453
  class ZodNativeEnum extends ZodType {
3853
- constructor() {
3854
- super(...arguments);
3855
- _ZodNativeEnum_cache.set(this, void 0);
3856
- }
3857
3454
  _parse(input) {
3858
3455
  const nativeEnumValues = util.getValidEnumValues(this._def.values);
3859
3456
  const ctx = this._getOrReturnCtx(input);
3860
- if (ctx.parsedType !== ZodParsedType.string &&
3861
- ctx.parsedType !== ZodParsedType.number) {
3457
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3862
3458
  const expectedValues = util.objectValues(nativeEnumValues);
3863
3459
  addIssueToContext(ctx, {
3864
3460
  expected: util.joinValues(expectedValues),
@@ -3867,10 +3463,10 @@ class ZodNativeEnum extends ZodType {
3867
3463
  });
3868
3464
  return INVALID;
3869
3465
  }
3870
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache)) {
3871
- __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)));
3466
+ if (!this._cache) {
3467
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
3872
3468
  }
3873
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache).has(input.data)) {
3469
+ if (!this._cache.has(input.data)) {
3874
3470
  const expectedValues = util.objectValues(nativeEnumValues);
3875
3471
  addIssueToContext(ctx, {
3876
3472
  received: ctx.data,
@@ -3885,7 +3481,6 @@ class ZodNativeEnum extends ZodType {
3885
3481
  return this._def.values;
3886
3482
  }
3887
3483
  }
3888
- _ZodNativeEnum_cache = new WeakMap();
3889
3484
  ZodNativeEnum.create = (values, params) => {
3890
3485
  return new ZodNativeEnum({
3891
3486
  values: values,
@@ -3899,8 +3494,7 @@ class ZodPromise extends ZodType {
3899
3494
  }
3900
3495
  _parse(input) {
3901
3496
  const { ctx } = this._processInputParams(input);
3902
- if (ctx.parsedType !== ZodParsedType.promise &&
3903
- ctx.common.async === false) {
3497
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3904
3498
  addIssueToContext(ctx, {
3905
3499
  code: ZodIssueCode.invalid_type,
3906
3500
  expected: ZodParsedType.promise,
@@ -3908,9 +3502,7 @@ class ZodPromise extends ZodType {
3908
3502
  });
3909
3503
  return INVALID;
3910
3504
  }
3911
- const promisified = ctx.parsedType === ZodParsedType.promise
3912
- ? ctx.data
3913
- : Promise.resolve(ctx.data);
3505
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3914
3506
  return OK(promisified.then((data) => {
3915
3507
  return this._def.type.parseAsync(data, {
3916
3508
  path: ctx.path,
@@ -4016,9 +3608,7 @@ class ZodEffects extends ZodType {
4016
3608
  return { status: status.value, value: inner.value };
4017
3609
  }
4018
3610
  else {
4019
- return this._def.schema
4020
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
4021
- .then((inner) => {
3611
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
4022
3612
  if (inner.status === "aborted")
4023
3613
  return INVALID;
4024
3614
  if (inner.status === "dirty")
@@ -4037,7 +3627,7 @@ class ZodEffects extends ZodType {
4037
3627
  parent: ctx,
4038
3628
  });
4039
3629
  if (!isValid(base))
4040
- return base;
3630
+ return INVALID;
4041
3631
  const result = effect.transform(base.value, checkCtx);
4042
3632
  if (result instanceof Promise) {
4043
3633
  throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
@@ -4045,12 +3635,13 @@ class ZodEffects extends ZodType {
4045
3635
  return { status: status.value, value: result };
4046
3636
  }
4047
3637
  else {
4048
- return this._def.schema
4049
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
4050
- .then((base) => {
3638
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
4051
3639
  if (!isValid(base))
4052
- return base;
4053
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
3640
+ return INVALID;
3641
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
3642
+ status: status.value,
3643
+ value: result,
3644
+ }));
4054
3645
  });
4055
3646
  }
4056
3647
  }
@@ -4132,9 +3723,7 @@ ZodDefault.create = (type, params) => {
4132
3723
  return new ZodDefault({
4133
3724
  innerType: type,
4134
3725
  typeName: ZodFirstPartyTypeKind.ZodDefault,
4135
- defaultValue: typeof params.default === "function"
4136
- ? params.default
4137
- : () => params.default,
3726
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
4138
3727
  ...processCreateParams(params),
4139
3728
  });
4140
3729
  };
@@ -4218,7 +3807,6 @@ ZodNaN.create = (params) => {
4218
3807
  ...processCreateParams(params),
4219
3808
  });
4220
3809
  };
4221
- const BRAND = Symbol("zod_brand");
4222
3810
  class ZodBranded extends ZodType {
4223
3811
  _parse(input) {
4224
3812
  const { ctx } = this._processInputParams(input);
@@ -4300,9 +3888,7 @@ class ZodReadonly extends ZodType {
4300
3888
  }
4301
3889
  return data;
4302
3890
  };
4303
- return isAsync(result)
4304
- ? result.then((data) => freeze(data))
4305
- : freeze(result);
3891
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
4306
3892
  }
4307
3893
  unwrap() {
4308
3894
  return this._def.innerType;
@@ -4315,60 +3901,6 @@ ZodReadonly.create = (type, params) => {
4315
3901
  ...processCreateParams(params),
4316
3902
  });
4317
3903
  };
4318
- ////////////////////////////////////////
4319
- ////////////////////////////////////////
4320
- ////////// //////////
4321
- ////////// z.custom //////////
4322
- ////////// //////////
4323
- ////////////////////////////////////////
4324
- ////////////////////////////////////////
4325
- function cleanParams(params, data) {
4326
- const p = typeof params === "function"
4327
- ? params(data)
4328
- : typeof params === "string"
4329
- ? { message: params }
4330
- : params;
4331
- const p2 = typeof p === "string" ? { message: p } : p;
4332
- return p2;
4333
- }
4334
- function custom(check, _params = {},
4335
- /**
4336
- * @deprecated
4337
- *
4338
- * Pass `fatal` into the params object instead:
4339
- *
4340
- * ```ts
4341
- * z.string().custom((val) => val.length > 5, { fatal: false })
4342
- * ```
4343
- *
4344
- */
4345
- fatal) {
4346
- if (check)
4347
- return ZodAny.create().superRefine((data, ctx) => {
4348
- var _a, _b;
4349
- const r = check(data);
4350
- if (r instanceof Promise) {
4351
- return r.then((r) => {
4352
- var _a, _b;
4353
- if (!r) {
4354
- const params = cleanParams(_params, data);
4355
- const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
4356
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
4357
- }
4358
- });
4359
- }
4360
- if (!r) {
4361
- const params = cleanParams(_params, data);
4362
- const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
4363
- ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
4364
- }
4365
- return;
4366
- });
4367
- return ZodAny.create();
4368
- }
4369
- const late = {
4370
- object: ZodObject.lazycreate,
4371
- };
4372
3904
  var ZodFirstPartyTypeKind;
4373
3905
  (function (ZodFirstPartyTypeKind) {
4374
3906
  ZodFirstPartyTypeKind["ZodString"] = "ZodString";
@@ -4408,48 +3940,20 @@ var ZodFirstPartyTypeKind;
4408
3940
  ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
4409
3941
  ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
4410
3942
  })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4411
- const instanceOfType = (
4412
- // const instanceOfType = <T extends new (...args: any[]) => any>(
4413
- cls, params = {
4414
- message: `Input not instance of ${cls.name}`,
4415
- }) => custom((data) => data instanceof cls, params);
4416
- const stringType = ZodString.create;
4417
- const numberType = ZodNumber.create;
4418
- const nanType = ZodNaN.create;
4419
- const bigIntType = ZodBigInt.create;
4420
- const booleanType = ZodBoolean.create;
4421
- const dateType = ZodDate.create;
4422
- const symbolType = ZodSymbol.create;
4423
- const undefinedType = ZodUndefined.create;
4424
- const nullType = ZodNull.create;
4425
- const anyType = ZodAny.create;
4426
- const unknownType = ZodUnknown.create;
4427
- const neverType = ZodNever.create;
4428
- const voidType = ZodVoid.create;
4429
- const arrayType = ZodArray.create;
4430
- const objectType = ZodObject.create;
4431
- const strictObjectType = ZodObject.strictCreate;
4432
- const unionType = ZodUnion.create;
4433
- const discriminatedUnionType = ZodDiscriminatedUnion.create;
4434
- const intersectionType = ZodIntersection.create;
4435
- const tupleType = ZodTuple.create;
4436
- const recordType = ZodRecord.create;
4437
- const mapType = ZodMap.create;
4438
- const setType = ZodSet.create;
4439
- const functionType = ZodFunction.create;
4440
- const lazyType = ZodLazy.create;
4441
- const literalType = ZodLiteral.create;
3943
+ ZodString.create;
3944
+ ZodNumber.create;
3945
+ ZodBigInt.create;
3946
+ ZodBoolean.create;
3947
+ ZodDate.create;
3948
+ ZodNever.create;
3949
+ ZodArray.create;
3950
+ ZodUnion.create;
3951
+ ZodIntersection.create;
3952
+ ZodTuple.create;
4442
3953
  const enumType = ZodEnum.create;
4443
- const nativeEnumType = ZodNativeEnum.create;
4444
- const promiseType = ZodPromise.create;
4445
- const effectsType = ZodEffects.create;
4446
- const optionalType = ZodOptional.create;
4447
- const nullableType = ZodNullable.create;
4448
- const preprocessType = ZodEffects.createWithPreprocess;
4449
- const pipelineType = ZodPipeline.create;
4450
- const ostring = () => stringType().optional();
4451
- const onumber = () => numberType().optional();
4452
- const oboolean = () => booleanType().optional();
3954
+ ZodPromise.create;
3955
+ ZodOptional.create;
3956
+ ZodNullable.create;
4453
3957
  const coerce = {
4454
3958
  string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4455
3959
  number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
@@ -4460,122 +3964,10 @@ const coerce = {
4460
3964
  bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4461
3965
  date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
4462
3966
  };
4463
- const NEVER = INVALID;
4464
-
4465
- var z = /*#__PURE__*/Object.freeze({
4466
- __proto__: null,
4467
- defaultErrorMap: errorMap,
4468
- setErrorMap: setErrorMap,
4469
- getErrorMap: getErrorMap,
4470
- makeIssue: makeIssue,
4471
- EMPTY_PATH: EMPTY_PATH,
4472
- addIssueToContext: addIssueToContext,
4473
- ParseStatus: ParseStatus,
4474
- INVALID: INVALID,
4475
- DIRTY: DIRTY,
4476
- OK: OK,
4477
- isAborted: isAborted,
4478
- isDirty: isDirty,
4479
- isValid: isValid,
4480
- isAsync: isAsync,
4481
- get util () { return util; },
4482
- get objectUtil () { return objectUtil; },
4483
- ZodParsedType: ZodParsedType,
4484
- getParsedType: getParsedType,
4485
- ZodType: ZodType,
4486
- datetimeRegex: datetimeRegex,
4487
- ZodString: ZodString,
4488
- ZodNumber: ZodNumber,
4489
- ZodBigInt: ZodBigInt,
4490
- ZodBoolean: ZodBoolean,
4491
- ZodDate: ZodDate,
4492
- ZodSymbol: ZodSymbol,
4493
- ZodUndefined: ZodUndefined,
4494
- ZodNull: ZodNull,
4495
- ZodAny: ZodAny,
4496
- ZodUnknown: ZodUnknown,
4497
- ZodNever: ZodNever,
4498
- ZodVoid: ZodVoid,
4499
- ZodArray: ZodArray,
4500
- ZodObject: ZodObject,
4501
- ZodUnion: ZodUnion,
4502
- ZodDiscriminatedUnion: ZodDiscriminatedUnion,
4503
- ZodIntersection: ZodIntersection,
4504
- ZodTuple: ZodTuple,
4505
- ZodRecord: ZodRecord,
4506
- ZodMap: ZodMap,
4507
- ZodSet: ZodSet,
4508
- ZodFunction: ZodFunction,
4509
- ZodLazy: ZodLazy,
4510
- ZodLiteral: ZodLiteral,
4511
- ZodEnum: ZodEnum,
4512
- ZodNativeEnum: ZodNativeEnum,
4513
- ZodPromise: ZodPromise,
4514
- ZodEffects: ZodEffects,
4515
- ZodTransformer: ZodEffects,
4516
- ZodOptional: ZodOptional,
4517
- ZodNullable: ZodNullable,
4518
- ZodDefault: ZodDefault,
4519
- ZodCatch: ZodCatch,
4520
- ZodNaN: ZodNaN,
4521
- BRAND: BRAND,
4522
- ZodBranded: ZodBranded,
4523
- ZodPipeline: ZodPipeline,
4524
- ZodReadonly: ZodReadonly,
4525
- custom: custom,
4526
- Schema: ZodType,
4527
- ZodSchema: ZodType,
4528
- late: late,
4529
- get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
4530
- coerce: coerce,
4531
- any: anyType,
4532
- array: arrayType,
4533
- bigint: bigIntType,
4534
- boolean: booleanType,
4535
- date: dateType,
4536
- discriminatedUnion: discriminatedUnionType,
4537
- effect: effectsType,
4538
- 'enum': enumType,
4539
- 'function': functionType,
4540
- 'instanceof': instanceOfType,
4541
- intersection: intersectionType,
4542
- lazy: lazyType,
4543
- literal: literalType,
4544
- map: mapType,
4545
- nan: nanType,
4546
- nativeEnum: nativeEnumType,
4547
- never: neverType,
4548
- 'null': nullType,
4549
- nullable: nullableType,
4550
- number: numberType,
4551
- object: objectType,
4552
- oboolean: oboolean,
4553
- onumber: onumber,
4554
- optional: optionalType,
4555
- ostring: ostring,
4556
- pipeline: pipelineType,
4557
- preprocess: preprocessType,
4558
- promise: promiseType,
4559
- record: recordType,
4560
- set: setType,
4561
- strictObject: strictObjectType,
4562
- string: stringType,
4563
- symbol: symbolType,
4564
- transformer: effectsType,
4565
- tuple: tupleType,
4566
- 'undefined': undefinedType,
4567
- union: unionType,
4568
- unknown: unknownType,
4569
- 'void': voidType,
4570
- NEVER: NEVER,
4571
- ZodIssueCode: ZodIssueCode,
4572
- quotelessJson: quotelessJson,
4573
- ZodError: ZodError
4574
- });
4575
3967
 
4576
3968
  const ageGate = (ageGateType, ageGateValue, legalAge = null) => {
4577
- const ageGateTypeValidation = z.enum([ 'yesno', 'dob' ]);
4578
- const ageDateValidation = z.coerce.date();
3969
+ const ageGateTypeValidation = enumType([ 'yesno', 'dob' ]);
3970
+ const ageDateValidation = coerce.date();
4579
3971
  legalAge = legalAge || 21;
4580
3972
 
4581
3973
  let _type = null;