@logicflow/engine 0.0.11-beta.0 → 0.0.12
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 +5 -2
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/es/EventEmitter.d.ts +34 -4
- package/es/EventEmitter.js +70 -48
- package/es/EventEmitter.js.map +1 -0
- package/es/FlowModel.d.ts +75 -73
- package/es/FlowModel.js +130 -173
- package/es/FlowModel.js.map +1 -0
- package/es/Scheduler.d.ts +50 -34
- package/es/Scheduler.js +134 -209
- package/es/Scheduler.js.map +1 -0
- package/es/constant/{constant.js → index.js} +8 -7
- package/es/constant/index.js.map +1 -0
- package/es/constant/logCode.js +29 -0
- package/es/constant/logCode.js.map +1 -0
- package/es/index.d.ts +135 -38
- package/es/index.js +92 -144
- package/es/index.js.map +1 -0
- package/es/nodes/base.d.ts +108 -0
- package/es/nodes/base.js +151 -0
- package/es/nodes/base.js.map +1 -0
- package/es/nodes/index.d.ts +3 -0
- package/es/nodes/index.js +4 -0
- package/es/nodes/index.js.map +1 -0
- package/es/nodes/{StartNode.d.ts → start.d.ts} +3 -2
- package/es/nodes/start.js +11 -0
- package/es/nodes/start.js.map +1 -0
- package/es/nodes/{TaskNode.d.ts → task.d.ts} +3 -2
- package/es/nodes/task.js +11 -0
- package/es/nodes/task.js.map +1 -0
- package/es/platform/browser/browserVm.d.ts +1 -0
- package/es/platform/browser/browserVm.js +66 -0
- package/es/platform/browser/browserVm.js.map +1 -0
- package/es/platform/browser/index.d.ts +4 -0
- package/es/platform/browser/index.js +23 -0
- package/es/platform/browser/index.js.map +1 -0
- package/es/platform/index.d.ts +1 -0
- package/es/platform/index.js +2 -0
- package/es/platform/index.js.map +1 -0
- package/es/platform/node/index.d.ts +4 -0
- package/es/platform/node/index.js +23 -0
- package/es/platform/node/index.js.map +1 -0
- package/es/platform/node/nodeVm.d.ts +1 -0
- package/es/platform/node/nodeVm.js +10 -0
- package/es/platform/node/nodeVm.js.map +1 -0
- package/es/recorder/index.d.ts +36 -10
- package/es/recorder/index.js +82 -135
- package/es/recorder/index.js.map +1 -0
- package/es/utils/global.d.ts +5 -0
- package/es/utils/global.js +27 -0
- package/es/utils/global.js.map +1 -0
- package/es/utils/id.js +14 -0
- package/es/utils/id.js.map +1 -0
- package/es/utils/index.d.ts +4 -0
- package/es/utils/index.js +5 -0
- package/es/utils/index.js.map +1 -0
- package/es/{util → utils}/storage.js +17 -16
- package/es/utils/storage.js.map +1 -0
- package/lib/EventEmitter.d.ts +37 -0
- package/lib/EventEmitter.js +94 -0
- package/lib/EventEmitter.js.map +1 -0
- package/lib/FlowModel.d.ts +146 -0
- package/lib/FlowModel.js +236 -0
- package/lib/FlowModel.js.map +1 -0
- package/lib/Scheduler.d.ts +78 -0
- package/lib/Scheduler.js +179 -0
- package/lib/Scheduler.js.map +1 -0
- package/lib/constant/index.d.ts +16 -0
- package/{cjs/constant/constant.js → lib/constant/index.js} +4 -3
- package/lib/constant/index.js.map +1 -0
- package/lib/constant/logCode.d.ts +12 -0
- package/{cjs/constant/LogCode.js → lib/constant/logCode.js} +16 -13
- package/lib/constant/logCode.js.map +1 -0
- package/lib/index.d.ts +157 -0
- package/lib/index.js +159 -0
- package/lib/index.js.map +1 -0
- package/lib/nodes/base.d.ts +108 -0
- package/lib/nodes/base.js +154 -0
- package/lib/nodes/base.js.map +1 -0
- package/lib/nodes/index.d.ts +3 -0
- package/lib/nodes/index.js +7 -0
- package/lib/nodes/index.js.map +1 -0
- package/lib/nodes/start.d.ts +6 -0
- package/lib/nodes/start.js +15 -0
- package/lib/nodes/start.js.map +1 -0
- package/lib/nodes/task.d.ts +6 -0
- package/lib/nodes/task.js +15 -0
- package/lib/nodes/task.js.map +1 -0
- package/lib/platform/browser/browserVm.d.ts +1 -0
- package/lib/platform/browser/browserVm.js +70 -0
- package/lib/platform/browser/browserVm.js.map +1 -0
- package/lib/platform/browser/index.d.ts +4 -0
- package/lib/platform/browser/index.js +28 -0
- package/lib/platform/browser/index.js.map +1 -0
- package/lib/platform/index.d.ts +1 -0
- package/lib/platform/index.js +5 -0
- package/lib/platform/index.js.map +1 -0
- package/lib/platform/node/index.d.ts +4 -0
- package/lib/platform/node/index.js +28 -0
- package/lib/platform/node/index.js.map +1 -0
- package/lib/platform/node/nodeVm.d.ts +1 -0
- package/lib/platform/node/nodeVm.js +14 -0
- package/lib/platform/node/nodeVm.js.map +1 -0
- package/lib/recorder/index.d.ts +46 -0
- package/lib/recorder/index.js +117 -0
- package/lib/recorder/index.js.map +1 -0
- package/lib/utils/global.d.ts +5 -0
- package/lib/utils/global.js +31 -0
- package/lib/utils/global.js.map +1 -0
- package/lib/utils/id.d.ts +3 -0
- package/lib/utils/id.js +20 -0
- package/lib/utils/id.js.map +1 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +9 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/storage.d.ts +7 -0
- package/{cjs/util → lib/utils}/storage.js +18 -17
- package/lib/utils/storage.js.map +1 -0
- package/package.json +30 -71
- package/src/EventEmitter.ts +103 -0
- package/src/FlowModel.ts +325 -0
- package/src/Scheduler.ts +244 -0
- package/src/constant/index.ts +23 -0
- package/src/constant/logCode.ts +34 -0
- package/src/index.ts +300 -0
- package/src/nodes/base.ts +236 -0
- package/src/nodes/index.ts +3 -0
- package/src/nodes/start.ts +8 -0
- package/src/nodes/task.ts +8 -0
- package/src/platform/browser/browserVm.ts +68 -0
- package/src/platform/browser/index.ts +28 -0
- package/src/platform/index.ts +1 -0
- package/src/platform/node/index.ts +28 -0
- package/src/platform/node/nodeVm.ts +14 -0
- package/src/recorder/index.ts +137 -0
- package/src/typings.d.ts +0 -0
- package/src/utils/global.ts +41 -0
- package/src/utils/id.ts +16 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/storage.ts +55 -0
- package/cjs/EventEmitter.js +0 -70
- package/cjs/FlowModel.js +0 -277
- package/cjs/Scheduler.js +0 -252
- package/cjs/expression/browserVm.js +0 -81
- package/cjs/expression/index.js +0 -57
- package/cjs/index.js +0 -210
- package/cjs/nodes/BaseNode.js +0 -252
- package/cjs/nodes/StartNode.js +0 -27
- package/cjs/nodes/TaskNode.js +0 -27
- package/cjs/recorder/index.js +0 -168
- package/cjs/util/ID.js +0 -16
- package/cjs/util/global.js +0 -32
- package/es/constant/LogCode.js +0 -28
- package/es/expression/browserVm.d.ts +0 -4
- package/es/expression/browserVm.js +0 -76
- package/es/expression/index.d.ts +0 -2
- package/es/expression/index.js +0 -54
- package/es/nodes/BaseNode.d.ts +0 -110
- package/es/nodes/BaseNode.js +0 -250
- package/es/nodes/StartNode.js +0 -25
- package/es/nodes/TaskNode.js +0 -25
- package/es/util/ID.js +0 -13
- package/es/util/global.d.ts +0 -5
- package/es/util/global.js +0 -26
- package/lib/main.js +0 -1
- /package/es/constant/{constant.d.ts → index.d.ts} +0 -0
- /package/es/constant/{LogCode.d.ts → logCode.d.ts} +0 -0
- /package/es/{util/ID.d.ts → utils/id.d.ts} +0 -0
- /package/es/{util → utils}/storage.d.ts +0 -0
package/lib/Scheduler.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Scheduler = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const EventEmitter_1 = tslib_1.__importDefault(require("./EventEmitter"));
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const constant_1 = require("./constant");
|
|
8
|
+
/**
|
|
9
|
+
* 调度器
|
|
10
|
+
* 通过一个队列维护需要执行的节点,一个集合维护正在执行的节点
|
|
11
|
+
*/
|
|
12
|
+
class Scheduler extends EventEmitter_1.default {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
super();
|
|
15
|
+
this.nodeQueueMap = new Map();
|
|
16
|
+
this.actionRunningMap = new Map();
|
|
17
|
+
this.flowModel = config.flowModel;
|
|
18
|
+
this.recorder = config.recorder;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 添加一个任务到队列中。
|
|
22
|
+
* 1. 由流程模型将所有的开始及诶带你添加到队列中
|
|
23
|
+
* 2. 当一个节点执行完成后,将后续的节点添加到队列中
|
|
24
|
+
* @param nodeParam
|
|
25
|
+
*/
|
|
26
|
+
addAction(nodeParam) {
|
|
27
|
+
const { executionId } = nodeParam;
|
|
28
|
+
if (!this.nodeQueueMap.has(executionId)) {
|
|
29
|
+
this.nodeQueueMap.set(executionId, []);
|
|
30
|
+
}
|
|
31
|
+
const currentActionQueue = this.nodeQueueMap.get(executionId);
|
|
32
|
+
if (currentActionQueue) {
|
|
33
|
+
currentActionQueue.push(nodeParam);
|
|
34
|
+
}
|
|
35
|
+
console.log('this.nodeQueueMap--->>>', this.nodeQueueMap);
|
|
36
|
+
}
|
|
37
|
+
pushActionToRunningMap(actionParam) {
|
|
38
|
+
var _a;
|
|
39
|
+
const { executionId, actionId } = actionParam;
|
|
40
|
+
if (!this.actionRunningMap.has(executionId)) {
|
|
41
|
+
const runningMap = new Map();
|
|
42
|
+
this.actionRunningMap.set(executionId, runningMap);
|
|
43
|
+
}
|
|
44
|
+
if (actionId) {
|
|
45
|
+
(_a = this.actionRunningMap.get(executionId)) === null || _a === void 0 ? void 0 : _a.set(actionId, actionParam);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
removeActionFromRunningMap(actionParam) {
|
|
49
|
+
const { executionId, actionId } = actionParam;
|
|
50
|
+
if (!actionId)
|
|
51
|
+
return;
|
|
52
|
+
const runningMap = this.actionRunningMap.get(executionId);
|
|
53
|
+
if (!runningMap)
|
|
54
|
+
return;
|
|
55
|
+
runningMap.delete(actionId);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 为了防止多次添加导致
|
|
59
|
+
* @param actionParam
|
|
60
|
+
*/
|
|
61
|
+
saveActionResult(actionParam) {
|
|
62
|
+
var _a;
|
|
63
|
+
(_a = this.recorder) === null || _a === void 0 ? void 0 : _a.addActionRecord(Object.assign({ timestamp: Date.now() }, actionParam));
|
|
64
|
+
}
|
|
65
|
+
hasRunningAction(executionId) {
|
|
66
|
+
const runningMap = this.actionRunningMap.get(executionId);
|
|
67
|
+
if (!runningMap)
|
|
68
|
+
return false;
|
|
69
|
+
if (runningMap.size === 0) {
|
|
70
|
+
this.actionRunningMap.delete(executionId);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 调度器执行下一个任务
|
|
77
|
+
* 1. 提供给流程模型,用户开始执行第一个任务
|
|
78
|
+
* 2. 内部任务执行完成后,调用此方法继续执行下一个任务
|
|
79
|
+
* 3. 当判断没有可以继续执行的任务后,触发流程结束事件
|
|
80
|
+
* @param runParam
|
|
81
|
+
*/
|
|
82
|
+
run(runParam) {
|
|
83
|
+
const nodeQueue = this.nodeQueueMap.get(runParam.executionId);
|
|
84
|
+
// 将同一个 executionId 当前待执行的节点一起执行
|
|
85
|
+
// 避免出现某一个节点执行时间过长,导致其他节点等待时间过长
|
|
86
|
+
while (nodeQueue === null || nodeQueue === void 0 ? void 0 : nodeQueue.length) {
|
|
87
|
+
const currentNode = nodeQueue.pop();
|
|
88
|
+
const actionId = (0, utils_1.createActionId)();
|
|
89
|
+
const actionParam = Object.assign(Object.assign({}, currentNode), { actionId });
|
|
90
|
+
this.pushActionToRunningMap(actionParam);
|
|
91
|
+
this.exec(actionParam);
|
|
92
|
+
}
|
|
93
|
+
if (!this.hasRunningAction(runParam.executionId)) {
|
|
94
|
+
// 当一个流程在 nodeQueueMap 和 actionRunningMap 中都不存在执行的节点时,说明这个流程已经执行完成。
|
|
95
|
+
this.emit(constant_1.EVENT_INSTANCE_COMPLETE, Object.assign(Object.assign({}, runParam), { status: constant_1.FlowStatus.COMPLETED }));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
next(data) {
|
|
99
|
+
if (data.outgoing && data.outgoing.length > 0) {
|
|
100
|
+
data.outgoing.forEach((item) => {
|
|
101
|
+
if (item.result) {
|
|
102
|
+
this.addAction({
|
|
103
|
+
executionId: data.executionId,
|
|
104
|
+
nodeId: item.target,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
this.saveActionResult(data);
|
|
110
|
+
this.removeActionFromRunningMap(data);
|
|
111
|
+
this.run(data);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 恢复某个任务的执行
|
|
115
|
+
* 可以自定义节点手动实现流程中断,然后通过此方法恢复流程的执行
|
|
116
|
+
* @param resumeParam
|
|
117
|
+
*/
|
|
118
|
+
resume(resumeParam) {
|
|
119
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const { executionId, actionId, nodeId } = resumeParam;
|
|
121
|
+
this.pushActionToRunningMap({
|
|
122
|
+
executionId,
|
|
123
|
+
actionId,
|
|
124
|
+
nodeId,
|
|
125
|
+
});
|
|
126
|
+
const model = this.flowModel.createAction(nodeId);
|
|
127
|
+
yield (model === null || model === void 0 ? void 0 : model.resume(Object.assign(Object.assign({}, resumeParam), { next: this.next.bind(this) })));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// 中断时,触发事件
|
|
131
|
+
interrupted(execResult) {
|
|
132
|
+
this.emit(constant_1.EVENT_INSTANCE_INTERRUPTED, execResult);
|
|
133
|
+
}
|
|
134
|
+
// 报错时,触发事件
|
|
135
|
+
error(execResult) {
|
|
136
|
+
this.emit(constant_1.EVENT_INSTANCE_ERROR, execResult);
|
|
137
|
+
}
|
|
138
|
+
exec(actionParam) {
|
|
139
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const { executionId, actionId, nodeId } = actionParam;
|
|
141
|
+
const model = this.flowModel.createAction(nodeId);
|
|
142
|
+
const execResult = yield (model === null || model === void 0 ? void 0 : model.execute({
|
|
143
|
+
executionId,
|
|
144
|
+
actionId,
|
|
145
|
+
nodeId,
|
|
146
|
+
next: this.next.bind(this),
|
|
147
|
+
}));
|
|
148
|
+
if (execResult) {
|
|
149
|
+
const { nodeType, properties, outgoing, status, detail } = execResult;
|
|
150
|
+
const actionResult = {
|
|
151
|
+
// actionParam
|
|
152
|
+
executionId,
|
|
153
|
+
actionId,
|
|
154
|
+
nodeId,
|
|
155
|
+
// execResult
|
|
156
|
+
nodeType,
|
|
157
|
+
properties,
|
|
158
|
+
outgoing,
|
|
159
|
+
status,
|
|
160
|
+
detail,
|
|
161
|
+
};
|
|
162
|
+
if ((execResult === null || execResult === void 0 ? void 0 : execResult.status) === constant_1.FlowStatus.INTERRUPTED) {
|
|
163
|
+
this.interrupted(execResult);
|
|
164
|
+
this.saveActionResult(actionResult);
|
|
165
|
+
this.removeActionFromRunningMap(actionParam);
|
|
166
|
+
}
|
|
167
|
+
if ((execResult === null || execResult === void 0 ? void 0 : execResult.status) === constant_1.FlowStatus.ERROR) {
|
|
168
|
+
this.error(execResult);
|
|
169
|
+
this.saveActionResult(actionResult);
|
|
170
|
+
this.removeActionFromRunningMap(actionParam);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// TODO: 考虑停下所有的任务
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.Scheduler = Scheduler;
|
|
178
|
+
exports.default = Scheduler;
|
|
179
|
+
//# sourceMappingURL=Scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Scheduler.js","sourceRoot":"","sources":["../src/Scheduler.ts"],"names":[],"mappings":";;;;AAGA,0EAAyC;AACzC,mCAAwC;AACxC,yCAKmB;AAEnB;;;GAGG;AACH,MAAa,SAAU,SAAQ,sBAAY;IAqBzC,YAAY,MAAiC;QAC3C,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAA;QAC7B,IAAI,CAAC,gBAAgB,GAAG,IAA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AA;oBACnC,IAAI,CAAC,0BAA0B,CAAC,WAAW,CAAC,CAAA;iBAC7C;aACF;YACD,kBAAkB;QACpB,CAAC;KAAA;CACF;AAjND,8BAiNC;AAkBD,kBAAe,SAAS,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const BASE_START_NODE = "start";
|
|
2
|
+
export declare const EVENT_INSTANCE_COMPLETE = "instance:complete";
|
|
3
|
+
export declare const EVENT_INSTANCE_INTERRUPTED = "instance:interrupted";
|
|
4
|
+
export declare const EVENT_INSTANCE_ERROR = "instance:error";
|
|
5
|
+
export declare enum FlowStatus {
|
|
6
|
+
COMPLETED = "completed",
|
|
7
|
+
INTERRUPTED = "interrupted",
|
|
8
|
+
RUNNING = "running",
|
|
9
|
+
PENDING = "pending",
|
|
10
|
+
ERROR = "error"
|
|
11
|
+
}
|
|
12
|
+
export declare enum ActionStatus {
|
|
13
|
+
SUCCESS = "success",
|
|
14
|
+
ERROR = "error",
|
|
15
|
+
INTERRUPTED = "interrupted"
|
|
16
|
+
}
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ActionStatus = exports.FlowStatus = exports.EVENT_INSTANCE_ERROR = exports.EVENT_INSTANCE_INTERRUPTED = exports.EVENT_INSTANCE_COMPLETE = exports.BASE_START_NODE = void 0;
|
|
4
4
|
// baseType
|
|
5
5
|
exports.BASE_START_NODE = 'start';
|
|
6
|
-
//
|
|
6
|
+
// eventType
|
|
7
7
|
exports.EVENT_INSTANCE_COMPLETE = 'instance:complete';
|
|
8
8
|
exports.EVENT_INSTANCE_INTERRUPTED = 'instance:interrupted';
|
|
9
9
|
exports.EVENT_INSTANCE_ERROR = 'instance:error';
|
|
10
|
-
//
|
|
10
|
+
// flowStatus
|
|
11
11
|
var FlowStatus;
|
|
12
12
|
(function (FlowStatus) {
|
|
13
13
|
FlowStatus["COMPLETED"] = "completed";
|
|
@@ -16,10 +16,11 @@ var FlowStatus;
|
|
|
16
16
|
FlowStatus["PENDING"] = "pending";
|
|
17
17
|
FlowStatus["ERROR"] = "error";
|
|
18
18
|
})(FlowStatus = exports.FlowStatus || (exports.FlowStatus = {}));
|
|
19
|
-
//
|
|
19
|
+
// actionStatus
|
|
20
20
|
var ActionStatus;
|
|
21
21
|
(function (ActionStatus) {
|
|
22
22
|
ActionStatus["SUCCESS"] = "success";
|
|
23
23
|
ActionStatus["ERROR"] = "error";
|
|
24
24
|
ActionStatus["INTERRUPTED"] = "interrupted";
|
|
25
25
|
})(ActionStatus = exports.ActionStatus || (exports.ActionStatus = {}));
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":";;;AAAA,WAAW;AACE,QAAA,eAAe,GAAG,OAAO,CAAA;AAEtC,YAAY;AACC,QAAA,uBAAuB,GAAG,mBAAmB,CAAA;AAC7C,QAAA,0BAA0B,GAAG,sBAAsB,CAAA;AACnD,QAAA,oBAAoB,GAAG,gBAAgB,CAAA;AAEpD,aAAa;AACb,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,qCAAuB,CAAA;IACvB,yCAA2B,CAAA;IAC3B,iCAAmB,CAAA;IACnB,iCAAmB,CAAA;IACnB,6BAAe,CAAA;AACjB,CAAC,EANW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAMrB;AAED,eAAe;AACf,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,mCAAmB,CAAA;IACnB,+BAAe,CAAA;IACf,2CAA2B,CAAA;AAC7B,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum ErrorCode {
|
|
2
|
+
NONE_START_NODE = 1000,
|
|
3
|
+
NONE_NODE_ID = 1001,
|
|
4
|
+
NO_DOCUMENT_BODY = 2001
|
|
5
|
+
}
|
|
6
|
+
export declare enum WarningCode {
|
|
7
|
+
NONE_START_NODE_IN_DATA = 2000,
|
|
8
|
+
START_NODE_INCOMING = 2001,
|
|
9
|
+
EXPRESSION_EXEC_ERROR = 3000
|
|
10
|
+
}
|
|
11
|
+
export declare const getErrorMsg: (code: ErrorCode) => string;
|
|
12
|
+
export declare const getWarningMsg: (code: WarningCode) => string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a, _b;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.getWarningMsg = exports.getErrorMsg = exports.WarningCode = exports.ErrorCode = void 0;
|
|
5
4
|
var ErrorCode;
|
|
@@ -17,15 +16,19 @@ var WarningCode;
|
|
|
17
16
|
// 表达式判断异常
|
|
18
17
|
WarningCode[WarningCode["EXPRESSION_EXEC_ERROR"] = 3000] = "EXPRESSION_EXEC_ERROR";
|
|
19
18
|
})(WarningCode = exports.WarningCode || (exports.WarningCode = {}));
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
// TODO: 感觉这块可以用个国际化插件,这样配置不同语言加文件就可以了。
|
|
20
|
+
const errorMsgMapCn = {
|
|
21
|
+
[ErrorCode.NONE_START_NODE]: '未找到入度为0的节点',
|
|
22
|
+
[ErrorCode.NONE_NODE_ID]: '流程数据中存在没有此节点',
|
|
23
|
+
[ErrorCode.NO_DOCUMENT_BODY]: '找不到document.body, 请在DOM加载完成后再执行',
|
|
24
|
+
};
|
|
25
|
+
const warningMsgMapCn = {
|
|
26
|
+
[WarningCode.NONE_START_NODE_IN_DATA]: '初始化数据中未找到入度为0的节点',
|
|
27
|
+
[WarningCode.START_NODE_INCOMING]: '开始节点不允许被连入',
|
|
28
|
+
[WarningCode.EXPRESSION_EXEC_ERROR]: '表达式执行异常',
|
|
29
|
+
};
|
|
30
|
+
const getErrorMsg = (code) => `error[${code}]: ${errorMsgMapCn[code]}`;
|
|
31
|
+
exports.getErrorMsg = getErrorMsg;
|
|
32
|
+
const getWarningMsg = (code) => `warning[${code}]: ${warningMsgMapCn[code]}`;
|
|
33
|
+
exports.getWarningMsg = getWarningMsg;
|
|
34
|
+
//# sourceMappingURL=logCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logCode.js","sourceRoot":"","sources":["../../src/constant/logCode.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,SAAS;IACT,kEAAsB,CAAA;IACtB,4DAAmB,CAAA;IAEnB,QAAQ;IACR,oEAAuB,CAAA;AACzB,CAAC,EAPW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAOpB;AAED,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,sFAA8B,CAAA;IAC9B,8EAA0B,CAAA;IAE1B,UAAU;IACV,kFAA4B,CAAA;AAC9B,CAAC,EANW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAMtB;AAED,uCAAuC;AACvC,MAAM,aAAa,GAAG;IACpB,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,YAAY;IACzC,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,cAAc;IACxC,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAAE,iCAAiC;CAChE,CAAA;AAED,MAAM,eAAe,GAAG;IACtB,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAE,kBAAkB;IACzD,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,YAAY;IAC/C,CAAC,WAAW,CAAC,qBAAqB,CAAC,EAAE,SAAS;CAC/C,CAAA;AAEM,MAAM,WAAW,GAAG,CAAC,IAAe,EAAE,EAAE,CAC7C,SAAS,IAAI,MAAM,aAAa,CAAC,IAAI,CAAC,EAAE,CAAA;AAD7B,QAAA,WAAW,eACkB;AACnC,MAAM,aAAa,GAAG,CAAC,IAAiB,EAAE,EAAE,CACjD,WAAW,IAAI,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE,CAAA;AADjC,QAAA,aAAa,iBACoB"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { BaseNode, StartNode, TaskNode } from './nodes';
|
|
2
|
+
import { FlowModel } from './FlowModel';
|
|
3
|
+
import { Recorder } from './recorder';
|
|
4
|
+
export declare class Engine {
|
|
5
|
+
readonly instanceId: string;
|
|
6
|
+
graphData?: Engine.GraphConfigData;
|
|
7
|
+
flowModel?: FlowModel;
|
|
8
|
+
recorder?: Recorder;
|
|
9
|
+
context?: Record<string, unknown>;
|
|
10
|
+
nodeModelMap: Map<string, BaseNode.NodeConstructor>;
|
|
11
|
+
constructor(options?: Engine.Options);
|
|
12
|
+
/**
|
|
13
|
+
* 注册节点
|
|
14
|
+
* @param nodeConfig { type: 'custom-node', model: NodeClass }
|
|
15
|
+
*/
|
|
16
|
+
register(nodeConfig: Engine.NodeConfig): void;
|
|
17
|
+
/**
|
|
18
|
+
* 自定义执行记录的存储,默认浏览器使用 sessionStorage, nodejs 使用内存存储
|
|
19
|
+
* 注意:由于执行记录不全会主动删除,所以需要自行清理。
|
|
20
|
+
* nodejs 环境建议自定义为持久化存储。
|
|
21
|
+
* engine.setCustomRecorder({{
|
|
22
|
+
* async addActionRecord(task) {}
|
|
23
|
+
* async getTask(actionId) {}
|
|
24
|
+
* async getExecutionTasks(executionId) {}
|
|
25
|
+
* clear(instanceId) {}
|
|
26
|
+
* }}
|
|
27
|
+
* @param recorder
|
|
28
|
+
*/
|
|
29
|
+
setCustomRecorder(recorder: Recorder): void;
|
|
30
|
+
/**
|
|
31
|
+
* 加载流程图数据
|
|
32
|
+
*/
|
|
33
|
+
load({ graphData, startNodeType, globalData, }: Engine.LoadGraphParam): FlowModel;
|
|
34
|
+
/**
|
|
35
|
+
* 执行流程,允许多次调用
|
|
36
|
+
*/
|
|
37
|
+
execute(param?: Partial<Engine.ActionParam>): Promise<Engine.NextActionParam>;
|
|
38
|
+
/**
|
|
39
|
+
* 中断流程恢复
|
|
40
|
+
* @param resumeParam
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
resume(resumeParam: Engine.ResumeParam): Promise<Engine.NextActionParam | undefined>;
|
|
44
|
+
getExecutionList(): Promise<any>;
|
|
45
|
+
/**
|
|
46
|
+
* 获取执行任务记录
|
|
47
|
+
* @param executionId
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
getExecutionRecord(executionId: Engine.Key): Promise<Recorder.Info[] | null>;
|
|
51
|
+
destroy(): void;
|
|
52
|
+
getGlobalData(): Record<string, unknown> | undefined;
|
|
53
|
+
setGlobalData(data: Record<string, unknown>): void;
|
|
54
|
+
updateGlobalData(data: Record<string, unknown>): void;
|
|
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;
|
|
154
|
+
}
|
|
155
|
+
export * from './constant';
|
|
156
|
+
export { BaseNode, StartNode, TaskNode, Recorder };
|
|
157
|
+
export default Engine;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Recorder = exports.TaskNode = exports.StartNode = exports.BaseNode = exports.Engine = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// import { LogicFlow } from '@logicflow/core';
|
|
6
|
+
const nodes_1 = require("./nodes");
|
|
7
|
+
Object.defineProperty(exports, "BaseNode", { enumerable: true, get: function () { return nodes_1.BaseNode; } });
|
|
8
|
+
Object.defineProperty(exports, "StartNode", { enumerable: true, get: function () { return nodes_1.StartNode; } });
|
|
9
|
+
Object.defineProperty(exports, "TaskNode", { enumerable: true, get: function () { return nodes_1.TaskNode; } });
|
|
10
|
+
const FlowModel_1 = require("./FlowModel");
|
|
11
|
+
const recorder_1 = require("./recorder");
|
|
12
|
+
Object.defineProperty(exports, "Recorder", { enumerable: true, get: function () { return recorder_1.Recorder; } });
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
class Engine {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.nodeModelMap = new Map();
|
|
17
|
+
this.instanceId = (0, utils_1.createEngineId)();
|
|
18
|
+
if (options === null || options === void 0 ? void 0 : options.debug) {
|
|
19
|
+
this.recorder = new recorder_1.Recorder({
|
|
20
|
+
instanceId: this.instanceId,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// 默认注册节点 register default nodes
|
|
24
|
+
this.register({
|
|
25
|
+
type: nodes_1.StartNode.nodeTypeName,
|
|
26
|
+
model: nodes_1.StartNode,
|
|
27
|
+
});
|
|
28
|
+
this.register({
|
|
29
|
+
type: nodes_1.TaskNode.nodeTypeName,
|
|
30
|
+
model: nodes_1.TaskNode,
|
|
31
|
+
});
|
|
32
|
+
this.context = (options === null || options === void 0 ? void 0 : options.context) || {};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 注册节点
|
|
36
|
+
* @param nodeConfig { type: 'custom-node', model: NodeClass }
|
|
37
|
+
*/
|
|
38
|
+
register(nodeConfig) {
|
|
39
|
+
this.nodeModelMap.set(nodeConfig.type, nodeConfig.model);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 自定义执行记录的存储,默认浏览器使用 sessionStorage, nodejs 使用内存存储
|
|
43
|
+
* 注意:由于执行记录不全会主动删除,所以需要自行清理。
|
|
44
|
+
* nodejs 环境建议自定义为持久化存储。
|
|
45
|
+
* engine.setCustomRecorder({{
|
|
46
|
+
* async addActionRecord(task) {}
|
|
47
|
+
* async getTask(actionId) {}
|
|
48
|
+
* async getExecutionTasks(executionId) {}
|
|
49
|
+
* clear(instanceId) {}
|
|
50
|
+
* }}
|
|
51
|
+
* @param recorder
|
|
52
|
+
*/
|
|
53
|
+
setCustomRecorder(recorder) {
|
|
54
|
+
this.recorder = recorder;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 加载流程图数据
|
|
58
|
+
*/
|
|
59
|
+
load({ graphData, startNodeType = 'StartNode', globalData = {}, }) {
|
|
60
|
+
this.graphData = graphData;
|
|
61
|
+
const flowModel = new FlowModel_1.FlowModel({
|
|
62
|
+
nodeModelMap: this.nodeModelMap,
|
|
63
|
+
recorder: this.recorder,
|
|
64
|
+
context: this.context,
|
|
65
|
+
globalData,
|
|
66
|
+
startNodeType,
|
|
67
|
+
});
|
|
68
|
+
flowModel.load(graphData);
|
|
69
|
+
this.flowModel = flowModel;
|
|
70
|
+
return flowModel;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 执行流程,允许多次调用
|
|
74
|
+
*/
|
|
75
|
+
execute(param) {
|
|
76
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
var _a;
|
|
79
|
+
let execParam = param;
|
|
80
|
+
if (!param) {
|
|
81
|
+
execParam = {};
|
|
82
|
+
}
|
|
83
|
+
(_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.execute(Object.assign(Object.assign({}, execParam), { callback: (result) => {
|
|
84
|
+
resolve(result);
|
|
85
|
+
}, onError: (error) => {
|
|
86
|
+
reject(error);
|
|
87
|
+
} }));
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 中断流程恢复
|
|
93
|
+
* @param resumeParam
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
resume(resumeParam) {
|
|
97
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
var _a;
|
|
100
|
+
(_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.resume(Object.assign(Object.assign({}, resumeParam), { callback: (result) => {
|
|
101
|
+
resolve(result);
|
|
102
|
+
}, onError: (error) => {
|
|
103
|
+
reject(error);
|
|
104
|
+
} }));
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
getExecutionList() {
|
|
109
|
+
var _a;
|
|
110
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
return yield ((_a = this.recorder) === null || _a === void 0 ? void 0 : _a.getExecutionList());
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 获取执行任务记录
|
|
116
|
+
* @param executionId
|
|
117
|
+
* @returns
|
|
118
|
+
*/
|
|
119
|
+
getExecutionRecord(executionId) {
|
|
120
|
+
var _a, _b;
|
|
121
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
const actions = yield ((_a = this.recorder) === null || _a === void 0 ? void 0 : _a.getExecutionActions(executionId));
|
|
123
|
+
if (!actions) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
// DONE: 确认 records 的类型
|
|
127
|
+
const records = [];
|
|
128
|
+
for (let i = 0; i < (actions === null || actions === void 0 ? void 0 : actions.length); i++) {
|
|
129
|
+
const action = actions[i];
|
|
130
|
+
if (this.recorder) {
|
|
131
|
+
records.push((_b = this.recorder) === null || _b === void 0 ? void 0 : _b.getActionRecord(action));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return Promise.all(records);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
destroy() {
|
|
138
|
+
var _a;
|
|
139
|
+
(_a = this.recorder) === null || _a === void 0 ? void 0 : _a.clear();
|
|
140
|
+
}
|
|
141
|
+
getGlobalData() {
|
|
142
|
+
var _a;
|
|
143
|
+
return (_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.globalData;
|
|
144
|
+
}
|
|
145
|
+
setGlobalData(data) {
|
|
146
|
+
if (this.flowModel) {
|
|
147
|
+
this.flowModel.globalData = data;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
updateGlobalData(data) {
|
|
151
|
+
if (this.flowModel) {
|
|
152
|
+
Object.assign(this.flowModel.globalData, data);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.Engine = Engine;
|
|
157
|
+
tslib_1.__exportStar(require("./constant"), exports);
|
|
158
|
+
exports.default = Engine;
|
|
159
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@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