@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/es/Scheduler.js
CHANGED
|
@@ -1,158 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
extendStatics(d, b);
|
|
10
|
-
function __() { this.constructor = d; }
|
|
11
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
-
};
|
|
13
|
-
})();
|
|
14
|
-
var __assign = (this && this.__assign) || function () {
|
|
15
|
-
__assign = Object.assign || function(t) {
|
|
16
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
17
|
-
s = arguments[i];
|
|
18
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
19
|
-
t[p] = s[p];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
|
-
return __assign.apply(this, arguments);
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
-
function step(op) {
|
|
39
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
-
while (_) try {
|
|
41
|
-
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;
|
|
42
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
-
switch (op[0]) {
|
|
44
|
-
case 0: case 1: t = op; break;
|
|
45
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
-
default:
|
|
49
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
-
if (t[2]) _.ops.pop();
|
|
54
|
-
_.trys.pop(); continue;
|
|
55
|
-
}
|
|
56
|
-
op = body.call(thisArg, _);
|
|
57
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
-
}
|
|
60
|
-
};
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
61
2
|
import EventEmitter from './EventEmitter';
|
|
62
|
-
import {
|
|
63
|
-
import {
|
|
3
|
+
import { createActionId } from './utils';
|
|
4
|
+
import { EVENT_INSTANCE_ERROR, EVENT_INSTANCE_COMPLETE, EVENT_INSTANCE_INTERRUPTED, FlowStatus, } from './constant';
|
|
64
5
|
/**
|
|
65
6
|
* 调度器
|
|
66
7
|
* 通过一个队列维护需要执行的节点,一个集合维护正在执行的节点
|
|
67
8
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
_this.recorder = config.recorder;
|
|
76
|
-
return _this;
|
|
9
|
+
export class Scheduler extends EventEmitter {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super();
|
|
12
|
+
this.nodeQueueMap = new Map();
|
|
13
|
+
this.actionRunningMap = new Map();
|
|
14
|
+
this.flowModel = config.flowModel;
|
|
15
|
+
this.recorder = config.recorder;
|
|
77
16
|
}
|
|
78
17
|
/**
|
|
79
18
|
* 添加一个任务到队列中。
|
|
80
|
-
* 1.
|
|
81
|
-
* 2.
|
|
19
|
+
* 1. 由流程模型将所有的开始及诶带你添加到队列中
|
|
20
|
+
* 2. 当一个节点执行完成后,将后续的节点添加到队列中
|
|
21
|
+
* @param nodeParam
|
|
82
22
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
23
|
+
addAction(nodeParam) {
|
|
24
|
+
const { executionId } = nodeParam;
|
|
85
25
|
if (!this.nodeQueueMap.has(executionId)) {
|
|
86
26
|
this.nodeQueueMap.set(executionId, []);
|
|
87
27
|
}
|
|
88
|
-
|
|
89
|
-
currentActionQueue
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 调度器执行下一个任务
|
|
93
|
-
* 1. 提供给流程模型,用户开始执行第一个任务。
|
|
94
|
-
* 2. 内部任务执行完成后,调用此方法继续执行下一个任务。
|
|
95
|
-
* 3. 当判断没有可以继续执行的任务后,触发流程结束事件。
|
|
96
|
-
*/
|
|
97
|
-
Scheduler.prototype.run = function (runParams) {
|
|
98
|
-
var nodeQueue = this.nodeQueueMap.get(runParams.executionId);
|
|
99
|
-
// 将同一个executionId当前待执行的节点一起执行
|
|
100
|
-
// 避免出现某一个节点执行时间过长,导致其他节点等待时间过长。
|
|
101
|
-
while (nodeQueue.length) {
|
|
102
|
-
var currentNode = nodeQueue.pop();
|
|
103
|
-
var actionId = createActionId();
|
|
104
|
-
var actionParam = __assign(__assign({}, currentNode), { actionId: actionId });
|
|
105
|
-
this.pushActionToRunningMap(actionParam);
|
|
106
|
-
this.exec(actionParam);
|
|
107
|
-
}
|
|
108
|
-
if (!this.hasRunningAction(runParams.executionId)) {
|
|
109
|
-
// 当一个流程在nodeQueueMap和actionRunningMap中都不存在执行的节点时,说明这个流程已经执行完成。
|
|
110
|
-
this.emit(EVENT_INSTANCE_COMPLETE, __assign(__assign({}, runParams), { status: FlowStatus.COMPLETED }));
|
|
28
|
+
const currentActionQueue = this.nodeQueueMap.get(executionId);
|
|
29
|
+
if (currentActionQueue) {
|
|
30
|
+
currentActionQueue.push(nodeParam);
|
|
111
31
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
Scheduler.prototype.resume = function (resumeParam) {
|
|
118
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
-
var model;
|
|
120
|
-
return __generator(this, function (_a) {
|
|
121
|
-
switch (_a.label) {
|
|
122
|
-
case 0:
|
|
123
|
-
this.pushActionToRunningMap({
|
|
124
|
-
executionId: resumeParam.executionId,
|
|
125
|
-
nodeId: resumeParam.nodeId,
|
|
126
|
-
actionId: resumeParam.actionId,
|
|
127
|
-
});
|
|
128
|
-
model = this.flowModel.createAction(resumeParam.nodeId);
|
|
129
|
-
return [4 /*yield*/, model.resume(__assign(__assign({}, resumeParam), { next: this.next.bind(this) }))];
|
|
130
|
-
case 1:
|
|
131
|
-
_a.sent();
|
|
132
|
-
return [2 /*return*/];
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
Scheduler.prototype.pushActionToRunningMap = function (actionParam) {
|
|
138
|
-
var executionId = actionParam.executionId, actionId = actionParam.actionId;
|
|
32
|
+
console.log('this.nodeQueueMap--->>>', this.nodeQueueMap);
|
|
33
|
+
}
|
|
34
|
+
pushActionToRunningMap(actionParam) {
|
|
35
|
+
var _a;
|
|
36
|
+
const { executionId, actionId } = actionParam;
|
|
139
37
|
if (!this.actionRunningMap.has(executionId)) {
|
|
140
|
-
|
|
38
|
+
const runningMap = new Map();
|
|
141
39
|
this.actionRunningMap.set(executionId, runningMap);
|
|
142
40
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
41
|
+
if (actionId) {
|
|
42
|
+
(_a = this.actionRunningMap.get(executionId)) === null || _a === void 0 ? void 0 : _a.set(actionId, actionParam);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
removeActionFromRunningMap(actionParam) {
|
|
46
|
+
const { executionId, actionId } = actionParam;
|
|
147
47
|
if (!actionId)
|
|
148
48
|
return;
|
|
149
|
-
|
|
49
|
+
const runningMap = this.actionRunningMap.get(executionId);
|
|
150
50
|
if (!runningMap)
|
|
151
51
|
return;
|
|
152
52
|
runningMap.delete(actionId);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 为了防止多次添加导致
|
|
56
|
+
* @param actionParam
|
|
57
|
+
*/
|
|
58
|
+
saveActionResult(actionParam) {
|
|
59
|
+
var _a;
|
|
60
|
+
(_a = this.recorder) === null || _a === void 0 ? void 0 : _a.addActionRecord(Object.assign({ timestamp: Date.now() }, actionParam));
|
|
61
|
+
}
|
|
62
|
+
hasRunningAction(executionId) {
|
|
63
|
+
const runningMap = this.actionRunningMap.get(executionId);
|
|
156
64
|
if (!runningMap)
|
|
157
65
|
return false;
|
|
158
66
|
if (runningMap.size === 0) {
|
|
@@ -160,67 +68,35 @@ var Scheduler = /** @class */ (function (_super) {
|
|
|
160
68
|
return false;
|
|
161
69
|
}
|
|
162
70
|
return true;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
status: execResult.status,
|
|
189
|
-
detail: execResult.detail,
|
|
190
|
-
});
|
|
191
|
-
this.removeActionFromRunningMap(actionParam);
|
|
192
|
-
}
|
|
193
|
-
if (execResult && execResult.status === FlowStatus.ERROR) {
|
|
194
|
-
this.error(execResult);
|
|
195
|
-
this.saveActionResult({
|
|
196
|
-
executionId: actionParam.executionId,
|
|
197
|
-
nodeId: actionParam.nodeId,
|
|
198
|
-
actionId: actionParam.actionId,
|
|
199
|
-
nodeType: execResult.nodeType,
|
|
200
|
-
properties: execResult.properties,
|
|
201
|
-
outgoing: execResult.outgoing,
|
|
202
|
-
status: execResult.status,
|
|
203
|
-
detail: execResult.detail,
|
|
204
|
-
});
|
|
205
|
-
this.removeActionFromRunningMap(actionParam);
|
|
206
|
-
}
|
|
207
|
-
return [2 /*return*/];
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
|
-
Scheduler.prototype.interrupted = function (execResult) {
|
|
213
|
-
this.emit(EVENT_INSTANCE_INTERRUPTED, execResult);
|
|
214
|
-
};
|
|
215
|
-
Scheduler.prototype.error = function (execResult) {
|
|
216
|
-
this.emit(EVENT_INSTANCE_ERROR, execResult);
|
|
217
|
-
};
|
|
218
|
-
Scheduler.prototype.next = function (data) {
|
|
219
|
-
var _this = this;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 调度器执行下一个任务
|
|
74
|
+
* 1. 提供给流程模型,用户开始执行第一个任务
|
|
75
|
+
* 2. 内部任务执行完成后,调用此方法继续执行下一个任务
|
|
76
|
+
* 3. 当判断没有可以继续执行的任务后,触发流程结束事件
|
|
77
|
+
* @param runParam
|
|
78
|
+
*/
|
|
79
|
+
run(runParam) {
|
|
80
|
+
const nodeQueue = this.nodeQueueMap.get(runParam.executionId);
|
|
81
|
+
// 将同一个 executionId 当前待执行的节点一起执行
|
|
82
|
+
// 避免出现某一个节点执行时间过长,导致其他节点等待时间过长
|
|
83
|
+
while (nodeQueue === null || nodeQueue === void 0 ? void 0 : nodeQueue.length) {
|
|
84
|
+
const currentNode = nodeQueue.pop();
|
|
85
|
+
const actionId = createActionId();
|
|
86
|
+
const actionParam = Object.assign(Object.assign({}, currentNode), { actionId });
|
|
87
|
+
this.pushActionToRunningMap(actionParam);
|
|
88
|
+
this.exec(actionParam);
|
|
89
|
+
}
|
|
90
|
+
if (!this.hasRunningAction(runParam.executionId)) {
|
|
91
|
+
// 当一个流程在 nodeQueueMap 和 actionRunningMap 中都不存在执行的节点时,说明这个流程已经执行完成。
|
|
92
|
+
this.emit(EVENT_INSTANCE_COMPLETE, Object.assign(Object.assign({}, runParam), { status: FlowStatus.COMPLETED }));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
next(data) {
|
|
220
96
|
if (data.outgoing && data.outgoing.length > 0) {
|
|
221
|
-
data.outgoing.forEach(
|
|
97
|
+
data.outgoing.forEach((item) => {
|
|
222
98
|
if (item.result) {
|
|
223
|
-
|
|
99
|
+
this.addAction({
|
|
224
100
|
executionId: data.executionId,
|
|
225
101
|
nodeId: item.target,
|
|
226
102
|
});
|
|
@@ -230,21 +106,70 @@ var Scheduler = /** @class */ (function (_super) {
|
|
|
230
106
|
this.saveActionResult(data);
|
|
231
107
|
this.removeActionFromRunningMap(data);
|
|
232
108
|
this.run(data);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 恢复某个任务的执行
|
|
112
|
+
* 可以自定义节点手动实现流程中断,然后通过此方法恢复流程的执行
|
|
113
|
+
* @param resumeParam
|
|
114
|
+
*/
|
|
115
|
+
resume(resumeParam) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const { executionId, actionId, nodeId } = resumeParam;
|
|
118
|
+
this.pushActionToRunningMap({
|
|
119
|
+
executionId,
|
|
120
|
+
actionId,
|
|
121
|
+
nodeId,
|
|
122
|
+
});
|
|
123
|
+
const model = this.flowModel.createAction(nodeId);
|
|
124
|
+
yield (model === null || model === void 0 ? void 0 : model.resume(Object.assign(Object.assign({}, resumeParam), { next: this.next.bind(this) })));
|
|
246
125
|
});
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
126
|
+
}
|
|
127
|
+
// 中断时,触发事件
|
|
128
|
+
interrupted(execResult) {
|
|
129
|
+
this.emit(EVENT_INSTANCE_INTERRUPTED, execResult);
|
|
130
|
+
}
|
|
131
|
+
// 报错时,触发事件
|
|
132
|
+
error(execResult) {
|
|
133
|
+
this.emit(EVENT_INSTANCE_ERROR, execResult);
|
|
134
|
+
}
|
|
135
|
+
exec(actionParam) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const { executionId, actionId, nodeId } = actionParam;
|
|
138
|
+
const model = this.flowModel.createAction(nodeId);
|
|
139
|
+
const execResult = yield (model === null || model === void 0 ? void 0 : model.execute({
|
|
140
|
+
executionId,
|
|
141
|
+
actionId,
|
|
142
|
+
nodeId,
|
|
143
|
+
next: this.next.bind(this),
|
|
144
|
+
}));
|
|
145
|
+
if (execResult) {
|
|
146
|
+
const { nodeType, properties, outgoing, status, detail } = execResult;
|
|
147
|
+
const actionResult = {
|
|
148
|
+
// actionParam
|
|
149
|
+
executionId,
|
|
150
|
+
actionId,
|
|
151
|
+
nodeId,
|
|
152
|
+
// execResult
|
|
153
|
+
nodeType,
|
|
154
|
+
properties,
|
|
155
|
+
outgoing,
|
|
156
|
+
status,
|
|
157
|
+
detail,
|
|
158
|
+
};
|
|
159
|
+
if ((execResult === null || execResult === void 0 ? void 0 : execResult.status) === FlowStatus.INTERRUPTED) {
|
|
160
|
+
this.interrupted(execResult);
|
|
161
|
+
this.saveActionResult(actionResult);
|
|
162
|
+
this.removeActionFromRunningMap(actionParam);
|
|
163
|
+
}
|
|
164
|
+
if ((execResult === null || execResult === void 0 ? void 0 : execResult.status) === FlowStatus.ERROR) {
|
|
165
|
+
this.error(execResult);
|
|
166
|
+
this.saveActionResult(actionResult);
|
|
167
|
+
this.removeActionFromRunningMap(actionParam);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// TODO: 考虑停下所有的任务
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
250
174
|
export default Scheduler;
|
|
175
|
+
//# sourceMappingURL=Scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Scheduler.js","sourceRoot":"","sources":["../src/Scheduler.ts"],"names":[],"mappings":";AAGA,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC1B,UAAU,GACX,MAAM,YAAY,CAAA;AAEnB;;;GAGG;AACH,MAAM,OAAO,SAAU,SAAQ,YAAY;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,YA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AU,CAAA;gBACrE,MAAM,YAAY,GAA2B;oBAC3C,cAAc;oBACd,WAAW;oBACX,QAAQ;oBACR,MAAM;oBACN,aAAa;oBACb,QAAQ;oBACR,UAAU;oBACV,QAAQ;oBACR,MAAM;oBACN,MAAM;iBACP,CAAA;gBACD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,MAAK,UAAU,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,UAAU,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;AAkBD,eAAe,SAAS,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// baseType
|
|
2
|
-
export
|
|
3
|
-
//
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
//
|
|
2
|
+
export const BASE_START_NODE = 'start';
|
|
3
|
+
// eventType
|
|
4
|
+
export const EVENT_INSTANCE_COMPLETE = 'instance:complete';
|
|
5
|
+
export const EVENT_INSTANCE_INTERRUPTED = 'instance:interrupted';
|
|
6
|
+
export const EVENT_INSTANCE_ERROR = 'instance:error';
|
|
7
|
+
// flowStatus
|
|
8
8
|
export var FlowStatus;
|
|
9
9
|
(function (FlowStatus) {
|
|
10
10
|
FlowStatus["COMPLETED"] = "completed";
|
|
@@ -13,10 +13,11 @@ export var FlowStatus;
|
|
|
13
13
|
FlowStatus["PENDING"] = "pending";
|
|
14
14
|
FlowStatus["ERROR"] = "error";
|
|
15
15
|
})(FlowStatus || (FlowStatus = {}));
|
|
16
|
-
//
|
|
16
|
+
// actionStatus
|
|
17
17
|
export var ActionStatus;
|
|
18
18
|
(function (ActionStatus) {
|
|
19
19
|
ActionStatus["SUCCESS"] = "success";
|
|
20
20
|
ActionStatus["ERROR"] = "error";
|
|
21
21
|
ActionStatus["INTERRUPTED"] = "interrupted";
|
|
22
22
|
})(ActionStatus || (ActionStatus = {}));
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAA;AAEtC,YAAY;AACZ,MAAM,CAAC,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAC1D,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAA;AAChE,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAA;AAEpD,aAAa;AACb,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,qCAAuB,CAAA;IACvB,yCAA2B,CAAA;IAC3B,iCAAmB,CAAA;IACnB,iCAAmB,CAAA;IACnB,6BAAe,CAAA;AACjB,CAAC,EANW,UAAU,KAAV,UAAU,QAMrB;AAED,eAAe;AACf,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,mCAAmB,CAAA;IACnB,+BAAe,CAAA;IACf,2CAA2B,CAAA;AAC7B,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export var ErrorCode;
|
|
2
|
+
(function (ErrorCode) {
|
|
3
|
+
// 模型数据错误
|
|
4
|
+
ErrorCode[ErrorCode["NONE_START_NODE"] = 1000] = "NONE_START_NODE";
|
|
5
|
+
ErrorCode[ErrorCode["NONE_NODE_ID"] = 1001] = "NONE_NODE_ID";
|
|
6
|
+
// 表达式错误
|
|
7
|
+
ErrorCode[ErrorCode["NO_DOCUMENT_BODY"] = 2001] = "NO_DOCUMENT_BODY";
|
|
8
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
9
|
+
export var WarningCode;
|
|
10
|
+
(function (WarningCode) {
|
|
11
|
+
WarningCode[WarningCode["NONE_START_NODE_IN_DATA"] = 2000] = "NONE_START_NODE_IN_DATA";
|
|
12
|
+
WarningCode[WarningCode["START_NODE_INCOMING"] = 2001] = "START_NODE_INCOMING";
|
|
13
|
+
// 表达式判断异常
|
|
14
|
+
WarningCode[WarningCode["EXPRESSION_EXEC_ERROR"] = 3000] = "EXPRESSION_EXEC_ERROR";
|
|
15
|
+
})(WarningCode || (WarningCode = {}));
|
|
16
|
+
// TODO: 感觉这块可以用个国际化插件,这样配置不同语言加文件就可以了。
|
|
17
|
+
const errorMsgMapCn = {
|
|
18
|
+
[ErrorCode.NONE_START_NODE]: '未找到入度为0的节点',
|
|
19
|
+
[ErrorCode.NONE_NODE_ID]: '流程数据中存在没有此节点',
|
|
20
|
+
[ErrorCode.NO_DOCUMENT_BODY]: '找不到document.body, 请在DOM加载完成后再执行',
|
|
21
|
+
};
|
|
22
|
+
const warningMsgMapCn = {
|
|
23
|
+
[WarningCode.NONE_START_NODE_IN_DATA]: '初始化数据中未找到入度为0的节点',
|
|
24
|
+
[WarningCode.START_NODE_INCOMING]: '开始节点不允许被连入',
|
|
25
|
+
[WarningCode.EXPRESSION_EXEC_ERROR]: '表达式执行异常',
|
|
26
|
+
};
|
|
27
|
+
export const getErrorMsg = (code) => `error[${code}]: ${errorMsgMapCn[code]}`;
|
|
28
|
+
export const getWarningMsg = (code) => `warning[${code}]: ${warningMsgMapCn[code]}`;
|
|
29
|
+
//# sourceMappingURL=logCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logCode.js","sourceRoot":"","sources":["../../src/constant/logCode.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,SAAS;IACT,kEAAsB,CAAA;IACtB,4DAAmB,CAAA;IAEnB,QAAQ;IACR,oEAAuB,CAAA;AACzB,CAAC,EAPW,SAAS,KAAT,SAAS,QAOpB;AAED,MAAM,CAAN,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,sFAA8B,CAAA;IAC9B,8EAA0B,CAAA;IAE1B,UAAU;IACV,kFAA4B,CAAA;AAC9B,CAAC,EANW,WAAW,KAAX,WAAW,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;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAe,EAAE,EAAE,CAC7C,SAAS,IAAI,MAAM,aAAa,CAAC,IAAI,CAAC,EAAE,CAAA;AAC1C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAiB,EAAE,EAAE,CACjD,WAAW,IAAI,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE,CAAA"}
|
package/es/index.d.ts
CHANGED
|
@@ -1,60 +1,157 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
instanceId: string;
|
|
9
|
-
global: Record<string, any>;
|
|
10
|
-
graphData: GraphConfigData;
|
|
11
|
-
nodeModelMap: Map<string, NodeConstructor>;
|
|
12
|
-
flowModel: FlowModel;
|
|
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;
|
|
13
8
|
recorder?: Recorder;
|
|
14
|
-
context
|
|
15
|
-
|
|
9
|
+
context?: Record<string, unknown>;
|
|
10
|
+
nodeModelMap: Map<string, BaseNode.NodeConstructor>;
|
|
11
|
+
constructor(options?: Engine.Options);
|
|
16
12
|
/**
|
|
17
13
|
* 注册节点
|
|
18
14
|
* @param nodeConfig { type: 'custom-node', model: NodeClass }
|
|
19
15
|
*/
|
|
20
|
-
register(nodeConfig:
|
|
16
|
+
register(nodeConfig: Engine.NodeConfig): void;
|
|
21
17
|
/**
|
|
22
|
-
* 自定义执行记录的存储,默认浏览器使用 sessionStorage
|
|
23
|
-
*
|
|
24
|
-
* nodejs环境建议自定义为持久化存储。
|
|
25
|
-
* engine.setCustomRecorder({
|
|
18
|
+
* 自定义执行记录的存储,默认浏览器使用 sessionStorage, nodejs 使用内存存储
|
|
19
|
+
* 注意:由于执行记录不全会主动删除,所以需要自行清理。
|
|
20
|
+
* nodejs 环境建议自定义为持久化存储。
|
|
21
|
+
* engine.setCustomRecorder({{
|
|
26
22
|
* async addActionRecord(task) {}
|
|
27
23
|
* async getTask(actionId) {}
|
|
28
24
|
* async getExecutionTasks(executionId) {}
|
|
29
25
|
* clear(instanceId) {}
|
|
30
|
-
* }
|
|
26
|
+
* }}
|
|
27
|
+
* @param recorder
|
|
31
28
|
*/
|
|
32
29
|
setCustomRecorder(recorder: Recorder): void;
|
|
33
30
|
/**
|
|
34
31
|
* 加载流程图数据
|
|
35
32
|
*/
|
|
36
|
-
load({ graphData, startNodeType, globalData, }:
|
|
37
|
-
graphData: any;
|
|
38
|
-
startNodeType?: string;
|
|
39
|
-
globalData?: {};
|
|
40
|
-
}): FlowModel;
|
|
33
|
+
load({ graphData, startNodeType, globalData, }: Engine.LoadGraphParam): FlowModel;
|
|
41
34
|
/**
|
|
42
|
-
*
|
|
35
|
+
* 执行流程,允许多次调用
|
|
43
36
|
*/
|
|
44
|
-
execute(
|
|
37
|
+
execute(param?: Partial<Engine.ActionParam>): Promise<Engine.NextActionParam>;
|
|
45
38
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* 在实际项目中,如果存在中断节点,建议流程所有的节点都是排他网关,这样可以保证执行的过程不存在分支。
|
|
39
|
+
* 中断流程恢复
|
|
40
|
+
* @param resumeParam
|
|
41
|
+
* @returns
|
|
50
42
|
*/
|
|
51
|
-
resume(resumeParam:
|
|
43
|
+
resume(resumeParam: Engine.ResumeParam): Promise<Engine.NextActionParam | undefined>;
|
|
52
44
|
getExecutionList(): Promise<any>;
|
|
53
|
-
|
|
45
|
+
/**
|
|
46
|
+
* 获取执行任务记录
|
|
47
|
+
* @param executionId
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
getExecutionRecord(executionId: Engine.Key): Promise<Recorder.Info[] | null>;
|
|
54
51
|
destroy(): void;
|
|
55
|
-
getGlobalData(): Record<string,
|
|
56
|
-
setGlobalData(data:
|
|
57
|
-
updateGlobalData(data:
|
|
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;
|
|
58
154
|
}
|
|
59
|
-
export
|
|
60
|
-
export
|
|
155
|
+
export * from './constant';
|
|
156
|
+
export { BaseNode, StartNode, TaskNode, Recorder };
|
|
157
|
+
export default Engine;
|