@storm-software/config-tools 1.39.2 → 1.40.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.
@@ -354,23 +354,23 @@ var require_conversions = __commonJS({
354
354
  b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
355
355
  const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
356
356
  const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
357
- const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
358
- return [x * 100, y * 100, z * 100];
357
+ const z2 = r * 0.0193 + g * 0.1192 + b * 0.9505;
358
+ return [x * 100, y * 100, z2 * 100];
359
359
  };
360
360
  convert.rgb.lab = function(rgb) {
361
361
  const xyz = convert.rgb.xyz(rgb);
362
362
  let x = xyz[0];
363
363
  let y = xyz[1];
364
- let z = xyz[2];
364
+ let z2 = xyz[2];
365
365
  x /= 95.047;
366
366
  y /= 100;
367
- z /= 108.883;
367
+ z2 /= 108.883;
368
368
  x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
369
369
  y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
370
- z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
370
+ z2 = z2 > 8856e-6 ? z2 ** (1 / 3) : 7.787 * z2 + 16 / 116;
371
371
  const l = 116 * y - 16;
372
372
  const a = 500 * (x - y);
373
- const b = 200 * (y - z);
373
+ const b = 200 * (y - z2);
374
374
  return [l, a, b];
375
375
  };
376
376
  convert.hsl.rgb = function(hsl) {
@@ -534,13 +534,13 @@ var require_conversions = __commonJS({
534
534
  convert.xyz.rgb = function(xyz) {
535
535
  const x = xyz[0] / 100;
536
536
  const y = xyz[1] / 100;
537
- const z = xyz[2] / 100;
537
+ const z2 = xyz[2] / 100;
538
538
  let r;
539
539
  let g;
540
540
  let b;
541
- r = x * 3.2406 + y * -1.5372 + z * -0.4986;
542
- g = x * -0.9689 + y * 1.8758 + z * 0.0415;
543
- b = x * 0.0557 + y * -0.204 + z * 1.057;
541
+ r = x * 3.2406 + y * -1.5372 + z2 * -0.4986;
542
+ g = x * -0.9689 + y * 1.8758 + z2 * 0.0415;
543
+ b = x * 0.0557 + y * -0.204 + z2 * 1.057;
544
544
  r = r > 31308e-7 ? 1.055 * r ** (1 / 2.4) - 0.055 : r * 12.92;
545
545
  g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : g * 12.92;
546
546
  b = b > 31308e-7 ? 1.055 * b ** (1 / 2.4) - 0.055 : b * 12.92;
@@ -552,16 +552,16 @@ var require_conversions = __commonJS({
552
552
  convert.xyz.lab = function(xyz) {
553
553
  let x = xyz[0];
554
554
  let y = xyz[1];
555
- let z = xyz[2];
555
+ let z2 = xyz[2];
556
556
  x /= 95.047;
557
557
  y /= 100;
558
- z /= 108.883;
558
+ z2 /= 108.883;
559
559
  x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
560
560
  y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
561
- z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
561
+ z2 = z2 > 8856e-6 ? z2 ** (1 / 3) : 7.787 * z2 + 16 / 116;
562
562
  const l = 116 * y - 16;
563
563
  const a = 500 * (x - y);
564
- const b = 200 * (y - z);
564
+ const b = 200 * (y - z2);
565
565
  return [l, a, b];
566
566
  };
567
567
  convert.lab.xyz = function(lab) {
@@ -570,20 +570,20 @@ var require_conversions = __commonJS({
570
570
  const b = lab[2];
571
571
  let x;
572
572
  let y;
573
- let z;
573
+ let z2;
574
574
  y = (l + 16) / 116;
575
575
  x = a / 500 + y;
576
- z = y - b / 200;
576
+ z2 = y - b / 200;
577
577
  const y2 = y ** 3;
578
578
  const x2 = x ** 3;
579
- const z2 = z ** 3;
579
+ const z22 = z2 ** 3;
580
580
  y = y2 > 8856e-6 ? y2 : (y - 16 / 116) / 7.787;
581
581
  x = x2 > 8856e-6 ? x2 : (x - 16 / 116) / 7.787;
582
- z = z2 > 8856e-6 ? z2 : (z - 16 / 116) / 7.787;
582
+ z2 = z22 > 8856e-6 ? z22 : (z2 - 16 / 116) / 7.787;
583
583
  x *= 95.047;
584
584
  y *= 100;
585
- z *= 108.883;
586
- return [x, y, z];
585
+ z2 *= 108.883;
586
+ return [x, y, z2];
587
587
  };
588
588
  convert.lab.lch = function(lab) {
589
589
  const l = lab[0];
@@ -1649,9 +1649,3900 @@ var getChalk = () => {
1649
1649
  return _chalk;
1650
1650
  };
1651
1651
 
1652
+ // node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
1653
+ var util;
1654
+ (function(util2) {
1655
+ util2.assertEqual = (val) => val;
1656
+ function assertIs(_arg) {
1657
+ }
1658
+ util2.assertIs = assertIs;
1659
+ function assertNever(_x) {
1660
+ throw new Error();
1661
+ }
1662
+ util2.assertNever = assertNever;
1663
+ util2.arrayToEnum = (items) => {
1664
+ const obj = {};
1665
+ for (const item of items) {
1666
+ obj[item] = item;
1667
+ }
1668
+ return obj;
1669
+ };
1670
+ util2.getValidEnumValues = (obj) => {
1671
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
1672
+ const filtered = {};
1673
+ for (const k of validKeys) {
1674
+ filtered[k] = obj[k];
1675
+ }
1676
+ return util2.objectValues(filtered);
1677
+ };
1678
+ util2.objectValues = (obj) => {
1679
+ return util2.objectKeys(obj).map(function(e) {
1680
+ return obj[e];
1681
+ });
1682
+ };
1683
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
1684
+ const keys = [];
1685
+ for (const key in object) {
1686
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
1687
+ keys.push(key);
1688
+ }
1689
+ }
1690
+ return keys;
1691
+ };
1692
+ util2.find = (arr, checker) => {
1693
+ for (const item of arr) {
1694
+ if (checker(item))
1695
+ return item;
1696
+ }
1697
+ return void 0;
1698
+ };
1699
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
1700
+ function joinValues(array, separator = " | ") {
1701
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
1702
+ }
1703
+ util2.joinValues = joinValues;
1704
+ util2.jsonStringifyReplacer = (_, value) => {
1705
+ if (typeof value === "bigint") {
1706
+ return value.toString();
1707
+ }
1708
+ return value;
1709
+ };
1710
+ })(util || (util = {}));
1711
+ var objectUtil;
1712
+ (function(objectUtil2) {
1713
+ objectUtil2.mergeShapes = (first, second) => {
1714
+ return {
1715
+ ...first,
1716
+ ...second
1717
+ // second overwrites first
1718
+ };
1719
+ };
1720
+ })(objectUtil || (objectUtil = {}));
1721
+ var ZodParsedType = util.arrayToEnum([
1722
+ "string",
1723
+ "nan",
1724
+ "number",
1725
+ "integer",
1726
+ "float",
1727
+ "boolean",
1728
+ "date",
1729
+ "bigint",
1730
+ "symbol",
1731
+ "function",
1732
+ "undefined",
1733
+ "null",
1734
+ "array",
1735
+ "object",
1736
+ "unknown",
1737
+ "promise",
1738
+ "void",
1739
+ "never",
1740
+ "map",
1741
+ "set"
1742
+ ]);
1743
+ var getParsedType = (data) => {
1744
+ const t = typeof data;
1745
+ switch (t) {
1746
+ case "undefined":
1747
+ return ZodParsedType.undefined;
1748
+ case "string":
1749
+ return ZodParsedType.string;
1750
+ case "number":
1751
+ return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
1752
+ case "boolean":
1753
+ return ZodParsedType.boolean;
1754
+ case "function":
1755
+ return ZodParsedType.function;
1756
+ case "bigint":
1757
+ return ZodParsedType.bigint;
1758
+ case "symbol":
1759
+ return ZodParsedType.symbol;
1760
+ case "object":
1761
+ if (Array.isArray(data)) {
1762
+ return ZodParsedType.array;
1763
+ }
1764
+ if (data === null) {
1765
+ return ZodParsedType.null;
1766
+ }
1767
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
1768
+ return ZodParsedType.promise;
1769
+ }
1770
+ if (typeof Map !== "undefined" && data instanceof Map) {
1771
+ return ZodParsedType.map;
1772
+ }
1773
+ if (typeof Set !== "undefined" && data instanceof Set) {
1774
+ return ZodParsedType.set;
1775
+ }
1776
+ if (typeof Date !== "undefined" && data instanceof Date) {
1777
+ return ZodParsedType.date;
1778
+ }
1779
+ return ZodParsedType.object;
1780
+ default:
1781
+ return ZodParsedType.unknown;
1782
+ }
1783
+ };
1784
+ var ZodIssueCode = util.arrayToEnum([
1785
+ "invalid_type",
1786
+ "invalid_literal",
1787
+ "custom",
1788
+ "invalid_union",
1789
+ "invalid_union_discriminator",
1790
+ "invalid_enum_value",
1791
+ "unrecognized_keys",
1792
+ "invalid_arguments",
1793
+ "invalid_return_type",
1794
+ "invalid_date",
1795
+ "invalid_string",
1796
+ "too_small",
1797
+ "too_big",
1798
+ "invalid_intersection_types",
1799
+ "not_multiple_of",
1800
+ "not_finite"
1801
+ ]);
1802
+ var quotelessJson = (obj) => {
1803
+ const json = JSON.stringify(obj, null, 2);
1804
+ return json.replace(/"([^"]+)":/g, "$1:");
1805
+ };
1806
+ var ZodError = class extends Error {
1807
+ constructor(issues) {
1808
+ super();
1809
+ this.issues = [];
1810
+ this.addIssue = (sub) => {
1811
+ this.issues = [...this.issues, sub];
1812
+ };
1813
+ this.addIssues = (subs = []) => {
1814
+ this.issues = [...this.issues, ...subs];
1815
+ };
1816
+ const actualProto = new.target.prototype;
1817
+ if (Object.setPrototypeOf) {
1818
+ Object.setPrototypeOf(this, actualProto);
1819
+ } else {
1820
+ this.__proto__ = actualProto;
1821
+ }
1822
+ this.name = "ZodError";
1823
+ this.issues = issues;
1824
+ }
1825
+ get errors() {
1826
+ return this.issues;
1827
+ }
1828
+ format(_mapper) {
1829
+ const mapper = _mapper || function(issue) {
1830
+ return issue.message;
1831
+ };
1832
+ const fieldErrors = { _errors: [] };
1833
+ const processError = (error) => {
1834
+ for (const issue of error.issues) {
1835
+ if (issue.code === "invalid_union") {
1836
+ issue.unionErrors.map(processError);
1837
+ } else if (issue.code === "invalid_return_type") {
1838
+ processError(issue.returnTypeError);
1839
+ } else if (issue.code === "invalid_arguments") {
1840
+ processError(issue.argumentsError);
1841
+ } else if (issue.path.length === 0) {
1842
+ fieldErrors._errors.push(mapper(issue));
1843
+ } else {
1844
+ let curr = fieldErrors;
1845
+ let i = 0;
1846
+ while (i < issue.path.length) {
1847
+ const el = issue.path[i];
1848
+ const terminal = i === issue.path.length - 1;
1849
+ if (!terminal) {
1850
+ curr[el] = curr[el] || { _errors: [] };
1851
+ } else {
1852
+ curr[el] = curr[el] || { _errors: [] };
1853
+ curr[el]._errors.push(mapper(issue));
1854
+ }
1855
+ curr = curr[el];
1856
+ i++;
1857
+ }
1858
+ }
1859
+ }
1860
+ };
1861
+ processError(this);
1862
+ return fieldErrors;
1863
+ }
1864
+ toString() {
1865
+ return this.message;
1866
+ }
1867
+ get message() {
1868
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
1869
+ }
1870
+ get isEmpty() {
1871
+ return this.issues.length === 0;
1872
+ }
1873
+ flatten(mapper = (issue) => issue.message) {
1874
+ const fieldErrors = {};
1875
+ const formErrors = [];
1876
+ for (const sub of this.issues) {
1877
+ if (sub.path.length > 0) {
1878
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
1879
+ fieldErrors[sub.path[0]].push(mapper(sub));
1880
+ } else {
1881
+ formErrors.push(mapper(sub));
1882
+ }
1883
+ }
1884
+ return { formErrors, fieldErrors };
1885
+ }
1886
+ get formErrors() {
1887
+ return this.flatten();
1888
+ }
1889
+ };
1890
+ ZodError.create = (issues) => {
1891
+ const error = new ZodError(issues);
1892
+ return error;
1893
+ };
1894
+ var errorMap = (issue, _ctx) => {
1895
+ let message;
1896
+ switch (issue.code) {
1897
+ case ZodIssueCode.invalid_type:
1898
+ if (issue.received === ZodParsedType.undefined) {
1899
+ message = "Required";
1900
+ } else {
1901
+ message = `Expected ${issue.expected}, received ${issue.received}`;
1902
+ }
1903
+ break;
1904
+ case ZodIssueCode.invalid_literal:
1905
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
1906
+ break;
1907
+ case ZodIssueCode.unrecognized_keys:
1908
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
1909
+ break;
1910
+ case ZodIssueCode.invalid_union:
1911
+ message = `Invalid input`;
1912
+ break;
1913
+ case ZodIssueCode.invalid_union_discriminator:
1914
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
1915
+ break;
1916
+ case ZodIssueCode.invalid_enum_value:
1917
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
1918
+ break;
1919
+ case ZodIssueCode.invalid_arguments:
1920
+ message = `Invalid function arguments`;
1921
+ break;
1922
+ case ZodIssueCode.invalid_return_type:
1923
+ message = `Invalid function return type`;
1924
+ break;
1925
+ case ZodIssueCode.invalid_date:
1926
+ message = `Invalid date`;
1927
+ break;
1928
+ case ZodIssueCode.invalid_string:
1929
+ if (typeof issue.validation === "object") {
1930
+ if ("includes" in issue.validation) {
1931
+ message = `Invalid input: must include "${issue.validation.includes}"`;
1932
+ if (typeof issue.validation.position === "number") {
1933
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
1934
+ }
1935
+ } else if ("startsWith" in issue.validation) {
1936
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
1937
+ } else if ("endsWith" in issue.validation) {
1938
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
1939
+ } else {
1940
+ util.assertNever(issue.validation);
1941
+ }
1942
+ } else if (issue.validation !== "regex") {
1943
+ message = `Invalid ${issue.validation}`;
1944
+ } else {
1945
+ message = "Invalid";
1946
+ }
1947
+ break;
1948
+ case ZodIssueCode.too_small:
1949
+ if (issue.type === "array")
1950
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
1951
+ else if (issue.type === "string")
1952
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
1953
+ else if (issue.type === "number")
1954
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
1955
+ else if (issue.type === "date")
1956
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
1957
+ else
1958
+ message = "Invalid input";
1959
+ break;
1960
+ case ZodIssueCode.too_big:
1961
+ if (issue.type === "array")
1962
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
1963
+ else if (issue.type === "string")
1964
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
1965
+ else if (issue.type === "number")
1966
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1967
+ else if (issue.type === "bigint")
1968
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1969
+ else if (issue.type === "date")
1970
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
1971
+ else
1972
+ message = "Invalid input";
1973
+ break;
1974
+ case ZodIssueCode.custom:
1975
+ message = `Invalid input`;
1976
+ break;
1977
+ case ZodIssueCode.invalid_intersection_types:
1978
+ message = `Intersection results could not be merged`;
1979
+ break;
1980
+ case ZodIssueCode.not_multiple_of:
1981
+ message = `Number must be a multiple of ${issue.multipleOf}`;
1982
+ break;
1983
+ case ZodIssueCode.not_finite:
1984
+ message = "Number must be finite";
1985
+ break;
1986
+ default:
1987
+ message = _ctx.defaultError;
1988
+ util.assertNever(issue);
1989
+ }
1990
+ return { message };
1991
+ };
1992
+ var overrideErrorMap = errorMap;
1993
+ function setErrorMap(map) {
1994
+ overrideErrorMap = map;
1995
+ }
1996
+ function getErrorMap() {
1997
+ return overrideErrorMap;
1998
+ }
1999
+ var makeIssue = (params) => {
2000
+ const { data, path, errorMaps, issueData } = params;
2001
+ const fullPath = [...path, ...issueData.path || []];
2002
+ const fullIssue = {
2003
+ ...issueData,
2004
+ path: fullPath
2005
+ };
2006
+ let errorMessage = "";
2007
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
2008
+ for (const map of maps) {
2009
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
2010
+ }
2011
+ return {
2012
+ ...issueData,
2013
+ path: fullPath,
2014
+ message: issueData.message || errorMessage
2015
+ };
2016
+ };
2017
+ var EMPTY_PATH = [];
2018
+ function addIssueToContext(ctx, issueData) {
2019
+ const issue = makeIssue({
2020
+ issueData,
2021
+ data: ctx.data,
2022
+ path: ctx.path,
2023
+ errorMaps: [
2024
+ ctx.common.contextualErrorMap,
2025
+ ctx.schemaErrorMap,
2026
+ getErrorMap(),
2027
+ errorMap
2028
+ // then global default map
2029
+ ].filter((x) => !!x)
2030
+ });
2031
+ ctx.common.issues.push(issue);
2032
+ }
2033
+ var ParseStatus = class _ParseStatus {
2034
+ constructor() {
2035
+ this.value = "valid";
2036
+ }
2037
+ dirty() {
2038
+ if (this.value === "valid")
2039
+ this.value = "dirty";
2040
+ }
2041
+ abort() {
2042
+ if (this.value !== "aborted")
2043
+ this.value = "aborted";
2044
+ }
2045
+ static mergeArray(status, results) {
2046
+ const arrayValue = [];
2047
+ for (const s of results) {
2048
+ if (s.status === "aborted")
2049
+ return INVALID;
2050
+ if (s.status === "dirty")
2051
+ status.dirty();
2052
+ arrayValue.push(s.value);
2053
+ }
2054
+ return { status: status.value, value: arrayValue };
2055
+ }
2056
+ static async mergeObjectAsync(status, pairs) {
2057
+ const syncPairs = [];
2058
+ for (const pair of pairs) {
2059
+ syncPairs.push({
2060
+ key: await pair.key,
2061
+ value: await pair.value
2062
+ });
2063
+ }
2064
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
2065
+ }
2066
+ static mergeObjectSync(status, pairs) {
2067
+ const finalObject = {};
2068
+ for (const pair of pairs) {
2069
+ const { key, value } = pair;
2070
+ if (key.status === "aborted")
2071
+ return INVALID;
2072
+ if (value.status === "aborted")
2073
+ return INVALID;
2074
+ if (key.status === "dirty")
2075
+ status.dirty();
2076
+ if (value.status === "dirty")
2077
+ status.dirty();
2078
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
2079
+ finalObject[key.value] = value.value;
2080
+ }
2081
+ }
2082
+ return { status: status.value, value: finalObject };
2083
+ }
2084
+ };
2085
+ var INVALID = Object.freeze({
2086
+ status: "aborted"
2087
+ });
2088
+ var DIRTY = (value) => ({ status: "dirty", value });
2089
+ var OK = (value) => ({ status: "valid", value });
2090
+ var isAborted = (x) => x.status === "aborted";
2091
+ var isDirty = (x) => x.status === "dirty";
2092
+ var isValid = (x) => x.status === "valid";
2093
+ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
2094
+ var errorUtil;
2095
+ (function(errorUtil2) {
2096
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
2097
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
2098
+ })(errorUtil || (errorUtil = {}));
2099
+ var ParseInputLazyPath = class {
2100
+ constructor(parent, value, path, key) {
2101
+ this._cachedPath = [];
2102
+ this.parent = parent;
2103
+ this.data = value;
2104
+ this._path = path;
2105
+ this._key = key;
2106
+ }
2107
+ get path() {
2108
+ if (!this._cachedPath.length) {
2109
+ if (this._key instanceof Array) {
2110
+ this._cachedPath.push(...this._path, ...this._key);
2111
+ } else {
2112
+ this._cachedPath.push(...this._path, this._key);
2113
+ }
2114
+ }
2115
+ return this._cachedPath;
2116
+ }
2117
+ };
2118
+ var handleResult = (ctx, result) => {
2119
+ if (isValid(result)) {
2120
+ return { success: true, data: result.value };
2121
+ } else {
2122
+ if (!ctx.common.issues.length) {
2123
+ throw new Error("Validation failed but no issues detected.");
2124
+ }
2125
+ return {
2126
+ success: false,
2127
+ get error() {
2128
+ if (this._error)
2129
+ return this._error;
2130
+ const error = new ZodError(ctx.common.issues);
2131
+ this._error = error;
2132
+ return this._error;
2133
+ }
2134
+ };
2135
+ }
2136
+ };
2137
+ function processCreateParams(params) {
2138
+ if (!params)
2139
+ return {};
2140
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
2141
+ if (errorMap2 && (invalid_type_error || required_error)) {
2142
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
2143
+ }
2144
+ if (errorMap2)
2145
+ return { errorMap: errorMap2, description };
2146
+ const customMap = (iss, ctx) => {
2147
+ if (iss.code !== "invalid_type")
2148
+ return { message: ctx.defaultError };
2149
+ if (typeof ctx.data === "undefined") {
2150
+ return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
2151
+ }
2152
+ return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
2153
+ };
2154
+ return { errorMap: customMap, description };
2155
+ }
2156
+ var ZodType = class {
2157
+ constructor(def) {
2158
+ this.spa = this.safeParseAsync;
2159
+ this._def = def;
2160
+ this.parse = this.parse.bind(this);
2161
+ this.safeParse = this.safeParse.bind(this);
2162
+ this.parseAsync = this.parseAsync.bind(this);
2163
+ this.safeParseAsync = this.safeParseAsync.bind(this);
2164
+ this.spa = this.spa.bind(this);
2165
+ this.refine = this.refine.bind(this);
2166
+ this.refinement = this.refinement.bind(this);
2167
+ this.superRefine = this.superRefine.bind(this);
2168
+ this.optional = this.optional.bind(this);
2169
+ this.nullable = this.nullable.bind(this);
2170
+ this.nullish = this.nullish.bind(this);
2171
+ this.array = this.array.bind(this);
2172
+ this.promise = this.promise.bind(this);
2173
+ this.or = this.or.bind(this);
2174
+ this.and = this.and.bind(this);
2175
+ this.transform = this.transform.bind(this);
2176
+ this.brand = this.brand.bind(this);
2177
+ this.default = this.default.bind(this);
2178
+ this.catch = this.catch.bind(this);
2179
+ this.describe = this.describe.bind(this);
2180
+ this.pipe = this.pipe.bind(this);
2181
+ this.readonly = this.readonly.bind(this);
2182
+ this.isNullable = this.isNullable.bind(this);
2183
+ this.isOptional = this.isOptional.bind(this);
2184
+ }
2185
+ get description() {
2186
+ return this._def.description;
2187
+ }
2188
+ _getType(input) {
2189
+ return getParsedType(input.data);
2190
+ }
2191
+ _getOrReturnCtx(input, ctx) {
2192
+ return ctx || {
2193
+ common: input.parent.common,
2194
+ data: input.data,
2195
+ parsedType: getParsedType(input.data),
2196
+ schemaErrorMap: this._def.errorMap,
2197
+ path: input.path,
2198
+ parent: input.parent
2199
+ };
2200
+ }
2201
+ _processInputParams(input) {
2202
+ return {
2203
+ status: new ParseStatus(),
2204
+ ctx: {
2205
+ common: input.parent.common,
2206
+ data: input.data,
2207
+ parsedType: getParsedType(input.data),
2208
+ schemaErrorMap: this._def.errorMap,
2209
+ path: input.path,
2210
+ parent: input.parent
2211
+ }
2212
+ };
2213
+ }
2214
+ _parseSync(input) {
2215
+ const result = this._parse(input);
2216
+ if (isAsync(result)) {
2217
+ throw new Error("Synchronous parse encountered promise.");
2218
+ }
2219
+ return result;
2220
+ }
2221
+ _parseAsync(input) {
2222
+ const result = this._parse(input);
2223
+ return Promise.resolve(result);
2224
+ }
2225
+ parse(data, params) {
2226
+ const result = this.safeParse(data, params);
2227
+ if (result.success)
2228
+ return result.data;
2229
+ throw result.error;
2230
+ }
2231
+ safeParse(data, params) {
2232
+ var _a;
2233
+ const ctx = {
2234
+ common: {
2235
+ issues: [],
2236
+ async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
2237
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
2238
+ },
2239
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
2240
+ schemaErrorMap: this._def.errorMap,
2241
+ parent: null,
2242
+ data,
2243
+ parsedType: getParsedType(data)
2244
+ };
2245
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
2246
+ return handleResult(ctx, result);
2247
+ }
2248
+ async parseAsync(data, params) {
2249
+ const result = await this.safeParseAsync(data, params);
2250
+ if (result.success)
2251
+ return result.data;
2252
+ throw result.error;
2253
+ }
2254
+ async safeParseAsync(data, params) {
2255
+ const ctx = {
2256
+ common: {
2257
+ issues: [],
2258
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
2259
+ async: true
2260
+ },
2261
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
2262
+ schemaErrorMap: this._def.errorMap,
2263
+ parent: null,
2264
+ data,
2265
+ parsedType: getParsedType(data)
2266
+ };
2267
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
2268
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
2269
+ return handleResult(ctx, result);
2270
+ }
2271
+ refine(check, message) {
2272
+ const getIssueProperties = (val) => {
2273
+ if (typeof message === "string" || typeof message === "undefined") {
2274
+ return { message };
2275
+ } else if (typeof message === "function") {
2276
+ return message(val);
2277
+ } else {
2278
+ return message;
2279
+ }
2280
+ };
2281
+ return this._refinement((val, ctx) => {
2282
+ const result = check(val);
2283
+ const setError = () => ctx.addIssue({
2284
+ code: ZodIssueCode.custom,
2285
+ ...getIssueProperties(val)
2286
+ });
2287
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
2288
+ return result.then((data) => {
2289
+ if (!data) {
2290
+ setError();
2291
+ return false;
2292
+ } else {
2293
+ return true;
2294
+ }
2295
+ });
2296
+ }
2297
+ if (!result) {
2298
+ setError();
2299
+ return false;
2300
+ } else {
2301
+ return true;
2302
+ }
2303
+ });
2304
+ }
2305
+ refinement(check, refinementData) {
2306
+ return this._refinement((val, ctx) => {
2307
+ if (!check(val)) {
2308
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
2309
+ return false;
2310
+ } else {
2311
+ return true;
2312
+ }
2313
+ });
2314
+ }
2315
+ _refinement(refinement) {
2316
+ return new ZodEffects({
2317
+ schema: this,
2318
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2319
+ effect: { type: "refinement", refinement }
2320
+ });
2321
+ }
2322
+ superRefine(refinement) {
2323
+ return this._refinement(refinement);
2324
+ }
2325
+ optional() {
2326
+ return ZodOptional.create(this, this._def);
2327
+ }
2328
+ nullable() {
2329
+ return ZodNullable.create(this, this._def);
2330
+ }
2331
+ nullish() {
2332
+ return this.nullable().optional();
2333
+ }
2334
+ array() {
2335
+ return ZodArray.create(this, this._def);
2336
+ }
2337
+ promise() {
2338
+ return ZodPromise.create(this, this._def);
2339
+ }
2340
+ or(option) {
2341
+ return ZodUnion.create([this, option], this._def);
2342
+ }
2343
+ and(incoming) {
2344
+ return ZodIntersection.create(this, incoming, this._def);
2345
+ }
2346
+ transform(transform) {
2347
+ return new ZodEffects({
2348
+ ...processCreateParams(this._def),
2349
+ schema: this,
2350
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2351
+ effect: { type: "transform", transform }
2352
+ });
2353
+ }
2354
+ default(def) {
2355
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
2356
+ return new ZodDefault({
2357
+ ...processCreateParams(this._def),
2358
+ innerType: this,
2359
+ defaultValue: defaultValueFunc,
2360
+ typeName: ZodFirstPartyTypeKind.ZodDefault
2361
+ });
2362
+ }
2363
+ brand() {
2364
+ return new ZodBranded({
2365
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
2366
+ type: this,
2367
+ ...processCreateParams(this._def)
2368
+ });
2369
+ }
2370
+ catch(def) {
2371
+ const catchValueFunc = typeof def === "function" ? def : () => def;
2372
+ return new ZodCatch({
2373
+ ...processCreateParams(this._def),
2374
+ innerType: this,
2375
+ catchValue: catchValueFunc,
2376
+ typeName: ZodFirstPartyTypeKind.ZodCatch
2377
+ });
2378
+ }
2379
+ describe(description) {
2380
+ const This = this.constructor;
2381
+ return new This({
2382
+ ...this._def,
2383
+ description
2384
+ });
2385
+ }
2386
+ pipe(target) {
2387
+ return ZodPipeline.create(this, target);
2388
+ }
2389
+ readonly() {
2390
+ return ZodReadonly.create(this);
2391
+ }
2392
+ isOptional() {
2393
+ return this.safeParse(void 0).success;
2394
+ }
2395
+ isNullable() {
2396
+ return this.safeParse(null).success;
2397
+ }
2398
+ };
2399
+ var cuidRegex = /^c[^\s-]{8,}$/i;
2400
+ var cuid2Regex = /^[a-z][a-z0-9]*$/;
2401
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
2402
+ var 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;
2403
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
2404
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
2405
+ var emojiRegex;
2406
+ var 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}))$/;
2407
+ var 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})))$/;
2408
+ var datetimeRegex = (args) => {
2409
+ if (args.precision) {
2410
+ if (args.offset) {
2411
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
2412
+ } else {
2413
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
2414
+ }
2415
+ } else if (args.precision === 0) {
2416
+ if (args.offset) {
2417
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
2418
+ } else {
2419
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
2420
+ }
2421
+ } else {
2422
+ if (args.offset) {
2423
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
2424
+ } else {
2425
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
2426
+ }
2427
+ }
2428
+ };
2429
+ function isValidIP(ip, version) {
2430
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
2431
+ return true;
2432
+ }
2433
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
2434
+ return true;
2435
+ }
2436
+ return false;
2437
+ }
2438
+ var ZodString = class _ZodString extends ZodType {
2439
+ _parse(input) {
2440
+ if (this._def.coerce) {
2441
+ input.data = String(input.data);
2442
+ }
2443
+ const parsedType = this._getType(input);
2444
+ if (parsedType !== ZodParsedType.string) {
2445
+ const ctx2 = this._getOrReturnCtx(input);
2446
+ addIssueToContext(
2447
+ ctx2,
2448
+ {
2449
+ code: ZodIssueCode.invalid_type,
2450
+ expected: ZodParsedType.string,
2451
+ received: ctx2.parsedType
2452
+ }
2453
+ //
2454
+ );
2455
+ return INVALID;
2456
+ }
2457
+ const status = new ParseStatus();
2458
+ let ctx = void 0;
2459
+ for (const check of this._def.checks) {
2460
+ if (check.kind === "min") {
2461
+ if (input.data.length < check.value) {
2462
+ ctx = this._getOrReturnCtx(input, ctx);
2463
+ addIssueToContext(ctx, {
2464
+ code: ZodIssueCode.too_small,
2465
+ minimum: check.value,
2466
+ type: "string",
2467
+ inclusive: true,
2468
+ exact: false,
2469
+ message: check.message
2470
+ });
2471
+ status.dirty();
2472
+ }
2473
+ } else if (check.kind === "max") {
2474
+ if (input.data.length > check.value) {
2475
+ ctx = this._getOrReturnCtx(input, ctx);
2476
+ addIssueToContext(ctx, {
2477
+ code: ZodIssueCode.too_big,
2478
+ maximum: check.value,
2479
+ type: "string",
2480
+ inclusive: true,
2481
+ exact: false,
2482
+ message: check.message
2483
+ });
2484
+ status.dirty();
2485
+ }
2486
+ } else if (check.kind === "length") {
2487
+ const tooBig = input.data.length > check.value;
2488
+ const tooSmall = input.data.length < check.value;
2489
+ if (tooBig || tooSmall) {
2490
+ ctx = this._getOrReturnCtx(input, ctx);
2491
+ if (tooBig) {
2492
+ addIssueToContext(ctx, {
2493
+ code: ZodIssueCode.too_big,
2494
+ maximum: check.value,
2495
+ type: "string",
2496
+ inclusive: true,
2497
+ exact: true,
2498
+ message: check.message
2499
+ });
2500
+ } else if (tooSmall) {
2501
+ addIssueToContext(ctx, {
2502
+ code: ZodIssueCode.too_small,
2503
+ minimum: check.value,
2504
+ type: "string",
2505
+ inclusive: true,
2506
+ exact: true,
2507
+ message: check.message
2508
+ });
2509
+ }
2510
+ status.dirty();
2511
+ }
2512
+ } else if (check.kind === "email") {
2513
+ if (!emailRegex.test(input.data)) {
2514
+ ctx = this._getOrReturnCtx(input, ctx);
2515
+ addIssueToContext(ctx, {
2516
+ validation: "email",
2517
+ code: ZodIssueCode.invalid_string,
2518
+ message: check.message
2519
+ });
2520
+ status.dirty();
2521
+ }
2522
+ } else if (check.kind === "emoji") {
2523
+ if (!emojiRegex) {
2524
+ emojiRegex = new RegExp(_emojiRegex, "u");
2525
+ }
2526
+ if (!emojiRegex.test(input.data)) {
2527
+ ctx = this._getOrReturnCtx(input, ctx);
2528
+ addIssueToContext(ctx, {
2529
+ validation: "emoji",
2530
+ code: ZodIssueCode.invalid_string,
2531
+ message: check.message
2532
+ });
2533
+ status.dirty();
2534
+ }
2535
+ } else if (check.kind === "uuid") {
2536
+ if (!uuidRegex.test(input.data)) {
2537
+ ctx = this._getOrReturnCtx(input, ctx);
2538
+ addIssueToContext(ctx, {
2539
+ validation: "uuid",
2540
+ code: ZodIssueCode.invalid_string,
2541
+ message: check.message
2542
+ });
2543
+ status.dirty();
2544
+ }
2545
+ } else if (check.kind === "cuid") {
2546
+ if (!cuidRegex.test(input.data)) {
2547
+ ctx = this._getOrReturnCtx(input, ctx);
2548
+ addIssueToContext(ctx, {
2549
+ validation: "cuid",
2550
+ code: ZodIssueCode.invalid_string,
2551
+ message: check.message
2552
+ });
2553
+ status.dirty();
2554
+ }
2555
+ } else if (check.kind === "cuid2") {
2556
+ if (!cuid2Regex.test(input.data)) {
2557
+ ctx = this._getOrReturnCtx(input, ctx);
2558
+ addIssueToContext(ctx, {
2559
+ validation: "cuid2",
2560
+ code: ZodIssueCode.invalid_string,
2561
+ message: check.message
2562
+ });
2563
+ status.dirty();
2564
+ }
2565
+ } else if (check.kind === "ulid") {
2566
+ if (!ulidRegex.test(input.data)) {
2567
+ ctx = this._getOrReturnCtx(input, ctx);
2568
+ addIssueToContext(ctx, {
2569
+ validation: "ulid",
2570
+ code: ZodIssueCode.invalid_string,
2571
+ message: check.message
2572
+ });
2573
+ status.dirty();
2574
+ }
2575
+ } else if (check.kind === "url") {
2576
+ try {
2577
+ new URL(input.data);
2578
+ } catch (_a) {
2579
+ ctx = this._getOrReturnCtx(input, ctx);
2580
+ addIssueToContext(ctx, {
2581
+ validation: "url",
2582
+ code: ZodIssueCode.invalid_string,
2583
+ message: check.message
2584
+ });
2585
+ status.dirty();
2586
+ }
2587
+ } else if (check.kind === "regex") {
2588
+ check.regex.lastIndex = 0;
2589
+ const testResult = check.regex.test(input.data);
2590
+ if (!testResult) {
2591
+ ctx = this._getOrReturnCtx(input, ctx);
2592
+ addIssueToContext(ctx, {
2593
+ validation: "regex",
2594
+ code: ZodIssueCode.invalid_string,
2595
+ message: check.message
2596
+ });
2597
+ status.dirty();
2598
+ }
2599
+ } else if (check.kind === "trim") {
2600
+ input.data = input.data.trim();
2601
+ } else if (check.kind === "includes") {
2602
+ if (!input.data.includes(check.value, check.position)) {
2603
+ ctx = this._getOrReturnCtx(input, ctx);
2604
+ addIssueToContext(ctx, {
2605
+ code: ZodIssueCode.invalid_string,
2606
+ validation: { includes: check.value, position: check.position },
2607
+ message: check.message
2608
+ });
2609
+ status.dirty();
2610
+ }
2611
+ } else if (check.kind === "toLowerCase") {
2612
+ input.data = input.data.toLowerCase();
2613
+ } else if (check.kind === "toUpperCase") {
2614
+ input.data = input.data.toUpperCase();
2615
+ } else if (check.kind === "startsWith") {
2616
+ if (!input.data.startsWith(check.value)) {
2617
+ ctx = this._getOrReturnCtx(input, ctx);
2618
+ addIssueToContext(ctx, {
2619
+ code: ZodIssueCode.invalid_string,
2620
+ validation: { startsWith: check.value },
2621
+ message: check.message
2622
+ });
2623
+ status.dirty();
2624
+ }
2625
+ } else if (check.kind === "endsWith") {
2626
+ if (!input.data.endsWith(check.value)) {
2627
+ ctx = this._getOrReturnCtx(input, ctx);
2628
+ addIssueToContext(ctx, {
2629
+ code: ZodIssueCode.invalid_string,
2630
+ validation: { endsWith: check.value },
2631
+ message: check.message
2632
+ });
2633
+ status.dirty();
2634
+ }
2635
+ } else if (check.kind === "datetime") {
2636
+ const regex = datetimeRegex(check);
2637
+ if (!regex.test(input.data)) {
2638
+ ctx = this._getOrReturnCtx(input, ctx);
2639
+ addIssueToContext(ctx, {
2640
+ code: ZodIssueCode.invalid_string,
2641
+ validation: "datetime",
2642
+ message: check.message
2643
+ });
2644
+ status.dirty();
2645
+ }
2646
+ } else if (check.kind === "ip") {
2647
+ if (!isValidIP(input.data, check.version)) {
2648
+ ctx = this._getOrReturnCtx(input, ctx);
2649
+ addIssueToContext(ctx, {
2650
+ validation: "ip",
2651
+ code: ZodIssueCode.invalid_string,
2652
+ message: check.message
2653
+ });
2654
+ status.dirty();
2655
+ }
2656
+ } else {
2657
+ util.assertNever(check);
2658
+ }
2659
+ }
2660
+ return { status: status.value, value: input.data };
2661
+ }
2662
+ _regex(regex, validation, message) {
2663
+ return this.refinement((data) => regex.test(data), {
2664
+ validation,
2665
+ code: ZodIssueCode.invalid_string,
2666
+ ...errorUtil.errToObj(message)
2667
+ });
2668
+ }
2669
+ _addCheck(check) {
2670
+ return new _ZodString({
2671
+ ...this._def,
2672
+ checks: [...this._def.checks, check]
2673
+ });
2674
+ }
2675
+ email(message) {
2676
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
2677
+ }
2678
+ url(message) {
2679
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
2680
+ }
2681
+ emoji(message) {
2682
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
2683
+ }
2684
+ uuid(message) {
2685
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
2686
+ }
2687
+ cuid(message) {
2688
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
2689
+ }
2690
+ cuid2(message) {
2691
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
2692
+ }
2693
+ ulid(message) {
2694
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
2695
+ }
2696
+ ip(options) {
2697
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
2698
+ }
2699
+ datetime(options) {
2700
+ var _a;
2701
+ if (typeof options === "string") {
2702
+ return this._addCheck({
2703
+ kind: "datetime",
2704
+ precision: null,
2705
+ offset: false,
2706
+ message: options
2707
+ });
2708
+ }
2709
+ return this._addCheck({
2710
+ kind: "datetime",
2711
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
2712
+ offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
2713
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
2714
+ });
2715
+ }
2716
+ regex(regex, message) {
2717
+ return this._addCheck({
2718
+ kind: "regex",
2719
+ regex,
2720
+ ...errorUtil.errToObj(message)
2721
+ });
2722
+ }
2723
+ includes(value, options) {
2724
+ return this._addCheck({
2725
+ kind: "includes",
2726
+ value,
2727
+ position: options === null || options === void 0 ? void 0 : options.position,
2728
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
2729
+ });
2730
+ }
2731
+ startsWith(value, message) {
2732
+ return this._addCheck({
2733
+ kind: "startsWith",
2734
+ value,
2735
+ ...errorUtil.errToObj(message)
2736
+ });
2737
+ }
2738
+ endsWith(value, message) {
2739
+ return this._addCheck({
2740
+ kind: "endsWith",
2741
+ value,
2742
+ ...errorUtil.errToObj(message)
2743
+ });
2744
+ }
2745
+ min(minLength, message) {
2746
+ return this._addCheck({
2747
+ kind: "min",
2748
+ value: minLength,
2749
+ ...errorUtil.errToObj(message)
2750
+ });
2751
+ }
2752
+ max(maxLength, message) {
2753
+ return this._addCheck({
2754
+ kind: "max",
2755
+ value: maxLength,
2756
+ ...errorUtil.errToObj(message)
2757
+ });
2758
+ }
2759
+ length(len, message) {
2760
+ return this._addCheck({
2761
+ kind: "length",
2762
+ value: len,
2763
+ ...errorUtil.errToObj(message)
2764
+ });
2765
+ }
2766
+ /**
2767
+ * @deprecated Use z.string().min(1) instead.
2768
+ * @see {@link ZodString.min}
2769
+ */
2770
+ nonempty(message) {
2771
+ return this.min(1, errorUtil.errToObj(message));
2772
+ }
2773
+ trim() {
2774
+ return new _ZodString({
2775
+ ...this._def,
2776
+ checks: [...this._def.checks, { kind: "trim" }]
2777
+ });
2778
+ }
2779
+ toLowerCase() {
2780
+ return new _ZodString({
2781
+ ...this._def,
2782
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
2783
+ });
2784
+ }
2785
+ toUpperCase() {
2786
+ return new _ZodString({
2787
+ ...this._def,
2788
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
2789
+ });
2790
+ }
2791
+ get isDatetime() {
2792
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
2793
+ }
2794
+ get isEmail() {
2795
+ return !!this._def.checks.find((ch) => ch.kind === "email");
2796
+ }
2797
+ get isURL() {
2798
+ return !!this._def.checks.find((ch) => ch.kind === "url");
2799
+ }
2800
+ get isEmoji() {
2801
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
2802
+ }
2803
+ get isUUID() {
2804
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
2805
+ }
2806
+ get isCUID() {
2807
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
2808
+ }
2809
+ get isCUID2() {
2810
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
2811
+ }
2812
+ get isULID() {
2813
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
2814
+ }
2815
+ get isIP() {
2816
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
2817
+ }
2818
+ get minLength() {
2819
+ let min = null;
2820
+ for (const ch of this._def.checks) {
2821
+ if (ch.kind === "min") {
2822
+ if (min === null || ch.value > min)
2823
+ min = ch.value;
2824
+ }
2825
+ }
2826
+ return min;
2827
+ }
2828
+ get maxLength() {
2829
+ let max = null;
2830
+ for (const ch of this._def.checks) {
2831
+ if (ch.kind === "max") {
2832
+ if (max === null || ch.value < max)
2833
+ max = ch.value;
2834
+ }
2835
+ }
2836
+ return max;
2837
+ }
2838
+ };
2839
+ ZodString.create = (params) => {
2840
+ var _a;
2841
+ return new ZodString({
2842
+ checks: [],
2843
+ typeName: ZodFirstPartyTypeKind.ZodString,
2844
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
2845
+ ...processCreateParams(params)
2846
+ });
2847
+ };
2848
+ function floatSafeRemainder(val, step) {
2849
+ const valDecCount = (val.toString().split(".")[1] || "").length;
2850
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
2851
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
2852
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
2853
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
2854
+ return valInt % stepInt / Math.pow(10, decCount);
2855
+ }
2856
+ var ZodNumber = class _ZodNumber extends ZodType {
2857
+ constructor() {
2858
+ super(...arguments);
2859
+ this.min = this.gte;
2860
+ this.max = this.lte;
2861
+ this.step = this.multipleOf;
2862
+ }
2863
+ _parse(input) {
2864
+ if (this._def.coerce) {
2865
+ input.data = Number(input.data);
2866
+ }
2867
+ const parsedType = this._getType(input);
2868
+ if (parsedType !== ZodParsedType.number) {
2869
+ const ctx2 = this._getOrReturnCtx(input);
2870
+ addIssueToContext(ctx2, {
2871
+ code: ZodIssueCode.invalid_type,
2872
+ expected: ZodParsedType.number,
2873
+ received: ctx2.parsedType
2874
+ });
2875
+ return INVALID;
2876
+ }
2877
+ let ctx = void 0;
2878
+ const status = new ParseStatus();
2879
+ for (const check of this._def.checks) {
2880
+ if (check.kind === "int") {
2881
+ if (!util.isInteger(input.data)) {
2882
+ ctx = this._getOrReturnCtx(input, ctx);
2883
+ addIssueToContext(ctx, {
2884
+ code: ZodIssueCode.invalid_type,
2885
+ expected: "integer",
2886
+ received: "float",
2887
+ message: check.message
2888
+ });
2889
+ status.dirty();
2890
+ }
2891
+ } else if (check.kind === "min") {
2892
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2893
+ if (tooSmall) {
2894
+ ctx = this._getOrReturnCtx(input, ctx);
2895
+ addIssueToContext(ctx, {
2896
+ code: ZodIssueCode.too_small,
2897
+ minimum: check.value,
2898
+ type: "number",
2899
+ inclusive: check.inclusive,
2900
+ exact: false,
2901
+ message: check.message
2902
+ });
2903
+ status.dirty();
2904
+ }
2905
+ } else if (check.kind === "max") {
2906
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2907
+ if (tooBig) {
2908
+ ctx = this._getOrReturnCtx(input, ctx);
2909
+ addIssueToContext(ctx, {
2910
+ code: ZodIssueCode.too_big,
2911
+ maximum: check.value,
2912
+ type: "number",
2913
+ inclusive: check.inclusive,
2914
+ exact: false,
2915
+ message: check.message
2916
+ });
2917
+ status.dirty();
2918
+ }
2919
+ } else if (check.kind === "multipleOf") {
2920
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
2921
+ ctx = this._getOrReturnCtx(input, ctx);
2922
+ addIssueToContext(ctx, {
2923
+ code: ZodIssueCode.not_multiple_of,
2924
+ multipleOf: check.value,
2925
+ message: check.message
2926
+ });
2927
+ status.dirty();
2928
+ }
2929
+ } else if (check.kind === "finite") {
2930
+ if (!Number.isFinite(input.data)) {
2931
+ ctx = this._getOrReturnCtx(input, ctx);
2932
+ addIssueToContext(ctx, {
2933
+ code: ZodIssueCode.not_finite,
2934
+ message: check.message
2935
+ });
2936
+ status.dirty();
2937
+ }
2938
+ } else {
2939
+ util.assertNever(check);
2940
+ }
2941
+ }
2942
+ return { status: status.value, value: input.data };
2943
+ }
2944
+ gte(value, message) {
2945
+ return this.setLimit("min", value, true, errorUtil.toString(message));
2946
+ }
2947
+ gt(value, message) {
2948
+ return this.setLimit("min", value, false, errorUtil.toString(message));
2949
+ }
2950
+ lte(value, message) {
2951
+ return this.setLimit("max", value, true, errorUtil.toString(message));
2952
+ }
2953
+ lt(value, message) {
2954
+ return this.setLimit("max", value, false, errorUtil.toString(message));
2955
+ }
2956
+ setLimit(kind, value, inclusive, message) {
2957
+ return new _ZodNumber({
2958
+ ...this._def,
2959
+ checks: [
2960
+ ...this._def.checks,
2961
+ {
2962
+ kind,
2963
+ value,
2964
+ inclusive,
2965
+ message: errorUtil.toString(message)
2966
+ }
2967
+ ]
2968
+ });
2969
+ }
2970
+ _addCheck(check) {
2971
+ return new _ZodNumber({
2972
+ ...this._def,
2973
+ checks: [...this._def.checks, check]
2974
+ });
2975
+ }
2976
+ int(message) {
2977
+ return this._addCheck({
2978
+ kind: "int",
2979
+ message: errorUtil.toString(message)
2980
+ });
2981
+ }
2982
+ positive(message) {
2983
+ return this._addCheck({
2984
+ kind: "min",
2985
+ value: 0,
2986
+ inclusive: false,
2987
+ message: errorUtil.toString(message)
2988
+ });
2989
+ }
2990
+ negative(message) {
2991
+ return this._addCheck({
2992
+ kind: "max",
2993
+ value: 0,
2994
+ inclusive: false,
2995
+ message: errorUtil.toString(message)
2996
+ });
2997
+ }
2998
+ nonpositive(message) {
2999
+ return this._addCheck({
3000
+ kind: "max",
3001
+ value: 0,
3002
+ inclusive: true,
3003
+ message: errorUtil.toString(message)
3004
+ });
3005
+ }
3006
+ nonnegative(message) {
3007
+ return this._addCheck({
3008
+ kind: "min",
3009
+ value: 0,
3010
+ inclusive: true,
3011
+ message: errorUtil.toString(message)
3012
+ });
3013
+ }
3014
+ multipleOf(value, message) {
3015
+ return this._addCheck({
3016
+ kind: "multipleOf",
3017
+ value,
3018
+ message: errorUtil.toString(message)
3019
+ });
3020
+ }
3021
+ finite(message) {
3022
+ return this._addCheck({
3023
+ kind: "finite",
3024
+ message: errorUtil.toString(message)
3025
+ });
3026
+ }
3027
+ safe(message) {
3028
+ return this._addCheck({
3029
+ kind: "min",
3030
+ inclusive: true,
3031
+ value: Number.MIN_SAFE_INTEGER,
3032
+ message: errorUtil.toString(message)
3033
+ })._addCheck({
3034
+ kind: "max",
3035
+ inclusive: true,
3036
+ value: Number.MAX_SAFE_INTEGER,
3037
+ message: errorUtil.toString(message)
3038
+ });
3039
+ }
3040
+ get minValue() {
3041
+ let min = null;
3042
+ for (const ch of this._def.checks) {
3043
+ if (ch.kind === "min") {
3044
+ if (min === null || ch.value > min)
3045
+ min = ch.value;
3046
+ }
3047
+ }
3048
+ return min;
3049
+ }
3050
+ get maxValue() {
3051
+ let max = null;
3052
+ for (const ch of this._def.checks) {
3053
+ if (ch.kind === "max") {
3054
+ if (max === null || ch.value < max)
3055
+ max = ch.value;
3056
+ }
3057
+ }
3058
+ return max;
3059
+ }
3060
+ get isInt() {
3061
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
3062
+ }
3063
+ get isFinite() {
3064
+ let max = null, min = null;
3065
+ for (const ch of this._def.checks) {
3066
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
3067
+ return true;
3068
+ } else if (ch.kind === "min") {
3069
+ if (min === null || ch.value > min)
3070
+ min = ch.value;
3071
+ } else if (ch.kind === "max") {
3072
+ if (max === null || ch.value < max)
3073
+ max = ch.value;
3074
+ }
3075
+ }
3076
+ return Number.isFinite(min) && Number.isFinite(max);
3077
+ }
3078
+ };
3079
+ ZodNumber.create = (params) => {
3080
+ return new ZodNumber({
3081
+ checks: [],
3082
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
3083
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
3084
+ ...processCreateParams(params)
3085
+ });
3086
+ };
3087
+ var ZodBigInt = class _ZodBigInt extends ZodType {
3088
+ constructor() {
3089
+ super(...arguments);
3090
+ this.min = this.gte;
3091
+ this.max = this.lte;
3092
+ }
3093
+ _parse(input) {
3094
+ if (this._def.coerce) {
3095
+ input.data = BigInt(input.data);
3096
+ }
3097
+ const parsedType = this._getType(input);
3098
+ if (parsedType !== ZodParsedType.bigint) {
3099
+ const ctx2 = this._getOrReturnCtx(input);
3100
+ addIssueToContext(ctx2, {
3101
+ code: ZodIssueCode.invalid_type,
3102
+ expected: ZodParsedType.bigint,
3103
+ received: ctx2.parsedType
3104
+ });
3105
+ return INVALID;
3106
+ }
3107
+ let ctx = void 0;
3108
+ const status = new ParseStatus();
3109
+ for (const check of this._def.checks) {
3110
+ if (check.kind === "min") {
3111
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
3112
+ if (tooSmall) {
3113
+ ctx = this._getOrReturnCtx(input, ctx);
3114
+ addIssueToContext(ctx, {
3115
+ code: ZodIssueCode.too_small,
3116
+ type: "bigint",
3117
+ minimum: check.value,
3118
+ inclusive: check.inclusive,
3119
+ message: check.message
3120
+ });
3121
+ status.dirty();
3122
+ }
3123
+ } else if (check.kind === "max") {
3124
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
3125
+ if (tooBig) {
3126
+ ctx = this._getOrReturnCtx(input, ctx);
3127
+ addIssueToContext(ctx, {
3128
+ code: ZodIssueCode.too_big,
3129
+ type: "bigint",
3130
+ maximum: check.value,
3131
+ inclusive: check.inclusive,
3132
+ message: check.message
3133
+ });
3134
+ status.dirty();
3135
+ }
3136
+ } else if (check.kind === "multipleOf") {
3137
+ if (input.data % check.value !== BigInt(0)) {
3138
+ ctx = this._getOrReturnCtx(input, ctx);
3139
+ addIssueToContext(ctx, {
3140
+ code: ZodIssueCode.not_multiple_of,
3141
+ multipleOf: check.value,
3142
+ message: check.message
3143
+ });
3144
+ status.dirty();
3145
+ }
3146
+ } else {
3147
+ util.assertNever(check);
3148
+ }
3149
+ }
3150
+ return { status: status.value, value: input.data };
3151
+ }
3152
+ gte(value, message) {
3153
+ return this.setLimit("min", value, true, errorUtil.toString(message));
3154
+ }
3155
+ gt(value, message) {
3156
+ return this.setLimit("min", value, false, errorUtil.toString(message));
3157
+ }
3158
+ lte(value, message) {
3159
+ return this.setLimit("max", value, true, errorUtil.toString(message));
3160
+ }
3161
+ lt(value, message) {
3162
+ return this.setLimit("max", value, false, errorUtil.toString(message));
3163
+ }
3164
+ setLimit(kind, value, inclusive, message) {
3165
+ return new _ZodBigInt({
3166
+ ...this._def,
3167
+ checks: [
3168
+ ...this._def.checks,
3169
+ {
3170
+ kind,
3171
+ value,
3172
+ inclusive,
3173
+ message: errorUtil.toString(message)
3174
+ }
3175
+ ]
3176
+ });
3177
+ }
3178
+ _addCheck(check) {
3179
+ return new _ZodBigInt({
3180
+ ...this._def,
3181
+ checks: [...this._def.checks, check]
3182
+ });
3183
+ }
3184
+ positive(message) {
3185
+ return this._addCheck({
3186
+ kind: "min",
3187
+ value: BigInt(0),
3188
+ inclusive: false,
3189
+ message: errorUtil.toString(message)
3190
+ });
3191
+ }
3192
+ negative(message) {
3193
+ return this._addCheck({
3194
+ kind: "max",
3195
+ value: BigInt(0),
3196
+ inclusive: false,
3197
+ message: errorUtil.toString(message)
3198
+ });
3199
+ }
3200
+ nonpositive(message) {
3201
+ return this._addCheck({
3202
+ kind: "max",
3203
+ value: BigInt(0),
3204
+ inclusive: true,
3205
+ message: errorUtil.toString(message)
3206
+ });
3207
+ }
3208
+ nonnegative(message) {
3209
+ return this._addCheck({
3210
+ kind: "min",
3211
+ value: BigInt(0),
3212
+ inclusive: true,
3213
+ message: errorUtil.toString(message)
3214
+ });
3215
+ }
3216
+ multipleOf(value, message) {
3217
+ return this._addCheck({
3218
+ kind: "multipleOf",
3219
+ value,
3220
+ message: errorUtil.toString(message)
3221
+ });
3222
+ }
3223
+ get minValue() {
3224
+ let min = null;
3225
+ for (const ch of this._def.checks) {
3226
+ if (ch.kind === "min") {
3227
+ if (min === null || ch.value > min)
3228
+ min = ch.value;
3229
+ }
3230
+ }
3231
+ return min;
3232
+ }
3233
+ get maxValue() {
3234
+ let max = null;
3235
+ for (const ch of this._def.checks) {
3236
+ if (ch.kind === "max") {
3237
+ if (max === null || ch.value < max)
3238
+ max = ch.value;
3239
+ }
3240
+ }
3241
+ return max;
3242
+ }
3243
+ };
3244
+ ZodBigInt.create = (params) => {
3245
+ var _a;
3246
+ return new ZodBigInt({
3247
+ checks: [],
3248
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
3249
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
3250
+ ...processCreateParams(params)
3251
+ });
3252
+ };
3253
+ var ZodBoolean = class extends ZodType {
3254
+ _parse(input) {
3255
+ if (this._def.coerce) {
3256
+ input.data = Boolean(input.data);
3257
+ }
3258
+ const parsedType = this._getType(input);
3259
+ if (parsedType !== ZodParsedType.boolean) {
3260
+ const ctx = this._getOrReturnCtx(input);
3261
+ addIssueToContext(ctx, {
3262
+ code: ZodIssueCode.invalid_type,
3263
+ expected: ZodParsedType.boolean,
3264
+ received: ctx.parsedType
3265
+ });
3266
+ return INVALID;
3267
+ }
3268
+ return OK(input.data);
3269
+ }
3270
+ };
3271
+ ZodBoolean.create = (params) => {
3272
+ return new ZodBoolean({
3273
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
3274
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
3275
+ ...processCreateParams(params)
3276
+ });
3277
+ };
3278
+ var ZodDate = class _ZodDate extends ZodType {
3279
+ _parse(input) {
3280
+ if (this._def.coerce) {
3281
+ input.data = new Date(input.data);
3282
+ }
3283
+ const parsedType = this._getType(input);
3284
+ if (parsedType !== ZodParsedType.date) {
3285
+ const ctx2 = this._getOrReturnCtx(input);
3286
+ addIssueToContext(ctx2, {
3287
+ code: ZodIssueCode.invalid_type,
3288
+ expected: ZodParsedType.date,
3289
+ received: ctx2.parsedType
3290
+ });
3291
+ return INVALID;
3292
+ }
3293
+ if (isNaN(input.data.getTime())) {
3294
+ const ctx2 = this._getOrReturnCtx(input);
3295
+ addIssueToContext(ctx2, {
3296
+ code: ZodIssueCode.invalid_date
3297
+ });
3298
+ return INVALID;
3299
+ }
3300
+ const status = new ParseStatus();
3301
+ let ctx = void 0;
3302
+ for (const check of this._def.checks) {
3303
+ if (check.kind === "min") {
3304
+ if (input.data.getTime() < check.value) {
3305
+ ctx = this._getOrReturnCtx(input, ctx);
3306
+ addIssueToContext(ctx, {
3307
+ code: ZodIssueCode.too_small,
3308
+ message: check.message,
3309
+ inclusive: true,
3310
+ exact: false,
3311
+ minimum: check.value,
3312
+ type: "date"
3313
+ });
3314
+ status.dirty();
3315
+ }
3316
+ } else if (check.kind === "max") {
3317
+ if (input.data.getTime() > check.value) {
3318
+ ctx = this._getOrReturnCtx(input, ctx);
3319
+ addIssueToContext(ctx, {
3320
+ code: ZodIssueCode.too_big,
3321
+ message: check.message,
3322
+ inclusive: true,
3323
+ exact: false,
3324
+ maximum: check.value,
3325
+ type: "date"
3326
+ });
3327
+ status.dirty();
3328
+ }
3329
+ } else {
3330
+ util.assertNever(check);
3331
+ }
3332
+ }
3333
+ return {
3334
+ status: status.value,
3335
+ value: new Date(input.data.getTime())
3336
+ };
3337
+ }
3338
+ _addCheck(check) {
3339
+ return new _ZodDate({
3340
+ ...this._def,
3341
+ checks: [...this._def.checks, check]
3342
+ });
3343
+ }
3344
+ min(minDate, message) {
3345
+ return this._addCheck({
3346
+ kind: "min",
3347
+ value: minDate.getTime(),
3348
+ message: errorUtil.toString(message)
3349
+ });
3350
+ }
3351
+ max(maxDate, message) {
3352
+ return this._addCheck({
3353
+ kind: "max",
3354
+ value: maxDate.getTime(),
3355
+ message: errorUtil.toString(message)
3356
+ });
3357
+ }
3358
+ get minDate() {
3359
+ let min = null;
3360
+ for (const ch of this._def.checks) {
3361
+ if (ch.kind === "min") {
3362
+ if (min === null || ch.value > min)
3363
+ min = ch.value;
3364
+ }
3365
+ }
3366
+ return min != null ? new Date(min) : null;
3367
+ }
3368
+ get maxDate() {
3369
+ let max = null;
3370
+ for (const ch of this._def.checks) {
3371
+ if (ch.kind === "max") {
3372
+ if (max === null || ch.value < max)
3373
+ max = ch.value;
3374
+ }
3375
+ }
3376
+ return max != null ? new Date(max) : null;
3377
+ }
3378
+ };
3379
+ ZodDate.create = (params) => {
3380
+ return new ZodDate({
3381
+ checks: [],
3382
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
3383
+ typeName: ZodFirstPartyTypeKind.ZodDate,
3384
+ ...processCreateParams(params)
3385
+ });
3386
+ };
3387
+ var ZodSymbol = class extends ZodType {
3388
+ _parse(input) {
3389
+ const parsedType = this._getType(input);
3390
+ if (parsedType !== ZodParsedType.symbol) {
3391
+ const ctx = this._getOrReturnCtx(input);
3392
+ addIssueToContext(ctx, {
3393
+ code: ZodIssueCode.invalid_type,
3394
+ expected: ZodParsedType.symbol,
3395
+ received: ctx.parsedType
3396
+ });
3397
+ return INVALID;
3398
+ }
3399
+ return OK(input.data);
3400
+ }
3401
+ };
3402
+ ZodSymbol.create = (params) => {
3403
+ return new ZodSymbol({
3404
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
3405
+ ...processCreateParams(params)
3406
+ });
3407
+ };
3408
+ var ZodUndefined = class extends ZodType {
3409
+ _parse(input) {
3410
+ const parsedType = this._getType(input);
3411
+ if (parsedType !== ZodParsedType.undefined) {
3412
+ const ctx = this._getOrReturnCtx(input);
3413
+ addIssueToContext(ctx, {
3414
+ code: ZodIssueCode.invalid_type,
3415
+ expected: ZodParsedType.undefined,
3416
+ received: ctx.parsedType
3417
+ });
3418
+ return INVALID;
3419
+ }
3420
+ return OK(input.data);
3421
+ }
3422
+ };
3423
+ ZodUndefined.create = (params) => {
3424
+ return new ZodUndefined({
3425
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
3426
+ ...processCreateParams(params)
3427
+ });
3428
+ };
3429
+ var ZodNull = class extends ZodType {
3430
+ _parse(input) {
3431
+ const parsedType = this._getType(input);
3432
+ if (parsedType !== ZodParsedType.null) {
3433
+ const ctx = this._getOrReturnCtx(input);
3434
+ addIssueToContext(ctx, {
3435
+ code: ZodIssueCode.invalid_type,
3436
+ expected: ZodParsedType.null,
3437
+ received: ctx.parsedType
3438
+ });
3439
+ return INVALID;
3440
+ }
3441
+ return OK(input.data);
3442
+ }
3443
+ };
3444
+ ZodNull.create = (params) => {
3445
+ return new ZodNull({
3446
+ typeName: ZodFirstPartyTypeKind.ZodNull,
3447
+ ...processCreateParams(params)
3448
+ });
3449
+ };
3450
+ var ZodAny = class extends ZodType {
3451
+ constructor() {
3452
+ super(...arguments);
3453
+ this._any = true;
3454
+ }
3455
+ _parse(input) {
3456
+ return OK(input.data);
3457
+ }
3458
+ };
3459
+ ZodAny.create = (params) => {
3460
+ return new ZodAny({
3461
+ typeName: ZodFirstPartyTypeKind.ZodAny,
3462
+ ...processCreateParams(params)
3463
+ });
3464
+ };
3465
+ var ZodUnknown = class extends ZodType {
3466
+ constructor() {
3467
+ super(...arguments);
3468
+ this._unknown = true;
3469
+ }
3470
+ _parse(input) {
3471
+ return OK(input.data);
3472
+ }
3473
+ };
3474
+ ZodUnknown.create = (params) => {
3475
+ return new ZodUnknown({
3476
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
3477
+ ...processCreateParams(params)
3478
+ });
3479
+ };
3480
+ var ZodNever = class extends ZodType {
3481
+ _parse(input) {
3482
+ const ctx = this._getOrReturnCtx(input);
3483
+ addIssueToContext(ctx, {
3484
+ code: ZodIssueCode.invalid_type,
3485
+ expected: ZodParsedType.never,
3486
+ received: ctx.parsedType
3487
+ });
3488
+ return INVALID;
3489
+ }
3490
+ };
3491
+ ZodNever.create = (params) => {
3492
+ return new ZodNever({
3493
+ typeName: ZodFirstPartyTypeKind.ZodNever,
3494
+ ...processCreateParams(params)
3495
+ });
3496
+ };
3497
+ var ZodVoid = class extends ZodType {
3498
+ _parse(input) {
3499
+ const parsedType = this._getType(input);
3500
+ if (parsedType !== ZodParsedType.undefined) {
3501
+ const ctx = this._getOrReturnCtx(input);
3502
+ addIssueToContext(ctx, {
3503
+ code: ZodIssueCode.invalid_type,
3504
+ expected: ZodParsedType.void,
3505
+ received: ctx.parsedType
3506
+ });
3507
+ return INVALID;
3508
+ }
3509
+ return OK(input.data);
3510
+ }
3511
+ };
3512
+ ZodVoid.create = (params) => {
3513
+ return new ZodVoid({
3514
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
3515
+ ...processCreateParams(params)
3516
+ });
3517
+ };
3518
+ var ZodArray = class _ZodArray extends ZodType {
3519
+ _parse(input) {
3520
+ const { ctx, status } = this._processInputParams(input);
3521
+ const def = this._def;
3522
+ if (ctx.parsedType !== ZodParsedType.array) {
3523
+ addIssueToContext(ctx, {
3524
+ code: ZodIssueCode.invalid_type,
3525
+ expected: ZodParsedType.array,
3526
+ received: ctx.parsedType
3527
+ });
3528
+ return INVALID;
3529
+ }
3530
+ if (def.exactLength !== null) {
3531
+ const tooBig = ctx.data.length > def.exactLength.value;
3532
+ const tooSmall = ctx.data.length < def.exactLength.value;
3533
+ if (tooBig || tooSmall) {
3534
+ addIssueToContext(ctx, {
3535
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
3536
+ minimum: tooSmall ? def.exactLength.value : void 0,
3537
+ maximum: tooBig ? def.exactLength.value : void 0,
3538
+ type: "array",
3539
+ inclusive: true,
3540
+ exact: true,
3541
+ message: def.exactLength.message
3542
+ });
3543
+ status.dirty();
3544
+ }
3545
+ }
3546
+ if (def.minLength !== null) {
3547
+ if (ctx.data.length < def.minLength.value) {
3548
+ addIssueToContext(ctx, {
3549
+ code: ZodIssueCode.too_small,
3550
+ minimum: def.minLength.value,
3551
+ type: "array",
3552
+ inclusive: true,
3553
+ exact: false,
3554
+ message: def.minLength.message
3555
+ });
3556
+ status.dirty();
3557
+ }
3558
+ }
3559
+ if (def.maxLength !== null) {
3560
+ if (ctx.data.length > def.maxLength.value) {
3561
+ addIssueToContext(ctx, {
3562
+ code: ZodIssueCode.too_big,
3563
+ maximum: def.maxLength.value,
3564
+ type: "array",
3565
+ inclusive: true,
3566
+ exact: false,
3567
+ message: def.maxLength.message
3568
+ });
3569
+ status.dirty();
3570
+ }
3571
+ }
3572
+ if (ctx.common.async) {
3573
+ return Promise.all([...ctx.data].map((item, i) => {
3574
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
3575
+ })).then((result2) => {
3576
+ return ParseStatus.mergeArray(status, result2);
3577
+ });
3578
+ }
3579
+ const result = [...ctx.data].map((item, i) => {
3580
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
3581
+ });
3582
+ return ParseStatus.mergeArray(status, result);
3583
+ }
3584
+ get element() {
3585
+ return this._def.type;
3586
+ }
3587
+ min(minLength, message) {
3588
+ return new _ZodArray({
3589
+ ...this._def,
3590
+ minLength: { value: minLength, message: errorUtil.toString(message) }
3591
+ });
3592
+ }
3593
+ max(maxLength, message) {
3594
+ return new _ZodArray({
3595
+ ...this._def,
3596
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
3597
+ });
3598
+ }
3599
+ length(len, message) {
3600
+ return new _ZodArray({
3601
+ ...this._def,
3602
+ exactLength: { value: len, message: errorUtil.toString(message) }
3603
+ });
3604
+ }
3605
+ nonempty(message) {
3606
+ return this.min(1, message);
3607
+ }
3608
+ };
3609
+ ZodArray.create = (schema, params) => {
3610
+ return new ZodArray({
3611
+ type: schema,
3612
+ minLength: null,
3613
+ maxLength: null,
3614
+ exactLength: null,
3615
+ typeName: ZodFirstPartyTypeKind.ZodArray,
3616
+ ...processCreateParams(params)
3617
+ });
3618
+ };
3619
+ function deepPartialify(schema) {
3620
+ if (schema instanceof ZodObject) {
3621
+ const newShape = {};
3622
+ for (const key in schema.shape) {
3623
+ const fieldSchema = schema.shape[key];
3624
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
3625
+ }
3626
+ return new ZodObject({
3627
+ ...schema._def,
3628
+ shape: () => newShape
3629
+ });
3630
+ } else if (schema instanceof ZodArray) {
3631
+ return new ZodArray({
3632
+ ...schema._def,
3633
+ type: deepPartialify(schema.element)
3634
+ });
3635
+ } else if (schema instanceof ZodOptional) {
3636
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
3637
+ } else if (schema instanceof ZodNullable) {
3638
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
3639
+ } else if (schema instanceof ZodTuple) {
3640
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
3641
+ } else {
3642
+ return schema;
3643
+ }
3644
+ }
3645
+ var ZodObject = class _ZodObject extends ZodType {
3646
+ constructor() {
3647
+ super(...arguments);
3648
+ this._cached = null;
3649
+ this.nonstrict = this.passthrough;
3650
+ this.augment = this.extend;
3651
+ }
3652
+ _getCached() {
3653
+ if (this._cached !== null)
3654
+ return this._cached;
3655
+ const shape = this._def.shape();
3656
+ const keys = util.objectKeys(shape);
3657
+ return this._cached = { shape, keys };
3658
+ }
3659
+ _parse(input) {
3660
+ const parsedType = this._getType(input);
3661
+ if (parsedType !== ZodParsedType.object) {
3662
+ const ctx2 = this._getOrReturnCtx(input);
3663
+ addIssueToContext(ctx2, {
3664
+ code: ZodIssueCode.invalid_type,
3665
+ expected: ZodParsedType.object,
3666
+ received: ctx2.parsedType
3667
+ });
3668
+ return INVALID;
3669
+ }
3670
+ const { status, ctx } = this._processInputParams(input);
3671
+ const { shape, keys: shapeKeys } = this._getCached();
3672
+ const extraKeys = [];
3673
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
3674
+ for (const key in ctx.data) {
3675
+ if (!shapeKeys.includes(key)) {
3676
+ extraKeys.push(key);
3677
+ }
3678
+ }
3679
+ }
3680
+ const pairs = [];
3681
+ for (const key of shapeKeys) {
3682
+ const keyValidator = shape[key];
3683
+ const value = ctx.data[key];
3684
+ pairs.push({
3685
+ key: { status: "valid", value: key },
3686
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
3687
+ alwaysSet: key in ctx.data
3688
+ });
3689
+ }
3690
+ if (this._def.catchall instanceof ZodNever) {
3691
+ const unknownKeys = this._def.unknownKeys;
3692
+ if (unknownKeys === "passthrough") {
3693
+ for (const key of extraKeys) {
3694
+ pairs.push({
3695
+ key: { status: "valid", value: key },
3696
+ value: { status: "valid", value: ctx.data[key] }
3697
+ });
3698
+ }
3699
+ } else if (unknownKeys === "strict") {
3700
+ if (extraKeys.length > 0) {
3701
+ addIssueToContext(ctx, {
3702
+ code: ZodIssueCode.unrecognized_keys,
3703
+ keys: extraKeys
3704
+ });
3705
+ status.dirty();
3706
+ }
3707
+ } else if (unknownKeys === "strip")
3708
+ ;
3709
+ else {
3710
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
3711
+ }
3712
+ } else {
3713
+ const catchall = this._def.catchall;
3714
+ for (const key of extraKeys) {
3715
+ const value = ctx.data[key];
3716
+ pairs.push({
3717
+ key: { status: "valid", value: key },
3718
+ value: catchall._parse(
3719
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
3720
+ //, ctx.child(key), value, getParsedType(value)
3721
+ ),
3722
+ alwaysSet: key in ctx.data
3723
+ });
3724
+ }
3725
+ }
3726
+ if (ctx.common.async) {
3727
+ return Promise.resolve().then(async () => {
3728
+ const syncPairs = [];
3729
+ for (const pair of pairs) {
3730
+ const key = await pair.key;
3731
+ syncPairs.push({
3732
+ key,
3733
+ value: await pair.value,
3734
+ alwaysSet: pair.alwaysSet
3735
+ });
3736
+ }
3737
+ return syncPairs;
3738
+ }).then((syncPairs) => {
3739
+ return ParseStatus.mergeObjectSync(status, syncPairs);
3740
+ });
3741
+ } else {
3742
+ return ParseStatus.mergeObjectSync(status, pairs);
3743
+ }
3744
+ }
3745
+ get shape() {
3746
+ return this._def.shape();
3747
+ }
3748
+ strict(message) {
3749
+ errorUtil.errToObj;
3750
+ return new _ZodObject({
3751
+ ...this._def,
3752
+ unknownKeys: "strict",
3753
+ ...message !== void 0 ? {
3754
+ errorMap: (issue, ctx) => {
3755
+ var _a, _b, _c, _d;
3756
+ 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;
3757
+ if (issue.code === "unrecognized_keys")
3758
+ return {
3759
+ message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
3760
+ };
3761
+ return {
3762
+ message: defaultError
3763
+ };
3764
+ }
3765
+ } : {}
3766
+ });
3767
+ }
3768
+ strip() {
3769
+ return new _ZodObject({
3770
+ ...this._def,
3771
+ unknownKeys: "strip"
3772
+ });
3773
+ }
3774
+ passthrough() {
3775
+ return new _ZodObject({
3776
+ ...this._def,
3777
+ unknownKeys: "passthrough"
3778
+ });
3779
+ }
3780
+ // const AugmentFactory =
3781
+ // <Def extends ZodObjectDef>(def: Def) =>
3782
+ // <Augmentation extends ZodRawShape>(
3783
+ // augmentation: Augmentation
3784
+ // ): ZodObject<
3785
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
3786
+ // Def["unknownKeys"],
3787
+ // Def["catchall"]
3788
+ // > => {
3789
+ // return new ZodObject({
3790
+ // ...def,
3791
+ // shape: () => ({
3792
+ // ...def.shape(),
3793
+ // ...augmentation,
3794
+ // }),
3795
+ // }) as any;
3796
+ // };
3797
+ extend(augmentation) {
3798
+ return new _ZodObject({
3799
+ ...this._def,
3800
+ shape: () => ({
3801
+ ...this._def.shape(),
3802
+ ...augmentation
3803
+ })
3804
+ });
3805
+ }
3806
+ /**
3807
+ * Prior to zod@1.0.12 there was a bug in the
3808
+ * inferred type of merged objects. Please
3809
+ * upgrade if you are experiencing issues.
3810
+ */
3811
+ merge(merging) {
3812
+ const merged = new _ZodObject({
3813
+ unknownKeys: merging._def.unknownKeys,
3814
+ catchall: merging._def.catchall,
3815
+ shape: () => ({
3816
+ ...this._def.shape(),
3817
+ ...merging._def.shape()
3818
+ }),
3819
+ typeName: ZodFirstPartyTypeKind.ZodObject
3820
+ });
3821
+ return merged;
3822
+ }
3823
+ // merge<
3824
+ // Incoming extends AnyZodObject,
3825
+ // Augmentation extends Incoming["shape"],
3826
+ // NewOutput extends {
3827
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
3828
+ // ? Augmentation[k]["_output"]
3829
+ // : k extends keyof Output
3830
+ // ? Output[k]
3831
+ // : never;
3832
+ // },
3833
+ // NewInput extends {
3834
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
3835
+ // ? Augmentation[k]["_input"]
3836
+ // : k extends keyof Input
3837
+ // ? Input[k]
3838
+ // : never;
3839
+ // }
3840
+ // >(
3841
+ // merging: Incoming
3842
+ // ): ZodObject<
3843
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
3844
+ // Incoming["_def"]["unknownKeys"],
3845
+ // Incoming["_def"]["catchall"],
3846
+ // NewOutput,
3847
+ // NewInput
3848
+ // > {
3849
+ // const merged: any = new ZodObject({
3850
+ // unknownKeys: merging._def.unknownKeys,
3851
+ // catchall: merging._def.catchall,
3852
+ // shape: () =>
3853
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3854
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
3855
+ // }) as any;
3856
+ // return merged;
3857
+ // }
3858
+ setKey(key, schema) {
3859
+ return this.augment({ [key]: schema });
3860
+ }
3861
+ // merge<Incoming extends AnyZodObject>(
3862
+ // merging: Incoming
3863
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
3864
+ // ZodObject<
3865
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
3866
+ // Incoming["_def"]["unknownKeys"],
3867
+ // Incoming["_def"]["catchall"]
3868
+ // > {
3869
+ // // const mergedShape = objectUtil.mergeShapes(
3870
+ // // this._def.shape(),
3871
+ // // merging._def.shape()
3872
+ // // );
3873
+ // const merged: any = new ZodObject({
3874
+ // unknownKeys: merging._def.unknownKeys,
3875
+ // catchall: merging._def.catchall,
3876
+ // shape: () =>
3877
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3878
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
3879
+ // }) as any;
3880
+ // return merged;
3881
+ // }
3882
+ catchall(index) {
3883
+ return new _ZodObject({
3884
+ ...this._def,
3885
+ catchall: index
3886
+ });
3887
+ }
3888
+ pick(mask) {
3889
+ const shape = {};
3890
+ util.objectKeys(mask).forEach((key) => {
3891
+ if (mask[key] && this.shape[key]) {
3892
+ shape[key] = this.shape[key];
3893
+ }
3894
+ });
3895
+ return new _ZodObject({
3896
+ ...this._def,
3897
+ shape: () => shape
3898
+ });
3899
+ }
3900
+ omit(mask) {
3901
+ const shape = {};
3902
+ util.objectKeys(this.shape).forEach((key) => {
3903
+ if (!mask[key]) {
3904
+ shape[key] = this.shape[key];
3905
+ }
3906
+ });
3907
+ return new _ZodObject({
3908
+ ...this._def,
3909
+ shape: () => shape
3910
+ });
3911
+ }
3912
+ /**
3913
+ * @deprecated
3914
+ */
3915
+ deepPartial() {
3916
+ return deepPartialify(this);
3917
+ }
3918
+ partial(mask) {
3919
+ const newShape = {};
3920
+ util.objectKeys(this.shape).forEach((key) => {
3921
+ const fieldSchema = this.shape[key];
3922
+ if (mask && !mask[key]) {
3923
+ newShape[key] = fieldSchema;
3924
+ } else {
3925
+ newShape[key] = fieldSchema.optional();
3926
+ }
3927
+ });
3928
+ return new _ZodObject({
3929
+ ...this._def,
3930
+ shape: () => newShape
3931
+ });
3932
+ }
3933
+ required(mask) {
3934
+ const newShape = {};
3935
+ util.objectKeys(this.shape).forEach((key) => {
3936
+ if (mask && !mask[key]) {
3937
+ newShape[key] = this.shape[key];
3938
+ } else {
3939
+ const fieldSchema = this.shape[key];
3940
+ let newField = fieldSchema;
3941
+ while (newField instanceof ZodOptional) {
3942
+ newField = newField._def.innerType;
3943
+ }
3944
+ newShape[key] = newField;
3945
+ }
3946
+ });
3947
+ return new _ZodObject({
3948
+ ...this._def,
3949
+ shape: () => newShape
3950
+ });
3951
+ }
3952
+ keyof() {
3953
+ return createZodEnum(util.objectKeys(this.shape));
3954
+ }
3955
+ };
3956
+ ZodObject.create = (shape, params) => {
3957
+ return new ZodObject({
3958
+ shape: () => shape,
3959
+ unknownKeys: "strip",
3960
+ catchall: ZodNever.create(),
3961
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3962
+ ...processCreateParams(params)
3963
+ });
3964
+ };
3965
+ ZodObject.strictCreate = (shape, params) => {
3966
+ return new ZodObject({
3967
+ shape: () => shape,
3968
+ unknownKeys: "strict",
3969
+ catchall: ZodNever.create(),
3970
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3971
+ ...processCreateParams(params)
3972
+ });
3973
+ };
3974
+ ZodObject.lazycreate = (shape, params) => {
3975
+ return new ZodObject({
3976
+ shape,
3977
+ unknownKeys: "strip",
3978
+ catchall: ZodNever.create(),
3979
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3980
+ ...processCreateParams(params)
3981
+ });
3982
+ };
3983
+ var ZodUnion = class extends ZodType {
3984
+ _parse(input) {
3985
+ const { ctx } = this._processInputParams(input);
3986
+ const options = this._def.options;
3987
+ function handleResults(results) {
3988
+ for (const result of results) {
3989
+ if (result.result.status === "valid") {
3990
+ return result.result;
3991
+ }
3992
+ }
3993
+ for (const result of results) {
3994
+ if (result.result.status === "dirty") {
3995
+ ctx.common.issues.push(...result.ctx.common.issues);
3996
+ return result.result;
3997
+ }
3998
+ }
3999
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
4000
+ addIssueToContext(ctx, {
4001
+ code: ZodIssueCode.invalid_union,
4002
+ unionErrors
4003
+ });
4004
+ return INVALID;
4005
+ }
4006
+ if (ctx.common.async) {
4007
+ return Promise.all(options.map(async (option) => {
4008
+ const childCtx = {
4009
+ ...ctx,
4010
+ common: {
4011
+ ...ctx.common,
4012
+ issues: []
4013
+ },
4014
+ parent: null
4015
+ };
4016
+ return {
4017
+ result: await option._parseAsync({
4018
+ data: ctx.data,
4019
+ path: ctx.path,
4020
+ parent: childCtx
4021
+ }),
4022
+ ctx: childCtx
4023
+ };
4024
+ })).then(handleResults);
4025
+ } else {
4026
+ let dirty = void 0;
4027
+ const issues = [];
4028
+ for (const option of options) {
4029
+ const childCtx = {
4030
+ ...ctx,
4031
+ common: {
4032
+ ...ctx.common,
4033
+ issues: []
4034
+ },
4035
+ parent: null
4036
+ };
4037
+ const result = option._parseSync({
4038
+ data: ctx.data,
4039
+ path: ctx.path,
4040
+ parent: childCtx
4041
+ });
4042
+ if (result.status === "valid") {
4043
+ return result;
4044
+ } else if (result.status === "dirty" && !dirty) {
4045
+ dirty = { result, ctx: childCtx };
4046
+ }
4047
+ if (childCtx.common.issues.length) {
4048
+ issues.push(childCtx.common.issues);
4049
+ }
4050
+ }
4051
+ if (dirty) {
4052
+ ctx.common.issues.push(...dirty.ctx.common.issues);
4053
+ return dirty.result;
4054
+ }
4055
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
4056
+ addIssueToContext(ctx, {
4057
+ code: ZodIssueCode.invalid_union,
4058
+ unionErrors
4059
+ });
4060
+ return INVALID;
4061
+ }
4062
+ }
4063
+ get options() {
4064
+ return this._def.options;
4065
+ }
4066
+ };
4067
+ ZodUnion.create = (types, params) => {
4068
+ return new ZodUnion({
4069
+ options: types,
4070
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
4071
+ ...processCreateParams(params)
4072
+ });
4073
+ };
4074
+ var getDiscriminator = (type) => {
4075
+ if (type instanceof ZodLazy) {
4076
+ return getDiscriminator(type.schema);
4077
+ } else if (type instanceof ZodEffects) {
4078
+ return getDiscriminator(type.innerType());
4079
+ } else if (type instanceof ZodLiteral) {
4080
+ return [type.value];
4081
+ } else if (type instanceof ZodEnum) {
4082
+ return type.options;
4083
+ } else if (type instanceof ZodNativeEnum) {
4084
+ return Object.keys(type.enum);
4085
+ } else if (type instanceof ZodDefault) {
4086
+ return getDiscriminator(type._def.innerType);
4087
+ } else if (type instanceof ZodUndefined) {
4088
+ return [void 0];
4089
+ } else if (type instanceof ZodNull) {
4090
+ return [null];
4091
+ } else {
4092
+ return null;
4093
+ }
4094
+ };
4095
+ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
4096
+ _parse(input) {
4097
+ const { ctx } = this._processInputParams(input);
4098
+ if (ctx.parsedType !== ZodParsedType.object) {
4099
+ addIssueToContext(ctx, {
4100
+ code: ZodIssueCode.invalid_type,
4101
+ expected: ZodParsedType.object,
4102
+ received: ctx.parsedType
4103
+ });
4104
+ return INVALID;
4105
+ }
4106
+ const discriminator = this.discriminator;
4107
+ const discriminatorValue = ctx.data[discriminator];
4108
+ const option = this.optionsMap.get(discriminatorValue);
4109
+ if (!option) {
4110
+ addIssueToContext(ctx, {
4111
+ code: ZodIssueCode.invalid_union_discriminator,
4112
+ options: Array.from(this.optionsMap.keys()),
4113
+ path: [discriminator]
4114
+ });
4115
+ return INVALID;
4116
+ }
4117
+ if (ctx.common.async) {
4118
+ return option._parseAsync({
4119
+ data: ctx.data,
4120
+ path: ctx.path,
4121
+ parent: ctx
4122
+ });
4123
+ } else {
4124
+ return option._parseSync({
4125
+ data: ctx.data,
4126
+ path: ctx.path,
4127
+ parent: ctx
4128
+ });
4129
+ }
4130
+ }
4131
+ get discriminator() {
4132
+ return this._def.discriminator;
4133
+ }
4134
+ get options() {
4135
+ return this._def.options;
4136
+ }
4137
+ get optionsMap() {
4138
+ return this._def.optionsMap;
4139
+ }
4140
+ /**
4141
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
4142
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
4143
+ * have a different value for each object in the union.
4144
+ * @param discriminator the name of the discriminator property
4145
+ * @param types an array of object schemas
4146
+ * @param params
4147
+ */
4148
+ static create(discriminator, options, params) {
4149
+ const optionsMap = /* @__PURE__ */ new Map();
4150
+ for (const type of options) {
4151
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
4152
+ if (!discriminatorValues) {
4153
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
4154
+ }
4155
+ for (const value of discriminatorValues) {
4156
+ if (optionsMap.has(value)) {
4157
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
4158
+ }
4159
+ optionsMap.set(value, type);
4160
+ }
4161
+ }
4162
+ return new _ZodDiscriminatedUnion({
4163
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
4164
+ discriminator,
4165
+ options,
4166
+ optionsMap,
4167
+ ...processCreateParams(params)
4168
+ });
4169
+ }
4170
+ };
4171
+ function mergeValues(a, b) {
4172
+ const aType = getParsedType(a);
4173
+ const bType = getParsedType(b);
4174
+ if (a === b) {
4175
+ return { valid: true, data: a };
4176
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
4177
+ const bKeys = util.objectKeys(b);
4178
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
4179
+ const newObj = { ...a, ...b };
4180
+ for (const key of sharedKeys) {
4181
+ const sharedValue = mergeValues(a[key], b[key]);
4182
+ if (!sharedValue.valid) {
4183
+ return { valid: false };
4184
+ }
4185
+ newObj[key] = sharedValue.data;
4186
+ }
4187
+ return { valid: true, data: newObj };
4188
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
4189
+ if (a.length !== b.length) {
4190
+ return { valid: false };
4191
+ }
4192
+ const newArray = [];
4193
+ for (let index = 0; index < a.length; index++) {
4194
+ const itemA = a[index];
4195
+ const itemB = b[index];
4196
+ const sharedValue = mergeValues(itemA, itemB);
4197
+ if (!sharedValue.valid) {
4198
+ return { valid: false };
4199
+ }
4200
+ newArray.push(sharedValue.data);
4201
+ }
4202
+ return { valid: true, data: newArray };
4203
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
4204
+ return { valid: true, data: a };
4205
+ } else {
4206
+ return { valid: false };
4207
+ }
4208
+ }
4209
+ var ZodIntersection = class extends ZodType {
4210
+ _parse(input) {
4211
+ const { status, ctx } = this._processInputParams(input);
4212
+ const handleParsed = (parsedLeft, parsedRight) => {
4213
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
4214
+ return INVALID;
4215
+ }
4216
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
4217
+ if (!merged.valid) {
4218
+ addIssueToContext(ctx, {
4219
+ code: ZodIssueCode.invalid_intersection_types
4220
+ });
4221
+ return INVALID;
4222
+ }
4223
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
4224
+ status.dirty();
4225
+ }
4226
+ return { status: status.value, value: merged.data };
4227
+ };
4228
+ if (ctx.common.async) {
4229
+ return Promise.all([
4230
+ this._def.left._parseAsync({
4231
+ data: ctx.data,
4232
+ path: ctx.path,
4233
+ parent: ctx
4234
+ }),
4235
+ this._def.right._parseAsync({
4236
+ data: ctx.data,
4237
+ path: ctx.path,
4238
+ parent: ctx
4239
+ })
4240
+ ]).then(([left, right]) => handleParsed(left, right));
4241
+ } else {
4242
+ return handleParsed(this._def.left._parseSync({
4243
+ data: ctx.data,
4244
+ path: ctx.path,
4245
+ parent: ctx
4246
+ }), this._def.right._parseSync({
4247
+ data: ctx.data,
4248
+ path: ctx.path,
4249
+ parent: ctx
4250
+ }));
4251
+ }
4252
+ }
4253
+ };
4254
+ ZodIntersection.create = (left, right, params) => {
4255
+ return new ZodIntersection({
4256
+ left,
4257
+ right,
4258
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
4259
+ ...processCreateParams(params)
4260
+ });
4261
+ };
4262
+ var ZodTuple = class _ZodTuple extends ZodType {
4263
+ _parse(input) {
4264
+ const { status, ctx } = this._processInputParams(input);
4265
+ if (ctx.parsedType !== ZodParsedType.array) {
4266
+ addIssueToContext(ctx, {
4267
+ code: ZodIssueCode.invalid_type,
4268
+ expected: ZodParsedType.array,
4269
+ received: ctx.parsedType
4270
+ });
4271
+ return INVALID;
4272
+ }
4273
+ if (ctx.data.length < this._def.items.length) {
4274
+ addIssueToContext(ctx, {
4275
+ code: ZodIssueCode.too_small,
4276
+ minimum: this._def.items.length,
4277
+ inclusive: true,
4278
+ exact: false,
4279
+ type: "array"
4280
+ });
4281
+ return INVALID;
4282
+ }
4283
+ const rest = this._def.rest;
4284
+ if (!rest && ctx.data.length > this._def.items.length) {
4285
+ addIssueToContext(ctx, {
4286
+ code: ZodIssueCode.too_big,
4287
+ maximum: this._def.items.length,
4288
+ inclusive: true,
4289
+ exact: false,
4290
+ type: "array"
4291
+ });
4292
+ status.dirty();
4293
+ }
4294
+ const items = [...ctx.data].map((item, itemIndex) => {
4295
+ const schema = this._def.items[itemIndex] || this._def.rest;
4296
+ if (!schema)
4297
+ return null;
4298
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
4299
+ }).filter((x) => !!x);
4300
+ if (ctx.common.async) {
4301
+ return Promise.all(items).then((results) => {
4302
+ return ParseStatus.mergeArray(status, results);
4303
+ });
4304
+ } else {
4305
+ return ParseStatus.mergeArray(status, items);
4306
+ }
4307
+ }
4308
+ get items() {
4309
+ return this._def.items;
4310
+ }
4311
+ rest(rest) {
4312
+ return new _ZodTuple({
4313
+ ...this._def,
4314
+ rest
4315
+ });
4316
+ }
4317
+ };
4318
+ ZodTuple.create = (schemas, params) => {
4319
+ if (!Array.isArray(schemas)) {
4320
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
4321
+ }
4322
+ return new ZodTuple({
4323
+ items: schemas,
4324
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
4325
+ rest: null,
4326
+ ...processCreateParams(params)
4327
+ });
4328
+ };
4329
+ var ZodRecord = class _ZodRecord extends ZodType {
4330
+ get keySchema() {
4331
+ return this._def.keyType;
4332
+ }
4333
+ get valueSchema() {
4334
+ return this._def.valueType;
4335
+ }
4336
+ _parse(input) {
4337
+ const { status, ctx } = this._processInputParams(input);
4338
+ if (ctx.parsedType !== ZodParsedType.object) {
4339
+ addIssueToContext(ctx, {
4340
+ code: ZodIssueCode.invalid_type,
4341
+ expected: ZodParsedType.object,
4342
+ received: ctx.parsedType
4343
+ });
4344
+ return INVALID;
4345
+ }
4346
+ const pairs = [];
4347
+ const keyType = this._def.keyType;
4348
+ const valueType = this._def.valueType;
4349
+ for (const key in ctx.data) {
4350
+ pairs.push({
4351
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
4352
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
4353
+ });
4354
+ }
4355
+ if (ctx.common.async) {
4356
+ return ParseStatus.mergeObjectAsync(status, pairs);
4357
+ } else {
4358
+ return ParseStatus.mergeObjectSync(status, pairs);
4359
+ }
4360
+ }
4361
+ get element() {
4362
+ return this._def.valueType;
4363
+ }
4364
+ static create(first, second, third) {
4365
+ if (second instanceof ZodType) {
4366
+ return new _ZodRecord({
4367
+ keyType: first,
4368
+ valueType: second,
4369
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
4370
+ ...processCreateParams(third)
4371
+ });
4372
+ }
4373
+ return new _ZodRecord({
4374
+ keyType: ZodString.create(),
4375
+ valueType: first,
4376
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
4377
+ ...processCreateParams(second)
4378
+ });
4379
+ }
4380
+ };
4381
+ var ZodMap = class extends ZodType {
4382
+ get keySchema() {
4383
+ return this._def.keyType;
4384
+ }
4385
+ get valueSchema() {
4386
+ return this._def.valueType;
4387
+ }
4388
+ _parse(input) {
4389
+ const { status, ctx } = this._processInputParams(input);
4390
+ if (ctx.parsedType !== ZodParsedType.map) {
4391
+ addIssueToContext(ctx, {
4392
+ code: ZodIssueCode.invalid_type,
4393
+ expected: ZodParsedType.map,
4394
+ received: ctx.parsedType
4395
+ });
4396
+ return INVALID;
4397
+ }
4398
+ const keyType = this._def.keyType;
4399
+ const valueType = this._def.valueType;
4400
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
4401
+ return {
4402
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
4403
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
4404
+ };
4405
+ });
4406
+ if (ctx.common.async) {
4407
+ const finalMap = /* @__PURE__ */ new Map();
4408
+ return Promise.resolve().then(async () => {
4409
+ for (const pair of pairs) {
4410
+ const key = await pair.key;
4411
+ const value = await pair.value;
4412
+ if (key.status === "aborted" || value.status === "aborted") {
4413
+ return INVALID;
4414
+ }
4415
+ if (key.status === "dirty" || value.status === "dirty") {
4416
+ status.dirty();
4417
+ }
4418
+ finalMap.set(key.value, value.value);
4419
+ }
4420
+ return { status: status.value, value: finalMap };
4421
+ });
4422
+ } else {
4423
+ const finalMap = /* @__PURE__ */ new Map();
4424
+ for (const pair of pairs) {
4425
+ const key = pair.key;
4426
+ const value = pair.value;
4427
+ if (key.status === "aborted" || value.status === "aborted") {
4428
+ return INVALID;
4429
+ }
4430
+ if (key.status === "dirty" || value.status === "dirty") {
4431
+ status.dirty();
4432
+ }
4433
+ finalMap.set(key.value, value.value);
4434
+ }
4435
+ return { status: status.value, value: finalMap };
4436
+ }
4437
+ }
4438
+ };
4439
+ ZodMap.create = (keyType, valueType, params) => {
4440
+ return new ZodMap({
4441
+ valueType,
4442
+ keyType,
4443
+ typeName: ZodFirstPartyTypeKind.ZodMap,
4444
+ ...processCreateParams(params)
4445
+ });
4446
+ };
4447
+ var ZodSet = class _ZodSet extends ZodType {
4448
+ _parse(input) {
4449
+ const { status, ctx } = this._processInputParams(input);
4450
+ if (ctx.parsedType !== ZodParsedType.set) {
4451
+ addIssueToContext(ctx, {
4452
+ code: ZodIssueCode.invalid_type,
4453
+ expected: ZodParsedType.set,
4454
+ received: ctx.parsedType
4455
+ });
4456
+ return INVALID;
4457
+ }
4458
+ const def = this._def;
4459
+ if (def.minSize !== null) {
4460
+ if (ctx.data.size < def.minSize.value) {
4461
+ addIssueToContext(ctx, {
4462
+ code: ZodIssueCode.too_small,
4463
+ minimum: def.minSize.value,
4464
+ type: "set",
4465
+ inclusive: true,
4466
+ exact: false,
4467
+ message: def.minSize.message
4468
+ });
4469
+ status.dirty();
4470
+ }
4471
+ }
4472
+ if (def.maxSize !== null) {
4473
+ if (ctx.data.size > def.maxSize.value) {
4474
+ addIssueToContext(ctx, {
4475
+ code: ZodIssueCode.too_big,
4476
+ maximum: def.maxSize.value,
4477
+ type: "set",
4478
+ inclusive: true,
4479
+ exact: false,
4480
+ message: def.maxSize.message
4481
+ });
4482
+ status.dirty();
4483
+ }
4484
+ }
4485
+ const valueType = this._def.valueType;
4486
+ function finalizeSet(elements2) {
4487
+ const parsedSet = /* @__PURE__ */ new Set();
4488
+ for (const element of elements2) {
4489
+ if (element.status === "aborted")
4490
+ return INVALID;
4491
+ if (element.status === "dirty")
4492
+ status.dirty();
4493
+ parsedSet.add(element.value);
4494
+ }
4495
+ return { status: status.value, value: parsedSet };
4496
+ }
4497
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
4498
+ if (ctx.common.async) {
4499
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
4500
+ } else {
4501
+ return finalizeSet(elements);
4502
+ }
4503
+ }
4504
+ min(minSize, message) {
4505
+ return new _ZodSet({
4506
+ ...this._def,
4507
+ minSize: { value: minSize, message: errorUtil.toString(message) }
4508
+ });
4509
+ }
4510
+ max(maxSize, message) {
4511
+ return new _ZodSet({
4512
+ ...this._def,
4513
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
4514
+ });
4515
+ }
4516
+ size(size, message) {
4517
+ return this.min(size, message).max(size, message);
4518
+ }
4519
+ nonempty(message) {
4520
+ return this.min(1, message);
4521
+ }
4522
+ };
4523
+ ZodSet.create = (valueType, params) => {
4524
+ return new ZodSet({
4525
+ valueType,
4526
+ minSize: null,
4527
+ maxSize: null,
4528
+ typeName: ZodFirstPartyTypeKind.ZodSet,
4529
+ ...processCreateParams(params)
4530
+ });
4531
+ };
4532
+ var ZodFunction = class _ZodFunction extends ZodType {
4533
+ constructor() {
4534
+ super(...arguments);
4535
+ this.validate = this.implement;
4536
+ }
4537
+ _parse(input) {
4538
+ const { ctx } = this._processInputParams(input);
4539
+ if (ctx.parsedType !== ZodParsedType.function) {
4540
+ addIssueToContext(ctx, {
4541
+ code: ZodIssueCode.invalid_type,
4542
+ expected: ZodParsedType.function,
4543
+ received: ctx.parsedType
4544
+ });
4545
+ return INVALID;
4546
+ }
4547
+ function makeArgsIssue(args, error) {
4548
+ return makeIssue({
4549
+ data: args,
4550
+ path: ctx.path,
4551
+ errorMaps: [
4552
+ ctx.common.contextualErrorMap,
4553
+ ctx.schemaErrorMap,
4554
+ getErrorMap(),
4555
+ errorMap
4556
+ ].filter((x) => !!x),
4557
+ issueData: {
4558
+ code: ZodIssueCode.invalid_arguments,
4559
+ argumentsError: error
4560
+ }
4561
+ });
4562
+ }
4563
+ function makeReturnsIssue(returns, error) {
4564
+ return makeIssue({
4565
+ data: returns,
4566
+ path: ctx.path,
4567
+ errorMaps: [
4568
+ ctx.common.contextualErrorMap,
4569
+ ctx.schemaErrorMap,
4570
+ getErrorMap(),
4571
+ errorMap
4572
+ ].filter((x) => !!x),
4573
+ issueData: {
4574
+ code: ZodIssueCode.invalid_return_type,
4575
+ returnTypeError: error
4576
+ }
4577
+ });
4578
+ }
4579
+ const params = { errorMap: ctx.common.contextualErrorMap };
4580
+ const fn = ctx.data;
4581
+ if (this._def.returns instanceof ZodPromise) {
4582
+ const me = this;
4583
+ return OK(async function(...args) {
4584
+ const error = new ZodError([]);
4585
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
4586
+ error.addIssue(makeArgsIssue(args, e));
4587
+ throw error;
4588
+ });
4589
+ const result = await Reflect.apply(fn, this, parsedArgs);
4590
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
4591
+ error.addIssue(makeReturnsIssue(result, e));
4592
+ throw error;
4593
+ });
4594
+ return parsedReturns;
4595
+ });
4596
+ } else {
4597
+ const me = this;
4598
+ return OK(function(...args) {
4599
+ const parsedArgs = me._def.args.safeParse(args, params);
4600
+ if (!parsedArgs.success) {
4601
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
4602
+ }
4603
+ const result = Reflect.apply(fn, this, parsedArgs.data);
4604
+ const parsedReturns = me._def.returns.safeParse(result, params);
4605
+ if (!parsedReturns.success) {
4606
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
4607
+ }
4608
+ return parsedReturns.data;
4609
+ });
4610
+ }
4611
+ }
4612
+ parameters() {
4613
+ return this._def.args;
4614
+ }
4615
+ returnType() {
4616
+ return this._def.returns;
4617
+ }
4618
+ args(...items) {
4619
+ return new _ZodFunction({
4620
+ ...this._def,
4621
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
4622
+ });
4623
+ }
4624
+ returns(returnType) {
4625
+ return new _ZodFunction({
4626
+ ...this._def,
4627
+ returns: returnType
4628
+ });
4629
+ }
4630
+ implement(func) {
4631
+ const validatedFunc = this.parse(func);
4632
+ return validatedFunc;
4633
+ }
4634
+ strictImplement(func) {
4635
+ const validatedFunc = this.parse(func);
4636
+ return validatedFunc;
4637
+ }
4638
+ static create(args, returns, params) {
4639
+ return new _ZodFunction({
4640
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
4641
+ returns: returns || ZodUnknown.create(),
4642
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
4643
+ ...processCreateParams(params)
4644
+ });
4645
+ }
4646
+ };
4647
+ var ZodLazy = class extends ZodType {
4648
+ get schema() {
4649
+ return this._def.getter();
4650
+ }
4651
+ _parse(input) {
4652
+ const { ctx } = this._processInputParams(input);
4653
+ const lazySchema = this._def.getter();
4654
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
4655
+ }
4656
+ };
4657
+ ZodLazy.create = (getter, params) => {
4658
+ return new ZodLazy({
4659
+ getter,
4660
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
4661
+ ...processCreateParams(params)
4662
+ });
4663
+ };
4664
+ var ZodLiteral = class extends ZodType {
4665
+ _parse(input) {
4666
+ if (input.data !== this._def.value) {
4667
+ const ctx = this._getOrReturnCtx(input);
4668
+ addIssueToContext(ctx, {
4669
+ received: ctx.data,
4670
+ code: ZodIssueCode.invalid_literal,
4671
+ expected: this._def.value
4672
+ });
4673
+ return INVALID;
4674
+ }
4675
+ return { status: "valid", value: input.data };
4676
+ }
4677
+ get value() {
4678
+ return this._def.value;
4679
+ }
4680
+ };
4681
+ ZodLiteral.create = (value, params) => {
4682
+ return new ZodLiteral({
4683
+ value,
4684
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
4685
+ ...processCreateParams(params)
4686
+ });
4687
+ };
4688
+ function createZodEnum(values, params) {
4689
+ return new ZodEnum({
4690
+ values,
4691
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
4692
+ ...processCreateParams(params)
4693
+ });
4694
+ }
4695
+ var ZodEnum = class _ZodEnum extends ZodType {
4696
+ _parse(input) {
4697
+ if (typeof input.data !== "string") {
4698
+ const ctx = this._getOrReturnCtx(input);
4699
+ const expectedValues = this._def.values;
4700
+ addIssueToContext(ctx, {
4701
+ expected: util.joinValues(expectedValues),
4702
+ received: ctx.parsedType,
4703
+ code: ZodIssueCode.invalid_type
4704
+ });
4705
+ return INVALID;
4706
+ }
4707
+ if (this._def.values.indexOf(input.data) === -1) {
4708
+ const ctx = this._getOrReturnCtx(input);
4709
+ const expectedValues = this._def.values;
4710
+ addIssueToContext(ctx, {
4711
+ received: ctx.data,
4712
+ code: ZodIssueCode.invalid_enum_value,
4713
+ options: expectedValues
4714
+ });
4715
+ return INVALID;
4716
+ }
4717
+ return OK(input.data);
4718
+ }
4719
+ get options() {
4720
+ return this._def.values;
4721
+ }
4722
+ get enum() {
4723
+ const enumValues = {};
4724
+ for (const val of this._def.values) {
4725
+ enumValues[val] = val;
4726
+ }
4727
+ return enumValues;
4728
+ }
4729
+ get Values() {
4730
+ const enumValues = {};
4731
+ for (const val of this._def.values) {
4732
+ enumValues[val] = val;
4733
+ }
4734
+ return enumValues;
4735
+ }
4736
+ get Enum() {
4737
+ const enumValues = {};
4738
+ for (const val of this._def.values) {
4739
+ enumValues[val] = val;
4740
+ }
4741
+ return enumValues;
4742
+ }
4743
+ extract(values) {
4744
+ return _ZodEnum.create(values);
4745
+ }
4746
+ exclude(values) {
4747
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
4748
+ }
4749
+ };
4750
+ ZodEnum.create = createZodEnum;
4751
+ var ZodNativeEnum = class extends ZodType {
4752
+ _parse(input) {
4753
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
4754
+ const ctx = this._getOrReturnCtx(input);
4755
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
4756
+ const expectedValues = util.objectValues(nativeEnumValues);
4757
+ addIssueToContext(ctx, {
4758
+ expected: util.joinValues(expectedValues),
4759
+ received: ctx.parsedType,
4760
+ code: ZodIssueCode.invalid_type
4761
+ });
4762
+ return INVALID;
4763
+ }
4764
+ if (nativeEnumValues.indexOf(input.data) === -1) {
4765
+ const expectedValues = util.objectValues(nativeEnumValues);
4766
+ addIssueToContext(ctx, {
4767
+ received: ctx.data,
4768
+ code: ZodIssueCode.invalid_enum_value,
4769
+ options: expectedValues
4770
+ });
4771
+ return INVALID;
4772
+ }
4773
+ return OK(input.data);
4774
+ }
4775
+ get enum() {
4776
+ return this._def.values;
4777
+ }
4778
+ };
4779
+ ZodNativeEnum.create = (values, params) => {
4780
+ return new ZodNativeEnum({
4781
+ values,
4782
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
4783
+ ...processCreateParams(params)
4784
+ });
4785
+ };
4786
+ var ZodPromise = class extends ZodType {
4787
+ unwrap() {
4788
+ return this._def.type;
4789
+ }
4790
+ _parse(input) {
4791
+ const { ctx } = this._processInputParams(input);
4792
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
4793
+ addIssueToContext(ctx, {
4794
+ code: ZodIssueCode.invalid_type,
4795
+ expected: ZodParsedType.promise,
4796
+ received: ctx.parsedType
4797
+ });
4798
+ return INVALID;
4799
+ }
4800
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
4801
+ return OK(promisified.then((data) => {
4802
+ return this._def.type.parseAsync(data, {
4803
+ path: ctx.path,
4804
+ errorMap: ctx.common.contextualErrorMap
4805
+ });
4806
+ }));
4807
+ }
4808
+ };
4809
+ ZodPromise.create = (schema, params) => {
4810
+ return new ZodPromise({
4811
+ type: schema,
4812
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
4813
+ ...processCreateParams(params)
4814
+ });
4815
+ };
4816
+ var ZodEffects = class extends ZodType {
4817
+ innerType() {
4818
+ return this._def.schema;
4819
+ }
4820
+ sourceType() {
4821
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
4822
+ }
4823
+ _parse(input) {
4824
+ const { status, ctx } = this._processInputParams(input);
4825
+ const effect = this._def.effect || null;
4826
+ const checkCtx = {
4827
+ addIssue: (arg) => {
4828
+ addIssueToContext(ctx, arg);
4829
+ if (arg.fatal) {
4830
+ status.abort();
4831
+ } else {
4832
+ status.dirty();
4833
+ }
4834
+ },
4835
+ get path() {
4836
+ return ctx.path;
4837
+ }
4838
+ };
4839
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
4840
+ if (effect.type === "preprocess") {
4841
+ const processed = effect.transform(ctx.data, checkCtx);
4842
+ if (ctx.common.issues.length) {
4843
+ return {
4844
+ status: "dirty",
4845
+ value: ctx.data
4846
+ };
4847
+ }
4848
+ if (ctx.common.async) {
4849
+ return Promise.resolve(processed).then((processed2) => {
4850
+ return this._def.schema._parseAsync({
4851
+ data: processed2,
4852
+ path: ctx.path,
4853
+ parent: ctx
4854
+ });
4855
+ });
4856
+ } else {
4857
+ return this._def.schema._parseSync({
4858
+ data: processed,
4859
+ path: ctx.path,
4860
+ parent: ctx
4861
+ });
4862
+ }
4863
+ }
4864
+ if (effect.type === "refinement") {
4865
+ const executeRefinement = (acc) => {
4866
+ const result = effect.refinement(acc, checkCtx);
4867
+ if (ctx.common.async) {
4868
+ return Promise.resolve(result);
4869
+ }
4870
+ if (result instanceof Promise) {
4871
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
4872
+ }
4873
+ return acc;
4874
+ };
4875
+ if (ctx.common.async === false) {
4876
+ const inner = this._def.schema._parseSync({
4877
+ data: ctx.data,
4878
+ path: ctx.path,
4879
+ parent: ctx
4880
+ });
4881
+ if (inner.status === "aborted")
4882
+ return INVALID;
4883
+ if (inner.status === "dirty")
4884
+ status.dirty();
4885
+ executeRefinement(inner.value);
4886
+ return { status: status.value, value: inner.value };
4887
+ } else {
4888
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
4889
+ if (inner.status === "aborted")
4890
+ return INVALID;
4891
+ if (inner.status === "dirty")
4892
+ status.dirty();
4893
+ return executeRefinement(inner.value).then(() => {
4894
+ return { status: status.value, value: inner.value };
4895
+ });
4896
+ });
4897
+ }
4898
+ }
4899
+ if (effect.type === "transform") {
4900
+ if (ctx.common.async === false) {
4901
+ const base = this._def.schema._parseSync({
4902
+ data: ctx.data,
4903
+ path: ctx.path,
4904
+ parent: ctx
4905
+ });
4906
+ if (!isValid(base))
4907
+ return base;
4908
+ const result = effect.transform(base.value, checkCtx);
4909
+ if (result instanceof Promise) {
4910
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
4911
+ }
4912
+ return { status: status.value, value: result };
4913
+ } else {
4914
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
4915
+ if (!isValid(base))
4916
+ return base;
4917
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
4918
+ });
4919
+ }
4920
+ }
4921
+ util.assertNever(effect);
4922
+ }
4923
+ };
4924
+ ZodEffects.create = (schema, effect, params) => {
4925
+ return new ZodEffects({
4926
+ schema,
4927
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
4928
+ effect,
4929
+ ...processCreateParams(params)
4930
+ });
4931
+ };
4932
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
4933
+ return new ZodEffects({
4934
+ schema,
4935
+ effect: { type: "preprocess", transform: preprocess },
4936
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
4937
+ ...processCreateParams(params)
4938
+ });
4939
+ };
4940
+ var ZodOptional = class extends ZodType {
4941
+ _parse(input) {
4942
+ const parsedType = this._getType(input);
4943
+ if (parsedType === ZodParsedType.undefined) {
4944
+ return OK(void 0);
4945
+ }
4946
+ return this._def.innerType._parse(input);
4947
+ }
4948
+ unwrap() {
4949
+ return this._def.innerType;
4950
+ }
4951
+ };
4952
+ ZodOptional.create = (type, params) => {
4953
+ return new ZodOptional({
4954
+ innerType: type,
4955
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
4956
+ ...processCreateParams(params)
4957
+ });
4958
+ };
4959
+ var ZodNullable = class extends ZodType {
4960
+ _parse(input) {
4961
+ const parsedType = this._getType(input);
4962
+ if (parsedType === ZodParsedType.null) {
4963
+ return OK(null);
4964
+ }
4965
+ return this._def.innerType._parse(input);
4966
+ }
4967
+ unwrap() {
4968
+ return this._def.innerType;
4969
+ }
4970
+ };
4971
+ ZodNullable.create = (type, params) => {
4972
+ return new ZodNullable({
4973
+ innerType: type,
4974
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
4975
+ ...processCreateParams(params)
4976
+ });
4977
+ };
4978
+ var ZodDefault = class extends ZodType {
4979
+ _parse(input) {
4980
+ const { ctx } = this._processInputParams(input);
4981
+ let data = ctx.data;
4982
+ if (ctx.parsedType === ZodParsedType.undefined) {
4983
+ data = this._def.defaultValue();
4984
+ }
4985
+ return this._def.innerType._parse({
4986
+ data,
4987
+ path: ctx.path,
4988
+ parent: ctx
4989
+ });
4990
+ }
4991
+ removeDefault() {
4992
+ return this._def.innerType;
4993
+ }
4994
+ };
4995
+ ZodDefault.create = (type, params) => {
4996
+ return new ZodDefault({
4997
+ innerType: type,
4998
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
4999
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
5000
+ ...processCreateParams(params)
5001
+ });
5002
+ };
5003
+ var ZodCatch = class extends ZodType {
5004
+ _parse(input) {
5005
+ const { ctx } = this._processInputParams(input);
5006
+ const newCtx = {
5007
+ ...ctx,
5008
+ common: {
5009
+ ...ctx.common,
5010
+ issues: []
5011
+ }
5012
+ };
5013
+ const result = this._def.innerType._parse({
5014
+ data: newCtx.data,
5015
+ path: newCtx.path,
5016
+ parent: {
5017
+ ...newCtx
5018
+ }
5019
+ });
5020
+ if (isAsync(result)) {
5021
+ return result.then((result2) => {
5022
+ return {
5023
+ status: "valid",
5024
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
5025
+ get error() {
5026
+ return new ZodError(newCtx.common.issues);
5027
+ },
5028
+ input: newCtx.data
5029
+ })
5030
+ };
5031
+ });
5032
+ } else {
5033
+ return {
5034
+ status: "valid",
5035
+ value: result.status === "valid" ? result.value : this._def.catchValue({
5036
+ get error() {
5037
+ return new ZodError(newCtx.common.issues);
5038
+ },
5039
+ input: newCtx.data
5040
+ })
5041
+ };
5042
+ }
5043
+ }
5044
+ removeCatch() {
5045
+ return this._def.innerType;
5046
+ }
5047
+ };
5048
+ ZodCatch.create = (type, params) => {
5049
+ return new ZodCatch({
5050
+ innerType: type,
5051
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
5052
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
5053
+ ...processCreateParams(params)
5054
+ });
5055
+ };
5056
+ var ZodNaN = class extends ZodType {
5057
+ _parse(input) {
5058
+ const parsedType = this._getType(input);
5059
+ if (parsedType !== ZodParsedType.nan) {
5060
+ const ctx = this._getOrReturnCtx(input);
5061
+ addIssueToContext(ctx, {
5062
+ code: ZodIssueCode.invalid_type,
5063
+ expected: ZodParsedType.nan,
5064
+ received: ctx.parsedType
5065
+ });
5066
+ return INVALID;
5067
+ }
5068
+ return { status: "valid", value: input.data };
5069
+ }
5070
+ };
5071
+ ZodNaN.create = (params) => {
5072
+ return new ZodNaN({
5073
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
5074
+ ...processCreateParams(params)
5075
+ });
5076
+ };
5077
+ var BRAND = Symbol("zod_brand");
5078
+ var ZodBranded = class extends ZodType {
5079
+ _parse(input) {
5080
+ const { ctx } = this._processInputParams(input);
5081
+ const data = ctx.data;
5082
+ return this._def.type._parse({
5083
+ data,
5084
+ path: ctx.path,
5085
+ parent: ctx
5086
+ });
5087
+ }
5088
+ unwrap() {
5089
+ return this._def.type;
5090
+ }
5091
+ };
5092
+ var ZodPipeline = class _ZodPipeline extends ZodType {
5093
+ _parse(input) {
5094
+ const { status, ctx } = this._processInputParams(input);
5095
+ if (ctx.common.async) {
5096
+ const handleAsync = async () => {
5097
+ const inResult = await this._def.in._parseAsync({
5098
+ data: ctx.data,
5099
+ path: ctx.path,
5100
+ parent: ctx
5101
+ });
5102
+ if (inResult.status === "aborted")
5103
+ return INVALID;
5104
+ if (inResult.status === "dirty") {
5105
+ status.dirty();
5106
+ return DIRTY(inResult.value);
5107
+ } else {
5108
+ return this._def.out._parseAsync({
5109
+ data: inResult.value,
5110
+ path: ctx.path,
5111
+ parent: ctx
5112
+ });
5113
+ }
5114
+ };
5115
+ return handleAsync();
5116
+ } else {
5117
+ const inResult = this._def.in._parseSync({
5118
+ data: ctx.data,
5119
+ path: ctx.path,
5120
+ parent: ctx
5121
+ });
5122
+ if (inResult.status === "aborted")
5123
+ return INVALID;
5124
+ if (inResult.status === "dirty") {
5125
+ status.dirty();
5126
+ return {
5127
+ status: "dirty",
5128
+ value: inResult.value
5129
+ };
5130
+ } else {
5131
+ return this._def.out._parseSync({
5132
+ data: inResult.value,
5133
+ path: ctx.path,
5134
+ parent: ctx
5135
+ });
5136
+ }
5137
+ }
5138
+ }
5139
+ static create(a, b) {
5140
+ return new _ZodPipeline({
5141
+ in: a,
5142
+ out: b,
5143
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
5144
+ });
5145
+ }
5146
+ };
5147
+ var ZodReadonly = class extends ZodType {
5148
+ _parse(input) {
5149
+ const result = this._def.innerType._parse(input);
5150
+ if (isValid(result)) {
5151
+ result.value = Object.freeze(result.value);
5152
+ }
5153
+ return result;
5154
+ }
5155
+ };
5156
+ ZodReadonly.create = (type, params) => {
5157
+ return new ZodReadonly({
5158
+ innerType: type,
5159
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
5160
+ ...processCreateParams(params)
5161
+ });
5162
+ };
5163
+ var custom = (check, params = {}, fatal) => {
5164
+ if (check)
5165
+ return ZodAny.create().superRefine((data, ctx) => {
5166
+ var _a, _b;
5167
+ if (!check(data)) {
5168
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
5169
+ const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
5170
+ const p2 = typeof p === "string" ? { message: p } : p;
5171
+ ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
5172
+ }
5173
+ });
5174
+ return ZodAny.create();
5175
+ };
5176
+ var late = {
5177
+ object: ZodObject.lazycreate
5178
+ };
5179
+ var ZodFirstPartyTypeKind;
5180
+ (function(ZodFirstPartyTypeKind2) {
5181
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
5182
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
5183
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
5184
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
5185
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
5186
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
5187
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
5188
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
5189
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
5190
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
5191
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
5192
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
5193
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
5194
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
5195
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
5196
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
5197
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
5198
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
5199
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
5200
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
5201
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
5202
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
5203
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
5204
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
5205
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
5206
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
5207
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
5208
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
5209
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
5210
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
5211
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
5212
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
5213
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
5214
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
5215
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
5216
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
5217
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
5218
+ var instanceOfType = (cls, params = {
5219
+ message: `Input not instance of ${cls.name}`
5220
+ }) => custom((data) => data instanceof cls, params);
5221
+ var stringType = ZodString.create;
5222
+ var numberType = ZodNumber.create;
5223
+ var nanType = ZodNaN.create;
5224
+ var bigIntType = ZodBigInt.create;
5225
+ var booleanType = ZodBoolean.create;
5226
+ var dateType = ZodDate.create;
5227
+ var symbolType = ZodSymbol.create;
5228
+ var undefinedType = ZodUndefined.create;
5229
+ var nullType = ZodNull.create;
5230
+ var anyType = ZodAny.create;
5231
+ var unknownType = ZodUnknown.create;
5232
+ var neverType = ZodNever.create;
5233
+ var voidType = ZodVoid.create;
5234
+ var arrayType = ZodArray.create;
5235
+ var objectType = ZodObject.create;
5236
+ var strictObjectType = ZodObject.strictCreate;
5237
+ var unionType = ZodUnion.create;
5238
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
5239
+ var intersectionType = ZodIntersection.create;
5240
+ var tupleType = ZodTuple.create;
5241
+ var recordType = ZodRecord.create;
5242
+ var mapType = ZodMap.create;
5243
+ var setType = ZodSet.create;
5244
+ var functionType = ZodFunction.create;
5245
+ var lazyType = ZodLazy.create;
5246
+ var literalType = ZodLiteral.create;
5247
+ var enumType = ZodEnum.create;
5248
+ var nativeEnumType = ZodNativeEnum.create;
5249
+ var promiseType = ZodPromise.create;
5250
+ var effectsType = ZodEffects.create;
5251
+ var optionalType = ZodOptional.create;
5252
+ var nullableType = ZodNullable.create;
5253
+ var preprocessType = ZodEffects.createWithPreprocess;
5254
+ var pipelineType = ZodPipeline.create;
5255
+ var ostring = () => stringType().optional();
5256
+ var onumber = () => numberType().optional();
5257
+ var oboolean = () => booleanType().optional();
5258
+ var coerce = {
5259
+ string: (arg) => ZodString.create({ ...arg, coerce: true }),
5260
+ number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
5261
+ boolean: (arg) => ZodBoolean.create({
5262
+ ...arg,
5263
+ coerce: true
5264
+ }),
5265
+ bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
5266
+ date: (arg) => ZodDate.create({ ...arg, coerce: true })
5267
+ };
5268
+ var NEVER = INVALID;
5269
+ var z = /* @__PURE__ */ Object.freeze({
5270
+ __proto__: null,
5271
+ defaultErrorMap: errorMap,
5272
+ setErrorMap,
5273
+ getErrorMap,
5274
+ makeIssue,
5275
+ EMPTY_PATH,
5276
+ addIssueToContext,
5277
+ ParseStatus,
5278
+ INVALID,
5279
+ DIRTY,
5280
+ OK,
5281
+ isAborted,
5282
+ isDirty,
5283
+ isValid,
5284
+ isAsync,
5285
+ get util() {
5286
+ return util;
5287
+ },
5288
+ get objectUtil() {
5289
+ return objectUtil;
5290
+ },
5291
+ ZodParsedType,
5292
+ getParsedType,
5293
+ ZodType,
5294
+ ZodString,
5295
+ ZodNumber,
5296
+ ZodBigInt,
5297
+ ZodBoolean,
5298
+ ZodDate,
5299
+ ZodSymbol,
5300
+ ZodUndefined,
5301
+ ZodNull,
5302
+ ZodAny,
5303
+ ZodUnknown,
5304
+ ZodNever,
5305
+ ZodVoid,
5306
+ ZodArray,
5307
+ ZodObject,
5308
+ ZodUnion,
5309
+ ZodDiscriminatedUnion,
5310
+ ZodIntersection,
5311
+ ZodTuple,
5312
+ ZodRecord,
5313
+ ZodMap,
5314
+ ZodSet,
5315
+ ZodFunction,
5316
+ ZodLazy,
5317
+ ZodLiteral,
5318
+ ZodEnum,
5319
+ ZodNativeEnum,
5320
+ ZodPromise,
5321
+ ZodEffects,
5322
+ ZodTransformer: ZodEffects,
5323
+ ZodOptional,
5324
+ ZodNullable,
5325
+ ZodDefault,
5326
+ ZodCatch,
5327
+ ZodNaN,
5328
+ BRAND,
5329
+ ZodBranded,
5330
+ ZodPipeline,
5331
+ ZodReadonly,
5332
+ custom,
5333
+ Schema: ZodType,
5334
+ ZodSchema: ZodType,
5335
+ late,
5336
+ get ZodFirstPartyTypeKind() {
5337
+ return ZodFirstPartyTypeKind;
5338
+ },
5339
+ coerce,
5340
+ any: anyType,
5341
+ array: arrayType,
5342
+ bigint: bigIntType,
5343
+ boolean: booleanType,
5344
+ date: dateType,
5345
+ discriminatedUnion: discriminatedUnionType,
5346
+ effect: effectsType,
5347
+ "enum": enumType,
5348
+ "function": functionType,
5349
+ "instanceof": instanceOfType,
5350
+ intersection: intersectionType,
5351
+ lazy: lazyType,
5352
+ literal: literalType,
5353
+ map: mapType,
5354
+ nan: nanType,
5355
+ nativeEnum: nativeEnumType,
5356
+ never: neverType,
5357
+ "null": nullType,
5358
+ nullable: nullableType,
5359
+ number: numberType,
5360
+ object: objectType,
5361
+ oboolean,
5362
+ onumber,
5363
+ optional: optionalType,
5364
+ ostring,
5365
+ pipeline: pipelineType,
5366
+ preprocess: preprocessType,
5367
+ promise: promiseType,
5368
+ record: recordType,
5369
+ set: setType,
5370
+ strictObject: strictObjectType,
5371
+ string: stringType,
5372
+ symbol: symbolType,
5373
+ transformer: effectsType,
5374
+ tuple: tupleType,
5375
+ "undefined": undefinedType,
5376
+ union: unionType,
5377
+ unknown: unknownType,
5378
+ "void": voidType,
5379
+ NEVER,
5380
+ ZodIssueCode,
5381
+ quotelessJson,
5382
+ ZodError
5383
+ });
5384
+
5385
+ // packages/config/src/schema.ts
5386
+ var DarkColorSchema = z.string().trim().toLowerCase().regex(/^#([0-9a-f]{3}){1,2}$/i).length(7).default("#1d232a").describe("The dark background color of the workspace");
5387
+ var LightColorSchema = z.string().trim().toLowerCase().regex(/^#([0-9a-f]{3}){1,2}$/i).length(7).default("#f4f4f5").describe("The light background color of the workspace");
5388
+ var PrimaryColorSchema = z.string().trim().toLowerCase().regex(/^#([0-9a-f]{3}){1,2}$/i).length(7).default("#1fb2a6").describe("The primary color of the workspace");
5389
+ var SecondaryColorSchema = z.string().trim().toLowerCase().regex(/^#([0-9a-f]{3}){1,2}$/i).length(7).default("#0ea5e9").describe("The secondary color of the workspace");
5390
+ var TertiaryColorSchema = z.string().trim().toLowerCase().regex(/^#([0-9a-f]{3}){1,2}$/i).length(7).default("#ec5990").describe("The tertiary color of the workspace");
5391
+ var AccentColorSchema = z.string().trim().toLowerCase().regex(/^#([0-9a-f]{3}){1,2}$/i).length(7).default("#6366f1").describe("The accent color of the workspace");
5392
+ var SuccessColorSchema = z.string().trim().toLowerCase().regex(/^#([0-9a-f]{3}){1,2}$/i).length(7).default("#087f5b").describe("The success color of the workspace");
5393
+ var InfoColorSchema = z.string().trim().toLowerCase().regex(/^#([0-9a-f]{3}){1,2}$/i).length(7).default("#0ea5e9").describe("The informational color of the workspace");
5394
+ var WarningColorSchema = z.string().trim().toLowerCase().regex(/^#([0-9a-f]{3}){1,2}$/i).length(7).default("#fcc419").describe("The warning color of the workspace");
5395
+ var ErrorColorSchema = z.string().trim().toLowerCase().regex(/^#([0-9a-f]{3}){1,2}$/i).length(7).default("#990000").describe("The error color of the workspace");
5396
+ var FatalColorSchema = z.string().trim().toLowerCase().regex(/^#([0-9a-f]{3}){1,2}$/i).length(7).default("#7d1a1a").describe("The fatal color of the workspace");
5397
+ var DarkThemeColorConfigSchema = z.object({
5398
+ foreground: LightColorSchema,
5399
+ background: DarkColorSchema,
5400
+ primary: PrimaryColorSchema,
5401
+ secondary: SecondaryColorSchema,
5402
+ tertiary: TertiaryColorSchema,
5403
+ accent: AccentColorSchema,
5404
+ success: SuccessColorSchema,
5405
+ info: InfoColorSchema,
5406
+ warning: WarningColorSchema,
5407
+ error: ErrorColorSchema,
5408
+ fatal: FatalColorSchema
5409
+ });
5410
+ var LightThemeColorConfigSchema = z.object({
5411
+ foreground: DarkColorSchema,
5412
+ background: LightColorSchema,
5413
+ primary: PrimaryColorSchema,
5414
+ secondary: SecondaryColorSchema,
5415
+ tertiary: TertiaryColorSchema,
5416
+ accent: AccentColorSchema,
5417
+ success: SuccessColorSchema,
5418
+ info: InfoColorSchema,
5419
+ warning: WarningColorSchema,
5420
+ error: ErrorColorSchema,
5421
+ fatal: FatalColorSchema
5422
+ });
5423
+ var MultiThemeColorConfigSchema = z.object({
5424
+ dark: DarkThemeColorConfigSchema,
5425
+ light: LightThemeColorConfigSchema
5426
+ });
5427
+ var SingleThemeColorConfigSchema = z.object({
5428
+ dark: DarkColorSchema,
5429
+ light: LightColorSchema,
5430
+ primary: PrimaryColorSchema,
5431
+ secondary: SecondaryColorSchema,
5432
+ tertiary: TertiaryColorSchema,
5433
+ accent: AccentColorSchema,
5434
+ success: SuccessColorSchema,
5435
+ info: InfoColorSchema,
5436
+ warning: WarningColorSchema,
5437
+ error: ErrorColorSchema,
5438
+ fatal: FatalColorSchema
5439
+ });
5440
+ var ColorConfigSchema = SingleThemeColorConfigSchema.or(
5441
+ MultiThemeColorConfigSchema
5442
+ ).describe("Colors used for various workspace elements");
5443
+ var ColorConfigMapSchema = z.union([
5444
+ z.object({ "base": ColorConfigSchema }),
5445
+ z.record(z.string(), ColorConfigSchema)
5446
+ ]);
5447
+ var StormConfigSchema = z.object({
5448
+ extends: z.string().trim().optional().describe(
5449
+ "The path to a base JSON file to use as a configuration preset file"
5450
+ ),
5451
+ name: z.string().trim().toLowerCase().optional().describe("The name of the package"),
5452
+ namespace: z.string().trim().toLowerCase().optional().describe("The namespace of the package"),
5453
+ organization: z.string().trim().default("storm-software").describe("The organization of the workspace"),
5454
+ repository: z.string().trim().url().optional().describe("The repo URL of the workspace (i.e. GitHub)"),
5455
+ license: z.string().trim().default("Apache License 2.0").describe("The root directory of the package"),
5456
+ homepage: z.string().trim().url().default("https://stormsoftware.com").describe("The homepage of the workspace"),
5457
+ branch: z.string().trim().default("main").describe("The branch of the workspace"),
5458
+ preid: z.string().optional().describe("A tag specifying the version pre-release identifier"),
5459
+ owner: z.string().trim().default("@storm-software/development").describe("The owner of the package"),
5460
+ worker: z.string().trim().default("Stormie-Bot").describe(
5461
+ "The worker of the package (this is the bot that will be used to perform various tasks)"
5462
+ ),
5463
+ env: z.enum(["development", "staging", "production"]).default("production").describe("The current runtime environment of the package"),
5464
+ ci: z.boolean().default(true).describe(
5465
+ "An indicator specifying if the current environment is a CI environment"
5466
+ ),
5467
+ workspaceRoot: z.string().trim().optional().describe("The root directory of the workspace"),
5468
+ packageDirectory: z.string().trim().optional().describe("The root directory of the package"),
5469
+ externalPackagePatterns: z.array(z.string()).default([]).describe(
5470
+ "The build will use these package patterns to determine if they should be external to the bundle"
5471
+ ),
5472
+ skipCache: z.boolean().default(false).describe("Should all known types of workspace caching be skipped?"),
5473
+ cacheDirectory: z.string().trim().default("node_modules/.cache/storm").describe("The directory used to store the workspace's cached file data"),
5474
+ buildDirectory: z.string().trim().default("dist").describe("The build directory for the workspace"),
5475
+ outputDirectory: z.string().trim().default("node_modules/.storm").describe("The runtime directory of Storm"),
5476
+ runtimeVersion: z.string().trim().regex(
5477
+ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
5478
+ ).default("1.0.0").describe("The global version of the Storm runtime"),
5479
+ packageManager: z.enum(["npm", "yarn", "pnpm", "bun"]).default("npm").describe("The package manager used by the repository"),
5480
+ timezone: z.string().trim().default("America/New_York").describe("The default timezone of the workspace"),
5481
+ locale: z.string().trim().default("en-US").describe("The default locale of the workspace"),
5482
+ logLevel: z.enum([
5483
+ "silent",
5484
+ "fatal",
5485
+ "error",
5486
+ "warn",
5487
+ "info",
5488
+ "debug",
5489
+ "trace",
5490
+ "all"
5491
+ ]).default("debug").describe(
5492
+ "The log level used to filter out lower priority log messages. If not provided, this is defaulted using the `environment` config value (if `environment` is set to `production` then `level` is `error`, else `level` is `debug`)."
5493
+ ),
5494
+ configFile: z.string().trim().nullable().default(null).describe(
5495
+ "The filepath of the Storm config. When this field is null, no config file was found in the current workspace."
5496
+ ),
5497
+ colors: ColorConfigSchema.or(ColorConfigMapSchema).describe(
5498
+ "Storm theme config values used for styling various package elements"
5499
+ ),
5500
+ extensions: z.record(z.any()).optional().default({}).describe("Configuration of each used extension")
5501
+ }).describe(
5502
+ "Storm Workspace config values used during various dev-ops processes. This type is a combination of the StormPackageConfig and StormProject types. It represents the config of the entire monorepo."
5503
+ );
5504
+
5505
+ // packages/config-tools/src/utilities/get-default-config.ts
5506
+ var DEFAULT_COLOR_CONFIG = {
5507
+ dark: "#1d232a",
5508
+ light: "#f4f4f5",
5509
+ primary: "#1fb2a6",
5510
+ secondary: "#0ea5e9",
5511
+ tertiary: "#ec5990",
5512
+ accent: "#6366f1",
5513
+ success: "#087f5b",
5514
+ info: "#0ea5e9",
5515
+ warning: "#fcc419",
5516
+ error: "#990000",
5517
+ fatal: "#7d1a1a"
5518
+ };
5519
+ var DEFAULT_STORM_CONFIG = {
5520
+ name: "storm",
5521
+ namespace: "storm-software",
5522
+ license: "Apache License 2.0",
5523
+ homepage: "https://stormsoftware.com",
5524
+ owner: "@storm-software/development",
5525
+ worker: "stormie-bot",
5526
+ runtimeDirectory: "node_modules/.storm",
5527
+ cacheDirectory: "node_modules/.cache/storm",
5528
+ skipCache: false,
5529
+ packageManager: "npm",
5530
+ timezone: "America/New_York",
5531
+ locale: "en-US",
5532
+ env: "production",
5533
+ branch: "main",
5534
+ organization: "storm-software",
5535
+ ci: true,
5536
+ configFile: null,
5537
+ runtimeVersion: "1.0.0",
5538
+ colors: { ...DEFAULT_COLOR_CONFIG },
5539
+ extensions: {}
5540
+ };
5541
+
1652
5542
  // packages/config-tools/src/utilities/logger.ts
1653
5543
  var getLogFn = (logLevel = LogLevel.INFO, config = {}) => {
1654
5544
  let _chalk = getChalk();
5545
+ const colors = !config.colors?.dark && !config.colors?.["base"] && !config.colors?.["base"]?.dark ? DEFAULT_COLOR_CONFIG : config.colors?.dark && typeof config.colors.dark === "string" ? config.colors : config.colors?.["base"]?.dark && typeof config.colors["base"].dark === "string" ? config.colors["base"].dark : config.colors?.["base"] ? config.colors?.["base"] : DEFAULT_COLOR_CONFIG;
1655
5546
  const configLogLevel = config.logLevel ?? process.env?.STORM_LOG_LEVEL ?? LogLevelLabel.INFO;
1656
5547
  if (typeof logLevel === "number" && (logLevel >= getLogLevel(configLogLevel) || logLevel <= LogLevel.SILENT) || typeof logLevel === "string" && getLogLevel(logLevel) >= getLogLevel(configLogLevel)) {
1657
5548
  return (_) => {
@@ -1661,9 +5552,7 @@ var getLogFn = (logLevel = LogLevel.INFO, config = {}) => {
1661
5552
  return (message) => {
1662
5553
  console.error(
1663
5554
  `
1664
- ${_chalk.bold.hex(config?.colors?.error ? config.colors.error : "#7d1a1a")(">")} ${_chalk.bold.bgHex(config?.colors?.fatal ? config.colors.fatal : "#7d1a1a").whiteBright(" \u{1F480} Fatal ")} ${_chalk.hex(
1665
- config?.colors?.error ? config.colors.error : "#1fb2a6"
1666
- )(message)}
5555
+ ${_chalk.bold.hex(colors.error)(">")} ${_chalk.bold.bgHex(colors.fatal).whiteBright(" \u{1F480} Fatal ")} ${_chalk.hex(colors.error)(message)}
1667
5556
 
1668
5557
  `
1669
5558
  );
@@ -1673,9 +5562,7 @@ ${_chalk.bold.hex(config?.colors?.error ? config.colors.error : "#7d1a1a")(">")}
1673
5562
  return (message) => {
1674
5563
  console.error(
1675
5564
  `
1676
- ${_chalk.bold.hex(config?.colors?.error ? config.colors.error : "#7d1a1a")(">")} ${_chalk.bold.bgHex(config?.colors?.error ? config.colors.error : "#7d1a1a").whiteBright(" \u2718 Error ")} ${_chalk.hex(
1677
- config?.colors?.error ? config.colors.error : "#7d1a1a"
1678
- )(message)}
5565
+ ${_chalk.bold.hex(colors.error)(">")} ${_chalk.bold.bgHex(colors.error).whiteBright(" \u2718 Error ")} ${_chalk.hex(colors.error)(message)}
1679
5566
  `
1680
5567
  );
1681
5568
  };
@@ -1684,9 +5571,7 @@ ${_chalk.bold.hex(config?.colors?.error ? config.colors.error : "#7d1a1a")(">")}
1684
5571
  return (message) => {
1685
5572
  console.warn(
1686
5573
  `
1687
- ${_chalk.bold.hex(config?.colors?.warning ? config.colors.warning : "#fcc419")("> ")} ${_chalk.bold.bgHex(config?.colors?.warning ? config.colors.warning : "#fcc419").whiteBright(" \u26A0 Warn ")} ${_chalk.hex(
1688
- config?.colors?.warning ? config.colors.warning : "#fcc419"
1689
- )(message)}
5574
+ ${_chalk.bold.hex(colors.warning)("> ")} ${_chalk.bold.bgHex(colors.warning).whiteBright(" \u26A0 Warn ")} ${_chalk.hex(colors.warning)(message)}
1690
5575
  `
1691
5576
  );
1692
5577
  };
@@ -1695,9 +5580,7 @@ ${_chalk.bold.hex(config?.colors?.warning ? config.colors.warning : "#fcc419")("
1695
5580
  return (message) => {
1696
5581
  console.info(
1697
5582
  `
1698
- ${_chalk.bold.hex(config?.colors?.success ? config.colors.success : "#087f5b")(">")} ${_chalk.bold.bgHex(config?.colors?.success ? config.colors.success : "#087f5b").whiteBright(" \u2713 Success ")} ${_chalk.hex(
1699
- config?.colors?.success ? config.colors.success : "#087f5b"
1700
- )(message)}
5583
+ ${_chalk.bold.hex(colors.success)(">")} ${_chalk.bold.bgHex(colors.success).whiteBright(" \u2713 Success ")} ${_chalk.hex(colors.success)(message)}
1701
5584
  `
1702
5585
  );
1703
5586
  };
@@ -1706,9 +5589,7 @@ ${_chalk.bold.hex(config?.colors?.success ? config.colors.success : "#087f5b")("
1706
5589
  return (message) => {
1707
5590
  console.info(
1708
5591
  `
1709
- ${_chalk.bold.hex(config?.colors?.info ? config.colors.info : "#0ea5e9")(">")} ${_chalk.bold.bgHex(config?.colors?.info ? config.colors.info : "#0ea5e9").whiteBright(" \u2139 Info ")} ${_chalk.hex(
1710
- config?.colors?.info ? config.colors.info : "#0ea5e9"
1711
- )(message)}
5592
+ ${_chalk.bold.hex(colors.info)(">")} ${_chalk.bold.bgHex(colors.info).whiteBright(" \u2139 Info ")} ${_chalk.hex(colors.info)(message)}
1712
5593
  `
1713
5594
  );
1714
5595
  };
@@ -1717,9 +5598,7 @@ ${_chalk.bold.hex(config?.colors?.info ? config.colors.info : "#0ea5e9")(">")} $
1717
5598
  return (message) => {
1718
5599
  console.debug(
1719
5600
  `
1720
- ${_chalk.bold.hex(config?.colors?.primary ? config.colors.primary : "#1fb2a6")(">")} ${_chalk.bold.bgHex(config?.colors?.primary ? config.colors.primary : "#1fb2a6").whiteBright(" \u{1F6E0} Debug ")} ${_chalk.hex(
1721
- config?.colors?.primary ? config.colors.primary : "#1fb2a6"
1722
- )(message)}
5601
+ ${_chalk.bold.hex(colors.primary)(">")} ${_chalk.bold.bgHex(colors.primary).whiteBright(" \u{1F6E0} Debug ")} ${_chalk.hex(colors.primary)(message)}
1723
5602
  `
1724
5603
  );
1725
5604
  };
@@ -1727,9 +5606,7 @@ ${_chalk.bold.hex(config?.colors?.primary ? config.colors.primary : "#1fb2a6")("
1727
5606
  return (message) => {
1728
5607
  console.log(
1729
5608
  `
1730
- ${_chalk.bold.hex(config?.colors?.primary ? config.colors.primary : "#1fb2a6")(">")} ${_chalk.bold.bgHex(config?.colors?.primary ? config.colors.primary : "#1fb2a6").whiteBright(" \u2709 System ")} ${_chalk.hex(
1731
- config?.colors?.primary ? config.colors.primary : "#1fb2a6"
1732
- )(message)}
5609
+ ${_chalk.bold.hex(colors.primary)(">")} ${_chalk.bold.bgHex(colors.primary).whiteBright(" \u2709 System ")} ${_chalk.hex(colors.primary)(message)}
1733
5610
  `
1734
5611
  );
1735
5612
  };