@logicflow/engine 0.0.4 → 0.0.6
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 +23 -0
- package/cjs/FlowModel.js +3 -0
- package/cjs/Scheduler.js +33 -32
- package/cjs/constant/constant.js +3 -1
- package/cjs/index.js +10 -4
- package/cjs/nodes/BaseNode.js +16 -7
- package/cjs/recorder/index.js +25 -10
- package/es/FlowModel.d.ts +4 -4
- package/es/FlowModel.js +4 -1
- package/es/Scheduler.d.ts +2 -2
- package/es/Scheduler.js +34 -33
- package/es/constant/constant.d.ts +2 -0
- package/es/constant/constant.js +2 -0
- package/es/index.d.ts +6 -5
- package/es/index.js +9 -4
- package/es/nodes/BaseNode.d.ts +7 -17
- package/es/nodes/BaseNode.js +16 -7
- package/es/recorder/index.d.ts +5 -1
- package/es/recorder/index.js +25 -10
- package/lib/main.js +1 -1
- package/package.json +1 -1
package/es/nodes/BaseNode.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NextActionParam, ActionResult, ExecResumeParams, ExecParams, OutgoingConfig } from '../types.d';
|
|
2
2
|
export interface BaseNodeInterface {
|
|
3
3
|
outgoing: Record<string, any>[];
|
|
4
4
|
incoming: Record<string, any>[];
|
|
5
5
|
nodeId: string;
|
|
6
6
|
type: string;
|
|
7
7
|
readonly baseType: string;
|
|
8
|
-
execute(actionParam: any): Promise<
|
|
8
|
+
execute(actionParam: any): Promise<NextActionParam>;
|
|
9
9
|
}
|
|
10
10
|
export declare type NodeConstructor = {
|
|
11
11
|
new (config: {
|
|
@@ -17,7 +17,7 @@ export declare type NodeConstructor = {
|
|
|
17
17
|
executionId: string;
|
|
18
18
|
actionId: string;
|
|
19
19
|
nodeId: string;
|
|
20
|
-
}): Promise<
|
|
20
|
+
}): Promise<NextActionParam>;
|
|
21
21
|
onResume(params: {
|
|
22
22
|
executionId: string;
|
|
23
23
|
actionId: string;
|
|
@@ -30,11 +30,6 @@ export declare type IncomingConfig = {
|
|
|
30
30
|
properties?: Record<string, any>;
|
|
31
31
|
source: string;
|
|
32
32
|
};
|
|
33
|
-
export declare type OutgoingConfig = {
|
|
34
|
-
id: string;
|
|
35
|
-
target: string;
|
|
36
|
-
properties?: Record<string, any>;
|
|
37
|
-
};
|
|
38
33
|
export declare type NodeConfig = {
|
|
39
34
|
id: string;
|
|
40
35
|
type: string;
|
|
@@ -42,14 +37,6 @@ export declare type NodeConfig = {
|
|
|
42
37
|
incoming: IncomingConfig[];
|
|
43
38
|
outgoing: OutgoingConfig[];
|
|
44
39
|
};
|
|
45
|
-
export declare type NextActionParam = {
|
|
46
|
-
executionId: string;
|
|
47
|
-
nodeId: string;
|
|
48
|
-
actionId: string;
|
|
49
|
-
nodeType: string;
|
|
50
|
-
outgoing: OutgoingConfig[];
|
|
51
|
-
properties?: Record<string, any>;
|
|
52
|
-
};
|
|
53
40
|
export default class BaseNode implements BaseNodeInterface {
|
|
54
41
|
static nodeTypeName: string;
|
|
55
42
|
/**
|
|
@@ -84,7 +71,7 @@ export default class BaseNode implements BaseNodeInterface {
|
|
|
84
71
|
/**
|
|
85
72
|
* 节点的每一次执行都会生成一个唯一的actionId
|
|
86
73
|
*/
|
|
87
|
-
execute(params: ExecParams): Promise<
|
|
74
|
+
execute(params: ExecParams): Promise<NextActionParam>;
|
|
88
75
|
/**
|
|
89
76
|
* 节点在执行中断后,可以通过resume方法恢复执行。
|
|
90
77
|
* 自定义节点时不建议重写此方法
|
|
@@ -98,6 +85,9 @@ export default class BaseNode implements BaseNodeInterface {
|
|
|
98
85
|
* @param params.executionId 流程执行记录ID
|
|
99
86
|
* @param params.actionId 此节点执行记录ID
|
|
100
87
|
* @param params.nodeId 节点ID
|
|
88
|
+
* @returns 返回下一步的执行参数
|
|
89
|
+
* 当不返回时,表示此节点执行成功,流程会继续执行下一步。
|
|
90
|
+
* 当返回时,返回格式
|
|
101
91
|
*/
|
|
102
92
|
action(params: {
|
|
103
93
|
executionId: string;
|
package/es/nodes/BaseNode.js
CHANGED
|
@@ -75,7 +75,7 @@ var BaseNode = /** @class */ (function () {
|
|
|
75
75
|
*/
|
|
76
76
|
BaseNode.prototype.execute = function (params) {
|
|
77
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
var r, outgoing;
|
|
78
|
+
var r, status, outgoing, detail;
|
|
79
79
|
return __generator(this, function (_a) {
|
|
80
80
|
switch (_a.label) {
|
|
81
81
|
case 0: return [4 /*yield*/, this.action({
|
|
@@ -85,11 +85,15 @@ var BaseNode = /** @class */ (function () {
|
|
|
85
85
|
})];
|
|
86
86
|
case 1:
|
|
87
87
|
r = _a.sent();
|
|
88
|
-
|
|
88
|
+
status = r ? r.status : 'success';
|
|
89
|
+
if (!(status === ActionStatus.SUCCESS)) return [3 /*break*/, 3];
|
|
89
90
|
return [4 /*yield*/, this.getOutgoing()];
|
|
90
91
|
case 2:
|
|
91
92
|
outgoing = _a.sent();
|
|
93
|
+
detail = r ? r.detail : {};
|
|
92
94
|
params.next({
|
|
95
|
+
status: ActionStatus.SUCCESS,
|
|
96
|
+
detail: detail,
|
|
93
97
|
executionId: params.executionId,
|
|
94
98
|
actionId: params.actionId,
|
|
95
99
|
nodeId: this.nodeId,
|
|
@@ -99,13 +103,14 @@ var BaseNode = /** @class */ (function () {
|
|
|
99
103
|
});
|
|
100
104
|
_a.label = 3;
|
|
101
105
|
case 3: return [2 /*return*/, {
|
|
102
|
-
status:
|
|
106
|
+
status: status,
|
|
103
107
|
detail: r && r.detail,
|
|
104
108
|
executionId: params.executionId,
|
|
105
109
|
actionId: params.actionId,
|
|
106
110
|
nodeId: this.nodeId,
|
|
107
111
|
nodeType: this.type,
|
|
108
112
|
properties: this.properties,
|
|
113
|
+
outgoing: [],
|
|
109
114
|
}];
|
|
110
115
|
}
|
|
111
116
|
});
|
|
@@ -138,6 +143,7 @@ var BaseNode = /** @class */ (function () {
|
|
|
138
143
|
nodeType: this.type,
|
|
139
144
|
properties: this.properties,
|
|
140
145
|
outgoing: outgoing,
|
|
146
|
+
status: ActionStatus.SUCCESS,
|
|
141
147
|
});
|
|
142
148
|
return [2 /*return*/, undefined];
|
|
143
149
|
}
|
|
@@ -172,9 +178,9 @@ var BaseNode = /** @class */ (function () {
|
|
|
172
178
|
case 1:
|
|
173
179
|
result = _d.sent();
|
|
174
180
|
result.forEach(function (item, index) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
181
|
+
var out = _this.outgoing[index];
|
|
182
|
+
out.result = item;
|
|
183
|
+
outgoing.push(out);
|
|
178
184
|
});
|
|
179
185
|
return [2 /*return*/, outgoing];
|
|
180
186
|
}
|
|
@@ -213,11 +219,14 @@ var BaseNode = /** @class */ (function () {
|
|
|
213
219
|
* @param params.executionId 流程执行记录ID
|
|
214
220
|
* @param params.actionId 此节点执行记录ID
|
|
215
221
|
* @param params.nodeId 节点ID
|
|
222
|
+
* @returns 返回下一步的执行参数
|
|
223
|
+
* 当不返回时,表示此节点执行成功,流程会继续执行下一步。
|
|
224
|
+
* 当返回时,返回格式
|
|
216
225
|
*/
|
|
217
226
|
BaseNode.prototype.action = function (params) {
|
|
218
227
|
return __awaiter(this, void 0, void 0, function () {
|
|
219
228
|
return __generator(this, function (_a) {
|
|
220
|
-
return [2 /*return*/,
|
|
229
|
+
return [2 /*return*/, null];
|
|
221
230
|
});
|
|
222
231
|
});
|
|
223
232
|
};
|
package/es/recorder/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { RecorderData, RecorderInterface } from '../types.d';
|
|
2
2
|
export default class Recorder implements RecorderInterface {
|
|
3
3
|
maxRecorder: number;
|
|
4
|
-
|
|
4
|
+
instanceId: number;
|
|
5
|
+
constructor({ instanceId }: {
|
|
6
|
+
instanceId: any;
|
|
7
|
+
});
|
|
5
8
|
setMaxRecorderNumber(maxRecorder: number): void;
|
|
6
9
|
addActionRecord(action: RecorderData): Promise<void>;
|
|
7
10
|
getActionRecord(actionId: string): Promise<RecorderData>;
|
|
8
11
|
getExecutionActions(executionId: any): Promise<any>;
|
|
9
12
|
getExecutionList(): Promise<any>;
|
|
10
13
|
clear(): void;
|
|
14
|
+
clearInstance(instanceId: any): void;
|
|
11
15
|
private pushExecution;
|
|
12
16
|
private popExecution;
|
|
13
17
|
private pushActionToExecution;
|
package/es/recorder/index.js
CHANGED
|
@@ -37,9 +37,21 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
import storage from '../util/storage';
|
|
38
38
|
var LOGICFLOW_ENGINE_INSTANCES = 'LOGICFLOW_ENGINE_INSTANCES';
|
|
39
39
|
var MAX_RECORDER = 100;
|
|
40
|
+
var MAX_INSTANCE = 100;
|
|
40
41
|
var Recorder = /** @class */ (function () {
|
|
41
|
-
function Recorder() {
|
|
42
|
+
function Recorder(_a) {
|
|
43
|
+
var instanceId = _a.instanceId;
|
|
42
44
|
this.maxRecorder = MAX_RECORDER;
|
|
45
|
+
this.instanceId = instanceId;
|
|
46
|
+
var instances = storage.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
|
|
47
|
+
if (instances.indexOf(instanceId) === -1) {
|
|
48
|
+
instances.push(instanceId);
|
|
49
|
+
}
|
|
50
|
+
if (instances.length > MAX_INSTANCE) {
|
|
51
|
+
var clearInstance = instances.shift();
|
|
52
|
+
this.clearInstance(clearInstance);
|
|
53
|
+
}
|
|
54
|
+
storage.setItem(LOGICFLOW_ENGINE_INSTANCES, instances);
|
|
43
55
|
}
|
|
44
56
|
Recorder.prototype.setMaxRecorderNumber = function (maxRecorder) {
|
|
45
57
|
this.maxRecorder = maxRecorder;
|
|
@@ -93,30 +105,33 @@ var Recorder = /** @class */ (function () {
|
|
|
93
105
|
return __awaiter(this, void 0, void 0, function () {
|
|
94
106
|
var instances;
|
|
95
107
|
return __generator(this, function (_a) {
|
|
96
|
-
instances = storage.getItem(
|
|
108
|
+
instances = storage.getItem(this.instanceId) || [];
|
|
97
109
|
return [2 /*return*/, instances];
|
|
98
110
|
});
|
|
99
111
|
});
|
|
100
112
|
};
|
|
101
113
|
Recorder.prototype.clear = function () {
|
|
102
|
-
|
|
103
|
-
|
|
114
|
+
this.clearInstance(this.instanceId);
|
|
115
|
+
};
|
|
116
|
+
Recorder.prototype.clearInstance = function (instanceId) {
|
|
117
|
+
var instanceExecutions = storage.getItem(instanceId) || [];
|
|
118
|
+
instanceExecutions.forEach(function (executionId) {
|
|
104
119
|
storage.removeItem(executionId);
|
|
105
120
|
var instanceData = storage.getItem(executionId) || [];
|
|
106
121
|
instanceData.forEach(function (actionId) {
|
|
107
122
|
storage.removeItem(actionId);
|
|
108
123
|
});
|
|
109
124
|
});
|
|
110
|
-
storage.removeItem(
|
|
125
|
+
storage.removeItem(instanceId);
|
|
111
126
|
};
|
|
112
127
|
Recorder.prototype.pushExecution = function (executionId) {
|
|
113
|
-
var
|
|
114
|
-
if (
|
|
115
|
-
var removeItem =
|
|
128
|
+
var instanceExecutions = storage.getItem(this.instanceId) || [];
|
|
129
|
+
if (instanceExecutions.length >= this.maxRecorder) {
|
|
130
|
+
var removeItem = instanceExecutions.shift();
|
|
116
131
|
this.popExecution(removeItem);
|
|
117
132
|
}
|
|
118
|
-
|
|
119
|
-
storage.setItem(
|
|
133
|
+
instanceExecutions.push(executionId);
|
|
134
|
+
storage.setItem(this.instanceId, instanceExecutions);
|
|
120
135
|
};
|
|
121
136
|
Recorder.prototype.popExecution = function (executionId) {
|
|
122
137
|
var instanceData = storage.getItem(executionId) || [];
|