refactor: 拆分工作流命令和循环诊断职责
拆出节点目录与执行上下文补全,复用客户端选择逻辑并整理循环规则。
This commit is contained in:
1 parent
7af7e7db35
commit
e185c84b4e
11 files changed
+383
-372
No files matched your search
@@ -1,25 +1,16 @@
|
||||
import type { WorkflowDetail, WorkflowTask } from "../types.js";
|
||||
import { addDiagnostic } from "./diagnostics.js";
|
||||
import { checkEveryConfiguration, extractLeafFilters } from "./every.js";
|
||||
import type {
|
||||
WorkflowAnalysis,
|
||||
WorkflowAstNode,
|
||||
WorkflowDependency,
|
||||
WorkflowDiagnostic,
|
||||
DiagnosticCategory,
|
||||
WorkflowAnalysisSummary,
|
||||
WorkflowFormSpecComponentLike,
|
||||
AnalyzeWorkflowOptions,
|
||||
} from "./types.js";
|
||||
|
||||
function addDiagnostic(
|
||||
diagnostics: WorkflowDiagnostic[],
|
||||
item: Omit<WorkflowDiagnostic, "category"> & { category?: DiagnosticCategory }
|
||||
): void {
|
||||
diagnostics.push({
|
||||
...item,
|
||||
category: item.category ?? (item.severity === "error" ? "hard_block" : "soft_advice"),
|
||||
});
|
||||
}
|
||||
|
||||
const KNOWN_TYPES = new Set([
|
||||
"webhook",
|
||||
"crontab",
|
||||
@@ -241,96 +232,6 @@ function getTaskFormEntries(
|
||||
return [];
|
||||
}
|
||||
|
||||
interface LeafFilterItem {
|
||||
key?: unknown;
|
||||
value?: unknown;
|
||||
compare?: unknown;
|
||||
label?: unknown;
|
||||
}
|
||||
|
||||
function extractLeafFilters(filterGroup: unknown): LeafFilterItem[] {
|
||||
if (Array.isArray(filterGroup)) return filterGroup.flatMap(extractLeafFilters);
|
||||
if (!filterGroup || typeof filterGroup !== "object") return [];
|
||||
const items: LeafFilterItem[] = [];
|
||||
const rec = filterGroup as Record<string, unknown>;
|
||||
|
||||
if (Array.isArray(rec.filters)) {
|
||||
for (const sub of rec.filters) {
|
||||
items.push(...extractLeafFilters(sub));
|
||||
}
|
||||
} else if ("key" in rec || "value" in rec) {
|
||||
items.push({
|
||||
key: rec.key,
|
||||
value: rec.value,
|
||||
compare: rec.compare,
|
||||
label: rec.label,
|
||||
});
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
/** 只检查前端 value 选择器的 JSON,不执行表达式或推断档案名称。 */
|
||||
function inspectValueSelector(value: unknown): { descriptor?: Record<string, unknown>; invalid?: boolean } | undefined {
|
||||
if (typeof value !== "string") return undefined;
|
||||
const match = /^@\{\s*value\s*\(([\s\S]*)\)\s*\}$/.exec(value.trim());
|
||||
if (!match) return undefined;
|
||||
const argument = match[1].trim();
|
||||
try {
|
||||
const json = argument.startsWith('"')
|
||||
? JSON.parse(argument)
|
||||
: argument.startsWith("'") && argument.endsWith("'")
|
||||
? argument.slice(1, -1).replace(/\\'/g, "'")
|
||||
: undefined;
|
||||
if (typeof json !== "string" || !json.trim().startsWith("{")) return undefined;
|
||||
const descriptor: unknown = JSON.parse(json);
|
||||
return descriptor && typeof descriptor === "object" && !Array.isArray(descriptor)
|
||||
? { descriptor: descriptor as Record<string, unknown> }
|
||||
: { invalid: true };
|
||||
} catch {
|
||||
return { invalid: true };
|
||||
}
|
||||
}
|
||||
|
||||
function checkEveryConfiguration(task: WorkflowTask, path: string, diagnostics: WorkflowDiagnostic[]): void {
|
||||
if (task.type !== "every") return;
|
||||
if (task.batch === true && task.batchSize !== undefined && (!Number.isInteger(task.batchSize) || Number(task.batchSize) <= 0)) {
|
||||
addDiagnostic(diagnostics, {
|
||||
severity: "warning", code: "EVERY_BATCH_SIZE_INVALID", path,
|
||||
message: "依次执行节点已开启并行,但 batchSize 不是正整数。请核对设计器的批次大小;CLI 不自动开启并行或补入默认批次。",
|
||||
});
|
||||
}
|
||||
if (task.mode !== "specified") return;
|
||||
for (const filter of extractLeafFilters(task.combineFilters ?? task.filters)) {
|
||||
if (inspectValueSelector(filter.key)?.descriptor?.key === "feeTypeId") {
|
||||
addDiagnostic(diagnostics, {
|
||||
severity: "warning", code: "EVERY_FILTER_FIELD_KEY_WRAPPED", path,
|
||||
message: "费用类型筛选的左侧字段被包装为 value()。原生 every 筛选应保留物理键 feeTypeId;选择器包装用于右侧值,混用可能导致运行时左值为空。",
|
||||
});
|
||||
}
|
||||
if (filter.key !== "feeTypeId" || !["eq", "neq"].includes(String(filter.compare))) continue;
|
||||
const selector = inspectValueSelector(filter.value);
|
||||
if (selector?.invalid) {
|
||||
addDiagnostic(diagnostics, {
|
||||
severity: "warning", code: "INVALID_VALUE_SELECTOR_DESCRIPTOR", path,
|
||||
message: "费用类型筛选右值的 value() 选择器不是有效 JSON 描述符,请在设计器重新选择并回读核对 key/label。",
|
||||
});
|
||||
} else if (selector?.descriptor) {
|
||||
const { key, label } = selector.descriptor;
|
||||
if (typeof key !== "string" || !key.trim() || typeof label !== "string" || !label.trim()) {
|
||||
addDiagnostic(diagnostics, {
|
||||
severity: "warning", code: "EVERY_FEE_TYPE_SELECTOR_INCOMPLETE", path,
|
||||
message: "费用类型筛选右值的选择器缺少有效 ID 或显示名称。请保留前端 value() 描述符中的 key 和 label;CLI 不猜测费用类型名称。",
|
||||
});
|
||||
}
|
||||
} else if (typeof filter.value === "string" && filter.value.trim() && !filter.value.includes("@{")) {
|
||||
addDiagnostic(diagnostics, {
|
||||
severity: "warning", code: "EVERY_FEE_TYPE_VALUE_NOT_DISPLAYABLE", path,
|
||||
message: "费用类型筛选右值使用裸 ID,运行时可能匹配,但设计器可能显示“请选择”。请采用前端 value() JSON 描述符,包含真实费用类型 ID(key)和名称(label)。",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function extractWorkflowSpecificationIds(detail: WorkflowDetail): string[] {
|
||||
const ids = new Set<string>();
|
||||
const walk = (tasks: WorkflowTask[]) => {
|
||||
|
||||
Reference in new issue
Block a user