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