refactor(workflow): 按节点类型原子化拆分工作流节点模型

- 创建 src/domains/platform/workflow/models/nodes/ 子目录
- 将原本混在一个大文件的 14 类节点拆分为独立定义模块:
  - common.ts: 基础任务契约与通用结构
  - http.ts: HTTP 动作节点 (放行 authId/appId 凭证与 passthrough)
  - delay.ts: 动态延迟等待节点
  - code.ts: MVEL / JS 代码节点
  - webhook.ts: Webhook 触发器节点
  - stop.ts: 终止流程节点
  - flow.ts: 单据详情与创建单据节点
  - datalink.ts: 台账查找、创建与数据转换节点
  - condition.ts & every.ts: 递归容器节点工厂
  - unknown.ts: 兜底节点
  - index.ts: 聚合实例化统一 WorkflowTaskSchema 导出
- 同步更新 specs/workflow-schema.json 并补齐各节点独立单测与文档
This commit is contained in:
gitea committed 2026-11-02 22:53:06 +08:00
1 parent b3010123ff
commit 2371ae0bf1
17 files changed
+494 -260

No files matched your search

@@ -66,4 +66,43 @@ describe("workflow CLI ergonomics & layered help", () => {
expect(result.stdout).toContain("追加工作流节点");
expect(result.stdout).toContain("task-dynamic-delay");
});
it("workflow node edit dry-run parses JSON payload in --set", async () => {
const result = await runCli([
"workflow",
"node",
"edit",
"881196955148578838",
"action_agree_normal",
'--set={"authId":157,"appId":"4"}',
"--dry-run",
]);
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain("修改工作流节点");
expect(result.stdout).toContain('"authId":157');
expect(result.stdout).toContain('"appId":"4"');
});
it("WorkflowTaskSchema preserves authId and appId on http tasks without stripping", async () => {
const { WorkflowTaskSchema } = await import("../../../domains/platform/workflow/models/nodes.js");
const sample = {
name: "action_test",
type: "http",
label: "http节点",
groupName: "action",
orderIndex: 0,
levelIndex: [0],
status: "active",
method: "POST",
url: "https://example.com",
header: [],
params: [],
successCode: ["200"],
authId: 157,
appId: "4",
};
const parsed = WorkflowTaskSchema.parse(sample);
expect((parsed as any).authId).toBe(157);
expect((parsed as any).appId).toBe("4");
});
});
+28 -12
View File
@@ -299,14 +299,22 @@ async function handleAddNode(
extra.sleepTime = rawSleepTime;
}
if (rawSet) {
const eqIdx = rawSet.indexOf("=");
if (eqIdx !== -1) {
const k = rawSet.slice(0, eqIdx).trim();
const v = rawSet.slice(eqIdx + 1).trim();
if (rawSet.startsWith("{") && rawSet.endsWith("}")) {
try {
extra[k] = JSON.parse(v);
Object.assign(extra, JSON.parse(rawSet));
} catch {
extra[k] = v;
// fallback
}
} else {
const eqIdx = rawSet.indexOf("=");
if (eqIdx !== -1) {
const k = rawSet.slice(0, eqIdx).trim();
const v = rawSet.slice(eqIdx + 1).trim();
try {
extra[k] = JSON.parse(v);
} catch {
extra[k] = v;
}
}
}
}
@@ -418,14 +426,22 @@ async function handleEditNode(
customSet.sleepTime = rawSleepTime;
}
if (rawSet) {
const eqIdx = rawSet.indexOf("=");
if (eqIdx !== -1) {
const k = rawSet.slice(0, eqIdx).trim();
const v = rawSet.slice(eqIdx + 1).trim();
if (rawSet.startsWith("{") && rawSet.endsWith("}")) {
try {
customSet[k] = JSON.parse(v);
Object.assign(customSet, JSON.parse(rawSet));
} catch {
customSet[k] = v;
// fallback to key=value if json parse fails
}
} else {
const eqIdx = rawSet.indexOf("=");
if (eqIdx !== -1) {
const k = rawSet.slice(0, eqIdx).trim();
const v = rawSet.slice(eqIdx + 1).trim();
try {
customSet[k] = JSON.parse(v);
} catch {
customSet[k] = v;
}
}
}
}