@logicflow/engine 0.0.1
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 +22 -0
- package/cjs/EventEmitter.js +70 -0
- package/cjs/FlowModel.js +252 -0
- package/cjs/Scheduler.js +278 -0
- package/cjs/constant/LogCode.js +31 -0
- package/cjs/constant/constant.js +23 -0
- package/cjs/expression/browserVm.js +69 -0
- package/cjs/expression/index.js +63 -0
- package/cjs/expression/nodeVm.js +53 -0
- package/cjs/index.js +161 -0
- package/cjs/nodes/BaseNode.js +243 -0
- package/cjs/nodes/StartNode.js +27 -0
- package/cjs/nodes/TaskNode.js +27 -0
- package/cjs/recorder/index.js +112 -0
- package/cjs/util/ID.js +12 -0
- package/cjs/util/global.js +32 -0
- package/cjs/util/storage.js +41 -0
- package/es/EventEmitter.d.ts +7 -0
- package/es/EventEmitter.js +68 -0
- package/es/FlowModel.d.ts +104 -0
- package/es/FlowModel.js +250 -0
- package/es/Scheduler.d.ts +51 -0
- package/es/Scheduler.js +276 -0
- package/es/constant/LogCode.d.ts +12 -0
- package/es/constant/LogCode.js +28 -0
- package/es/constant/constant.d.ts +14 -0
- package/es/constant/constant.js +20 -0
- package/es/expression/browserVm.d.ts +2 -0
- package/es/expression/browserVm.js +66 -0
- package/es/expression/index.d.ts +2 -0
- package/es/expression/index.js +60 -0
- package/es/expression/nodeVm.d.ts +2 -0
- package/es/expression/nodeVm.js +50 -0
- package/es/index.d.ts +47 -0
- package/es/index.js +156 -0
- package/es/nodes/BaseNode.d.ts +109 -0
- package/es/nodes/BaseNode.js +241 -0
- package/es/nodes/StartNode.d.ts +5 -0
- package/es/nodes/StartNode.js +25 -0
- package/es/nodes/TaskNode.d.ts +5 -0
- package/es/nodes/TaskNode.js +25 -0
- package/es/recorder/index.d.ts +9 -0
- package/es/recorder/index.js +110 -0
- package/es/util/ID.d.ts +2 -0
- package/es/util/ID.js +9 -0
- package/es/util/global.d.ts +5 -0
- package/es/util/global.js +26 -0
- package/es/util/storage.d.ts +6 -0
- package/es/util/storage.js +39 -0
- package/lib/main.js +1 -0
- package/package.json +87 -0
- package/types/EventEmitter.d.ts +7 -0
- package/types/FlowModel.d.ts +104 -0
- package/types/Scheduler.d.ts +51 -0
- package/types/constant/LogCode.d.ts +12 -0
- package/types/constant/constant.d.ts +14 -0
- package/types/expression/browserVm.d.ts +2 -0
- package/types/expression/index.d.ts +2 -0
- package/types/expression/nodeVm.d.ts +2 -0
- package/types/index.d.ts +47 -0
- package/types/nodes/BaseNode.d.ts +109 -0
- package/types/nodes/StartNode.d.ts +5 -0
- package/types/nodes/TaskNode.d.ts +5 -0
- package/types/recorder/index.d.ts +9 -0
- package/types/util/ID.d.ts +2 -0
- package/types/util/global.d.ts +5 -0
- package/types/util/storage.d.ts +6 -0
package/es/index.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import FlowModel from './FlowModel';
|
|
49
|
+
import StartNode from './nodes/StartNode';
|
|
50
|
+
import TaskNode from './nodes/TaskNode';
|
|
51
|
+
import Recorder from './recorder';
|
|
52
|
+
var Engine = /** @class */ (function () {
|
|
53
|
+
function Engine() {
|
|
54
|
+
this.nodeModelMap = new Map();
|
|
55
|
+
this.recorder = new Recorder();
|
|
56
|
+
// register node
|
|
57
|
+
this.register({
|
|
58
|
+
type: StartNode.nodeTypeName,
|
|
59
|
+
model: StartNode,
|
|
60
|
+
});
|
|
61
|
+
this.register({
|
|
62
|
+
type: TaskNode.nodeTypeName,
|
|
63
|
+
model: TaskNode,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 注册节点
|
|
68
|
+
* @param nodeConfig { type: 'custom-node', model: Class }
|
|
69
|
+
*/
|
|
70
|
+
Engine.prototype.register = function (nodeConfig) {
|
|
71
|
+
this.nodeModelMap.set(nodeConfig.type, nodeConfig.model);
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* 自定义执行记录的存储,默认浏览器使用 sessionStorage,nodejs 使用内存存储。
|
|
75
|
+
* 注意:由于执行记录不会主动删除,所以需要自行清理。
|
|
76
|
+
* nodejs环境建议自定义为持久化存储。
|
|
77
|
+
* engine.setCustomRecorder({
|
|
78
|
+
* async addTask(task) {}
|
|
79
|
+
* async getTask(taskId) {}
|
|
80
|
+
* async getExecutionTasks(executionId) {}
|
|
81
|
+
* clear() {}
|
|
82
|
+
* });
|
|
83
|
+
*/
|
|
84
|
+
Engine.prototype.setCustomRecorder = function (recorder) {
|
|
85
|
+
this.recorder = recorder;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* 加载流程图数据
|
|
89
|
+
*/
|
|
90
|
+
Engine.prototype.load = function (_a) {
|
|
91
|
+
var graphData = _a.graphData, _b = _a.startNodeType, startNodeType = _b === void 0 ? 'StartNode' : _b, _c = _a.globalData, globalData = _c === void 0 ? {} : _c, _d = _a.context, context = _d === void 0 ? {} : _d;
|
|
92
|
+
this.flowModel = new FlowModel({
|
|
93
|
+
nodeModelMap: this.nodeModelMap,
|
|
94
|
+
recorder: this.recorder,
|
|
95
|
+
context: context,
|
|
96
|
+
globalData: globalData,
|
|
97
|
+
startNodeType: startNodeType,
|
|
98
|
+
});
|
|
99
|
+
this.flowModel.load(graphData);
|
|
100
|
+
return this.flowModel;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* 执行流程,允许多次调用。
|
|
104
|
+
*/
|
|
105
|
+
Engine.prototype.execute = function (execParam) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
var _this = this;
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
110
|
+
if (!execParam) {
|
|
111
|
+
execParam = {};
|
|
112
|
+
}
|
|
113
|
+
_this.flowModel.execute(__assign(__assign({}, execParam), { callback: function (result) {
|
|
114
|
+
resolve(result);
|
|
115
|
+
}, onError: function (error) {
|
|
116
|
+
reject(error);
|
|
117
|
+
} }));
|
|
118
|
+
})];
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
Engine.prototype.resume = function (resumeParam) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
var _this = this;
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
127
|
+
_this.flowModel.resume(__assign(__assign({}, resumeParam), { callback: function (result) {
|
|
128
|
+
resolve(result);
|
|
129
|
+
}, onError: function (error) {
|
|
130
|
+
reject(error);
|
|
131
|
+
} }));
|
|
132
|
+
})];
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
Engine.prototype.getExecutionRecord = function (executionId) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
138
|
+
var tasks, records, i;
|
|
139
|
+
return __generator(this, function (_a) {
|
|
140
|
+
switch (_a.label) {
|
|
141
|
+
case 0: return [4 /*yield*/, this.recorder.getExecutionTasks(executionId)];
|
|
142
|
+
case 1:
|
|
143
|
+
tasks = _a.sent();
|
|
144
|
+
records = [];
|
|
145
|
+
for (i = 0; i < tasks.length; i++) {
|
|
146
|
+
records.push(this.recorder.getTask(tasks[i]));
|
|
147
|
+
}
|
|
148
|
+
return [2 /*return*/, Promise.all(records)];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
return Engine;
|
|
154
|
+
}());
|
|
155
|
+
export default Engine;
|
|
156
|
+
export { Engine, TaskNode, StartNode, };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { ActionResult, NodeExecResult, ExecResumeParams, ExecParams } from '../types.d';
|
|
2
|
+
export interface BaseNodeInterface {
|
|
3
|
+
outgoing: Record<string, any>[];
|
|
4
|
+
incoming: Record<string, any>[];
|
|
5
|
+
nodeId: string;
|
|
6
|
+
type: string;
|
|
7
|
+
readonly baseType: string;
|
|
8
|
+
execute(taskParam: any): Promise<NodeExecResult>;
|
|
9
|
+
}
|
|
10
|
+
export declare type NodeConstructor = {
|
|
11
|
+
new (config: {
|
|
12
|
+
nodeConfig: NodeConfig;
|
|
13
|
+
context: Record<string, any>;
|
|
14
|
+
globalData: Record<string, any>;
|
|
15
|
+
}): BaseNode;
|
|
16
|
+
};
|
|
17
|
+
export declare type IncomingConfig = {
|
|
18
|
+
id: string;
|
|
19
|
+
properties?: Record<string, any>;
|
|
20
|
+
source: string;
|
|
21
|
+
};
|
|
22
|
+
export declare type OutgoingConfig = {
|
|
23
|
+
id: string;
|
|
24
|
+
target: string;
|
|
25
|
+
properties?: Record<string, any>;
|
|
26
|
+
};
|
|
27
|
+
export declare type NodeConfig = {
|
|
28
|
+
id: string;
|
|
29
|
+
type: string;
|
|
30
|
+
properties?: Record<string, any>;
|
|
31
|
+
incoming: IncomingConfig[];
|
|
32
|
+
outgoing: OutgoingConfig[];
|
|
33
|
+
};
|
|
34
|
+
export declare type NextTaskParam = {
|
|
35
|
+
executionId: string;
|
|
36
|
+
nodeId: string;
|
|
37
|
+
taskId: string;
|
|
38
|
+
nodeType: string;
|
|
39
|
+
outgoing: OutgoingConfig[];
|
|
40
|
+
properties?: Record<string, any>;
|
|
41
|
+
};
|
|
42
|
+
export default class BaseNode implements BaseNodeInterface {
|
|
43
|
+
static nodeTypeName: string;
|
|
44
|
+
/**
|
|
45
|
+
* 节点的出边
|
|
46
|
+
*/
|
|
47
|
+
outgoing: OutgoingConfig[];
|
|
48
|
+
/**
|
|
49
|
+
* 节点的入边
|
|
50
|
+
*/
|
|
51
|
+
incoming: IncomingConfig[];
|
|
52
|
+
/**
|
|
53
|
+
* 节点的属性
|
|
54
|
+
*/
|
|
55
|
+
properties?: Record<string, any>;
|
|
56
|
+
nodeId: string;
|
|
57
|
+
type: string;
|
|
58
|
+
/**
|
|
59
|
+
* 节点的上下文,是调用流程时传入的上下文
|
|
60
|
+
*/
|
|
61
|
+
context: Record<string, any>;
|
|
62
|
+
/**
|
|
63
|
+
* 节点的全局数据,是调用流程时传入的全局数据。
|
|
64
|
+
* 在计算表达式时,即基于全局数据进行计算。
|
|
65
|
+
*/
|
|
66
|
+
globalData: Record<string, any>;
|
|
67
|
+
readonly baseType: string;
|
|
68
|
+
constructor({ nodeConfig, context, globalData }: {
|
|
69
|
+
nodeConfig: any;
|
|
70
|
+
context: any;
|
|
71
|
+
globalData: any;
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* 节点的每一次执行都会生成一个唯一的taskId
|
|
75
|
+
*/
|
|
76
|
+
execute(params: ExecParams): Promise<NodeExecResult>;
|
|
77
|
+
/**
|
|
78
|
+
* 节点在执行中断后,可以通过resume方法恢复执行。
|
|
79
|
+
* 自定义节点时不建议重写此方法
|
|
80
|
+
*/
|
|
81
|
+
resume(params: ExecResumeParams): Promise<undefined>;
|
|
82
|
+
private getOutgoing;
|
|
83
|
+
private isPass;
|
|
84
|
+
/**
|
|
85
|
+
* 节点的执行逻辑
|
|
86
|
+
* @overridable 可以自定义节点重写此方法。
|
|
87
|
+
* @param params.executionId 流程执行记录ID
|
|
88
|
+
* @param params.taskId 此节点执行记录ID
|
|
89
|
+
* @param params.nodeId 节点ID
|
|
90
|
+
*/
|
|
91
|
+
action(params: {
|
|
92
|
+
executionId: string;
|
|
93
|
+
taskId: string;
|
|
94
|
+
nodeId: string;
|
|
95
|
+
}): Promise<ActionResult>;
|
|
96
|
+
/**
|
|
97
|
+
* 节点的重新恢复执行逻辑
|
|
98
|
+
* @overridable 可以自定义节点重写此方法。
|
|
99
|
+
* @param params.executionId 流程执行记录ID
|
|
100
|
+
* @param params.taskId 此节点执行记录ID
|
|
101
|
+
* @param params.nodeId 节点ID
|
|
102
|
+
*/
|
|
103
|
+
onResume(params: {
|
|
104
|
+
executionId: string;
|
|
105
|
+
taskId: string;
|
|
106
|
+
nodeId: string;
|
|
107
|
+
data?: Record<string, any>;
|
|
108
|
+
}): Promise<void>;
|
|
109
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __values = (this && this.__values) || function(o) {
|
|
49
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
50
|
+
if (m) return m.call(o);
|
|
51
|
+
if (o && typeof o.length === "number") return {
|
|
52
|
+
next: function () {
|
|
53
|
+
if (o && i >= o.length) o = void 0;
|
|
54
|
+
return { value: o && o[i++], done: !o };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
58
|
+
};
|
|
59
|
+
import { TaskStatus } from '../constant/constant';
|
|
60
|
+
import { getExpressionResult } from '../expression';
|
|
61
|
+
var BaseNode = /** @class */ (function () {
|
|
62
|
+
function BaseNode(_a) {
|
|
63
|
+
var nodeConfig = _a.nodeConfig, context = _a.context, globalData = _a.globalData;
|
|
64
|
+
this.outgoing = nodeConfig.outgoing;
|
|
65
|
+
this.incoming = nodeConfig.incoming;
|
|
66
|
+
this.nodeId = nodeConfig.id;
|
|
67
|
+
this.type = nodeConfig.type;
|
|
68
|
+
this.properties = nodeConfig.properties;
|
|
69
|
+
this.context = context;
|
|
70
|
+
this.globalData = globalData;
|
|
71
|
+
this.baseType = 'base';
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 节点的每一次执行都会生成一个唯一的taskId
|
|
75
|
+
*/
|
|
76
|
+
BaseNode.prototype.execute = function (params) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var r, outgoing;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0: return [4 /*yield*/, this.action({
|
|
82
|
+
executionId: params.executionId,
|
|
83
|
+
taskId: params.taskId,
|
|
84
|
+
nodeId: this.nodeId,
|
|
85
|
+
})];
|
|
86
|
+
case 1:
|
|
87
|
+
r = _a.sent();
|
|
88
|
+
if (!(!r || r.status === TaskStatus.SUCCESS)) return [3 /*break*/, 3];
|
|
89
|
+
return [4 /*yield*/, this.getOutgoing()];
|
|
90
|
+
case 2:
|
|
91
|
+
outgoing = _a.sent();
|
|
92
|
+
params.next({
|
|
93
|
+
executionId: params.executionId,
|
|
94
|
+
taskId: params.taskId,
|
|
95
|
+
nodeId: this.nodeId,
|
|
96
|
+
nodeType: this.type,
|
|
97
|
+
properties: this.properties,
|
|
98
|
+
outgoing: outgoing,
|
|
99
|
+
});
|
|
100
|
+
_a.label = 3;
|
|
101
|
+
case 3: return [2 /*return*/, {
|
|
102
|
+
status: r && r.status,
|
|
103
|
+
detail: r && r.detail,
|
|
104
|
+
executionId: params.executionId,
|
|
105
|
+
taskId: params.taskId,
|
|
106
|
+
nodeId: this.nodeId,
|
|
107
|
+
nodeType: this.type,
|
|
108
|
+
properties: this.properties,
|
|
109
|
+
}];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* 节点在执行中断后,可以通过resume方法恢复执行。
|
|
116
|
+
* 自定义节点时不建议重写此方法
|
|
117
|
+
*/
|
|
118
|
+
BaseNode.prototype.resume = function (params) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
+
var outgoing;
|
|
121
|
+
return __generator(this, function (_a) {
|
|
122
|
+
switch (_a.label) {
|
|
123
|
+
case 0: return [4 /*yield*/, this.getOutgoing()];
|
|
124
|
+
case 1:
|
|
125
|
+
outgoing = _a.sent();
|
|
126
|
+
return [4 /*yield*/, this.onResume({
|
|
127
|
+
executionId: params.executionId,
|
|
128
|
+
nodeId: params.nodeId,
|
|
129
|
+
taskId: params.taskId,
|
|
130
|
+
data: params.data,
|
|
131
|
+
})];
|
|
132
|
+
case 2:
|
|
133
|
+
_a.sent();
|
|
134
|
+
params.next({
|
|
135
|
+
executionId: params.executionId,
|
|
136
|
+
taskId: params.taskId,
|
|
137
|
+
nodeId: this.nodeId,
|
|
138
|
+
nodeType: this.type,
|
|
139
|
+
properties: this.properties,
|
|
140
|
+
outgoing: outgoing,
|
|
141
|
+
});
|
|
142
|
+
return [2 /*return*/, undefined];
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
BaseNode.prototype.getOutgoing = function () {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
var outgoing, expressions, _a, _b, item, properties, result;
|
|
150
|
+
var e_1, _c;
|
|
151
|
+
var _this = this;
|
|
152
|
+
return __generator(this, function (_d) {
|
|
153
|
+
switch (_d.label) {
|
|
154
|
+
case 0:
|
|
155
|
+
outgoing = [];
|
|
156
|
+
expressions = [];
|
|
157
|
+
try {
|
|
158
|
+
for (_a = __values(this.outgoing), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
159
|
+
item = _b.value;
|
|
160
|
+
properties = item.properties;
|
|
161
|
+
expressions.push(this.isPass(properties));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
165
|
+
finally {
|
|
166
|
+
try {
|
|
167
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
168
|
+
}
|
|
169
|
+
finally { if (e_1) throw e_1.error; }
|
|
170
|
+
}
|
|
171
|
+
return [4 /*yield*/, Promise.all(expressions)];
|
|
172
|
+
case 1:
|
|
173
|
+
result = _d.sent();
|
|
174
|
+
result.forEach(function (item, index) {
|
|
175
|
+
if (item) {
|
|
176
|
+
outgoing.push(_this.outgoing[index]);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return [2 /*return*/, outgoing];
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
BaseNode.prototype.isPass = function (properties) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
+
var conditionExpression, result, e_2;
|
|
187
|
+
return __generator(this, function (_a) {
|
|
188
|
+
switch (_a.label) {
|
|
189
|
+
case 0:
|
|
190
|
+
if (!properties)
|
|
191
|
+
return [2 /*return*/, true];
|
|
192
|
+
conditionExpression = properties.conditionExpression;
|
|
193
|
+
if (!conditionExpression)
|
|
194
|
+
return [2 /*return*/, true];
|
|
195
|
+
_a.label = 1;
|
|
196
|
+
case 1:
|
|
197
|
+
_a.trys.push([1, 3, , 4]);
|
|
198
|
+
return [4 /*yield*/, getExpressionResult("result" + this.nodeId + " = (" + conditionExpression + ")", __assign({}, this.globalData))];
|
|
199
|
+
case 2:
|
|
200
|
+
result = _a.sent();
|
|
201
|
+
return [2 /*return*/, result["result" + this.nodeId]];
|
|
202
|
+
case 3:
|
|
203
|
+
e_2 = _a.sent();
|
|
204
|
+
return [2 /*return*/, false];
|
|
205
|
+
case 4: return [2 /*return*/];
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* 节点的执行逻辑
|
|
212
|
+
* @overridable 可以自定义节点重写此方法。
|
|
213
|
+
* @param params.executionId 流程执行记录ID
|
|
214
|
+
* @param params.taskId 此节点执行记录ID
|
|
215
|
+
* @param params.nodeId 节点ID
|
|
216
|
+
*/
|
|
217
|
+
BaseNode.prototype.action = function (params) {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
return [2 /*return*/, undefined];
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* 节点的重新恢复执行逻辑
|
|
226
|
+
* @overridable 可以自定义节点重写此方法。
|
|
227
|
+
* @param params.executionId 流程执行记录ID
|
|
228
|
+
* @param params.taskId 此节点执行记录ID
|
|
229
|
+
* @param params.nodeId 节点ID
|
|
230
|
+
*/
|
|
231
|
+
BaseNode.prototype.onResume = function (params) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
+
return __generator(this, function (_a) {
|
|
234
|
+
return [2 /*return*/, undefined];
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
BaseNode.nodeTypeName = 'BaseNode';
|
|
239
|
+
return BaseNode;
|
|
240
|
+
}());
|
|
241
|
+
export default BaseNode;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
import BaseNode from './BaseNode';
|
|
15
|
+
var StartNode = /** @class */ (function (_super) {
|
|
16
|
+
__extends(StartNode, _super);
|
|
17
|
+
function StartNode() {
|
|
18
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
19
|
+
_this.baseType = 'start';
|
|
20
|
+
return _this;
|
|
21
|
+
}
|
|
22
|
+
StartNode.nodeTypeName = 'StartNode';
|
|
23
|
+
return StartNode;
|
|
24
|
+
}(BaseNode));
|
|
25
|
+
export default StartNode;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
import BaseNode from './BaseNode';
|
|
15
|
+
var TaskNode = /** @class */ (function (_super) {
|
|
16
|
+
__extends(TaskNode, _super);
|
|
17
|
+
function TaskNode() {
|
|
18
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
19
|
+
_this.baseType = 'task';
|
|
20
|
+
return _this;
|
|
21
|
+
}
|
|
22
|
+
TaskNode.nodeTypeName = 'TaskNode';
|
|
23
|
+
return TaskNode;
|
|
24
|
+
}(BaseNode));
|
|
25
|
+
export default TaskNode;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RecorderData, RecorderInterface } from '../types.d';
|
|
2
|
+
export default class Recorder implements RecorderInterface {
|
|
3
|
+
addTask(task: RecorderData): Promise<void>;
|
|
4
|
+
getTask(taskId: string): Promise<RecorderData>;
|
|
5
|
+
getExecutionTasks(executionId: any): Promise<any>;
|
|
6
|
+
clear(): void;
|
|
7
|
+
private pushExecution;
|
|
8
|
+
private pushTaskToExecution;
|
|
9
|
+
}
|