@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/lib/Scheduler.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
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
|
package/lib/Scheduler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,IAAI,GAAG,EAAE,CAAA;QACjC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;QACjC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;IACjC,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,SAA2B;QAC1C,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAA;QACjC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;YACvC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;SACvC;QAED,MAAM,kBAAkB,GACtB,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QACpC,IAAI,kBAAkB,EAAE;YACtB,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;SACnC;QACD,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;IAC3D,CAAC;IAEO,sBAAsB,CAAC,WAAkC;;QAC/D,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,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aAAa;oBACb,QAAQ;oBACR,UAAU;oBACV,QAAQ;oBACR,MAAM;oBACN,MAAM;iBACP,CAAA;gBACD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,MAAK,qBAAU,CAAC,WAAW,EAAE;oBACjD,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAA;oBAC5B,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAA;oBACnC,IAAI,CAAC,0BAA0B,CAAC,WAAW,CAAC,CAAA;iBAC7C;gBAED,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,MAAK,qBAAU,CAAC,KAAK,EAAE;oBAC3C,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;oBACtB,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAA;oBACnC,IAAI,CAAC,0BAA0B,CAAC,WAAW,CAAC,CAAA;iBAC7C;aACF;YACD,kBAAkB;QACpB,CAAC;KAAA;CACF;AAjND,8BAiNC;AAkBD,kBAAe,SAAS,CAAA"}
|
package/lib/constant/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,12 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runInBrowserContext = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const logCode_1 = require("../constant/logCode");
|
|
6
|
-
const runInBrowserContext = (code, globalData = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
7
|
-
const iframe = document.createElement('iframe');
|
|
8
|
-
iframe.style.display = 'none';
|
|
9
|
-
if (!document || !document.body) {
|
|
10
|
-
console.error((0, logCode_1.getErrorMsg)(logCode_1.ErrorCode.NO_DOCUMENT_BODY));
|
|
11
|
-
}
|
|
12
|
-
document.body.appendChild(iframe);
|
|
13
|
-
const iframeWindow = iframe.contentWindow;
|
|
14
|
-
const iframeEval = iframeWindow.eval;
|
|
15
|
-
Object.keys(globalData).forEach((key) => {
|
|
16
|
-
iframeWindow[key] = globalData[key];
|
|
17
|
-
});
|
|
18
|
-
let res = null;
|
|
19
|
-
try {
|
|
20
|
-
res = iframeEval.call(iframeWindow, code);
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
console.warn((0, logCode_1.getWarningMsg)(logCode_1.WarningCode.EXPRESSION_EXEC_ERROR), {
|
|
24
|
-
code,
|
|
25
|
-
globalData,
|
|
26
|
-
e,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
document.body.removeChild(iframe);
|
|
30
|
-
return res;
|
|
31
|
-
});
|
|
32
|
-
exports.runInBrowserContext = runInBrowserContext;
|
|
33
|
-
//# sourceMappingURL=brewserVm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"brewserVm.js","sourceRoot":"","sources":["../../src/expression/brewserVm.ts"],"names":[],"mappings":";;;;AAAA,iDAK4B;AAE5B,MAAM,mBAAmB,GAAG,CAAO,IAAY,EAAE,UAAU,GAAG,EAAE,EAAE,EAAE;IAClE,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;IAC/C,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAA;IAC7B,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;QAC/B,OAAO,CAAC,KAAK,CAAC,IAAA,qBAAW,EAAC,mBAAS,CAAC,gBAAgB,CAAC,CAAC,CAAA;KACvD;IACD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAEjC,MAAM,YAAY,GAAG,MAAM,CAAC,aAAoB,CAAA;IAChD,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAA;IACpC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;QAC9C,YAAY,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;IAEF,IAAI,GAAG,GAAG,IAAI,CAAA;IACd,IAAI;QACF,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;KAC1C;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,IAAI,CAAC,IAAA,uBAAa,EAAC,qBAAW,CAAC,qBAAqB,CAAC,EAAE;YAC7D,IAAI;YACJ,UAAU;YACV,CAAC;SACF,CAAC,CAAA;KACH;IACD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACjC,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA,CAAA;AAEQ,kDAAmB"}
|
package/lib/expression/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExpressionResult = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const nodeVm_1 = require("./nodeVm");
|
|
6
|
-
const brewserVm_1 = require("./brewserVm");
|
|
7
|
-
const utils_1 = require("../utils");
|
|
8
|
-
const getExpressionResult = (code, context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
9
|
-
if (utils_1.isInNodeJS) {
|
|
10
|
-
const r = yield (0, nodeVm_1.runInNodeContext)(code, context);
|
|
11
|
-
return r;
|
|
12
|
-
}
|
|
13
|
-
if (utils_1.isInBrowser) {
|
|
14
|
-
const r = yield (0, brewserVm_1.runInBrowserContext)(code, context);
|
|
15
|
-
return r;
|
|
16
|
-
}
|
|
17
|
-
return utils_1.globalScope.eval(code);
|
|
18
|
-
});
|
|
19
|
-
exports.getExpressionResult = getExpressionResult;
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/expression/index.ts"],"names":[],"mappings":";;;;AAAA,qCAA2C;AAC3C,2CAAiD;AACjD,oCAA+D;AAE/D,MAAM,mBAAmB,GAAG,CAAO,IAAY,EAAE,OAAY,EAAE,EAAE;IAC/D,IAAI,kBAAU,EAAE;QACd,MAAM,CAAC,GAAG,MAAM,IAAA,yBAAgB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAC/C,OAAO,CAAC,CAAA;KACT;IACD,IAAI,mBAAW,EAAE;QACf,MAAM,CAAC,GAAG,MAAM,IAAA,+BAAmB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAClD,OAAO,CAAC,CAAA;KACT;IACD,OAAO,mBAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC,CAAA,CAAA;AAEQ,kDAAmB"}
|
package/lib/expression/nodeVm.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runInNodeContext = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const node_vm_1 = tslib_1.__importDefault(require("node:vm"));
|
|
6
|
-
// const vm = require('node:vm');
|
|
7
|
-
const runInNodeContext = (code, globalData = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
-
const context = node_vm_1.default.createContext(globalData);
|
|
9
|
-
node_vm_1.default.runInContext(code, context);
|
|
10
|
-
return context;
|
|
11
|
-
});
|
|
12
|
-
exports.runInNodeContext = runInNodeContext;
|
|
13
|
-
//# sourceMappingURL=nodeVm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nodeVm.js","sourceRoot":"","sources":["../../src/expression/nodeVm.ts"],"names":[],"mappings":";;;;AAAA,8DAAwB;AACxB,iCAAiC;AAEjC,MAAM,gBAAgB,GAAG,CACvB,IAAY,EACZ,aAAsC,EAAE,EACxC,EAAE;IACF,MAAM,OAAO,GAAG,iBAAE,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;IAC5C,iBAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAE9B,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA,CAAA;AAEQ,4CAAgB"}
|
package/lib/index.d.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,+CAA+C;AAC/C,mCAAuD;AAwS9C,yFAxSA,gBAAQ,OAwSA;AAAE,0FAxSA,iBAAS,OAwSA;AAAE,yFAxSA,gBAAQ,OAwSA;AAvStC,2CAAuC;AACvC,yCAAqC;AAsSG,yFAtS/B,mBAAQ,OAsS+B;AArShD,mCAAwC;AAExC,MAAa,MAAM;IASjB,YAAY,OAAwB;QAClC,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAA;QAC7B,IAAI,CAAC,UAAU,GAAG,IAAA,sBAAc,GAAE,CAAA;QAClC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,CAAC;gBAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;aAC5B,CAAC,CAAA;SACH;QACD,gCAAgC;QAChC,IAAI,CAAC,QAAQ,CAAC;YACZ,IAAI,EAAE,iBAAS,CAAC,YAAY;YAC5B,KAAK,EAAE,iBAAS;SACjB,CAAC,CAAA;QACF,IAAI,CAAC,QAAQ,CAAC;YACZ,IAAI,EAAE,gBAAQ,CAAC,YAAY;YAC3B,KAAK,EAAE,gBAAQ;SAChB,CAAC,CAAA;QACF,IAAI,CAAC,OAAO,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,KAAI,EAAE,CAAA;IACvC,CAAC;IAED;;;OAGG;IACH,QAAQ,CAA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