@lark-apaas/devtool-kits 1.2.8-alpha.0 → 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 -202
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -202
- 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) {
|
|
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;
|
|
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,58 +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 path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2629
|
-
const limit = parseLimit(req.query.limit, 10, 200);
|
|
2630
|
-
try {
|
|
2631
|
-
const result = await readTriggerList(traceLogPath, trigger, path7, limit);
|
|
2632
|
-
if (!result) {
|
|
2633
|
-
return handleNotFound(res, traceLogPath);
|
|
2634
|
-
}
|
|
2635
|
-
res.json({
|
|
2636
|
-
file: getRelativePath(traceLogPath),
|
|
2637
|
-
path: path7,
|
|
2638
|
-
...result
|
|
2639
|
-
});
|
|
2640
|
-
} catch (error) {
|
|
2641
|
-
handleError(res, error, "Failed to read trace log");
|
|
2642
|
-
}
|
|
2643
|
-
};
|
|
2644
|
-
}
|
|
2645
|
-
__name(createGetTriggerListHandler, "createGetTriggerListHandler");
|
|
2646
|
-
function createGetTriggerDetailHandler(logDir) {
|
|
2647
|
-
const traceLogPath = (0, import_node_path7.join)(logDir, "server.log");
|
|
2648
|
-
return async (req, res) => {
|
|
2649
|
-
const instanceID = (req.params.instanceID || "").trim();
|
|
2650
|
-
if (!instanceID) {
|
|
2651
|
-
return res.status(400).json({
|
|
2652
|
-
message: "instanceID is required"
|
|
2653
|
-
});
|
|
2654
|
-
}
|
|
2655
|
-
const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
|
|
2656
|
-
try {
|
|
2657
|
-
const result = await readTriggerDetail(traceLogPath, path7, instanceID);
|
|
2658
|
-
if (!result) {
|
|
2659
|
-
return handleNotFound(res, traceLogPath);
|
|
2660
|
-
}
|
|
2661
|
-
res.json({
|
|
2662
|
-
file: getRelativePath(traceLogPath),
|
|
2663
|
-
...result
|
|
2664
|
-
});
|
|
2665
|
-
} catch (error) {
|
|
2666
|
-
handleError(res, error, "Failed to read trace log");
|
|
2667
|
-
}
|
|
2668
|
-
};
|
|
2669
|
-
}
|
|
2670
|
-
__name(createGetTriggerDetailHandler, "createGetTriggerDetailHandler");
|
|
2671
2507
|
|
|
2672
2508
|
// src/middlewares/dev-logs/health.controller.ts
|
|
2673
2509
|
var import_node_http2 = __toESM(require("http"), 1);
|
|
@@ -2744,8 +2580,6 @@ function createDevLogRouter(options = {}) {
|
|
|
2744
2580
|
router.get("/trace/recent", createGetRecentTracesHandler(logDir));
|
|
2745
2581
|
router.get("/files/:fileName", createGetLogFileHandler(logDir));
|
|
2746
2582
|
router.get("/server-logs", createGetServerLogsHandler(logDir));
|
|
2747
|
-
router.get("/trace/trigger/list", createGetTriggerListHandler(logDir));
|
|
2748
|
-
router.get("/trace/trigger/:instanceID", createGetTriggerDetailHandler(logDir));
|
|
2749
2583
|
router.get("/health", createHealthCheckHandler());
|
|
2750
2584
|
return router;
|
|
2751
2585
|
}
|
|
@@ -2772,16 +2606,6 @@ var DEV_LOGS_ROUTES = [
|
|
|
2772
2606
|
method: "GET",
|
|
2773
2607
|
path: "/server-logs",
|
|
2774
2608
|
description: "Get server logs in ServerLog format (compatible with frontend)"
|
|
2775
|
-
},
|
|
2776
|
-
{
|
|
2777
|
-
method: "GET",
|
|
2778
|
-
path: "/trace/trigger/list",
|
|
2779
|
-
description: "Get trigger list (automation trigger) in trace.log"
|
|
2780
|
-
},
|
|
2781
|
-
{
|
|
2782
|
-
method: "GET",
|
|
2783
|
-
path: "/trace/trigger/:instanceID",
|
|
2784
|
-
description: "Get trigger detail (automation trigger) in trace.log by instanceID"
|
|
2785
2609
|
}
|
|
2786
2610
|
];
|
|
2787
2611
|
function createDevLogsMiddleware(options = {}) {
|