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