@514labs/moose-lib 0.6.267-ci-5-gfe9b0c33 → 0.6.268

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.
@@ -962,15 +962,8 @@ var runApis = async (config) => {
962
962
  const apisCluster = new Cluster({
963
963
  maxWorkerCount: (config.workerCount ?? 0) > 0 ? config.workerCount : void 0,
964
964
  workerStart: async () => {
965
- const workerInfo = `[Worker ${process.pid}]`;
966
- const startTime = Date.now();
967
- console.log(`${workerInfo} workerStart: beginning initialization`);
968
965
  let temporalClient;
969
966
  if (config.temporalConfig) {
970
- const temporalStart = Date.now();
971
- console.log(
972
- `${workerInfo} workerStart: initializing Temporal client...`
973
- );
974
967
  temporalClient = await getTemporalClient(
975
968
  config.temporalConfig.url,
976
969
  config.temporalConfig.namespace,
@@ -978,51 +971,29 @@ var runApis = async (config) => {
978
971
  config.temporalConfig.clientKey,
979
972
  config.temporalConfig.apiKey
980
973
  );
981
- console.log(
982
- `${workerInfo} workerStart: Temporal client initialized in ${Date.now() - temporalStart}ms`
983
- );
984
974
  }
985
- const clickhouseStart = Date.now();
986
- console.log(
987
- `${workerInfo} workerStart: initializing ClickHouse client...`
988
- );
989
975
  const clickhouseClient = getClickhouseClient(
990
976
  toClientConfig(config.clickhouseConfig)
991
977
  );
992
- console.log(
993
- `${workerInfo} workerStart: ClickHouse client initialized in ${Date.now() - clickhouseStart}ms`
994
- );
995
978
  let publicKey;
996
979
  if (config.jwtConfig?.secret) {
997
- const jwtStart = Date.now();
998
- console.log(`${workerInfo} workerStart: importing JWT public key...`);
980
+ console.log("Importing JWT public key...");
999
981
  publicKey = await jose.importSPKI(config.jwtConfig.secret, "RS256");
1000
- console.log(
1001
- `${workerInfo} workerStart: JWT key imported in ${Date.now() - jwtStart}ms`
1002
- );
1003
982
  }
1004
- const routerStart = Date.now();
1005
- console.log(`${workerInfo} workerStart: creating main router...`);
1006
- const router = await createMainRouter(
1007
- publicKey,
1008
- clickhouseClient,
1009
- temporalClient,
1010
- config.apisDir,
1011
- config.enforceAuth,
1012
- config.isDmv2,
1013
- config.jwtConfig
1014
- );
1015
- console.log(
1016
- `${workerInfo} workerStart: main router created in ${Date.now() - routerStart}ms`
983
+ const server = http2.createServer(
984
+ await createMainRouter(
985
+ publicKey,
986
+ clickhouseClient,
987
+ temporalClient,
988
+ config.apisDir,
989
+ config.enforceAuth,
990
+ config.isDmv2,
991
+ config.jwtConfig
992
+ )
1017
993
  );
1018
- const serverStart = Date.now();
1019
- console.log(`${workerInfo} workerStart: creating HTTP server...`);
1020
- const server = http2.createServer(router);
1021
994
  const port = config.proxyPort !== void 0 ? config.proxyPort : 4001;
1022
995
  server.listen(port, "localhost", () => {
1023
- console.log(
1024
- `${workerInfo} Server running on port ${port} (total startup: ${Date.now() - startTime}ms)`
1025
- );
996
+ console.log(`Server running on port ${port}`);
1026
997
  });
1027
998
  return server;
1028
999
  },
@@ -1643,106 +1614,43 @@ if (getMooseInternal() === void 0) {
1643
1614
  globalThis.moose_internal = moose_internal;
1644
1615
  }
1645
1616
  var dumpMooseInternal = async () => {
1646
- await loadIndex();
1617
+ loadIndex();
1647
1618
  console.log(
1648
1619
  "___MOOSE_STUFF___start",
1649
1620
  JSON.stringify(toInfraMap(getMooseInternal())),
1650
1621
  "end___MOOSE_STUFF___"
1651
1622
  );
1652
1623
  };
1653
- var indexLoadState = "unloaded";
1654
- var indexLoadPromise = null;
1655
- var loadIndex = async () => {
1656
- const workerInfo = `[Worker ${process2.pid}]`;
1657
- if (indexLoadState === "loaded") {
1658
- console.log(
1659
- `${workerInfo} loadIndex: already loaded, returning immediately`
1660
- );
1661
- return;
1662
- }
1663
- if (indexLoadState === "loading" && indexLoadPromise) {
1664
- console.log(
1665
- `${workerInfo} loadIndex: already loading, waiting for completion`
1666
- );
1667
- return indexLoadPromise;
1668
- }
1669
- console.log(`${workerInfo} loadIndex: starting load process`);
1670
- const startTime = Date.now();
1671
- const delay = Math.random() * 500;
1672
- console.log(
1673
- `${workerInfo} loadIndex: waiting ${delay.toFixed(0)}ms to stagger load`
1674
- );
1675
- await new Promise((resolve2) => setTimeout(resolve2, delay));
1676
- if (indexLoadState === "loading" && indexLoadPromise) {
1677
- console.log(
1678
- `${workerInfo} loadIndex: another worker started loading during delay, waiting`
1679
- );
1680
- return indexLoadPromise;
1681
- }
1682
- if (indexLoadState === "loaded") {
1683
- console.log(
1684
- `${workerInfo} loadIndex: loaded by another worker during delay`
1685
- );
1686
- return;
1687
- }
1688
- indexLoadState = "loading";
1689
- indexLoadPromise = (async () => {
1690
- try {
1691
- console.log(`${workerInfo} loadIndex: clearing registry...`);
1692
- const clearStart = Date.now();
1693
- const registry = getMooseInternal();
1694
- registry.tables.clear();
1695
- registry.streams.clear();
1696
- registry.ingestApis.clear();
1697
- registry.apis.clear();
1698
- registry.sqlResources.clear();
1699
- registry.workflows.clear();
1700
- registry.webApps.clear();
1701
- console.log(
1702
- `${workerInfo} loadIndex: registry cleared in ${Date.now() - clearStart}ms`
1703
- );
1704
- console.log(`${workerInfo} loadIndex: clearing require cache...`);
1705
- const cacheStart = Date.now();
1706
- const appDir = `${process2.cwd()}/${getSourceDir()}`;
1707
- Object.keys(__require.cache).forEach((key) => {
1708
- if (key.startsWith(appDir)) {
1709
- delete __require.cache[key];
1710
- }
1711
- });
1712
- console.log(
1713
- `${workerInfo} loadIndex: require cache cleared in ${Date.now() - cacheStart}ms`
1714
- );
1715
- console.log(`${workerInfo} loadIndex: requiring index.ts...`);
1716
- const requireStart = Date.now();
1717
- __require(`${process2.cwd()}/${getSourceDir()}/index.ts`);
1718
- console.log(
1719
- `${workerInfo} loadIndex: require completed in ${Date.now() - requireStart}ms`
1720
- );
1721
- indexLoadState = "loaded";
1722
- console.log(
1723
- `${workerInfo} loadIndex: total load time ${Date.now() - startTime}ms`
1724
- );
1725
- } catch (error) {
1726
- console.error(
1727
- `${workerInfo} loadIndex: FAILED after ${Date.now() - startTime}ms`,
1728
- error
1729
- );
1730
- indexLoadState = "unloaded";
1731
- indexLoadPromise = null;
1732
- let hint;
1733
- const details = error instanceof Error ? error.message : String(error);
1734
- if (details.includes("ERR_REQUIRE_ESM") || details.includes("ES Module")) {
1735
- hint = "The file or its dependencies are ESM-only. Switch to packages that dual-support CJS & ESM, or upgrade to Node 22.12+. If you must use Node 20, you may try Node 20.19\n\n";
1736
- }
1737
- const errorMsg = `${hint ?? ""}${details}`;
1738
- const cause = error instanceof Error ? error : void 0;
1739
- throw new Error(errorMsg, { cause });
1624
+ var loadIndex = () => {
1625
+ const registry = getMooseInternal();
1626
+ registry.tables.clear();
1627
+ registry.streams.clear();
1628
+ registry.ingestApis.clear();
1629
+ registry.apis.clear();
1630
+ registry.sqlResources.clear();
1631
+ registry.workflows.clear();
1632
+ registry.webApps.clear();
1633
+ const appDir = `${process2.cwd()}/${getSourceDir()}`;
1634
+ Object.keys(__require.cache).forEach((key) => {
1635
+ if (key.startsWith(appDir)) {
1636
+ delete __require.cache[key];
1740
1637
  }
1741
- })();
1742
- return indexLoadPromise;
1638
+ });
1639
+ try {
1640
+ __require(`${process2.cwd()}/${getSourceDir()}/index.ts`);
1641
+ } catch (error) {
1642
+ let hint;
1643
+ const details = error instanceof Error ? error.message : String(error);
1644
+ if (details.includes("ERR_REQUIRE_ESM") || details.includes("ES Module")) {
1645
+ hint = "The file or its dependencies are ESM-only. Switch to packages that dual-support CJS & ESM, or upgrade to Node 22.12+. If you must use Node 20, you may try Node 20.19\n\n";
1646
+ }
1647
+ const errorMsg = `${hint ?? ""}${details}`;
1648
+ const cause = error instanceof Error ? error : void 0;
1649
+ throw new Error(errorMsg, { cause });
1650
+ }
1743
1651
  };
1744
1652
  var getStreamingFunctions = async () => {
1745
- await loadIndex();
1653
+ loadIndex();
1746
1654
  const registry = getMooseInternal();
1747
1655
  const transformFunctions = /* @__PURE__ */ new Map();
1748
1656
  registry.streams.forEach((stream) => {
@@ -1769,7 +1677,7 @@ var getStreamingFunctions = async () => {
1769
1677
  return transformFunctions;
1770
1678
  };
1771
1679
  var getApis2 = async () => {
1772
- await loadIndex();
1680
+ loadIndex();
1773
1681
  const apiFunctions = /* @__PURE__ */ new Map();
1774
1682
  const registry = getMooseInternal();
1775
1683
  const versionCountByName = /* @__PURE__ */ new Map();
@@ -1801,7 +1709,7 @@ var getApis2 = async () => {
1801
1709
  return apiFunctions;
1802
1710
  };
1803
1711
  var getWorkflows2 = async () => {
1804
- await loadIndex();
1712
+ loadIndex();
1805
1713
  const registry = getMooseInternal();
1806
1714
  return registry.workflows;
1807
1715
  };
@@ -1835,7 +1743,7 @@ var getTaskForWorkflow = async (workflowName, taskName) => {
1835
1743
  return task;
1836
1744
  };
1837
1745
  var getWebApps2 = async () => {
1838
- await loadIndex();
1746
+ loadIndex();
1839
1747
  return getMooseInternal().webApps;
1840
1748
  };
1841
1749