建立 applications 的应用模型和查询出口,保留基础及详情投影差异。 下沉 DataLink,将工作流模型、API、编排及执行上下文归回 workflow。 同步 CLI、SDK、生成脚本、测试和活跃文档引用,公开命令与 SDK 名称保持兼容。 验证:943 项测试、类型和版本检查通过;三份生成规范字节一致,README 审计通过。
86 lines
2.8 KiB
TypeScript
86 lines
2.8 KiB
TypeScript
import type { WorkflowDetail, WorkflowTask } from "../types.js";
|
|
import type { NodeScriptLintReport, WorkflowScriptLintReport, ScriptIssue } from "./types.js";
|
|
import { lintJavaScriptCode } from "./lint-js.js";
|
|
import { lintMvelCode, collectAllWorkflowNodeNames } from "./lint-mvel.js";
|
|
|
|
/**
|
|
* 扫描并全面静态校验工作流中的全部代码节点(JS 与 MVEL)
|
|
*/
|
|
export function lintWorkflowScripts(
|
|
workflow: WorkflowDetail,
|
|
targetNodeQuery?: string
|
|
): WorkflowScriptLintReport {
|
|
const tasks = workflow.tasks || [];
|
|
const allNodeNames = collectAllWorkflowNodeNames(tasks);
|
|
const reports: NodeScriptLintReport[] = [];
|
|
|
|
function traverse(list: WorkflowTask[]) {
|
|
for (const task of list) {
|
|
if (!task) continue;
|
|
|
|
if (task.type === "code" || task.type === "code-js2") {
|
|
if (!targetNodeQuery || task.name === targetNodeQuery || task.label === targetNodeQuery || task.displayName === targetNodeQuery) {
|
|
const rawCode = (task as any).code || "";
|
|
const lineCount = rawCode ? rawCode.split(/\r?\n/).length : 0;
|
|
const mappings = Array.isArray((task as any).mapping) ? (task as any).mapping : [];
|
|
const boundVariables: Array<{ key: string; upstreamTarget?: string }> = mappings.map((m: any) => ({
|
|
key: m.key,
|
|
upstreamTarget: m.value,
|
|
}));
|
|
|
|
let issues: ScriptIssue[] = [];
|
|
let hasReturn = false;
|
|
let referencedNodes: Array<{ name: string; exists: boolean }> = [];
|
|
|
|
if (task.type === "code-js2") {
|
|
const paramNames = boundVariables.map((b) => b.key);
|
|
const res = lintJavaScriptCode(rawCode, paramNames);
|
|
issues = res.issues;
|
|
hasReturn = res.hasReturn;
|
|
} else {
|
|
const res = lintMvelCode(rawCode, allNodeNames);
|
|
issues = res.issues;
|
|
hasReturn = res.hasReturn;
|
|
referencedNodes = res.referencedNodes;
|
|
}
|
|
|
|
const hasErrors = issues.some((i) => i.level === "error");
|
|
|
|
reports.push({
|
|
nodeName: task.name,
|
|
displayName: task.displayName || undefined,
|
|
label: task.label || undefined,
|
|
type: task.type,
|
|
codeLength: rawCode.length,
|
|
lineCount,
|
|
hasReturn,
|
|
boundVariables,
|
|
referencedNodes,
|
|
issues,
|
|
valid: !hasErrors,
|
|
});
|
|
}
|
|
}
|
|
|
|
if (Array.isArray(task.tasks) && task.tasks.length > 0) {
|
|
traverse(task.tasks);
|
|
}
|
|
}
|
|
}
|
|
|
|
traverse(tasks);
|
|
|
|
const validCount = reports.filter((r) => r.valid).length;
|
|
const invalidCount = reports.length - validCount;
|
|
|
|
return {
|
|
pipelineId: workflow.id,
|
|
label: workflow.label,
|
|
totalCodeNodes: reports.length,
|
|
validCount,
|
|
invalidCount,
|
|
reports,
|
|
allValid: invalidCount === 0,
|
|
};
|
|
}
|