@lodashventure/medusa-campaign 0.0.6 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1255,7 +1255,8 @@ const config$1 = defineRouteConfig({
1255
1255
  });
1256
1256
  var util;
1257
1257
  (function(util2) {
1258
- util2.assertEqual = (val) => val;
1258
+ util2.assertEqual = (_) => {
1259
+ };
1259
1260
  function assertIs(_arg) {
1260
1261
  }
1261
1262
  util2.assertIs = assertIs;
@@ -1299,7 +1300,7 @@ var util;
1299
1300
  }
1300
1301
  return void 0;
1301
1302
  };
1302
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
1303
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
1303
1304
  function joinValues(array, separator = " | ") {
1304
1305
  return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
1305
1306
  }
@@ -1351,7 +1352,7 @@ const getParsedType = (data) => {
1351
1352
  case "string":
1352
1353
  return ZodParsedType.string;
1353
1354
  case "number":
1354
- return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
1355
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
1355
1356
  case "boolean":
1356
1357
  return ZodParsedType.boolean;
1357
1358
  case "function":
@@ -1407,6 +1408,9 @@ const quotelessJson = (obj) => {
1407
1408
  return json.replace(/"([^"]+)":/g, "$1:");
1408
1409
  };
1409
1410
  class ZodError extends Error {
1411
+ get errors() {
1412
+ return this.issues;
1413
+ }
1410
1414
  constructor(issues) {
1411
1415
  super();
1412
1416
  this.issues = [];
@@ -1425,9 +1429,6 @@ class ZodError extends Error {
1425
1429
  this.name = "ZodError";
1426
1430
  this.issues = issues;
1427
1431
  }
1428
- get errors() {
1429
- return this.issues;
1430
- }
1431
1432
  format(_mapper) {
1432
1433
  const mapper = _mapper || function(issue) {
1433
1434
  return issue.message;
@@ -1464,6 +1465,11 @@ class ZodError extends Error {
1464
1465
  processError(this);
1465
1466
  return fieldErrors;
1466
1467
  }
1468
+ static assert(value) {
1469
+ if (!(value instanceof ZodError)) {
1470
+ throw new Error(`Not a ZodError: ${value}`);
1471
+ }
1472
+ }
1467
1473
  toString() {
1468
1474
  return this.message;
1469
1475
  }
@@ -1478,8 +1484,9 @@ class ZodError extends Error {
1478
1484
  const formErrors = [];
1479
1485
  for (const sub of this.issues) {
1480
1486
  if (sub.path.length > 0) {
1481
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
1482
- fieldErrors[sub.path[0]].push(mapper(sub));
1487
+ const firstEl = sub.path[0];
1488
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
1489
+ fieldErrors[firstEl].push(mapper(sub));
1483
1490
  } else {
1484
1491
  formErrors.push(mapper(sub));
1485
1492
  }
@@ -1555,6 +1562,8 @@ const errorMap = (issue, _ctx) => {
1555
1562
  message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
1556
1563
  else if (issue.type === "number")
1557
1564
  message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
1565
+ else if (issue.type === "bigint")
1566
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
1558
1567
  else if (issue.type === "date")
1559
1568
  message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
1560
1569
  else
@@ -1606,6 +1615,13 @@ const makeIssue = (params) => {
1606
1615
  ...issueData,
1607
1616
  path: fullPath
1608
1617
  };
1618
+ if (issueData.message !== void 0) {
1619
+ return {
1620
+ ...issueData,
1621
+ path: fullPath,
1622
+ message: issueData.message
1623
+ };
1624
+ }
1609
1625
  let errorMessage = "";
1610
1626
  const maps = errorMaps.filter((m) => !!m).slice().reverse();
1611
1627
  for (const map of maps) {
@@ -1614,20 +1630,24 @@ const makeIssue = (params) => {
1614
1630
  return {
1615
1631
  ...issueData,
1616
1632
  path: fullPath,
1617
- message: issueData.message || errorMessage
1633
+ message: errorMessage
1618
1634
  };
1619
1635
  };
1620
1636
  const EMPTY_PATH = [];
1621
1637
  function addIssueToContext(ctx, issueData) {
1638
+ const overrideMap = getErrorMap();
1622
1639
  const issue = makeIssue({
1623
1640
  issueData,
1624
1641
  data: ctx.data,
1625
1642
  path: ctx.path,
1626
1643
  errorMaps: [
1627
1644
  ctx.common.contextualErrorMap,
1645
+ // contextual error map is first priority
1628
1646
  ctx.schemaErrorMap,
1629
- getErrorMap(),
1630
- errorMap
1647
+ // then schema-bound map if available
1648
+ overrideMap,
1649
+ // then global override map
1650
+ overrideMap === errorMap ? void 0 : errorMap
1631
1651
  // then global default map
1632
1652
  ].filter((x) => !!x)
1633
1653
  });
@@ -1659,9 +1679,11 @@ class ParseStatus {
1659
1679
  static async mergeObjectAsync(status, pairs) {
1660
1680
  const syncPairs = [];
1661
1681
  for (const pair of pairs) {
1682
+ const key = await pair.key;
1683
+ const value = await pair.value;
1662
1684
  syncPairs.push({
1663
- key: await pair.key,
1664
- value: await pair.value
1685
+ key,
1686
+ value
1665
1687
  });
1666
1688
  }
1667
1689
  return ParseStatus.mergeObjectSync(status, syncPairs);
@@ -1697,7 +1719,7 @@ const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
1697
1719
  var errorUtil;
1698
1720
  (function(errorUtil2) {
1699
1721
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
1700
- errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
1722
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message == null ? void 0 : message.message;
1701
1723
  })(errorUtil || (errorUtil = {}));
1702
1724
  class ParseInputLazyPath {
1703
1725
  constructor(parent, value, path, key) {
@@ -1709,7 +1731,7 @@ class ParseInputLazyPath {
1709
1731
  }
1710
1732
  get path() {
1711
1733
  if (!this._cachedPath.length) {
1712
- if (this._key instanceof Array) {
1734
+ if (Array.isArray(this._key)) {
1713
1735
  this._cachedPath.push(...this._path, ...this._key);
1714
1736
  } else {
1715
1737
  this._cachedPath.push(...this._path, this._key);
@@ -1747,44 +1769,20 @@ function processCreateParams(params) {
1747
1769
  if (errorMap2)
1748
1770
  return { errorMap: errorMap2, description };
1749
1771
  const customMap = (iss, ctx) => {
1750
- if (iss.code !== "invalid_type")
1751
- return { message: ctx.defaultError };
1772
+ const { message } = params;
1773
+ if (iss.code === "invalid_enum_value") {
1774
+ return { message: message ?? ctx.defaultError };
1775
+ }
1752
1776
  if (typeof ctx.data === "undefined") {
1753
- return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
1777
+ return { message: message ?? required_error ?? ctx.defaultError };
1754
1778
  }
1755
- return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
1779
+ if (iss.code !== "invalid_type")
1780
+ return { message: ctx.defaultError };
1781
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
1756
1782
  };
1757
1783
  return { errorMap: customMap, description };
1758
1784
  }
1759
1785
  class ZodType {
1760
- constructor(def) {
1761
- this.spa = this.safeParseAsync;
1762
- this._def = def;
1763
- this.parse = this.parse.bind(this);
1764
- this.safeParse = this.safeParse.bind(this);
1765
- this.parseAsync = this.parseAsync.bind(this);
1766
- this.safeParseAsync = this.safeParseAsync.bind(this);
1767
- this.spa = this.spa.bind(this);
1768
- this.refine = this.refine.bind(this);
1769
- this.refinement = this.refinement.bind(this);
1770
- this.superRefine = this.superRefine.bind(this);
1771
- this.optional = this.optional.bind(this);
1772
- this.nullable = this.nullable.bind(this);
1773
- this.nullish = this.nullish.bind(this);
1774
- this.array = this.array.bind(this);
1775
- this.promise = this.promise.bind(this);
1776
- this.or = this.or.bind(this);
1777
- this.and = this.and.bind(this);
1778
- this.transform = this.transform.bind(this);
1779
- this.brand = this.brand.bind(this);
1780
- this.default = this.default.bind(this);
1781
- this.catch = this.catch.bind(this);
1782
- this.describe = this.describe.bind(this);
1783
- this.pipe = this.pipe.bind(this);
1784
- this.readonly = this.readonly.bind(this);
1785
- this.isNullable = this.isNullable.bind(this);
1786
- this.isOptional = this.isOptional.bind(this);
1787
- }
1788
1786
  get description() {
1789
1787
  return this._def.description;
1790
1788
  }
@@ -1832,14 +1830,13 @@ class ZodType {
1832
1830
  throw result.error;
1833
1831
  }
1834
1832
  safeParse(data, params) {
1835
- var _a;
1836
1833
  const ctx = {
1837
1834
  common: {
1838
1835
  issues: [],
1839
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
1840
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
1836
+ async: (params == null ? void 0 : params.async) ?? false,
1837
+ contextualErrorMap: params == null ? void 0 : params.errorMap
1841
1838
  },
1842
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
1839
+ path: (params == null ? void 0 : params.path) || [],
1843
1840
  schemaErrorMap: this._def.errorMap,
1844
1841
  parent: null,
1845
1842
  data,
@@ -1848,6 +1845,43 @@ class ZodType {
1848
1845
  const result = this._parseSync({ data, path: ctx.path, parent: ctx });
1849
1846
  return handleResult(ctx, result);
1850
1847
  }
1848
+ "~validate"(data) {
1849
+ var _a, _b;
1850
+ const ctx = {
1851
+ common: {
1852
+ issues: [],
1853
+ async: !!this["~standard"].async
1854
+ },
1855
+ path: [],
1856
+ schemaErrorMap: this._def.errorMap,
1857
+ parent: null,
1858
+ data,
1859
+ parsedType: getParsedType(data)
1860
+ };
1861
+ if (!this["~standard"].async) {
1862
+ try {
1863
+ const result = this._parseSync({ data, path: [], parent: ctx });
1864
+ return isValid(result) ? {
1865
+ value: result.value
1866
+ } : {
1867
+ issues: ctx.common.issues
1868
+ };
1869
+ } catch (err) {
1870
+ if ((_b = (_a = err == null ? void 0 : err.message) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("encountered")) {
1871
+ this["~standard"].async = true;
1872
+ }
1873
+ ctx.common = {
1874
+ issues: [],
1875
+ async: true
1876
+ };
1877
+ }
1878
+ }
1879
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
1880
+ value: result.value
1881
+ } : {
1882
+ issues: ctx.common.issues
1883
+ });
1884
+ }
1851
1885
  async parseAsync(data, params) {
1852
1886
  const result = await this.safeParseAsync(data, params);
1853
1887
  if (result.success)
@@ -1858,10 +1892,10 @@ class ZodType {
1858
1892
  const ctx = {
1859
1893
  common: {
1860
1894
  issues: [],
1861
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
1895
+ contextualErrorMap: params == null ? void 0 : params.errorMap,
1862
1896
  async: true
1863
1897
  },
1864
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
1898
+ path: (params == null ? void 0 : params.path) || [],
1865
1899
  schemaErrorMap: this._def.errorMap,
1866
1900
  parent: null,
1867
1901
  data,
@@ -1925,6 +1959,39 @@ class ZodType {
1925
1959
  superRefine(refinement) {
1926
1960
  return this._refinement(refinement);
1927
1961
  }
1962
+ constructor(def) {
1963
+ this.spa = this.safeParseAsync;
1964
+ this._def = def;
1965
+ this.parse = this.parse.bind(this);
1966
+ this.safeParse = this.safeParse.bind(this);
1967
+ this.parseAsync = this.parseAsync.bind(this);
1968
+ this.safeParseAsync = this.safeParseAsync.bind(this);
1969
+ this.spa = this.spa.bind(this);
1970
+ this.refine = this.refine.bind(this);
1971
+ this.refinement = this.refinement.bind(this);
1972
+ this.superRefine = this.superRefine.bind(this);
1973
+ this.optional = this.optional.bind(this);
1974
+ this.nullable = this.nullable.bind(this);
1975
+ this.nullish = this.nullish.bind(this);
1976
+ this.array = this.array.bind(this);
1977
+ this.promise = this.promise.bind(this);
1978
+ this.or = this.or.bind(this);
1979
+ this.and = this.and.bind(this);
1980
+ this.transform = this.transform.bind(this);
1981
+ this.brand = this.brand.bind(this);
1982
+ this.default = this.default.bind(this);
1983
+ this.catch = this.catch.bind(this);
1984
+ this.describe = this.describe.bind(this);
1985
+ this.pipe = this.pipe.bind(this);
1986
+ this.readonly = this.readonly.bind(this);
1987
+ this.isNullable = this.isNullable.bind(this);
1988
+ this.isOptional = this.isOptional.bind(this);
1989
+ this["~standard"] = {
1990
+ version: 1,
1991
+ vendor: "zod",
1992
+ validate: (data) => this["~validate"](data)
1993
+ };
1994
+ }
1928
1995
  optional() {
1929
1996
  return ZodOptional.create(this, this._def);
1930
1997
  }
@@ -1935,7 +2002,7 @@ class ZodType {
1935
2002
  return this.nullable().optional();
1936
2003
  }
1937
2004
  array() {
1938
- return ZodArray.create(this, this._def);
2005
+ return ZodArray.create(this);
1939
2006
  }
1940
2007
  promise() {
1941
2008
  return ZodPromise.create(this, this._def);
@@ -2000,35 +2067,45 @@ class ZodType {
2000
2067
  }
2001
2068
  }
2002
2069
  const cuidRegex = /^c[^\s-]{8,}$/i;
2003
- const cuid2Regex = /^[a-z][a-z0-9]*$/;
2004
- const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
2070
+ const cuid2Regex = /^[0-9a-z]+$/;
2071
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
2005
2072
  const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
2006
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
2073
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
2074
+ const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
2075
+ const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
2076
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
2007
2077
  const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
2008
2078
  let emojiRegex;
2009
- const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
2010
- const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
2011
- const datetimeRegex = (args) => {
2079
+ const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
2080
+ const ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
2081
+ const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
2082
+ const ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
2083
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
2084
+ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
2085
+ 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])))`;
2086
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
2087
+ function timeRegexSource(args) {
2088
+ let secondsRegexSource = `[0-5]\\d`;
2012
2089
  if (args.precision) {
2013
- if (args.offset) {
2014
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
2015
- } else {
2016
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
2017
- }
2018
- } else if (args.precision === 0) {
2019
- if (args.offset) {
2020
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
2021
- } else {
2022
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
2023
- }
2024
- } else {
2025
- if (args.offset) {
2026
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
2027
- } else {
2028
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
2029
- }
2090
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
2091
+ } else if (args.precision == null) {
2092
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
2030
2093
  }
2031
- };
2094
+ const secondsQuantifier = args.precision ? "+" : "?";
2095
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
2096
+ }
2097
+ function timeRegex(args) {
2098
+ return new RegExp(`^${timeRegexSource(args)}$`);
2099
+ }
2100
+ function datetimeRegex(args) {
2101
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
2102
+ const opts = [];
2103
+ opts.push(args.local ? `Z?` : `Z`);
2104
+ if (args.offset)
2105
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
2106
+ regex = `${regex}(${opts.join("|")})`;
2107
+ return new RegExp(`^${regex}$`);
2108
+ }
2032
2109
  function isValidIP(ip, version2) {
2033
2110
  if ((version2 === "v4" || !version2) && ipv4Regex.test(ip)) {
2034
2111
  return true;
@@ -2038,6 +2115,37 @@ function isValidIP(ip, version2) {
2038
2115
  }
2039
2116
  return false;
2040
2117
  }
2118
+ function isValidJWT(jwt, alg) {
2119
+ if (!jwtRegex.test(jwt))
2120
+ return false;
2121
+ try {
2122
+ const [header] = jwt.split(".");
2123
+ if (!header)
2124
+ return false;
2125
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
2126
+ const decoded = JSON.parse(atob(base64));
2127
+ if (typeof decoded !== "object" || decoded === null)
2128
+ return false;
2129
+ if ("typ" in decoded && (decoded == null ? void 0 : decoded.typ) !== "JWT")
2130
+ return false;
2131
+ if (!decoded.alg)
2132
+ return false;
2133
+ if (alg && decoded.alg !== alg)
2134
+ return false;
2135
+ return true;
2136
+ } catch {
2137
+ return false;
2138
+ }
2139
+ }
2140
+ function isValidCidr(ip, version2) {
2141
+ if ((version2 === "v4" || !version2) && ipv4CidrRegex.test(ip)) {
2142
+ return true;
2143
+ }
2144
+ if ((version2 === "v6" || !version2) && ipv6CidrRegex.test(ip)) {
2145
+ return true;
2146
+ }
2147
+ return false;
2148
+ }
2041
2149
  class ZodString extends ZodType {
2042
2150
  _parse(input) {
2043
2151
  if (this._def.coerce) {
@@ -2046,15 +2154,11 @@ class ZodString extends ZodType {
2046
2154
  const parsedType = this._getType(input);
2047
2155
  if (parsedType !== ZodParsedType.string) {
2048
2156
  const ctx2 = this._getOrReturnCtx(input);
2049
- addIssueToContext(
2050
- ctx2,
2051
- {
2052
- code: ZodIssueCode.invalid_type,
2053
- expected: ZodParsedType.string,
2054
- received: ctx2.parsedType
2055
- }
2056
- //
2057
- );
2157
+ addIssueToContext(ctx2, {
2158
+ code: ZodIssueCode.invalid_type,
2159
+ expected: ZodParsedType.string,
2160
+ received: ctx2.parsedType
2161
+ });
2058
2162
  return INVALID;
2059
2163
  }
2060
2164
  const status = new ParseStatus();
@@ -2145,6 +2249,16 @@ class ZodString extends ZodType {
2145
2249
  });
2146
2250
  status.dirty();
2147
2251
  }
2252
+ } else if (check.kind === "nanoid") {
2253
+ if (!nanoidRegex.test(input.data)) {
2254
+ ctx = this._getOrReturnCtx(input, ctx);
2255
+ addIssueToContext(ctx, {
2256
+ validation: "nanoid",
2257
+ code: ZodIssueCode.invalid_string,
2258
+ message: check.message
2259
+ });
2260
+ status.dirty();
2261
+ }
2148
2262
  } else if (check.kind === "cuid") {
2149
2263
  if (!cuidRegex.test(input.data)) {
2150
2264
  ctx = this._getOrReturnCtx(input, ctx);
@@ -2178,7 +2292,7 @@ class ZodString extends ZodType {
2178
2292
  } else if (check.kind === "url") {
2179
2293
  try {
2180
2294
  new URL(input.data);
2181
- } catch (_a) {
2295
+ } catch {
2182
2296
  ctx = this._getOrReturnCtx(input, ctx);
2183
2297
  addIssueToContext(ctx, {
2184
2298
  validation: "url",
@@ -2246,6 +2360,38 @@ class ZodString extends ZodType {
2246
2360
  });
2247
2361
  status.dirty();
2248
2362
  }
2363
+ } else if (check.kind === "date") {
2364
+ const regex = dateRegex;
2365
+ if (!regex.test(input.data)) {
2366
+ ctx = this._getOrReturnCtx(input, ctx);
2367
+ addIssueToContext(ctx, {
2368
+ code: ZodIssueCode.invalid_string,
2369
+ validation: "date",
2370
+ message: check.message
2371
+ });
2372
+ status.dirty();
2373
+ }
2374
+ } else if (check.kind === "time") {
2375
+ const regex = timeRegex(check);
2376
+ if (!regex.test(input.data)) {
2377
+ ctx = this._getOrReturnCtx(input, ctx);
2378
+ addIssueToContext(ctx, {
2379
+ code: ZodIssueCode.invalid_string,
2380
+ validation: "time",
2381
+ message: check.message
2382
+ });
2383
+ status.dirty();
2384
+ }
2385
+ } else if (check.kind === "duration") {
2386
+ if (!durationRegex.test(input.data)) {
2387
+ ctx = this._getOrReturnCtx(input, ctx);
2388
+ addIssueToContext(ctx, {
2389
+ validation: "duration",
2390
+ code: ZodIssueCode.invalid_string,
2391
+ message: check.message
2392
+ });
2393
+ status.dirty();
2394
+ }
2249
2395
  } else if (check.kind === "ip") {
2250
2396
  if (!isValidIP(input.data, check.version)) {
2251
2397
  ctx = this._getOrReturnCtx(input, ctx);
@@ -2256,6 +2402,46 @@ class ZodString extends ZodType {
2256
2402
  });
2257
2403
  status.dirty();
2258
2404
  }
2405
+ } else if (check.kind === "jwt") {
2406
+ if (!isValidJWT(input.data, check.alg)) {
2407
+ ctx = this._getOrReturnCtx(input, ctx);
2408
+ addIssueToContext(ctx, {
2409
+ validation: "jwt",
2410
+ code: ZodIssueCode.invalid_string,
2411
+ message: check.message
2412
+ });
2413
+ status.dirty();
2414
+ }
2415
+ } else if (check.kind === "cidr") {
2416
+ if (!isValidCidr(input.data, check.version)) {
2417
+ ctx = this._getOrReturnCtx(input, ctx);
2418
+ addIssueToContext(ctx, {
2419
+ validation: "cidr",
2420
+ code: ZodIssueCode.invalid_string,
2421
+ message: check.message
2422
+ });
2423
+ status.dirty();
2424
+ }
2425
+ } else if (check.kind === "base64") {
2426
+ if (!base64Regex.test(input.data)) {
2427
+ ctx = this._getOrReturnCtx(input, ctx);
2428
+ addIssueToContext(ctx, {
2429
+ validation: "base64",
2430
+ code: ZodIssueCode.invalid_string,
2431
+ message: check.message
2432
+ });
2433
+ status.dirty();
2434
+ }
2435
+ } else if (check.kind === "base64url") {
2436
+ if (!base64urlRegex.test(input.data)) {
2437
+ ctx = this._getOrReturnCtx(input, ctx);
2438
+ addIssueToContext(ctx, {
2439
+ validation: "base64url",
2440
+ code: ZodIssueCode.invalid_string,
2441
+ message: check.message
2442
+ });
2443
+ status.dirty();
2444
+ }
2259
2445
  } else {
2260
2446
  util.assertNever(check);
2261
2447
  }
@@ -2287,6 +2473,9 @@ class ZodString extends ZodType {
2287
2473
  uuid(message) {
2288
2474
  return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
2289
2475
  }
2476
+ nanoid(message) {
2477
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
2478
+ }
2290
2479
  cuid(message) {
2291
2480
  return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
2292
2481
  }
@@ -2296,26 +2485,62 @@ class ZodString extends ZodType {
2296
2485
  ulid(message) {
2297
2486
  return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
2298
2487
  }
2488
+ base64(message) {
2489
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
2490
+ }
2491
+ base64url(message) {
2492
+ return this._addCheck({
2493
+ kind: "base64url",
2494
+ ...errorUtil.errToObj(message)
2495
+ });
2496
+ }
2497
+ jwt(options) {
2498
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
2499
+ }
2299
2500
  ip(options) {
2300
2501
  return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
2301
2502
  }
2503
+ cidr(options) {
2504
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
2505
+ }
2302
2506
  datetime(options) {
2303
- var _a;
2304
2507
  if (typeof options === "string") {
2305
2508
  return this._addCheck({
2306
2509
  kind: "datetime",
2307
2510
  precision: null,
2308
2511
  offset: false,
2512
+ local: false,
2309
2513
  message: options
2310
2514
  });
2311
2515
  }
2312
2516
  return this._addCheck({
2313
2517
  kind: "datetime",
2314
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
2315
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
2316
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
2518
+ precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
2519
+ offset: (options == null ? void 0 : options.offset) ?? false,
2520
+ local: (options == null ? void 0 : options.local) ?? false,
2521
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
2317
2522
  });
2318
2523
  }
2524
+ date(message) {
2525
+ return this._addCheck({ kind: "date", message });
2526
+ }
2527
+ time(options) {
2528
+ if (typeof options === "string") {
2529
+ return this._addCheck({
2530
+ kind: "time",
2531
+ precision: null,
2532
+ message: options
2533
+ });
2534
+ }
2535
+ return this._addCheck({
2536
+ kind: "time",
2537
+ precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
2538
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
2539
+ });
2540
+ }
2541
+ duration(message) {
2542
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
2543
+ }
2319
2544
  regex(regex, message) {
2320
2545
  return this._addCheck({
2321
2546
  kind: "regex",
@@ -2327,8 +2552,8 @@ class ZodString extends ZodType {
2327
2552
  return this._addCheck({
2328
2553
  kind: "includes",
2329
2554
  value,
2330
- position: options === null || options === void 0 ? void 0 : options.position,
2331
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
2555
+ position: options == null ? void 0 : options.position,
2556
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
2332
2557
  });
2333
2558
  }
2334
2559
  startsWith(value, message) {
@@ -2367,8 +2592,7 @@ class ZodString extends ZodType {
2367
2592
  });
2368
2593
  }
2369
2594
  /**
2370
- * @deprecated Use z.string().min(1) instead.
2371
- * @see {@link ZodString.min}
2595
+ * Equivalent to `.min(1)`
2372
2596
  */
2373
2597
  nonempty(message) {
2374
2598
  return this.min(1, errorUtil.errToObj(message));
@@ -2394,6 +2618,15 @@ class ZodString extends ZodType {
2394
2618
  get isDatetime() {
2395
2619
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
2396
2620
  }
2621
+ get isDate() {
2622
+ return !!this._def.checks.find((ch) => ch.kind === "date");
2623
+ }
2624
+ get isTime() {
2625
+ return !!this._def.checks.find((ch) => ch.kind === "time");
2626
+ }
2627
+ get isDuration() {
2628
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
2629
+ }
2397
2630
  get isEmail() {
2398
2631
  return !!this._def.checks.find((ch) => ch.kind === "email");
2399
2632
  }
@@ -2406,6 +2639,9 @@ class ZodString extends ZodType {
2406
2639
  get isUUID() {
2407
2640
  return !!this._def.checks.find((ch) => ch.kind === "uuid");
2408
2641
  }
2642
+ get isNANOID() {
2643
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
2644
+ }
2409
2645
  get isCUID() {
2410
2646
  return !!this._def.checks.find((ch) => ch.kind === "cuid");
2411
2647
  }
@@ -2418,6 +2654,15 @@ class ZodString extends ZodType {
2418
2654
  get isIP() {
2419
2655
  return !!this._def.checks.find((ch) => ch.kind === "ip");
2420
2656
  }
2657
+ get isCIDR() {
2658
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
2659
+ }
2660
+ get isBase64() {
2661
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
2662
+ }
2663
+ get isBase64url() {
2664
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
2665
+ }
2421
2666
  get minLength() {
2422
2667
  let min = null;
2423
2668
  for (const ch of this._def.checks) {
@@ -2440,11 +2685,10 @@ class ZodString extends ZodType {
2440
2685
  }
2441
2686
  }
2442
2687
  ZodString.create = (params) => {
2443
- var _a;
2444
2688
  return new ZodString({
2445
2689
  checks: [],
2446
2690
  typeName: ZodFirstPartyTypeKind.ZodString,
2447
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
2691
+ coerce: (params == null ? void 0 : params.coerce) ?? false,
2448
2692
  ...processCreateParams(params)
2449
2693
  });
2450
2694
  };
@@ -2452,9 +2696,9 @@ function floatSafeRemainder(val, step) {
2452
2696
  const valDecCount = (val.toString().split(".")[1] || "").length;
2453
2697
  const stepDecCount = (step.toString().split(".")[1] || "").length;
2454
2698
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
2455
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
2456
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
2457
- return valInt % stepInt / Math.pow(10, decCount);
2699
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
2700
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
2701
+ return valInt % stepInt / 10 ** decCount;
2458
2702
  }
2459
2703
  class ZodNumber extends ZodType {
2460
2704
  constructor() {
@@ -2664,7 +2908,8 @@ class ZodNumber extends ZodType {
2664
2908
  return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
2665
2909
  }
2666
2910
  get isFinite() {
2667
- let max = null, min = null;
2911
+ let max = null;
2912
+ let min = null;
2668
2913
  for (const ch of this._def.checks) {
2669
2914
  if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
2670
2915
  return true;
@@ -2683,7 +2928,7 @@ ZodNumber.create = (params) => {
2683
2928
  return new ZodNumber({
2684
2929
  checks: [],
2685
2930
  typeName: ZodFirstPartyTypeKind.ZodNumber,
2686
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2931
+ coerce: (params == null ? void 0 : params.coerce) || false,
2687
2932
  ...processCreateParams(params)
2688
2933
  });
2689
2934
  };
@@ -2695,17 +2940,15 @@ class ZodBigInt extends ZodType {
2695
2940
  }
2696
2941
  _parse(input) {
2697
2942
  if (this._def.coerce) {
2698
- input.data = BigInt(input.data);
2943
+ try {
2944
+ input.data = BigInt(input.data);
2945
+ } catch {
2946
+ return this._getInvalidInput(input);
2947
+ }
2699
2948
  }
2700
2949
  const parsedType = this._getType(input);
2701
2950
  if (parsedType !== ZodParsedType.bigint) {
2702
- const ctx2 = this._getOrReturnCtx(input);
2703
- addIssueToContext(ctx2, {
2704
- code: ZodIssueCode.invalid_type,
2705
- expected: ZodParsedType.bigint,
2706
- received: ctx2.parsedType
2707
- });
2708
- return INVALID;
2951
+ return this._getInvalidInput(input);
2709
2952
  }
2710
2953
  let ctx = void 0;
2711
2954
  const status = new ParseStatus();
@@ -2752,6 +2995,15 @@ class ZodBigInt extends ZodType {
2752
2995
  }
2753
2996
  return { status: status.value, value: input.data };
2754
2997
  }
2998
+ _getInvalidInput(input) {
2999
+ const ctx = this._getOrReturnCtx(input);
3000
+ addIssueToContext(ctx, {
3001
+ code: ZodIssueCode.invalid_type,
3002
+ expected: ZodParsedType.bigint,
3003
+ received: ctx.parsedType
3004
+ });
3005
+ return INVALID;
3006
+ }
2755
3007
  gte(value, message) {
2756
3008
  return this.setLimit("min", value, true, errorUtil.toString(message));
2757
3009
  }
@@ -2845,11 +3097,10 @@ class ZodBigInt extends ZodType {
2845
3097
  }
2846
3098
  }
2847
3099
  ZodBigInt.create = (params) => {
2848
- var _a;
2849
3100
  return new ZodBigInt({
2850
3101
  checks: [],
2851
3102
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
2852
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
3103
+ coerce: (params == null ? void 0 : params.coerce) ?? false,
2853
3104
  ...processCreateParams(params)
2854
3105
  });
2855
3106
  };
@@ -2874,7 +3125,7 @@ class ZodBoolean extends ZodType {
2874
3125
  ZodBoolean.create = (params) => {
2875
3126
  return new ZodBoolean({
2876
3127
  typeName: ZodFirstPartyTypeKind.ZodBoolean,
2877
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
3128
+ coerce: (params == null ? void 0 : params.coerce) || false,
2878
3129
  ...processCreateParams(params)
2879
3130
  });
2880
3131
  };
@@ -2893,7 +3144,7 @@ class ZodDate extends ZodType {
2893
3144
  });
2894
3145
  return INVALID;
2895
3146
  }
2896
- if (isNaN(input.data.getTime())) {
3147
+ if (Number.isNaN(input.data.getTime())) {
2897
3148
  const ctx2 = this._getOrReturnCtx(input);
2898
3149
  addIssueToContext(ctx2, {
2899
3150
  code: ZodIssueCode.invalid_date
@@ -2982,7 +3233,7 @@ class ZodDate extends ZodType {
2982
3233
  ZodDate.create = (params) => {
2983
3234
  return new ZodDate({
2984
3235
  checks: [],
2985
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
3236
+ coerce: (params == null ? void 0 : params.coerce) || false,
2986
3237
  typeName: ZodFirstPartyTypeKind.ZodDate,
2987
3238
  ...processCreateParams(params)
2988
3239
  });
@@ -3257,7 +3508,8 @@ class ZodObject extends ZodType {
3257
3508
  return this._cached;
3258
3509
  const shape = this._def.shape();
3259
3510
  const keys = util.objectKeys(shape);
3260
- return this._cached = { shape, keys };
3511
+ this._cached = { shape, keys };
3512
+ return this._cached;
3261
3513
  }
3262
3514
  _parse(input) {
3263
3515
  const parsedType = this._getType(input);
@@ -3330,9 +3582,10 @@ class ZodObject extends ZodType {
3330
3582
  const syncPairs = [];
3331
3583
  for (const pair of pairs) {
3332
3584
  const key = await pair.key;
3585
+ const value = await pair.value;
3333
3586
  syncPairs.push({
3334
3587
  key,
3335
- value: await pair.value,
3588
+ value,
3336
3589
  alwaysSet: pair.alwaysSet
3337
3590
  });
3338
3591
  }
@@ -3354,11 +3607,11 @@ class ZodObject extends ZodType {
3354
3607
  unknownKeys: "strict",
3355
3608
  ...message !== void 0 ? {
3356
3609
  errorMap: (issue, ctx) => {
3357
- var _a, _b, _c, _d;
3358
- 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;
3610
+ var _a, _b;
3611
+ const defaultError = ((_b = (_a = this._def).errorMap) == null ? void 0 : _b.call(_a, issue, ctx).message) ?? ctx.defaultError;
3359
3612
  if (issue.code === "unrecognized_keys")
3360
3613
  return {
3361
- message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
3614
+ message: errorUtil.errToObj(message).message ?? defaultError
3362
3615
  };
3363
3616
  return {
3364
3617
  message: defaultError
@@ -3489,11 +3742,11 @@ class ZodObject extends ZodType {
3489
3742
  }
3490
3743
  pick(mask) {
3491
3744
  const shape = {};
3492
- util.objectKeys(mask).forEach((key) => {
3745
+ for (const key of util.objectKeys(mask)) {
3493
3746
  if (mask[key] && this.shape[key]) {
3494
3747
  shape[key] = this.shape[key];
3495
3748
  }
3496
- });
3749
+ }
3497
3750
  return new ZodObject({
3498
3751
  ...this._def,
3499
3752
  shape: () => shape
@@ -3501,11 +3754,11 @@ class ZodObject extends ZodType {
3501
3754
  }
3502
3755
  omit(mask) {
3503
3756
  const shape = {};
3504
- util.objectKeys(this.shape).forEach((key) => {
3757
+ for (const key of util.objectKeys(this.shape)) {
3505
3758
  if (!mask[key]) {
3506
3759
  shape[key] = this.shape[key];
3507
3760
  }
3508
- });
3761
+ }
3509
3762
  return new ZodObject({
3510
3763
  ...this._def,
3511
3764
  shape: () => shape
@@ -3519,14 +3772,14 @@ class ZodObject extends ZodType {
3519
3772
  }
3520
3773
  partial(mask) {
3521
3774
  const newShape = {};
3522
- util.objectKeys(this.shape).forEach((key) => {
3775
+ for (const key of util.objectKeys(this.shape)) {
3523
3776
  const fieldSchema = this.shape[key];
3524
3777
  if (mask && !mask[key]) {
3525
3778
  newShape[key] = fieldSchema;
3526
3779
  } else {
3527
3780
  newShape[key] = fieldSchema.optional();
3528
3781
  }
3529
- });
3782
+ }
3530
3783
  return new ZodObject({
3531
3784
  ...this._def,
3532
3785
  shape: () => newShape
@@ -3534,7 +3787,7 @@ class ZodObject extends ZodType {
3534
3787
  }
3535
3788
  required(mask) {
3536
3789
  const newShape = {};
3537
- util.objectKeys(this.shape).forEach((key) => {
3790
+ for (const key of util.objectKeys(this.shape)) {
3538
3791
  if (mask && !mask[key]) {
3539
3792
  newShape[key] = this.shape[key];
3540
3793
  } else {
@@ -3545,7 +3798,7 @@ class ZodObject extends ZodType {
3545
3798
  }
3546
3799
  newShape[key] = newField;
3547
3800
  }
3548
- });
3801
+ }
3549
3802
  return new ZodObject({
3550
3803
  ...this._def,
3551
3804
  shape: () => newShape
@@ -3683,15 +3936,25 @@ const getDiscriminator = (type) => {
3683
3936
  } else if (type instanceof ZodEnum) {
3684
3937
  return type.options;
3685
3938
  } else if (type instanceof ZodNativeEnum) {
3686
- return Object.keys(type.enum);
3939
+ return util.objectValues(type.enum);
3687
3940
  } else if (type instanceof ZodDefault) {
3688
3941
  return getDiscriminator(type._def.innerType);
3689
3942
  } else if (type instanceof ZodUndefined) {
3690
3943
  return [void 0];
3691
3944
  } else if (type instanceof ZodNull) {
3692
3945
  return [null];
3946
+ } else if (type instanceof ZodOptional) {
3947
+ return [void 0, ...getDiscriminator(type.unwrap())];
3948
+ } else if (type instanceof ZodNullable) {
3949
+ return [null, ...getDiscriminator(type.unwrap())];
3950
+ } else if (type instanceof ZodBranded) {
3951
+ return getDiscriminator(type.unwrap());
3952
+ } else if (type instanceof ZodReadonly) {
3953
+ return getDiscriminator(type.unwrap());
3954
+ } else if (type instanceof ZodCatch) {
3955
+ return getDiscriminator(type._def.innerType);
3693
3956
  } else {
3694
- return null;
3957
+ return [];
3695
3958
  }
3696
3959
  };
3697
3960
  class ZodDiscriminatedUnion extends ZodType {
@@ -3751,7 +4014,7 @@ class ZodDiscriminatedUnion extends ZodType {
3751
4014
  const optionsMap = /* @__PURE__ */ new Map();
3752
4015
  for (const type of options) {
3753
4016
  const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3754
- if (!discriminatorValues) {
4017
+ if (!discriminatorValues.length) {
3755
4018
  throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3756
4019
  }
3757
4020
  for (const value of discriminatorValues) {
@@ -3951,7 +4214,8 @@ class ZodRecord extends ZodType {
3951
4214
  for (const key in ctx.data) {
3952
4215
  pairs.push({
3953
4216
  key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3954
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
4217
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
4218
+ alwaysSet: key in ctx.data
3955
4219
  });
3956
4220
  }
3957
4221
  if (ctx.common.async) {
@@ -4150,12 +4414,7 @@ class ZodFunction extends ZodType {
4150
4414
  return makeIssue({
4151
4415
  data: args,
4152
4416
  path: ctx.path,
4153
- errorMaps: [
4154
- ctx.common.contextualErrorMap,
4155
- ctx.schemaErrorMap,
4156
- getErrorMap(),
4157
- errorMap
4158
- ].filter((x) => !!x),
4417
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), errorMap].filter((x) => !!x),
4159
4418
  issueData: {
4160
4419
  code: ZodIssueCode.invalid_arguments,
4161
4420
  argumentsError: error
@@ -4166,12 +4425,7 @@ class ZodFunction extends ZodType {
4166
4425
  return makeIssue({
4167
4426
  data: returns,
4168
4427
  path: ctx.path,
4169
- errorMaps: [
4170
- ctx.common.contextualErrorMap,
4171
- ctx.schemaErrorMap,
4172
- getErrorMap(),
4173
- errorMap
4174
- ].filter((x) => !!x),
4428
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), errorMap].filter((x) => !!x),
4175
4429
  issueData: {
4176
4430
  code: ZodIssueCode.invalid_return_type,
4177
4431
  returnTypeError: error
@@ -4306,7 +4560,10 @@ class ZodEnum extends ZodType {
4306
4560
  });
4307
4561
  return INVALID;
4308
4562
  }
4309
- if (this._def.values.indexOf(input.data) === -1) {
4563
+ if (!this._cache) {
4564
+ this._cache = new Set(this._def.values);
4565
+ }
4566
+ if (!this._cache.has(input.data)) {
4310
4567
  const ctx = this._getOrReturnCtx(input);
4311
4568
  const expectedValues = this._def.values;
4312
4569
  addIssueToContext(ctx, {
@@ -4342,11 +4599,17 @@ class ZodEnum extends ZodType {
4342
4599
  }
4343
4600
  return enumValues;
4344
4601
  }
4345
- extract(values) {
4346
- return ZodEnum.create(values);
4602
+ extract(values, newDef = this._def) {
4603
+ return ZodEnum.create(values, {
4604
+ ...this._def,
4605
+ ...newDef
4606
+ });
4347
4607
  }
4348
- exclude(values) {
4349
- return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
4608
+ exclude(values, newDef = this._def) {
4609
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
4610
+ ...this._def,
4611
+ ...newDef
4612
+ });
4350
4613
  }
4351
4614
  }
4352
4615
  ZodEnum.create = createZodEnum;
@@ -4363,7 +4626,10 @@ class ZodNativeEnum extends ZodType {
4363
4626
  });
4364
4627
  return INVALID;
4365
4628
  }
4366
- if (nativeEnumValues.indexOf(input.data) === -1) {
4629
+ if (!this._cache) {
4630
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
4631
+ }
4632
+ if (!this._cache.has(input.data)) {
4367
4633
  const expectedValues = util.objectValues(nativeEnumValues);
4368
4634
  addIssueToContext(ctx, {
4369
4635
  received: ctx.data,
@@ -4441,26 +4707,38 @@ class ZodEffects extends ZodType {
4441
4707
  checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
4442
4708
  if (effect.type === "preprocess") {
4443
4709
  const processed = effect.transform(ctx.data, checkCtx);
4444
- if (ctx.common.issues.length) {
4445
- return {
4446
- status: "dirty",
4447
- value: ctx.data
4448
- };
4449
- }
4450
4710
  if (ctx.common.async) {
4451
- return Promise.resolve(processed).then((processed2) => {
4452
- return this._def.schema._parseAsync({
4711
+ return Promise.resolve(processed).then(async (processed2) => {
4712
+ if (status.value === "aborted")
4713
+ return INVALID;
4714
+ const result = await this._def.schema._parseAsync({
4453
4715
  data: processed2,
4454
4716
  path: ctx.path,
4455
4717
  parent: ctx
4456
4718
  });
4719
+ if (result.status === "aborted")
4720
+ return INVALID;
4721
+ if (result.status === "dirty")
4722
+ return DIRTY(result.value);
4723
+ if (status.value === "dirty")
4724
+ return DIRTY(result.value);
4725
+ return result;
4457
4726
  });
4458
4727
  } else {
4459
- return this._def.schema._parseSync({
4728
+ if (status.value === "aborted")
4729
+ return INVALID;
4730
+ const result = this._def.schema._parseSync({
4460
4731
  data: processed,
4461
4732
  path: ctx.path,
4462
4733
  parent: ctx
4463
4734
  });
4735
+ if (result.status === "aborted")
4736
+ return INVALID;
4737
+ if (result.status === "dirty")
4738
+ return DIRTY(result.value);
4739
+ if (status.value === "dirty")
4740
+ return DIRTY(result.value);
4741
+ return result;
4464
4742
  }
4465
4743
  }
4466
4744
  if (effect.type === "refinement") {
@@ -4506,7 +4784,7 @@ class ZodEffects extends ZodType {
4506
4784
  parent: ctx
4507
4785
  });
4508
4786
  if (!isValid(base))
4509
- return base;
4787
+ return INVALID;
4510
4788
  const result = effect.transform(base.value, checkCtx);
4511
4789
  if (result instanceof Promise) {
4512
4790
  throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
@@ -4515,8 +4793,11 @@ class ZodEffects extends ZodType {
4515
4793
  } else {
4516
4794
  return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
4517
4795
  if (!isValid(base))
4518
- return base;
4519
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
4796
+ return INVALID;
4797
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
4798
+ status: status.value,
4799
+ value: result
4800
+ }));
4520
4801
  });
4521
4802
  }
4522
4803
  }
@@ -4749,10 +5030,16 @@ class ZodPipeline extends ZodType {
4749
5030
  class ZodReadonly extends ZodType {
4750
5031
  _parse(input) {
4751
5032
  const result = this._def.innerType._parse(input);
4752
- if (isValid(result)) {
4753
- result.value = Object.freeze(result.value);
4754
- }
4755
- return result;
5033
+ const freeze = (data) => {
5034
+ if (isValid(data)) {
5035
+ data.value = Object.freeze(data.value);
5036
+ }
5037
+ return data;
5038
+ };
5039
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
5040
+ }
5041
+ unwrap() {
5042
+ return this._def.innerType;
4756
5043
  }
4757
5044
  }
4758
5045
  ZodReadonly.create = (type, params) => {
@@ -4762,19 +5049,33 @@ ZodReadonly.create = (type, params) => {
4762
5049
  ...processCreateParams(params)
4763
5050
  });
4764
5051
  };
4765
- const custom = (check, params = {}, fatal) => {
5052
+ function cleanParams(params, data) {
5053
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
5054
+ const p2 = typeof p === "string" ? { message: p } : p;
5055
+ return p2;
5056
+ }
5057
+ function custom(check, _params = {}, fatal) {
4766
5058
  if (check)
4767
5059
  return ZodAny.create().superRefine((data, ctx) => {
4768
- var _a, _b;
4769
- if (!check(data)) {
4770
- const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
4771
- const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
4772
- const p2 = typeof p === "string" ? { message: p } : p;
4773
- ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
5060
+ const r = check(data);
5061
+ if (r instanceof Promise) {
5062
+ return r.then((r2) => {
5063
+ if (!r2) {
5064
+ const params = cleanParams(_params, data);
5065
+ const _fatal = params.fatal ?? fatal ?? true;
5066
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
5067
+ }
5068
+ });
5069
+ }
5070
+ if (!r) {
5071
+ const params = cleanParams(_params, data);
5072
+ const _fatal = params.fatal ?? fatal ?? true;
5073
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
4774
5074
  }
5075
+ return;
4775
5076
  });
4776
5077
  return ZodAny.create();
4777
- };
5078
+ }
4778
5079
  const late = {
4779
5080
  object: ZodObject.lazycreate
4780
5081
  };
@@ -4868,98 +5169,98 @@ const coerce = {
4868
5169
  date: (arg) => ZodDate.create({ ...arg, coerce: true })
4869
5170
  };
4870
5171
  const NEVER = INVALID;
4871
- var z = /* @__PURE__ */ Object.freeze({
5172
+ const z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4872
5173
  __proto__: null,
4873
- defaultErrorMap: errorMap,
4874
- setErrorMap,
4875
- getErrorMap,
4876
- makeIssue,
5174
+ BRAND,
5175
+ DIRTY,
4877
5176
  EMPTY_PATH,
4878
- addIssueToContext,
4879
- ParseStatus,
4880
5177
  INVALID,
4881
- DIRTY,
5178
+ NEVER,
4882
5179
  OK,
4883
- isAborted,
4884
- isDirty,
4885
- isValid,
4886
- isAsync,
4887
- get util() {
4888
- return util;
4889
- },
4890
- get objectUtil() {
4891
- return objectUtil;
4892
- },
4893
- ZodParsedType,
4894
- getParsedType,
4895
- ZodType,
4896
- ZodString,
4897
- ZodNumber,
5180
+ ParseStatus,
5181
+ Schema: ZodType,
5182
+ ZodAny,
5183
+ ZodArray,
4898
5184
  ZodBigInt,
4899
5185
  ZodBoolean,
5186
+ ZodBranded,
5187
+ ZodCatch,
4900
5188
  ZodDate,
4901
- ZodSymbol,
4902
- ZodUndefined,
4903
- ZodNull,
4904
- ZodAny,
4905
- ZodUnknown,
4906
- ZodNever,
4907
- ZodVoid,
4908
- ZodArray,
4909
- ZodObject,
4910
- ZodUnion,
5189
+ ZodDefault,
4911
5190
  ZodDiscriminatedUnion,
4912
- ZodIntersection,
4913
- ZodTuple,
4914
- ZodRecord,
4915
- ZodMap,
4916
- ZodSet,
5191
+ ZodEffects,
5192
+ ZodEnum,
5193
+ ZodError,
5194
+ get ZodFirstPartyTypeKind() {
5195
+ return ZodFirstPartyTypeKind;
5196
+ },
4917
5197
  ZodFunction,
5198
+ ZodIntersection,
5199
+ ZodIssueCode,
4918
5200
  ZodLazy,
4919
5201
  ZodLiteral,
4920
- ZodEnum,
5202
+ ZodMap,
5203
+ ZodNaN,
4921
5204
  ZodNativeEnum,
4922
- ZodPromise,
4923
- ZodEffects,
4924
- ZodTransformer: ZodEffects,
4925
- ZodOptional,
5205
+ ZodNever,
5206
+ ZodNull,
4926
5207
  ZodNullable,
4927
- ZodDefault,
4928
- ZodCatch,
4929
- ZodNaN,
4930
- BRAND,
4931
- ZodBranded,
5208
+ ZodNumber,
5209
+ ZodObject,
5210
+ ZodOptional,
5211
+ ZodParsedType,
4932
5212
  ZodPipeline,
5213
+ ZodPromise,
4933
5214
  ZodReadonly,
4934
- custom,
4935
- Schema: ZodType,
5215
+ ZodRecord,
4936
5216
  ZodSchema: ZodType,
4937
- late,
4938
- get ZodFirstPartyTypeKind() {
4939
- return ZodFirstPartyTypeKind;
4940
- },
4941
- coerce,
5217
+ ZodSet,
5218
+ ZodString,
5219
+ ZodSymbol,
5220
+ ZodTransformer: ZodEffects,
5221
+ ZodTuple,
5222
+ ZodType,
5223
+ ZodUndefined,
5224
+ ZodUnion,
5225
+ ZodUnknown,
5226
+ ZodVoid,
5227
+ addIssueToContext,
4942
5228
  any: anyType,
4943
5229
  array: arrayType,
4944
5230
  bigint: bigIntType,
4945
5231
  boolean: booleanType,
5232
+ coerce,
5233
+ custom,
4946
5234
  date: dateType,
5235
+ datetimeRegex,
5236
+ defaultErrorMap: errorMap,
4947
5237
  discriminatedUnion: discriminatedUnionType,
4948
5238
  effect: effectsType,
4949
- "enum": enumType,
4950
- "function": functionType,
4951
- "instanceof": instanceOfType,
5239
+ enum: enumType,
5240
+ function: functionType,
5241
+ getErrorMap,
5242
+ getParsedType,
5243
+ instanceof: instanceOfType,
4952
5244
  intersection: intersectionType,
5245
+ isAborted,
5246
+ isAsync,
5247
+ isDirty,
5248
+ isValid,
5249
+ late,
4953
5250
  lazy: lazyType,
4954
5251
  literal: literalType,
5252
+ makeIssue,
4955
5253
  map: mapType,
4956
5254
  nan: nanType,
4957
5255
  nativeEnum: nativeEnumType,
4958
5256
  never: neverType,
4959
- "null": nullType,
5257
+ null: nullType,
4960
5258
  nullable: nullableType,
4961
5259
  number: numberType,
4962
5260
  object: objectType,
5261
+ get objectUtil() {
5262
+ return objectUtil;
5263
+ },
4963
5264
  oboolean,
4964
5265
  onumber,
4965
5266
  optional: optionalType,
@@ -4967,22 +5268,23 @@ var z = /* @__PURE__ */ Object.freeze({
4967
5268
  pipeline: pipelineType,
4968
5269
  preprocess: preprocessType,
4969
5270
  promise: promiseType,
5271
+ quotelessJson,
4970
5272
  record: recordType,
4971
5273
  set: setType,
5274
+ setErrorMap,
4972
5275
  strictObject: strictObjectType,
4973
5276
  string: stringType,
4974
5277
  symbol: symbolType,
4975
5278
  transformer: effectsType,
4976
5279
  tuple: tupleType,
4977
- "undefined": undefinedType,
5280
+ undefined: undefinedType,
4978
5281
  union: unionType,
4979
5282
  unknown: unknownType,
4980
- "void": voidType,
4981
- NEVER,
4982
- ZodIssueCode,
4983
- quotelessJson,
4984
- ZodError
4985
- });
5283
+ get util() {
5284
+ return util;
5285
+ },
5286
+ void: voidType
5287
+ }, Symbol.toStringTag, { value: "Module" }));
4986
5288
  const sdk = new Medusa({
4987
5289
  baseUrl: "/",
4988
5290
  debug: false,