@514labs/moose-lib 0.6.267-ci-2-g72faeb73 → 0.6.267-ci-2-g580f80e4

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.
@@ -489,7 +489,6 @@ async function getTemporalClient(temporalUrl, namespace, clientCert, clientKey,
489
489
  // src/consumption-apis/runner.ts
490
490
  init_commons();
491
491
  import http2 from "http";
492
- import cluster2 from "cluster";
493
492
  import * as jose from "jose";
494
493
 
495
494
  // src/cluster-utils.ts
@@ -710,13 +709,7 @@ var httpLogger = (req, res, startMs) => {
710
709
  };
711
710
  var modulesCache = /* @__PURE__ */ new Map();
712
711
  var apiHandler = async (publicKey, clickhouseClient, temporalClient, apisDir, enforceAuth, isDmv2, jwtConfig) => {
713
- console.log(
714
- `[DEBUG] Worker ${cluster2.worker?.id} apiHandler: about to call getApis (isDmv2=${isDmv2})`
715
- );
716
712
  const apis = isDmv2 ? await getApis2() : /* @__PURE__ */ new Map();
717
- console.log(
718
- `[DEBUG] Worker ${cluster2.worker?.id} apiHandler: getApis completed, returning handler`
719
- );
720
713
  return async (req, res) => {
721
714
  const start = Date.now();
722
715
  try {
@@ -861,9 +854,6 @@ var apiHandler = async (publicKey, clickhouseClient, temporalClient, apisDir, en
861
854
  };
862
855
  };
863
856
  var createMainRouter = async (publicKey, clickhouseClient, temporalClient, apisDir, enforceAuth, isDmv2, jwtConfig) => {
864
- console.log(
865
- `[DEBUG] Worker ${cluster2.worker?.id} createMainRouter: about to call apiHandler`
866
- );
867
857
  const apiRequestHandler = await apiHandler(
868
858
  publicKey,
869
859
  clickhouseClient,
@@ -873,16 +863,7 @@ var createMainRouter = async (publicKey, clickhouseClient, temporalClient, apisD
873
863
  isDmv2,
874
864
  jwtConfig
875
865
  );
876
- console.log(
877
- `[DEBUG] Worker ${cluster2.worker?.id} createMainRouter: apiHandler completed`
878
- );
879
- console.log(
880
- `[DEBUG] Worker ${cluster2.worker?.id} createMainRouter: about to call getWebApps (isDmv2=${isDmv2})`
881
- );
882
866
  const webApps = isDmv2 ? await getWebApps2() : /* @__PURE__ */ new Map();
883
- console.log(
884
- `[DEBUG] Worker ${cluster2.worker?.id} createMainRouter: getWebApps completed, returning router`
885
- );
886
867
  const sortedWebApps = Array.from(webApps.values()).sort((a, b) => {
887
868
  const pathA = a.config.mountPath || "/";
888
869
  const pathB = b.config.mountPath || "/";
@@ -999,10 +980,6 @@ var runApis = async (config) => {
999
980
  console.log("Importing JWT public key...");
1000
981
  publicKey = await jose.importSPKI(config.jwtConfig.secret, "RS256");
1001
982
  }
1002
- const port = config.proxyPort !== void 0 ? config.proxyPort : 4001;
1003
- console.log(
1004
- `[DEBUG] Worker ${cluster2.worker?.id} about to create server on port ${port}`
1005
- );
1006
983
  const server = http2.createServer(
1007
984
  await createMainRouter(
1008
985
  publicKey,
@@ -1014,39 +991,11 @@ var runApis = async (config) => {
1014
991
  config.jwtConfig
1015
992
  )
1016
993
  );
1017
- console.log(
1018
- `[DEBUG] Worker ${cluster2.worker?.id} server created, about to listen on port ${port}`
1019
- );
1020
- return new Promise((resolve2, reject) => {
1021
- server.on("error", (err) => {
1022
- console.error(
1023
- `[ERROR] Worker ${cluster2.worker?.id} server error on port ${port}:`,
1024
- err
1025
- );
1026
- if (err.code === "EADDRINUSE") {
1027
- console.error(`[ERROR] Port ${port} is already in use`);
1028
- }
1029
- reject(err);
1030
- });
1031
- server.listen(port, "localhost", () => {
1032
- console.log(
1033
- `[SUCCESS] Worker ${cluster2.worker?.id} server running on port ${port}`
1034
- );
1035
- resolve2(server);
1036
- });
1037
- const timeout = setTimeout(() => {
1038
- console.error(
1039
- `[ERROR] Worker ${cluster2.worker?.id} listen timeout after 10s on port ${port}`
1040
- );
1041
- reject(new Error(`Listen timeout on port ${port}`));
1042
- }, 1e4);
1043
- server.once("listening", () => {
1044
- clearTimeout(timeout);
1045
- console.log(
1046
- `[DEBUG] Worker ${cluster2.worker?.id} 'listening' event fired for port ${port}`
1047
- );
1048
- });
994
+ const port = config.proxyPort !== void 0 ? config.proxyPort : 4001;
995
+ server.listen(port, "localhost", () => {
996
+ console.log(`Server running on port ${port}`);
1049
997
  });
998
+ return server;
1050
999
  },
1051
1000
  workerStop: async (server) => {
1052
1001
  return new Promise((resolve2) => {
@@ -1665,43 +1614,58 @@ if (getMooseInternal() === void 0) {
1665
1614
  globalThis.moose_internal = moose_internal;
1666
1615
  }
1667
1616
  var dumpMooseInternal = async () => {
1668
- loadIndex();
1617
+ await loadIndex();
1669
1618
  console.log(
1670
1619
  "___MOOSE_STUFF___start",
1671
1620
  JSON.stringify(toInfraMap(getMooseInternal())),
1672
1621
  "end___MOOSE_STUFF___"
1673
1622
  );
1674
1623
  };
1675
- var loadIndex = () => {
1676
- const registry = getMooseInternal();
1677
- registry.tables.clear();
1678
- registry.streams.clear();
1679
- registry.ingestApis.clear();
1680
- registry.apis.clear();
1681
- registry.sqlResources.clear();
1682
- registry.workflows.clear();
1683
- registry.webApps.clear();
1684
- const appDir = `${process2.cwd()}/${getSourceDir()}`;
1685
- Object.keys(__require.cache).forEach((key) => {
1686
- if (key.startsWith(appDir)) {
1687
- delete __require.cache[key];
1688
- }
1689
- });
1690
- try {
1691
- __require(`${process2.cwd()}/${getSourceDir()}/index.ts`);
1692
- } catch (error) {
1693
- let hint;
1694
- const details = error instanceof Error ? error.message : String(error);
1695
- if (details.includes("ERR_REQUIRE_ESM") || details.includes("ES Module")) {
1696
- 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";
1697
- }
1698
- const errorMsg = `${hint ?? ""}${details}`;
1699
- const cause = error instanceof Error ? error : void 0;
1700
- throw new Error(errorMsg, { cause });
1624
+ var indexLoadState = "unloaded";
1625
+ var indexLoadPromise = null;
1626
+ var loadIndex = async () => {
1627
+ if (indexLoadState === "loaded") {
1628
+ return;
1701
1629
  }
1630
+ if (indexLoadState === "loading" && indexLoadPromise) {
1631
+ return indexLoadPromise;
1632
+ }
1633
+ indexLoadState = "loading";
1634
+ indexLoadPromise = (async () => {
1635
+ try {
1636
+ const registry = getMooseInternal();
1637
+ registry.tables.clear();
1638
+ registry.streams.clear();
1639
+ registry.ingestApis.clear();
1640
+ registry.apis.clear();
1641
+ registry.sqlResources.clear();
1642
+ registry.workflows.clear();
1643
+ registry.webApps.clear();
1644
+ const appDir = `${process2.cwd()}/${getSourceDir()}`;
1645
+ Object.keys(__require.cache).forEach((key) => {
1646
+ if (key.startsWith(appDir)) {
1647
+ delete __require.cache[key];
1648
+ }
1649
+ });
1650
+ __require(`${process2.cwd()}/${getSourceDir()}/index.ts`);
1651
+ indexLoadState = "loaded";
1652
+ } catch (error) {
1653
+ indexLoadState = "unloaded";
1654
+ indexLoadPromise = null;
1655
+ let hint;
1656
+ const details = error instanceof Error ? error.message : String(error);
1657
+ if (details.includes("ERR_REQUIRE_ESM") || details.includes("ES Module")) {
1658
+ 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";
1659
+ }
1660
+ const errorMsg = `${hint ?? ""}${details}`;
1661
+ const cause = error instanceof Error ? error : void 0;
1662
+ throw new Error(errorMsg, { cause });
1663
+ }
1664
+ })();
1665
+ return indexLoadPromise;
1702
1666
  };
1703
1667
  var getStreamingFunctions = async () => {
1704
- loadIndex();
1668
+ await loadIndex();
1705
1669
  const registry = getMooseInternal();
1706
1670
  const transformFunctions = /* @__PURE__ */ new Map();
1707
1671
  registry.streams.forEach((stream) => {
@@ -1728,7 +1692,7 @@ var getStreamingFunctions = async () => {
1728
1692
  return transformFunctions;
1729
1693
  };
1730
1694
  var getApis2 = async () => {
1731
- loadIndex();
1695
+ await loadIndex();
1732
1696
  const apiFunctions = /* @__PURE__ */ new Map();
1733
1697
  const registry = getMooseInternal();
1734
1698
  const versionCountByName = /* @__PURE__ */ new Map();
@@ -1760,7 +1724,7 @@ var getApis2 = async () => {
1760
1724
  return apiFunctions;
1761
1725
  };
1762
1726
  var getWorkflows2 = async () => {
1763
- loadIndex();
1727
+ await loadIndex();
1764
1728
  const registry = getMooseInternal();
1765
1729
  return registry.workflows;
1766
1730
  };
@@ -1794,7 +1758,7 @@ var getTaskForWorkflow = async (workflowName, taskName) => {
1794
1758
  return task;
1795
1759
  };
1796
1760
  var getWebApps2 = async () => {
1797
- loadIndex();
1761
+ await loadIndex();
1798
1762
  return getMooseInternal().webApps;
1799
1763
  };
1800
1764
 
@@ -2361,7 +2325,7 @@ var runStreamingFunctions = async (args) => {
2361
2325
  validateTopicConfig(args.targetTopic);
2362
2326
  }
2363
2327
  const streamingFuncId = `flow-${args.sourceTopic.name}-${args.targetTopic?.name || ""}`;
2364
- const cluster3 = new Cluster({
2328
+ const cluster2 = new Cluster({
2365
2329
  maxCpuUsageRatio: 0.5,
2366
2330
  maxWorkerCount: args.maxSubscriberCount,
2367
2331
  workerStart: async (worker, parallelism) => {
@@ -2444,7 +2408,7 @@ var runStreamingFunctions = async (args) => {
2444
2408
  logger2.log("Graceful shutdown completed");
2445
2409
  }
2446
2410
  });
2447
- cluster3.start();
2411
+ cluster2.start();
2448
2412
  };
2449
2413
 
2450
2414
  // src/moduleExportSerializer.ts