@514labs/moose-lib 0.6.322-ci-1-gb296906d → 0.6.322-ci-9-g72529e37

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.
@@ -30,6 +30,59 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  mod
31
31
  ));
32
32
 
33
+ // src/compiler-config.ts
34
+ function getSourceDir() {
35
+ return process.env.MOOSE_SOURCE_DIR || "app";
36
+ }
37
+ function hasCompiledArtifacts(projectRoot = process.cwd()) {
38
+ const sourceDir = getSourceDir();
39
+ const compiledIndexPath = import_path.default.join(
40
+ projectRoot,
41
+ ".moose",
42
+ "compiled",
43
+ sourceDir,
44
+ "index.js"
45
+ );
46
+ return (0, import_fs.existsSync)(compiledIndexPath);
47
+ }
48
+ function shouldUseCompiled(projectRoot = process.cwd()) {
49
+ const envSaysCompiled = process.env.MOOSE_USE_COMPILED === "true";
50
+ if (!envSaysCompiled) {
51
+ return false;
52
+ }
53
+ const hasArtifacts = hasCompiledArtifacts(projectRoot);
54
+ if (!hasArtifacts) {
55
+ console.warn(
56
+ `[moose] MOOSE_USE_COMPILED=true but no compiled artifacts found at .moose/compiled/${getSourceDir()}/index.js. Falling back to ts-node.`
57
+ );
58
+ }
59
+ return hasArtifacts;
60
+ }
61
+ var import_fs, import_path, MOOSE_COMPILER_PLUGINS, COMMANDS_REQUIRING_PLUGINS;
62
+ var init_compiler_config = __esm({
63
+ "src/compiler-config.ts"() {
64
+ "use strict";
65
+ import_fs = require("fs");
66
+ import_path = __toESM(require("path"));
67
+ MOOSE_COMPILER_PLUGINS = [
68
+ {
69
+ transform: "./node_modules/@514labs/moose-lib/dist/compilerPlugin.js",
70
+ transformProgram: true
71
+ },
72
+ {
73
+ transform: "typia/lib/transform"
74
+ }
75
+ ];
76
+ COMMANDS_REQUIRING_PLUGINS = [
77
+ "consumption-apis",
78
+ "consumption-type-serializer",
79
+ "dmv2-serializer",
80
+ "streaming-functions",
81
+ "scripts"
82
+ ];
83
+ }
84
+ });
85
+
33
86
  // src/dmv2/utils/stackTrace.ts
34
87
  var init_stackTrace = __esm({
35
88
  "src/dmv2/utils/stackTrace.ts"() {
@@ -1221,11 +1274,15 @@ var init_runner = __esm({
1221
1274
  init_cluster_utils();
1222
1275
  init_sqlHelpers();
1223
1276
  init_internal();
1277
+ init_compiler_config();
1224
1278
  toClientConfig2 = (config) => ({
1225
1279
  ...config,
1226
1280
  useSSL: config.useSSL ? "true" : "false"
1227
1281
  });
1228
- createPath = (apisDir, path5) => `${apisDir}${path5}.ts`;
1282
+ createPath = (apisDir, path6, useCompiled2) => {
1283
+ const extension = useCompiled2 ? ".js" : ".ts";
1284
+ return `${apisDir}${path6}${extension}`;
1285
+ };
1229
1286
  httpLogger = (req, res, startMs) => {
1230
1287
  console.log(
1231
1288
  `${req.method} ${req.url} ${res.statusCode} ${Date.now() - startMs}ms`
@@ -1233,6 +1290,9 @@ var init_runner = __esm({
1233
1290
  };
1234
1291
  modulesCache = /* @__PURE__ */ new Map();
1235
1292
  apiHandler = async (publicKey, clickhouseClient, temporalClient, apisDir, enforceAuth, isDmv2, jwtConfig) => {
1293
+ const useCompiled2 = shouldUseCompiled();
1294
+ const sourceDir = getSourceDir();
1295
+ const actualApisDir = useCompiled2 ? `${process.cwd()}/.moose/compiled/${sourceDir}/apis/` : apisDir;
1236
1296
  const apis = isDmv2 ? await getApis2() : /* @__PURE__ */ new Map();
1237
1297
  return async (req, res) => {
1238
1298
  const start = Date.now();
@@ -1270,7 +1330,7 @@ var init_runner = __esm({
1270
1330
  httpLogger(req, res, start);
1271
1331
  return;
1272
1332
  }
1273
- const pathName = createPath(apisDir, fileName);
1333
+ const pathName = createPath(actualApisDir, fileName, useCompiled2);
1274
1334
  const paramsObject = Array.from(url.searchParams.entries()).reduce(
1275
1335
  (obj, [key, value]) => {
1276
1336
  const existingValue = obj[key];
@@ -1728,15 +1788,12 @@ var init_index = __esm({
1728
1788
  });
1729
1789
 
1730
1790
  // src/dmv2/internal.ts
1731
- function getSourceDir() {
1732
- return import_process.default.env.MOOSE_SOURCE_DIR || "app";
1733
- }
1734
1791
  function findSourceFiles(dir, extensions = [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts"]) {
1735
1792
  const files = [];
1736
1793
  try {
1737
1794
  const entries = fs2.readdirSync(dir, { withFileTypes: true });
1738
1795
  for (const entry of entries) {
1739
- const fullPath = path2.join(dir, entry.name);
1796
+ const fullPath = path3.join(dir, entry.name);
1740
1797
  if (entry.isDirectory()) {
1741
1798
  if (entry.name !== "node_modules" && !entry.name.startsWith(".")) {
1742
1799
  files.push(...findSourceFiles(fullPath, extensions));
@@ -1745,7 +1802,7 @@ function findSourceFiles(dir, extensions = [".ts", ".tsx", ".js", ".jsx", ".mts"
1745
1802
  if (entry.name.endsWith(".d.ts") || entry.name.endsWith(".d.mts") || entry.name.endsWith(".d.cts")) {
1746
1803
  continue;
1747
1804
  }
1748
- const ext = path2.extname(entry.name);
1805
+ const ext = path3.extname(entry.name);
1749
1806
  if (extensions.includes(ext)) {
1750
1807
  files.push(fullPath);
1751
1808
  }
@@ -1757,12 +1814,12 @@ function findSourceFiles(dir, extensions = [".ts", ".tsx", ".js", ".jsx", ".mts"
1757
1814
  return files;
1758
1815
  }
1759
1816
  function findUnloadedFiles() {
1760
- const appDir = path2.resolve(import_process.default.cwd(), getSourceDir());
1817
+ const appDir = path3.resolve(import_process.default.cwd(), getSourceDir());
1761
1818
  const allSourceFiles = findSourceFiles(appDir);
1762
1819
  const loadedFiles = new Set(
1763
- Object.keys(require.cache).filter((key) => key.startsWith(appDir)).map((key) => path2.resolve(key))
1820
+ Object.keys(require.cache).filter((key) => key.startsWith(appDir)).map((key) => path3.resolve(key))
1764
1821
  );
1765
- const unloadedFiles = allSourceFiles.map((file) => path2.resolve(file)).filter((file) => !loadedFiles.has(file)).map((file) => path2.relative(import_process.default.cwd(), file));
1822
+ const unloadedFiles = allSourceFiles.map((file) => path3.resolve(file)).filter((file) => !loadedFiles.has(file)).map((file) => path3.relative(import_process.default.cwd(), file));
1766
1823
  return unloadedFiles;
1767
1824
  }
1768
1825
  function isS3QueueConfig(config) {
@@ -2015,15 +2072,16 @@ function findTaskInTree(task, targetName) {
2015
2072
  }
2016
2073
  return void 0;
2017
2074
  }
2018
- var import_process, fs2, path2, moose_internal, defaultRetentionPeriod, toInfraMap, getMooseInternal, dumpMooseInternal, loadIndex, getStreamingFunctions, getApis2, getWorkflows2, getTaskForWorkflow, getWebApps2;
2075
+ var import_process, fs2, path3, moose_internal, defaultRetentionPeriod, toInfraMap, getMooseInternal, dumpMooseInternal, loadIndex, getStreamingFunctions, getApis2, getWorkflows2, getTaskForWorkflow, getWebApps2;
2019
2076
  var init_internal = __esm({
2020
2077
  "src/dmv2/internal.ts"() {
2021
2078
  "use strict";
2022
2079
  import_process = __toESM(require("process"));
2023
2080
  fs2 = __toESM(require("fs"));
2024
- path2 = __toESM(require("path"));
2081
+ path3 = __toESM(require("path"));
2025
2082
  init_index();
2026
2083
  init_commons();
2084
+ init_compiler_config();
2027
2085
  moose_internal = {
2028
2086
  tables: /* @__PURE__ */ new Map(),
2029
2087
  streams: /* @__PURE__ */ new Map(),
@@ -2308,6 +2366,7 @@ var init_internal = __esm({
2308
2366
  );
2309
2367
  };
2310
2368
  loadIndex = () => {
2369
+ const useCompiled2 = shouldUseCompiled();
2311
2370
  const registry = getMooseInternal();
2312
2371
  registry.tables.clear();
2313
2372
  registry.streams.clear();
@@ -2318,14 +2377,21 @@ var init_internal = __esm({
2318
2377
  registry.webApps.clear();
2319
2378
  registry.materializedViews.clear();
2320
2379
  registry.views.clear();
2321
- const appDir = `${import_process.default.cwd()}/${getSourceDir()}`;
2322
- Object.keys(require.cache).forEach((key) => {
2323
- if (key.startsWith(appDir)) {
2324
- delete require.cache[key];
2325
- }
2326
- });
2380
+ if (!useCompiled2) {
2381
+ const appDir = `${import_process.default.cwd()}/${getSourceDir()}`;
2382
+ Object.keys(require.cache).forEach((key) => {
2383
+ if (key.startsWith(appDir)) {
2384
+ delete require.cache[key];
2385
+ }
2386
+ });
2387
+ }
2327
2388
  try {
2328
- require(`${import_process.default.cwd()}/${getSourceDir()}/index.ts`);
2389
+ const sourceDir = getSourceDir();
2390
+ if (useCompiled2) {
2391
+ require(`${import_process.default.cwd()}/.moose/compiled/${sourceDir}/index.js`);
2392
+ } else {
2393
+ require(`${import_process.default.cwd()}/${sourceDir}/index.ts`);
2394
+ }
2329
2395
  } catch (error) {
2330
2396
  let hint;
2331
2397
  let includeDetails = true;
@@ -2433,6 +2499,7 @@ var init_internal = __esm({
2433
2499
 
2434
2500
  // src/moose-runner.ts
2435
2501
  var import_ts_node = require("ts-node");
2502
+ init_compiler_config();
2436
2503
  init_internal();
2437
2504
 
2438
2505
  // src/blocks/runner.ts
@@ -2440,6 +2507,7 @@ var import_fastq = __toESM(require("fastq"));
2440
2507
  init_commons();
2441
2508
  var import_node_fs = __toESM(require("fs"));
2442
2509
  var import_node_path2 = __toESM(require("path"));
2510
+ init_compiler_config();
2443
2511
  var walkDir = (dir, fileExtension, fileList) => {
2444
2512
  const files = import_node_fs.default.readdirSync(dir);
2445
2513
  files.forEach((file) => {
@@ -2511,7 +2579,11 @@ var asyncWorker = async (task) => {
2511
2579
  var runBlocks = async (config) => {
2512
2580
  const chClient = getClickhouseClient(toClientConfig3(config.clickhouseConfig));
2513
2581
  console.log(`Connected`);
2514
- const blocksFiles = walkDir(config.blocksDir, ".ts", []);
2582
+ const useCompiled2 = shouldUseCompiled();
2583
+ const sourceDir = getSourceDir();
2584
+ const blocksDir = useCompiled2 ? `${process.cwd()}/.moose/compiled/${sourceDir}/blocks/` : config.blocksDir;
2585
+ const fileExtension = useCompiled2 ? ".js" : ".ts";
2586
+ const blocksFiles = walkDir(blocksDir, fileExtension, []);
2515
2587
  const numOfBlockFiles = blocksFiles.length;
2516
2588
  console.log(`Found ${numOfBlockFiles} blocks files`);
2517
2589
  const queue = import_fastq.default.promise(asyncWorker, 1);
@@ -2522,10 +2594,10 @@ var runBlocks = async (config) => {
2522
2594
  }
2523
2595
  }
2524
2596
  });
2525
- for (const path5 of blocksFiles) {
2526
- console.log(`Adding to queue: ${path5}`);
2597
+ for (const path6 of blocksFiles) {
2598
+ console.log(`Adding to queue: ${path6}`);
2527
2599
  try {
2528
- const blocks = require(path5).default;
2600
+ const blocks = require(path6).default;
2529
2601
  queue.push({
2530
2602
  chClient,
2531
2603
  blocks,
@@ -2534,7 +2606,7 @@ var runBlocks = async (config) => {
2534
2606
  } catch (err) {
2535
2607
  cliLog({
2536
2608
  action: "Blocks",
2537
- message: `Failed to import blocks from ${path5}: ${err}`,
2609
+ message: `Failed to import blocks from ${path6}: ${err}`,
2538
2610
  message_type: "Error"
2539
2611
  });
2540
2612
  }
@@ -2832,7 +2904,8 @@ var sendMessageMetrics = (logger2, metrics) => {
2832
2904
  function loadStreamingFunction(functionFilePath) {
2833
2905
  let streamingFunctionImport;
2834
2906
  try {
2835
- streamingFunctionImport = require(functionFilePath.substring(0, functionFilePath.length - 3));
2907
+ const pathWithoutExt = functionFilePath.replace(/\.(ts|js)$/, "");
2908
+ streamingFunctionImport = require(pathWithoutExt);
2836
2909
  } catch (e) {
2837
2910
  cliLog({ action: "Function", message: `${e}`, message_type: "Error" });
2838
2911
  throw e;
@@ -3104,18 +3177,32 @@ var runStreamingFunctions = async (args) => {
3104
3177
  };
3105
3178
 
3106
3179
  // src/moduleExportSerializer.ts
3180
+ init_compiler_config();
3107
3181
  async function runExportSerializer(targetModel) {
3108
- const exports_list = require(targetModel);
3182
+ const useCompiled2 = shouldUseCompiled();
3183
+ const sourceDir = getSourceDir();
3184
+ let modulePath = targetModel;
3185
+ if (useCompiled2) {
3186
+ if (modulePath.includes(sourceDir)) {
3187
+ modulePath = modulePath.replace(
3188
+ new RegExp(`/${sourceDir}/`),
3189
+ `/.moose/compiled/${sourceDir}/`
3190
+ );
3191
+ }
3192
+ modulePath = modulePath.replace(/\.ts$/, ".js");
3193
+ }
3194
+ const exports_list = require(modulePath);
3109
3195
  console.log(JSON.stringify(exports_list));
3110
3196
  }
3111
3197
 
3112
3198
  // src/consumption-apis/exportTypeSerializer.ts
3113
3199
  var import_process2 = __toESM(require("process"));
3114
- function getSourceDir2() {
3115
- return import_process2.default.env.MOOSE_SOURCE_DIR || "app";
3116
- }
3200
+ init_compiler_config();
3117
3201
  async function runApiTypeSerializer(targetModel) {
3118
- const func = require(`${import_process2.default.cwd()}/${getSourceDir2()}/apis/${targetModel}.ts`).default;
3202
+ const sourceDir = getSourceDir();
3203
+ const useCompiled2 = shouldUseCompiled();
3204
+ const apiPath = useCompiled2 ? `${import_process2.default.cwd()}/.moose/compiled/${sourceDir}/apis/${targetModel}.js` : `${import_process2.default.cwd()}/${sourceDir}/apis/${targetModel}.ts`;
3205
+ const func = require(apiPath).default;
3119
3206
  const inputSchema = func["moose_input_schema"] || null;
3120
3207
  const outputSchema = func["moose_output_schema"] || null;
3121
3208
  console.log(
@@ -3128,7 +3215,7 @@ async function runApiTypeSerializer(targetModel) {
3128
3215
 
3129
3216
  // src/scripts/runner.ts
3130
3217
  var import_worker2 = require("@temporalio/worker");
3131
- var path4 = __toESM(require("path"));
3218
+ var path5 = __toESM(require("path"));
3132
3219
  var fs4 = __toESM(require("fs"));
3133
3220
  init_internal();
3134
3221
 
@@ -3421,7 +3508,7 @@ async function registerWorkflows(logger2, config) {
3421
3508
  }
3422
3509
  };
3423
3510
  const workflowBundle = await (0, import_worker2.bundleWorkflowCode)({
3424
- workflowsPath: path4.resolve(__dirname, "scripts/workflow.js"),
3511
+ workflowsPath: path5.resolve(__dirname, "scripts/workflow.js"),
3425
3512
  logger: silentLogger
3426
3513
  });
3427
3514
  const worker = await import_worker2.Worker.create({
@@ -3502,31 +3589,27 @@ async function runScripts(config) {
3502
3589
  // src/moose-runner.ts
3503
3590
  var import_process3 = __toESM(require("process"));
3504
3591
  var import_commander = require("commander");
3505
- if (import_process3.default.argv[2] == "consumption-apis" || import_process3.default.argv[2] == "consumption-type-serializer" || import_process3.default.argv[2] == "dmv2-serializer" || // Streaming functions for dmv2 need to load moose internals
3506
- import_process3.default.argv[2] == "streaming-functions" || import_process3.default.argv[2] == "scripts") {
3507
- (0, import_ts_node.register)({
3508
- require: ["tsconfig-paths/register"],
3509
- esm: true,
3510
- experimentalTsImportSpecifiers: true,
3511
- compiler: "ts-patch/compiler",
3512
- compilerOptions: {
3513
- plugins: [
3514
- {
3515
- transform: `./node_modules/@514labs/moose-lib/dist/compilerPlugin.js`,
3516
- transformProgram: true
3517
- },
3518
- {
3519
- transform: "typia/lib/transform"
3520
- }
3521
- ],
3522
- experimentalDecorators: true
3523
- }
3524
- });
3525
- } else {
3526
- (0, import_ts_node.register)({
3527
- esm: true,
3528
- experimentalTsImportSpecifiers: true
3529
- });
3592
+ var useCompiled = shouldUseCompiled();
3593
+ if (!useCompiled) {
3594
+ const command = import_process3.default.argv[2];
3595
+ const needsPlugins = COMMANDS_REQUIRING_PLUGINS.includes(command);
3596
+ if (needsPlugins) {
3597
+ (0, import_ts_node.register)({
3598
+ require: ["tsconfig-paths/register"],
3599
+ esm: true,
3600
+ experimentalTsImportSpecifiers: true,
3601
+ compiler: "ts-patch/compiler",
3602
+ compilerOptions: {
3603
+ plugins: [...MOOSE_COMPILER_PLUGINS],
3604
+ experimentalDecorators: true
3605
+ }
3606
+ });
3607
+ } else {
3608
+ (0, import_ts_node.register)({
3609
+ esm: true,
3610
+ experimentalTsImportSpecifiers: true
3611
+ });
3612
+ }
3530
3613
  }
3531
3614
  var program = new import_commander.Command();
3532
3615
  program.name("moose-runner").description("Moose runner for various operations").version("1.0.0");