@logicflow/engine 0.0.10-beta.0 → 0.0.11-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -5
- package/cjs/EventEmitter.js +70 -0
- package/cjs/FlowModel.js +277 -0
- package/cjs/Scheduler.js +252 -0
- package/{lib/constant/logCode.js → cjs/constant/LogCode.js} +13 -16
- package/{lib/constant/index.js → cjs/constant/constant.js} +3 -4
- package/cjs/expression/browserVm.js +81 -0
- package/cjs/expression/index.js +57 -0
- package/cjs/index.js +210 -0
- package/cjs/nodes/BaseNode.js +252 -0
- package/cjs/nodes/StartNode.js +27 -0
- package/cjs/nodes/TaskNode.js +27 -0
- package/cjs/recorder/index.js +168 -0
- package/cjs/util/ID.js +16 -0
- package/cjs/util/global.js +32 -0
- package/{lib/utils → cjs/util}/storage.js +17 -18
- package/es/EventEmitter.d.ts +4 -34
- package/es/EventEmitter.js +48 -70
- package/es/FlowModel.d.ts +73 -75
- package/es/FlowModel.js +173 -130
- package/es/Scheduler.d.ts +34 -50
- package/es/Scheduler.js +209 -134
- package/es/constant/LogCode.js +28 -0
- package/es/constant/{index.js → constant.js} +7 -8
- package/es/expression/browserVm.d.ts +4 -0
- package/es/expression/browserVm.js +76 -0
- package/es/expression/index.d.ts +1 -1
- package/es/expression/index.js +53 -16
- package/es/index.d.ts +38 -135
- package/es/index.js +144 -92
- package/es/nodes/BaseNode.d.ts +110 -0
- package/es/nodes/BaseNode.js +250 -0
- package/es/nodes/{start.d.ts → StartNode.d.ts} +2 -3
- package/es/nodes/StartNode.js +25 -0
- package/es/nodes/{task.d.ts → TaskNode.d.ts} +2 -3
- package/es/nodes/TaskNode.js +25 -0
- package/es/recorder/index.d.ts +10 -36
- package/es/recorder/index.js +135 -82
- package/es/util/ID.js +13 -0
- package/es/util/global.d.ts +5 -0
- package/es/util/global.js +26 -0
- package/es/{utils → util}/storage.js +16 -17
- package/lib/main.js +1 -0
- package/package.json +71 -30
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/es/EventEmitter.js.map +0 -1
- package/es/FlowModel.js.map +0 -1
- package/es/Scheduler.js.map +0 -1
- package/es/constant/index.js.map +0 -1
- package/es/constant/logCode.js +0 -29
- package/es/constant/logCode.js.map +0 -1
- package/es/expression/brewserVm.d.ts +0 -2
- package/es/expression/brewserVm.js +0 -30
- package/es/expression/brewserVm.js.map +0 -1
- package/es/expression/index.js.map +0 -1
- package/es/expression/nodeVm.d.ts +0 -4
- package/es/expression/nodeVm.js +0 -10
- package/es/expression/nodeVm.js.map +0 -1
- package/es/index.js.map +0 -1
- package/es/nodes/base.d.ts +0 -108
- package/es/nodes/base.js +0 -149
- package/es/nodes/base.js.map +0 -1
- package/es/nodes/index.d.ts +0 -3
- package/es/nodes/index.js +0 -4
- package/es/nodes/index.js.map +0 -1
- package/es/nodes/start.js +0 -11
- package/es/nodes/start.js.map +0 -1
- package/es/nodes/task.js +0 -11
- package/es/nodes/task.js.map +0 -1
- package/es/platform/browser/browserVm.d.ts +0 -4
- package/es/platform/browser/browserVm.js +0 -44
- package/es/platform/browser/browserVm.js.map +0 -1
- package/es/platform/browser/index.d.ts +0 -4
- package/es/platform/browser/index.js +0 -23
- package/es/platform/browser/index.js.map +0 -1
- package/es/platform/index.d.ts +0 -1
- package/es/platform/index.js +0 -2
- package/es/platform/index.js.map +0 -1
- package/es/platform/node/index.d.ts +0 -4
- package/es/platform/node/index.js +0 -23
- package/es/platform/node/index.js.map +0 -1
- package/es/platform/node/nodeVm.d.ts +0 -1
- package/es/platform/node/nodeVm.js +0 -9
- package/es/platform/node/nodeVm.js.map +0 -1
- package/es/recorder/index.js.map +0 -1
- package/es/utils/global.d.ts +0 -5
- package/es/utils/global.js +0 -27
- package/es/utils/global.js.map +0 -1
- package/es/utils/id.js +0 -14
- package/es/utils/id.js.map +0 -1
- package/es/utils/index.d.ts +0 -4
- package/es/utils/index.js +0 -5
- package/es/utils/index.js.map +0 -1
- package/es/utils/storage.js.map +0 -1
- package/lib/EventEmitter.d.ts +0 -37
- package/lib/EventEmitter.js +0 -94
- package/lib/EventEmitter.js.map +0 -1
- package/lib/FlowModel.d.ts +0 -146
- package/lib/FlowModel.js +0 -236
- package/lib/FlowModel.js.map +0 -1
- package/lib/Scheduler.d.ts +0 -78
- package/lib/Scheduler.js +0 -179
- package/lib/Scheduler.js.map +0 -1
- package/lib/constant/index.d.ts +0 -16
- package/lib/constant/index.js.map +0 -1
- package/lib/constant/logCode.d.ts +0 -12
- package/lib/constant/logCode.js.map +0 -1
- package/lib/expression/brewserVm.d.ts +0 -2
- package/lib/expression/brewserVm.js +0 -33
- package/lib/expression/brewserVm.js.map +0 -1
- package/lib/expression/index.d.ts +0 -2
- package/lib/expression/index.js +0 -20
- package/lib/expression/index.js.map +0 -1
- package/lib/expression/nodeVm.d.ts +0 -4
- package/lib/expression/nodeVm.js +0 -13
- package/lib/expression/nodeVm.js.map +0 -1
- package/lib/index.d.ts +0 -157
- package/lib/index.js +0 -159
- package/lib/index.js.map +0 -1
- package/lib/nodes/base.d.ts +0 -108
- package/lib/nodes/base.js +0 -152
- package/lib/nodes/base.js.map +0 -1
- package/lib/nodes/index.d.ts +0 -3
- package/lib/nodes/index.js +0 -7
- package/lib/nodes/index.js.map +0 -1
- package/lib/nodes/start.d.ts +0 -6
- package/lib/nodes/start.js +0 -15
- package/lib/nodes/start.js.map +0 -1
- package/lib/nodes/task.d.ts +0 -6
- package/lib/nodes/task.js +0 -15
- package/lib/nodes/task.js.map +0 -1
- package/lib/platform/browser/browserVm.d.ts +0 -4
- package/lib/platform/browser/browserVm.js +0 -49
- package/lib/platform/browser/browserVm.js.map +0 -1
- package/lib/platform/browser/index.d.ts +0 -4
- package/lib/platform/browser/index.js +0 -28
- package/lib/platform/browser/index.js.map +0 -1
- package/lib/platform/index.d.ts +0 -1
- package/lib/platform/index.js +0 -5
- package/lib/platform/index.js.map +0 -1
- package/lib/platform/node/index.d.ts +0 -4
- package/lib/platform/node/index.js +0 -28
- package/lib/platform/node/index.js.map +0 -1
- package/lib/platform/node/nodeVm.d.ts +0 -1
- package/lib/platform/node/nodeVm.js +0 -13
- package/lib/platform/node/nodeVm.js.map +0 -1
- package/lib/recorder/index.d.ts +0 -46
- package/lib/recorder/index.js +0 -117
- package/lib/recorder/index.js.map +0 -1
- package/lib/utils/global.d.ts +0 -5
- package/lib/utils/global.js +0 -31
- package/lib/utils/global.js.map +0 -1
- package/lib/utils/id.d.ts +0 -3
- package/lib/utils/id.js +0 -20
- package/lib/utils/id.js.map +0 -1
- package/lib/utils/index.d.ts +0 -4
- package/lib/utils/index.js +0 -9
- package/lib/utils/index.js.map +0 -1
- package/lib/utils/storage.d.ts +0 -7
- package/lib/utils/storage.js.map +0 -1
- package/src/EventEmitter.ts +0 -103
- package/src/FlowModel.ts +0 -325
- package/src/Scheduler.ts +0 -244
- package/src/constant/index.ts +0 -23
- package/src/constant/logCode.ts +0 -34
- package/src/expression/brewserVm.ts +0 -36
- package/src/expression/index.ts +0 -17
- package/src/expression/nodeVm.ts +0 -14
- package/src/index.ts +0 -300
- package/src/nodes/base.ts +0 -234
- package/src/nodes/index.ts +0 -3
- package/src/nodes/start.ts +0 -8
- package/src/nodes/task.ts +0 -8
- package/src/platform/browser/browserVm.ts +0 -52
- package/src/platform/browser/index.ts +0 -28
- package/src/platform/index.ts +0 -1
- package/src/platform/node/index.ts +0 -28
- package/src/platform/node/nodeVm.ts +0 -12
- package/src/recorder/index.ts +0 -137
- package/src/typings.d.ts +0 -0
- package/src/utils/global.ts +0 -41
- package/src/utils/id.ts +0 -16
- package/src/utils/index.ts +0 -5
- package/src/utils/storage.ts +0 -55
- /package/es/constant/{logCode.d.ts → LogCode.d.ts} +0 -0
- /package/es/constant/{index.d.ts → constant.d.ts} +0 -0
- /package/es/{utils/id.d.ts → util/ID.d.ts} +0 -0
- /package/es/{utils → util}/storage.d.ts +0 -0
package/es/Scheduler.js
CHANGED
|
@@ -1,66 +1,158 @@
|
|
|
1
|
-
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
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
|
+
};
|
|
2
61
|
import EventEmitter from './EventEmitter';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
62
|
+
import { EVENT_INSTANCE_COMPLETE, EVENT_INSTANCE_INTERRUPTED, EVENT_INSTANCE_ERROR, FlowStatus, } from './constant/constant';
|
|
63
|
+
import { createActionId } from './util/ID';
|
|
5
64
|
/**
|
|
6
65
|
* 调度器
|
|
7
66
|
* 通过一个队列维护需要执行的节点,一个集合维护正在执行的节点
|
|
8
67
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
68
|
+
var Scheduler = /** @class */ (function (_super) {
|
|
69
|
+
__extends(Scheduler, _super);
|
|
70
|
+
function Scheduler(config) {
|
|
71
|
+
var _this = _super.call(this) || this;
|
|
72
|
+
_this.nodeQueueMap = new Map();
|
|
73
|
+
_this.actionRunningMap = new Map();
|
|
74
|
+
_this.flowModel = config.flowModel;
|
|
75
|
+
_this.recorder = config.recorder;
|
|
76
|
+
return _this;
|
|
16
77
|
}
|
|
17
78
|
/**
|
|
18
79
|
* 添加一个任务到队列中。
|
|
19
|
-
* 1.
|
|
20
|
-
* 2.
|
|
21
|
-
* @param nodeParam
|
|
80
|
+
* 1. 由流程模型将所有的开始节点添加到队列中。
|
|
81
|
+
* 2. 当一个节点执行完成后,将后续的节点添加到队列中。
|
|
22
82
|
*/
|
|
23
|
-
addAction(nodeParam) {
|
|
24
|
-
|
|
83
|
+
Scheduler.prototype.addAction = function (nodeParam) {
|
|
84
|
+
var executionId = nodeParam.executionId;
|
|
25
85
|
if (!this.nodeQueueMap.has(executionId)) {
|
|
26
86
|
this.nodeQueueMap.set(executionId, []);
|
|
27
87
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
88
|
+
var currentActionQueue = this.nodeQueueMap.get(executionId);
|
|
89
|
+
currentActionQueue.push(nodeParam);
|
|
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);
|
|
31
107
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
108
|
+
if (!this.hasRunningAction(runParams.executionId)) {
|
|
109
|
+
// 当一个流程在nodeQueueMap和actionRunningMap中都不存在执行的节点时,说明这个流程已经执行完成。
|
|
110
|
+
this.emit(EVENT_INSTANCE_COMPLETE, __assign(__assign({}, runParams), { status: FlowStatus.COMPLETED }));
|
|
111
|
+
}
|
|
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;
|
|
37
139
|
if (!this.actionRunningMap.has(executionId)) {
|
|
38
|
-
|
|
140
|
+
var runningMap = new Map();
|
|
39
141
|
this.actionRunningMap.set(executionId, runningMap);
|
|
40
142
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
removeActionFromRunningMap(actionParam) {
|
|
46
|
-
const { executionId, actionId } = actionParam;
|
|
143
|
+
this.actionRunningMap.get(executionId).set(actionId, actionParam);
|
|
144
|
+
};
|
|
145
|
+
Scheduler.prototype.removeActionFromRunningMap = function (actionParam) {
|
|
146
|
+
var executionId = actionParam.executionId, actionId = actionParam.actionId;
|
|
47
147
|
if (!actionId)
|
|
48
148
|
return;
|
|
49
|
-
|
|
149
|
+
var runningMap = this.actionRunningMap.get(executionId);
|
|
50
150
|
if (!runningMap)
|
|
51
151
|
return;
|
|
52
152
|
runningMap.delete(actionId);
|
|
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);
|
|
153
|
+
};
|
|
154
|
+
Scheduler.prototype.hasRunningAction = function (executionId) {
|
|
155
|
+
var runningMap = this.actionRunningMap.get(executionId);
|
|
64
156
|
if (!runningMap)
|
|
65
157
|
return false;
|
|
66
158
|
if (runningMap.size === 0) {
|
|
@@ -68,35 +160,67 @@ export class Scheduler extends EventEmitter {
|
|
|
68
160
|
return false;
|
|
69
161
|
}
|
|
70
162
|
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
163
|
+
};
|
|
164
|
+
Scheduler.prototype.exec = function (actionParam) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
166
|
+
var model, execResult;
|
|
167
|
+
return __generator(this, function (_a) {
|
|
168
|
+
switch (_a.label) {
|
|
169
|
+
case 0:
|
|
170
|
+
model = this.flowModel.createAction(actionParam.nodeId);
|
|
171
|
+
return [4 /*yield*/, model.execute({
|
|
172
|
+
executionId: actionParam.executionId,
|
|
173
|
+
actionId: actionParam.actionId,
|
|
174
|
+
nodeId: actionParam.nodeId,
|
|
175
|
+
next: this.next.bind(this),
|
|
176
|
+
})];
|
|
177
|
+
case 1:
|
|
178
|
+
execResult = _a.sent();
|
|
179
|
+
if (execResult && execResult.status === FlowStatus.INTERRUPTED) {
|
|
180
|
+
this.interrupted(execResult);
|
|
181
|
+
this.saveActionResult({
|
|
182
|
+
executionId: actionParam.executionId,
|
|
183
|
+
nodeId: actionParam.nodeId,
|
|
184
|
+
actionId: actionParam.actionId,
|
|
185
|
+
nodeType: execResult.nodeType,
|
|
186
|
+
properties: execResult.properties,
|
|
187
|
+
outgoing: execResult.outgoing,
|
|
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;
|
|
96
220
|
if (data.outgoing && data.outgoing.length > 0) {
|
|
97
|
-
data.outgoing.forEach((item)
|
|
221
|
+
data.outgoing.forEach(function (item) {
|
|
98
222
|
if (item.result) {
|
|
99
|
-
|
|
223
|
+
_this.addAction({
|
|
100
224
|
executionId: data.executionId,
|
|
101
225
|
nodeId: item.target,
|
|
102
226
|
});
|
|
@@ -106,70 +230,21 @@ export class Scheduler extends EventEmitter {
|
|
|
106
230
|
this.saveActionResult(data);
|
|
107
231
|
this.removeActionFromRunningMap(data);
|
|
108
232
|
this.run(data);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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) })));
|
|
125
|
-
});
|
|
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: 考虑停下所有的任务
|
|
233
|
+
};
|
|
234
|
+
Scheduler.prototype.saveActionResult = function (data) {
|
|
235
|
+
var _a;
|
|
236
|
+
(_a = this.recorder) === null || _a === void 0 ? void 0 : _a.addActionRecord({
|
|
237
|
+
executionId: data.executionId,
|
|
238
|
+
actionId: data.actionId,
|
|
239
|
+
nodeId: data.nodeId,
|
|
240
|
+
nodeType: data.nodeType,
|
|
241
|
+
timestamp: Date.now(),
|
|
242
|
+
properties: data.properties,
|
|
243
|
+
outgoing: data.outgoing,
|
|
244
|
+
detail: data.detail,
|
|
245
|
+
status: data.status,
|
|
171
246
|
});
|
|
172
|
-
}
|
|
173
|
-
|
|
247
|
+
};
|
|
248
|
+
return Scheduler;
|
|
249
|
+
}(EventEmitter));
|
|
174
250
|
export default Scheduler;
|
|
175
|
-
//# sourceMappingURL=Scheduler.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var _a, _b;
|
|
2
|
+
export var ErrorCode;
|
|
3
|
+
(function (ErrorCode) {
|
|
4
|
+
// 模型数据错误
|
|
5
|
+
ErrorCode[ErrorCode["NONE_START_NODE"] = 1000] = "NONE_START_NODE";
|
|
6
|
+
ErrorCode[ErrorCode["NONE_NODE_ID"] = 1001] = "NONE_NODE_ID";
|
|
7
|
+
// 表达式错误
|
|
8
|
+
ErrorCode[ErrorCode["NO_DOCUMENT_BODY"] = 2001] = "NO_DOCUMENT_BODY";
|
|
9
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
10
|
+
export var WarningCode;
|
|
11
|
+
(function (WarningCode) {
|
|
12
|
+
WarningCode[WarningCode["NONE_START_NODE_IN_DATA"] = 2000] = "NONE_START_NODE_IN_DATA";
|
|
13
|
+
WarningCode[WarningCode["START_NODE_INCOMING"] = 2001] = "START_NODE_INCOMING";
|
|
14
|
+
// 表达式判断异常
|
|
15
|
+
WarningCode[WarningCode["EXPRESSION_EXEC_ERROR"] = 3000] = "EXPRESSION_EXEC_ERROR";
|
|
16
|
+
})(WarningCode || (WarningCode = {}));
|
|
17
|
+
var errorMsgMapCn = (_a = {},
|
|
18
|
+
_a[ErrorCode.NONE_START_NODE] = '未找到入度为0的节点',
|
|
19
|
+
_a[ErrorCode.NONE_NODE_ID] = '流程数据中存在没有此节点',
|
|
20
|
+
_a[ErrorCode.NO_DOCUMENT_BODY] = '找不到document.body, 请在DOM加载完成后再执行',
|
|
21
|
+
_a);
|
|
22
|
+
var warningMsgMapCn = (_b = {},
|
|
23
|
+
_b[WarningCode.NONE_START_NODE_IN_DATA] = '初始化数据中未找到入度为0的节点',
|
|
24
|
+
_b[WarningCode.START_NODE_INCOMING] = '开始节点不允许被连入',
|
|
25
|
+
_b[WarningCode.EXPRESSION_EXEC_ERROR] = '表达式执行异常',
|
|
26
|
+
_b);
|
|
27
|
+
export var getErrorMsg = function (code) { return "error[" + code + "]: " + errorMsgMapCn[code]; };
|
|
28
|
+
export var getWarningMsg = function (code) { return "warning[" + code + "]: " + warningMsgMapCn[code]; };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// baseType
|
|
2
|
-
export
|
|
3
|
-
//
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
//
|
|
2
|
+
export var BASE_START_NODE = 'start';
|
|
3
|
+
// event name
|
|
4
|
+
export var EVENT_INSTANCE_COMPLETE = 'instance:complete';
|
|
5
|
+
export var EVENT_INSTANCE_INTERRUPTED = 'instance:interrupted';
|
|
6
|
+
export var EVENT_INSTANCE_ERROR = 'instance:error';
|
|
7
|
+
// flow status
|
|
8
8
|
export var FlowStatus;
|
|
9
9
|
(function (FlowStatus) {
|
|
10
10
|
FlowStatus["COMPLETED"] = "completed";
|
|
@@ -13,11 +13,10 @@ export var FlowStatus;
|
|
|
13
13
|
FlowStatus["PENDING"] = "pending";
|
|
14
14
|
FlowStatus["ERROR"] = "error";
|
|
15
15
|
})(FlowStatus || (FlowStatus = {}));
|
|
16
|
-
//
|
|
16
|
+
// action status
|
|
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,76 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { ErrorCode, WarningCode, getErrorMsg, getWarningMsg, } from '../constant/LogCode';
|
|
38
|
+
var createContext = function (globalData) {
|
|
39
|
+
var iframe = document.createElement('iframe');
|
|
40
|
+
iframe.style.display = 'none';
|
|
41
|
+
if (!document || !document.body) {
|
|
42
|
+
console.error(getErrorMsg(ErrorCode.NO_DOCUMENT_BODY));
|
|
43
|
+
}
|
|
44
|
+
document.body.appendChild(iframe);
|
|
45
|
+
var iframeWindow = iframe.contentWindow;
|
|
46
|
+
iframeWindow.parent = null;
|
|
47
|
+
Object.keys(globalData).forEach(function (key) {
|
|
48
|
+
iframeWindow[key] = globalData[key];
|
|
49
|
+
});
|
|
50
|
+
return iframeWindow;
|
|
51
|
+
};
|
|
52
|
+
var runInContext = function (code, context) {
|
|
53
|
+
try {
|
|
54
|
+
var iframeEval = context.eval;
|
|
55
|
+
iframeEval.call(context, code);
|
|
56
|
+
if (context.frameElement) {
|
|
57
|
+
document.body.removeChild(context.frameElement);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
console.warn(getWarningMsg(WarningCode.EXPRESSION_EXEC_ERROR), { code: code, context: context, e: e });
|
|
62
|
+
}
|
|
63
|
+
return context;
|
|
64
|
+
};
|
|
65
|
+
var runInBrowserContext = function (code, globalData) {
|
|
66
|
+
if (globalData === void 0) { globalData = {}; }
|
|
67
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
68
|
+
var context;
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
context = createContext(globalData);
|
|
71
|
+
runInContext(code, context);
|
|
72
|
+
return [2 /*return*/, context];
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
export { runInBrowserContext, createContext, runInContext, };
|
package/es/expression/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
declare const getExpressionResult: (code: string, context: any) => Promise<any>;
|
|
2
|
-
export { getExpressionResult };
|
|
2
|
+
export { getExpressionResult, };
|
package/es/expression/index.js
CHANGED
|
@@ -1,17 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
9
35
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
36
|
+
};
|
|
37
|
+
// import { runInNewContext } from './nodeVm';
|
|
38
|
+
import { runInBrowserContext } from './browserVm';
|
|
39
|
+
import { isInBrowser, globalScope } from '../util/global';
|
|
40
|
+
var getExpressionResult = function (code, context) { return __awaiter(void 0, void 0, void 0, function () {
|
|
41
|
+
var r;
|
|
42
|
+
return __generator(this, function (_a) {
|
|
43
|
+
switch (_a.label) {
|
|
44
|
+
case 0:
|
|
45
|
+
if (!isInBrowser) return [3 /*break*/, 2];
|
|
46
|
+
return [4 /*yield*/, runInBrowserContext(code, context)];
|
|
47
|
+
case 1:
|
|
48
|
+
r = _a.sent();
|
|
49
|
+
return [2 /*return*/, r];
|
|
50
|
+
case 2: return [2 /*return*/, globalScope.eval(code)]; // eslint-disable-line no-eval
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}); };
|
|
54
|
+
export { getExpressionResult, };
|