@uniformdev/cli 18.16.1-alpha.6 → 18.18.1-alpha.12

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.
@@ -26,6 +26,32 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
27
  mod
28
28
  ));
29
+ var __accessCheck = (obj, member, msg) => {
30
+ if (!member.has(obj))
31
+ throw TypeError("Cannot " + msg);
32
+ };
33
+ var __privateGet = (obj, member, getter) => {
34
+ __accessCheck(obj, member, "read from private field");
35
+ return getter ? getter.call(obj) : member.get(obj);
36
+ };
37
+ var __privateAdd = (obj, member, value) => {
38
+ if (member.has(obj))
39
+ throw TypeError("Cannot add the same private member more than once");
40
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
41
+ };
42
+ var __privateSet = (obj, member, value, setter) => {
43
+ __accessCheck(obj, member, "write to private field");
44
+ setter ? setter.call(obj, value) : member.set(obj, value);
45
+ return value;
46
+ };
47
+ var __privateWrapper = (obj, member, setter, getter) => ({
48
+ set _(value) {
49
+ __privateSet(obj, member, value, setter);
50
+ },
51
+ get _() {
52
+ return __privateGet(obj, member, getter);
53
+ }
54
+ });
29
55
 
30
56
  // ../../node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js
31
57
  var require_color_name = __commonJS({
@@ -1339,14 +1365,14 @@ var require_templates = __commonJS({
1339
1365
  }
1340
1366
  return results;
1341
1367
  }
1342
- function buildStyle(chalk, styles) {
1368
+ function buildStyle(chalk3, styles) {
1343
1369
  const enabled = {};
1344
1370
  for (const layer of styles) {
1345
1371
  for (const style of layer.styles) {
1346
1372
  enabled[style[0]] = layer.inverse ? null : style.slice(1);
1347
1373
  }
1348
1374
  }
1349
- let current = chalk;
1375
+ let current = chalk3;
1350
1376
  for (const [styleName, styles2] of Object.entries(enabled)) {
1351
1377
  if (!Array.isArray(styles2)) {
1352
1378
  continue;
@@ -1358,7 +1384,7 @@ var require_templates = __commonJS({
1358
1384
  }
1359
1385
  return current;
1360
1386
  }
1361
- module.exports = (chalk, temporary) => {
1387
+ module.exports = (chalk3, temporary) => {
1362
1388
  const styles = [];
1363
1389
  const chunks = [];
1364
1390
  let chunk = [];
@@ -1368,13 +1394,13 @@ var require_templates = __commonJS({
1368
1394
  } else if (style) {
1369
1395
  const string = chunk.join("");
1370
1396
  chunk = [];
1371
- chunks.push(styles.length === 0 ? string : buildStyle(chalk, styles)(string));
1397
+ chunks.push(styles.length === 0 ? string : buildStyle(chalk3, styles)(string));
1372
1398
  styles.push({ inverse, styles: parseStyle(style) });
1373
1399
  } else if (close) {
1374
1400
  if (styles.length === 0) {
1375
1401
  throw new Error("Found extraneous } in Chalk template literal");
1376
1402
  }
1377
- chunks.push(buildStyle(chalk, styles)(chunk.join("")));
1403
+ chunks.push(buildStyle(chalk3, styles)(chunk.join("")));
1378
1404
  chunk = [];
1379
1405
  styles.pop();
1380
1406
  } else {
@@ -1422,16 +1448,16 @@ var require_source = __commonJS({
1422
1448
  }
1423
1449
  };
1424
1450
  var chalkFactory = (options) => {
1425
- const chalk2 = {};
1426
- applyOptions(chalk2, options);
1427
- chalk2.template = (...arguments_) => chalkTag(chalk2.template, ...arguments_);
1428
- Object.setPrototypeOf(chalk2, Chalk.prototype);
1429
- Object.setPrototypeOf(chalk2.template, chalk2);
1430
- chalk2.template.constructor = () => {
1451
+ const chalk4 = {};
1452
+ applyOptions(chalk4, options);
1453
+ chalk4.template = (...arguments_) => chalkTag(chalk4.template, ...arguments_);
1454
+ Object.setPrototypeOf(chalk4, Chalk.prototype);
1455
+ Object.setPrototypeOf(chalk4.template, chalk4);
1456
+ chalk4.template.constructor = () => {
1431
1457
  throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.");
1432
1458
  };
1433
- chalk2.template.Instance = ChalkClass;
1434
- return chalk2.template;
1459
+ chalk4.template.Instance = ChalkClass;
1460
+ return chalk4.template;
1435
1461
  };
1436
1462
  function Chalk(options) {
1437
1463
  return chalkFactory(options);
@@ -1542,7 +1568,7 @@ var require_source = __commonJS({
1542
1568
  return openAll + string + closeAll;
1543
1569
  };
1544
1570
  var template;
1545
- var chalkTag = (chalk2, ...strings) => {
1571
+ var chalkTag = (chalk4, ...strings) => {
1546
1572
  const [firstString] = strings;
1547
1573
  if (!isArray(firstString) || !isArray(firstString.raw)) {
1548
1574
  return strings.join(" ");
@@ -1558,19 +1584,442 @@ var require_source = __commonJS({
1558
1584
  if (template === void 0) {
1559
1585
  template = require_templates();
1560
1586
  }
1561
- return template(chalk2, parts.join(""));
1587
+ return template(chalk4, parts.join(""));
1562
1588
  };
1563
1589
  Object.defineProperties(Chalk.prototype, styles);
1564
- var chalk = Chalk();
1565
- chalk.supportsColor = stdoutColor;
1566
- chalk.stderr = Chalk({ level: stderrColor ? stderrColor.level : 0 });
1567
- chalk.stderr.supportsColor = stderrColor;
1568
- module.exports = chalk;
1590
+ var chalk3 = Chalk();
1591
+ chalk3.supportsColor = stdoutColor;
1592
+ chalk3.stderr = Chalk({ level: stderrColor ? stderrColor.level : 0 });
1593
+ chalk3.stderr.supportsColor = stderrColor;
1594
+ module.exports = chalk3;
1569
1595
  }
1570
1596
  });
1571
1597
 
1598
+ // src/sync/arraySyncEngineDataSource.ts
1599
+ async function createArraySyncEngineDataSource({
1600
+ objects,
1601
+ selectIdentifier,
1602
+ selectDisplayName = selectIdentifier,
1603
+ onSyncComplete
1604
+ }) {
1605
+ const objectIndex = objects.reduce((result, current) => {
1606
+ const identifier = selectIdentifier(current);
1607
+ if (result[identifier]) {
1608
+ throw new Error(`Identifier ${identifier} was not unique.`);
1609
+ }
1610
+ result[identifier] = {
1611
+ id: identifier,
1612
+ object: current,
1613
+ providerId: identifier,
1614
+ displayName: selectDisplayName(current)
1615
+ };
1616
+ return result;
1617
+ }, {});
1618
+ async function* getObjects() {
1619
+ for (const item of Object.values(objectIndex)) {
1620
+ yield item;
1621
+ }
1622
+ }
1623
+ function extractCurrent() {
1624
+ return Object.entries(objectIndex).sort((a, b) => a[0].localeCompare(b[0])).map((entry) => entry[1].object);
1625
+ }
1626
+ return {
1627
+ objects: getObjects(),
1628
+ deleteObject: async (providerId) => {
1629
+ delete objectIndex[providerId];
1630
+ },
1631
+ writeObject: async (objectToWrite) => {
1632
+ const id = selectIdentifier(objectToWrite.object);
1633
+ objectIndex[id] = objectToWrite;
1634
+ },
1635
+ extractCurrent,
1636
+ onSyncComplete: onSyncComplete ? (isTarget) => onSyncComplete(isTarget, extractCurrent()) : void 0
1637
+ };
1638
+ }
1639
+
1640
+ // src/sync/fileSyncEngineDataSource.ts
1641
+ var import_chalk = __toESM(require_source());
1642
+ import { existsSync, mkdirSync } from "fs";
1643
+ import { readdir, unlink } from "fs/promises";
1644
+ import { extname as extname2, join } from "path";
1645
+
1646
+ // src/sync/util.ts
1647
+ import { writeFileSync } from "fs";
1648
+ import { readFileSync } from "fs";
1649
+ import { HttpsProxyAgent } from "https-proxy-agent";
1650
+ import unfetch from "isomorphic-unfetch";
1651
+ import { dump, load } from "js-yaml";
1652
+ import { extname } from "path";
1653
+ function withApiOptions(yargs) {
1654
+ var _a, _b, _c;
1655
+ return yargs.option("apiKey", {
1656
+ describe: "Uniform API key. Defaults to UNIFORM_CLI_API_KEY or UNIFORM_API_KEY env. Supports dotenv.",
1657
+ default: (_c = (_b = (_a = process.env.UNIFORM_CLI_API_KEY) != null ? _a : process.env.CANVAS_CLI_API_KEY) != null ? _b : process.env.UPM_CLI_API_KEY) != null ? _c : process.env.UNIFORM_API_KEY,
1658
+ demandOption: true,
1659
+ type: "string"
1660
+ }).option("apiHost", {
1661
+ describe: "Uniform host. Defaults to UNIFORM_CLI_BASE_URL env var or https://uniform.app. Supports dotenv.",
1662
+ default: process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app",
1663
+ demandOption: true,
1664
+ type: "string"
1665
+ }).option("edgeApiHost", {
1666
+ describe: "Uniform edge host. Defaults to UNIFORM_CLI_BASE_EDGE_URL env var or https://uniform.global. Supports dotenv.",
1667
+ default: process.env.UNIFORM_CLI_BASE_EDGE_URL || "https://uniform.global",
1668
+ demandOption: true,
1669
+ type: "string"
1670
+ }).option("proxy", {
1671
+ describe: "HTTPS proxy to use for Uniform API calls. Defaults to HTTPS_PROXY, https_proxy, ALL_PROXY, or all_proxy env vars (in that order). Supports dotenv.",
1672
+ default: process.env.HTTPS_PROXY || process.env.https_proxy || process.env.ALL_PROXY || process.env.all_proxy,
1673
+ type: "string"
1674
+ });
1675
+ }
1676
+ function nodeFetchProxy(proxy) {
1677
+ if (proxy) {
1678
+ console.log(`\u{1F991} Using proxy ${proxy}`);
1679
+ }
1680
+ const wrappedFetch = (input, init) => {
1681
+ if (proxy) {
1682
+ const wrappedInit = {
1683
+ ...init,
1684
+ agent: new HttpsProxyAgent(proxy)
1685
+ };
1686
+ return unfetch(input, wrappedInit);
1687
+ }
1688
+ return unfetch(input, init);
1689
+ };
1690
+ return wrappedFetch;
1691
+ }
1692
+ function withProjectOptions(yargs) {
1693
+ var _a, _b, _c;
1694
+ return yargs.option("project", {
1695
+ describe: "Uniform project ID. Defaults to UNIFORM_CLI_PROJECT_ID or UNIFORM_PROJECT_ID env. Supports dotenv.",
1696
+ default: (_c = (_b = (_a = process.env.UNIFORM_CLI_PROJECT_ID) != null ? _a : process.env.CANVAS_CLI_PROJECT_ID) != null ? _b : process.env.UPM_CLI_PROJECT_ID) != null ? _c : process.env.UNIFORM_PROJECT_ID,
1697
+ demandOption: true,
1698
+ type: "string",
1699
+ alias: ["p"]
1700
+ });
1701
+ }
1702
+ function withFormatOptions(yargs) {
1703
+ return yargs.option("format", {
1704
+ alias: ["f"],
1705
+ describe: "Output format",
1706
+ default: "yaml",
1707
+ choices: ["yaml", "json"],
1708
+ type: "string"
1709
+ }).option("filename", {
1710
+ alias: ["o"],
1711
+ describe: "Output filename. If not specified, write to stdout.",
1712
+ type: "string"
1713
+ });
1714
+ }
1715
+ function withDiffOptions(yargs) {
1716
+ var _a;
1717
+ return yargs.option("diff", {
1718
+ describe: "Whether to show diffs in stdout. off = no diffs; update = on for updates; on = updates, creates, deletes. Can be set by UNIFORM_CLI_DIFF_MODE environment variable.",
1719
+ default: (_a = process.env.UNIFORM_CLI_DIFF_MODE) != null ? _a : "off",
1720
+ type: "string",
1721
+ choices: ["off", "update", "on"],
1722
+ alias: ["d"]
1723
+ });
1724
+ }
1725
+ function isPathAPackageFile(path) {
1726
+ const extension = extname(path);
1727
+ return extension === ".yaml" || extension === ".yml" || extension === ".json";
1728
+ }
1729
+ function emitWithFormat(object, format, filename) {
1730
+ let content;
1731
+ if (filename && !format) {
1732
+ const extension = extname(filename);
1733
+ if (extension === ".yaml" || extension === ".yml") {
1734
+ format = "yaml";
1735
+ } else if (extension === ".json") {
1736
+ format = "json";
1737
+ }
1738
+ } else if (!format) {
1739
+ throw new Error("Format must be specified when no filename is passed");
1740
+ }
1741
+ switch (format) {
1742
+ case "json":
1743
+ content = JSON.stringify(object, null, 2);
1744
+ break;
1745
+ case "yaml":
1746
+ content = dump(object);
1747
+ break;
1748
+ default:
1749
+ throw new Error(`Unsupported format: ${format}`);
1750
+ }
1751
+ if (filename) {
1752
+ writeFileSync(filename, content, "utf8");
1753
+ } else {
1754
+ console.log(content);
1755
+ }
1756
+ }
1757
+ function readFileToObject(filename) {
1758
+ const file = readFileSync(filename, "utf8");
1759
+ return load(file, { filename, json: true });
1760
+ }
1761
+ async function* paginateAsync(fetchPage, options) {
1762
+ const perPage = options.pageSize || 100;
1763
+ let offset = 0;
1764
+ let pageData = [];
1765
+ do {
1766
+ pageData = await fetchPage(offset, perPage);
1767
+ for (const item of pageData) {
1768
+ yield item;
1769
+ }
1770
+ offset += perPage;
1771
+ } while (pageData.length === perPage);
1772
+ }
1773
+
1774
+ // src/sync/fileSyncEngineDataSource.ts
1775
+ async function createFileSyncEngineDataSource({
1776
+ directory,
1777
+ format = "yaml",
1778
+ selectIdentifier,
1779
+ selectDisplayName = selectIdentifier,
1780
+ selectFilename
1781
+ }) {
1782
+ const dirExists = existsSync(directory);
1783
+ if (!dirExists) {
1784
+ mkdirSync(directory, { recursive: true });
1785
+ }
1786
+ const rawFilenames = await readdir(directory, "utf-8");
1787
+ const filenames = new Set(
1788
+ rawFilenames.filter((filename) => {
1789
+ const ext = extname2(filename);
1790
+ return ext === `.json` || ext === `.yaml` || ext === `.yml`;
1791
+ })
1792
+ );
1793
+ const getFullFilename = (id) => join(directory, `${id}.${format}`);
1794
+ async function* getObjects() {
1795
+ for (const filename of filenames) {
1796
+ const fullFilename = join(directory, filename);
1797
+ try {
1798
+ const contents = await readFileToObject(fullFilename);
1799
+ const object = {
1800
+ id: selectIdentifier(contents),
1801
+ displayName: selectDisplayName(contents),
1802
+ providerId: fullFilename,
1803
+ object: contents
1804
+ };
1805
+ yield object;
1806
+ } catch (e) {
1807
+ console.error(import_chalk.default.red(`Failed to read ${fullFilename}, data is likely invalid.
1808
+ ${e == null ? void 0 : e.message}`));
1809
+ throw e;
1810
+ }
1811
+ }
1812
+ }
1813
+ return {
1814
+ objects: getObjects(),
1815
+ deleteObject: async (providerId) => {
1816
+ await unlink(providerId);
1817
+ },
1818
+ writeObject: async (object) => {
1819
+ if (selectFilename) {
1820
+ emitWithFormat(object.object, format, join(directory, `${selectFilename(object.object)}.${format}`));
1821
+ } else {
1822
+ emitWithFormat(object.object, format, getFullFilename(object.id));
1823
+ }
1824
+ }
1825
+ };
1826
+ }
1827
+
1828
+ // src/sync/package.ts
1829
+ import fs from "fs";
1830
+ function readUniformPackage(filename, assertExists) {
1831
+ if (!assertExists && !fs.existsSync(filename)) {
1832
+ return {};
1833
+ }
1834
+ const packageContents = readFileToObject(filename);
1835
+ if (typeof packageContents !== "object") {
1836
+ throw new Error(`Package ${filename} does not appear valid.`);
1837
+ }
1838
+ return packageContents;
1839
+ }
1840
+ function writeUniformPackage(filename, packageContents) {
1841
+ emitWithFormat(packageContents, void 0, filename);
1842
+ }
1843
+
1844
+ // src/sync/syncEngine.ts
1845
+ import { diffJson, diffLines } from "diff";
1846
+ import isEqualWith from "lodash.isequalwith";
1847
+ async function syncEngine({
1848
+ source,
1849
+ target,
1850
+ compareContents = (source2, target2) => {
1851
+ return isEqualWith(
1852
+ source2.object,
1853
+ target2.object,
1854
+ (_a, _b, key) => key === "created" || key === "modified" ? true : void 0
1855
+ );
1856
+ },
1857
+ mode,
1858
+ allowEmptySource = false,
1859
+ whatIf = false,
1860
+ log = () => {
1861
+ }
1862
+ }) {
1863
+ var _a, _b;
1864
+ const targetItems = /* @__PURE__ */ new Map();
1865
+ for await (const obj of target.objects) {
1866
+ targetItems.set(obj.id, obj);
1867
+ }
1868
+ const actions = [];
1869
+ let sourceHasItems = false;
1870
+ for await (const sourceObject of source.objects) {
1871
+ sourceHasItems = true;
1872
+ const id = sourceObject.id;
1873
+ const targetObject = targetItems.get(id);
1874
+ if (targetObject) {
1875
+ if (!compareContents(sourceObject, targetObject)) {
1876
+ if (mode === "createOrUpdate" || mode === "mirror") {
1877
+ const process2 = async (sourceObject2, targetObject2) => {
1878
+ var _a2;
1879
+ if (!whatIf) {
1880
+ try {
1881
+ await target.writeObject(sourceObject2, targetObject2);
1882
+ } catch (e) {
1883
+ throw new SyncEngineError(e, sourceObject2);
1884
+ }
1885
+ }
1886
+ log({
1887
+ action: "update",
1888
+ id,
1889
+ providerId: sourceObject2.providerId,
1890
+ displayName: (_a2 = sourceObject2.displayName) != null ? _a2 : sourceObject2.providerId,
1891
+ whatIf,
1892
+ diff: diffJson(targetObject2.object, sourceObject2.object)
1893
+ });
1894
+ };
1895
+ actions.push(process2(sourceObject, targetObject));
1896
+ }
1897
+ }
1898
+ targetItems.delete(id);
1899
+ } else {
1900
+ const process2 = async (sourceObject2, id2) => {
1901
+ var _a2;
1902
+ if (!whatIf) {
1903
+ try {
1904
+ await target.writeObject(sourceObject2);
1905
+ } catch (e) {
1906
+ throw new SyncEngineError(e, sourceObject2);
1907
+ }
1908
+ }
1909
+ log({
1910
+ action: "create",
1911
+ id: id2,
1912
+ providerId: id2,
1913
+ displayName: (_a2 = sourceObject2.displayName) != null ? _a2 : sourceObject2.providerId,
1914
+ whatIf,
1915
+ diff: diffLines("", JSON.stringify(sourceObject2.object, null, 2))
1916
+ });
1917
+ };
1918
+ actions.push(process2(sourceObject, id));
1919
+ }
1920
+ }
1921
+ await Promise.all(actions);
1922
+ if (mode === "mirror") {
1923
+ if (!sourceHasItems && !allowEmptySource) {
1924
+ throw new Error(
1925
+ "Source is empty and mode is mirror. This would cause deletion of everything in the target, and most likely indicates an error in source definition."
1926
+ );
1927
+ }
1928
+ const deletes = [];
1929
+ targetItems.forEach(async (object) => {
1930
+ const process2 = async (object2) => {
1931
+ var _a2;
1932
+ if (!whatIf) {
1933
+ try {
1934
+ await target.deleteObject(object2.providerId, object2);
1935
+ } catch (e) {
1936
+ throw new SyncEngineError(e, object2);
1937
+ }
1938
+ }
1939
+ log({
1940
+ action: "delete",
1941
+ id: object2.id,
1942
+ providerId: object2.providerId,
1943
+ displayName: (_a2 = object2.displayName) != null ? _a2 : object2.providerId,
1944
+ whatIf,
1945
+ diff: diffLines(JSON.stringify(object2.object, null, 2), "")
1946
+ });
1947
+ };
1948
+ deletes.push(process2(object));
1949
+ });
1950
+ await Promise.all(deletes);
1951
+ }
1952
+ await Promise.all([(_a = source.onSyncComplete) == null ? void 0 : _a.call(source, false), (_b = target.onSyncComplete) == null ? void 0 : _b.call(target, true)]);
1953
+ }
1954
+ var SyncEngineError = class extends Error {
1955
+ constructor(innerError, sourceObject) {
1956
+ var _a;
1957
+ super(
1958
+ `Error syncing ${(_a = sourceObject.displayName) != null ? _a : sourceObject.providerId} (${sourceObject.providerId})
1959
+ ${innerError}`
1960
+ );
1961
+ this.stack = void 0;
1962
+ Object.setPrototypeOf(this, SyncEngineError.prototype);
1963
+ }
1964
+ };
1965
+
1966
+ // src/sync/syncEngineConsoleLogger.ts
1967
+ var import_chalk2 = __toESM(require_source());
1968
+ function createSyncEngineConsoleLogger(options) {
1969
+ const { diffMode = "off", indent, prefix } = options != null ? options : {};
1970
+ return function syncEngineConsoleLogger({ action, displayName, whatIf, diff }) {
1971
+ let actionTag = "";
1972
+ switch (action) {
1973
+ case "create":
1974
+ actionTag = import_chalk2.default.green("[A]");
1975
+ break;
1976
+ case "update":
1977
+ actionTag = import_chalk2.default.white("[U]");
1978
+ break;
1979
+ case "delete":
1980
+ actionTag = import_chalk2.default.yellow("[D]");
1981
+ break;
1982
+ }
1983
+ let diffString = "";
1984
+ if (diffMode === "on" || diffMode === "update" && action === "update") {
1985
+ diffString = "\n" + diff.map((change) => {
1986
+ if (change.added) {
1987
+ return import_chalk2.default.green(change.value);
1988
+ }
1989
+ if (change.removed) {
1990
+ return import_chalk2.default.red(change.value);
1991
+ }
1992
+ return change.value;
1993
+ }).join("");
1994
+ }
1995
+ console.log(
1996
+ `${indent != null ? indent : ""}${whatIf ? import_chalk2.default.gray("[WHATIF]") : ""}${actionTag}${prefix != null ? prefix : ""} ${displayName}${diffString}`
1997
+ );
1998
+ };
1999
+ }
2000
+
1572
2001
  export {
1573
2002
  __require,
1574
2003
  __toESM,
1575
- require_source
2004
+ __privateGet,
2005
+ __privateAdd,
2006
+ __privateSet,
2007
+ __privateWrapper,
2008
+ createArraySyncEngineDataSource,
2009
+ require_source,
2010
+ withApiOptions,
2011
+ nodeFetchProxy,
2012
+ withProjectOptions,
2013
+ withFormatOptions,
2014
+ withDiffOptions,
2015
+ isPathAPackageFile,
2016
+ emitWithFormat,
2017
+ readFileToObject,
2018
+ paginateAsync,
2019
+ createFileSyncEngineDataSource,
2020
+ readUniformPackage,
2021
+ writeUniformPackage,
2022
+ syncEngine,
2023
+ SyncEngineError,
2024
+ createSyncEngineConsoleLogger
1576
2025
  };