@lark-apaas/devtool-kits 1.2.8-alpha.1 → 1.2.8-alpha.2
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/index.cjs +26 -203
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -203
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -496,6 +496,31 @@ function replaceDefaultNowWithSql(source) {
|
|
|
496
496
|
}
|
|
497
497
|
__name(replaceDefaultNowWithSql, "replaceDefaultNowWithSql");
|
|
498
498
|
|
|
499
|
+
// src/helpers/gen-dbschema/helper/appendTableAliases.ts
|
|
500
|
+
var TABLE_ALIAS_MARKER = "// table aliases";
|
|
501
|
+
function appendTableAliases(source) {
|
|
502
|
+
const markerIndex = source.indexOf(`
|
|
503
|
+
${TABLE_ALIAS_MARKER}`);
|
|
504
|
+
const base = markerIndex === -1 ? source : source.slice(0, markerIndex);
|
|
505
|
+
const exportRegex = /export const\s+([A-Za-z_$][\w$]*)\s*=\s*pgTable\s*\(/g;
|
|
506
|
+
const tableExports = /* @__PURE__ */ new Set();
|
|
507
|
+
for (const match of base.matchAll(exportRegex)) {
|
|
508
|
+
const name = match[1];
|
|
509
|
+
tableExports.add(name);
|
|
510
|
+
}
|
|
511
|
+
if (tableExports.size === 0) {
|
|
512
|
+
return base;
|
|
513
|
+
}
|
|
514
|
+
const aliasLines = Array.from(tableExports).sort().map((name) => `export const ${name}Table = ${name};`).join("\n");
|
|
515
|
+
const prefix = base.trimEnd();
|
|
516
|
+
return `${prefix}
|
|
517
|
+
|
|
518
|
+
${TABLE_ALIAS_MARKER}
|
|
519
|
+
${aliasLines}
|
|
520
|
+
`;
|
|
521
|
+
}
|
|
522
|
+
__name(appendTableAliases, "appendTableAliases");
|
|
523
|
+
|
|
499
524
|
// src/helpers/gen-dbschema/postprocess.ts
|
|
500
525
|
function postprocessDrizzleSchema(targetPath) {
|
|
501
526
|
const resolvedPath = import_node_path2.default.resolve(targetPath);
|
|
@@ -523,6 +548,7 @@ function postprocessDrizzleSchema(targetPath) {
|
|
|
523
548
|
text = addSystemFieldComments(text);
|
|
524
549
|
text = tweakImports(text);
|
|
525
550
|
text = inlineCustomTypes(text);
|
|
551
|
+
text = appendTableAliases(text);
|
|
526
552
|
text = text.replace(/\r?\n/g, "\n");
|
|
527
553
|
text = collapseExtraBlankLines(text);
|
|
528
554
|
import_node_fs2.default.writeFileSync(resolvedPath, text, "utf8");
|
|
@@ -2359,144 +2385,6 @@ function generateUUID() {
|
|
|
2359
2385
|
});
|
|
2360
2386
|
}
|
|
2361
2387
|
__name(generateUUID, "generateUUID");
|
|
2362
|
-
async function readTriggerList(filePath, trigger, path7, limit, triggerID) {
|
|
2363
|
-
if (!await fileExists(filePath)) {
|
|
2364
|
-
return void 0;
|
|
2365
|
-
}
|
|
2366
|
-
const config = {
|
|
2367
|
-
maxEntriesPerTrace: 10,
|
|
2368
|
-
chunkSize: 64 * 1024
|
|
2369
|
-
};
|
|
2370
|
-
const builders = /* @__PURE__ */ new Map();
|
|
2371
|
-
const completedCalls = [];
|
|
2372
|
-
const createTraceBuilder = /* @__PURE__ */ __name((traceId) => ({
|
|
2373
|
-
traceId,
|
|
2374
|
-
entries: [],
|
|
2375
|
-
method: void 0,
|
|
2376
|
-
path: void 0,
|
|
2377
|
-
startTime: void 0,
|
|
2378
|
-
endTime: void 0,
|
|
2379
|
-
statusCode: void 0,
|
|
2380
|
-
durationMs: void 0,
|
|
2381
|
-
hasCompleted: false
|
|
2382
|
-
}), "createTraceBuilder");
|
|
2383
|
-
const shouldIncludeInCompletedCalls = /* @__PURE__ */ __name((builder) => {
|
|
2384
|
-
const alreadyAdded = completedCalls.some((call) => call.traceId === builder.traceId);
|
|
2385
|
-
if (alreadyAdded) {
|
|
2386
|
-
return false;
|
|
2387
|
-
}
|
|
2388
|
-
const isAutomationTrigger = builder.path?.endsWith(path7);
|
|
2389
|
-
if (!isAutomationTrigger) {
|
|
2390
|
-
return false;
|
|
2391
|
-
}
|
|
2392
|
-
if (trigger && builder.entries.length > 0) {
|
|
2393
|
-
const requestEntry = builder.entries.find((e) => e.request_body?.trigger);
|
|
2394
|
-
if (requestEntry?.request_body?.trigger) {
|
|
2395
|
-
return String(requestEntry.request_body.trigger) === trigger && (triggerID ? requestEntry?.request_body?.triggerID === triggerID : true);
|
|
2396
|
-
}
|
|
2397
|
-
return false;
|
|
2398
|
-
}
|
|
2399
|
-
return true;
|
|
2400
|
-
}, "shouldIncludeInCompletedCalls");
|
|
2401
|
-
const updateBuilderMetadata = /* @__PURE__ */ __name((builder, entry) => {
|
|
2402
|
-
if (entry.method && !builder.method) builder.method = String(entry.method);
|
|
2403
|
-
if (entry.path && !builder.path) builder.path = String(entry.path);
|
|
2404
|
-
builder.entries.push(entry);
|
|
2405
|
-
if (builder.entries.length > config.maxEntriesPerTrace) {
|
|
2406
|
-
builder.entries.shift();
|
|
2407
|
-
}
|
|
2408
|
-
if (shouldIncludeInCompletedCalls(builder)) {
|
|
2409
|
-
completedCalls.push(builder);
|
|
2410
|
-
if (limit && completedCalls.length > limit) {
|
|
2411
|
-
completedCalls.pop();
|
|
2412
|
-
}
|
|
2413
|
-
}
|
|
2414
|
-
}, "updateBuilderMetadata");
|
|
2415
|
-
const handleRequestCompleted = /* @__PURE__ */ __name((builder, entry, message) => {
|
|
2416
|
-
builder.hasCompleted = true;
|
|
2417
|
-
builder.endTime = entry.time;
|
|
2418
|
-
builder.statusCode = extractNumber(message, /status_code:\s*(\d+)/);
|
|
2419
|
-
builder.durationMs = extractNumber(message, /duration_ms:\s*(\d+)/);
|
|
2420
|
-
if (!builder.path && entry.path) {
|
|
2421
|
-
builder.path = String(entry.path);
|
|
2422
|
-
}
|
|
2423
|
-
if (shouldIncludeInCompletedCalls(builder)) {
|
|
2424
|
-
completedCalls.push(builder);
|
|
2425
|
-
if (limit && completedCalls.length > limit) {
|
|
2426
|
-
completedCalls.pop();
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
}, "handleRequestCompleted");
|
|
2430
|
-
const processLogEntry = /* @__PURE__ */ __name((entry) => {
|
|
2431
|
-
const { trace_id: traceId, message = "" } = entry;
|
|
2432
|
-
if (!traceId) return;
|
|
2433
|
-
let builder = builders.get(traceId);
|
|
2434
|
-
if (!builder) {
|
|
2435
|
-
builder = createTraceBuilder(traceId);
|
|
2436
|
-
builders.set(traceId, builder);
|
|
2437
|
-
}
|
|
2438
|
-
updateBuilderMetadata(builder, entry);
|
|
2439
|
-
if (!builder.hasCompleted && (message.includes("HTTP request completed") || message.includes("HTTP request failed"))) {
|
|
2440
|
-
handleRequestCompleted(builder, entry, message);
|
|
2441
|
-
}
|
|
2442
|
-
if (message.includes("HTTP request started") && !builder.startTime) {
|
|
2443
|
-
builder.startTime = entry.time;
|
|
2444
|
-
}
|
|
2445
|
-
}, "processLogEntry");
|
|
2446
|
-
const processLine = /* @__PURE__ */ __name((line) => {
|
|
2447
|
-
const entry = parseLogLine2(line);
|
|
2448
|
-
if (entry?.trace_id) {
|
|
2449
|
-
processLogEntry(entry);
|
|
2450
|
-
}
|
|
2451
|
-
}, "processLine");
|
|
2452
|
-
await readFileReverse(filePath, config.chunkSize, processLine);
|
|
2453
|
-
return {
|
|
2454
|
-
page: 1,
|
|
2455
|
-
pageSize: completedCalls.length,
|
|
2456
|
-
totalCalls: completedCalls.length,
|
|
2457
|
-
totalPages: 1,
|
|
2458
|
-
calls: completedCalls.map((builder) => ({
|
|
2459
|
-
traceId: builder.traceId,
|
|
2460
|
-
method: builder.method,
|
|
2461
|
-
path: builder.path,
|
|
2462
|
-
startTime: builder.startTime,
|
|
2463
|
-
endTime: builder.endTime,
|
|
2464
|
-
statusCode: builder.statusCode,
|
|
2465
|
-
durationMs: builder.durationMs,
|
|
2466
|
-
entries: builder.entries.slice().reverse()
|
|
2467
|
-
}))
|
|
2468
|
-
};
|
|
2469
|
-
}
|
|
2470
|
-
__name(readTriggerList, "readTriggerList");
|
|
2471
|
-
async function readTriggerDetail(filePath, path7, instanceID) {
|
|
2472
|
-
const exists = await fileExists(filePath);
|
|
2473
|
-
if (!exists) {
|
|
2474
|
-
return void 0;
|
|
2475
|
-
}
|
|
2476
|
-
const matches = [];
|
|
2477
|
-
const stream = (0, import_node_fs7.createReadStream)(filePath, {
|
|
2478
|
-
encoding: "utf8"
|
|
2479
|
-
});
|
|
2480
|
-
const rl = (0, import_node_readline.createInterface)({
|
|
2481
|
-
input: stream,
|
|
2482
|
-
crlfDelay: Infinity
|
|
2483
|
-
});
|
|
2484
|
-
for await (const line of rl) {
|
|
2485
|
-
const entry = parseLogLine2(line);
|
|
2486
|
-
if (!entry) continue;
|
|
2487
|
-
const isAutomationTrigger = entry.path?.endsWith(path7);
|
|
2488
|
-
const hasInstanceID = entry.instance_id === instanceID && entry.trigger;
|
|
2489
|
-
if (!isAutomationTrigger || !hasInstanceID) continue;
|
|
2490
|
-
matches.push(entry);
|
|
2491
|
-
}
|
|
2492
|
-
rl.close();
|
|
2493
|
-
stream.close();
|
|
2494
|
-
return {
|
|
2495
|
-
instanceID,
|
|
2496
|
-
entries: matches
|
|
2497
|
-
};
|
|
2498
|
-
}
|
|
2499
|
-
__name(readTriggerDetail, "readTriggerDetail");
|
|
2500
2388
|
|
|
2501
2389
|
// src/middlewares/dev-logs/controller.ts
|
|
2502
2390
|
function handleNotFound(res, filePath, message = "Log file not found") {
|
|
@@ -2616,59 +2504,6 @@ function createGetServerLogsHandler(logDir) {
|
|
|
2616
2504
|
};
|
|
2617
2505
|
}
|
|
2618
2506
|
__name(createGetServerLogsHandler, "createGetServerLogsHandler");
|
|
2619
|
-
function createGetTriggerListHandler(logDir) {
|
|
2620
|
-
const traceLogPath = (0, import_node_path7.join)(logDir, "trace.log");
|
|
2621
|
-
return async (req, res) => {
|
|
2622
|
-
const trigger = typeof req.query.trigger === "string" ? req.query.trigger.trim() : void 0;
|
|
2623
|
-
if (!trigger) {
|
|
2624
|
-
return res.status(400).json({
|
|
2625
|
-
message: "trigger is required"
|
|
2626
|
-
});
|
|
2627
|
-
}
|
|
2628
|
-
const triggerID = typeof req.query.triggerID === "string" ? req.query.triggerID.trim() : void 0;
|
|
2629
|
-
const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2630
|
-
const limit = parseLimit(req.query.limit, 10, 200);
|
|
2631
|
-
try {
|
|
2632
|
-
const result = await readTriggerList(traceLogPath, trigger, path7, limit, triggerID);
|
|
2633
|
-
if (!result) {
|
|
2634
|
-
return handleNotFound(res, traceLogPath);
|
|
2635
|
-
}
|
|
2636
|
-
res.json({
|
|
2637
|
-
file: getRelativePath(traceLogPath),
|
|
2638
|
-
path: path7,
|
|
2639
|
-
...result
|
|
2640
|
-
});
|
|
2641
|
-
} catch (error) {
|
|
2642
|
-
handleError(res, error, "Failed to read trace log");
|
|
2643
|
-
}
|
|
2644
|
-
};
|
|
2645
|
-
}
|
|
2646
|
-
__name(createGetTriggerListHandler, "createGetTriggerListHandler");
|
|
2647
|
-
function createGetTriggerDetailHandler(logDir) {
|
|
2648
|
-
const traceLogPath = (0, import_node_path7.join)(logDir, "server.log");
|
|
2649
|
-
return async (req, res) => {
|
|
2650
|
-
const instanceID = (req.params.instanceID || "").trim();
|
|
2651
|
-
if (!instanceID) {
|
|
2652
|
-
return res.status(400).json({
|
|
2653
|
-
message: "instanceID is required"
|
|
2654
|
-
});
|
|
2655
|
-
}
|
|
2656
|
-
const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2657
|
-
try {
|
|
2658
|
-
const result = await readTriggerDetail(traceLogPath, path7, instanceID);
|
|
2659
|
-
if (!result) {
|
|
2660
|
-
return handleNotFound(res, traceLogPath);
|
|
2661
|
-
}
|
|
2662
|
-
res.json({
|
|
2663
|
-
file: getRelativePath(traceLogPath),
|
|
2664
|
-
...result
|
|
2665
|
-
});
|
|
2666
|
-
} catch (error) {
|
|
2667
|
-
handleError(res, error, "Failed to read trace log");
|
|
2668
|
-
}
|
|
2669
|
-
};
|
|
2670
|
-
}
|
|
2671
|
-
__name(createGetTriggerDetailHandler, "createGetTriggerDetailHandler");
|
|
2672
2507
|
|
|
2673
2508
|
// src/middlewares/dev-logs/health.controller.ts
|
|
2674
2509
|
var import_node_http2 = __toESM(require("http"), 1);
|
|
@@ -2745,8 +2580,6 @@ function createDevLogRouter(options = {}) {
|
|
|
2745
2580
|
router.get("/trace/recent", createGetRecentTracesHandler(logDir));
|
|
2746
2581
|
router.get("/files/:fileName", createGetLogFileHandler(logDir));
|
|
2747
2582
|
router.get("/server-logs", createGetServerLogsHandler(logDir));
|
|
2748
|
-
router.get("/trace/trigger/list", createGetTriggerListHandler(logDir));
|
|
2749
|
-
router.get("/trace/trigger/:instanceID", createGetTriggerDetailHandler(logDir));
|
|
2750
2583
|
router.get("/health", createHealthCheckHandler());
|
|
2751
2584
|
return router;
|
|
2752
2585
|
}
|
|
@@ -2773,16 +2606,6 @@ var DEV_LOGS_ROUTES = [
|
|
|
2773
2606
|
method: "GET",
|
|
2774
2607
|
path: "/server-logs",
|
|
2775
2608
|
description: "Get server logs in ServerLog format (compatible with frontend)"
|
|
2776
|
-
},
|
|
2777
|
-
{
|
|
2778
|
-
method: "GET",
|
|
2779
|
-
path: "/trace/trigger/list",
|
|
2780
|
-
description: "Get trigger list (automation trigger) in trace.log"
|
|
2781
|
-
},
|
|
2782
|
-
{
|
|
2783
|
-
method: "GET",
|
|
2784
|
-
path: "/trace/trigger/:instanceID",
|
|
2785
|
-
description: "Get trigger detail (automation trigger) in trace.log by instanceID"
|
|
2786
2609
|
}
|
|
2787
2610
|
];
|
|
2788
2611
|
function createDevLogsMiddleware(options = {}) {
|