@luzmo/embed 5.1.3-beta.3 → 5.1.4

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.
@@ -42,8 +42,7 @@ var __decorateClass = (decorators, target, key, kind) => {
42
42
  // libs/embed-libs/embed/src/index.libs.ts
43
43
  var index_libs_exports = {};
44
44
  __export(index_libs_exports, {
45
- LuzmoDashboardWebComponent: () => LuzmoDashboardWebComponent,
46
- LuzmoVizItemWebComponent: () => LuzmoVizItemWebComponent
45
+ LuzmoDashboardWebComponent: () => LuzmoDashboardWebComponent
47
46
  });
48
47
  module.exports = __toCommonJS(index_libs_exports);
49
48
 
@@ -625,7 +624,7 @@ var formatDashboardList = (dashboards, integrationId, user, dashboardComponent)
625
624
  }
626
625
  return treatedDashboards;
627
626
  };
628
- var VERSION = "0.0.0-unknown-luzmo";
627
+ var VERSION = "0.0.0-shared-luzmo";
629
628
  var sanitizeUrl = (url) => {
630
629
  const invalidPrototcolRegex = /^(%20|\s)*(javascript|data)/im;
631
630
  const ctrlCharactersRegex = /[^\u0020-\u007E]/gim;
@@ -738,7 +737,7 @@ var createIframeUrl = (dashboardContent) => {
738
737
  searchString.push("editMode=" + editMode);
739
738
  }
740
739
  const keyTokenUrlAnchor = key && token ? "#" + key + ":" + token : "";
741
- searchString.push("version=" + (dashboardContent.libVersion || VERSION));
740
+ searchString.push("version=" + (dashboardContent.VERSION || VERSION));
742
741
  const iframeUrl = itemEmbedding ? `${appServer}i/${dashboardId || dashboardSlug}/${itemId}?${encodeURIComponent(
743
742
  searchString.join("&")
744
743
  )}${keyTokenUrlAnchor}` : `${appServer}i/${dashboardId || dashboardSlug}?${encodeURIComponent(
@@ -891,7 +890,7 @@ var exportDashboard = (dashboardComponent, iframe, format) => {
891
890
  {
892
891
  action: "exportDashboard",
893
892
  format: format || "png",
894
- _version: dashboardComponent.libVersion,
893
+ _version: dashboardComponent.VERSION,
895
894
  requestId
896
895
  },
897
896
  "*"
@@ -1029,7 +1028,7 @@ var getData = (dashboardComponent, iframe, itemId) => {
1029
1028
  {
1030
1029
  action: "getData",
1031
1030
  id: itemId,
1032
- _version: dashboardComponent.libVersion,
1031
+ _version: dashboardComponent.VERSION,
1033
1032
  requestId
1034
1033
  },
1035
1034
  "*"
@@ -1055,7 +1054,7 @@ var getFilters = (dashboardComponent, iframe) => {
1055
1054
  if (iframe?.contentWindow) {
1056
1055
  const requestId = uuidv4();
1057
1056
  iframe.contentWindow.postMessage(
1058
- { action: "getFilters", _version: dashboardComponent.libVersion, requestId },
1057
+ { action: "getFilters", _version: dashboardComponent.VERSION, requestId },
1059
1058
  "*"
1060
1059
  );
1061
1060
  return new Promise((resolve, reject) => {
@@ -1081,7 +1080,7 @@ var refreshData = (dashboardComponent, iframe, itemId) => {
1081
1080
  {
1082
1081
  action: "refreshData",
1083
1082
  id: itemId ?? null,
1084
- _version: dashboardComponent.libVersion
1083
+ _version: dashboardComponent.VERSION
1085
1084
  },
1086
1085
  "*"
1087
1086
  );
@@ -1094,7 +1093,7 @@ var refreshData = (dashboardComponent, iframe, itemId) => {
1094
1093
  var reloadDashboard = (dashboardComponent, iframe) => {
1095
1094
  if (iframe) {
1096
1095
  iframe.contentWindow.postMessage(
1097
- { action: "reloadDashboard", _version: dashboardComponent.libVersion },
1096
+ { action: "reloadDashboard", _version: dashboardComponent.VERSION },
1098
1097
  "*"
1099
1098
  );
1100
1099
  return Promise.resolve();
@@ -1110,7 +1109,7 @@ var setAuthorization = (dashboardComponent, iframe, key, token) => {
1110
1109
  action: "setAuthorization",
1111
1110
  key,
1112
1111
  token,
1113
- _version: dashboardComponent.libVersion
1112
+ _version: dashboardComponent.VERSION
1114
1113
  },
1115
1114
  "*"
1116
1115
  );
@@ -1138,7 +1137,7 @@ var setEditMode = (dashboardComponent, iframe, editMode) => {
1138
1137
  {
1139
1138
  action: "setEditMode",
1140
1139
  editMode,
1141
- _version: dashboardComponent.libVersion,
1140
+ _version: dashboardComponent.VERSION,
1142
1141
  requestId
1143
1142
  },
1144
1143
  "*"
@@ -1159,7 +1158,7 @@ var setFilters = (dashboardComponent, iframe, itemId, filters) => {
1159
1158
  action: "setFilters",
1160
1159
  itemId,
1161
1160
  filters,
1162
- _version: dashboardComponent.libVersion,
1161
+ _version: dashboardComponent.VERSION,
1163
1162
  requestId
1164
1163
  },
1165
1164
  "*"
@@ -1189,7 +1188,7 @@ var setPreview = (dashboardComponent, iframe, preview) => {
1189
1188
  action: "setPreview",
1190
1189
  preview,
1191
1190
  requestId,
1192
- _version: dashboardComponent.libVersion
1191
+ _version: dashboardComponent.VERSION
1193
1192
  },
1194
1193
  "*"
1195
1194
  );
@@ -1490,4053 +1489,6 @@ var _extendAndValidate = (dashboardContent) => {
1490
1489
  }
1491
1490
  };
1492
1491
 
1493
- // node_modules/zod/lib/index.mjs
1494
- var util;
1495
- (function(util2) {
1496
- util2.assertEqual = (val) => val;
1497
- function assertIs(_arg) {
1498
- }
1499
- util2.assertIs = assertIs;
1500
- function assertNever(_x) {
1501
- throw new Error();
1502
- }
1503
- util2.assertNever = assertNever;
1504
- util2.arrayToEnum = (items) => {
1505
- const obj = {};
1506
- for (const item of items) {
1507
- obj[item] = item;
1508
- }
1509
- return obj;
1510
- };
1511
- util2.getValidEnumValues = (obj) => {
1512
- const validKeys = util2.objectKeys(obj).filter((k2) => typeof obj[obj[k2]] !== "number");
1513
- const filtered = {};
1514
- for (const k2 of validKeys) {
1515
- filtered[k2] = obj[k2];
1516
- }
1517
- return util2.objectValues(filtered);
1518
- };
1519
- util2.objectValues = (obj) => {
1520
- return util2.objectKeys(obj).map(function(e7) {
1521
- return obj[e7];
1522
- });
1523
- };
1524
- util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
1525
- const keys = [];
1526
- for (const key in object) {
1527
- if (Object.prototype.hasOwnProperty.call(object, key)) {
1528
- keys.push(key);
1529
- }
1530
- }
1531
- return keys;
1532
- };
1533
- util2.find = (arr, checker) => {
1534
- for (const item of arr) {
1535
- if (checker(item))
1536
- return item;
1537
- }
1538
- return void 0;
1539
- };
1540
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
1541
- function joinValues(array, separator = " | ") {
1542
- return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
1543
- }
1544
- util2.joinValues = joinValues;
1545
- util2.jsonStringifyReplacer = (_2, value) => {
1546
- if (typeof value === "bigint") {
1547
- return value.toString();
1548
- }
1549
- return value;
1550
- };
1551
- })(util || (util = {}));
1552
- var objectUtil;
1553
- (function(objectUtil2) {
1554
- objectUtil2.mergeShapes = (first, second) => {
1555
- return {
1556
- ...first,
1557
- ...second
1558
- // second overwrites first
1559
- };
1560
- };
1561
- })(objectUtil || (objectUtil = {}));
1562
- var ZodParsedType = util.arrayToEnum([
1563
- "string",
1564
- "nan",
1565
- "number",
1566
- "integer",
1567
- "float",
1568
- "boolean",
1569
- "date",
1570
- "bigint",
1571
- "symbol",
1572
- "function",
1573
- "undefined",
1574
- "null",
1575
- "array",
1576
- "object",
1577
- "unknown",
1578
- "promise",
1579
- "void",
1580
- "never",
1581
- "map",
1582
- "set"
1583
- ]);
1584
- var getParsedType = (data) => {
1585
- const t5 = typeof data;
1586
- switch (t5) {
1587
- case "undefined":
1588
- return ZodParsedType.undefined;
1589
- case "string":
1590
- return ZodParsedType.string;
1591
- case "number":
1592
- return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
1593
- case "boolean":
1594
- return ZodParsedType.boolean;
1595
- case "function":
1596
- return ZodParsedType.function;
1597
- case "bigint":
1598
- return ZodParsedType.bigint;
1599
- case "symbol":
1600
- return ZodParsedType.symbol;
1601
- case "object":
1602
- if (Array.isArray(data)) {
1603
- return ZodParsedType.array;
1604
- }
1605
- if (data === null) {
1606
- return ZodParsedType.null;
1607
- }
1608
- if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
1609
- return ZodParsedType.promise;
1610
- }
1611
- if (typeof Map !== "undefined" && data instanceof Map) {
1612
- return ZodParsedType.map;
1613
- }
1614
- if (typeof Set !== "undefined" && data instanceof Set) {
1615
- return ZodParsedType.set;
1616
- }
1617
- if (typeof Date !== "undefined" && data instanceof Date) {
1618
- return ZodParsedType.date;
1619
- }
1620
- return ZodParsedType.object;
1621
- default:
1622
- return ZodParsedType.unknown;
1623
- }
1624
- };
1625
- var ZodIssueCode = util.arrayToEnum([
1626
- "invalid_type",
1627
- "invalid_literal",
1628
- "custom",
1629
- "invalid_union",
1630
- "invalid_union_discriminator",
1631
- "invalid_enum_value",
1632
- "unrecognized_keys",
1633
- "invalid_arguments",
1634
- "invalid_return_type",
1635
- "invalid_date",
1636
- "invalid_string",
1637
- "too_small",
1638
- "too_big",
1639
- "invalid_intersection_types",
1640
- "not_multiple_of",
1641
- "not_finite"
1642
- ]);
1643
- var quotelessJson = (obj) => {
1644
- const json = JSON.stringify(obj, null, 2);
1645
- return json.replace(/"([^"]+)":/g, "$1:");
1646
- };
1647
- var ZodError = class _ZodError extends Error {
1648
- constructor(issues) {
1649
- super();
1650
- this.issues = [];
1651
- this.addIssue = (sub) => {
1652
- this.issues = [...this.issues, sub];
1653
- };
1654
- this.addIssues = (subs = []) => {
1655
- this.issues = [...this.issues, ...subs];
1656
- };
1657
- const actualProto = new.target.prototype;
1658
- if (Object.setPrototypeOf) {
1659
- Object.setPrototypeOf(this, actualProto);
1660
- } else {
1661
- this.__proto__ = actualProto;
1662
- }
1663
- this.name = "ZodError";
1664
- this.issues = issues;
1665
- }
1666
- get errors() {
1667
- return this.issues;
1668
- }
1669
- format(_mapper) {
1670
- const mapper = _mapper || function(issue) {
1671
- return issue.message;
1672
- };
1673
- const fieldErrors = { _errors: [] };
1674
- const processError = (error) => {
1675
- for (const issue of error.issues) {
1676
- if (issue.code === "invalid_union") {
1677
- issue.unionErrors.map(processError);
1678
- } else if (issue.code === "invalid_return_type") {
1679
- processError(issue.returnTypeError);
1680
- } else if (issue.code === "invalid_arguments") {
1681
- processError(issue.argumentsError);
1682
- } else if (issue.path.length === 0) {
1683
- fieldErrors._errors.push(mapper(issue));
1684
- } else {
1685
- let curr = fieldErrors;
1686
- let i6 = 0;
1687
- while (i6 < issue.path.length) {
1688
- const el = issue.path[i6];
1689
- const terminal = i6 === issue.path.length - 1;
1690
- if (!terminal) {
1691
- curr[el] = curr[el] || { _errors: [] };
1692
- } else {
1693
- curr[el] = curr[el] || { _errors: [] };
1694
- curr[el]._errors.push(mapper(issue));
1695
- }
1696
- curr = curr[el];
1697
- i6++;
1698
- }
1699
- }
1700
- }
1701
- };
1702
- processError(this);
1703
- return fieldErrors;
1704
- }
1705
- static assert(value) {
1706
- if (!(value instanceof _ZodError)) {
1707
- throw new Error(`Not a ZodError: ${value}`);
1708
- }
1709
- }
1710
- toString() {
1711
- return this.message;
1712
- }
1713
- get message() {
1714
- return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
1715
- }
1716
- get isEmpty() {
1717
- return this.issues.length === 0;
1718
- }
1719
- flatten(mapper = (issue) => issue.message) {
1720
- const fieldErrors = {};
1721
- const formErrors = [];
1722
- for (const sub of this.issues) {
1723
- if (sub.path.length > 0) {
1724
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
1725
- fieldErrors[sub.path[0]].push(mapper(sub));
1726
- } else {
1727
- formErrors.push(mapper(sub));
1728
- }
1729
- }
1730
- return { formErrors, fieldErrors };
1731
- }
1732
- get formErrors() {
1733
- return this.flatten();
1734
- }
1735
- };
1736
- ZodError.create = (issues) => {
1737
- const error = new ZodError(issues);
1738
- return error;
1739
- };
1740
- var errorMap = (issue, _ctx) => {
1741
- let message;
1742
- switch (issue.code) {
1743
- case ZodIssueCode.invalid_type:
1744
- if (issue.received === ZodParsedType.undefined) {
1745
- message = "Required";
1746
- } else {
1747
- message = `Expected ${issue.expected}, received ${issue.received}`;
1748
- }
1749
- break;
1750
- case ZodIssueCode.invalid_literal:
1751
- message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
1752
- break;
1753
- case ZodIssueCode.unrecognized_keys:
1754
- message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
1755
- break;
1756
- case ZodIssueCode.invalid_union:
1757
- message = `Invalid input`;
1758
- break;
1759
- case ZodIssueCode.invalid_union_discriminator:
1760
- message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
1761
- break;
1762
- case ZodIssueCode.invalid_enum_value:
1763
- message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
1764
- break;
1765
- case ZodIssueCode.invalid_arguments:
1766
- message = `Invalid function arguments`;
1767
- break;
1768
- case ZodIssueCode.invalid_return_type:
1769
- message = `Invalid function return type`;
1770
- break;
1771
- case ZodIssueCode.invalid_date:
1772
- message = `Invalid date`;
1773
- break;
1774
- case ZodIssueCode.invalid_string:
1775
- if (typeof issue.validation === "object") {
1776
- if ("includes" in issue.validation) {
1777
- message = `Invalid input: must include "${issue.validation.includes}"`;
1778
- if (typeof issue.validation.position === "number") {
1779
- message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
1780
- }
1781
- } else if ("startsWith" in issue.validation) {
1782
- message = `Invalid input: must start with "${issue.validation.startsWith}"`;
1783
- } else if ("endsWith" in issue.validation) {
1784
- message = `Invalid input: must end with "${issue.validation.endsWith}"`;
1785
- } else {
1786
- util.assertNever(issue.validation);
1787
- }
1788
- } else if (issue.validation !== "regex") {
1789
- message = `Invalid ${issue.validation}`;
1790
- } else {
1791
- message = "Invalid";
1792
- }
1793
- break;
1794
- case ZodIssueCode.too_small:
1795
- if (issue.type === "array")
1796
- message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
1797
- else if (issue.type === "string")
1798
- message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
1799
- else if (issue.type === "number")
1800
- message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
1801
- else if (issue.type === "date")
1802
- message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
1803
- else
1804
- message = "Invalid input";
1805
- break;
1806
- case ZodIssueCode.too_big:
1807
- if (issue.type === "array")
1808
- message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
1809
- else if (issue.type === "string")
1810
- message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
1811
- else if (issue.type === "number")
1812
- message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1813
- else if (issue.type === "bigint")
1814
- message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1815
- else if (issue.type === "date")
1816
- message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
1817
- else
1818
- message = "Invalid input";
1819
- break;
1820
- case ZodIssueCode.custom:
1821
- message = `Invalid input`;
1822
- break;
1823
- case ZodIssueCode.invalid_intersection_types:
1824
- message = `Intersection results could not be merged`;
1825
- break;
1826
- case ZodIssueCode.not_multiple_of:
1827
- message = `Number must be a multiple of ${issue.multipleOf}`;
1828
- break;
1829
- case ZodIssueCode.not_finite:
1830
- message = "Number must be finite";
1831
- break;
1832
- default:
1833
- message = _ctx.defaultError;
1834
- util.assertNever(issue);
1835
- }
1836
- return { message };
1837
- };
1838
- var overrideErrorMap = errorMap;
1839
- function setErrorMap(map) {
1840
- overrideErrorMap = map;
1841
- }
1842
- function getErrorMap() {
1843
- return overrideErrorMap;
1844
- }
1845
- var makeIssue = (params) => {
1846
- const { data, path, errorMaps, issueData } = params;
1847
- const fullPath = [...path, ...issueData.path || []];
1848
- const fullIssue = {
1849
- ...issueData,
1850
- path: fullPath
1851
- };
1852
- if (issueData.message !== void 0) {
1853
- return {
1854
- ...issueData,
1855
- path: fullPath,
1856
- message: issueData.message
1857
- };
1858
- }
1859
- let errorMessage = "";
1860
- const maps = errorMaps.filter((m2) => !!m2).slice().reverse();
1861
- for (const map of maps) {
1862
- errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
1863
- }
1864
- return {
1865
- ...issueData,
1866
- path: fullPath,
1867
- message: errorMessage
1868
- };
1869
- };
1870
- var EMPTY_PATH = [];
1871
- function addIssueToContext(ctx, issueData) {
1872
- const overrideMap = getErrorMap();
1873
- const issue = makeIssue({
1874
- issueData,
1875
- data: ctx.data,
1876
- path: ctx.path,
1877
- errorMaps: [
1878
- ctx.common.contextualErrorMap,
1879
- ctx.schemaErrorMap,
1880
- overrideMap,
1881
- overrideMap === errorMap ? void 0 : errorMap
1882
- // then global default map
1883
- ].filter((x2) => !!x2)
1884
- });
1885
- ctx.common.issues.push(issue);
1886
- }
1887
- var ParseStatus = class _ParseStatus {
1888
- constructor() {
1889
- this.value = "valid";
1890
- }
1891
- dirty() {
1892
- if (this.value === "valid")
1893
- this.value = "dirty";
1894
- }
1895
- abort() {
1896
- if (this.value !== "aborted")
1897
- this.value = "aborted";
1898
- }
1899
- static mergeArray(status, results) {
1900
- const arrayValue = [];
1901
- for (const s4 of results) {
1902
- if (s4.status === "aborted")
1903
- return INVALID;
1904
- if (s4.status === "dirty")
1905
- status.dirty();
1906
- arrayValue.push(s4.value);
1907
- }
1908
- return { status: status.value, value: arrayValue };
1909
- }
1910
- static async mergeObjectAsync(status, pairs) {
1911
- const syncPairs = [];
1912
- for (const pair of pairs) {
1913
- const key = await pair.key;
1914
- const value = await pair.value;
1915
- syncPairs.push({
1916
- key,
1917
- value
1918
- });
1919
- }
1920
- return _ParseStatus.mergeObjectSync(status, syncPairs);
1921
- }
1922
- static mergeObjectSync(status, pairs) {
1923
- const finalObject = {};
1924
- for (const pair of pairs) {
1925
- const { key, value } = pair;
1926
- if (key.status === "aborted")
1927
- return INVALID;
1928
- if (value.status === "aborted")
1929
- return INVALID;
1930
- if (key.status === "dirty")
1931
- status.dirty();
1932
- if (value.status === "dirty")
1933
- status.dirty();
1934
- if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
1935
- finalObject[key.value] = value.value;
1936
- }
1937
- }
1938
- return { status: status.value, value: finalObject };
1939
- }
1940
- };
1941
- var INVALID = Object.freeze({
1942
- status: "aborted"
1943
- });
1944
- var DIRTY = (value) => ({ status: "dirty", value });
1945
- var OK = (value) => ({ status: "valid", value });
1946
- var isAborted = (x2) => x2.status === "aborted";
1947
- var isDirty = (x2) => x2.status === "dirty";
1948
- var isValid = (x2) => x2.status === "valid";
1949
- var isAsync = (x2) => typeof Promise !== "undefined" && x2 instanceof Promise;
1950
- function __classPrivateFieldGet(receiver, state, kind, f3) {
1951
- if (kind === "a" && !f3)
1952
- throw new TypeError("Private accessor was defined without a getter");
1953
- if (typeof state === "function" ? receiver !== state || !f3 : !state.has(receiver))
1954
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
1955
- return kind === "m" ? f3 : kind === "a" ? f3.call(receiver) : f3 ? f3.value : state.get(receiver);
1956
- }
1957
- function __classPrivateFieldSet(receiver, state, value, kind, f3) {
1958
- if (kind === "m")
1959
- throw new TypeError("Private method is not writable");
1960
- if (kind === "a" && !f3)
1961
- throw new TypeError("Private accessor was defined without a setter");
1962
- if (typeof state === "function" ? receiver !== state || !f3 : !state.has(receiver))
1963
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
1964
- return kind === "a" ? f3.call(receiver, value) : f3 ? f3.value = value : state.set(receiver, value), value;
1965
- }
1966
- var errorUtil;
1967
- (function(errorUtil2) {
1968
- errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
1969
- errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
1970
- })(errorUtil || (errorUtil = {}));
1971
- var _ZodEnum_cache;
1972
- var _ZodNativeEnum_cache;
1973
- var ParseInputLazyPath = class {
1974
- constructor(parent, value, path, key) {
1975
- this._cachedPath = [];
1976
- this.parent = parent;
1977
- this.data = value;
1978
- this._path = path;
1979
- this._key = key;
1980
- }
1981
- get path() {
1982
- if (!this._cachedPath.length) {
1983
- if (this._key instanceof Array) {
1984
- this._cachedPath.push(...this._path, ...this._key);
1985
- } else {
1986
- this._cachedPath.push(...this._path, this._key);
1987
- }
1988
- }
1989
- return this._cachedPath;
1990
- }
1991
- };
1992
- var handleResult = (ctx, result) => {
1993
- if (isValid(result)) {
1994
- return { success: true, data: result.value };
1995
- } else {
1996
- if (!ctx.common.issues.length) {
1997
- throw new Error("Validation failed but no issues detected.");
1998
- }
1999
- return {
2000
- success: false,
2001
- get error() {
2002
- if (this._error)
2003
- return this._error;
2004
- const error = new ZodError(ctx.common.issues);
2005
- this._error = error;
2006
- return this._error;
2007
- }
2008
- };
2009
- }
2010
- };
2011
- function processCreateParams(params) {
2012
- if (!params)
2013
- return {};
2014
- const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
2015
- if (errorMap2 && (invalid_type_error || required_error)) {
2016
- throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
2017
- }
2018
- if (errorMap2)
2019
- return { errorMap: errorMap2, description };
2020
- const customMap = (iss, ctx) => {
2021
- var _a, _b;
2022
- const { message } = params;
2023
- if (iss.code === "invalid_enum_value") {
2024
- return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
2025
- }
2026
- if (typeof ctx.data === "undefined") {
2027
- return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
2028
- }
2029
- if (iss.code !== "invalid_type")
2030
- return { message: ctx.defaultError };
2031
- return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
2032
- };
2033
- return { errorMap: customMap, description };
2034
- }
2035
- var ZodType = class {
2036
- constructor(def) {
2037
- this.spa = this.safeParseAsync;
2038
- this._def = def;
2039
- this.parse = this.parse.bind(this);
2040
- this.safeParse = this.safeParse.bind(this);
2041
- this.parseAsync = this.parseAsync.bind(this);
2042
- this.safeParseAsync = this.safeParseAsync.bind(this);
2043
- this.spa = this.spa.bind(this);
2044
- this.refine = this.refine.bind(this);
2045
- this.refinement = this.refinement.bind(this);
2046
- this.superRefine = this.superRefine.bind(this);
2047
- this.optional = this.optional.bind(this);
2048
- this.nullable = this.nullable.bind(this);
2049
- this.nullish = this.nullish.bind(this);
2050
- this.array = this.array.bind(this);
2051
- this.promise = this.promise.bind(this);
2052
- this.or = this.or.bind(this);
2053
- this.and = this.and.bind(this);
2054
- this.transform = this.transform.bind(this);
2055
- this.brand = this.brand.bind(this);
2056
- this.default = this.default.bind(this);
2057
- this.catch = this.catch.bind(this);
2058
- this.describe = this.describe.bind(this);
2059
- this.pipe = this.pipe.bind(this);
2060
- this.readonly = this.readonly.bind(this);
2061
- this.isNullable = this.isNullable.bind(this);
2062
- this.isOptional = this.isOptional.bind(this);
2063
- }
2064
- get description() {
2065
- return this._def.description;
2066
- }
2067
- _getType(input) {
2068
- return getParsedType(input.data);
2069
- }
2070
- _getOrReturnCtx(input, ctx) {
2071
- return ctx || {
2072
- common: input.parent.common,
2073
- data: input.data,
2074
- parsedType: getParsedType(input.data),
2075
- schemaErrorMap: this._def.errorMap,
2076
- path: input.path,
2077
- parent: input.parent
2078
- };
2079
- }
2080
- _processInputParams(input) {
2081
- return {
2082
- status: new ParseStatus(),
2083
- ctx: {
2084
- common: input.parent.common,
2085
- data: input.data,
2086
- parsedType: getParsedType(input.data),
2087
- schemaErrorMap: this._def.errorMap,
2088
- path: input.path,
2089
- parent: input.parent
2090
- }
2091
- };
2092
- }
2093
- _parseSync(input) {
2094
- const result = this._parse(input);
2095
- if (isAsync(result)) {
2096
- throw new Error("Synchronous parse encountered promise.");
2097
- }
2098
- return result;
2099
- }
2100
- _parseAsync(input) {
2101
- const result = this._parse(input);
2102
- return Promise.resolve(result);
2103
- }
2104
- parse(data, params) {
2105
- const result = this.safeParse(data, params);
2106
- if (result.success)
2107
- return result.data;
2108
- throw result.error;
2109
- }
2110
- safeParse(data, params) {
2111
- var _a;
2112
- const ctx = {
2113
- common: {
2114
- issues: [],
2115
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
2116
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
2117
- },
2118
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
2119
- schemaErrorMap: this._def.errorMap,
2120
- parent: null,
2121
- data,
2122
- parsedType: getParsedType(data)
2123
- };
2124
- const result = this._parseSync({ data, path: ctx.path, parent: ctx });
2125
- return handleResult(ctx, result);
2126
- }
2127
- async parseAsync(data, params) {
2128
- const result = await this.safeParseAsync(data, params);
2129
- if (result.success)
2130
- return result.data;
2131
- throw result.error;
2132
- }
2133
- async safeParseAsync(data, params) {
2134
- const ctx = {
2135
- common: {
2136
- issues: [],
2137
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
2138
- async: true
2139
- },
2140
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
2141
- schemaErrorMap: this._def.errorMap,
2142
- parent: null,
2143
- data,
2144
- parsedType: getParsedType(data)
2145
- };
2146
- const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
2147
- const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
2148
- return handleResult(ctx, result);
2149
- }
2150
- refine(check, message) {
2151
- const getIssueProperties = (val) => {
2152
- if (typeof message === "string" || typeof message === "undefined") {
2153
- return { message };
2154
- } else if (typeof message === "function") {
2155
- return message(val);
2156
- } else {
2157
- return message;
2158
- }
2159
- };
2160
- return this._refinement((val, ctx) => {
2161
- const result = check(val);
2162
- const setError = () => ctx.addIssue({
2163
- code: ZodIssueCode.custom,
2164
- ...getIssueProperties(val)
2165
- });
2166
- if (typeof Promise !== "undefined" && result instanceof Promise) {
2167
- return result.then((data) => {
2168
- if (!data) {
2169
- setError();
2170
- return false;
2171
- } else {
2172
- return true;
2173
- }
2174
- });
2175
- }
2176
- if (!result) {
2177
- setError();
2178
- return false;
2179
- } else {
2180
- return true;
2181
- }
2182
- });
2183
- }
2184
- refinement(check, refinementData) {
2185
- return this._refinement((val, ctx) => {
2186
- if (!check(val)) {
2187
- ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
2188
- return false;
2189
- } else {
2190
- return true;
2191
- }
2192
- });
2193
- }
2194
- _refinement(refinement) {
2195
- return new ZodEffects({
2196
- schema: this,
2197
- typeName: ZodFirstPartyTypeKind.ZodEffects,
2198
- effect: { type: "refinement", refinement }
2199
- });
2200
- }
2201
- superRefine(refinement) {
2202
- return this._refinement(refinement);
2203
- }
2204
- optional() {
2205
- return ZodOptional.create(this, this._def);
2206
- }
2207
- nullable() {
2208
- return ZodNullable.create(this, this._def);
2209
- }
2210
- nullish() {
2211
- return this.nullable().optional();
2212
- }
2213
- array() {
2214
- return ZodArray.create(this, this._def);
2215
- }
2216
- promise() {
2217
- return ZodPromise.create(this, this._def);
2218
- }
2219
- or(option) {
2220
- return ZodUnion.create([this, option], this._def);
2221
- }
2222
- and(incoming) {
2223
- return ZodIntersection.create(this, incoming, this._def);
2224
- }
2225
- transform(transform) {
2226
- return new ZodEffects({
2227
- ...processCreateParams(this._def),
2228
- schema: this,
2229
- typeName: ZodFirstPartyTypeKind.ZodEffects,
2230
- effect: { type: "transform", transform }
2231
- });
2232
- }
2233
- default(def) {
2234
- const defaultValueFunc = typeof def === "function" ? def : () => def;
2235
- return new ZodDefault({
2236
- ...processCreateParams(this._def),
2237
- innerType: this,
2238
- defaultValue: defaultValueFunc,
2239
- typeName: ZodFirstPartyTypeKind.ZodDefault
2240
- });
2241
- }
2242
- brand() {
2243
- return new ZodBranded({
2244
- typeName: ZodFirstPartyTypeKind.ZodBranded,
2245
- type: this,
2246
- ...processCreateParams(this._def)
2247
- });
2248
- }
2249
- catch(def) {
2250
- const catchValueFunc = typeof def === "function" ? def : () => def;
2251
- return new ZodCatch({
2252
- ...processCreateParams(this._def),
2253
- innerType: this,
2254
- catchValue: catchValueFunc,
2255
- typeName: ZodFirstPartyTypeKind.ZodCatch
2256
- });
2257
- }
2258
- describe(description) {
2259
- const This = this.constructor;
2260
- return new This({
2261
- ...this._def,
2262
- description
2263
- });
2264
- }
2265
- pipe(target) {
2266
- return ZodPipeline.create(this, target);
2267
- }
2268
- readonly() {
2269
- return ZodReadonly.create(this);
2270
- }
2271
- isOptional() {
2272
- return this.safeParse(void 0).success;
2273
- }
2274
- isNullable() {
2275
- return this.safeParse(null).success;
2276
- }
2277
- };
2278
- var cuidRegex = /^c[^\s-]{8,}$/i;
2279
- var cuid2Regex = /^[0-9a-z]+$/;
2280
- var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
2281
- 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;
2282
- var nanoidRegex = /^[a-z0-9_-]{21}$/i;
2283
- var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
2284
- var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
2285
- var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
2286
- var emojiRegex;
2287
- var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
2288
- 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})))$/;
2289
- var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
2290
- var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
2291
- var dateRegex = new RegExp(`^${dateRegexSource}$`);
2292
- function timeRegexSource(args) {
2293
- let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
2294
- if (args.precision) {
2295
- regex = `${regex}\\.\\d{${args.precision}}`;
2296
- } else if (args.precision == null) {
2297
- regex = `${regex}(\\.\\d+)?`;
2298
- }
2299
- return regex;
2300
- }
2301
- function timeRegex(args) {
2302
- return new RegExp(`^${timeRegexSource(args)}$`);
2303
- }
2304
- function datetimeRegex(args) {
2305
- let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
2306
- const opts = [];
2307
- opts.push(args.local ? `Z?` : `Z`);
2308
- if (args.offset)
2309
- opts.push(`([+-]\\d{2}:?\\d{2})`);
2310
- regex = `${regex}(${opts.join("|")})`;
2311
- return new RegExp(`^${regex}$`);
2312
- }
2313
- function isValidIP(ip, version2) {
2314
- if ((version2 === "v4" || !version2) && ipv4Regex.test(ip)) {
2315
- return true;
2316
- }
2317
- if ((version2 === "v6" || !version2) && ipv6Regex.test(ip)) {
2318
- return true;
2319
- }
2320
- return false;
2321
- }
2322
- var ZodString = class _ZodString extends ZodType {
2323
- _parse(input) {
2324
- if (this._def.coerce) {
2325
- input.data = String(input.data);
2326
- }
2327
- const parsedType = this._getType(input);
2328
- if (parsedType !== ZodParsedType.string) {
2329
- const ctx2 = this._getOrReturnCtx(input);
2330
- addIssueToContext(ctx2, {
2331
- code: ZodIssueCode.invalid_type,
2332
- expected: ZodParsedType.string,
2333
- received: ctx2.parsedType
2334
- });
2335
- return INVALID;
2336
- }
2337
- const status = new ParseStatus();
2338
- let ctx = void 0;
2339
- for (const check of this._def.checks) {
2340
- if (check.kind === "min") {
2341
- if (input.data.length < check.value) {
2342
- ctx = this._getOrReturnCtx(input, ctx);
2343
- addIssueToContext(ctx, {
2344
- code: ZodIssueCode.too_small,
2345
- minimum: check.value,
2346
- type: "string",
2347
- inclusive: true,
2348
- exact: false,
2349
- message: check.message
2350
- });
2351
- status.dirty();
2352
- }
2353
- } else if (check.kind === "max") {
2354
- if (input.data.length > check.value) {
2355
- ctx = this._getOrReturnCtx(input, ctx);
2356
- addIssueToContext(ctx, {
2357
- code: ZodIssueCode.too_big,
2358
- maximum: check.value,
2359
- type: "string",
2360
- inclusive: true,
2361
- exact: false,
2362
- message: check.message
2363
- });
2364
- status.dirty();
2365
- }
2366
- } else if (check.kind === "length") {
2367
- const tooBig = input.data.length > check.value;
2368
- const tooSmall = input.data.length < check.value;
2369
- if (tooBig || tooSmall) {
2370
- ctx = this._getOrReturnCtx(input, ctx);
2371
- if (tooBig) {
2372
- addIssueToContext(ctx, {
2373
- code: ZodIssueCode.too_big,
2374
- maximum: check.value,
2375
- type: "string",
2376
- inclusive: true,
2377
- exact: true,
2378
- message: check.message
2379
- });
2380
- } else if (tooSmall) {
2381
- addIssueToContext(ctx, {
2382
- code: ZodIssueCode.too_small,
2383
- minimum: check.value,
2384
- type: "string",
2385
- inclusive: true,
2386
- exact: true,
2387
- message: check.message
2388
- });
2389
- }
2390
- status.dirty();
2391
- }
2392
- } else if (check.kind === "email") {
2393
- if (!emailRegex.test(input.data)) {
2394
- ctx = this._getOrReturnCtx(input, ctx);
2395
- addIssueToContext(ctx, {
2396
- validation: "email",
2397
- code: ZodIssueCode.invalid_string,
2398
- message: check.message
2399
- });
2400
- status.dirty();
2401
- }
2402
- } else if (check.kind === "emoji") {
2403
- if (!emojiRegex) {
2404
- emojiRegex = new RegExp(_emojiRegex, "u");
2405
- }
2406
- if (!emojiRegex.test(input.data)) {
2407
- ctx = this._getOrReturnCtx(input, ctx);
2408
- addIssueToContext(ctx, {
2409
- validation: "emoji",
2410
- code: ZodIssueCode.invalid_string,
2411
- message: check.message
2412
- });
2413
- status.dirty();
2414
- }
2415
- } else if (check.kind === "uuid") {
2416
- if (!uuidRegex.test(input.data)) {
2417
- ctx = this._getOrReturnCtx(input, ctx);
2418
- addIssueToContext(ctx, {
2419
- validation: "uuid",
2420
- code: ZodIssueCode.invalid_string,
2421
- message: check.message
2422
- });
2423
- status.dirty();
2424
- }
2425
- } else if (check.kind === "nanoid") {
2426
- if (!nanoidRegex.test(input.data)) {
2427
- ctx = this._getOrReturnCtx(input, ctx);
2428
- addIssueToContext(ctx, {
2429
- validation: "nanoid",
2430
- code: ZodIssueCode.invalid_string,
2431
- message: check.message
2432
- });
2433
- status.dirty();
2434
- }
2435
- } else if (check.kind === "cuid") {
2436
- if (!cuidRegex.test(input.data)) {
2437
- ctx = this._getOrReturnCtx(input, ctx);
2438
- addIssueToContext(ctx, {
2439
- validation: "cuid",
2440
- code: ZodIssueCode.invalid_string,
2441
- message: check.message
2442
- });
2443
- status.dirty();
2444
- }
2445
- } else if (check.kind === "cuid2") {
2446
- if (!cuid2Regex.test(input.data)) {
2447
- ctx = this._getOrReturnCtx(input, ctx);
2448
- addIssueToContext(ctx, {
2449
- validation: "cuid2",
2450
- code: ZodIssueCode.invalid_string,
2451
- message: check.message
2452
- });
2453
- status.dirty();
2454
- }
2455
- } else if (check.kind === "ulid") {
2456
- if (!ulidRegex.test(input.data)) {
2457
- ctx = this._getOrReturnCtx(input, ctx);
2458
- addIssueToContext(ctx, {
2459
- validation: "ulid",
2460
- code: ZodIssueCode.invalid_string,
2461
- message: check.message
2462
- });
2463
- status.dirty();
2464
- }
2465
- } else if (check.kind === "url") {
2466
- try {
2467
- new URL(input.data);
2468
- } catch (_a) {
2469
- ctx = this._getOrReturnCtx(input, ctx);
2470
- addIssueToContext(ctx, {
2471
- validation: "url",
2472
- code: ZodIssueCode.invalid_string,
2473
- message: check.message
2474
- });
2475
- status.dirty();
2476
- }
2477
- } else if (check.kind === "regex") {
2478
- check.regex.lastIndex = 0;
2479
- const testResult = check.regex.test(input.data);
2480
- if (!testResult) {
2481
- ctx = this._getOrReturnCtx(input, ctx);
2482
- addIssueToContext(ctx, {
2483
- validation: "regex",
2484
- code: ZodIssueCode.invalid_string,
2485
- message: check.message
2486
- });
2487
- status.dirty();
2488
- }
2489
- } else if (check.kind === "trim") {
2490
- input.data = input.data.trim();
2491
- } else if (check.kind === "includes") {
2492
- if (!input.data.includes(check.value, check.position)) {
2493
- ctx = this._getOrReturnCtx(input, ctx);
2494
- addIssueToContext(ctx, {
2495
- code: ZodIssueCode.invalid_string,
2496
- validation: { includes: check.value, position: check.position },
2497
- message: check.message
2498
- });
2499
- status.dirty();
2500
- }
2501
- } else if (check.kind === "toLowerCase") {
2502
- input.data = input.data.toLowerCase();
2503
- } else if (check.kind === "toUpperCase") {
2504
- input.data = input.data.toUpperCase();
2505
- } else if (check.kind === "startsWith") {
2506
- if (!input.data.startsWith(check.value)) {
2507
- ctx = this._getOrReturnCtx(input, ctx);
2508
- addIssueToContext(ctx, {
2509
- code: ZodIssueCode.invalid_string,
2510
- validation: { startsWith: check.value },
2511
- message: check.message
2512
- });
2513
- status.dirty();
2514
- }
2515
- } else if (check.kind === "endsWith") {
2516
- if (!input.data.endsWith(check.value)) {
2517
- ctx = this._getOrReturnCtx(input, ctx);
2518
- addIssueToContext(ctx, {
2519
- code: ZodIssueCode.invalid_string,
2520
- validation: { endsWith: check.value },
2521
- message: check.message
2522
- });
2523
- status.dirty();
2524
- }
2525
- } else if (check.kind === "datetime") {
2526
- const regex = datetimeRegex(check);
2527
- if (!regex.test(input.data)) {
2528
- ctx = this._getOrReturnCtx(input, ctx);
2529
- addIssueToContext(ctx, {
2530
- code: ZodIssueCode.invalid_string,
2531
- validation: "datetime",
2532
- message: check.message
2533
- });
2534
- status.dirty();
2535
- }
2536
- } else if (check.kind === "date") {
2537
- const regex = dateRegex;
2538
- if (!regex.test(input.data)) {
2539
- ctx = this._getOrReturnCtx(input, ctx);
2540
- addIssueToContext(ctx, {
2541
- code: ZodIssueCode.invalid_string,
2542
- validation: "date",
2543
- message: check.message
2544
- });
2545
- status.dirty();
2546
- }
2547
- } else if (check.kind === "time") {
2548
- const regex = timeRegex(check);
2549
- if (!regex.test(input.data)) {
2550
- ctx = this._getOrReturnCtx(input, ctx);
2551
- addIssueToContext(ctx, {
2552
- code: ZodIssueCode.invalid_string,
2553
- validation: "time",
2554
- message: check.message
2555
- });
2556
- status.dirty();
2557
- }
2558
- } else if (check.kind === "duration") {
2559
- if (!durationRegex.test(input.data)) {
2560
- ctx = this._getOrReturnCtx(input, ctx);
2561
- addIssueToContext(ctx, {
2562
- validation: "duration",
2563
- code: ZodIssueCode.invalid_string,
2564
- message: check.message
2565
- });
2566
- status.dirty();
2567
- }
2568
- } else if (check.kind === "ip") {
2569
- if (!isValidIP(input.data, check.version)) {
2570
- ctx = this._getOrReturnCtx(input, ctx);
2571
- addIssueToContext(ctx, {
2572
- validation: "ip",
2573
- code: ZodIssueCode.invalid_string,
2574
- message: check.message
2575
- });
2576
- status.dirty();
2577
- }
2578
- } else if (check.kind === "base64") {
2579
- if (!base64Regex.test(input.data)) {
2580
- ctx = this._getOrReturnCtx(input, ctx);
2581
- addIssueToContext(ctx, {
2582
- validation: "base64",
2583
- code: ZodIssueCode.invalid_string,
2584
- message: check.message
2585
- });
2586
- status.dirty();
2587
- }
2588
- } else {
2589
- util.assertNever(check);
2590
- }
2591
- }
2592
- return { status: status.value, value: input.data };
2593
- }
2594
- _regex(regex, validation, message) {
2595
- return this.refinement((data) => regex.test(data), {
2596
- validation,
2597
- code: ZodIssueCode.invalid_string,
2598
- ...errorUtil.errToObj(message)
2599
- });
2600
- }
2601
- _addCheck(check) {
2602
- return new _ZodString({
2603
- ...this._def,
2604
- checks: [...this._def.checks, check]
2605
- });
2606
- }
2607
- email(message) {
2608
- return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
2609
- }
2610
- url(message) {
2611
- return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
2612
- }
2613
- emoji(message) {
2614
- return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
2615
- }
2616
- uuid(message) {
2617
- return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
2618
- }
2619
- nanoid(message) {
2620
- return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
2621
- }
2622
- cuid(message) {
2623
- return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
2624
- }
2625
- cuid2(message) {
2626
- return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
2627
- }
2628
- ulid(message) {
2629
- return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
2630
- }
2631
- base64(message) {
2632
- return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
2633
- }
2634
- ip(options) {
2635
- return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
2636
- }
2637
- datetime(options) {
2638
- var _a, _b;
2639
- if (typeof options === "string") {
2640
- return this._addCheck({
2641
- kind: "datetime",
2642
- precision: null,
2643
- offset: false,
2644
- local: false,
2645
- message: options
2646
- });
2647
- }
2648
- return this._addCheck({
2649
- kind: "datetime",
2650
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
2651
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
2652
- local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
2653
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
2654
- });
2655
- }
2656
- date(message) {
2657
- return this._addCheck({ kind: "date", message });
2658
- }
2659
- time(options) {
2660
- if (typeof options === "string") {
2661
- return this._addCheck({
2662
- kind: "time",
2663
- precision: null,
2664
- message: options
2665
- });
2666
- }
2667
- return this._addCheck({
2668
- kind: "time",
2669
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
2670
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
2671
- });
2672
- }
2673
- duration(message) {
2674
- return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
2675
- }
2676
- regex(regex, message) {
2677
- return this._addCheck({
2678
- kind: "regex",
2679
- regex,
2680
- ...errorUtil.errToObj(message)
2681
- });
2682
- }
2683
- includes(value, options) {
2684
- return this._addCheck({
2685
- kind: "includes",
2686
- value,
2687
- position: options === null || options === void 0 ? void 0 : options.position,
2688
- ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
2689
- });
2690
- }
2691
- startsWith(value, message) {
2692
- return this._addCheck({
2693
- kind: "startsWith",
2694
- value,
2695
- ...errorUtil.errToObj(message)
2696
- });
2697
- }
2698
- endsWith(value, message) {
2699
- return this._addCheck({
2700
- kind: "endsWith",
2701
- value,
2702
- ...errorUtil.errToObj(message)
2703
- });
2704
- }
2705
- min(minLength, message) {
2706
- return this._addCheck({
2707
- kind: "min",
2708
- value: minLength,
2709
- ...errorUtil.errToObj(message)
2710
- });
2711
- }
2712
- max(maxLength, message) {
2713
- return this._addCheck({
2714
- kind: "max",
2715
- value: maxLength,
2716
- ...errorUtil.errToObj(message)
2717
- });
2718
- }
2719
- length(len, message) {
2720
- return this._addCheck({
2721
- kind: "length",
2722
- value: len,
2723
- ...errorUtil.errToObj(message)
2724
- });
2725
- }
2726
- /**
2727
- * @deprecated Use z.string().min(1) instead.
2728
- * @see {@link ZodString.min}
2729
- */
2730
- nonempty(message) {
2731
- return this.min(1, errorUtil.errToObj(message));
2732
- }
2733
- trim() {
2734
- return new _ZodString({
2735
- ...this._def,
2736
- checks: [...this._def.checks, { kind: "trim" }]
2737
- });
2738
- }
2739
- toLowerCase() {
2740
- return new _ZodString({
2741
- ...this._def,
2742
- checks: [...this._def.checks, { kind: "toLowerCase" }]
2743
- });
2744
- }
2745
- toUpperCase() {
2746
- return new _ZodString({
2747
- ...this._def,
2748
- checks: [...this._def.checks, { kind: "toUpperCase" }]
2749
- });
2750
- }
2751
- get isDatetime() {
2752
- return !!this._def.checks.find((ch) => ch.kind === "datetime");
2753
- }
2754
- get isDate() {
2755
- return !!this._def.checks.find((ch) => ch.kind === "date");
2756
- }
2757
- get isTime() {
2758
- return !!this._def.checks.find((ch) => ch.kind === "time");
2759
- }
2760
- get isDuration() {
2761
- return !!this._def.checks.find((ch) => ch.kind === "duration");
2762
- }
2763
- get isEmail() {
2764
- return !!this._def.checks.find((ch) => ch.kind === "email");
2765
- }
2766
- get isURL() {
2767
- return !!this._def.checks.find((ch) => ch.kind === "url");
2768
- }
2769
- get isEmoji() {
2770
- return !!this._def.checks.find((ch) => ch.kind === "emoji");
2771
- }
2772
- get isUUID() {
2773
- return !!this._def.checks.find((ch) => ch.kind === "uuid");
2774
- }
2775
- get isNANOID() {
2776
- return !!this._def.checks.find((ch) => ch.kind === "nanoid");
2777
- }
2778
- get isCUID() {
2779
- return !!this._def.checks.find((ch) => ch.kind === "cuid");
2780
- }
2781
- get isCUID2() {
2782
- return !!this._def.checks.find((ch) => ch.kind === "cuid2");
2783
- }
2784
- get isULID() {
2785
- return !!this._def.checks.find((ch) => ch.kind === "ulid");
2786
- }
2787
- get isIP() {
2788
- return !!this._def.checks.find((ch) => ch.kind === "ip");
2789
- }
2790
- get isBase64() {
2791
- return !!this._def.checks.find((ch) => ch.kind === "base64");
2792
- }
2793
- get minLength() {
2794
- let min = null;
2795
- for (const ch of this._def.checks) {
2796
- if (ch.kind === "min") {
2797
- if (min === null || ch.value > min)
2798
- min = ch.value;
2799
- }
2800
- }
2801
- return min;
2802
- }
2803
- get maxLength() {
2804
- let max = null;
2805
- for (const ch of this._def.checks) {
2806
- if (ch.kind === "max") {
2807
- if (max === null || ch.value < max)
2808
- max = ch.value;
2809
- }
2810
- }
2811
- return max;
2812
- }
2813
- };
2814
- ZodString.create = (params) => {
2815
- var _a;
2816
- return new ZodString({
2817
- checks: [],
2818
- typeName: ZodFirstPartyTypeKind.ZodString,
2819
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
2820
- ...processCreateParams(params)
2821
- });
2822
- };
2823
- function floatSafeRemainder(val, step) {
2824
- const valDecCount = (val.toString().split(".")[1] || "").length;
2825
- const stepDecCount = (step.toString().split(".")[1] || "").length;
2826
- const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
2827
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
2828
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
2829
- return valInt % stepInt / Math.pow(10, decCount);
2830
- }
2831
- var ZodNumber = class _ZodNumber extends ZodType {
2832
- constructor() {
2833
- super(...arguments);
2834
- this.min = this.gte;
2835
- this.max = this.lte;
2836
- this.step = this.multipleOf;
2837
- }
2838
- _parse(input) {
2839
- if (this._def.coerce) {
2840
- input.data = Number(input.data);
2841
- }
2842
- const parsedType = this._getType(input);
2843
- if (parsedType !== ZodParsedType.number) {
2844
- const ctx2 = this._getOrReturnCtx(input);
2845
- addIssueToContext(ctx2, {
2846
- code: ZodIssueCode.invalid_type,
2847
- expected: ZodParsedType.number,
2848
- received: ctx2.parsedType
2849
- });
2850
- return INVALID;
2851
- }
2852
- let ctx = void 0;
2853
- const status = new ParseStatus();
2854
- for (const check of this._def.checks) {
2855
- if (check.kind === "int") {
2856
- if (!util.isInteger(input.data)) {
2857
- ctx = this._getOrReturnCtx(input, ctx);
2858
- addIssueToContext(ctx, {
2859
- code: ZodIssueCode.invalid_type,
2860
- expected: "integer",
2861
- received: "float",
2862
- message: check.message
2863
- });
2864
- status.dirty();
2865
- }
2866
- } else if (check.kind === "min") {
2867
- const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2868
- if (tooSmall) {
2869
- ctx = this._getOrReturnCtx(input, ctx);
2870
- addIssueToContext(ctx, {
2871
- code: ZodIssueCode.too_small,
2872
- minimum: check.value,
2873
- type: "number",
2874
- inclusive: check.inclusive,
2875
- exact: false,
2876
- message: check.message
2877
- });
2878
- status.dirty();
2879
- }
2880
- } else if (check.kind === "max") {
2881
- const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2882
- if (tooBig) {
2883
- ctx = this._getOrReturnCtx(input, ctx);
2884
- addIssueToContext(ctx, {
2885
- code: ZodIssueCode.too_big,
2886
- maximum: check.value,
2887
- type: "number",
2888
- inclusive: check.inclusive,
2889
- exact: false,
2890
- message: check.message
2891
- });
2892
- status.dirty();
2893
- }
2894
- } else if (check.kind === "multipleOf") {
2895
- if (floatSafeRemainder(input.data, check.value) !== 0) {
2896
- ctx = this._getOrReturnCtx(input, ctx);
2897
- addIssueToContext(ctx, {
2898
- code: ZodIssueCode.not_multiple_of,
2899
- multipleOf: check.value,
2900
- message: check.message
2901
- });
2902
- status.dirty();
2903
- }
2904
- } else if (check.kind === "finite") {
2905
- if (!Number.isFinite(input.data)) {
2906
- ctx = this._getOrReturnCtx(input, ctx);
2907
- addIssueToContext(ctx, {
2908
- code: ZodIssueCode.not_finite,
2909
- message: check.message
2910
- });
2911
- status.dirty();
2912
- }
2913
- } else {
2914
- util.assertNever(check);
2915
- }
2916
- }
2917
- return { status: status.value, value: input.data };
2918
- }
2919
- gte(value, message) {
2920
- return this.setLimit("min", value, true, errorUtil.toString(message));
2921
- }
2922
- gt(value, message) {
2923
- return this.setLimit("min", value, false, errorUtil.toString(message));
2924
- }
2925
- lte(value, message) {
2926
- return this.setLimit("max", value, true, errorUtil.toString(message));
2927
- }
2928
- lt(value, message) {
2929
- return this.setLimit("max", value, false, errorUtil.toString(message));
2930
- }
2931
- setLimit(kind, value, inclusive, message) {
2932
- return new _ZodNumber({
2933
- ...this._def,
2934
- checks: [
2935
- ...this._def.checks,
2936
- {
2937
- kind,
2938
- value,
2939
- inclusive,
2940
- message: errorUtil.toString(message)
2941
- }
2942
- ]
2943
- });
2944
- }
2945
- _addCheck(check) {
2946
- return new _ZodNumber({
2947
- ...this._def,
2948
- checks: [...this._def.checks, check]
2949
- });
2950
- }
2951
- int(message) {
2952
- return this._addCheck({
2953
- kind: "int",
2954
- message: errorUtil.toString(message)
2955
- });
2956
- }
2957
- positive(message) {
2958
- return this._addCheck({
2959
- kind: "min",
2960
- value: 0,
2961
- inclusive: false,
2962
- message: errorUtil.toString(message)
2963
- });
2964
- }
2965
- negative(message) {
2966
- return this._addCheck({
2967
- kind: "max",
2968
- value: 0,
2969
- inclusive: false,
2970
- message: errorUtil.toString(message)
2971
- });
2972
- }
2973
- nonpositive(message) {
2974
- return this._addCheck({
2975
- kind: "max",
2976
- value: 0,
2977
- inclusive: true,
2978
- message: errorUtil.toString(message)
2979
- });
2980
- }
2981
- nonnegative(message) {
2982
- return this._addCheck({
2983
- kind: "min",
2984
- value: 0,
2985
- inclusive: true,
2986
- message: errorUtil.toString(message)
2987
- });
2988
- }
2989
- multipleOf(value, message) {
2990
- return this._addCheck({
2991
- kind: "multipleOf",
2992
- value,
2993
- message: errorUtil.toString(message)
2994
- });
2995
- }
2996
- finite(message) {
2997
- return this._addCheck({
2998
- kind: "finite",
2999
- message: errorUtil.toString(message)
3000
- });
3001
- }
3002
- safe(message) {
3003
- return this._addCheck({
3004
- kind: "min",
3005
- inclusive: true,
3006
- value: Number.MIN_SAFE_INTEGER,
3007
- message: errorUtil.toString(message)
3008
- })._addCheck({
3009
- kind: "max",
3010
- inclusive: true,
3011
- value: Number.MAX_SAFE_INTEGER,
3012
- message: errorUtil.toString(message)
3013
- });
3014
- }
3015
- get minValue() {
3016
- let min = null;
3017
- for (const ch of this._def.checks) {
3018
- if (ch.kind === "min") {
3019
- if (min === null || ch.value > min)
3020
- min = ch.value;
3021
- }
3022
- }
3023
- return min;
3024
- }
3025
- get maxValue() {
3026
- let max = null;
3027
- for (const ch of this._def.checks) {
3028
- if (ch.kind === "max") {
3029
- if (max === null || ch.value < max)
3030
- max = ch.value;
3031
- }
3032
- }
3033
- return max;
3034
- }
3035
- get isInt() {
3036
- return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
3037
- }
3038
- get isFinite() {
3039
- let max = null, min = null;
3040
- for (const ch of this._def.checks) {
3041
- if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
3042
- return true;
3043
- } else if (ch.kind === "min") {
3044
- if (min === null || ch.value > min)
3045
- min = ch.value;
3046
- } else if (ch.kind === "max") {
3047
- if (max === null || ch.value < max)
3048
- max = ch.value;
3049
- }
3050
- }
3051
- return Number.isFinite(min) && Number.isFinite(max);
3052
- }
3053
- };
3054
- ZodNumber.create = (params) => {
3055
- return new ZodNumber({
3056
- checks: [],
3057
- typeName: ZodFirstPartyTypeKind.ZodNumber,
3058
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
3059
- ...processCreateParams(params)
3060
- });
3061
- };
3062
- var ZodBigInt = class _ZodBigInt extends ZodType {
3063
- constructor() {
3064
- super(...arguments);
3065
- this.min = this.gte;
3066
- this.max = this.lte;
3067
- }
3068
- _parse(input) {
3069
- if (this._def.coerce) {
3070
- input.data = BigInt(input.data);
3071
- }
3072
- const parsedType = this._getType(input);
3073
- if (parsedType !== ZodParsedType.bigint) {
3074
- const ctx2 = this._getOrReturnCtx(input);
3075
- addIssueToContext(ctx2, {
3076
- code: ZodIssueCode.invalid_type,
3077
- expected: ZodParsedType.bigint,
3078
- received: ctx2.parsedType
3079
- });
3080
- return INVALID;
3081
- }
3082
- let ctx = void 0;
3083
- const status = new ParseStatus();
3084
- for (const check of this._def.checks) {
3085
- if (check.kind === "min") {
3086
- const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
3087
- if (tooSmall) {
3088
- ctx = this._getOrReturnCtx(input, ctx);
3089
- addIssueToContext(ctx, {
3090
- code: ZodIssueCode.too_small,
3091
- type: "bigint",
3092
- minimum: check.value,
3093
- inclusive: check.inclusive,
3094
- message: check.message
3095
- });
3096
- status.dirty();
3097
- }
3098
- } else if (check.kind === "max") {
3099
- const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
3100
- if (tooBig) {
3101
- ctx = this._getOrReturnCtx(input, ctx);
3102
- addIssueToContext(ctx, {
3103
- code: ZodIssueCode.too_big,
3104
- type: "bigint",
3105
- maximum: check.value,
3106
- inclusive: check.inclusive,
3107
- message: check.message
3108
- });
3109
- status.dirty();
3110
- }
3111
- } else if (check.kind === "multipleOf") {
3112
- if (input.data % check.value !== BigInt(0)) {
3113
- ctx = this._getOrReturnCtx(input, ctx);
3114
- addIssueToContext(ctx, {
3115
- code: ZodIssueCode.not_multiple_of,
3116
- multipleOf: check.value,
3117
- message: check.message
3118
- });
3119
- status.dirty();
3120
- }
3121
- } else {
3122
- util.assertNever(check);
3123
- }
3124
- }
3125
- return { status: status.value, value: input.data };
3126
- }
3127
- gte(value, message) {
3128
- return this.setLimit("min", value, true, errorUtil.toString(message));
3129
- }
3130
- gt(value, message) {
3131
- return this.setLimit("min", value, false, errorUtil.toString(message));
3132
- }
3133
- lte(value, message) {
3134
- return this.setLimit("max", value, true, errorUtil.toString(message));
3135
- }
3136
- lt(value, message) {
3137
- return this.setLimit("max", value, false, errorUtil.toString(message));
3138
- }
3139
- setLimit(kind, value, inclusive, message) {
3140
- return new _ZodBigInt({
3141
- ...this._def,
3142
- checks: [
3143
- ...this._def.checks,
3144
- {
3145
- kind,
3146
- value,
3147
- inclusive,
3148
- message: errorUtil.toString(message)
3149
- }
3150
- ]
3151
- });
3152
- }
3153
- _addCheck(check) {
3154
- return new _ZodBigInt({
3155
- ...this._def,
3156
- checks: [...this._def.checks, check]
3157
- });
3158
- }
3159
- positive(message) {
3160
- return this._addCheck({
3161
- kind: "min",
3162
- value: BigInt(0),
3163
- inclusive: false,
3164
- message: errorUtil.toString(message)
3165
- });
3166
- }
3167
- negative(message) {
3168
- return this._addCheck({
3169
- kind: "max",
3170
- value: BigInt(0),
3171
- inclusive: false,
3172
- message: errorUtil.toString(message)
3173
- });
3174
- }
3175
- nonpositive(message) {
3176
- return this._addCheck({
3177
- kind: "max",
3178
- value: BigInt(0),
3179
- inclusive: true,
3180
- message: errorUtil.toString(message)
3181
- });
3182
- }
3183
- nonnegative(message) {
3184
- return this._addCheck({
3185
- kind: "min",
3186
- value: BigInt(0),
3187
- inclusive: true,
3188
- message: errorUtil.toString(message)
3189
- });
3190
- }
3191
- multipleOf(value, message) {
3192
- return this._addCheck({
3193
- kind: "multipleOf",
3194
- value,
3195
- message: errorUtil.toString(message)
3196
- });
3197
- }
3198
- get minValue() {
3199
- let min = null;
3200
- for (const ch of this._def.checks) {
3201
- if (ch.kind === "min") {
3202
- if (min === null || ch.value > min)
3203
- min = ch.value;
3204
- }
3205
- }
3206
- return min;
3207
- }
3208
- get maxValue() {
3209
- let max = null;
3210
- for (const ch of this._def.checks) {
3211
- if (ch.kind === "max") {
3212
- if (max === null || ch.value < max)
3213
- max = ch.value;
3214
- }
3215
- }
3216
- return max;
3217
- }
3218
- };
3219
- ZodBigInt.create = (params) => {
3220
- var _a;
3221
- return new ZodBigInt({
3222
- checks: [],
3223
- typeName: ZodFirstPartyTypeKind.ZodBigInt,
3224
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
3225
- ...processCreateParams(params)
3226
- });
3227
- };
3228
- var ZodBoolean = class extends ZodType {
3229
- _parse(input) {
3230
- if (this._def.coerce) {
3231
- input.data = Boolean(input.data);
3232
- }
3233
- const parsedType = this._getType(input);
3234
- if (parsedType !== ZodParsedType.boolean) {
3235
- const ctx = this._getOrReturnCtx(input);
3236
- addIssueToContext(ctx, {
3237
- code: ZodIssueCode.invalid_type,
3238
- expected: ZodParsedType.boolean,
3239
- received: ctx.parsedType
3240
- });
3241
- return INVALID;
3242
- }
3243
- return OK(input.data);
3244
- }
3245
- };
3246
- ZodBoolean.create = (params) => {
3247
- return new ZodBoolean({
3248
- typeName: ZodFirstPartyTypeKind.ZodBoolean,
3249
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
3250
- ...processCreateParams(params)
3251
- });
3252
- };
3253
- var ZodDate = class _ZodDate extends ZodType {
3254
- _parse(input) {
3255
- if (this._def.coerce) {
3256
- input.data = new Date(input.data);
3257
- }
3258
- const parsedType = this._getType(input);
3259
- if (parsedType !== ZodParsedType.date) {
3260
- const ctx2 = this._getOrReturnCtx(input);
3261
- addIssueToContext(ctx2, {
3262
- code: ZodIssueCode.invalid_type,
3263
- expected: ZodParsedType.date,
3264
- received: ctx2.parsedType
3265
- });
3266
- return INVALID;
3267
- }
3268
- if (isNaN(input.data.getTime())) {
3269
- const ctx2 = this._getOrReturnCtx(input);
3270
- addIssueToContext(ctx2, {
3271
- code: ZodIssueCode.invalid_date
3272
- });
3273
- return INVALID;
3274
- }
3275
- const status = new ParseStatus();
3276
- let ctx = void 0;
3277
- for (const check of this._def.checks) {
3278
- if (check.kind === "min") {
3279
- if (input.data.getTime() < check.value) {
3280
- ctx = this._getOrReturnCtx(input, ctx);
3281
- addIssueToContext(ctx, {
3282
- code: ZodIssueCode.too_small,
3283
- message: check.message,
3284
- inclusive: true,
3285
- exact: false,
3286
- minimum: check.value,
3287
- type: "date"
3288
- });
3289
- status.dirty();
3290
- }
3291
- } else if (check.kind === "max") {
3292
- if (input.data.getTime() > check.value) {
3293
- ctx = this._getOrReturnCtx(input, ctx);
3294
- addIssueToContext(ctx, {
3295
- code: ZodIssueCode.too_big,
3296
- message: check.message,
3297
- inclusive: true,
3298
- exact: false,
3299
- maximum: check.value,
3300
- type: "date"
3301
- });
3302
- status.dirty();
3303
- }
3304
- } else {
3305
- util.assertNever(check);
3306
- }
3307
- }
3308
- return {
3309
- status: status.value,
3310
- value: new Date(input.data.getTime())
3311
- };
3312
- }
3313
- _addCheck(check) {
3314
- return new _ZodDate({
3315
- ...this._def,
3316
- checks: [...this._def.checks, check]
3317
- });
3318
- }
3319
- min(minDate, message) {
3320
- return this._addCheck({
3321
- kind: "min",
3322
- value: minDate.getTime(),
3323
- message: errorUtil.toString(message)
3324
- });
3325
- }
3326
- max(maxDate, message) {
3327
- return this._addCheck({
3328
- kind: "max",
3329
- value: maxDate.getTime(),
3330
- message: errorUtil.toString(message)
3331
- });
3332
- }
3333
- get minDate() {
3334
- let min = null;
3335
- for (const ch of this._def.checks) {
3336
- if (ch.kind === "min") {
3337
- if (min === null || ch.value > min)
3338
- min = ch.value;
3339
- }
3340
- }
3341
- return min != null ? new Date(min) : null;
3342
- }
3343
- get maxDate() {
3344
- let max = null;
3345
- for (const ch of this._def.checks) {
3346
- if (ch.kind === "max") {
3347
- if (max === null || ch.value < max)
3348
- max = ch.value;
3349
- }
3350
- }
3351
- return max != null ? new Date(max) : null;
3352
- }
3353
- };
3354
- ZodDate.create = (params) => {
3355
- return new ZodDate({
3356
- checks: [],
3357
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
3358
- typeName: ZodFirstPartyTypeKind.ZodDate,
3359
- ...processCreateParams(params)
3360
- });
3361
- };
3362
- var ZodSymbol = class extends ZodType {
3363
- _parse(input) {
3364
- const parsedType = this._getType(input);
3365
- if (parsedType !== ZodParsedType.symbol) {
3366
- const ctx = this._getOrReturnCtx(input);
3367
- addIssueToContext(ctx, {
3368
- code: ZodIssueCode.invalid_type,
3369
- expected: ZodParsedType.symbol,
3370
- received: ctx.parsedType
3371
- });
3372
- return INVALID;
3373
- }
3374
- return OK(input.data);
3375
- }
3376
- };
3377
- ZodSymbol.create = (params) => {
3378
- return new ZodSymbol({
3379
- typeName: ZodFirstPartyTypeKind.ZodSymbol,
3380
- ...processCreateParams(params)
3381
- });
3382
- };
3383
- var ZodUndefined = class extends ZodType {
3384
- _parse(input) {
3385
- const parsedType = this._getType(input);
3386
- if (parsedType !== ZodParsedType.undefined) {
3387
- const ctx = this._getOrReturnCtx(input);
3388
- addIssueToContext(ctx, {
3389
- code: ZodIssueCode.invalid_type,
3390
- expected: ZodParsedType.undefined,
3391
- received: ctx.parsedType
3392
- });
3393
- return INVALID;
3394
- }
3395
- return OK(input.data);
3396
- }
3397
- };
3398
- ZodUndefined.create = (params) => {
3399
- return new ZodUndefined({
3400
- typeName: ZodFirstPartyTypeKind.ZodUndefined,
3401
- ...processCreateParams(params)
3402
- });
3403
- };
3404
- var ZodNull = class extends ZodType {
3405
- _parse(input) {
3406
- const parsedType = this._getType(input);
3407
- if (parsedType !== ZodParsedType.null) {
3408
- const ctx = this._getOrReturnCtx(input);
3409
- addIssueToContext(ctx, {
3410
- code: ZodIssueCode.invalid_type,
3411
- expected: ZodParsedType.null,
3412
- received: ctx.parsedType
3413
- });
3414
- return INVALID;
3415
- }
3416
- return OK(input.data);
3417
- }
3418
- };
3419
- ZodNull.create = (params) => {
3420
- return new ZodNull({
3421
- typeName: ZodFirstPartyTypeKind.ZodNull,
3422
- ...processCreateParams(params)
3423
- });
3424
- };
3425
- var ZodAny = class extends ZodType {
3426
- constructor() {
3427
- super(...arguments);
3428
- this._any = true;
3429
- }
3430
- _parse(input) {
3431
- return OK(input.data);
3432
- }
3433
- };
3434
- ZodAny.create = (params) => {
3435
- return new ZodAny({
3436
- typeName: ZodFirstPartyTypeKind.ZodAny,
3437
- ...processCreateParams(params)
3438
- });
3439
- };
3440
- var ZodUnknown = class extends ZodType {
3441
- constructor() {
3442
- super(...arguments);
3443
- this._unknown = true;
3444
- }
3445
- _parse(input) {
3446
- return OK(input.data);
3447
- }
3448
- };
3449
- ZodUnknown.create = (params) => {
3450
- return new ZodUnknown({
3451
- typeName: ZodFirstPartyTypeKind.ZodUnknown,
3452
- ...processCreateParams(params)
3453
- });
3454
- };
3455
- var ZodNever = class extends ZodType {
3456
- _parse(input) {
3457
- const ctx = this._getOrReturnCtx(input);
3458
- addIssueToContext(ctx, {
3459
- code: ZodIssueCode.invalid_type,
3460
- expected: ZodParsedType.never,
3461
- received: ctx.parsedType
3462
- });
3463
- return INVALID;
3464
- }
3465
- };
3466
- ZodNever.create = (params) => {
3467
- return new ZodNever({
3468
- typeName: ZodFirstPartyTypeKind.ZodNever,
3469
- ...processCreateParams(params)
3470
- });
3471
- };
3472
- var ZodVoid = class extends ZodType {
3473
- _parse(input) {
3474
- const parsedType = this._getType(input);
3475
- if (parsedType !== ZodParsedType.undefined) {
3476
- const ctx = this._getOrReturnCtx(input);
3477
- addIssueToContext(ctx, {
3478
- code: ZodIssueCode.invalid_type,
3479
- expected: ZodParsedType.void,
3480
- received: ctx.parsedType
3481
- });
3482
- return INVALID;
3483
- }
3484
- return OK(input.data);
3485
- }
3486
- };
3487
- ZodVoid.create = (params) => {
3488
- return new ZodVoid({
3489
- typeName: ZodFirstPartyTypeKind.ZodVoid,
3490
- ...processCreateParams(params)
3491
- });
3492
- };
3493
- var ZodArray = class _ZodArray extends ZodType {
3494
- _parse(input) {
3495
- const { ctx, status } = this._processInputParams(input);
3496
- const def = this._def;
3497
- if (ctx.parsedType !== ZodParsedType.array) {
3498
- addIssueToContext(ctx, {
3499
- code: ZodIssueCode.invalid_type,
3500
- expected: ZodParsedType.array,
3501
- received: ctx.parsedType
3502
- });
3503
- return INVALID;
3504
- }
3505
- if (def.exactLength !== null) {
3506
- const tooBig = ctx.data.length > def.exactLength.value;
3507
- const tooSmall = ctx.data.length < def.exactLength.value;
3508
- if (tooBig || tooSmall) {
3509
- addIssueToContext(ctx, {
3510
- code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
3511
- minimum: tooSmall ? def.exactLength.value : void 0,
3512
- maximum: tooBig ? def.exactLength.value : void 0,
3513
- type: "array",
3514
- inclusive: true,
3515
- exact: true,
3516
- message: def.exactLength.message
3517
- });
3518
- status.dirty();
3519
- }
3520
- }
3521
- if (def.minLength !== null) {
3522
- if (ctx.data.length < def.minLength.value) {
3523
- addIssueToContext(ctx, {
3524
- code: ZodIssueCode.too_small,
3525
- minimum: def.minLength.value,
3526
- type: "array",
3527
- inclusive: true,
3528
- exact: false,
3529
- message: def.minLength.message
3530
- });
3531
- status.dirty();
3532
- }
3533
- }
3534
- if (def.maxLength !== null) {
3535
- if (ctx.data.length > def.maxLength.value) {
3536
- addIssueToContext(ctx, {
3537
- code: ZodIssueCode.too_big,
3538
- maximum: def.maxLength.value,
3539
- type: "array",
3540
- inclusive: true,
3541
- exact: false,
3542
- message: def.maxLength.message
3543
- });
3544
- status.dirty();
3545
- }
3546
- }
3547
- if (ctx.common.async) {
3548
- return Promise.all([...ctx.data].map((item, i6) => {
3549
- return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i6));
3550
- })).then((result2) => {
3551
- return ParseStatus.mergeArray(status, result2);
3552
- });
3553
- }
3554
- const result = [...ctx.data].map((item, i6) => {
3555
- return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i6));
3556
- });
3557
- return ParseStatus.mergeArray(status, result);
3558
- }
3559
- get element() {
3560
- return this._def.type;
3561
- }
3562
- min(minLength, message) {
3563
- return new _ZodArray({
3564
- ...this._def,
3565
- minLength: { value: minLength, message: errorUtil.toString(message) }
3566
- });
3567
- }
3568
- max(maxLength, message) {
3569
- return new _ZodArray({
3570
- ...this._def,
3571
- maxLength: { value: maxLength, message: errorUtil.toString(message) }
3572
- });
3573
- }
3574
- length(len, message) {
3575
- return new _ZodArray({
3576
- ...this._def,
3577
- exactLength: { value: len, message: errorUtil.toString(message) }
3578
- });
3579
- }
3580
- nonempty(message) {
3581
- return this.min(1, message);
3582
- }
3583
- };
3584
- ZodArray.create = (schema, params) => {
3585
- return new ZodArray({
3586
- type: schema,
3587
- minLength: null,
3588
- maxLength: null,
3589
- exactLength: null,
3590
- typeName: ZodFirstPartyTypeKind.ZodArray,
3591
- ...processCreateParams(params)
3592
- });
3593
- };
3594
- function deepPartialify(schema) {
3595
- if (schema instanceof ZodObject) {
3596
- const newShape = {};
3597
- for (const key in schema.shape) {
3598
- const fieldSchema = schema.shape[key];
3599
- newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
3600
- }
3601
- return new ZodObject({
3602
- ...schema._def,
3603
- shape: () => newShape
3604
- });
3605
- } else if (schema instanceof ZodArray) {
3606
- return new ZodArray({
3607
- ...schema._def,
3608
- type: deepPartialify(schema.element)
3609
- });
3610
- } else if (schema instanceof ZodOptional) {
3611
- return ZodOptional.create(deepPartialify(schema.unwrap()));
3612
- } else if (schema instanceof ZodNullable) {
3613
- return ZodNullable.create(deepPartialify(schema.unwrap()));
3614
- } else if (schema instanceof ZodTuple) {
3615
- return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
3616
- } else {
3617
- return schema;
3618
- }
3619
- }
3620
- var ZodObject = class _ZodObject extends ZodType {
3621
- constructor() {
3622
- super(...arguments);
3623
- this._cached = null;
3624
- this.nonstrict = this.passthrough;
3625
- this.augment = this.extend;
3626
- }
3627
- _getCached() {
3628
- if (this._cached !== null)
3629
- return this._cached;
3630
- const shape = this._def.shape();
3631
- const keys = util.objectKeys(shape);
3632
- return this._cached = { shape, keys };
3633
- }
3634
- _parse(input) {
3635
- const parsedType = this._getType(input);
3636
- if (parsedType !== ZodParsedType.object) {
3637
- const ctx2 = this._getOrReturnCtx(input);
3638
- addIssueToContext(ctx2, {
3639
- code: ZodIssueCode.invalid_type,
3640
- expected: ZodParsedType.object,
3641
- received: ctx2.parsedType
3642
- });
3643
- return INVALID;
3644
- }
3645
- const { status, ctx } = this._processInputParams(input);
3646
- const { shape, keys: shapeKeys } = this._getCached();
3647
- const extraKeys = [];
3648
- if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
3649
- for (const key in ctx.data) {
3650
- if (!shapeKeys.includes(key)) {
3651
- extraKeys.push(key);
3652
- }
3653
- }
3654
- }
3655
- const pairs = [];
3656
- for (const key of shapeKeys) {
3657
- const keyValidator = shape[key];
3658
- const value = ctx.data[key];
3659
- pairs.push({
3660
- key: { status: "valid", value: key },
3661
- value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
3662
- alwaysSet: key in ctx.data
3663
- });
3664
- }
3665
- if (this._def.catchall instanceof ZodNever) {
3666
- const unknownKeys = this._def.unknownKeys;
3667
- if (unknownKeys === "passthrough") {
3668
- for (const key of extraKeys) {
3669
- pairs.push({
3670
- key: { status: "valid", value: key },
3671
- value: { status: "valid", value: ctx.data[key] }
3672
- });
3673
- }
3674
- } else if (unknownKeys === "strict") {
3675
- if (extraKeys.length > 0) {
3676
- addIssueToContext(ctx, {
3677
- code: ZodIssueCode.unrecognized_keys,
3678
- keys: extraKeys
3679
- });
3680
- status.dirty();
3681
- }
3682
- } else if (unknownKeys === "strip")
3683
- ;
3684
- else {
3685
- throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
3686
- }
3687
- } else {
3688
- const catchall = this._def.catchall;
3689
- for (const key of extraKeys) {
3690
- const value = ctx.data[key];
3691
- pairs.push({
3692
- key: { status: "valid", value: key },
3693
- value: catchall._parse(
3694
- new ParseInputLazyPath(ctx, value, ctx.path, key)
3695
- //, ctx.child(key), value, getParsedType(value)
3696
- ),
3697
- alwaysSet: key in ctx.data
3698
- });
3699
- }
3700
- }
3701
- if (ctx.common.async) {
3702
- return Promise.resolve().then(async () => {
3703
- const syncPairs = [];
3704
- for (const pair of pairs) {
3705
- const key = await pair.key;
3706
- const value = await pair.value;
3707
- syncPairs.push({
3708
- key,
3709
- value,
3710
- alwaysSet: pair.alwaysSet
3711
- });
3712
- }
3713
- return syncPairs;
3714
- }).then((syncPairs) => {
3715
- return ParseStatus.mergeObjectSync(status, syncPairs);
3716
- });
3717
- } else {
3718
- return ParseStatus.mergeObjectSync(status, pairs);
3719
- }
3720
- }
3721
- get shape() {
3722
- return this._def.shape();
3723
- }
3724
- strict(message) {
3725
- errorUtil.errToObj;
3726
- return new _ZodObject({
3727
- ...this._def,
3728
- unknownKeys: "strict",
3729
- ...message !== void 0 ? {
3730
- errorMap: (issue, ctx) => {
3731
- var _a, _b, _c, _d;
3732
- 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;
3733
- if (issue.code === "unrecognized_keys")
3734
- return {
3735
- message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
3736
- };
3737
- return {
3738
- message: defaultError
3739
- };
3740
- }
3741
- } : {}
3742
- });
3743
- }
3744
- strip() {
3745
- return new _ZodObject({
3746
- ...this._def,
3747
- unknownKeys: "strip"
3748
- });
3749
- }
3750
- passthrough() {
3751
- return new _ZodObject({
3752
- ...this._def,
3753
- unknownKeys: "passthrough"
3754
- });
3755
- }
3756
- // const AugmentFactory =
3757
- // <Def extends ZodObjectDef>(def: Def) =>
3758
- // <Augmentation extends ZodRawShape>(
3759
- // augmentation: Augmentation
3760
- // ): ZodObject<
3761
- // extendShape<ReturnType<Def["shape"]>, Augmentation>,
3762
- // Def["unknownKeys"],
3763
- // Def["catchall"]
3764
- // > => {
3765
- // return new ZodObject({
3766
- // ...def,
3767
- // shape: () => ({
3768
- // ...def.shape(),
3769
- // ...augmentation,
3770
- // }),
3771
- // }) as any;
3772
- // };
3773
- extend(augmentation) {
3774
- return new _ZodObject({
3775
- ...this._def,
3776
- shape: () => ({
3777
- ...this._def.shape(),
3778
- ...augmentation
3779
- })
3780
- });
3781
- }
3782
- /**
3783
- * Prior to zod@1.0.12 there was a bug in the
3784
- * inferred type of merged objects. Please
3785
- * upgrade if you are experiencing issues.
3786
- */
3787
- merge(merging) {
3788
- const merged = new _ZodObject({
3789
- unknownKeys: merging._def.unknownKeys,
3790
- catchall: merging._def.catchall,
3791
- shape: () => ({
3792
- ...this._def.shape(),
3793
- ...merging._def.shape()
3794
- }),
3795
- typeName: ZodFirstPartyTypeKind.ZodObject
3796
- });
3797
- return merged;
3798
- }
3799
- // merge<
3800
- // Incoming extends AnyZodObject,
3801
- // Augmentation extends Incoming["shape"],
3802
- // NewOutput extends {
3803
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
3804
- // ? Augmentation[k]["_output"]
3805
- // : k extends keyof Output
3806
- // ? Output[k]
3807
- // : never;
3808
- // },
3809
- // NewInput extends {
3810
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
3811
- // ? Augmentation[k]["_input"]
3812
- // : k extends keyof Input
3813
- // ? Input[k]
3814
- // : never;
3815
- // }
3816
- // >(
3817
- // merging: Incoming
3818
- // ): ZodObject<
3819
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
3820
- // Incoming["_def"]["unknownKeys"],
3821
- // Incoming["_def"]["catchall"],
3822
- // NewOutput,
3823
- // NewInput
3824
- // > {
3825
- // const merged: any = new ZodObject({
3826
- // unknownKeys: merging._def.unknownKeys,
3827
- // catchall: merging._def.catchall,
3828
- // shape: () =>
3829
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3830
- // typeName: ZodFirstPartyTypeKind.ZodObject,
3831
- // }) as any;
3832
- // return merged;
3833
- // }
3834
- setKey(key, schema) {
3835
- return this.augment({ [key]: schema });
3836
- }
3837
- // merge<Incoming extends AnyZodObject>(
3838
- // merging: Incoming
3839
- // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
3840
- // ZodObject<
3841
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
3842
- // Incoming["_def"]["unknownKeys"],
3843
- // Incoming["_def"]["catchall"]
3844
- // > {
3845
- // // const mergedShape = objectUtil.mergeShapes(
3846
- // // this._def.shape(),
3847
- // // merging._def.shape()
3848
- // // );
3849
- // const merged: any = new ZodObject({
3850
- // unknownKeys: merging._def.unknownKeys,
3851
- // catchall: merging._def.catchall,
3852
- // shape: () =>
3853
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3854
- // typeName: ZodFirstPartyTypeKind.ZodObject,
3855
- // }) as any;
3856
- // return merged;
3857
- // }
3858
- catchall(index) {
3859
- return new _ZodObject({
3860
- ...this._def,
3861
- catchall: index
3862
- });
3863
- }
3864
- pick(mask) {
3865
- const shape = {};
3866
- util.objectKeys(mask).forEach((key) => {
3867
- if (mask[key] && this.shape[key]) {
3868
- shape[key] = this.shape[key];
3869
- }
3870
- });
3871
- return new _ZodObject({
3872
- ...this._def,
3873
- shape: () => shape
3874
- });
3875
- }
3876
- omit(mask) {
3877
- const shape = {};
3878
- util.objectKeys(this.shape).forEach((key) => {
3879
- if (!mask[key]) {
3880
- shape[key] = this.shape[key];
3881
- }
3882
- });
3883
- return new _ZodObject({
3884
- ...this._def,
3885
- shape: () => shape
3886
- });
3887
- }
3888
- /**
3889
- * @deprecated
3890
- */
3891
- deepPartial() {
3892
- return deepPartialify(this);
3893
- }
3894
- partial(mask) {
3895
- const newShape = {};
3896
- util.objectKeys(this.shape).forEach((key) => {
3897
- const fieldSchema = this.shape[key];
3898
- if (mask && !mask[key]) {
3899
- newShape[key] = fieldSchema;
3900
- } else {
3901
- newShape[key] = fieldSchema.optional();
3902
- }
3903
- });
3904
- return new _ZodObject({
3905
- ...this._def,
3906
- shape: () => newShape
3907
- });
3908
- }
3909
- required(mask) {
3910
- const newShape = {};
3911
- util.objectKeys(this.shape).forEach((key) => {
3912
- if (mask && !mask[key]) {
3913
- newShape[key] = this.shape[key];
3914
- } else {
3915
- const fieldSchema = this.shape[key];
3916
- let newField = fieldSchema;
3917
- while (newField instanceof ZodOptional) {
3918
- newField = newField._def.innerType;
3919
- }
3920
- newShape[key] = newField;
3921
- }
3922
- });
3923
- return new _ZodObject({
3924
- ...this._def,
3925
- shape: () => newShape
3926
- });
3927
- }
3928
- keyof() {
3929
- return createZodEnum(util.objectKeys(this.shape));
3930
- }
3931
- };
3932
- ZodObject.create = (shape, params) => {
3933
- return new ZodObject({
3934
- shape: () => shape,
3935
- unknownKeys: "strip",
3936
- catchall: ZodNever.create(),
3937
- typeName: ZodFirstPartyTypeKind.ZodObject,
3938
- ...processCreateParams(params)
3939
- });
3940
- };
3941
- ZodObject.strictCreate = (shape, params) => {
3942
- return new ZodObject({
3943
- shape: () => shape,
3944
- unknownKeys: "strict",
3945
- catchall: ZodNever.create(),
3946
- typeName: ZodFirstPartyTypeKind.ZodObject,
3947
- ...processCreateParams(params)
3948
- });
3949
- };
3950
- ZodObject.lazycreate = (shape, params) => {
3951
- return new ZodObject({
3952
- shape,
3953
- unknownKeys: "strip",
3954
- catchall: ZodNever.create(),
3955
- typeName: ZodFirstPartyTypeKind.ZodObject,
3956
- ...processCreateParams(params)
3957
- });
3958
- };
3959
- var ZodUnion = class extends ZodType {
3960
- _parse(input) {
3961
- const { ctx } = this._processInputParams(input);
3962
- const options = this._def.options;
3963
- function handleResults(results) {
3964
- for (const result of results) {
3965
- if (result.result.status === "valid") {
3966
- return result.result;
3967
- }
3968
- }
3969
- for (const result of results) {
3970
- if (result.result.status === "dirty") {
3971
- ctx.common.issues.push(...result.ctx.common.issues);
3972
- return result.result;
3973
- }
3974
- }
3975
- const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
3976
- addIssueToContext(ctx, {
3977
- code: ZodIssueCode.invalid_union,
3978
- unionErrors
3979
- });
3980
- return INVALID;
3981
- }
3982
- if (ctx.common.async) {
3983
- return Promise.all(options.map(async (option) => {
3984
- const childCtx = {
3985
- ...ctx,
3986
- common: {
3987
- ...ctx.common,
3988
- issues: []
3989
- },
3990
- parent: null
3991
- };
3992
- return {
3993
- result: await option._parseAsync({
3994
- data: ctx.data,
3995
- path: ctx.path,
3996
- parent: childCtx
3997
- }),
3998
- ctx: childCtx
3999
- };
4000
- })).then(handleResults);
4001
- } else {
4002
- let dirty = void 0;
4003
- const issues = [];
4004
- for (const option of options) {
4005
- const childCtx = {
4006
- ...ctx,
4007
- common: {
4008
- ...ctx.common,
4009
- issues: []
4010
- },
4011
- parent: null
4012
- };
4013
- const result = option._parseSync({
4014
- data: ctx.data,
4015
- path: ctx.path,
4016
- parent: childCtx
4017
- });
4018
- if (result.status === "valid") {
4019
- return result;
4020
- } else if (result.status === "dirty" && !dirty) {
4021
- dirty = { result, ctx: childCtx };
4022
- }
4023
- if (childCtx.common.issues.length) {
4024
- issues.push(childCtx.common.issues);
4025
- }
4026
- }
4027
- if (dirty) {
4028
- ctx.common.issues.push(...dirty.ctx.common.issues);
4029
- return dirty.result;
4030
- }
4031
- const unionErrors = issues.map((issues2) => new ZodError(issues2));
4032
- addIssueToContext(ctx, {
4033
- code: ZodIssueCode.invalid_union,
4034
- unionErrors
4035
- });
4036
- return INVALID;
4037
- }
4038
- }
4039
- get options() {
4040
- return this._def.options;
4041
- }
4042
- };
4043
- ZodUnion.create = (types, params) => {
4044
- return new ZodUnion({
4045
- options: types,
4046
- typeName: ZodFirstPartyTypeKind.ZodUnion,
4047
- ...processCreateParams(params)
4048
- });
4049
- };
4050
- var getDiscriminator = (type) => {
4051
- if (type instanceof ZodLazy) {
4052
- return getDiscriminator(type.schema);
4053
- } else if (type instanceof ZodEffects) {
4054
- return getDiscriminator(type.innerType());
4055
- } else if (type instanceof ZodLiteral) {
4056
- return [type.value];
4057
- } else if (type instanceof ZodEnum) {
4058
- return type.options;
4059
- } else if (type instanceof ZodNativeEnum) {
4060
- return util.objectValues(type.enum);
4061
- } else if (type instanceof ZodDefault) {
4062
- return getDiscriminator(type._def.innerType);
4063
- } else if (type instanceof ZodUndefined) {
4064
- return [void 0];
4065
- } else if (type instanceof ZodNull) {
4066
- return [null];
4067
- } else if (type instanceof ZodOptional) {
4068
- return [void 0, ...getDiscriminator(type.unwrap())];
4069
- } else if (type instanceof ZodNullable) {
4070
- return [null, ...getDiscriminator(type.unwrap())];
4071
- } else if (type instanceof ZodBranded) {
4072
- return getDiscriminator(type.unwrap());
4073
- } else if (type instanceof ZodReadonly) {
4074
- return getDiscriminator(type.unwrap());
4075
- } else if (type instanceof ZodCatch) {
4076
- return getDiscriminator(type._def.innerType);
4077
- } else {
4078
- return [];
4079
- }
4080
- };
4081
- var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
4082
- _parse(input) {
4083
- const { ctx } = this._processInputParams(input);
4084
- if (ctx.parsedType !== ZodParsedType.object) {
4085
- addIssueToContext(ctx, {
4086
- code: ZodIssueCode.invalid_type,
4087
- expected: ZodParsedType.object,
4088
- received: ctx.parsedType
4089
- });
4090
- return INVALID;
4091
- }
4092
- const discriminator = this.discriminator;
4093
- const discriminatorValue = ctx.data[discriminator];
4094
- const option = this.optionsMap.get(discriminatorValue);
4095
- if (!option) {
4096
- addIssueToContext(ctx, {
4097
- code: ZodIssueCode.invalid_union_discriminator,
4098
- options: Array.from(this.optionsMap.keys()),
4099
- path: [discriminator]
4100
- });
4101
- return INVALID;
4102
- }
4103
- if (ctx.common.async) {
4104
- return option._parseAsync({
4105
- data: ctx.data,
4106
- path: ctx.path,
4107
- parent: ctx
4108
- });
4109
- } else {
4110
- return option._parseSync({
4111
- data: ctx.data,
4112
- path: ctx.path,
4113
- parent: ctx
4114
- });
4115
- }
4116
- }
4117
- get discriminator() {
4118
- return this._def.discriminator;
4119
- }
4120
- get options() {
4121
- return this._def.options;
4122
- }
4123
- get optionsMap() {
4124
- return this._def.optionsMap;
4125
- }
4126
- /**
4127
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
4128
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
4129
- * have a different value for each object in the union.
4130
- * @param discriminator the name of the discriminator property
4131
- * @param types an array of object schemas
4132
- * @param params
4133
- */
4134
- static create(discriminator, options, params) {
4135
- const optionsMap = /* @__PURE__ */ new Map();
4136
- for (const type of options) {
4137
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
4138
- if (!discriminatorValues.length) {
4139
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
4140
- }
4141
- for (const value of discriminatorValues) {
4142
- if (optionsMap.has(value)) {
4143
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
4144
- }
4145
- optionsMap.set(value, type);
4146
- }
4147
- }
4148
- return new _ZodDiscriminatedUnion({
4149
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
4150
- discriminator,
4151
- options,
4152
- optionsMap,
4153
- ...processCreateParams(params)
4154
- });
4155
- }
4156
- };
4157
- function mergeValues(a3, b3) {
4158
- const aType = getParsedType(a3);
4159
- const bType = getParsedType(b3);
4160
- if (a3 === b3) {
4161
- return { valid: true, data: a3 };
4162
- } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
4163
- const bKeys = util.objectKeys(b3);
4164
- const sharedKeys = util.objectKeys(a3).filter((key) => bKeys.indexOf(key) !== -1);
4165
- const newObj = { ...a3, ...b3 };
4166
- for (const key of sharedKeys) {
4167
- const sharedValue = mergeValues(a3[key], b3[key]);
4168
- if (!sharedValue.valid) {
4169
- return { valid: false };
4170
- }
4171
- newObj[key] = sharedValue.data;
4172
- }
4173
- return { valid: true, data: newObj };
4174
- } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
4175
- if (a3.length !== b3.length) {
4176
- return { valid: false };
4177
- }
4178
- const newArray = [];
4179
- for (let index = 0; index < a3.length; index++) {
4180
- const itemA = a3[index];
4181
- const itemB = b3[index];
4182
- const sharedValue = mergeValues(itemA, itemB);
4183
- if (!sharedValue.valid) {
4184
- return { valid: false };
4185
- }
4186
- newArray.push(sharedValue.data);
4187
- }
4188
- return { valid: true, data: newArray };
4189
- } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a3 === +b3) {
4190
- return { valid: true, data: a3 };
4191
- } else {
4192
- return { valid: false };
4193
- }
4194
- }
4195
- var ZodIntersection = class extends ZodType {
4196
- _parse(input) {
4197
- const { status, ctx } = this._processInputParams(input);
4198
- const handleParsed = (parsedLeft, parsedRight) => {
4199
- if (isAborted(parsedLeft) || isAborted(parsedRight)) {
4200
- return INVALID;
4201
- }
4202
- const merged = mergeValues(parsedLeft.value, parsedRight.value);
4203
- if (!merged.valid) {
4204
- addIssueToContext(ctx, {
4205
- code: ZodIssueCode.invalid_intersection_types
4206
- });
4207
- return INVALID;
4208
- }
4209
- if (isDirty(parsedLeft) || isDirty(parsedRight)) {
4210
- status.dirty();
4211
- }
4212
- return { status: status.value, value: merged.data };
4213
- };
4214
- if (ctx.common.async) {
4215
- return Promise.all([
4216
- this._def.left._parseAsync({
4217
- data: ctx.data,
4218
- path: ctx.path,
4219
- parent: ctx
4220
- }),
4221
- this._def.right._parseAsync({
4222
- data: ctx.data,
4223
- path: ctx.path,
4224
- parent: ctx
4225
- })
4226
- ]).then(([left, right]) => handleParsed(left, right));
4227
- } else {
4228
- return handleParsed(this._def.left._parseSync({
4229
- data: ctx.data,
4230
- path: ctx.path,
4231
- parent: ctx
4232
- }), this._def.right._parseSync({
4233
- data: ctx.data,
4234
- path: ctx.path,
4235
- parent: ctx
4236
- }));
4237
- }
4238
- }
4239
- };
4240
- ZodIntersection.create = (left, right, params) => {
4241
- return new ZodIntersection({
4242
- left,
4243
- right,
4244
- typeName: ZodFirstPartyTypeKind.ZodIntersection,
4245
- ...processCreateParams(params)
4246
- });
4247
- };
4248
- var ZodTuple = class _ZodTuple extends ZodType {
4249
- _parse(input) {
4250
- const { status, ctx } = this._processInputParams(input);
4251
- if (ctx.parsedType !== ZodParsedType.array) {
4252
- addIssueToContext(ctx, {
4253
- code: ZodIssueCode.invalid_type,
4254
- expected: ZodParsedType.array,
4255
- received: ctx.parsedType
4256
- });
4257
- return INVALID;
4258
- }
4259
- if (ctx.data.length < this._def.items.length) {
4260
- addIssueToContext(ctx, {
4261
- code: ZodIssueCode.too_small,
4262
- minimum: this._def.items.length,
4263
- inclusive: true,
4264
- exact: false,
4265
- type: "array"
4266
- });
4267
- return INVALID;
4268
- }
4269
- const rest = this._def.rest;
4270
- if (!rest && ctx.data.length > this._def.items.length) {
4271
- addIssueToContext(ctx, {
4272
- code: ZodIssueCode.too_big,
4273
- maximum: this._def.items.length,
4274
- inclusive: true,
4275
- exact: false,
4276
- type: "array"
4277
- });
4278
- status.dirty();
4279
- }
4280
- const items = [...ctx.data].map((item, itemIndex) => {
4281
- const schema = this._def.items[itemIndex] || this._def.rest;
4282
- if (!schema)
4283
- return null;
4284
- return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
4285
- }).filter((x2) => !!x2);
4286
- if (ctx.common.async) {
4287
- return Promise.all(items).then((results) => {
4288
- return ParseStatus.mergeArray(status, results);
4289
- });
4290
- } else {
4291
- return ParseStatus.mergeArray(status, items);
4292
- }
4293
- }
4294
- get items() {
4295
- return this._def.items;
4296
- }
4297
- rest(rest) {
4298
- return new _ZodTuple({
4299
- ...this._def,
4300
- rest
4301
- });
4302
- }
4303
- };
4304
- ZodTuple.create = (schemas, params) => {
4305
- if (!Array.isArray(schemas)) {
4306
- throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
4307
- }
4308
- return new ZodTuple({
4309
- items: schemas,
4310
- typeName: ZodFirstPartyTypeKind.ZodTuple,
4311
- rest: null,
4312
- ...processCreateParams(params)
4313
- });
4314
- };
4315
- var ZodRecord = class _ZodRecord extends ZodType {
4316
- get keySchema() {
4317
- return this._def.keyType;
4318
- }
4319
- get valueSchema() {
4320
- return this._def.valueType;
4321
- }
4322
- _parse(input) {
4323
- const { status, ctx } = this._processInputParams(input);
4324
- if (ctx.parsedType !== ZodParsedType.object) {
4325
- addIssueToContext(ctx, {
4326
- code: ZodIssueCode.invalid_type,
4327
- expected: ZodParsedType.object,
4328
- received: ctx.parsedType
4329
- });
4330
- return INVALID;
4331
- }
4332
- const pairs = [];
4333
- const keyType = this._def.keyType;
4334
- const valueType = this._def.valueType;
4335
- for (const key in ctx.data) {
4336
- pairs.push({
4337
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
4338
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
4339
- alwaysSet: key in ctx.data
4340
- });
4341
- }
4342
- if (ctx.common.async) {
4343
- return ParseStatus.mergeObjectAsync(status, pairs);
4344
- } else {
4345
- return ParseStatus.mergeObjectSync(status, pairs);
4346
- }
4347
- }
4348
- get element() {
4349
- return this._def.valueType;
4350
- }
4351
- static create(first, second, third) {
4352
- if (second instanceof ZodType) {
4353
- return new _ZodRecord({
4354
- keyType: first,
4355
- valueType: second,
4356
- typeName: ZodFirstPartyTypeKind.ZodRecord,
4357
- ...processCreateParams(third)
4358
- });
4359
- }
4360
- return new _ZodRecord({
4361
- keyType: ZodString.create(),
4362
- valueType: first,
4363
- typeName: ZodFirstPartyTypeKind.ZodRecord,
4364
- ...processCreateParams(second)
4365
- });
4366
- }
4367
- };
4368
- var ZodMap = class extends ZodType {
4369
- get keySchema() {
4370
- return this._def.keyType;
4371
- }
4372
- get valueSchema() {
4373
- return this._def.valueType;
4374
- }
4375
- _parse(input) {
4376
- const { status, ctx } = this._processInputParams(input);
4377
- if (ctx.parsedType !== ZodParsedType.map) {
4378
- addIssueToContext(ctx, {
4379
- code: ZodIssueCode.invalid_type,
4380
- expected: ZodParsedType.map,
4381
- received: ctx.parsedType
4382
- });
4383
- return INVALID;
4384
- }
4385
- const keyType = this._def.keyType;
4386
- const valueType = this._def.valueType;
4387
- const pairs = [...ctx.data.entries()].map(([key, value], index) => {
4388
- return {
4389
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
4390
- value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
4391
- };
4392
- });
4393
- if (ctx.common.async) {
4394
- const finalMap = /* @__PURE__ */ new Map();
4395
- return Promise.resolve().then(async () => {
4396
- for (const pair of pairs) {
4397
- const key = await pair.key;
4398
- const value = await pair.value;
4399
- if (key.status === "aborted" || value.status === "aborted") {
4400
- return INVALID;
4401
- }
4402
- if (key.status === "dirty" || value.status === "dirty") {
4403
- status.dirty();
4404
- }
4405
- finalMap.set(key.value, value.value);
4406
- }
4407
- return { status: status.value, value: finalMap };
4408
- });
4409
- } else {
4410
- const finalMap = /* @__PURE__ */ new Map();
4411
- for (const pair of pairs) {
4412
- const key = pair.key;
4413
- const value = pair.value;
4414
- if (key.status === "aborted" || value.status === "aborted") {
4415
- return INVALID;
4416
- }
4417
- if (key.status === "dirty" || value.status === "dirty") {
4418
- status.dirty();
4419
- }
4420
- finalMap.set(key.value, value.value);
4421
- }
4422
- return { status: status.value, value: finalMap };
4423
- }
4424
- }
4425
- };
4426
- ZodMap.create = (keyType, valueType, params) => {
4427
- return new ZodMap({
4428
- valueType,
4429
- keyType,
4430
- typeName: ZodFirstPartyTypeKind.ZodMap,
4431
- ...processCreateParams(params)
4432
- });
4433
- };
4434
- var ZodSet = class _ZodSet extends ZodType {
4435
- _parse(input) {
4436
- const { status, ctx } = this._processInputParams(input);
4437
- if (ctx.parsedType !== ZodParsedType.set) {
4438
- addIssueToContext(ctx, {
4439
- code: ZodIssueCode.invalid_type,
4440
- expected: ZodParsedType.set,
4441
- received: ctx.parsedType
4442
- });
4443
- return INVALID;
4444
- }
4445
- const def = this._def;
4446
- if (def.minSize !== null) {
4447
- if (ctx.data.size < def.minSize.value) {
4448
- addIssueToContext(ctx, {
4449
- code: ZodIssueCode.too_small,
4450
- minimum: def.minSize.value,
4451
- type: "set",
4452
- inclusive: true,
4453
- exact: false,
4454
- message: def.minSize.message
4455
- });
4456
- status.dirty();
4457
- }
4458
- }
4459
- if (def.maxSize !== null) {
4460
- if (ctx.data.size > def.maxSize.value) {
4461
- addIssueToContext(ctx, {
4462
- code: ZodIssueCode.too_big,
4463
- maximum: def.maxSize.value,
4464
- type: "set",
4465
- inclusive: true,
4466
- exact: false,
4467
- message: def.maxSize.message
4468
- });
4469
- status.dirty();
4470
- }
4471
- }
4472
- const valueType = this._def.valueType;
4473
- function finalizeSet(elements2) {
4474
- const parsedSet = /* @__PURE__ */ new Set();
4475
- for (const element of elements2) {
4476
- if (element.status === "aborted")
4477
- return INVALID;
4478
- if (element.status === "dirty")
4479
- status.dirty();
4480
- parsedSet.add(element.value);
4481
- }
4482
- return { status: status.value, value: parsedSet };
4483
- }
4484
- const elements = [...ctx.data.values()].map((item, i6) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i6)));
4485
- if (ctx.common.async) {
4486
- return Promise.all(elements).then((elements2) => finalizeSet(elements2));
4487
- } else {
4488
- return finalizeSet(elements);
4489
- }
4490
- }
4491
- min(minSize, message) {
4492
- return new _ZodSet({
4493
- ...this._def,
4494
- minSize: { value: minSize, message: errorUtil.toString(message) }
4495
- });
4496
- }
4497
- max(maxSize, message) {
4498
- return new _ZodSet({
4499
- ...this._def,
4500
- maxSize: { value: maxSize, message: errorUtil.toString(message) }
4501
- });
4502
- }
4503
- size(size, message) {
4504
- return this.min(size, message).max(size, message);
4505
- }
4506
- nonempty(message) {
4507
- return this.min(1, message);
4508
- }
4509
- };
4510
- ZodSet.create = (valueType, params) => {
4511
- return new ZodSet({
4512
- valueType,
4513
- minSize: null,
4514
- maxSize: null,
4515
- typeName: ZodFirstPartyTypeKind.ZodSet,
4516
- ...processCreateParams(params)
4517
- });
4518
- };
4519
- var ZodFunction = class _ZodFunction extends ZodType {
4520
- constructor() {
4521
- super(...arguments);
4522
- this.validate = this.implement;
4523
- }
4524
- _parse(input) {
4525
- const { ctx } = this._processInputParams(input);
4526
- if (ctx.parsedType !== ZodParsedType.function) {
4527
- addIssueToContext(ctx, {
4528
- code: ZodIssueCode.invalid_type,
4529
- expected: ZodParsedType.function,
4530
- received: ctx.parsedType
4531
- });
4532
- return INVALID;
4533
- }
4534
- function makeArgsIssue(args, error) {
4535
- return makeIssue({
4536
- data: args,
4537
- path: ctx.path,
4538
- errorMaps: [
4539
- ctx.common.contextualErrorMap,
4540
- ctx.schemaErrorMap,
4541
- getErrorMap(),
4542
- errorMap
4543
- ].filter((x2) => !!x2),
4544
- issueData: {
4545
- code: ZodIssueCode.invalid_arguments,
4546
- argumentsError: error
4547
- }
4548
- });
4549
- }
4550
- function makeReturnsIssue(returns, error) {
4551
- return makeIssue({
4552
- data: returns,
4553
- path: ctx.path,
4554
- errorMaps: [
4555
- ctx.common.contextualErrorMap,
4556
- ctx.schemaErrorMap,
4557
- getErrorMap(),
4558
- errorMap
4559
- ].filter((x2) => !!x2),
4560
- issueData: {
4561
- code: ZodIssueCode.invalid_return_type,
4562
- returnTypeError: error
4563
- }
4564
- });
4565
- }
4566
- const params = { errorMap: ctx.common.contextualErrorMap };
4567
- const fn = ctx.data;
4568
- if (this._def.returns instanceof ZodPromise) {
4569
- const me = this;
4570
- return OK(async function(...args) {
4571
- const error = new ZodError([]);
4572
- const parsedArgs = await me._def.args.parseAsync(args, params).catch((e7) => {
4573
- error.addIssue(makeArgsIssue(args, e7));
4574
- throw error;
4575
- });
4576
- const result = await Reflect.apply(fn, this, parsedArgs);
4577
- const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e7) => {
4578
- error.addIssue(makeReturnsIssue(result, e7));
4579
- throw error;
4580
- });
4581
- return parsedReturns;
4582
- });
4583
- } else {
4584
- const me = this;
4585
- return OK(function(...args) {
4586
- const parsedArgs = me._def.args.safeParse(args, params);
4587
- if (!parsedArgs.success) {
4588
- throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
4589
- }
4590
- const result = Reflect.apply(fn, this, parsedArgs.data);
4591
- const parsedReturns = me._def.returns.safeParse(result, params);
4592
- if (!parsedReturns.success) {
4593
- throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
4594
- }
4595
- return parsedReturns.data;
4596
- });
4597
- }
4598
- }
4599
- parameters() {
4600
- return this._def.args;
4601
- }
4602
- returnType() {
4603
- return this._def.returns;
4604
- }
4605
- args(...items) {
4606
- return new _ZodFunction({
4607
- ...this._def,
4608
- args: ZodTuple.create(items).rest(ZodUnknown.create())
4609
- });
4610
- }
4611
- returns(returnType) {
4612
- return new _ZodFunction({
4613
- ...this._def,
4614
- returns: returnType
4615
- });
4616
- }
4617
- implement(func) {
4618
- const validatedFunc = this.parse(func);
4619
- return validatedFunc;
4620
- }
4621
- strictImplement(func) {
4622
- const validatedFunc = this.parse(func);
4623
- return validatedFunc;
4624
- }
4625
- static create(args, returns, params) {
4626
- return new _ZodFunction({
4627
- args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
4628
- returns: returns || ZodUnknown.create(),
4629
- typeName: ZodFirstPartyTypeKind.ZodFunction,
4630
- ...processCreateParams(params)
4631
- });
4632
- }
4633
- };
4634
- var ZodLazy = class extends ZodType {
4635
- get schema() {
4636
- return this._def.getter();
4637
- }
4638
- _parse(input) {
4639
- const { ctx } = this._processInputParams(input);
4640
- const lazySchema = this._def.getter();
4641
- return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
4642
- }
4643
- };
4644
- ZodLazy.create = (getter, params) => {
4645
- return new ZodLazy({
4646
- getter,
4647
- typeName: ZodFirstPartyTypeKind.ZodLazy,
4648
- ...processCreateParams(params)
4649
- });
4650
- };
4651
- var ZodLiteral = class extends ZodType {
4652
- _parse(input) {
4653
- if (input.data !== this._def.value) {
4654
- const ctx = this._getOrReturnCtx(input);
4655
- addIssueToContext(ctx, {
4656
- received: ctx.data,
4657
- code: ZodIssueCode.invalid_literal,
4658
- expected: this._def.value
4659
- });
4660
- return INVALID;
4661
- }
4662
- return { status: "valid", value: input.data };
4663
- }
4664
- get value() {
4665
- return this._def.value;
4666
- }
4667
- };
4668
- ZodLiteral.create = (value, params) => {
4669
- return new ZodLiteral({
4670
- value,
4671
- typeName: ZodFirstPartyTypeKind.ZodLiteral,
4672
- ...processCreateParams(params)
4673
- });
4674
- };
4675
- function createZodEnum(values, params) {
4676
- return new ZodEnum({
4677
- values,
4678
- typeName: ZodFirstPartyTypeKind.ZodEnum,
4679
- ...processCreateParams(params)
4680
- });
4681
- }
4682
- var ZodEnum = class _ZodEnum extends ZodType {
4683
- constructor() {
4684
- super(...arguments);
4685
- _ZodEnum_cache.set(this, void 0);
4686
- }
4687
- _parse(input) {
4688
- if (typeof input.data !== "string") {
4689
- const ctx = this._getOrReturnCtx(input);
4690
- const expectedValues = this._def.values;
4691
- addIssueToContext(ctx, {
4692
- expected: util.joinValues(expectedValues),
4693
- received: ctx.parsedType,
4694
- code: ZodIssueCode.invalid_type
4695
- });
4696
- return INVALID;
4697
- }
4698
- if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
4699
- __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
4700
- }
4701
- if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
4702
- const ctx = this._getOrReturnCtx(input);
4703
- const expectedValues = this._def.values;
4704
- addIssueToContext(ctx, {
4705
- received: ctx.data,
4706
- code: ZodIssueCode.invalid_enum_value,
4707
- options: expectedValues
4708
- });
4709
- return INVALID;
4710
- }
4711
- return OK(input.data);
4712
- }
4713
- get options() {
4714
- return this._def.values;
4715
- }
4716
- get enum() {
4717
- const enumValues = {};
4718
- for (const val of this._def.values) {
4719
- enumValues[val] = val;
4720
- }
4721
- return enumValues;
4722
- }
4723
- get Values() {
4724
- const enumValues = {};
4725
- for (const val of this._def.values) {
4726
- enumValues[val] = val;
4727
- }
4728
- return enumValues;
4729
- }
4730
- get Enum() {
4731
- const enumValues = {};
4732
- for (const val of this._def.values) {
4733
- enumValues[val] = val;
4734
- }
4735
- return enumValues;
4736
- }
4737
- extract(values, newDef = this._def) {
4738
- return _ZodEnum.create(values, {
4739
- ...this._def,
4740
- ...newDef
4741
- });
4742
- }
4743
- exclude(values, newDef = this._def) {
4744
- return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
4745
- ...this._def,
4746
- ...newDef
4747
- });
4748
- }
4749
- };
4750
- _ZodEnum_cache = /* @__PURE__ */ new WeakMap();
4751
- ZodEnum.create = createZodEnum;
4752
- var ZodNativeEnum = class extends ZodType {
4753
- constructor() {
4754
- super(...arguments);
4755
- _ZodNativeEnum_cache.set(this, void 0);
4756
- }
4757
- _parse(input) {
4758
- const nativeEnumValues = util.getValidEnumValues(this._def.values);
4759
- const ctx = this._getOrReturnCtx(input);
4760
- if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
4761
- const expectedValues = util.objectValues(nativeEnumValues);
4762
- addIssueToContext(ctx, {
4763
- expected: util.joinValues(expectedValues),
4764
- received: ctx.parsedType,
4765
- code: ZodIssueCode.invalid_type
4766
- });
4767
- return INVALID;
4768
- }
4769
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
4770
- __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
4771
- }
4772
- if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
4773
- const expectedValues = util.objectValues(nativeEnumValues);
4774
- addIssueToContext(ctx, {
4775
- received: ctx.data,
4776
- code: ZodIssueCode.invalid_enum_value,
4777
- options: expectedValues
4778
- });
4779
- return INVALID;
4780
- }
4781
- return OK(input.data);
4782
- }
4783
- get enum() {
4784
- return this._def.values;
4785
- }
4786
- };
4787
- _ZodNativeEnum_cache = /* @__PURE__ */ new WeakMap();
4788
- ZodNativeEnum.create = (values, params) => {
4789
- return new ZodNativeEnum({
4790
- values,
4791
- typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
4792
- ...processCreateParams(params)
4793
- });
4794
- };
4795
- var ZodPromise = class extends ZodType {
4796
- unwrap() {
4797
- return this._def.type;
4798
- }
4799
- _parse(input) {
4800
- const { ctx } = this._processInputParams(input);
4801
- if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
4802
- addIssueToContext(ctx, {
4803
- code: ZodIssueCode.invalid_type,
4804
- expected: ZodParsedType.promise,
4805
- received: ctx.parsedType
4806
- });
4807
- return INVALID;
4808
- }
4809
- const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
4810
- return OK(promisified.then((data) => {
4811
- return this._def.type.parseAsync(data, {
4812
- path: ctx.path,
4813
- errorMap: ctx.common.contextualErrorMap
4814
- });
4815
- }));
4816
- }
4817
- };
4818
- ZodPromise.create = (schema, params) => {
4819
- return new ZodPromise({
4820
- type: schema,
4821
- typeName: ZodFirstPartyTypeKind.ZodPromise,
4822
- ...processCreateParams(params)
4823
- });
4824
- };
4825
- var ZodEffects = class extends ZodType {
4826
- innerType() {
4827
- return this._def.schema;
4828
- }
4829
- sourceType() {
4830
- return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
4831
- }
4832
- _parse(input) {
4833
- const { status, ctx } = this._processInputParams(input);
4834
- const effect = this._def.effect || null;
4835
- const checkCtx = {
4836
- addIssue: (arg) => {
4837
- addIssueToContext(ctx, arg);
4838
- if (arg.fatal) {
4839
- status.abort();
4840
- } else {
4841
- status.dirty();
4842
- }
4843
- },
4844
- get path() {
4845
- return ctx.path;
4846
- }
4847
- };
4848
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
4849
- if (effect.type === "preprocess") {
4850
- const processed = effect.transform(ctx.data, checkCtx);
4851
- if (ctx.common.async) {
4852
- return Promise.resolve(processed).then(async (processed2) => {
4853
- if (status.value === "aborted")
4854
- return INVALID;
4855
- const result = await this._def.schema._parseAsync({
4856
- data: processed2,
4857
- path: ctx.path,
4858
- parent: ctx
4859
- });
4860
- if (result.status === "aborted")
4861
- return INVALID;
4862
- if (result.status === "dirty")
4863
- return DIRTY(result.value);
4864
- if (status.value === "dirty")
4865
- return DIRTY(result.value);
4866
- return result;
4867
- });
4868
- } else {
4869
- if (status.value === "aborted")
4870
- return INVALID;
4871
- const result = this._def.schema._parseSync({
4872
- data: processed,
4873
- path: ctx.path,
4874
- parent: ctx
4875
- });
4876
- if (result.status === "aborted")
4877
- return INVALID;
4878
- if (result.status === "dirty")
4879
- return DIRTY(result.value);
4880
- if (status.value === "dirty")
4881
- return DIRTY(result.value);
4882
- return result;
4883
- }
4884
- }
4885
- if (effect.type === "refinement") {
4886
- const executeRefinement = (acc) => {
4887
- const result = effect.refinement(acc, checkCtx);
4888
- if (ctx.common.async) {
4889
- return Promise.resolve(result);
4890
- }
4891
- if (result instanceof Promise) {
4892
- throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
4893
- }
4894
- return acc;
4895
- };
4896
- if (ctx.common.async === false) {
4897
- const inner = this._def.schema._parseSync({
4898
- data: ctx.data,
4899
- path: ctx.path,
4900
- parent: ctx
4901
- });
4902
- if (inner.status === "aborted")
4903
- return INVALID;
4904
- if (inner.status === "dirty")
4905
- status.dirty();
4906
- executeRefinement(inner.value);
4907
- return { status: status.value, value: inner.value };
4908
- } else {
4909
- return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
4910
- if (inner.status === "aborted")
4911
- return INVALID;
4912
- if (inner.status === "dirty")
4913
- status.dirty();
4914
- return executeRefinement(inner.value).then(() => {
4915
- return { status: status.value, value: inner.value };
4916
- });
4917
- });
4918
- }
4919
- }
4920
- if (effect.type === "transform") {
4921
- if (ctx.common.async === false) {
4922
- const base = this._def.schema._parseSync({
4923
- data: ctx.data,
4924
- path: ctx.path,
4925
- parent: ctx
4926
- });
4927
- if (!isValid(base))
4928
- return base;
4929
- const result = effect.transform(base.value, checkCtx);
4930
- if (result instanceof Promise) {
4931
- throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
4932
- }
4933
- return { status: status.value, value: result };
4934
- } else {
4935
- return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
4936
- if (!isValid(base))
4937
- return base;
4938
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
4939
- });
4940
- }
4941
- }
4942
- util.assertNever(effect);
4943
- }
4944
- };
4945
- ZodEffects.create = (schema, effect, params) => {
4946
- return new ZodEffects({
4947
- schema,
4948
- typeName: ZodFirstPartyTypeKind.ZodEffects,
4949
- effect,
4950
- ...processCreateParams(params)
4951
- });
4952
- };
4953
- ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
4954
- return new ZodEffects({
4955
- schema,
4956
- effect: { type: "preprocess", transform: preprocess },
4957
- typeName: ZodFirstPartyTypeKind.ZodEffects,
4958
- ...processCreateParams(params)
4959
- });
4960
- };
4961
- var ZodOptional = class extends ZodType {
4962
- _parse(input) {
4963
- const parsedType = this._getType(input);
4964
- if (parsedType === ZodParsedType.undefined) {
4965
- return OK(void 0);
4966
- }
4967
- return this._def.innerType._parse(input);
4968
- }
4969
- unwrap() {
4970
- return this._def.innerType;
4971
- }
4972
- };
4973
- ZodOptional.create = (type, params) => {
4974
- return new ZodOptional({
4975
- innerType: type,
4976
- typeName: ZodFirstPartyTypeKind.ZodOptional,
4977
- ...processCreateParams(params)
4978
- });
4979
- };
4980
- var ZodNullable = class extends ZodType {
4981
- _parse(input) {
4982
- const parsedType = this._getType(input);
4983
- if (parsedType === ZodParsedType.null) {
4984
- return OK(null);
4985
- }
4986
- return this._def.innerType._parse(input);
4987
- }
4988
- unwrap() {
4989
- return this._def.innerType;
4990
- }
4991
- };
4992
- ZodNullable.create = (type, params) => {
4993
- return new ZodNullable({
4994
- innerType: type,
4995
- typeName: ZodFirstPartyTypeKind.ZodNullable,
4996
- ...processCreateParams(params)
4997
- });
4998
- };
4999
- var ZodDefault = class extends ZodType {
5000
- _parse(input) {
5001
- const { ctx } = this._processInputParams(input);
5002
- let data = ctx.data;
5003
- if (ctx.parsedType === ZodParsedType.undefined) {
5004
- data = this._def.defaultValue();
5005
- }
5006
- return this._def.innerType._parse({
5007
- data,
5008
- path: ctx.path,
5009
- parent: ctx
5010
- });
5011
- }
5012
- removeDefault() {
5013
- return this._def.innerType;
5014
- }
5015
- };
5016
- ZodDefault.create = (type, params) => {
5017
- return new ZodDefault({
5018
- innerType: type,
5019
- typeName: ZodFirstPartyTypeKind.ZodDefault,
5020
- defaultValue: typeof params.default === "function" ? params.default : () => params.default,
5021
- ...processCreateParams(params)
5022
- });
5023
- };
5024
- var ZodCatch = class extends ZodType {
5025
- _parse(input) {
5026
- const { ctx } = this._processInputParams(input);
5027
- const newCtx = {
5028
- ...ctx,
5029
- common: {
5030
- ...ctx.common,
5031
- issues: []
5032
- }
5033
- };
5034
- const result = this._def.innerType._parse({
5035
- data: newCtx.data,
5036
- path: newCtx.path,
5037
- parent: {
5038
- ...newCtx
5039
- }
5040
- });
5041
- if (isAsync(result)) {
5042
- return result.then((result2) => {
5043
- return {
5044
- status: "valid",
5045
- value: result2.status === "valid" ? result2.value : this._def.catchValue({
5046
- get error() {
5047
- return new ZodError(newCtx.common.issues);
5048
- },
5049
- input: newCtx.data
5050
- })
5051
- };
5052
- });
5053
- } else {
5054
- return {
5055
- status: "valid",
5056
- value: result.status === "valid" ? result.value : this._def.catchValue({
5057
- get error() {
5058
- return new ZodError(newCtx.common.issues);
5059
- },
5060
- input: newCtx.data
5061
- })
5062
- };
5063
- }
5064
- }
5065
- removeCatch() {
5066
- return this._def.innerType;
5067
- }
5068
- };
5069
- ZodCatch.create = (type, params) => {
5070
- return new ZodCatch({
5071
- innerType: type,
5072
- typeName: ZodFirstPartyTypeKind.ZodCatch,
5073
- catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
5074
- ...processCreateParams(params)
5075
- });
5076
- };
5077
- var ZodNaN = class extends ZodType {
5078
- _parse(input) {
5079
- const parsedType = this._getType(input);
5080
- if (parsedType !== ZodParsedType.nan) {
5081
- const ctx = this._getOrReturnCtx(input);
5082
- addIssueToContext(ctx, {
5083
- code: ZodIssueCode.invalid_type,
5084
- expected: ZodParsedType.nan,
5085
- received: ctx.parsedType
5086
- });
5087
- return INVALID;
5088
- }
5089
- return { status: "valid", value: input.data };
5090
- }
5091
- };
5092
- ZodNaN.create = (params) => {
5093
- return new ZodNaN({
5094
- typeName: ZodFirstPartyTypeKind.ZodNaN,
5095
- ...processCreateParams(params)
5096
- });
5097
- };
5098
- var BRAND = Symbol("zod_brand");
5099
- var ZodBranded = class extends ZodType {
5100
- _parse(input) {
5101
- const { ctx } = this._processInputParams(input);
5102
- const data = ctx.data;
5103
- return this._def.type._parse({
5104
- data,
5105
- path: ctx.path,
5106
- parent: ctx
5107
- });
5108
- }
5109
- unwrap() {
5110
- return this._def.type;
5111
- }
5112
- };
5113
- var ZodPipeline = class _ZodPipeline extends ZodType {
5114
- _parse(input) {
5115
- const { status, ctx } = this._processInputParams(input);
5116
- if (ctx.common.async) {
5117
- const handleAsync = async () => {
5118
- const inResult = await this._def.in._parseAsync({
5119
- data: ctx.data,
5120
- path: ctx.path,
5121
- parent: ctx
5122
- });
5123
- if (inResult.status === "aborted")
5124
- return INVALID;
5125
- if (inResult.status === "dirty") {
5126
- status.dirty();
5127
- return DIRTY(inResult.value);
5128
- } else {
5129
- return this._def.out._parseAsync({
5130
- data: inResult.value,
5131
- path: ctx.path,
5132
- parent: ctx
5133
- });
5134
- }
5135
- };
5136
- return handleAsync();
5137
- } else {
5138
- const inResult = this._def.in._parseSync({
5139
- data: ctx.data,
5140
- path: ctx.path,
5141
- parent: ctx
5142
- });
5143
- if (inResult.status === "aborted")
5144
- return INVALID;
5145
- if (inResult.status === "dirty") {
5146
- status.dirty();
5147
- return {
5148
- status: "dirty",
5149
- value: inResult.value
5150
- };
5151
- } else {
5152
- return this._def.out._parseSync({
5153
- data: inResult.value,
5154
- path: ctx.path,
5155
- parent: ctx
5156
- });
5157
- }
5158
- }
5159
- }
5160
- static create(a3, b3) {
5161
- return new _ZodPipeline({
5162
- in: a3,
5163
- out: b3,
5164
- typeName: ZodFirstPartyTypeKind.ZodPipeline
5165
- });
5166
- }
5167
- };
5168
- var ZodReadonly = class extends ZodType {
5169
- _parse(input) {
5170
- const result = this._def.innerType._parse(input);
5171
- const freeze = (data) => {
5172
- if (isValid(data)) {
5173
- data.value = Object.freeze(data.value);
5174
- }
5175
- return data;
5176
- };
5177
- return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
5178
- }
5179
- unwrap() {
5180
- return this._def.innerType;
5181
- }
5182
- };
5183
- ZodReadonly.create = (type, params) => {
5184
- return new ZodReadonly({
5185
- innerType: type,
5186
- typeName: ZodFirstPartyTypeKind.ZodReadonly,
5187
- ...processCreateParams(params)
5188
- });
5189
- };
5190
- function custom(check, params = {}, fatal) {
5191
- if (check)
5192
- return ZodAny.create().superRefine((data, ctx) => {
5193
- var _a, _b;
5194
- if (!check(data)) {
5195
- const p3 = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
5196
- const _fatal = (_b = (_a = p3.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
5197
- const p22 = typeof p3 === "string" ? { message: p3 } : p3;
5198
- ctx.addIssue({ code: "custom", ...p22, fatal: _fatal });
5199
- }
5200
- });
5201
- return ZodAny.create();
5202
- }
5203
- var late = {
5204
- object: ZodObject.lazycreate
5205
- };
5206
- var ZodFirstPartyTypeKind;
5207
- (function(ZodFirstPartyTypeKind2) {
5208
- ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
5209
- ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
5210
- ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
5211
- ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
5212
- ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
5213
- ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
5214
- ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
5215
- ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
5216
- ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
5217
- ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
5218
- ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
5219
- ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
5220
- ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
5221
- ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
5222
- ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
5223
- ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
5224
- ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
5225
- ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
5226
- ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
5227
- ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
5228
- ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
5229
- ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
5230
- ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
5231
- ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
5232
- ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
5233
- ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
5234
- ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
5235
- ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
5236
- ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
5237
- ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
5238
- ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
5239
- ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
5240
- ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
5241
- ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
5242
- ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
5243
- ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
5244
- })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
5245
- var instanceOfType = (cls, params = {
5246
- message: `Input not instance of ${cls.name}`
5247
- }) => custom((data) => data instanceof cls, params);
5248
- var stringType = ZodString.create;
5249
- var numberType = ZodNumber.create;
5250
- var nanType = ZodNaN.create;
5251
- var bigIntType = ZodBigInt.create;
5252
- var booleanType = ZodBoolean.create;
5253
- var dateType = ZodDate.create;
5254
- var symbolType = ZodSymbol.create;
5255
- var undefinedType = ZodUndefined.create;
5256
- var nullType = ZodNull.create;
5257
- var anyType = ZodAny.create;
5258
- var unknownType = ZodUnknown.create;
5259
- var neverType = ZodNever.create;
5260
- var voidType = ZodVoid.create;
5261
- var arrayType = ZodArray.create;
5262
- var objectType = ZodObject.create;
5263
- var strictObjectType = ZodObject.strictCreate;
5264
- var unionType = ZodUnion.create;
5265
- var discriminatedUnionType = ZodDiscriminatedUnion.create;
5266
- var intersectionType = ZodIntersection.create;
5267
- var tupleType = ZodTuple.create;
5268
- var recordType = ZodRecord.create;
5269
- var mapType = ZodMap.create;
5270
- var setType = ZodSet.create;
5271
- var functionType = ZodFunction.create;
5272
- var lazyType = ZodLazy.create;
5273
- var literalType = ZodLiteral.create;
5274
- var enumType = ZodEnum.create;
5275
- var nativeEnumType = ZodNativeEnum.create;
5276
- var promiseType = ZodPromise.create;
5277
- var effectsType = ZodEffects.create;
5278
- var optionalType = ZodOptional.create;
5279
- var nullableType = ZodNullable.create;
5280
- var preprocessType = ZodEffects.createWithPreprocess;
5281
- var pipelineType = ZodPipeline.create;
5282
- var ostring = () => stringType().optional();
5283
- var onumber = () => numberType().optional();
5284
- var oboolean = () => booleanType().optional();
5285
- var coerce = {
5286
- string: (arg) => ZodString.create({ ...arg, coerce: true }),
5287
- number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
5288
- boolean: (arg) => ZodBoolean.create({
5289
- ...arg,
5290
- coerce: true
5291
- }),
5292
- bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
5293
- date: (arg) => ZodDate.create({ ...arg, coerce: true })
5294
- };
5295
- var NEVER = INVALID;
5296
- var z = /* @__PURE__ */ Object.freeze({
5297
- __proto__: null,
5298
- defaultErrorMap: errorMap,
5299
- setErrorMap,
5300
- getErrorMap,
5301
- makeIssue,
5302
- EMPTY_PATH,
5303
- addIssueToContext,
5304
- ParseStatus,
5305
- INVALID,
5306
- DIRTY,
5307
- OK,
5308
- isAborted,
5309
- isDirty,
5310
- isValid,
5311
- isAsync,
5312
- get util() {
5313
- return util;
5314
- },
5315
- get objectUtil() {
5316
- return objectUtil;
5317
- },
5318
- ZodParsedType,
5319
- getParsedType,
5320
- ZodType,
5321
- datetimeRegex,
5322
- ZodString,
5323
- ZodNumber,
5324
- ZodBigInt,
5325
- ZodBoolean,
5326
- ZodDate,
5327
- ZodSymbol,
5328
- ZodUndefined,
5329
- ZodNull,
5330
- ZodAny,
5331
- ZodUnknown,
5332
- ZodNever,
5333
- ZodVoid,
5334
- ZodArray,
5335
- ZodObject,
5336
- ZodUnion,
5337
- ZodDiscriminatedUnion,
5338
- ZodIntersection,
5339
- ZodTuple,
5340
- ZodRecord,
5341
- ZodMap,
5342
- ZodSet,
5343
- ZodFunction,
5344
- ZodLazy,
5345
- ZodLiteral,
5346
- ZodEnum,
5347
- ZodNativeEnum,
5348
- ZodPromise,
5349
- ZodEffects,
5350
- ZodTransformer: ZodEffects,
5351
- ZodOptional,
5352
- ZodNullable,
5353
- ZodDefault,
5354
- ZodCatch,
5355
- ZodNaN,
5356
- BRAND,
5357
- ZodBranded,
5358
- ZodPipeline,
5359
- ZodReadonly,
5360
- custom,
5361
- Schema: ZodType,
5362
- ZodSchema: ZodType,
5363
- late,
5364
- get ZodFirstPartyTypeKind() {
5365
- return ZodFirstPartyTypeKind;
5366
- },
5367
- coerce,
5368
- any: anyType,
5369
- array: arrayType,
5370
- bigint: bigIntType,
5371
- boolean: booleanType,
5372
- date: dateType,
5373
- discriminatedUnion: discriminatedUnionType,
5374
- effect: effectsType,
5375
- "enum": enumType,
5376
- "function": functionType,
5377
- "instanceof": instanceOfType,
5378
- intersection: intersectionType,
5379
- lazy: lazyType,
5380
- literal: literalType,
5381
- map: mapType,
5382
- nan: nanType,
5383
- nativeEnum: nativeEnumType,
5384
- never: neverType,
5385
- "null": nullType,
5386
- nullable: nullableType,
5387
- number: numberType,
5388
- object: objectType,
5389
- oboolean,
5390
- onumber,
5391
- optional: optionalType,
5392
- ostring,
5393
- pipeline: pipelineType,
5394
- preprocess: preprocessType,
5395
- promise: promiseType,
5396
- record: recordType,
5397
- set: setType,
5398
- strictObject: strictObjectType,
5399
- string: stringType,
5400
- symbol: symbolType,
5401
- transformer: effectsType,
5402
- tuple: tupleType,
5403
- "undefined": undefinedType,
5404
- union: unionType,
5405
- unknown: unknownType,
5406
- "void": voidType,
5407
- NEVER,
5408
- ZodIssueCode,
5409
- quotelessJson,
5410
- ZodError
5411
- });
5412
-
5413
- // libs/embed-libs/shared-embed/src/lib/models/viz-item.model.ts
5414
- var slotsNameParser = z.enum([
5415
- "y-axis",
5416
- "measure",
5417
- "legend",
5418
- "x-axis",
5419
- "evolution",
5420
- "row",
5421
- "column",
5422
- "columns",
5423
- "category",
5424
- "target",
5425
- "color",
5426
- "geo",
5427
- "route",
5428
- "order",
5429
- "source",
5430
- "destination",
5431
- "size",
5432
- "name",
5433
- "levels",
5434
- "open",
5435
- "high",
5436
- "low",
5437
- "close",
5438
- "coordinates",
5439
- "identifier"
5440
- ]);
5441
- var slotParser = z.object({
5442
- name: slotsNameParser,
5443
- content: z.array(
5444
- z.object({
5445
- type: z.enum(["numeric", "hierarchy", "datetime", "spatial"]),
5446
- format: z.string().optional(),
5447
- label: z.union([z.string(), z.record(z.string())]).optional(),
5448
- column: z.string().uuid().optional(),
5449
- set: z.string().uuid().optional(),
5450
- aggregationFunc: z.string().optional(),
5451
- subtype: z.string().optional(),
5452
- level: z.number().optional(),
5453
- lowestLevel: z.number().optional(),
5454
- currency: z.string().optional(),
5455
- id: z.string().optional(),
5456
- bins: z.object({
5457
- enabled: z.boolean(),
5458
- // eslint-disable-next-line id-blacklist
5459
- number: z.number()
5460
- }).optional()
5461
- })
5462
- )
5463
- });
5464
- var itemTypeParser = z.enum([
5465
- "bar-chart",
5466
- "column-chart",
5467
- "area-chart",
5468
- "one-number",
5469
- "pivot-table",
5470
- "textobject",
5471
- "regular-table",
5472
- "donut",
5473
- "line-chart",
5474
- "imageobject",
5475
- "number-conditional",
5476
- "combination-chart",
5477
- "spacer",
5478
- "boxplot",
5479
- "circle-gauge",
5480
- "treemap",
5481
- "choropleth",
5482
- "symbolmap",
5483
- "routemap",
5484
- "markermap",
5485
- "hexbinmap",
5486
- "heatmap",
5487
- "spikemap",
5488
- "heattable",
5489
- "bullet",
5490
- "funnel",
5491
- "sunburst",
5492
- "bubble-chart",
5493
- "sankey",
5494
- "scatter-plot",
5495
- "speedometer",
5496
- "circle-pack",
5497
- "radar-chart",
5498
- "pyramid",
5499
- "parallel-coord",
5500
- "ohlc",
5501
- "strip-plot",
5502
- "wordcloud",
5503
- "videoobject",
5504
- "venn-diagram"
5505
- ]);
5506
- var slotsParser = z.array(slotParser);
5507
- var vizItemOptionsParser = z.object({
5508
- title: z.record(z.string()).optional(),
5509
- theme: z.union([z.string(), z.record(z.any())]).optional(),
5510
- locale: z.string().optional(),
5511
- html: z.record(z.string()).optional(),
5512
- slices: z.record(z.any()).optional(),
5513
- mode: z.string().optional(),
5514
- url: z.string().optional(),
5515
- bars: z.record(z.any()).optional(),
5516
- manualValues: z.record(z.any()).optional(),
5517
- measures: z.array(z.record(z.any())).optional(),
5518
- classification: z.string().optional(),
5519
- numberClasses: z.number().optional(),
5520
- tileProvider: z.record(z.any()).optional(),
5521
- vectorTileProvider: z.record(z.any()).optional(),
5522
- sources: z.record(z.any()).optional(),
5523
- display: z.union([z.record(z.any()), z.object({ title: z.boolean() })]).optional()
5524
- });
5525
- var canFilterParser = z.union([z.array(z.string()), z.literal("all")]);
5526
- var libraryTypeToWebComponentTypeMapping = {
5527
- type: "type",
5528
- theme: "theme",
5529
- slots: "slots",
5530
- options: "options",
5531
- appServer: "app-server",
5532
- apiHost: "api-host",
5533
- authKey: "auth-key",
5534
- authToken: "auth-token",
5535
- contextId: "context-id",
5536
- canFilter: "can-filter",
5537
- filters: "filters"
5538
- };
5539
-
5540
1492
  // libs/embed-libs/shared-embed/src/lib/constants/class-constants.ts
5541
1493
  var luzmoEmbedContainerClass = "luzmo-embed-container";
5542
1494
 
@@ -5604,21 +1556,6 @@ function __federationMethodWrapDefault(module2, need) {
5604
1556
  async function __federationMethodGetRemote(remoteName, componentName) {
5605
1557
  return __federationMethodEnsure(remoteName).then((remote) => remote.get(componentName).then((factory) => factory()));
5606
1558
  }
5607
- async function loadLibrary(appServer, componentName = "DashboardApp") {
5608
- if (remotesMap[appServer]) {
5609
- return remotesMap[appServer].module;
5610
- }
5611
- remotesMap[appServer] = {
5612
- url: appServer?.startsWith("http://localhost") ? `${removeTrailingSlash(appServer)}/remoteEntry.mjs` : `${removeTrailingSlash(appServer)}/dashboard-app/remoteEntry.mjs`,
5613
- format: "esm",
5614
- from: "vite",
5615
- module: void 0
5616
- };
5617
- const module2 = await __federationMethodGetRemote(appServer, `./${componentName}`);
5618
- const wrappedModule = __federationMethodWrapDefault(module2, true);
5619
- remotesMap[appServer].module = wrappedModule;
5620
- return wrappedModule;
5621
- }
5622
1559
 
5623
1560
  // node_modules/lit-html/lit-html.js
5624
1561
  var t3 = globalThis;
@@ -5969,7 +1906,7 @@ var o5 = e6(class extends i4 {
5969
1906
  });
5970
1907
 
5971
1908
  // libs/embed-libs/embed/package.json
5972
- var version = "5.1.3-beta.3";
1909
+ var version = "5.1.4";
5973
1910
 
5974
1911
  // libs/embed-libs/embed/src/lib/luzmo-service.ts
5975
1912
  var LuzmoService = class {
@@ -6139,6 +2076,7 @@ var _setEventHandler = () => {
6139
2076
  var dashboardStyles = i`
6140
2077
  :host {
6141
2078
  display: block;
2079
+ height: 100%;
6142
2080
  }
6143
2081
 
6144
2082
  @-webkit-keyframes spin {
@@ -6173,6 +2111,9 @@ var dashboardStyles = i`
6173
2111
  border: 0;
6174
2112
  }
6175
2113
 
2114
+ .luzmo-embed-dashboard-ede {
2115
+ }
2116
+
6176
2117
  .luzmo-embed-container-ede {
6177
2118
  width: 100%;
6178
2119
  height: 100%;
@@ -6249,7 +2190,7 @@ var dashboardStyles = i`
6249
2190
 
6250
2191
  // libs/embed-libs/embed/src/lib/dashboard-component/dashboard-base.ts
6251
2192
  var LuzmoDashboard = class extends s3 {
6252
- constructor() {
2193
+ constructor(inputParameters) {
6253
2194
  super();
6254
2195
  this.language = "auto";
6255
2196
  this.screenMode = "auto";
@@ -6268,11 +2209,10 @@ var LuzmoDashboard = class extends s3 {
6268
2209
  this.browserErrorMsg = "";
6269
2210
  this.dashboardError = false;
6270
2211
  this.browserNotSupported = [];
6271
- this.libVersion = version + "-wc-luzmo";
2212
+ this.VERSION = version + "-wc-luzmo";
6272
2213
  this.isLibraryLoaded = false;
6273
2214
  this.currentAuthKey = null;
6274
2215
  this.currentAuthToken = null;
6275
- this.isInitCalled = false;
6276
2216
  this.attributesMap = {
6277
2217
  dashboardId: "dashboard-id",
6278
2218
  dashboardSlug: "dashboard-slug",
@@ -6302,6 +2242,7 @@ var LuzmoDashboard = class extends s3 {
6302
2242
  this._iframeId = `luzmo-dashboard-${this._containerId}`;
6303
2243
  this.iframeLoaded = false;
6304
2244
  this.promises = {};
2245
+ this.setInputParameters(inputParameters);
6305
2246
  this.params = this._setOptions();
6306
2247
  this._onResize = () => {
6307
2248
  if (this.shadowRoot?.querySelector(".dashboard-container")) {
@@ -6332,6 +2273,60 @@ var LuzmoDashboard = class extends s3 {
6332
2273
  });
6333
2274
  });
6334
2275
  }
2276
+ loadLibrary(appServer) {
2277
+ if (remotesMap[appServer]) {
2278
+ return Promise.resolve(remotesMap[appServer].module);
2279
+ }
2280
+ remotesMap[appServer] = {
2281
+ url: appServer?.startsWith("http://localhost") ? `${removeTrailingSlash(appServer)}/remoteEntry.mjs` : `${removeTrailingSlash(appServer)}/dashboard-app/remoteEntry.mjs`,
2282
+ format: "esm",
2283
+ from: "vite",
2284
+ module: void 0
2285
+ };
2286
+ return __federationMethodGetRemote(appServer, "./DashboardApp").then((module2) => {
2287
+ const wrappedModule = __federationMethodWrapDefault(module2, true);
2288
+ remotesMap[appServer].module = wrappedModule;
2289
+ return wrappedModule;
2290
+ });
2291
+ }
2292
+ setInputParameters(inputParameters) {
2293
+ if (!inputParameters) {
2294
+ return;
2295
+ }
2296
+ const params = [
2297
+ "dashboardId",
2298
+ "dashboardSlug",
2299
+ "itemId",
2300
+ "language",
2301
+ "qeVersion",
2302
+ "screenMode",
2303
+ "switchScreenModeOnResize",
2304
+ "accentColor",
2305
+ "mainColor",
2306
+ "authToken",
2307
+ "authKey",
2308
+ "editMode",
2309
+ "loaderBackground",
2310
+ "loaderFontColor",
2311
+ "loaderSpinnerColor",
2312
+ "loaderSpinnerBackground",
2313
+ "timezoneId",
2314
+ "itemDimensions",
2315
+ "apiHost"
2316
+ ];
2317
+ for (const key of params) {
2318
+ const value = inputParameters[key];
2319
+ if (value) {
2320
+ this[key] = value;
2321
+ }
2322
+ }
2323
+ if (inputParameters.experimental) {
2324
+ this.experimental = inputParameters.experimental;
2325
+ }
2326
+ if (inputParameters.appServer) {
2327
+ this.appServer = addTrailingSlash(inputParameters.appServer);
2328
+ }
2329
+ }
6335
2330
  // Set resize event listener
6336
2331
  connectedCallback() {
6337
2332
  super.connectedCallback();
@@ -6350,6 +2345,7 @@ var LuzmoDashboard = class extends s3 {
6350
2345
  this._loaderMsg = getLoader(this)?.loadingMsg;
6351
2346
  this._loaderStyles();
6352
2347
  luzmo_service_default._components.push(this);
2348
+ this.initComponent();
6353
2349
  if (this.luzmoEmbedContainer) {
6354
2350
  this._resizeObserver.observe(this.luzmoEmbedContainer);
6355
2351
  }
@@ -6357,7 +2353,7 @@ var LuzmoDashboard = class extends s3 {
6357
2353
  initComponent() {
6358
2354
  this.params = this._setOptions();
6359
2355
  if (this.getIsViewMode()) {
6360
- loadLibrary(this.params.appServer).then(async () => {
2356
+ this.loadLibrary(this.params.appServer).then(async () => {
6361
2357
  this.isLibraryLoaded = true;
6362
2358
  await this.updateComplete;
6363
2359
  const oldReference = this.renderRoot.querySelector("dashboard-component");
@@ -6429,21 +2425,11 @@ var LuzmoDashboard = class extends s3 {
6429
2425
  "timezoneId",
6430
2426
  "itemDimensions"
6431
2427
  ]);
6432
- const conditionsToCheck = ["dashboardId", "dashboardSlug", "itemId"];
6433
- let callInitComponent = false;
6434
- for (const condition of conditionsToCheck) {
6435
- callInitComponent = callInitComponent || changedProperties.get(condition) === void 0 && this[condition];
6436
- }
6437
- if (callInitComponent && !this.isInitCalled) {
6438
- this.initComponent();
6439
- this.isInitCalled = true;
6440
- return;
6441
- }
6442
2428
  if (this.getIsViewMode()) {
6443
2429
  if (this.dashboardReference) {
6444
2430
  for (const [propertyName] of changedProperties.entries()) {
6445
2431
  if (propertyName === "appSever") {
6446
- loadLibrary(changedProperties[propertyName]).then(async () => {
2432
+ this.loadLibrary(changedProperties[propertyName]).then(async () => {
6447
2433
  this.isLibraryLoaded = true;
6448
2434
  await this.updateComplete;
6449
2435
  this.dashboardReference = this.renderRoot.querySelector("dashboard-component");
@@ -6651,7 +2637,7 @@ var LuzmoDashboard = class extends s3 {
6651
2637
  ${this.dashboardId || this.dashboardSlug ? x`
6652
2638
  ${loader}
6653
2639
  <iframe
6654
- class="luzmo-embed-dashboard"
2640
+ class="luzmo-embed-dashboard ${!this.getIsViewMode() ? `luzmo-embed-dashboard-ede` : ""}"
6655
2641
  id="${this._iframeId}"
6656
2642
  name="${this._iframeId}"
6657
2643
  style=${o5(this.iframeStyle)}
@@ -6942,7 +2928,7 @@ __decorateClass([
6942
2928
  ], LuzmoDashboard.prototype, "browserNotSupported", 2);
6943
2929
  __decorateClass([
6944
2930
  n3()
6945
- ], LuzmoDashboard.prototype, "libVersion", 2);
2931
+ ], LuzmoDashboard.prototype, "VERSION", 2);
6946
2932
  __decorateClass([
6947
2933
  r4()
6948
2934
  ], LuzmoDashboard.prototype, "isLibraryLoaded", 2);
@@ -6955,9 +2941,6 @@ __decorateClass([
6955
2941
  __decorateClass([
6956
2942
  r4()
6957
2943
  ], LuzmoDashboard.prototype, "currentAuthToken", 2);
6958
- __decorateClass([
6959
- r4()
6960
- ], LuzmoDashboard.prototype, "isInitCalled", 2);
6961
2944
 
6962
2945
  // libs/embed-libs/embed/src/lib/dashboard-component/dashboard-web-component.ts
6963
2946
  var LuzmoDashboardWebComponent = class extends LuzmoDashboard {
@@ -6965,305 +2948,6 @@ var LuzmoDashboardWebComponent = class extends LuzmoDashboard {
6965
2948
  LuzmoDashboardWebComponent = __decorateClass([
6966
2949
  t("luzmo-dashboard-web-component")
6967
2950
  ], LuzmoDashboardWebComponent);
6968
-
6969
- // node_modules/zod-validation-error/dist/index.mjs
6970
- var ValidationError = class extends Error {
6971
- name;
6972
- details;
6973
- constructor(message, options) {
6974
- super(message, options);
6975
- this.name = "ZodValidationError";
6976
- this.details = getIssuesFromErrorOptions(options);
6977
- }
6978
- toString() {
6979
- return this.message;
6980
- }
6981
- };
6982
- function getIssuesFromErrorOptions(options) {
6983
- if (options) {
6984
- const cause = options.cause;
6985
- if (cause instanceof ZodError) {
6986
- return cause.issues;
6987
- }
6988
- }
6989
- return [];
6990
- }
6991
- var ISSUE_SEPARATOR = "; ";
6992
- var MAX_ISSUES_IN_MESSAGE = 99;
6993
- var PREFIX = "Validation error";
6994
- var PREFIX_SEPARATOR = ": ";
6995
- var UNION_SEPARATOR = ", or ";
6996
- function prefixMessage(message, prefix, prefixSeparator) {
6997
- if (prefix !== null) {
6998
- if (message.length > 0) {
6999
- return [prefix, message].join(prefixSeparator);
7000
- }
7001
- return prefix;
7002
- }
7003
- if (message.length > 0) {
7004
- return message;
7005
- }
7006
- return PREFIX;
7007
- }
7008
- var identifierRegex = /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;
7009
- function joinPath(path) {
7010
- if (path.length === 1) {
7011
- return path[0].toString();
7012
- }
7013
- return path.reduce((acc, item) => {
7014
- if (typeof item === "number") {
7015
- return acc + "[" + item.toString() + "]";
7016
- }
7017
- if (item.includes('"')) {
7018
- return acc + '["' + escapeQuotes(item) + '"]';
7019
- }
7020
- if (!identifierRegex.test(item)) {
7021
- return acc + '["' + item + '"]';
7022
- }
7023
- const separator = acc.length === 0 ? "" : ".";
7024
- return acc + separator + item;
7025
- }, "");
7026
- }
7027
- function escapeQuotes(str) {
7028
- return str.replace(/"/g, '\\"');
7029
- }
7030
- function isNonEmptyArray(value) {
7031
- return value.length !== 0;
7032
- }
7033
- function getMessageFromZodIssue(props) {
7034
- const { issue, issueSeparator, unionSeparator, includePath } = props;
7035
- if (issue.code === "invalid_union") {
7036
- return issue.unionErrors.reduce((acc, zodError) => {
7037
- const newIssues = zodError.issues.map(
7038
- (issue2) => getMessageFromZodIssue({
7039
- issue: issue2,
7040
- issueSeparator,
7041
- unionSeparator,
7042
- includePath
7043
- })
7044
- ).join(issueSeparator);
7045
- if (!acc.includes(newIssues)) {
7046
- acc.push(newIssues);
7047
- }
7048
- return acc;
7049
- }, []).join(unionSeparator);
7050
- }
7051
- if (issue.code === "invalid_arguments") {
7052
- return [
7053
- issue.message,
7054
- ...issue.argumentsError.issues.map(
7055
- (issue2) => getMessageFromZodIssue({
7056
- issue: issue2,
7057
- issueSeparator,
7058
- unionSeparator,
7059
- includePath
7060
- })
7061
- )
7062
- ].join(issueSeparator);
7063
- }
7064
- if (issue.code === "invalid_return_type") {
7065
- return [
7066
- issue.message,
7067
- ...issue.returnTypeError.issues.map(
7068
- (issue2) => getMessageFromZodIssue({
7069
- issue: issue2,
7070
- issueSeparator,
7071
- unionSeparator,
7072
- includePath
7073
- })
7074
- )
7075
- ].join(issueSeparator);
7076
- }
7077
- if (includePath && isNonEmptyArray(issue.path)) {
7078
- if (issue.path.length === 1) {
7079
- const identifier = issue.path[0];
7080
- if (typeof identifier === "number") {
7081
- return `${issue.message} at index ${identifier}`;
7082
- }
7083
- }
7084
- return `${issue.message} at "${joinPath(issue.path)}"`;
7085
- }
7086
- return issue.message;
7087
- }
7088
- function fromZodError(zodError, options = {}) {
7089
- if (!(zodError instanceof ZodError)) {
7090
- throw new TypeError(
7091
- `Invalid zodError param; expected instance of ZodError. Did you mean to use the "${fromError.name}" method instead?`
7092
- );
7093
- }
7094
- const {
7095
- maxIssuesInMessage = MAX_ISSUES_IN_MESSAGE,
7096
- issueSeparator = ISSUE_SEPARATOR,
7097
- unionSeparator = UNION_SEPARATOR,
7098
- prefixSeparator = PREFIX_SEPARATOR,
7099
- prefix = PREFIX,
7100
- includePath = true
7101
- } = options;
7102
- const zodIssues = zodError.errors;
7103
- const reason = zodIssues.length === 0 ? zodError.message : zodIssues.slice(0, maxIssuesInMessage).map(
7104
- (issue) => getMessageFromZodIssue({
7105
- issue,
7106
- issueSeparator,
7107
- unionSeparator,
7108
- includePath
7109
- })
7110
- ).join(issueSeparator);
7111
- const message = prefixMessage(reason, prefix, prefixSeparator);
7112
- return new ValidationError(message, { cause: zodError });
7113
- }
7114
- var toValidationError = (options = {}) => (err) => {
7115
- if (err instanceof ZodError) {
7116
- return fromZodError(err, options);
7117
- }
7118
- if (err instanceof Error) {
7119
- return new ValidationError(err.message, { cause: err });
7120
- }
7121
- return new ValidationError("Unknown error");
7122
- };
7123
- function fromError(err, options = {}) {
7124
- return toValidationError(options)(err);
7125
- }
7126
-
7127
- // libs/embed-libs/embed/src/lib/viz-item/viz-item.base.ts
7128
- var LuzmoBaseVizItem = class extends s3 {
7129
- constructor() {
7130
- super();
7131
- this.appServer = "https://app.luzmo.com";
7132
- this.apiHost = "https://api.luzmo.com";
7133
- this.slots = [];
7134
- this.options = {
7135
- title: {
7136
- en: ""
7137
- },
7138
- theme: "default"
7139
- };
7140
- this.version = version + "-wc-luzmo";
7141
- }
7142
- static {
7143
- // Static styles to set host display to block, else it is not shown at all for some reason.
7144
- this.styles = i`
7145
- :host {
7146
- display: block;
7147
- width: 100%;
7148
- height: 100%;
7149
- }
7150
- `;
7151
- }
7152
- async firstUpdated(_changedProperties) {
7153
- super.firstUpdated(_changedProperties);
7154
- if (this.type) {
7155
- await loadLibrary(this.appServer, "DashboardApp");
7156
- this.createAndAppendElement();
7157
- }
7158
- }
7159
- createAndAppendElement() {
7160
- if (!this.chartElement) {
7161
- this.chartElement = document.createElement("chart-component");
7162
- this.chartElement.setAttribute("embedding-mode", "chart");
7163
- this.updateVizItemProperties();
7164
- this.renderRoot.append(this.chartElement);
7165
- }
7166
- }
7167
- updateVizItemProperties() {
7168
- if (this.chartElement) {
7169
- for (const key in libraryTypeToWebComponentTypeMapping) {
7170
- const value = this[key];
7171
- if (value) {
7172
- this.parseAndValidate(key);
7173
- const attributeValue = ["appServer", "apiHost"].includes(key) ? removeTrailingSlash(value) : value;
7174
- this.chartElement.setAttribute(
7175
- libraryTypeToWebComponentTypeMapping[key],
7176
- typeof attributeValue === "object" ? JSON.stringify(attributeValue) : attributeValue
7177
- );
7178
- }
7179
- }
7180
- }
7181
- }
7182
- async updated(changedProperties) {
7183
- if (this.chartElement) {
7184
- for (const [propertyName] of changedProperties.entries()) {
7185
- const mappedAttributeName = libraryTypeToWebComponentTypeMapping[propertyName] ?? propertyName;
7186
- this.parseAndValidate(propertyName);
7187
- const attributeValue = typeof this[propertyName] === "object" ? JSON.stringify(this[propertyName]) : this[propertyName]?.toString() ?? this[propertyName];
7188
- this.chartElement.setAttribute(mappedAttributeName, attributeValue);
7189
- }
7190
- } else {
7191
- if (this.type) {
7192
- this.parseAndValidate("type");
7193
- await loadLibrary(this.appServer, "DashboardApp");
7194
- this.createAndAppendElement();
7195
- }
7196
- }
7197
- }
7198
- parseAndValidate(key) {
7199
- try {
7200
- if (key === "slots") {
7201
- slotsParser.parse(this.slots);
7202
- } else if (key === "options") {
7203
- vizItemOptionsParser.parse(this.options);
7204
- } else if (key === "canFilter") {
7205
- canFilterParser.parse(this.canFilter);
7206
- } else if (key === "type") {
7207
- itemTypeParser.parse(this.type);
7208
- }
7209
- } catch (err) {
7210
- const validationError = fromError(err);
7211
- console.error(err);
7212
- console.error(validationError.toString());
7213
- }
7214
- }
7215
- render() {
7216
- return x` `;
7217
- }
7218
- };
7219
- __decorateClass([
7220
- n3()
7221
- ], LuzmoBaseVizItem.prototype, "appServer", 2);
7222
- __decorateClass([
7223
- n3()
7224
- ], LuzmoBaseVizItem.prototype, "apiHost", 2);
7225
- __decorateClass([
7226
- n3({ type: Array })
7227
- ], LuzmoBaseVizItem.prototype, "slots", 2);
7228
- __decorateClass([
7229
- n3({ type: Object })
7230
- ], LuzmoBaseVizItem.prototype, "options", 2);
7231
- __decorateClass([
7232
- n3()
7233
- ], LuzmoBaseVizItem.prototype, "type", 2);
7234
- __decorateClass([
7235
- n3()
7236
- ], LuzmoBaseVizItem.prototype, "authKey", 2);
7237
- __decorateClass([
7238
- n3()
7239
- ], LuzmoBaseVizItem.prototype, "authToken", 2);
7240
- __decorateClass([
7241
- n3()
7242
- ], LuzmoBaseVizItem.prototype, "version", 2);
7243
- __decorateClass([
7244
- n3()
7245
- ], LuzmoBaseVizItem.prototype, "contextId", 2);
7246
- __decorateClass([
7247
- n3({
7248
- converter: (value) => {
7249
- try {
7250
- return JSON.parse(value);
7251
- } catch (exc) {
7252
- return value;
7253
- }
7254
- }
7255
- })
7256
- ], LuzmoBaseVizItem.prototype, "canFilter", 2);
7257
- __decorateClass([
7258
- n3({ type: Array })
7259
- ], LuzmoBaseVizItem.prototype, "filters", 2);
7260
-
7261
- // libs/embed-libs/embed/src/lib/viz-item/viz-item-web-component.ts
7262
- var LuzmoVizItemWebComponent = class extends LuzmoBaseVizItem {
7263
- };
7264
- LuzmoVizItemWebComponent = __decorateClass([
7265
- t("luzmo-viz-item-web-component")
7266
- ], LuzmoVizItemWebComponent);
7267
2951
  /*! Bundled license information:
7268
2952
 
7269
2953
  @lit/reactive-element/decorators/custom-element.js: