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:
1 parent
b3010123ff
commit
2371ae0bf1
17 files changed
+494
-260
No files matched your search
+99
-39
@@ -267,7 +267,7 @@
|
||||
"params",
|
||||
"urlPath"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -328,7 +328,7 @@
|
||||
"combineFilters",
|
||||
"tasks"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -405,7 +405,7 @@
|
||||
"tasksMaxLevel",
|
||||
"tasks"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -451,7 +451,7 @@
|
||||
"levelIndex",
|
||||
"status"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -538,6 +538,26 @@
|
||||
"type": "string"
|
||||
},
|
||||
"additionalProperties": {}
|
||||
},
|
||||
"authId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"appId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -554,7 +574,7 @@
|
||||
"params",
|
||||
"successCode"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -635,7 +655,7 @@
|
||||
"mapping",
|
||||
"flowCode"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -685,7 +705,7 @@
|
||||
"status",
|
||||
"code"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -766,7 +786,7 @@
|
||||
"status",
|
||||
"code"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -875,7 +895,7 @@
|
||||
"orderMode",
|
||||
"limitCount"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -955,7 +975,7 @@
|
||||
"filters",
|
||||
"combineFilters"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1060,7 +1080,7 @@
|
||||
"targetType",
|
||||
"feeFormType"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1144,7 +1164,7 @@
|
||||
"form",
|
||||
"details"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1200,7 +1220,7 @@
|
||||
"levelIndex",
|
||||
"status"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1372,7 +1392,7 @@
|
||||
"params",
|
||||
"urlPath"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1433,7 +1453,7 @@
|
||||
"combineFilters",
|
||||
"tasks"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1510,7 +1530,7 @@
|
||||
"tasksMaxLevel",
|
||||
"tasks"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1556,7 +1576,7 @@
|
||||
"levelIndex",
|
||||
"status"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1643,6 +1663,26 @@
|
||||
"type": "string"
|
||||
},
|
||||
"additionalProperties": {}
|
||||
},
|
||||
"authId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"appId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1659,7 +1699,7 @@
|
||||
"params",
|
||||
"successCode"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1740,7 +1780,7 @@
|
||||
"mapping",
|
||||
"flowCode"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1790,7 +1830,7 @@
|
||||
"status",
|
||||
"code"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1871,7 +1911,7 @@
|
||||
"status",
|
||||
"code"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -1980,7 +2020,7 @@
|
||||
"orderMode",
|
||||
"limitCount"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -2060,7 +2100,7 @@
|
||||
"filters",
|
||||
"combineFilters"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -2165,7 +2205,7 @@
|
||||
"targetType",
|
||||
"feeFormType"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -2249,7 +2289,7 @@
|
||||
"form",
|
||||
"details"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -2305,7 +2345,7 @@
|
||||
"levelIndex",
|
||||
"status"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -2552,7 +2592,7 @@
|
||||
"params",
|
||||
"urlPath"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -2613,7 +2653,7 @@
|
||||
"combineFilters",
|
||||
"tasks"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -2690,7 +2730,7 @@
|
||||
"tasksMaxLevel",
|
||||
"tasks"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -2736,7 +2776,7 @@
|
||||
"levelIndex",
|
||||
"status"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -2823,6 +2863,26 @@
|
||||
"type": "string"
|
||||
},
|
||||
"additionalProperties": {}
|
||||
},
|
||||
"authId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"appId": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "number"
|
||||
},
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -2839,7 +2899,7 @@
|
||||
"params",
|
||||
"successCode"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -2920,7 +2980,7 @@
|
||||
"mapping",
|
||||
"flowCode"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -2970,7 +3030,7 @@
|
||||
"status",
|
||||
"code"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -3051,7 +3111,7 @@
|
||||
"status",
|
||||
"code"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -3160,7 +3220,7 @@
|
||||
"orderMode",
|
||||
"limitCount"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -3240,7 +3300,7 @@
|
||||
"filters",
|
||||
"combineFilters"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -3345,7 +3405,7 @@
|
||||
"targetType",
|
||||
"feeFormType"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -3429,7 +3489,7 @@
|
||||
"form",
|
||||
"details"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@@ -3485,7 +3545,7 @@
|
||||
"levelIndex",
|
||||
"status"
|
||||
],
|
||||
"additionalProperties": false
|
||||
"additionalProperties": {}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,209 +1,5 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// ── 工作流任务节点(递归、按类型区分)─────────────────────────────────────────
|
||||
|
||||
export const BaseTaskSchema = z.object({
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
label: z.string(),
|
||||
desc: z.string().optional(),
|
||||
groupName: z.string(),
|
||||
orderIndex: z.number(),
|
||||
levelIndex: z.array(z.number()),
|
||||
status: z.string(),
|
||||
displayName: z.string().optional(),
|
||||
});
|
||||
|
||||
// 任务节点运行时类型(用于递归结构中的类型标注)
|
||||
export interface WorkflowTask {
|
||||
name: string;
|
||||
type: string;
|
||||
label?: string;
|
||||
desc?: string;
|
||||
groupName: string;
|
||||
orderIndex: number;
|
||||
levelIndex: number[];
|
||||
status: string;
|
||||
displayName?: string;
|
||||
tasks?: WorkflowTask[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
// 条件/过滤的递归结构:condition / combineFilters
|
||||
export const FilterConditionSchema = z.object({
|
||||
key: z.string(),
|
||||
value: z.any().optional(),
|
||||
compare: z.string(),
|
||||
});
|
||||
|
||||
export const FilterGroupSchema: z.ZodType<any> = z.lazy(() =>
|
||||
z.object({
|
||||
filters: z.array(z.union([FilterConditionSchema, FilterGroupSchema])),
|
||||
condition: z.string(),
|
||||
})
|
||||
);
|
||||
|
||||
// 字段映射条目的两种形态:只读 key 或 key-value 映射(保留 value 及其余配置项)
|
||||
export const FieldMappingSchema = z.object({
|
||||
key: z.string(),
|
||||
value: z.any().optional(),
|
||||
}).passthrough();
|
||||
|
||||
// 错误处理配置
|
||||
export const OnErrorSchema = z.object({
|
||||
defaultAction: z.string(),
|
||||
});
|
||||
|
||||
// ── 控制节点 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const ConditionTaskSchema: z.ZodType<WorkflowTask> = BaseTaskSchema.extend({
|
||||
type: z.literal("condition"),
|
||||
tasksMaxLevel: z.number(),
|
||||
combineFilters: FilterGroupSchema,
|
||||
tasks: z.lazy(() => z.array(WorkflowTaskSchema)),
|
||||
});
|
||||
|
||||
export const EveryTaskSchema: z.ZodType<WorkflowTask> = BaseTaskSchema.extend({
|
||||
type: z.literal("every"),
|
||||
batch: z.boolean(),
|
||||
batchSize: z.number().optional(),
|
||||
mode: z.string(),
|
||||
list: z.string(),
|
||||
filters: z.array(z.any()),
|
||||
tasksMaxLevel: z.number(),
|
||||
tasks: z.lazy(() => z.array(WorkflowTaskSchema)),
|
||||
});
|
||||
|
||||
// ── 触发器节点 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WebhookTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("webhook"),
|
||||
sampleId: z.string(),
|
||||
params: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
urlPath: z.string(),
|
||||
});
|
||||
|
||||
// ── 动作节点 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const StopTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("stop"),
|
||||
});
|
||||
|
||||
export const HttpTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("http"),
|
||||
method: z.string(),
|
||||
url: z.string(),
|
||||
bodyType: z.string().optional(),
|
||||
bodyRaw: z.record(z.string(), z.any()).optional(),
|
||||
header: z.array(z.any()),
|
||||
params: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
successCode: z.array(z.string()),
|
||||
sampleData: z.record(z.string(), z.any()).optional(),
|
||||
});
|
||||
|
||||
export const FlowDetailTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("flow-detail"),
|
||||
specificationId: z.string(),
|
||||
mapping: z.union([
|
||||
z.boolean(),
|
||||
z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
]),
|
||||
flowCode: z.string(),
|
||||
});
|
||||
|
||||
export const CodeTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("code"),
|
||||
code: z.string(),
|
||||
});
|
||||
|
||||
export const CodeJs2TaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("code-js2"),
|
||||
code: z.string(),
|
||||
mapping: z.array(z.object({ key: z.string(), value: z.string() })).optional(),
|
||||
onError: OnErrorSchema.optional(),
|
||||
});
|
||||
|
||||
export const EkuaibaoDatalinkFilterTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("ekuaibao-datalink-filter"),
|
||||
mode: z.string(),
|
||||
entityId: z.string(),
|
||||
fields: z.array(FieldMappingSchema),
|
||||
filters: z.array(z.any()),
|
||||
selectFields: z.array(z.any()),
|
||||
combineFilters: FilterGroupSchema,
|
||||
orderKey: z.string(),
|
||||
orderMode: z.string(),
|
||||
limitCount: z.string(),
|
||||
onError: OnErrorSchema.optional(),
|
||||
});
|
||||
|
||||
export const EkuaibaoDatalinkCreateTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("ekuaibao-datalink-create"),
|
||||
mode: z.string(),
|
||||
entityId: z.string(),
|
||||
fields: z.array(FieldMappingSchema),
|
||||
filters: z.array(z.any()),
|
||||
combineFilters: FilterGroupSchema,
|
||||
});
|
||||
|
||||
export const DataConvertTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("data-convert"),
|
||||
mode: z.string(),
|
||||
path: z.array(z.string()),
|
||||
fields: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
onError: OnErrorSchema.optional(),
|
||||
subType: z.string(),
|
||||
itemType: z.string(),
|
||||
targetType: z.string(),
|
||||
feeFormType: z.string(),
|
||||
});
|
||||
|
||||
export const FlowCreateTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("flow-create-task"),
|
||||
specificationId: z.string(),
|
||||
formState: z.string(),
|
||||
form: z.record(z.string(), z.string()),
|
||||
details: z.record(z.string(), z.any()),
|
||||
onError: OnErrorSchema.optional(),
|
||||
});
|
||||
|
||||
export const DynamicDelayTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("task-dynamic-delay"),
|
||||
sleepTime: z.union([z.number(), z.string()]).optional(),
|
||||
});
|
||||
|
||||
// 兜底节点:遇到未收录类型时仍保留全部字段
|
||||
export const UnknownTaskSchema = z
|
||||
.object({
|
||||
name: z.string().default("task"),
|
||||
type: z.string(),
|
||||
label: z.string().optional(),
|
||||
desc: z.string().optional(),
|
||||
groupName: z.string().default("trigger"),
|
||||
orderIndex: z.number().default(0),
|
||||
levelIndex: z.array(z.number()).default([0]),
|
||||
status: z.string().default("active"),
|
||||
displayName: z.string().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
// 统一任务节点类型
|
||||
export const WorkflowTaskSchema: z.ZodType<WorkflowTask> = z.union([
|
||||
WebhookTaskSchema,
|
||||
ConditionTaskSchema,
|
||||
EveryTaskSchema,
|
||||
StopTaskSchema,
|
||||
HttpTaskSchema,
|
||||
FlowDetailTaskSchema,
|
||||
CodeTaskSchema,
|
||||
CodeJs2TaskSchema,
|
||||
EkuaibaoDatalinkFilterTaskSchema,
|
||||
EkuaibaoDatalinkCreateTaskSchema,
|
||||
DataConvertTaskSchema,
|
||||
FlowCreateTaskSchema,
|
||||
DynamicDelayTaskSchema,
|
||||
UnknownTaskSchema,
|
||||
]);
|
||||
|
||||
|
||||
export type FilterGroup = z.infer<typeof FilterGroupSchema>;
|
||||
/**
|
||||
* 工作流任务节点统一模型与子节点契约出口
|
||||
* 节点各类型 Schema 与字段已原子化拆分至 ./nodes/ 子目录
|
||||
*/
|
||||
export * from "./nodes/index.js";
|
||||
@@ -0,0 +1,20 @@
|
||||
# 工作流节点原子模型定义(models/nodes)
|
||||
|
||||
本目录将工作流各类型节点的数据模型与 Schema 从原本庞大的单文件按类型原子化拆分,确保各节点具备清晰的强类型边界和独立演进能力。
|
||||
|
||||
## 文件分工
|
||||
|
||||
| 文件 | 节点类型 / 职责 |
|
||||
|---|---|
|
||||
| [common.ts](./common.ts) | 基础任务契约(`BaseTaskSchema`、`WorkflowTask`)、过滤与映射通用 Schema |
|
||||
| [http.ts](./http.ts) | HTTP 请求动作节点(包含 `authId` / `appId` 授权凭证、URL、参数与报文) |
|
||||
| [delay.ts](./delay.ts) | 动态延迟等待节点(`task-dynamic-delay` / `sleepTime`) |
|
||||
| [code.ts](./code.ts) | 脚本代码节点(MVEL `code` / JavaScript `code-js2`) |
|
||||
| [webhook.ts](./webhook.ts) | Webhook 外部触发器节点(`sampleId` / `urlPath`) |
|
||||
| [stop.ts](./stop.ts) | 终止流程控制节点(`stop`) |
|
||||
| [flow.ts](./flow.ts) | 单据操作节点(`flow-detail` 查询详情 / `flow-create-task` 创建单据) |
|
||||
| [datalink.ts](./datalink.ts) | 数据连接台账与转换节点(`ekuaibao-datalink-filter`、`create` 与 `data-convert`) |
|
||||
| [condition.ts](./condition.ts) | 条件分支控制节点工厂(`createConditionTaskSchema`) |
|
||||
| [every.ts](./every.ts) | 依次执行循环控制节点工厂(`createEveryTaskSchema`) |
|
||||
| [unknown.ts](./unknown.ts) | 兜底节点模型(未知节点类型全透传) |
|
||||
| [index.ts](./index.ts) | 实例化递归容器节点、聚合统一 `WorkflowTaskSchema` 并集中导出 |
|
||||
@@ -0,0 +1,19 @@
|
||||
import { z } from "zod";
|
||||
import { BaseTaskSchema, OnErrorSchema } from "./common.js";
|
||||
|
||||
// ── 脚本代码节点 (MVEL / JavaScript) ──────────────────────────────────────────
|
||||
|
||||
export const CodeTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("code"),
|
||||
code: z.string(),
|
||||
}).passthrough();
|
||||
|
||||
export const CodeJs2TaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("code-js2"),
|
||||
code: z.string(),
|
||||
mapping: z.array(z.object({ key: z.string(), value: z.string() })).optional(),
|
||||
onError: OnErrorSchema.optional(),
|
||||
}).passthrough();
|
||||
|
||||
export type CodeTask = z.infer<typeof CodeTaskSchema>;
|
||||
export type CodeJs2Task = z.infer<typeof CodeJs2TaskSchema>;
|
||||
@@ -0,0 +1,57 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// ── 工作流任务节点基础 Schema ─────────────────────────────────────────────────
|
||||
|
||||
export const BaseTaskSchema = z.object({
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
label: z.string(),
|
||||
desc: z.string().optional(),
|
||||
groupName: z.string(),
|
||||
orderIndex: z.number(),
|
||||
levelIndex: z.array(z.number()),
|
||||
status: z.string(),
|
||||
displayName: z.string().optional(),
|
||||
}).passthrough();
|
||||
|
||||
// 任务节点运行时类型(用于递归结构中的类型标注)
|
||||
export interface WorkflowTask {
|
||||
name: string;
|
||||
type: string;
|
||||
label?: string;
|
||||
desc?: string;
|
||||
groupName: string;
|
||||
orderIndex: number;
|
||||
levelIndex: number[];
|
||||
status: string;
|
||||
displayName?: string;
|
||||
tasks?: WorkflowTask[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
// 条件/过滤的递归结构:condition / combineFilters
|
||||
export const FilterConditionSchema = z.object({
|
||||
key: z.string(),
|
||||
value: z.any().optional(),
|
||||
compare: z.string(),
|
||||
});
|
||||
|
||||
export const FilterGroupSchema: z.ZodType<any> = z.lazy(() =>
|
||||
z.object({
|
||||
filters: z.array(z.union([FilterConditionSchema, FilterGroupSchema])),
|
||||
condition: z.string(),
|
||||
})
|
||||
);
|
||||
|
||||
// 字段映射条目的两种形态:只读 key 或 key-value 映射(保留 value 及其余配置项)
|
||||
export const FieldMappingSchema = z.object({
|
||||
key: z.string(),
|
||||
value: z.any().optional(),
|
||||
}).passthrough();
|
||||
|
||||
// 错误处理配置
|
||||
export const OnErrorSchema = z.object({
|
||||
defaultAction: z.string(),
|
||||
});
|
||||
|
||||
export type FilterGroup = z.infer<typeof FilterGroupSchema>;
|
||||
@@ -0,0 +1,15 @@
|
||||
import { z } from "zod";
|
||||
import { BaseTaskSchema, FilterGroupSchema, type WorkflowTask } from "./common.js";
|
||||
|
||||
// ── 条件分支控制节点 ─────────────────────────────────────────────────────────
|
||||
|
||||
export function createConditionTaskSchema(
|
||||
getTaskSchema: () => z.ZodType<WorkflowTask>
|
||||
): z.ZodType<WorkflowTask> {
|
||||
return BaseTaskSchema.extend({
|
||||
type: z.literal("condition"),
|
||||
tasksMaxLevel: z.number(),
|
||||
combineFilters: FilterGroupSchema,
|
||||
tasks: z.lazy(() => z.array(getTaskSchema())),
|
||||
}).passthrough();
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { z } from "zod";
|
||||
import { BaseTaskSchema, FieldMappingSchema, FilterGroupSchema, OnErrorSchema } from "./common.js";
|
||||
|
||||
// ── 数据连接 / 台账与转换节点 ────────────────────────────────────────────────
|
||||
|
||||
export const EkuaibaoDatalinkFilterTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("ekuaibao-datalink-filter"),
|
||||
mode: z.string(),
|
||||
entityId: z.string(),
|
||||
fields: z.array(FieldMappingSchema),
|
||||
filters: z.array(z.any()),
|
||||
selectFields: z.array(z.any()),
|
||||
combineFilters: FilterGroupSchema,
|
||||
orderKey: z.string(),
|
||||
orderMode: z.string(),
|
||||
limitCount: z.string(),
|
||||
onError: OnErrorSchema.optional(),
|
||||
}).passthrough();
|
||||
|
||||
export const EkuaibaoDatalinkCreateTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("ekuaibao-datalink-create"),
|
||||
mode: z.string(),
|
||||
entityId: z.string(),
|
||||
fields: z.array(FieldMappingSchema),
|
||||
filters: z.array(z.any()),
|
||||
combineFilters: FilterGroupSchema,
|
||||
}).passthrough();
|
||||
|
||||
export const DataConvertTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("data-convert"),
|
||||
mode: z.string(),
|
||||
path: z.array(z.string()),
|
||||
fields: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
onError: OnErrorSchema.optional(),
|
||||
subType: z.string(),
|
||||
itemType: z.string(),
|
||||
targetType: z.string(),
|
||||
feeFormType: z.string(),
|
||||
}).passthrough();
|
||||
|
||||
export type EkuaibaoDatalinkFilterTask = z.infer<typeof EkuaibaoDatalinkFilterTaskSchema>;
|
||||
export type EkuaibaoDatalinkCreateTask = z.infer<typeof EkuaibaoDatalinkCreateTaskSchema>;
|
||||
export type DataConvertTask = z.infer<typeof DataConvertTaskSchema>;
|
||||
@@ -0,0 +1,11 @@
|
||||
import { z } from "zod";
|
||||
import { BaseTaskSchema } from "./common.js";
|
||||
|
||||
// ── 延迟等待节点 ─────────────────────────────────────────────────────────────
|
||||
|
||||
export const DynamicDelayTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("task-dynamic-delay"),
|
||||
sleepTime: z.union([z.number(), z.string()]).optional(),
|
||||
}).passthrough();
|
||||
|
||||
export type DynamicDelayTask = z.infer<typeof DynamicDelayTaskSchema>;
|
||||
@@ -0,0 +1,19 @@
|
||||
import { z } from "zod";
|
||||
import { BaseTaskSchema, type WorkflowTask } from "./common.js";
|
||||
|
||||
// ── 依次执行循环控制节点 ─────────────────────────────────────────────────────
|
||||
|
||||
export function createEveryTaskSchema(
|
||||
getTaskSchema: () => z.ZodType<WorkflowTask>
|
||||
): z.ZodType<WorkflowTask> {
|
||||
return BaseTaskSchema.extend({
|
||||
type: z.literal("every"),
|
||||
batch: z.boolean(),
|
||||
batchSize: z.number().optional(),
|
||||
mode: z.string(),
|
||||
list: z.string(),
|
||||
filters: z.array(z.any()),
|
||||
tasksMaxLevel: z.number(),
|
||||
tasks: z.lazy(() => z.array(getTaskSchema())),
|
||||
}).passthrough();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { z } from "zod";
|
||||
import { BaseTaskSchema, OnErrorSchema } from "./common.js";
|
||||
|
||||
// ── 单据相关节点 (详情查询 / 创建单据) ─────────────────────────────────────────
|
||||
|
||||
export const FlowDetailTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("flow-detail"),
|
||||
specificationId: z.string(),
|
||||
mapping: z.union([
|
||||
z.boolean(),
|
||||
z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
]),
|
||||
flowCode: z.string(),
|
||||
}).passthrough();
|
||||
|
||||
export const FlowCreateTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("flow-create-task"),
|
||||
specificationId: z.string(),
|
||||
formState: z.string(),
|
||||
form: z.record(z.string(), z.string()),
|
||||
details: z.record(z.string(), z.any()),
|
||||
onError: OnErrorSchema.optional(),
|
||||
}).passthrough();
|
||||
|
||||
export type FlowDetailTask = z.infer<typeof FlowDetailTaskSchema>;
|
||||
export type FlowCreateTask = z.infer<typeof FlowCreateTaskSchema>;
|
||||
@@ -0,0 +1,20 @@
|
||||
import { z } from "zod";
|
||||
import { BaseTaskSchema } from "./common.js";
|
||||
|
||||
// ── HTTP 请求动作节点 ─────────────────────────────────────────────────────────
|
||||
|
||||
export const HttpTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("http"),
|
||||
method: z.string(),
|
||||
url: z.string(),
|
||||
bodyType: z.string().optional(),
|
||||
bodyRaw: z.record(z.string(), z.any()).optional(),
|
||||
header: z.array(z.any()),
|
||||
params: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
successCode: z.array(z.string()),
|
||||
sampleData: z.record(z.string(), z.any()).optional(),
|
||||
authId: z.union([z.number(), z.string()]).optional(),
|
||||
appId: z.union([z.number(), z.string()]).optional(),
|
||||
}).passthrough();
|
||||
|
||||
export type HttpTask = z.infer<typeof HttpTaskSchema>;
|
||||
@@ -0,0 +1,51 @@
|
||||
import { z } from "zod";
|
||||
import type { WorkflowTask } from "./common.js";
|
||||
import { createConditionTaskSchema } from "./condition.js";
|
||||
import { createEveryTaskSchema } from "./every.js";
|
||||
import { WebhookTaskSchema } from "./webhook.js";
|
||||
import { StopTaskSchema } from "./stop.js";
|
||||
import { HttpTaskSchema } from "./http.js";
|
||||
import { FlowDetailTaskSchema, FlowCreateTaskSchema } from "./flow.js";
|
||||
import { CodeTaskSchema, CodeJs2TaskSchema } from "./code.js";
|
||||
import {
|
||||
EkuaibaoDatalinkFilterTaskSchema,
|
||||
EkuaibaoDatalinkCreateTaskSchema,
|
||||
DataConvertTaskSchema,
|
||||
} from "./datalink.js";
|
||||
import { DynamicDelayTaskSchema } from "./delay.js";
|
||||
import { UnknownTaskSchema } from "./unknown.js";
|
||||
|
||||
// 导出所有基础与通用类型
|
||||
export * from "./common.js";
|
||||
export * from "./http.js";
|
||||
export * from "./delay.js";
|
||||
export * from "./code.js";
|
||||
export * from "./webhook.js";
|
||||
export * from "./stop.js";
|
||||
export * from "./flow.js";
|
||||
export * from "./datalink.js";
|
||||
export * from "./condition.js";
|
||||
export * from "./every.js";
|
||||
export * from "./unknown.js";
|
||||
|
||||
// 递归容器节点 Schema 实例化
|
||||
export const ConditionTaskSchema: z.ZodType<WorkflowTask> = createConditionTaskSchema(() => WorkflowTaskSchema);
|
||||
export const EveryTaskSchema: z.ZodType<WorkflowTask> = createEveryTaskSchema(() => WorkflowTaskSchema);
|
||||
|
||||
// 统一任务节点联合 Schema
|
||||
export const WorkflowTaskSchema: z.ZodType<WorkflowTask> = z.union([
|
||||
WebhookTaskSchema,
|
||||
ConditionTaskSchema,
|
||||
EveryTaskSchema,
|
||||
StopTaskSchema,
|
||||
HttpTaskSchema,
|
||||
FlowDetailTaskSchema,
|
||||
CodeTaskSchema,
|
||||
CodeJs2TaskSchema,
|
||||
EkuaibaoDatalinkFilterTaskSchema,
|
||||
EkuaibaoDatalinkCreateTaskSchema,
|
||||
DataConvertTaskSchema,
|
||||
FlowCreateTaskSchema,
|
||||
DynamicDelayTaskSchema,
|
||||
UnknownTaskSchema,
|
||||
]);
|
||||
@@ -0,0 +1,10 @@
|
||||
import { z } from "zod";
|
||||
import { BaseTaskSchema } from "./common.js";
|
||||
|
||||
// ── 终止流程节点 ─────────────────────────────────────────────────────────────
|
||||
|
||||
export const StopTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("stop"),
|
||||
}).passthrough();
|
||||
|
||||
export type StopTask = z.infer<typeof StopTaskSchema>;
|
||||
@@ -0,0 +1,19 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// ── 兜底节点:遇到未收录类型时仍保留全部字段 ─────────────────────────────────────
|
||||
|
||||
export const UnknownTaskSchema = z
|
||||
.object({
|
||||
name: z.string().default("task"),
|
||||
type: z.string(),
|
||||
label: z.string().optional(),
|
||||
desc: z.string().optional(),
|
||||
groupName: z.string().default("trigger"),
|
||||
orderIndex: z.number().default(0),
|
||||
levelIndex: z.array(z.number()).default([0]),
|
||||
status: z.string().default("active"),
|
||||
displayName: z.string().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export type UnknownTask = z.infer<typeof UnknownTaskSchema>;
|
||||
@@ -0,0 +1,13 @@
|
||||
import { z } from "zod";
|
||||
import { BaseTaskSchema } from "./common.js";
|
||||
|
||||
// ── Webhook 触发器节点 ────────────────────────────────────────────────────────
|
||||
|
||||
export const WebhookTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("webhook"),
|
||||
sampleId: z.string(),
|
||||
params: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
urlPath: z.string(),
|
||||
}).passthrough();
|
||||
|
||||
export type WebhookTask = z.infer<typeof WebhookTaskSchema>;
|
||||
Reference in new issue
Block a user