@514labs/moose-lib 0.6.322-ci-9-g72529e37 → 0.6.322-ci-14-ga8e5dacb

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.
@@ -15,59 +15,6 @@ var __export = (target, all) => {
15
15
  __defProp(target, name, { get: all[name], enumerable: true });
16
16
  };
17
17
 
18
- // src/compiler-config.ts
19
- import { existsSync } from "fs";
20
- import path from "path";
21
- function getSourceDir() {
22
- return process.env.MOOSE_SOURCE_DIR || "app";
23
- }
24
- function hasCompiledArtifacts(projectRoot = process.cwd()) {
25
- const sourceDir = getSourceDir();
26
- const compiledIndexPath = path.join(
27
- projectRoot,
28
- ".moose",
29
- "compiled",
30
- sourceDir,
31
- "index.js"
32
- );
33
- return existsSync(compiledIndexPath);
34
- }
35
- function shouldUseCompiled(projectRoot = process.cwd()) {
36
- const envSaysCompiled = process.env.MOOSE_USE_COMPILED === "true";
37
- if (!envSaysCompiled) {
38
- return false;
39
- }
40
- const hasArtifacts = hasCompiledArtifacts(projectRoot);
41
- if (!hasArtifacts) {
42
- console.warn(
43
- `[moose] MOOSE_USE_COMPILED=true but no compiled artifacts found at .moose/compiled/${getSourceDir()}/index.js. Falling back to ts-node.`
44
- );
45
- }
46
- return hasArtifacts;
47
- }
48
- var MOOSE_COMPILER_PLUGINS, COMMANDS_REQUIRING_PLUGINS;
49
- var init_compiler_config = __esm({
50
- "src/compiler-config.ts"() {
51
- "use strict";
52
- MOOSE_COMPILER_PLUGINS = [
53
- {
54
- transform: "./node_modules/@514labs/moose-lib/dist/compilerPlugin.js",
55
- transformProgram: true
56
- },
57
- {
58
- transform: "typia/lib/transform"
59
- }
60
- ];
61
- COMMANDS_REQUIRING_PLUGINS = [
62
- "consumption-apis",
63
- "consumption-type-serializer",
64
- "dmv2-serializer",
65
- "streaming-functions",
66
- "scripts"
67
- ];
68
- }
69
- });
70
-
71
18
  // src/dmv2/utils/stackTrace.ts
72
19
  var init_stackTrace = __esm({
73
20
  "src/dmv2/utils/stackTrace.ts"() {
@@ -973,17 +920,17 @@ var init_cluster_utils = __esm({
973
920
  });
974
921
 
975
922
  // src/config/configFile.ts
976
- import path2 from "path";
923
+ import path from "path";
977
924
  import * as toml from "toml";
978
925
  async function findConfigFile(startDir = process.cwd()) {
979
926
  const fs5 = await import("fs");
980
- let currentDir = path2.resolve(startDir);
927
+ let currentDir = path.resolve(startDir);
981
928
  while (true) {
982
- const configPath = path2.join(currentDir, "moose.config.toml");
929
+ const configPath = path.join(currentDir, "moose.config.toml");
983
930
  if (fs5.existsSync(configPath)) {
984
931
  return configPath;
985
932
  }
986
- const parentDir = path2.dirname(currentDir);
933
+ const parentDir = path.dirname(currentDir);
987
934
  if (parentDir === currentDir) {
988
935
  break;
989
936
  }
@@ -1260,15 +1207,11 @@ var init_runner = __esm({
1260
1207
  init_cluster_utils();
1261
1208
  init_sqlHelpers();
1262
1209
  init_internal();
1263
- init_compiler_config();
1264
1210
  toClientConfig2 = (config) => ({
1265
1211
  ...config,
1266
1212
  useSSL: config.useSSL ? "true" : "false"
1267
1213
  });
1268
- createPath = (apisDir, path6, useCompiled2) => {
1269
- const extension = useCompiled2 ? ".js" : ".ts";
1270
- return `${apisDir}${path6}${extension}`;
1271
- };
1214
+ createPath = (apisDir, path5) => `${apisDir}${path5}.ts`;
1272
1215
  httpLogger = (req, res, startMs) => {
1273
1216
  console.log(
1274
1217
  `${req.method} ${req.url} ${res.statusCode} ${Date.now() - startMs}ms`
@@ -1276,9 +1219,6 @@ var init_runner = __esm({
1276
1219
  };
1277
1220
  modulesCache = /* @__PURE__ */ new Map();
1278
1221
  apiHandler = async (publicKey, clickhouseClient, temporalClient, apisDir, enforceAuth, isDmv2, jwtConfig) => {
1279
- const useCompiled2 = shouldUseCompiled();
1280
- const sourceDir = getSourceDir();
1281
- const actualApisDir = useCompiled2 ? `${process.cwd()}/.moose/compiled/${sourceDir}/apis/` : apisDir;
1282
1222
  const apis = isDmv2 ? await getApis2() : /* @__PURE__ */ new Map();
1283
1223
  return async (req, res) => {
1284
1224
  const start = Date.now();
@@ -1316,7 +1256,7 @@ var init_runner = __esm({
1316
1256
  httpLogger(req, res, start);
1317
1257
  return;
1318
1258
  }
1319
- const pathName = createPath(actualApisDir, fileName, useCompiled2);
1259
+ const pathName = createPath(apisDir, fileName);
1320
1260
  const paramsObject = Array.from(url.searchParams.entries()).reduce(
1321
1261
  (obj, [key, value]) => {
1322
1262
  const existingValue = obj[key];
@@ -1775,13 +1715,16 @@ var init_index = __esm({
1775
1715
  // src/dmv2/internal.ts
1776
1716
  import process2 from "process";
1777
1717
  import * as fs2 from "fs";
1778
- import * as path3 from "path";
1718
+ import * as path2 from "path";
1719
+ function getSourceDir() {
1720
+ return process2.env.MOOSE_SOURCE_DIR || "app";
1721
+ }
1779
1722
  function findSourceFiles(dir, extensions = [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts"]) {
1780
1723
  const files = [];
1781
1724
  try {
1782
1725
  const entries = fs2.readdirSync(dir, { withFileTypes: true });
1783
1726
  for (const entry of entries) {
1784
- const fullPath = path3.join(dir, entry.name);
1727
+ const fullPath = path2.join(dir, entry.name);
1785
1728
  if (entry.isDirectory()) {
1786
1729
  if (entry.name !== "node_modules" && !entry.name.startsWith(".")) {
1787
1730
  files.push(...findSourceFiles(fullPath, extensions));
@@ -1790,7 +1733,7 @@ function findSourceFiles(dir, extensions = [".ts", ".tsx", ".js", ".jsx", ".mts"
1790
1733
  if (entry.name.endsWith(".d.ts") || entry.name.endsWith(".d.mts") || entry.name.endsWith(".d.cts")) {
1791
1734
  continue;
1792
1735
  }
1793
- const ext = path3.extname(entry.name);
1736
+ const ext = path2.extname(entry.name);
1794
1737
  if (extensions.includes(ext)) {
1795
1738
  files.push(fullPath);
1796
1739
  }
@@ -1802,12 +1745,12 @@ function findSourceFiles(dir, extensions = [".ts", ".tsx", ".js", ".jsx", ".mts"
1802
1745
  return files;
1803
1746
  }
1804
1747
  function findUnloadedFiles() {
1805
- const appDir = path3.resolve(process2.cwd(), getSourceDir());
1748
+ const appDir = path2.resolve(process2.cwd(), getSourceDir());
1806
1749
  const allSourceFiles = findSourceFiles(appDir);
1807
1750
  const loadedFiles = new Set(
1808
- Object.keys(__require.cache).filter((key) => key.startsWith(appDir)).map((key) => path3.resolve(key))
1751
+ Object.keys(__require.cache).filter((key) => key.startsWith(appDir)).map((key) => path2.resolve(key))
1809
1752
  );
1810
- const unloadedFiles = allSourceFiles.map((file) => path3.resolve(file)).filter((file) => !loadedFiles.has(file)).map((file) => path3.relative(process2.cwd(), file));
1753
+ const unloadedFiles = allSourceFiles.map((file) => path2.resolve(file)).filter((file) => !loadedFiles.has(file)).map((file) => path2.relative(process2.cwd(), file));
1811
1754
  return unloadedFiles;
1812
1755
  }
1813
1756
  function isS3QueueConfig(config) {
@@ -2066,7 +2009,6 @@ var init_internal = __esm({
2066
2009
  "use strict";
2067
2010
  init_index();
2068
2011
  init_commons();
2069
- init_compiler_config();
2070
2012
  moose_internal = {
2071
2013
  tables: /* @__PURE__ */ new Map(),
2072
2014
  streams: /* @__PURE__ */ new Map(),
@@ -2351,7 +2293,6 @@ var init_internal = __esm({
2351
2293
  );
2352
2294
  };
2353
2295
  loadIndex = () => {
2354
- const useCompiled2 = shouldUseCompiled();
2355
2296
  const registry = getMooseInternal();
2356
2297
  registry.tables.clear();
2357
2298
  registry.streams.clear();
@@ -2362,21 +2303,14 @@ var init_internal = __esm({
2362
2303
  registry.webApps.clear();
2363
2304
  registry.materializedViews.clear();
2364
2305
  registry.views.clear();
2365
- if (!useCompiled2) {
2366
- const appDir = `${process2.cwd()}/${getSourceDir()}`;
2367
- Object.keys(__require.cache).forEach((key) => {
2368
- if (key.startsWith(appDir)) {
2369
- delete __require.cache[key];
2370
- }
2371
- });
2372
- }
2373
- try {
2374
- const sourceDir = getSourceDir();
2375
- if (useCompiled2) {
2376
- __require(`${process2.cwd()}/.moose/compiled/${sourceDir}/index.js`);
2377
- } else {
2378
- __require(`${process2.cwd()}/${sourceDir}/index.ts`);
2306
+ const appDir = `${process2.cwd()}/${getSourceDir()}`;
2307
+ Object.keys(__require.cache).forEach((key) => {
2308
+ if (key.startsWith(appDir)) {
2309
+ delete __require.cache[key];
2379
2310
  }
2311
+ });
2312
+ try {
2313
+ __require(`${process2.cwd()}/${getSourceDir()}/index.ts`);
2380
2314
  } catch (error) {
2381
2315
  let hint;
2382
2316
  let includeDetails = true;
@@ -2483,23 +2417,21 @@ var init_internal = __esm({
2483
2417
  });
2484
2418
 
2485
2419
  // src/moose-runner.ts
2486
- init_compiler_config();
2487
2420
  init_internal();
2488
2421
  import { register } from "ts-node";
2489
2422
 
2490
2423
  // src/blocks/runner.ts
2491
2424
  init_commons();
2492
- init_compiler_config();
2493
2425
  import fastq from "fastq";
2494
2426
  import fs3 from "fs";
2495
- import path4 from "path";
2427
+ import path3 from "path";
2496
2428
  var walkDir = (dir, fileExtension, fileList) => {
2497
2429
  const files = fs3.readdirSync(dir);
2498
2430
  files.forEach((file) => {
2499
- if (fs3.statSync(path4.join(dir, file)).isDirectory()) {
2500
- fileList = walkDir(path4.join(dir, file), fileExtension, fileList);
2431
+ if (fs3.statSync(path3.join(dir, file)).isDirectory()) {
2432
+ fileList = walkDir(path3.join(dir, file), fileExtension, fileList);
2501
2433
  } else if (file.endsWith(fileExtension)) {
2502
- fileList.push(path4.join(dir, file));
2434
+ fileList.push(path3.join(dir, file));
2503
2435
  }
2504
2436
  });
2505
2437
  return fileList;
@@ -2564,11 +2496,7 @@ var asyncWorker = async (task) => {
2564
2496
  var runBlocks = async (config) => {
2565
2497
  const chClient = getClickhouseClient(toClientConfig3(config.clickhouseConfig));
2566
2498
  console.log(`Connected`);
2567
- const useCompiled2 = shouldUseCompiled();
2568
- const sourceDir = getSourceDir();
2569
- const blocksDir = useCompiled2 ? `${process.cwd()}/.moose/compiled/${sourceDir}/blocks/` : config.blocksDir;
2570
- const fileExtension = useCompiled2 ? ".js" : ".ts";
2571
- const blocksFiles = walkDir(blocksDir, fileExtension, []);
2499
+ const blocksFiles = walkDir(config.blocksDir, ".ts", []);
2572
2500
  const numOfBlockFiles = blocksFiles.length;
2573
2501
  console.log(`Found ${numOfBlockFiles} blocks files`);
2574
2502
  const queue = fastq.promise(asyncWorker, 1);
@@ -2579,10 +2507,10 @@ var runBlocks = async (config) => {
2579
2507
  }
2580
2508
  }
2581
2509
  });
2582
- for (const path6 of blocksFiles) {
2583
- console.log(`Adding to queue: ${path6}`);
2510
+ for (const path5 of blocksFiles) {
2511
+ console.log(`Adding to queue: ${path5}`);
2584
2512
  try {
2585
- const blocks = __require(path6).default;
2513
+ const blocks = __require(path5).default;
2586
2514
  queue.push({
2587
2515
  chClient,
2588
2516
  blocks,
@@ -2591,7 +2519,7 @@ var runBlocks = async (config) => {
2591
2519
  } catch (err) {
2592
2520
  cliLog({
2593
2521
  action: "Blocks",
2594
- message: `Failed to import blocks from ${path6}: ${err}`,
2522
+ message: `Failed to import blocks from ${path5}: ${err}`,
2595
2523
  message_type: "Error"
2596
2524
  });
2597
2525
  }
@@ -2889,8 +2817,7 @@ var sendMessageMetrics = (logger2, metrics) => {
2889
2817
  function loadStreamingFunction(functionFilePath) {
2890
2818
  let streamingFunctionImport;
2891
2819
  try {
2892
- const pathWithoutExt = functionFilePath.replace(/\.(ts|js)$/, "");
2893
- streamingFunctionImport = __require(pathWithoutExt);
2820
+ streamingFunctionImport = __require(functionFilePath.substring(0, functionFilePath.length - 3));
2894
2821
  } catch (e) {
2895
2822
  cliLog({ action: "Function", message: `${e}`, message_type: "Error" });
2896
2823
  throw e;
@@ -3162,32 +3089,18 @@ var runStreamingFunctions = async (args) => {
3162
3089
  };
3163
3090
 
3164
3091
  // src/moduleExportSerializer.ts
3165
- init_compiler_config();
3166
3092
  async function runExportSerializer(targetModel) {
3167
- const useCompiled2 = shouldUseCompiled();
3168
- const sourceDir = getSourceDir();
3169
- let modulePath = targetModel;
3170
- if (useCompiled2) {
3171
- if (modulePath.includes(sourceDir)) {
3172
- modulePath = modulePath.replace(
3173
- new RegExp(`/${sourceDir}/`),
3174
- `/.moose/compiled/${sourceDir}/`
3175
- );
3176
- }
3177
- modulePath = modulePath.replace(/\.ts$/, ".js");
3178
- }
3179
- const exports_list = __require(modulePath);
3093
+ const exports_list = __require(targetModel);
3180
3094
  console.log(JSON.stringify(exports_list));
3181
3095
  }
3182
3096
 
3183
3097
  // src/consumption-apis/exportTypeSerializer.ts
3184
- init_compiler_config();
3185
3098
  import process4 from "process";
3099
+ function getSourceDir2() {
3100
+ return process4.env.MOOSE_SOURCE_DIR || "app";
3101
+ }
3186
3102
  async function runApiTypeSerializer(targetModel) {
3187
- const sourceDir = getSourceDir();
3188
- const useCompiled2 = shouldUseCompiled();
3189
- const apiPath = useCompiled2 ? `${process4.cwd()}/.moose/compiled/${sourceDir}/apis/${targetModel}.js` : `${process4.cwd()}/${sourceDir}/apis/${targetModel}.ts`;
3190
- const func = __require(apiPath).default;
3103
+ const func = __require(`${process4.cwd()}/${getSourceDir2()}/apis/${targetModel}.ts`).default;
3191
3104
  const inputSchema = func["moose_input_schema"] || null;
3192
3105
  const outputSchema = func["moose_output_schema"] || null;
3193
3106
  console.log(
@@ -3205,7 +3118,7 @@ import {
3205
3118
  Worker,
3206
3119
  bundleWorkflowCode
3207
3120
  } from "@temporalio/worker";
3208
- import * as path5 from "path";
3121
+ import * as path4 from "path";
3209
3122
  import * as fs4 from "fs";
3210
3123
 
3211
3124
  // src/scripts/activity.ts
@@ -3501,7 +3414,7 @@ async function registerWorkflows(logger2, config) {
3501
3414
  }
3502
3415
  };
3503
3416
  const workflowBundle = await bundleWorkflowCode({
3504
- workflowsPath: path5.resolve(__dirname, "scripts/workflow.js"),
3417
+ workflowsPath: path4.resolve(__dirname, "scripts/workflow.js"),
3505
3418
  logger: silentLogger
3506
3419
  });
3507
3420
  const worker = await Worker.create({
@@ -3582,27 +3495,31 @@ async function runScripts(config) {
3582
3495
  // src/moose-runner.ts
3583
3496
  import process5 from "process";
3584
3497
  import { Command } from "commander";
3585
- var useCompiled = shouldUseCompiled();
3586
- if (!useCompiled) {
3587
- const command = process5.argv[2];
3588
- const needsPlugins = COMMANDS_REQUIRING_PLUGINS.includes(command);
3589
- if (needsPlugins) {
3590
- register({
3591
- require: ["tsconfig-paths/register"],
3592
- esm: true,
3593
- experimentalTsImportSpecifiers: true,
3594
- compiler: "ts-patch/compiler",
3595
- compilerOptions: {
3596
- plugins: [...MOOSE_COMPILER_PLUGINS],
3597
- experimentalDecorators: true
3598
- }
3599
- });
3600
- } else {
3601
- register({
3602
- esm: true,
3603
- experimentalTsImportSpecifiers: true
3604
- });
3605
- }
3498
+ if (process5.argv[2] == "consumption-apis" || process5.argv[2] == "consumption-type-serializer" || process5.argv[2] == "dmv2-serializer" || // Streaming functions for dmv2 need to load moose internals
3499
+ process5.argv[2] == "streaming-functions" || process5.argv[2] == "scripts") {
3500
+ register({
3501
+ require: ["tsconfig-paths/register"],
3502
+ esm: true,
3503
+ experimentalTsImportSpecifiers: true,
3504
+ compiler: "ts-patch/compiler",
3505
+ compilerOptions: {
3506
+ plugins: [
3507
+ {
3508
+ transform: `./node_modules/@514labs/moose-lib/dist/compilerPlugin.js`,
3509
+ transformProgram: true
3510
+ },
3511
+ {
3512
+ transform: "typia/lib/transform"
3513
+ }
3514
+ ],
3515
+ experimentalDecorators: true
3516
+ }
3517
+ });
3518
+ } else {
3519
+ register({
3520
+ esm: true,
3521
+ experimentalTsImportSpecifiers: true
3522
+ });
3606
3523
  }
3607
3524
  var program = new Command();
3608
3525
  program.name("moose-runner").description("Moose runner for various operations").version("1.0.0");