@logicflow/engine 0.0.10 → 0.0.11-beta.0
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 +2 -5
- package/cjs/EventEmitter.js +70 -0
- package/cjs/FlowModel.js +277 -0
- package/cjs/Scheduler.js +252 -0
- package/{lib/constant/logCode.js → cjs/constant/LogCode.js} +13 -16
- package/{lib/constant/index.js → cjs/constant/constant.js} +3 -4
- package/cjs/expression/browserVm.js +81 -0
- package/cjs/expression/index.js +57 -0
- package/cjs/index.js +210 -0
- package/cjs/nodes/BaseNode.js +252 -0
- package/cjs/nodes/StartNode.js +27 -0
- package/cjs/nodes/TaskNode.js +27 -0
- package/cjs/recorder/index.js +168 -0
- package/cjs/util/ID.js +16 -0
- package/cjs/util/global.js +32 -0
- package/{lib/utils → cjs/util}/storage.js +17 -18
- package/es/EventEmitter.d.ts +4 -34
- package/es/EventEmitter.js +48 -70
- package/es/FlowModel.d.ts +73 -75
- package/es/FlowModel.js +173 -130
- package/es/Scheduler.d.ts +34 -50
- package/es/Scheduler.js +209 -134
- package/es/constant/LogCode.js +28 -0
- package/es/constant/{index.js → constant.js} +7 -8
- package/es/expression/browserVm.d.ts +4 -0
- package/es/expression/browserVm.js +76 -0
- package/es/expression/index.d.ts +1 -1
- package/es/expression/index.js +53 -16
- package/es/index.d.ts +38 -135
- package/es/index.js +144 -92
- package/es/nodes/BaseNode.d.ts +110 -0
- package/es/nodes/BaseNode.js +250 -0
- package/es/nodes/{start.d.ts → StartNode.d.ts} +2 -3
- package/es/nodes/StartNode.js +25 -0
- package/es/nodes/{task.d.ts → TaskNode.d.ts} +2 -3
- package/es/nodes/TaskNode.js +25 -0
- package/es/recorder/index.d.ts +10 -36
- package/es/recorder/index.js +135 -82
- package/es/util/ID.js +13 -0
- package/es/util/global.d.ts +5 -0
- package/es/util/global.js +26 -0
- package/es/{utils → util}/storage.js +16 -17
- package/lib/main.js +1 -0
- package/package.json +71 -30
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/es/EventEmitter.js.map +0 -1
- package/es/FlowModel.js.map +0 -1
- package/es/Scheduler.js.map +0 -1
- package/es/constant/index.js.map +0 -1
- package/es/constant/logCode.js +0 -29
- package/es/constant/logCode.js.map +0 -1
- package/es/expression/brewserVm.d.ts +0 -2
- package/es/expression/brewserVm.js +0 -30
- package/es/expression/brewserVm.js.map +0 -1
- package/es/expression/index.js.map +0 -1
- package/es/expression/nodeVm.d.ts +0 -4
- package/es/expression/nodeVm.js +0 -10
- package/es/expression/nodeVm.js.map +0 -1
- package/es/index.js.map +0 -1
- package/es/nodes/base.d.ts +0 -108
- package/es/nodes/base.js +0 -149
- package/es/nodes/base.js.map +0 -1
- package/es/nodes/index.d.ts +0 -3
- package/es/nodes/index.js +0 -4
- package/es/nodes/index.js.map +0 -1
- package/es/nodes/start.js +0 -11
- package/es/nodes/start.js.map +0 -1
- package/es/nodes/task.js +0 -11
- package/es/nodes/task.js.map +0 -1
- package/es/platform/browser/browserVm.d.ts +0 -4
- package/es/platform/browser/browserVm.js +0 -44
- package/es/platform/browser/browserVm.js.map +0 -1
- package/es/platform/browser/index.d.ts +0 -4
- package/es/platform/browser/index.js +0 -23
- package/es/platform/browser/index.js.map +0 -1
- package/es/platform/index.d.ts +0 -1
- package/es/platform/index.js +0 -2
- package/es/platform/index.js.map +0 -1
- package/es/platform/node/index.d.ts +0 -4
- package/es/platform/node/index.js +0 -23
- package/es/platform/node/index.js.map +0 -1
- package/es/platform/node/nodeVm.d.ts +0 -1
- package/es/platform/node/nodeVm.js +0 -9
- package/es/platform/node/nodeVm.js.map +0 -1
- package/es/recorder/index.js.map +0 -1
- package/es/utils/global.d.ts +0 -5
- package/es/utils/global.js +0 -27
- package/es/utils/global.js.map +0 -1
- package/es/utils/id.js +0 -14
- package/es/utils/id.js.map +0 -1
- package/es/utils/index.d.ts +0 -4
- package/es/utils/index.js +0 -5
- package/es/utils/index.js.map +0 -1
- package/es/utils/storage.js.map +0 -1
- package/lib/EventEmitter.d.ts +0 -37
- package/lib/EventEmitter.js +0 -94
- package/lib/EventEmitter.js.map +0 -1
- package/lib/FlowModel.d.ts +0 -146
- package/lib/FlowModel.js +0 -236
- package/lib/FlowModel.js.map +0 -1
- package/lib/Scheduler.d.ts +0 -78
- package/lib/Scheduler.js +0 -179
- package/lib/Scheduler.js.map +0 -1
- package/lib/constant/index.d.ts +0 -16
- package/lib/constant/index.js.map +0 -1
- package/lib/constant/logCode.d.ts +0 -12
- package/lib/constant/logCode.js.map +0 -1
- package/lib/expression/brewserVm.d.ts +0 -2
- package/lib/expression/brewserVm.js +0 -33
- package/lib/expression/brewserVm.js.map +0 -1
- package/lib/expression/index.d.ts +0 -2
- package/lib/expression/index.js +0 -20
- package/lib/expression/index.js.map +0 -1
- package/lib/expression/nodeVm.d.ts +0 -4
- package/lib/expression/nodeVm.js +0 -13
- package/lib/expression/nodeVm.js.map +0 -1
- package/lib/index.d.ts +0 -157
- package/lib/index.js +0 -159
- package/lib/index.js.map +0 -1
- package/lib/nodes/base.d.ts +0 -108
- package/lib/nodes/base.js +0 -152
- package/lib/nodes/base.js.map +0 -1
- package/lib/nodes/index.d.ts +0 -3
- package/lib/nodes/index.js +0 -7
- package/lib/nodes/index.js.map +0 -1
- package/lib/nodes/start.d.ts +0 -6
- package/lib/nodes/start.js +0 -15
- package/lib/nodes/start.js.map +0 -1
- package/lib/nodes/task.d.ts +0 -6
- package/lib/nodes/task.js +0 -15
- package/lib/nodes/task.js.map +0 -1
- package/lib/platform/browser/browserVm.d.ts +0 -4
- package/lib/platform/browser/browserVm.js +0 -49
- package/lib/platform/browser/browserVm.js.map +0 -1
- package/lib/platform/browser/index.d.ts +0 -4
- package/lib/platform/browser/index.js +0 -28
- package/lib/platform/browser/index.js.map +0 -1
- package/lib/platform/index.d.ts +0 -1
- package/lib/platform/index.js +0 -5
- package/lib/platform/index.js.map +0 -1
- package/lib/platform/node/index.d.ts +0 -4
- package/lib/platform/node/index.js +0 -28
- package/lib/platform/node/index.js.map +0 -1
- package/lib/platform/node/nodeVm.d.ts +0 -1
- package/lib/platform/node/nodeVm.js +0 -13
- package/lib/platform/node/nodeVm.js.map +0 -1
- package/lib/recorder/index.d.ts +0 -46
- package/lib/recorder/index.js +0 -117
- package/lib/recorder/index.js.map +0 -1
- package/lib/utils/global.d.ts +0 -5
- package/lib/utils/global.js +0 -31
- package/lib/utils/global.js.map +0 -1
- package/lib/utils/id.d.ts +0 -3
- package/lib/utils/id.js +0 -20
- package/lib/utils/id.js.map +0 -1
- package/lib/utils/index.d.ts +0 -4
- package/lib/utils/index.js +0 -9
- package/lib/utils/index.js.map +0 -1
- package/lib/utils/storage.d.ts +0 -7
- package/lib/utils/storage.js.map +0 -1
- package/src/EventEmitter.ts +0 -103
- package/src/FlowModel.ts +0 -325
- package/src/Scheduler.ts +0 -244
- package/src/constant/index.ts +0 -23
- package/src/constant/logCode.ts +0 -34
- package/src/expression/brewserVm.ts +0 -36
- package/src/expression/index.ts +0 -17
- package/src/expression/nodeVm.ts +0 -14
- package/src/index.ts +0 -300
- package/src/nodes/base.ts +0 -234
- package/src/nodes/index.ts +0 -3
- package/src/nodes/start.ts +0 -8
- package/src/nodes/task.ts +0 -8
- package/src/platform/browser/browserVm.ts +0 -52
- package/src/platform/browser/index.ts +0 -28
- package/src/platform/index.ts +0 -1
- package/src/platform/node/index.ts +0 -28
- package/src/platform/node/nodeVm.ts +0 -12
- package/src/recorder/index.ts +0 -137
- package/src/typings.d.ts +0 -0
- package/src/utils/global.ts +0 -41
- package/src/utils/id.ts +0 -16
- package/src/utils/index.ts +0 -5
- package/src/utils/storage.ts +0 -55
- /package/es/constant/{logCode.d.ts → LogCode.d.ts} +0 -0
- /package/es/constant/{index.d.ts → constant.d.ts} +0 -0
- /package/es/{utils/id.d.ts → util/ID.d.ts} +0 -0
- /package/es/{utils → util}/storage.d.ts +0 -0
package/es/index.d.ts
CHANGED
|
@@ -1,157 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { ResumeParams, GraphConfigData, EngineConstructorOptions, NextActionParam } from './types.d';
|
|
2
|
+
import FlowModel, { ActionParams } from './FlowModel';
|
|
3
|
+
import StartNode from './nodes/StartNode';
|
|
4
|
+
import TaskNode from './nodes/TaskNode';
|
|
5
|
+
import Recorder from './recorder';
|
|
6
|
+
import { NodeConstructor } from './nodes/BaseNode';
|
|
7
|
+
export default class Engine {
|
|
8
|
+
instanceId: string;
|
|
9
|
+
global: Record<string, any>;
|
|
10
|
+
graphData: GraphConfigData;
|
|
11
|
+
nodeModelMap: Map<string, NodeConstructor>;
|
|
12
|
+
flowModel: FlowModel;
|
|
8
13
|
recorder?: Recorder;
|
|
9
|
-
context
|
|
10
|
-
|
|
11
|
-
constructor(options?: Engine.Options);
|
|
14
|
+
context: Record<string, any>;
|
|
15
|
+
constructor(options?: EngineConstructorOptions);
|
|
12
16
|
/**
|
|
13
17
|
* 注册节点
|
|
14
18
|
* @param nodeConfig { type: 'custom-node', model: NodeClass }
|
|
15
19
|
*/
|
|
16
|
-
register(nodeConfig:
|
|
20
|
+
register(nodeConfig: any): void;
|
|
17
21
|
/**
|
|
18
|
-
* 自定义执行记录的存储,默认浏览器使用 sessionStorage
|
|
19
|
-
*
|
|
20
|
-
* nodejs
|
|
21
|
-
* engine.setCustomRecorder({
|
|
22
|
+
* 自定义执行记录的存储,默认浏览器使用 sessionStorage,nodejs 使用内存存储。
|
|
23
|
+
* 注意:由于执行记录不会主动删除,所以需要自行清理。
|
|
24
|
+
* nodejs环境建议自定义为持久化存储。
|
|
25
|
+
* engine.setCustomRecorder({
|
|
22
26
|
* async addActionRecord(task) {}
|
|
23
27
|
* async getTask(actionId) {}
|
|
24
28
|
* async getExecutionTasks(executionId) {}
|
|
25
29
|
* clear(instanceId) {}
|
|
26
|
-
* }
|
|
27
|
-
* @param recorder
|
|
30
|
+
* });
|
|
28
31
|
*/
|
|
29
32
|
setCustomRecorder(recorder: Recorder): void;
|
|
30
33
|
/**
|
|
31
34
|
* 加载流程图数据
|
|
32
35
|
*/
|
|
33
|
-
load({ graphData, startNodeType, globalData, }:
|
|
36
|
+
load({ graphData, startNodeType, globalData, }: {
|
|
37
|
+
graphData: any;
|
|
38
|
+
startNodeType?: string;
|
|
39
|
+
globalData?: {};
|
|
40
|
+
}): FlowModel;
|
|
34
41
|
/**
|
|
35
|
-
*
|
|
42
|
+
* 执行流程,允许多次调用。
|
|
36
43
|
*/
|
|
37
|
-
execute(
|
|
44
|
+
execute(execParam?: ActionParams): Promise<NextActionParam>;
|
|
38
45
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
46
|
+
* 恢复执行
|
|
47
|
+
* 注意此方法只能恢复节点后面的执行,不能恢复流程其他分支的执行。
|
|
48
|
+
* 同理,中断执行也只能中断节点后面的执行,不会中断其他分支的执行。
|
|
49
|
+
* 在实际项目中,如果存在中断节点,建议流程所有的节点都是排他网关,这样可以保证执行的过程不存在分支。
|
|
42
50
|
*/
|
|
43
|
-
resume(resumeParam:
|
|
51
|
+
resume(resumeParam: ResumeParams): Promise<unknown>;
|
|
44
52
|
getExecutionList(): Promise<any>;
|
|
45
|
-
|
|
46
|
-
* 获取执行任务记录
|
|
47
|
-
* @param executionId
|
|
48
|
-
* @returns
|
|
49
|
-
*/
|
|
50
|
-
getExecutionRecord(executionId: Engine.Key): Promise<Recorder.Info[] | null>;
|
|
53
|
+
getExecutionRecord(executionId: any): Promise<any[]>;
|
|
51
54
|
destroy(): void;
|
|
52
|
-
getGlobalData(): Record<string,
|
|
53
|
-
setGlobalData(data:
|
|
54
|
-
updateGlobalData(data:
|
|
55
|
-
}
|
|
56
|
-
export declare namespace Engine {
|
|
57
|
-
type Point = {
|
|
58
|
-
id?: string;
|
|
59
|
-
x: number;
|
|
60
|
-
y: number;
|
|
61
|
-
[key: string]: unknown;
|
|
62
|
-
};
|
|
63
|
-
type TextConfig = {
|
|
64
|
-
value: string;
|
|
65
|
-
} & Point;
|
|
66
|
-
type NodeData = {
|
|
67
|
-
id: string;
|
|
68
|
-
type: string;
|
|
69
|
-
x?: number;
|
|
70
|
-
y?: number;
|
|
71
|
-
text?: TextConfig | string;
|
|
72
|
-
zIndex?: number;
|
|
73
|
-
properties?: Record<string, unknown>;
|
|
74
|
-
};
|
|
75
|
-
type EdgeData = {
|
|
76
|
-
id: string;
|
|
77
|
-
/**
|
|
78
|
-
* 边的类型,不传默认为lf.setDefaultEdgeType(type)传入的类型。
|
|
79
|
-
* LogicFlow内部默认为polyline
|
|
80
|
-
*/
|
|
81
|
-
type?: string;
|
|
82
|
-
sourceNodeId: string;
|
|
83
|
-
sourceAnchorId?: string;
|
|
84
|
-
targetNodeId: string;
|
|
85
|
-
targetAnchorId?: string;
|
|
86
|
-
startPoint?: {
|
|
87
|
-
x: number;
|
|
88
|
-
y: number;
|
|
89
|
-
};
|
|
90
|
-
endPoint?: {
|
|
91
|
-
x: number;
|
|
92
|
-
y: number;
|
|
93
|
-
};
|
|
94
|
-
text?: {
|
|
95
|
-
x: number;
|
|
96
|
-
y: number;
|
|
97
|
-
value: string;
|
|
98
|
-
} | string;
|
|
99
|
-
pointsList?: Point[];
|
|
100
|
-
zIndex?: number;
|
|
101
|
-
properties?: Record<string, unknown>;
|
|
102
|
-
};
|
|
103
|
-
type GraphConfigData = {
|
|
104
|
-
nodes: NodeData[];
|
|
105
|
-
edges: EdgeData[];
|
|
106
|
-
};
|
|
107
|
-
type LoadGraphParam = {
|
|
108
|
-
graphData: GraphConfigData;
|
|
109
|
-
startNodeType?: string;
|
|
110
|
-
globalData?: Record<string, unknown>;
|
|
111
|
-
};
|
|
112
|
-
type Options = {
|
|
113
|
-
context?: Record<string, unknown>;
|
|
114
|
-
debug?: boolean;
|
|
115
|
-
};
|
|
116
|
-
type Key = string | number;
|
|
117
|
-
type NodeConfig = {
|
|
118
|
-
type: string;
|
|
119
|
-
model: any;
|
|
120
|
-
};
|
|
121
|
-
type NodeParam = {
|
|
122
|
-
executionId: Key;
|
|
123
|
-
nodeId: Key;
|
|
124
|
-
};
|
|
125
|
-
type CommonActionInfo = {
|
|
126
|
-
actionId: Key;
|
|
127
|
-
} & NodeParam;
|
|
128
|
-
type ActionParam = CommonActionInfo;
|
|
129
|
-
type ResumeParam = {
|
|
130
|
-
data?: Record<string, unknown>;
|
|
131
|
-
} & CommonActionInfo;
|
|
132
|
-
type ExecParam = {
|
|
133
|
-
next: (data: NextActionParam) => void;
|
|
134
|
-
} & ActionParam;
|
|
135
|
-
type ExecResumeParam = {
|
|
136
|
-
next: (data: NextActionParam) => void;
|
|
137
|
-
} & ResumeParam;
|
|
138
|
-
type ActionStatus = 'success' | 'error' | 'interrupted' | '';
|
|
139
|
-
type NextActionParam = {
|
|
140
|
-
executionId: Key;
|
|
141
|
-
nodeId: Key;
|
|
142
|
-
actionId: Key;
|
|
143
|
-
nodeType: string;
|
|
144
|
-
outgoing: BaseNode.OutgoingConfig[];
|
|
145
|
-
properties?: Record<string, unknown>;
|
|
146
|
-
detail?: Record<string, unknown>;
|
|
147
|
-
status?: ActionStatus;
|
|
148
|
-
};
|
|
149
|
-
type ActionResult = NextActionParam;
|
|
150
|
-
type NodeExecResult = {
|
|
151
|
-
nodeType: string;
|
|
152
|
-
properties?: Record<string, unknown>;
|
|
153
|
-
} & CommonActionInfo & ActionResult;
|
|
55
|
+
getGlobalData(): Record<string, any>;
|
|
56
|
+
setGlobalData(data: any): void;
|
|
57
|
+
updateGlobalData(data: any): void;
|
|
154
58
|
}
|
|
155
|
-
export
|
|
156
|
-
export {
|
|
157
|
-
export default Engine;
|
|
59
|
+
export { Engine, TaskNode, StartNode, Recorder, };
|
|
60
|
+
export type { ActionParams, };
|
package/es/index.js
CHANGED
|
@@ -1,11 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import FlowModel from './FlowModel';
|
|
49
|
+
import StartNode from './nodes/StartNode';
|
|
50
|
+
import TaskNode from './nodes/TaskNode';
|
|
51
|
+
import Recorder from './recorder';
|
|
52
|
+
import { createEngineId } from './util/ID';
|
|
53
|
+
var Engine = /** @class */ (function () {
|
|
54
|
+
function Engine(options) {
|
|
9
55
|
this.nodeModelMap = new Map();
|
|
10
56
|
this.instanceId = createEngineId();
|
|
11
57
|
if (options === null || options === void 0 ? void 0 : options.debug) {
|
|
@@ -13,7 +59,6 @@ export class Engine {
|
|
|
13
59
|
instanceId: this.instanceId,
|
|
14
60
|
});
|
|
15
61
|
}
|
|
16
|
-
// 默认注册节点 register default nodes
|
|
17
62
|
this.register({
|
|
18
63
|
type: StartNode.nodeTypeName,
|
|
19
64
|
model: StartNode,
|
|
@@ -28,125 +73,132 @@ export class Engine {
|
|
|
28
73
|
* 注册节点
|
|
29
74
|
* @param nodeConfig { type: 'custom-node', model: NodeClass }
|
|
30
75
|
*/
|
|
31
|
-
register(nodeConfig) {
|
|
76
|
+
Engine.prototype.register = function (nodeConfig) {
|
|
32
77
|
this.nodeModelMap.set(nodeConfig.type, nodeConfig.model);
|
|
33
|
-
}
|
|
78
|
+
};
|
|
34
79
|
/**
|
|
35
|
-
* 自定义执行记录的存储,默认浏览器使用 sessionStorage
|
|
36
|
-
*
|
|
37
|
-
* nodejs
|
|
38
|
-
* engine.setCustomRecorder({
|
|
80
|
+
* 自定义执行记录的存储,默认浏览器使用 sessionStorage,nodejs 使用内存存储。
|
|
81
|
+
* 注意:由于执行记录不会主动删除,所以需要自行清理。
|
|
82
|
+
* nodejs环境建议自定义为持久化存储。
|
|
83
|
+
* engine.setCustomRecorder({
|
|
39
84
|
* async addActionRecord(task) {}
|
|
40
85
|
* async getTask(actionId) {}
|
|
41
86
|
* async getExecutionTasks(executionId) {}
|
|
42
87
|
* clear(instanceId) {}
|
|
43
|
-
* }
|
|
44
|
-
* @param recorder
|
|
88
|
+
* });
|
|
45
89
|
*/
|
|
46
|
-
setCustomRecorder(recorder) {
|
|
90
|
+
Engine.prototype.setCustomRecorder = function (recorder) {
|
|
47
91
|
this.recorder = recorder;
|
|
48
|
-
}
|
|
92
|
+
};
|
|
49
93
|
/**
|
|
50
94
|
* 加载流程图数据
|
|
51
95
|
*/
|
|
52
|
-
load
|
|
53
|
-
|
|
54
|
-
|
|
96
|
+
Engine.prototype.load = function (_a) {
|
|
97
|
+
var graphData = _a.graphData, _b = _a.startNodeType, startNodeType = _b === void 0 ? 'StartNode' : _b, _c = _a.globalData, globalData = _c === void 0 ? {} : _c;
|
|
98
|
+
this.flowModel = new FlowModel({
|
|
55
99
|
nodeModelMap: this.nodeModelMap,
|
|
56
100
|
recorder: this.recorder,
|
|
57
101
|
context: this.context,
|
|
58
|
-
globalData,
|
|
59
|
-
startNodeType,
|
|
102
|
+
globalData: globalData,
|
|
103
|
+
startNodeType: startNodeType,
|
|
60
104
|
});
|
|
61
|
-
flowModel.load(graphData);
|
|
62
|
-
this.flowModel
|
|
63
|
-
|
|
64
|
-
}
|
|
105
|
+
this.flowModel.load(graphData);
|
|
106
|
+
return this.flowModel;
|
|
107
|
+
};
|
|
65
108
|
/**
|
|
66
|
-
*
|
|
109
|
+
* 执行流程,允许多次调用。
|
|
67
110
|
*/
|
|
68
|
-
execute(
|
|
69
|
-
return __awaiter(this, void 0, void 0, function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
111
|
+
Engine.prototype.execute = function (execParam) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
+
var _this = this;
|
|
114
|
+
return __generator(this, function (_a) {
|
|
115
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
116
|
+
if (!execParam) {
|
|
117
|
+
execParam = {};
|
|
118
|
+
}
|
|
119
|
+
_this.flowModel.execute(__assign(__assign({}, execParam), { callback: function (result) {
|
|
120
|
+
resolve(result);
|
|
121
|
+
}, onError: function (error) {
|
|
122
|
+
reject(error);
|
|
123
|
+
} }));
|
|
124
|
+
})];
|
|
81
125
|
});
|
|
82
126
|
});
|
|
83
|
-
}
|
|
127
|
+
};
|
|
84
128
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
129
|
+
* 恢复执行
|
|
130
|
+
* 注意此方法只能恢复节点后面的执行,不能恢复流程其他分支的执行。
|
|
131
|
+
* 同理,中断执行也只能中断节点后面的执行,不会中断其他分支的执行。
|
|
132
|
+
* 在实际项目中,如果存在中断节点,建议流程所有的节点都是排他网关,这样可以保证执行的过程不存在分支。
|
|
88
133
|
*/
|
|
89
|
-
resume(resumeParam) {
|
|
90
|
-
return __awaiter(this, void 0, void 0, function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
134
|
+
Engine.prototype.resume = function (resumeParam) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
var _this = this;
|
|
137
|
+
return __generator(this, function (_a) {
|
|
138
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
139
|
+
_this.flowModel.resume(__assign(__assign({}, resumeParam), { callback: function (result) {
|
|
140
|
+
resolve(result);
|
|
141
|
+
}, onError: function (error) {
|
|
142
|
+
reject(error);
|
|
143
|
+
} }));
|
|
144
|
+
})];
|
|
98
145
|
});
|
|
99
146
|
});
|
|
100
|
-
}
|
|
101
|
-
getExecutionList() {
|
|
147
|
+
};
|
|
148
|
+
Engine.prototype.getExecutionList = function () {
|
|
102
149
|
var _a;
|
|
103
|
-
return __awaiter(this, void 0, void 0, function
|
|
104
|
-
|
|
150
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
+
var executionIds;
|
|
152
|
+
return __generator(this, function (_b) {
|
|
153
|
+
switch (_b.label) {
|
|
154
|
+
case 0: return [4 /*yield*/, ((_a = this.recorder) === null || _a === void 0 ? void 0 : _a.getExecutionList())];
|
|
155
|
+
case 1:
|
|
156
|
+
executionIds = _b.sent();
|
|
157
|
+
return [2 /*return*/, executionIds];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
105
160
|
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
* 获取执行任务记录
|
|
109
|
-
* @param executionId
|
|
110
|
-
* @returns
|
|
111
|
-
*/
|
|
112
|
-
getExecutionRecord(executionId) {
|
|
161
|
+
};
|
|
162
|
+
Engine.prototype.getExecutionRecord = function (executionId) {
|
|
113
163
|
var _a, _b;
|
|
114
|
-
return __awaiter(this, void 0, void 0, function
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
164
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
165
|
+
var tasks, records, i;
|
|
166
|
+
return __generator(this, function (_c) {
|
|
167
|
+
switch (_c.label) {
|
|
168
|
+
case 0: return [4 /*yield*/, ((_a = this.recorder) === null || _a === void 0 ? void 0 : _a.getExecutionActions(executionId))];
|
|
169
|
+
case 1:
|
|
170
|
+
tasks = _c.sent();
|
|
171
|
+
if (!tasks) {
|
|
172
|
+
return [2 /*return*/, null];
|
|
173
|
+
}
|
|
174
|
+
records = [];
|
|
175
|
+
for (i = 0; i < tasks.length; i++) {
|
|
176
|
+
records.push((_b = this.recorder) === null || _b === void 0 ? void 0 : _b.getActionRecord(tasks[i]));
|
|
177
|
+
}
|
|
178
|
+
return [2 /*return*/, Promise.all(records)];
|
|
125
179
|
}
|
|
126
|
-
}
|
|
127
|
-
return Promise.all(records);
|
|
180
|
+
});
|
|
128
181
|
});
|
|
129
|
-
}
|
|
130
|
-
destroy() {
|
|
182
|
+
};
|
|
183
|
+
Engine.prototype.destroy = function () {
|
|
131
184
|
var _a;
|
|
132
185
|
(_a = this.recorder) === null || _a === void 0 ? void 0 : _a.clear();
|
|
133
|
-
}
|
|
134
|
-
getGlobalData() {
|
|
186
|
+
};
|
|
187
|
+
Engine.prototype.getGlobalData = function () {
|
|
135
188
|
var _a;
|
|
136
189
|
return (_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.globalData;
|
|
137
|
-
}
|
|
138
|
-
setGlobalData(data) {
|
|
190
|
+
};
|
|
191
|
+
Engine.prototype.setGlobalData = function (data) {
|
|
139
192
|
if (this.flowModel) {
|
|
140
193
|
this.flowModel.globalData = data;
|
|
141
194
|
}
|
|
142
|
-
}
|
|
143
|
-
updateGlobalData(data) {
|
|
195
|
+
};
|
|
196
|
+
Engine.prototype.updateGlobalData = function (data) {
|
|
144
197
|
if (this.flowModel) {
|
|
145
198
|
Object.assign(this.flowModel.globalData, data);
|
|
146
199
|
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
export { BaseNode, StartNode, TaskNode, Recorder };
|
|
200
|
+
};
|
|
201
|
+
return Engine;
|
|
202
|
+
}());
|
|
151
203
|
export default Engine;
|
|
152
|
-
|
|
204
|
+
export { Engine, TaskNode, StartNode, Recorder, };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { NextActionParam, ActionResult, ExecResumeParams, ExecParams, OutgoingConfig } from '../types.d';
|
|
2
|
+
export interface BaseNodeInterface {
|
|
3
|
+
outgoing: Record<string, any>[];
|
|
4
|
+
incoming: Record<string, any>[];
|
|
5
|
+
nodeId: string;
|
|
6
|
+
type: string;
|
|
7
|
+
readonly baseType: string;
|
|
8
|
+
execute(actionParam: any): Promise<NextActionParam>;
|
|
9
|
+
}
|
|
10
|
+
export declare type NodeConstructor = {
|
|
11
|
+
new (config: {
|
|
12
|
+
nodeConfig: NodeConfig;
|
|
13
|
+
context: Record<string, any>;
|
|
14
|
+
globalData: Record<string, any>;
|
|
15
|
+
}): BaseNode;
|
|
16
|
+
action(params: {
|
|
17
|
+
executionId: string;
|
|
18
|
+
actionId: string;
|
|
19
|
+
nodeId: string;
|
|
20
|
+
}): Promise<NextActionParam>;
|
|
21
|
+
onResume(params: {
|
|
22
|
+
executionId: string;
|
|
23
|
+
actionId: string;
|
|
24
|
+
nodeId: string;
|
|
25
|
+
data?: Record<string, any>;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
export declare type IncomingConfig = {
|
|
29
|
+
id: string;
|
|
30
|
+
properties?: Record<string, any>;
|
|
31
|
+
source: string;
|
|
32
|
+
};
|
|
33
|
+
export declare type NodeConfig = {
|
|
34
|
+
id: string;
|
|
35
|
+
type: string;
|
|
36
|
+
properties?: Record<string, any>;
|
|
37
|
+
incoming: IncomingConfig[];
|
|
38
|
+
outgoing: OutgoingConfig[];
|
|
39
|
+
};
|
|
40
|
+
export default class BaseNode implements BaseNodeInterface {
|
|
41
|
+
static nodeTypeName: string;
|
|
42
|
+
/**
|
|
43
|
+
* 节点的出边
|
|
44
|
+
*/
|
|
45
|
+
outgoing: OutgoingConfig[];
|
|
46
|
+
/**
|
|
47
|
+
* 节点的入边
|
|
48
|
+
*/
|
|
49
|
+
incoming: IncomingConfig[];
|
|
50
|
+
/**
|
|
51
|
+
* 节点的属性
|
|
52
|
+
*/
|
|
53
|
+
properties?: Record<string, any>;
|
|
54
|
+
nodeId: string;
|
|
55
|
+
type: string;
|
|
56
|
+
/**
|
|
57
|
+
* 节点的上下文,是调用流程时传入的上下文
|
|
58
|
+
*/
|
|
59
|
+
context: Record<string, any>;
|
|
60
|
+
/**
|
|
61
|
+
* 节点的全局数据,是调用流程时传入的全局数据。
|
|
62
|
+
* 在计算表达式时,即基于全局数据进行计算。
|
|
63
|
+
*/
|
|
64
|
+
globalData: Record<string, any>;
|
|
65
|
+
readonly baseType: string;
|
|
66
|
+
constructor({ nodeConfig, context, globalData }: {
|
|
67
|
+
nodeConfig: any;
|
|
68
|
+
context: any;
|
|
69
|
+
globalData: any;
|
|
70
|
+
});
|
|
71
|
+
/**
|
|
72
|
+
* 节点的每一次执行都会生成一个唯一的actionId
|
|
73
|
+
*/
|
|
74
|
+
execute(params: ExecParams): Promise<NextActionParam>;
|
|
75
|
+
/**
|
|
76
|
+
* 节点在执行中断后,可以通过resume方法恢复执行。
|
|
77
|
+
* 自定义节点时不建议重写此方法
|
|
78
|
+
*/
|
|
79
|
+
resume(params: ExecResumeParams): Promise<undefined>;
|
|
80
|
+
private getOutgoing;
|
|
81
|
+
private isPass;
|
|
82
|
+
/**
|
|
83
|
+
* 节点的执行逻辑
|
|
84
|
+
* @overridable 可以自定义节点重写此方法。
|
|
85
|
+
* @param params.executionId 流程执行记录ID
|
|
86
|
+
* @param params.actionId 此节点执行记录ID
|
|
87
|
+
* @param params.nodeId 节点ID
|
|
88
|
+
* @returns 返回下一步的执行参数
|
|
89
|
+
* 当不返回时,表示此节点执行成功,流程会继续执行下一步。
|
|
90
|
+
* 当返回时,返回格式
|
|
91
|
+
*/
|
|
92
|
+
action(params: {
|
|
93
|
+
executionId: string;
|
|
94
|
+
actionId: string;
|
|
95
|
+
nodeId: string;
|
|
96
|
+
}): Promise<ActionResult>;
|
|
97
|
+
/**
|
|
98
|
+
* 节点的重新恢复执行逻辑
|
|
99
|
+
* @overridable 可以自定义节点重写此方法。
|
|
100
|
+
* @param params.executionId 流程执行记录ID
|
|
101
|
+
* @param params.actionId 此节点执行记录ID
|
|
102
|
+
* @param params.nodeId 节点ID
|
|
103
|
+
*/
|
|
104
|
+
onResume(params: {
|
|
105
|
+
executionId: string;
|
|
106
|
+
actionId: string;
|
|
107
|
+
nodeId: string;
|
|
108
|
+
data?: Record<string, any>;
|
|
109
|
+
}): Promise<void>;
|
|
110
|
+
}
|