@logicflow/engine 0.0.2 → 0.0.3
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/CHANGELOG.md +12 -0
- package/cjs/FlowModel.js +24 -38
- package/cjs/Scheduler.js +53 -54
- package/cjs/constant/constant.js +8 -8
- package/cjs/expression/browserVm.js +30 -22
- package/cjs/expression/nodeVm.js +1 -1
- package/cjs/index.js +34 -9
- package/cjs/nodes/BaseNode.js +10 -10
- package/cjs/recorder/index.js +41 -20
- package/cjs/util/ID.js +7 -3
- package/es/FlowModel.d.ts +11 -11
- package/es/FlowModel.js +24 -38
- package/es/Scheduler.d.ts +9 -9
- package/es/Scheduler.js +54 -55
- package/es/constant/constant.d.ts +1 -1
- package/es/constant/constant.js +7 -7
- package/es/expression/browserVm.d.ts +3 -1
- package/es/expression/browserVm.js +28 -22
- package/es/expression/nodeVm.js +1 -1
- package/es/index.d.ts +22 -11
- package/es/index.js +34 -9
- package/es/nodes/BaseNode.d.ts +19 -8
- package/es/nodes/BaseNode.js +11 -11
- package/es/recorder/index.d.ts +8 -4
- package/es/recorder/index.js +41 -20
- package/es/util/ID.d.ts +2 -1
- package/es/util/ID.js +6 -2
- package/lib/main.js +1 -1
- package/package.json +4 -1
|
@@ -35,32 +35,38 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
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
|
+
var iframeWindow = iframe.contentWindow;
|
|
45
|
+
iframeWindow.parent = null;
|
|
46
|
+
Object.keys(globalData).forEach(function (key) {
|
|
47
|
+
iframeWindow[key] = globalData[key];
|
|
48
|
+
});
|
|
49
|
+
return iframeWindow;
|
|
50
|
+
};
|
|
51
|
+
var runInContext = function (code, context) {
|
|
52
|
+
try {
|
|
53
|
+
var iframeEval = context.eval;
|
|
54
|
+
iframeEval.call(context, code);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.warn(getWarningMsg(WarningCode.EXPRESSION_EXEC_ERROR), { code: code, context: context, e: e });
|
|
58
|
+
}
|
|
59
|
+
return context;
|
|
60
|
+
};
|
|
38
61
|
var runInBrowserContext = function (code, globalData) {
|
|
39
62
|
if (globalData === void 0) { globalData = {}; }
|
|
40
63
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
41
|
-
var
|
|
64
|
+
var context;
|
|
42
65
|
return __generator(this, function (_a) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
console.error(getErrorMsg(ErrorCode.NO_DOCUMENT_BODY));
|
|
47
|
-
}
|
|
48
|
-
document.body.appendChild(iframe);
|
|
49
|
-
iframeWindow = iframe.contentWindow;
|
|
50
|
-
iframeEval = iframeWindow.eval;
|
|
51
|
-
Object.keys(globalData).forEach(function (key) {
|
|
52
|
-
iframeWindow[key] = globalData[key];
|
|
53
|
-
});
|
|
54
|
-
res = null;
|
|
55
|
-
try {
|
|
56
|
-
res = iframeEval.call(iframeWindow, code);
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
console.warn(getWarningMsg(WarningCode.EXPRESSION_EXEC_ERROR), { code: code, globalData: globalData, e: e });
|
|
60
|
-
}
|
|
61
|
-
document.body.removeChild(iframe);
|
|
62
|
-
return [2 /*return*/, res];
|
|
66
|
+
context = createContext(globalData);
|
|
67
|
+
runInContext(code, context);
|
|
68
|
+
return [2 /*return*/, context];
|
|
63
69
|
});
|
|
64
70
|
});
|
|
65
71
|
};
|
|
66
|
-
export { runInBrowserContext, };
|
|
72
|
+
export { runInBrowserContext, createContext, runInContext, };
|
package/es/expression/nodeVm.js
CHANGED
|
@@ -34,7 +34,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
/* eslint-disable global-require */
|
|
38
38
|
var vm = require('vm');
|
|
39
39
|
var runInNewContext = function (code, globalData) {
|
|
40
40
|
if (globalData === void 0) { globalData = {}; }
|
package/es/index.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import type { ResumeParams, GraphConfigData } from './types.d';
|
|
2
|
-
import FlowModel, {
|
|
1
|
+
import type { ResumeParams, GraphConfigData, EngineConstructorOptions } from './types.d';
|
|
2
|
+
import FlowModel, { ActionParams } from './FlowModel';
|
|
3
3
|
import StartNode from './nodes/StartNode';
|
|
4
4
|
import TaskNode from './nodes/TaskNode';
|
|
5
5
|
import Recorder from './recorder';
|
|
6
|
+
import { NodeConstructor } from './nodes/BaseNode';
|
|
6
7
|
export default class Engine {
|
|
8
|
+
id: string;
|
|
7
9
|
global: Record<string, any>;
|
|
8
10
|
graphData: GraphConfigData;
|
|
9
|
-
nodeModelMap: Map<string,
|
|
11
|
+
nodeModelMap: Map<string, NodeConstructor>;
|
|
10
12
|
flowModel: FlowModel;
|
|
11
13
|
recorder: Recorder;
|
|
12
|
-
|
|
14
|
+
context: Record<string, any>;
|
|
15
|
+
constructor(options?: EngineConstructorOptions);
|
|
13
16
|
/**
|
|
14
17
|
* 注册节点
|
|
15
|
-
* @param nodeConfig { type: 'custom-node', model:
|
|
18
|
+
* @param nodeConfig { type: 'custom-node', model: NodeClass }
|
|
16
19
|
*/
|
|
17
20
|
register(nodeConfig: any): void;
|
|
18
21
|
/**
|
|
@@ -20,8 +23,8 @@ export default class Engine {
|
|
|
20
23
|
* 注意:由于执行记录不会主动删除,所以需要自行清理。
|
|
21
24
|
* nodejs环境建议自定义为持久化存储。
|
|
22
25
|
* engine.setCustomRecorder({
|
|
23
|
-
* async
|
|
24
|
-
* async getTask(
|
|
26
|
+
* async addActionRecord(task) {}
|
|
27
|
+
* async getTask(actionId) {}
|
|
25
28
|
* async getExecutionTasks(executionId) {}
|
|
26
29
|
* clear() {}
|
|
27
30
|
* });
|
|
@@ -30,18 +33,26 @@ export default class Engine {
|
|
|
30
33
|
/**
|
|
31
34
|
* 加载流程图数据
|
|
32
35
|
*/
|
|
33
|
-
load({ graphData, startNodeType, globalData,
|
|
36
|
+
load({ graphData, startNodeType, globalData, }: {
|
|
34
37
|
graphData: any;
|
|
35
38
|
startNodeType?: string;
|
|
36
39
|
globalData?: {};
|
|
37
|
-
context?: {};
|
|
38
40
|
}): FlowModel;
|
|
39
41
|
/**
|
|
40
42
|
* 执行流程,允许多次调用。
|
|
41
43
|
*/
|
|
42
|
-
execute(execParam?:
|
|
44
|
+
execute(execParam?: ActionParams): Promise<unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* 恢复执行
|
|
47
|
+
* 注意此方法只能恢复节点后面的执行,不能恢复流程其他分支的执行。
|
|
48
|
+
* 同理,中断执行也只能中断节点后面的执行,不会中断其他分支的执行。
|
|
49
|
+
* 在实际项目中,如果存在中断节点,建议流程所有的节点都是排他网关,这样可以保证执行的过程不存在分支。
|
|
50
|
+
*/
|
|
43
51
|
resume(resumeParam: ResumeParams): Promise<unknown>;
|
|
44
52
|
getExecutionRecord(executionId: any): Promise<any[]>;
|
|
53
|
+
getGlobalData(): Record<string, any>;
|
|
54
|
+
setGlobalData(data: any): void;
|
|
55
|
+
updateGlobalData(data: any): void;
|
|
45
56
|
}
|
|
46
57
|
export { Engine, TaskNode, StartNode, };
|
|
47
|
-
export type {
|
|
58
|
+
export type { ActionParams, };
|
package/es/index.js
CHANGED
|
@@ -49,11 +49,12 @@ import FlowModel from './FlowModel';
|
|
|
49
49
|
import StartNode from './nodes/StartNode';
|
|
50
50
|
import TaskNode from './nodes/TaskNode';
|
|
51
51
|
import Recorder from './recorder';
|
|
52
|
+
import { createEngineId } from './util/ID';
|
|
52
53
|
var Engine = /** @class */ (function () {
|
|
53
|
-
function Engine() {
|
|
54
|
+
function Engine(options) {
|
|
54
55
|
this.nodeModelMap = new Map();
|
|
56
|
+
this.id = createEngineId();
|
|
55
57
|
this.recorder = new Recorder();
|
|
56
|
-
// register node
|
|
57
58
|
this.register({
|
|
58
59
|
type: StartNode.nodeTypeName,
|
|
59
60
|
model: StartNode,
|
|
@@ -62,10 +63,11 @@ var Engine = /** @class */ (function () {
|
|
|
62
63
|
type: TaskNode.nodeTypeName,
|
|
63
64
|
model: TaskNode,
|
|
64
65
|
});
|
|
66
|
+
this.context = (options === null || options === void 0 ? void 0 : options.context) || {};
|
|
65
67
|
}
|
|
66
68
|
/**
|
|
67
69
|
* 注册节点
|
|
68
|
-
* @param nodeConfig { type: 'custom-node', model:
|
|
70
|
+
* @param nodeConfig { type: 'custom-node', model: NodeClass }
|
|
69
71
|
*/
|
|
70
72
|
Engine.prototype.register = function (nodeConfig) {
|
|
71
73
|
this.nodeModelMap.set(nodeConfig.type, nodeConfig.model);
|
|
@@ -75,8 +77,8 @@ var Engine = /** @class */ (function () {
|
|
|
75
77
|
* 注意:由于执行记录不会主动删除,所以需要自行清理。
|
|
76
78
|
* nodejs环境建议自定义为持久化存储。
|
|
77
79
|
* engine.setCustomRecorder({
|
|
78
|
-
* async
|
|
79
|
-
* async getTask(
|
|
80
|
+
* async addActionRecord(task) {}
|
|
81
|
+
* async getTask(actionId) {}
|
|
80
82
|
* async getExecutionTasks(executionId) {}
|
|
81
83
|
* clear() {}
|
|
82
84
|
* });
|
|
@@ -88,11 +90,11 @@ var Engine = /** @class */ (function () {
|
|
|
88
90
|
* 加载流程图数据
|
|
89
91
|
*/
|
|
90
92
|
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
|
|
93
|
+
var graphData = _a.graphData, _b = _a.startNodeType, startNodeType = _b === void 0 ? 'StartNode' : _b, _c = _a.globalData, globalData = _c === void 0 ? {} : _c;
|
|
92
94
|
this.flowModel = new FlowModel({
|
|
93
95
|
nodeModelMap: this.nodeModelMap,
|
|
94
96
|
recorder: this.recorder,
|
|
95
|
-
context: context,
|
|
97
|
+
context: this.context,
|
|
96
98
|
globalData: globalData,
|
|
97
99
|
startNodeType: startNodeType,
|
|
98
100
|
});
|
|
@@ -119,6 +121,12 @@ var Engine = /** @class */ (function () {
|
|
|
119
121
|
});
|
|
120
122
|
});
|
|
121
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* 恢复执行
|
|
126
|
+
* 注意此方法只能恢复节点后面的执行,不能恢复流程其他分支的执行。
|
|
127
|
+
* 同理,中断执行也只能中断节点后面的执行,不会中断其他分支的执行。
|
|
128
|
+
* 在实际项目中,如果存在中断节点,建议流程所有的节点都是排他网关,这样可以保证执行的过程不存在分支。
|
|
129
|
+
*/
|
|
122
130
|
Engine.prototype.resume = function (resumeParam) {
|
|
123
131
|
return __awaiter(this, void 0, void 0, function () {
|
|
124
132
|
var _this = this;
|
|
@@ -138,18 +146,35 @@ var Engine = /** @class */ (function () {
|
|
|
138
146
|
var tasks, records, i;
|
|
139
147
|
return __generator(this, function (_a) {
|
|
140
148
|
switch (_a.label) {
|
|
141
|
-
case 0: return [4 /*yield*/, this.recorder.
|
|
149
|
+
case 0: return [4 /*yield*/, this.recorder.getExecutionActions(executionId)];
|
|
142
150
|
case 1:
|
|
143
151
|
tasks = _a.sent();
|
|
152
|
+
if (!tasks) {
|
|
153
|
+
return [2 /*return*/, null];
|
|
154
|
+
}
|
|
144
155
|
records = [];
|
|
145
156
|
for (i = 0; i < tasks.length; i++) {
|
|
146
|
-
records.push(this.recorder.
|
|
157
|
+
records.push(this.recorder.getActionRecord(tasks[i]));
|
|
147
158
|
}
|
|
148
159
|
return [2 /*return*/, Promise.all(records)];
|
|
149
160
|
}
|
|
150
161
|
});
|
|
151
162
|
});
|
|
152
163
|
};
|
|
164
|
+
Engine.prototype.getGlobalData = function () {
|
|
165
|
+
var _a;
|
|
166
|
+
return (_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.globalData;
|
|
167
|
+
};
|
|
168
|
+
Engine.prototype.setGlobalData = function (data) {
|
|
169
|
+
if (this.flowModel) {
|
|
170
|
+
this.flowModel.globalData = data;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
Engine.prototype.updateGlobalData = function (data) {
|
|
174
|
+
if (this.flowModel) {
|
|
175
|
+
Object.assign(this.flowModel.globalData, data);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
153
178
|
return Engine;
|
|
154
179
|
}());
|
|
155
180
|
export default Engine;
|
package/es/nodes/BaseNode.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface BaseNodeInterface {
|
|
|
5
5
|
nodeId: string;
|
|
6
6
|
type: string;
|
|
7
7
|
readonly baseType: string;
|
|
8
|
-
execute(
|
|
8
|
+
execute(actionParam: any): Promise<NodeExecResult>;
|
|
9
9
|
}
|
|
10
10
|
export declare type NodeConstructor = {
|
|
11
11
|
new (config: {
|
|
@@ -13,6 +13,17 @@ export declare type NodeConstructor = {
|
|
|
13
13
|
context: Record<string, any>;
|
|
14
14
|
globalData: Record<string, any>;
|
|
15
15
|
}): BaseNode;
|
|
16
|
+
action(params: {
|
|
17
|
+
executionId: string;
|
|
18
|
+
actionId: string;
|
|
19
|
+
nodeId: string;
|
|
20
|
+
}): Promise<ActionResult>;
|
|
21
|
+
onResume(params: {
|
|
22
|
+
executionId: string;
|
|
23
|
+
actionId: string;
|
|
24
|
+
nodeId: string;
|
|
25
|
+
data?: Record<string, any>;
|
|
26
|
+
}): Promise<void>;
|
|
16
27
|
};
|
|
17
28
|
export declare type IncomingConfig = {
|
|
18
29
|
id: string;
|
|
@@ -31,10 +42,10 @@ export declare type NodeConfig = {
|
|
|
31
42
|
incoming: IncomingConfig[];
|
|
32
43
|
outgoing: OutgoingConfig[];
|
|
33
44
|
};
|
|
34
|
-
export declare type
|
|
45
|
+
export declare type NextActionParam = {
|
|
35
46
|
executionId: string;
|
|
36
47
|
nodeId: string;
|
|
37
|
-
|
|
48
|
+
actionId: string;
|
|
38
49
|
nodeType: string;
|
|
39
50
|
outgoing: OutgoingConfig[];
|
|
40
51
|
properties?: Record<string, any>;
|
|
@@ -71,7 +82,7 @@ export default class BaseNode implements BaseNodeInterface {
|
|
|
71
82
|
globalData: any;
|
|
72
83
|
});
|
|
73
84
|
/**
|
|
74
|
-
* 节点的每一次执行都会生成一个唯一的
|
|
85
|
+
* 节点的每一次执行都会生成一个唯一的actionId
|
|
75
86
|
*/
|
|
76
87
|
execute(params: ExecParams): Promise<NodeExecResult>;
|
|
77
88
|
/**
|
|
@@ -85,24 +96,24 @@ export default class BaseNode implements BaseNodeInterface {
|
|
|
85
96
|
* 节点的执行逻辑
|
|
86
97
|
* @overridable 可以自定义节点重写此方法。
|
|
87
98
|
* @param params.executionId 流程执行记录ID
|
|
88
|
-
* @param params.
|
|
99
|
+
* @param params.actionId 此节点执行记录ID
|
|
89
100
|
* @param params.nodeId 节点ID
|
|
90
101
|
*/
|
|
91
102
|
action(params: {
|
|
92
103
|
executionId: string;
|
|
93
|
-
|
|
104
|
+
actionId: string;
|
|
94
105
|
nodeId: string;
|
|
95
106
|
}): Promise<ActionResult>;
|
|
96
107
|
/**
|
|
97
108
|
* 节点的重新恢复执行逻辑
|
|
98
109
|
* @overridable 可以自定义节点重写此方法。
|
|
99
110
|
* @param params.executionId 流程执行记录ID
|
|
100
|
-
* @param params.
|
|
111
|
+
* @param params.actionId 此节点执行记录ID
|
|
101
112
|
* @param params.nodeId 节点ID
|
|
102
113
|
*/
|
|
103
114
|
onResume(params: {
|
|
104
115
|
executionId: string;
|
|
105
|
-
|
|
116
|
+
actionId: string;
|
|
106
117
|
nodeId: string;
|
|
107
118
|
data?: Record<string, any>;
|
|
108
119
|
}): Promise<void>;
|
package/es/nodes/BaseNode.js
CHANGED
|
@@ -56,7 +56,7 @@ var __values = (this && this.__values) || function(o) {
|
|
|
56
56
|
};
|
|
57
57
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
58
58
|
};
|
|
59
|
-
import {
|
|
59
|
+
import { ActionStatus } from '../constant/constant';
|
|
60
60
|
import { getExpressionResult } from '../expression';
|
|
61
61
|
var BaseNode = /** @class */ (function () {
|
|
62
62
|
function BaseNode(_a) {
|
|
@@ -65,13 +65,13 @@ var BaseNode = /** @class */ (function () {
|
|
|
65
65
|
this.incoming = nodeConfig.incoming;
|
|
66
66
|
this.nodeId = nodeConfig.id;
|
|
67
67
|
this.type = nodeConfig.type;
|
|
68
|
-
this.properties = nodeConfig.properties;
|
|
68
|
+
this.properties = nodeConfig.properties || {};
|
|
69
69
|
this.context = context;
|
|
70
70
|
this.globalData = globalData;
|
|
71
71
|
this.baseType = 'base';
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* 节点的每一次执行都会生成一个唯一的
|
|
74
|
+
* 节点的每一次执行都会生成一个唯一的actionId
|
|
75
75
|
*/
|
|
76
76
|
BaseNode.prototype.execute = function (params) {
|
|
77
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -80,18 +80,18 @@ var BaseNode = /** @class */ (function () {
|
|
|
80
80
|
switch (_a.label) {
|
|
81
81
|
case 0: return [4 /*yield*/, this.action({
|
|
82
82
|
executionId: params.executionId,
|
|
83
|
-
|
|
83
|
+
actionId: params.actionId,
|
|
84
84
|
nodeId: this.nodeId,
|
|
85
85
|
})];
|
|
86
86
|
case 1:
|
|
87
87
|
r = _a.sent();
|
|
88
|
-
if (!(!r || r.status ===
|
|
88
|
+
if (!(!r || r.status === ActionStatus.SUCCESS)) return [3 /*break*/, 3];
|
|
89
89
|
return [4 /*yield*/, this.getOutgoing()];
|
|
90
90
|
case 2:
|
|
91
91
|
outgoing = _a.sent();
|
|
92
92
|
params.next({
|
|
93
93
|
executionId: params.executionId,
|
|
94
|
-
|
|
94
|
+
actionId: params.actionId,
|
|
95
95
|
nodeId: this.nodeId,
|
|
96
96
|
nodeType: this.type,
|
|
97
97
|
properties: this.properties,
|
|
@@ -102,7 +102,7 @@ var BaseNode = /** @class */ (function () {
|
|
|
102
102
|
status: r && r.status,
|
|
103
103
|
detail: r && r.detail,
|
|
104
104
|
executionId: params.executionId,
|
|
105
|
-
|
|
105
|
+
actionId: params.actionId,
|
|
106
106
|
nodeId: this.nodeId,
|
|
107
107
|
nodeType: this.type,
|
|
108
108
|
properties: this.properties,
|
|
@@ -126,14 +126,14 @@ var BaseNode = /** @class */ (function () {
|
|
|
126
126
|
return [4 /*yield*/, this.onResume({
|
|
127
127
|
executionId: params.executionId,
|
|
128
128
|
nodeId: params.nodeId,
|
|
129
|
-
|
|
129
|
+
actionId: params.actionId,
|
|
130
130
|
data: params.data,
|
|
131
131
|
})];
|
|
132
132
|
case 2:
|
|
133
133
|
_a.sent();
|
|
134
134
|
params.next({
|
|
135
135
|
executionId: params.executionId,
|
|
136
|
-
|
|
136
|
+
actionId: params.actionId,
|
|
137
137
|
nodeId: this.nodeId,
|
|
138
138
|
nodeType: this.type,
|
|
139
139
|
properties: this.properties,
|
|
@@ -211,7 +211,7 @@ var BaseNode = /** @class */ (function () {
|
|
|
211
211
|
* 节点的执行逻辑
|
|
212
212
|
* @overridable 可以自定义节点重写此方法。
|
|
213
213
|
* @param params.executionId 流程执行记录ID
|
|
214
|
-
* @param params.
|
|
214
|
+
* @param params.actionId 此节点执行记录ID
|
|
215
215
|
* @param params.nodeId 节点ID
|
|
216
216
|
*/
|
|
217
217
|
BaseNode.prototype.action = function (params) {
|
|
@@ -225,7 +225,7 @@ var BaseNode = /** @class */ (function () {
|
|
|
225
225
|
* 节点的重新恢复执行逻辑
|
|
226
226
|
* @overridable 可以自定义节点重写此方法。
|
|
227
227
|
* @param params.executionId 流程执行记录ID
|
|
228
|
-
* @param params.
|
|
228
|
+
* @param params.actionId 此节点执行记录ID
|
|
229
229
|
* @param params.nodeId 节点ID
|
|
230
230
|
*/
|
|
231
231
|
BaseNode.prototype.onResume = function (params) {
|
package/es/recorder/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { RecorderData, RecorderInterface } from '../types.d';
|
|
2
2
|
export default class Recorder implements RecorderInterface {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
maxRecorder: number;
|
|
4
|
+
constructor();
|
|
5
|
+
setMaxRecorderNumber(maxRecorder: number): void;
|
|
6
|
+
addActionRecord(action: RecorderData): Promise<void>;
|
|
7
|
+
getActionRecord(actionId: string): Promise<RecorderData>;
|
|
8
|
+
getExecutionActions(executionId: any): Promise<any>;
|
|
6
9
|
clear(): void;
|
|
7
10
|
private pushExecution;
|
|
8
|
-
private
|
|
11
|
+
private popExecution;
|
|
12
|
+
private pushActionToExecution;
|
|
9
13
|
}
|
package/es/recorder/index.js
CHANGED
|
@@ -36,13 +36,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
};
|
|
37
37
|
import storage from '../util/storage';
|
|
38
38
|
var LOGICFLOW_ENGINE_INSTANCES = 'LOGICFLOW_ENGINE_INSTANCES';
|
|
39
|
+
var MAX_RECORDER = 100;
|
|
39
40
|
var Recorder = /** @class */ (function () {
|
|
40
41
|
function Recorder() {
|
|
42
|
+
this.maxRecorder = MAX_RECORDER;
|
|
41
43
|
}
|
|
44
|
+
Recorder.prototype.setMaxRecorderNumber = function (maxRecorder) {
|
|
45
|
+
this.maxRecorder = maxRecorder;
|
|
46
|
+
};
|
|
42
47
|
/*
|
|
43
|
-
* @param {Object}
|
|
48
|
+
* @param {Object} action
|
|
44
49
|
* {
|
|
45
|
-
*
|
|
50
|
+
* actionId: '',
|
|
46
51
|
* nodeId: '',
|
|
47
52
|
* executionId: '',
|
|
48
53
|
* nodeType: '',
|
|
@@ -50,29 +55,34 @@ var Recorder = /** @class */ (function () {
|
|
|
50
55
|
* properties: {},
|
|
51
56
|
* }
|
|
52
57
|
*/
|
|
53
|
-
Recorder.prototype.
|
|
58
|
+
Recorder.prototype.addActionRecord = function (action) {
|
|
54
59
|
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
-
var executionId,
|
|
60
|
+
var executionId, actionId, instanceData;
|
|
56
61
|
return __generator(this, function (_a) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
switch (_a.label) {
|
|
63
|
+
case 0:
|
|
64
|
+
executionId = action.executionId, actionId = action.actionId;
|
|
65
|
+
return [4 /*yield*/, this.getExecutionActions(executionId)];
|
|
66
|
+
case 1:
|
|
67
|
+
instanceData = _a.sent();
|
|
68
|
+
if (!instanceData) {
|
|
69
|
+
this.pushExecution(executionId);
|
|
70
|
+
}
|
|
71
|
+
this.pushActionToExecution(executionId, actionId);
|
|
72
|
+
storage.setItem(actionId, action);
|
|
73
|
+
return [2 /*return*/];
|
|
61
74
|
}
|
|
62
|
-
this.pushTaskToExecution(executionId, taskId);
|
|
63
|
-
storage.setItem(taskId, task);
|
|
64
|
-
return [2 /*return*/];
|
|
65
75
|
});
|
|
66
76
|
});
|
|
67
77
|
};
|
|
68
|
-
Recorder.prototype.
|
|
78
|
+
Recorder.prototype.getActionRecord = function (actionId) {
|
|
69
79
|
return __awaiter(this, void 0, void 0, function () {
|
|
70
80
|
return __generator(this, function (_a) {
|
|
71
|
-
return [2 /*return*/, storage.getItem(
|
|
81
|
+
return [2 /*return*/, storage.getItem(actionId)];
|
|
72
82
|
});
|
|
73
83
|
});
|
|
74
84
|
};
|
|
75
|
-
Recorder.prototype.
|
|
85
|
+
Recorder.prototype.getExecutionActions = function (executionId) {
|
|
76
86
|
return __awaiter(this, void 0, void 0, function () {
|
|
77
87
|
return __generator(this, function (_a) {
|
|
78
88
|
return [2 /*return*/, storage.getItem(executionId)];
|
|
@@ -84,21 +94,32 @@ var Recorder = /** @class */ (function () {
|
|
|
84
94
|
instance.forEach(function (executionId) {
|
|
85
95
|
storage.removeItem(executionId);
|
|
86
96
|
var instanceData = storage.getItem(executionId) || [];
|
|
87
|
-
instanceData.forEach(function (
|
|
88
|
-
storage.removeItem(
|
|
97
|
+
instanceData.forEach(function (actionId) {
|
|
98
|
+
storage.removeItem(actionId);
|
|
89
99
|
});
|
|
90
100
|
});
|
|
91
101
|
storage.removeItem(LOGICFLOW_ENGINE_INSTANCES);
|
|
92
102
|
};
|
|
93
103
|
Recorder.prototype.pushExecution = function (executionId) {
|
|
94
104
|
var instance = storage.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
|
|
105
|
+
if (instance.length >= this.maxRecorder) {
|
|
106
|
+
var removeItem = instance.shift();
|
|
107
|
+
this.popExecution(removeItem);
|
|
108
|
+
}
|
|
95
109
|
instance.push(executionId);
|
|
96
110
|
storage.setItem(LOGICFLOW_ENGINE_INSTANCES, instance);
|
|
97
111
|
};
|
|
98
|
-
Recorder.prototype.
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
112
|
+
Recorder.prototype.popExecution = function (executionId) {
|
|
113
|
+
var instanceData = storage.getItem(executionId) || [];
|
|
114
|
+
instanceData.forEach(function (actionId) {
|
|
115
|
+
storage.removeItem(actionId);
|
|
116
|
+
});
|
|
117
|
+
storage.removeItem(executionId);
|
|
118
|
+
};
|
|
119
|
+
Recorder.prototype.pushActionToExecution = function (executionId, actionId) {
|
|
120
|
+
var actions = storage.getItem(executionId) || [];
|
|
121
|
+
actions.push(actionId);
|
|
122
|
+
storage.setItem(executionId, actions);
|
|
102
123
|
};
|
|
103
124
|
return Recorder;
|
|
104
125
|
}());
|
package/es/util/ID.d.ts
CHANGED
package/es/util/ID.js
CHANGED
|
@@ -3,7 +3,11 @@ export var createExecId = function () {
|
|
|
3
3
|
var uuid = uuidv4();
|
|
4
4
|
return "exec-" + uuid;
|
|
5
5
|
};
|
|
6
|
-
export var
|
|
6
|
+
export var createActionId = function () {
|
|
7
7
|
var uuid = uuidv4();
|
|
8
|
-
return "
|
|
8
|
+
return "action-" + uuid;
|
|
9
|
+
};
|
|
10
|
+
export var createEngineId = function () {
|
|
11
|
+
var uuid = uuidv4();
|
|
12
|
+
return "engine-" + uuid;
|
|
9
13
|
};
|