openxiangda 1.0.25 → 1.0.27
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/README.md +16 -0
- package/lib/cli.js +324 -17
- package/openxiangda-skills/SKILL.md +1 -0
- package/openxiangda-skills/references/automation-v3.md +56 -0
- package/openxiangda-skills/references/openxiangda-api.md +4 -0
- package/openxiangda-skills/references/pages/publish-flow.md +7 -0
- package/openxiangda-skills/references/workflow-v3.md +44 -0
- package/openxiangda-skills/skills/openxiangda-core/SKILL.md +2 -0
- package/openxiangda-skills/skills/openxiangda-workflow-automation/SKILL.md +4 -0
- package/package.json +6 -1
- package/packages/sdk/dist/workflow/index.cjs +230 -0
- package/packages/sdk/dist/workflow/index.cjs.map +1 -0
- package/packages/sdk/dist/workflow/index.d.mts +61 -0
- package/packages/sdk/dist/workflow/index.d.ts +61 -0
- package/packages/sdk/dist/workflow/index.mjs +209 -0
- package/packages/sdk/dist/workflow/index.mjs.map +1 -0
- package/templates/sy-lowcode-app-workspace/scripts/build-js-code.mjs +56 -16
- package/templates/sy-lowcode-app-workspace/tsconfig.js-code-nodes.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openxiangda",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"description": "OpenXiangda CLI, workspace build tools, runtime SDK, and form components.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"bin": {
|
|
@@ -26,6 +26,11 @@
|
|
|
26
26
|
"import": "./packages/sdk/dist/build/index.mjs",
|
|
27
27
|
"require": "./packages/sdk/dist/build/index.cjs"
|
|
28
28
|
},
|
|
29
|
+
"./workflow": {
|
|
30
|
+
"types": "./packages/sdk/dist/workflow/index.d.ts",
|
|
31
|
+
"import": "./packages/sdk/dist/workflow/index.mjs",
|
|
32
|
+
"require": "./packages/sdk/dist/workflow/index.cjs"
|
|
33
|
+
},
|
|
29
34
|
"./tailwind-preset": {
|
|
30
35
|
"types": "./packages/sdk/dist/styles/tailwind-preset.d.ts",
|
|
31
36
|
"import": "./packages/sdk/dist/styles/tailwind-preset.mjs",
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/sdk/src/workflow/index.ts
|
|
21
|
+
var workflow_exports = {};
|
|
22
|
+
__export(workflow_exports, {
|
|
23
|
+
WorkflowBuilder: () => WorkflowBuilder,
|
|
24
|
+
defineWorkflow: () => defineWorkflow
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(workflow_exports);
|
|
27
|
+
function sanitizeId(value) {
|
|
28
|
+
return String(value || "").trim().replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
29
|
+
}
|
|
30
|
+
function createPosition(index) {
|
|
31
|
+
return { x: 400, y: 100 + index * 150 };
|
|
32
|
+
}
|
|
33
|
+
var WorkflowBuilder = class {
|
|
34
|
+
constructor(meta = {}) {
|
|
35
|
+
this.meta = meta;
|
|
36
|
+
this.nodes = [];
|
|
37
|
+
this.edges = [];
|
|
38
|
+
this.flowConfig = {};
|
|
39
|
+
this.globalSettings = {};
|
|
40
|
+
this.data = {
|
|
41
|
+
retrieveSingle: (id, data) => this.node("data_retrieve_single", id, {
|
|
42
|
+
type: "data_retrieve_single",
|
|
43
|
+
label: data.label || "\u83B7\u53D6\u5355\u6761\u6570\u636E",
|
|
44
|
+
filterType: data.filterType || "condition",
|
|
45
|
+
...data
|
|
46
|
+
}),
|
|
47
|
+
retrieveBatch: (id, data) => this.node("data_retrieve_batch", id, {
|
|
48
|
+
type: "data_retrieve_batch",
|
|
49
|
+
label: data.label || "\u83B7\u53D6\u591A\u6761\u6570\u636E",
|
|
50
|
+
filterType: data.filterType || "condition",
|
|
51
|
+
...data
|
|
52
|
+
}),
|
|
53
|
+
create: (id, data) => this.node("data_create", id, {
|
|
54
|
+
type: "data_create",
|
|
55
|
+
label: data.label || "\u65B0\u589E\u6570\u636E",
|
|
56
|
+
insertType: data.insertType || "form",
|
|
57
|
+
assignments: data.assignments || [],
|
|
58
|
+
...data
|
|
59
|
+
}),
|
|
60
|
+
update: (id, data) => this.node("data_update", id, {
|
|
61
|
+
type: "data_update",
|
|
62
|
+
label: data.label || "\u66F4\u65B0\u6570\u636E",
|
|
63
|
+
updateType: data.updateType || "direct_form",
|
|
64
|
+
assignments: data.assignments || [],
|
|
65
|
+
noneOperation: data.noneOperation || "ignored",
|
|
66
|
+
...data
|
|
67
|
+
})
|
|
68
|
+
};
|
|
69
|
+
this.globalSettings = { ...meta.globalSettings || {} };
|
|
70
|
+
}
|
|
71
|
+
start(id = "start", data = {}) {
|
|
72
|
+
return this.node("start", id, { label: "\u5F00\u59CB\u8282\u70B9", ...data });
|
|
73
|
+
}
|
|
74
|
+
end(id = "end", data = {}) {
|
|
75
|
+
return this.node("end", id, { label: "\u7ED3\u675F\u8282\u70B9", ...data });
|
|
76
|
+
}
|
|
77
|
+
approval(id, data) {
|
|
78
|
+
return this.node("approval", id, {
|
|
79
|
+
label: data.label || "\u5BA1\u6279",
|
|
80
|
+
value: data.value || "",
|
|
81
|
+
approverType: data.approverType || "ext_target_approval",
|
|
82
|
+
approvals: data.approvals || [],
|
|
83
|
+
approvalNames: data.approvalNames || [],
|
|
84
|
+
multiApprove: data.multiApprove || "or",
|
|
85
|
+
...data
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
copy(id, data) {
|
|
89
|
+
return this.node("copy", id, {
|
|
90
|
+
label: data.label || "\u6284\u9001",
|
|
91
|
+
value: data.value || "",
|
|
92
|
+
approverType: data.approverType || "ext_target_approval",
|
|
93
|
+
approvals: data.approvals || [],
|
|
94
|
+
approvalNames: data.approvalNames || [],
|
|
95
|
+
...data
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
jsCode(id, data) {
|
|
99
|
+
return this.node("js_code", id, {
|
|
100
|
+
label: data.label || "JS\u4EE3\u7801\u8282\u70B9",
|
|
101
|
+
runtimeMode: "trusted_node",
|
|
102
|
+
sourceType: data.sourceFile ? "file_snapshot" : data.sourceType || "inline",
|
|
103
|
+
timeout: data.timeout || data.timeoutMs || 3e4,
|
|
104
|
+
...data
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
callbackWait(id, data) {
|
|
108
|
+
return this.node("callback_wait", id, {
|
|
109
|
+
type: "callback_wait",
|
|
110
|
+
label: data.label || "\u56DE\u8C03\u7B49\u5F85",
|
|
111
|
+
timeoutSeconds: data.timeoutSeconds || 86400,
|
|
112
|
+
timeoutStrategy: data.timeoutStrategy || "FAIL",
|
|
113
|
+
...data
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
connectorCall(id, data) {
|
|
117
|
+
return this.node("connector_call", id, {
|
|
118
|
+
type: "connector_call",
|
|
119
|
+
label: data.label || "\u8FDE\u63A5\u5668",
|
|
120
|
+
timeout: data.timeout || 3e4,
|
|
121
|
+
...data
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
workNotification(id, data) {
|
|
125
|
+
return this.node("work_notification", id, {
|
|
126
|
+
label: data.label || "\u5DE5\u4F5C\u901A\u77E5",
|
|
127
|
+
buttonText: data.buttonText || "\u67E5\u770B\u8BE6\u60C5",
|
|
128
|
+
linkType: data.linkType || "current_form",
|
|
129
|
+
...data
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
dingtalkCard(id, data) {
|
|
133
|
+
return this.node("dingtalk_card", id, {
|
|
134
|
+
config: {
|
|
135
|
+
type: "dingtalk_card",
|
|
136
|
+
label: data.label || "\u9489\u9489\u6D88\u606F\u5361\u7247",
|
|
137
|
+
sameFieldStrategy: "create",
|
|
138
|
+
...data.config || data
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
condition(id, data) {
|
|
143
|
+
return this.node("condition_branch", id, {
|
|
144
|
+
type: "condition_branch",
|
|
145
|
+
label: data.label || "\u6761\u4EF6\u5206\u652F",
|
|
146
|
+
condition: data.condition || { ruleType: "group", condition: "AND", rules: [] },
|
|
147
|
+
isElse: data.isElse === true,
|
|
148
|
+
priority: data.priority || "1",
|
|
149
|
+
trueNodeId: data.trueNodeId,
|
|
150
|
+
falseNodeId: data.falseNodeId,
|
|
151
|
+
...data
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
node(type, id, data) {
|
|
155
|
+
const nodeId = sanitizeId(id);
|
|
156
|
+
if (!nodeId) throw new Error("workflow node id is required");
|
|
157
|
+
if (this.nodes.some((node) => node.id === nodeId)) {
|
|
158
|
+
throw new Error(`duplicate workflow node id: ${nodeId}`);
|
|
159
|
+
}
|
|
160
|
+
this.nodes.push({
|
|
161
|
+
id: nodeId,
|
|
162
|
+
type,
|
|
163
|
+
data,
|
|
164
|
+
position: createPosition(this.nodes.length)
|
|
165
|
+
});
|
|
166
|
+
if (Array.isArray(data.fieldPermissions)) {
|
|
167
|
+
this.flowConfig[nodeId] = data.fieldPermissions;
|
|
168
|
+
}
|
|
169
|
+
return nodeId;
|
|
170
|
+
}
|
|
171
|
+
edge(source, target, data = {}) {
|
|
172
|
+
const id = data.id || `edge_${source}_${target}`;
|
|
173
|
+
this.edges.push({
|
|
174
|
+
id,
|
|
175
|
+
source,
|
|
176
|
+
target,
|
|
177
|
+
type: data.type || "custom",
|
|
178
|
+
...data.label ? { label: data.label } : {}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
sequence(...refs) {
|
|
182
|
+
for (let index = 0; index < refs.length - 1; index += 1) {
|
|
183
|
+
this.edge(refs[index], refs[index + 1]);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
setFieldPermissions(nodeId, permissions) {
|
|
187
|
+
this.flowConfig[nodeId] = permissions;
|
|
188
|
+
}
|
|
189
|
+
setGlobalSettings(settings) {
|
|
190
|
+
this.globalSettings = { ...this.globalSettings, ...settings };
|
|
191
|
+
}
|
|
192
|
+
compile() {
|
|
193
|
+
return {
|
|
194
|
+
definitionJson: {
|
|
195
|
+
version: "v3",
|
|
196
|
+
nodes: this.nodes,
|
|
197
|
+
edges: this.edges,
|
|
198
|
+
flowConfig: this.flowConfig,
|
|
199
|
+
globalSettings: this.globalSettings
|
|
200
|
+
},
|
|
201
|
+
previewJson: {
|
|
202
|
+
kind: "workflow_code_preview",
|
|
203
|
+
version: "preview_v1",
|
|
204
|
+
sourceMode: "workflow_code_ts",
|
|
205
|
+
steps: this.nodes.map((node) => ({
|
|
206
|
+
id: node.id,
|
|
207
|
+
type: node.type,
|
|
208
|
+
label: node.data?.label || node.id,
|
|
209
|
+
config: node.data
|
|
210
|
+
})),
|
|
211
|
+
edges: this.edges.map((edge) => ({
|
|
212
|
+
source: edge.source,
|
|
213
|
+
target: edge.target,
|
|
214
|
+
label: edge.label
|
|
215
|
+
}))
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
function defineWorkflow(input) {
|
|
221
|
+
return {
|
|
222
|
+
__openxiangdaWorkflow: true,
|
|
223
|
+
compile() {
|
|
224
|
+
const builder = new WorkflowBuilder(input);
|
|
225
|
+
input.build(builder);
|
|
226
|
+
return builder.compile();
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/workflow/index.ts"],"sourcesContent":["export type WorkflowNodeRef = string;\n\nexport interface WorkflowCompileResult {\n definitionJson: {\n version: \"v3\";\n nodes: any[];\n edges: any[];\n flowConfig: Record<string, any[]>;\n globalSettings: Record<string, any>;\n };\n previewJson: {\n kind: \"workflow_code_preview\";\n version: \"preview_v1\";\n steps: any[];\n edges: any[];\n sourceMode: \"workflow_code_ts\";\n };\n}\n\nexport interface WorkflowDefinitionInput {\n name?: string;\n formCode?: string;\n formUuid?: string;\n globalSettings?: Record<string, any>;\n build: (flow: WorkflowBuilder) => void;\n}\n\ntype NodeOptions = Record<string, any>;\n\nfunction sanitizeId(value: string) {\n return String(value || \"\")\n .trim()\n .replace(/[^a-zA-Z0-9_-]/g, \"_\");\n}\n\nfunction createPosition(index: number) {\n return { x: 400, y: 100 + index * 150 };\n}\n\nexport class WorkflowBuilder {\n private nodes: any[] = [];\n private edges: any[] = [];\n private flowConfig: Record<string, any[]> = {};\n private globalSettings: Record<string, any> = {};\n\n constructor(private readonly meta: Omit<WorkflowDefinitionInput, \"build\"> = {}) {\n this.globalSettings = { ...(meta.globalSettings || {}) };\n }\n\n start(id = \"start\", data: NodeOptions = {}): WorkflowNodeRef {\n return this.node(\"start\", id, { label: \"开始节点\", ...data });\n }\n\n end(id = \"end\", data: NodeOptions = {}): WorkflowNodeRef {\n return this.node(\"end\", id, { label: \"结束节点\", ...data });\n }\n\n approval(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"approval\", id, {\n label: data.label || \"审批\",\n value: data.value || \"\",\n approverType: data.approverType || \"ext_target_approval\",\n approvals: data.approvals || [],\n approvalNames: data.approvalNames || [],\n multiApprove: data.multiApprove || \"or\",\n ...data,\n });\n }\n\n copy(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"copy\", id, {\n label: data.label || \"抄送\",\n value: data.value || \"\",\n approverType: data.approverType || \"ext_target_approval\",\n approvals: data.approvals || [],\n approvalNames: data.approvalNames || [],\n ...data,\n });\n }\n\n jsCode(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"js_code\", id, {\n label: data.label || \"JS代码节点\",\n runtimeMode: \"trusted_node\",\n sourceType: data.sourceFile ? \"file_snapshot\" : data.sourceType || \"inline\",\n timeout: data.timeout || data.timeoutMs || 30000,\n ...data,\n });\n }\n\n callbackWait(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"callback_wait\", id, {\n type: \"callback_wait\",\n label: data.label || \"回调等待\",\n timeoutSeconds: data.timeoutSeconds || 86400,\n timeoutStrategy: data.timeoutStrategy || \"FAIL\",\n ...data,\n });\n }\n\n connectorCall(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"connector_call\", id, {\n type: \"connector_call\",\n label: data.label || \"连接器\",\n timeout: data.timeout || 30000,\n ...data,\n });\n }\n\n workNotification(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"work_notification\", id, {\n label: data.label || \"工作通知\",\n buttonText: data.buttonText || \"查看详情\",\n linkType: data.linkType || \"current_form\",\n ...data,\n });\n }\n\n dingtalkCard(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"dingtalk_card\", id, {\n config: {\n type: \"dingtalk_card\",\n label: data.label || \"钉钉消息卡片\",\n sameFieldStrategy: \"create\",\n ...(data.config || data),\n },\n });\n }\n\n condition(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"condition_branch\", id, {\n type: \"condition_branch\",\n label: data.label || \"条件分支\",\n condition: data.condition || { ruleType: \"group\", condition: \"AND\", rules: [] },\n isElse: data.isElse === true,\n priority: data.priority || \"1\",\n trueNodeId: data.trueNodeId,\n falseNodeId: data.falseNodeId,\n ...data,\n });\n }\n\n data = {\n retrieveSingle: (id: string, data: NodeOptions) =>\n this.node(\"data_retrieve_single\", id, {\n type: \"data_retrieve_single\",\n label: data.label || \"获取单条数据\",\n filterType: data.filterType || \"condition\",\n ...data,\n }),\n retrieveBatch: (id: string, data: NodeOptions) =>\n this.node(\"data_retrieve_batch\", id, {\n type: \"data_retrieve_batch\",\n label: data.label || \"获取多条数据\",\n filterType: data.filterType || \"condition\",\n ...data,\n }),\n create: (id: string, data: NodeOptions) =>\n this.node(\"data_create\", id, {\n type: \"data_create\",\n label: data.label || \"新增数据\",\n insertType: data.insertType || \"form\",\n assignments: data.assignments || [],\n ...data,\n }),\n update: (id: string, data: NodeOptions) =>\n this.node(\"data_update\", id, {\n type: \"data_update\",\n label: data.label || \"更新数据\",\n updateType: data.updateType || \"direct_form\",\n assignments: data.assignments || [],\n noneOperation: data.noneOperation || \"ignored\",\n ...data,\n }),\n };\n\n node(type: string, id: string, data: NodeOptions): WorkflowNodeRef {\n const nodeId = sanitizeId(id);\n if (!nodeId) throw new Error(\"workflow node id is required\");\n if (this.nodes.some((node) => node.id === nodeId)) {\n throw new Error(`duplicate workflow node id: ${nodeId}`);\n }\n this.nodes.push({\n id: nodeId,\n type,\n data,\n position: createPosition(this.nodes.length),\n });\n if (Array.isArray(data.fieldPermissions)) {\n this.flowConfig[nodeId] = data.fieldPermissions;\n }\n return nodeId;\n }\n\n edge(source: WorkflowNodeRef, target: WorkflowNodeRef, data: NodeOptions = {}) {\n const id = data.id || `edge_${source}_${target}`;\n this.edges.push({\n id,\n source,\n target,\n type: data.type || \"custom\",\n ...(data.label ? { label: data.label } : {}),\n });\n }\n\n sequence(...refs: WorkflowNodeRef[]) {\n for (let index = 0; index < refs.length - 1; index += 1) {\n this.edge(refs[index], refs[index + 1]);\n }\n }\n\n setFieldPermissions(nodeId: WorkflowNodeRef, permissions: any[]) {\n this.flowConfig[nodeId] = permissions;\n }\n\n setGlobalSettings(settings: Record<string, any>) {\n this.globalSettings = { ...this.globalSettings, ...settings };\n }\n\n compile(): WorkflowCompileResult {\n return {\n definitionJson: {\n version: \"v3\",\n nodes: this.nodes,\n edges: this.edges,\n flowConfig: this.flowConfig,\n globalSettings: this.globalSettings,\n },\n previewJson: {\n kind: \"workflow_code_preview\",\n version: \"preview_v1\",\n sourceMode: \"workflow_code_ts\",\n steps: this.nodes.map((node) => ({\n id: node.id,\n type: node.type,\n label: node.data?.label || node.id,\n config: node.data,\n })),\n edges: this.edges.map((edge) => ({\n source: edge.source,\n target: edge.target,\n label: edge.label,\n })),\n },\n };\n }\n}\n\nexport function defineWorkflow(input: WorkflowDefinitionInput) {\n return {\n __openxiangdaWorkflow: true,\n compile() {\n const builder = new WorkflowBuilder(input);\n input.build(builder);\n return builder.compile();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6BA,SAAS,WAAW,OAAe;AACjC,SAAO,OAAO,SAAS,EAAE,EACtB,KAAK,EACL,QAAQ,mBAAmB,GAAG;AACnC;AAEA,SAAS,eAAe,OAAe;AACrC,SAAO,EAAE,GAAG,KAAK,GAAG,MAAM,QAAQ,IAAI;AACxC;AAEO,IAAM,kBAAN,MAAsB;AAAA,EAM3B,YAA6B,OAA+C,CAAC,GAAG;AAAnD;AAL7B,SAAQ,QAAe,CAAC;AACxB,SAAQ,QAAe,CAAC;AACxB,SAAQ,aAAoC,CAAC;AAC7C,SAAQ,iBAAsC,CAAC;AAmG/C,gBAAO;AAAA,MACL,gBAAgB,CAAC,IAAY,SAC3B,KAAK,KAAK,wBAAwB,IAAI;AAAA,QACpC,MAAM;AAAA,QACN,OAAO,KAAK,SAAS;AAAA,QACrB,YAAY,KAAK,cAAc;AAAA,QAC/B,GAAG;AAAA,MACL,CAAC;AAAA,MACH,eAAe,CAAC,IAAY,SAC1B,KAAK,KAAK,uBAAuB,IAAI;AAAA,QACnC,MAAM;AAAA,QACN,OAA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|
+
type WorkflowNodeRef = string;
|
|
2
|
+
interface WorkflowCompileResult {
|
|
3
|
+
definitionJson: {
|
|
4
|
+
version: "v3";
|
|
5
|
+
nodes: any[];
|
|
6
|
+
edges: any[];
|
|
7
|
+
flowConfig: Record<string, any[]>;
|
|
8
|
+
globalSettings: Record<string, any>;
|
|
9
|
+
};
|
|
10
|
+
previewJson: {
|
|
11
|
+
kind: "workflow_code_preview";
|
|
12
|
+
version: "preview_v1";
|
|
13
|
+
steps: any[];
|
|
14
|
+
edges: any[];
|
|
15
|
+
sourceMode: "workflow_code_ts";
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface WorkflowDefinitionInput {
|
|
19
|
+
name?: string;
|
|
20
|
+
formCode?: string;
|
|
21
|
+
formUuid?: string;
|
|
22
|
+
globalSettings?: Record<string, any>;
|
|
23
|
+
build: (flow: WorkflowBuilder) => void;
|
|
24
|
+
}
|
|
25
|
+
type NodeOptions = Record<string, any>;
|
|
26
|
+
declare class WorkflowBuilder {
|
|
27
|
+
private readonly meta;
|
|
28
|
+
private nodes;
|
|
29
|
+
private edges;
|
|
30
|
+
private flowConfig;
|
|
31
|
+
private globalSettings;
|
|
32
|
+
constructor(meta?: Omit<WorkflowDefinitionInput, "build">);
|
|
33
|
+
start(id?: string, data?: NodeOptions): WorkflowNodeRef;
|
|
34
|
+
end(id?: string, data?: NodeOptions): WorkflowNodeRef;
|
|
35
|
+
approval(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
36
|
+
copy(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
37
|
+
jsCode(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
38
|
+
callbackWait(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
39
|
+
connectorCall(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
40
|
+
workNotification(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
41
|
+
dingtalkCard(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
42
|
+
condition(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
43
|
+
data: {
|
|
44
|
+
retrieveSingle: (id: string, data: NodeOptions) => string;
|
|
45
|
+
retrieveBatch: (id: string, data: NodeOptions) => string;
|
|
46
|
+
create: (id: string, data: NodeOptions) => string;
|
|
47
|
+
update: (id: string, data: NodeOptions) => string;
|
|
48
|
+
};
|
|
49
|
+
node(type: string, id: string, data: NodeOptions): WorkflowNodeRef;
|
|
50
|
+
edge(source: WorkflowNodeRef, target: WorkflowNodeRef, data?: NodeOptions): void;
|
|
51
|
+
sequence(...refs: WorkflowNodeRef[]): void;
|
|
52
|
+
setFieldPermissions(nodeId: WorkflowNodeRef, permissions: any[]): void;
|
|
53
|
+
setGlobalSettings(settings: Record<string, any>): void;
|
|
54
|
+
compile(): WorkflowCompileResult;
|
|
55
|
+
}
|
|
56
|
+
declare function defineWorkflow(input: WorkflowDefinitionInput): {
|
|
57
|
+
__openxiangdaWorkflow: boolean;
|
|
58
|
+
compile(): WorkflowCompileResult;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export { WorkflowBuilder, type WorkflowCompileResult, type WorkflowDefinitionInput, type WorkflowNodeRef, defineWorkflow };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
type WorkflowNodeRef = string;
|
|
2
|
+
interface WorkflowCompileResult {
|
|
3
|
+
definitionJson: {
|
|
4
|
+
version: "v3";
|
|
5
|
+
nodes: any[];
|
|
6
|
+
edges: any[];
|
|
7
|
+
flowConfig: Record<string, any[]>;
|
|
8
|
+
globalSettings: Record<string, any>;
|
|
9
|
+
};
|
|
10
|
+
previewJson: {
|
|
11
|
+
kind: "workflow_code_preview";
|
|
12
|
+
version: "preview_v1";
|
|
13
|
+
steps: any[];
|
|
14
|
+
edges: any[];
|
|
15
|
+
sourceMode: "workflow_code_ts";
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface WorkflowDefinitionInput {
|
|
19
|
+
name?: string;
|
|
20
|
+
formCode?: string;
|
|
21
|
+
formUuid?: string;
|
|
22
|
+
globalSettings?: Record<string, any>;
|
|
23
|
+
build: (flow: WorkflowBuilder) => void;
|
|
24
|
+
}
|
|
25
|
+
type NodeOptions = Record<string, any>;
|
|
26
|
+
declare class WorkflowBuilder {
|
|
27
|
+
private readonly meta;
|
|
28
|
+
private nodes;
|
|
29
|
+
private edges;
|
|
30
|
+
private flowConfig;
|
|
31
|
+
private globalSettings;
|
|
32
|
+
constructor(meta?: Omit<WorkflowDefinitionInput, "build">);
|
|
33
|
+
start(id?: string, data?: NodeOptions): WorkflowNodeRef;
|
|
34
|
+
end(id?: string, data?: NodeOptions): WorkflowNodeRef;
|
|
35
|
+
approval(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
36
|
+
copy(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
37
|
+
jsCode(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
38
|
+
callbackWait(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
39
|
+
connectorCall(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
40
|
+
workNotification(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
41
|
+
dingtalkCard(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
42
|
+
condition(id: string, data: NodeOptions): WorkflowNodeRef;
|
|
43
|
+
data: {
|
|
44
|
+
retrieveSingle: (id: string, data: NodeOptions) => string;
|
|
45
|
+
retrieveBatch: (id: string, data: NodeOptions) => string;
|
|
46
|
+
create: (id: string, data: NodeOptions) => string;
|
|
47
|
+
update: (id: string, data: NodeOptions) => string;
|
|
48
|
+
};
|
|
49
|
+
node(type: string, id: string, data: NodeOptions): WorkflowNodeRef;
|
|
50
|
+
edge(source: WorkflowNodeRef, target: WorkflowNodeRef, data?: NodeOptions): void;
|
|
51
|
+
sequence(...refs: WorkflowNodeRef[]): void;
|
|
52
|
+
setFieldPermissions(nodeId: WorkflowNodeRef, permissions: any[]): void;
|
|
53
|
+
setGlobalSettings(settings: Record<string, any>): void;
|
|
54
|
+
compile(): WorkflowCompileResult;
|
|
55
|
+
}
|
|
56
|
+
declare function defineWorkflow(input: WorkflowDefinitionInput): {
|
|
57
|
+
__openxiangdaWorkflow: boolean;
|
|
58
|
+
compile(): WorkflowCompileResult;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export { WorkflowBuilder, type WorkflowCompileResult, type WorkflowDefinitionInput, type WorkflowNodeRef, defineWorkflow };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// packages/sdk/src/workflow/index.ts
|
|
2
|
+
function sanitizeId(value) {
|
|
3
|
+
return String(value || "").trim().replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4
|
+
}
|
|
5
|
+
function createPosition(index) {
|
|
6
|
+
return { x: 400, y: 100 + index * 150 };
|
|
7
|
+
}
|
|
8
|
+
var WorkflowBuilder = class {
|
|
9
|
+
constructor(meta = {}) {
|
|
10
|
+
this.meta = meta;
|
|
11
|
+
this.nodes = [];
|
|
12
|
+
this.edges = [];
|
|
13
|
+
this.flowConfig = {};
|
|
14
|
+
this.globalSettings = {};
|
|
15
|
+
this.data = {
|
|
16
|
+
retrieveSingle: (id, data) => this.node("data_retrieve_single", id, {
|
|
17
|
+
type: "data_retrieve_single",
|
|
18
|
+
label: data.label || "\u83B7\u53D6\u5355\u6761\u6570\u636E",
|
|
19
|
+
filterType: data.filterType || "condition",
|
|
20
|
+
...data
|
|
21
|
+
}),
|
|
22
|
+
retrieveBatch: (id, data) => this.node("data_retrieve_batch", id, {
|
|
23
|
+
type: "data_retrieve_batch",
|
|
24
|
+
label: data.label || "\u83B7\u53D6\u591A\u6761\u6570\u636E",
|
|
25
|
+
filterType: data.filterType || "condition",
|
|
26
|
+
...data
|
|
27
|
+
}),
|
|
28
|
+
create: (id, data) => this.node("data_create", id, {
|
|
29
|
+
type: "data_create",
|
|
30
|
+
label: data.label || "\u65B0\u589E\u6570\u636E",
|
|
31
|
+
insertType: data.insertType || "form",
|
|
32
|
+
assignments: data.assignments || [],
|
|
33
|
+
...data
|
|
34
|
+
}),
|
|
35
|
+
update: (id, data) => this.node("data_update", id, {
|
|
36
|
+
type: "data_update",
|
|
37
|
+
label: data.label || "\u66F4\u65B0\u6570\u636E",
|
|
38
|
+
updateType: data.updateType || "direct_form",
|
|
39
|
+
assignments: data.assignments || [],
|
|
40
|
+
noneOperation: data.noneOperation || "ignored",
|
|
41
|
+
...data
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
this.globalSettings = { ...meta.globalSettings || {} };
|
|
45
|
+
}
|
|
46
|
+
start(id = "start", data = {}) {
|
|
47
|
+
return this.node("start", id, { label: "\u5F00\u59CB\u8282\u70B9", ...data });
|
|
48
|
+
}
|
|
49
|
+
end(id = "end", data = {}) {
|
|
50
|
+
return this.node("end", id, { label: "\u7ED3\u675F\u8282\u70B9", ...data });
|
|
51
|
+
}
|
|
52
|
+
approval(id, data) {
|
|
53
|
+
return this.node("approval", id, {
|
|
54
|
+
label: data.label || "\u5BA1\u6279",
|
|
55
|
+
value: data.value || "",
|
|
56
|
+
approverType: data.approverType || "ext_target_approval",
|
|
57
|
+
approvals: data.approvals || [],
|
|
58
|
+
approvalNames: data.approvalNames || [],
|
|
59
|
+
multiApprove: data.multiApprove || "or",
|
|
60
|
+
...data
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
copy(id, data) {
|
|
64
|
+
return this.node("copy", id, {
|
|
65
|
+
label: data.label || "\u6284\u9001",
|
|
66
|
+
value: data.value || "",
|
|
67
|
+
approverType: data.approverType || "ext_target_approval",
|
|
68
|
+
approvals: data.approvals || [],
|
|
69
|
+
approvalNames: data.approvalNames || [],
|
|
70
|
+
...data
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
jsCode(id, data) {
|
|
74
|
+
return this.node("js_code", id, {
|
|
75
|
+
label: data.label || "JS\u4EE3\u7801\u8282\u70B9",
|
|
76
|
+
runtimeMode: "trusted_node",
|
|
77
|
+
sourceType: data.sourceFile ? "file_snapshot" : data.sourceType || "inline",
|
|
78
|
+
timeout: data.timeout || data.timeoutMs || 3e4,
|
|
79
|
+
...data
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
callbackWait(id, data) {
|
|
83
|
+
return this.node("callback_wait", id, {
|
|
84
|
+
type: "callback_wait",
|
|
85
|
+
label: data.label || "\u56DE\u8C03\u7B49\u5F85",
|
|
86
|
+
timeoutSeconds: data.timeoutSeconds || 86400,
|
|
87
|
+
timeoutStrategy: data.timeoutStrategy || "FAIL",
|
|
88
|
+
...data
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
connectorCall(id, data) {
|
|
92
|
+
return this.node("connector_call", id, {
|
|
93
|
+
type: "connector_call",
|
|
94
|
+
label: data.label || "\u8FDE\u63A5\u5668",
|
|
95
|
+
timeout: data.timeout || 3e4,
|
|
96
|
+
...data
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
workNotification(id, data) {
|
|
100
|
+
return this.node("work_notification", id, {
|
|
101
|
+
label: data.label || "\u5DE5\u4F5C\u901A\u77E5",
|
|
102
|
+
buttonText: data.buttonText || "\u67E5\u770B\u8BE6\u60C5",
|
|
103
|
+
linkType: data.linkType || "current_form",
|
|
104
|
+
...data
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
dingtalkCard(id, data) {
|
|
108
|
+
return this.node("dingtalk_card", id, {
|
|
109
|
+
config: {
|
|
110
|
+
type: "dingtalk_card",
|
|
111
|
+
label: data.label || "\u9489\u9489\u6D88\u606F\u5361\u7247",
|
|
112
|
+
sameFieldStrategy: "create",
|
|
113
|
+
...data.config || data
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
condition(id, data) {
|
|
118
|
+
return this.node("condition_branch", id, {
|
|
119
|
+
type: "condition_branch",
|
|
120
|
+
label: data.label || "\u6761\u4EF6\u5206\u652F",
|
|
121
|
+
condition: data.condition || { ruleType: "group", condition: "AND", rules: [] },
|
|
122
|
+
isElse: data.isElse === true,
|
|
123
|
+
priority: data.priority || "1",
|
|
124
|
+
trueNodeId: data.trueNodeId,
|
|
125
|
+
falseNodeId: data.falseNodeId,
|
|
126
|
+
...data
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
node(type, id, data) {
|
|
130
|
+
const nodeId = sanitizeId(id);
|
|
131
|
+
if (!nodeId) throw new Error("workflow node id is required");
|
|
132
|
+
if (this.nodes.some((node) => node.id === nodeId)) {
|
|
133
|
+
throw new Error(`duplicate workflow node id: ${nodeId}`);
|
|
134
|
+
}
|
|
135
|
+
this.nodes.push({
|
|
136
|
+
id: nodeId,
|
|
137
|
+
type,
|
|
138
|
+
data,
|
|
139
|
+
position: createPosition(this.nodes.length)
|
|
140
|
+
});
|
|
141
|
+
if (Array.isArray(data.fieldPermissions)) {
|
|
142
|
+
this.flowConfig[nodeId] = data.fieldPermissions;
|
|
143
|
+
}
|
|
144
|
+
return nodeId;
|
|
145
|
+
}
|
|
146
|
+
edge(source, target, data = {}) {
|
|
147
|
+
const id = data.id || `edge_${source}_${target}`;
|
|
148
|
+
this.edges.push({
|
|
149
|
+
id,
|
|
150
|
+
source,
|
|
151
|
+
target,
|
|
152
|
+
type: data.type || "custom",
|
|
153
|
+
...data.label ? { label: data.label } : {}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
sequence(...refs) {
|
|
157
|
+
for (let index = 0; index < refs.length - 1; index += 1) {
|
|
158
|
+
this.edge(refs[index], refs[index + 1]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
setFieldPermissions(nodeId, permissions) {
|
|
162
|
+
this.flowConfig[nodeId] = permissions;
|
|
163
|
+
}
|
|
164
|
+
setGlobalSettings(settings) {
|
|
165
|
+
this.globalSettings = { ...this.globalSettings, ...settings };
|
|
166
|
+
}
|
|
167
|
+
compile() {
|
|
168
|
+
return {
|
|
169
|
+
definitionJson: {
|
|
170
|
+
version: "v3",
|
|
171
|
+
nodes: this.nodes,
|
|
172
|
+
edges: this.edges,
|
|
173
|
+
flowConfig: this.flowConfig,
|
|
174
|
+
globalSettings: this.globalSettings
|
|
175
|
+
},
|
|
176
|
+
previewJson: {
|
|
177
|
+
kind: "workflow_code_preview",
|
|
178
|
+
version: "preview_v1",
|
|
179
|
+
sourceMode: "workflow_code_ts",
|
|
180
|
+
steps: this.nodes.map((node) => ({
|
|
181
|
+
id: node.id,
|
|
182
|
+
type: node.type,
|
|
183
|
+
label: node.data?.label || node.id,
|
|
184
|
+
config: node.data
|
|
185
|
+
})),
|
|
186
|
+
edges: this.edges.map((edge) => ({
|
|
187
|
+
source: edge.source,
|
|
188
|
+
target: edge.target,
|
|
189
|
+
label: edge.label
|
|
190
|
+
}))
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
function defineWorkflow(input) {
|
|
196
|
+
return {
|
|
197
|
+
__openxiangdaWorkflow: true,
|
|
198
|
+
compile() {
|
|
199
|
+
const builder = new WorkflowBuilder(input);
|
|
200
|
+
input.build(builder);
|
|
201
|
+
return builder.compile();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
export {
|
|
206
|
+
WorkflowBuilder,
|
|
207
|
+
defineWorkflow
|
|
208
|
+
};
|
|
209
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/workflow/index.ts"],"sourcesContent":["export type WorkflowNodeRef = string;\n\nexport interface WorkflowCompileResult {\n definitionJson: {\n version: \"v3\";\n nodes: any[];\n edges: any[];\n flowConfig: Record<string, any[]>;\n globalSettings: Record<string, any>;\n };\n previewJson: {\n kind: \"workflow_code_preview\";\n version: \"preview_v1\";\n steps: any[];\n edges: any[];\n sourceMode: \"workflow_code_ts\";\n };\n}\n\nexport interface WorkflowDefinitionInput {\n name?: string;\n formCode?: string;\n formUuid?: string;\n globalSettings?: Record<string, any>;\n build: (flow: WorkflowBuilder) => void;\n}\n\ntype NodeOptions = Record<string, any>;\n\nfunction sanitizeId(value: string) {\n return String(value || \"\")\n .trim()\n .replace(/[^a-zA-Z0-9_-]/g, \"_\");\n}\n\nfunction createPosition(index: number) {\n return { x: 400, y: 100 + index * 150 };\n}\n\nexport class WorkflowBuilder {\n private nodes: any[] = [];\n private edges: any[] = [];\n private flowConfig: Record<string, any[]> = {};\n private globalSettings: Record<string, any> = {};\n\n constructor(private readonly meta: Omit<WorkflowDefinitionInput, \"build\"> = {}) {\n this.globalSettings = { ...(meta.globalSettings || {}) };\n }\n\n start(id = \"start\", data: NodeOptions = {}): WorkflowNodeRef {\n return this.node(\"start\", id, { label: \"开始节点\", ...data });\n }\n\n end(id = \"end\", data: NodeOptions = {}): WorkflowNodeRef {\n return this.node(\"end\", id, { label: \"结束节点\", ...data });\n }\n\n approval(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"approval\", id, {\n label: data.label || \"审批\",\n value: data.value || \"\",\n approverType: data.approverType || \"ext_target_approval\",\n approvals: data.approvals || [],\n approvalNames: data.approvalNames || [],\n multiApprove: data.multiApprove || \"or\",\n ...data,\n });\n }\n\n copy(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"copy\", id, {\n label: data.label || \"抄送\",\n value: data.value || \"\",\n approverType: data.approverType || \"ext_target_approval\",\n approvals: data.approvals || [],\n approvalNames: data.approvalNames || [],\n ...data,\n });\n }\n\n jsCode(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"js_code\", id, {\n label: data.label || \"JS代码节点\",\n runtimeMode: \"trusted_node\",\n sourceType: data.sourceFile ? \"file_snapshot\" : data.sourceType || \"inline\",\n timeout: data.timeout || data.timeoutMs || 30000,\n ...data,\n });\n }\n\n callbackWait(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"callback_wait\", id, {\n type: \"callback_wait\",\n label: data.label || \"回调等待\",\n timeoutSeconds: data.timeoutSeconds || 86400,\n timeoutStrategy: data.timeoutStrategy || \"FAIL\",\n ...data,\n });\n }\n\n connectorCall(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"connector_call\", id, {\n type: \"connector_call\",\n label: data.label || \"连接器\",\n timeout: data.timeout || 30000,\n ...data,\n });\n }\n\n workNotification(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"work_notification\", id, {\n label: data.label || \"工作通知\",\n buttonText: data.buttonText || \"查看详情\",\n linkType: data.linkType || \"current_form\",\n ...data,\n });\n }\n\n dingtalkCard(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"dingtalk_card\", id, {\n config: {\n type: \"dingtalk_card\",\n label: data.label || \"钉钉消息卡片\",\n sameFieldStrategy: \"create\",\n ...(data.config || data),\n },\n });\n }\n\n condition(id: string, data: NodeOptions): WorkflowNodeRef {\n return this.node(\"condition_branch\", id, {\n type: \"condition_branch\",\n label: data.label || \"条件分支\",\n condition: data.condition || { ruleType: \"group\", condition: \"AND\", rules: [] },\n isElse: data.isElse === true,\n priority: data.priority || \"1\",\n trueNodeId: data.trueNodeId,\n falseNodeId: data.falseNodeId,\n ...data,\n });\n }\n\n data = {\n retrieveSingle: (id: string, data: NodeOptions) =>\n this.node(\"data_retrieve_single\", id, {\n type: \"data_retrieve_single\",\n label: data.label || \"获取单条数据\",\n filterType: data.filterType || \"condition\",\n ...data,\n }),\n retrieveBatch: (id: string, data: NodeOptions) =>\n this.node(\"data_retrieve_batch\", id, {\n type: \"data_retrieve_batch\",\n label: data.label || \"获取多条数据\",\n filterType: data.filterType || \"condition\",\n ...data,\n }),\n create: (id: string, data: NodeOptions) =>\n this.node(\"data_create\", id, {\n type: \"data_create\",\n label: data.label || \"新增数据\",\n insertType: data.insertType || \"form\",\n assignments: data.assignments || [],\n ...data,\n }),\n update: (id: string, data: NodeOptions) =>\n this.node(\"data_update\", id, {\n type: \"data_update\",\n label: data.label || \"更新数据\",\n updateType: data.updateType || \"direct_form\",\n assignments: data.assignments || [],\n noneOperation: data.noneOperation || \"ignored\",\n ...data,\n }),\n };\n\n node(type: string, id: string, data: NodeOptions): WorkflowNodeRef {\n const nodeId = sanitizeId(id);\n if (!nodeId) throw new Error(\"workflow node id is required\");\n if (this.nodes.some((node) => node.id === nodeId)) {\n throw new Error(`duplicate workflow node id: ${nodeId}`);\n }\n this.nodes.push({\n id: nodeId,\n type,\n data,\n position: createPosition(this.nodes.length),\n });\n if (Array.isArray(data.fieldPermissions)) {\n this.flowConfig[nodeId] = data.fieldPermissions;\n }\n return nodeId;\n }\n\n edge(source: WorkflowNodeRef, target: WorkflowNodeRef, data: NodeOptions = {}) {\n const id = data.id || `edge_${source}_${target}`;\n this.edges.push({\n id,\n source,\n target,\n type: data.type || \"custom\",\n ...(data.label ? { label: data.label } : {}),\n });\n }\n\n sequence(...refs: WorkflowNodeRef[]) {\n for (let index = 0; index < refs.length - 1; index += 1) {\n this.edge(refs[index], refs[index + 1]);\n }\n }\n\n setFieldPermissions(nodeId: WorkflowNodeRef, permissions: any[]) {\n this.flowConfig[nodeId] = permissions;\n }\n\n setGlobalSettings(settings: Record<string, any>) {\n this.globalSettings = { ...this.globalSettings, ...settings };\n }\n\n compile(): WorkflowCompileResult {\n return {\n definitionJson: {\n version: \"v3\",\n nodes: this.nodes,\n edges: this.edges,\n flowConfig: this.flowConfig,\n globalSettings: this.globalSettings,\n },\n previewJson: {\n kind: \"workflow_code_preview\",\n version: \"preview_v1\",\n sourceMode: \"workflow_code_ts\",\n steps: this.nodes.map((node) => ({\n id: node.id,\n type: node.type,\n label: node.data?.label || node.id,\n config: node.data,\n })),\n edges: this.edges.map((edge) => ({\n source: edge.source,\n target: edge.target,\n label: edge.label,\n })),\n },\n };\n }\n}\n\nexport function defineWorkflow(input: WorkflowDefinitionInput) {\n return {\n __openxiangdaWorkflow: true,\n compile() {\n const builder = new WorkflowBuilder(input);\n input.build(builder);\n return builder.compile();\n },\n };\n}\n"],"mappings":";AA6BA,SAAS,WAAW,OAAe;AACjC,SAAO,OAAO,SAAS,EAAE,EACtB,KAAK,EACL,QAAQ,mBAAmB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