@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
|
@@ -0,0 +1,250 @@
|
|
|
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 { ActionStatus } 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
|
+
* 节点的每一次执行都会生成一个唯一的actionId
|
|
75
|
+
*/
|
|
76
|
+
BaseNode.prototype.execute = function (params) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var r, status, outgoing, detail;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0: return [4 /*yield*/, this.action({
|
|
82
|
+
executionId: params.executionId,
|
|
83
|
+
actionId: params.actionId,
|
|
84
|
+
nodeId: this.nodeId,
|
|
85
|
+
})];
|
|
86
|
+
case 1:
|
|
87
|
+
r = _a.sent();
|
|
88
|
+
status = r ? r.status : 'success';
|
|
89
|
+
if (!(status === ActionStatus.SUCCESS)) return [3 /*break*/, 3];
|
|
90
|
+
return [4 /*yield*/, this.getOutgoing()];
|
|
91
|
+
case 2:
|
|
92
|
+
outgoing = _a.sent();
|
|
93
|
+
detail = r ? r.detail : {};
|
|
94
|
+
params.next({
|
|
95
|
+
status: ActionStatus.SUCCESS,
|
|
96
|
+
detail: detail,
|
|
97
|
+
executionId: params.executionId,
|
|
98
|
+
actionId: params.actionId,
|
|
99
|
+
nodeId: this.nodeId,
|
|
100
|
+
nodeType: this.type,
|
|
101
|
+
properties: this.properties,
|
|
102
|
+
outgoing: outgoing,
|
|
103
|
+
});
|
|
104
|
+
_a.label = 3;
|
|
105
|
+
case 3: return [2 /*return*/, {
|
|
106
|
+
status: status,
|
|
107
|
+
detail: r && r.detail,
|
|
108
|
+
executionId: params.executionId,
|
|
109
|
+
actionId: params.actionId,
|
|
110
|
+
nodeId: this.nodeId,
|
|
111
|
+
nodeType: this.type,
|
|
112
|
+
properties: this.properties,
|
|
113
|
+
outgoing: [],
|
|
114
|
+
}];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* 节点在执行中断后,可以通过resume方法恢复执行。
|
|
121
|
+
* 自定义节点时不建议重写此方法
|
|
122
|
+
*/
|
|
123
|
+
BaseNode.prototype.resume = function (params) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
+
var outgoing;
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0: return [4 /*yield*/, this.getOutgoing()];
|
|
129
|
+
case 1:
|
|
130
|
+
outgoing = _a.sent();
|
|
131
|
+
return [4 /*yield*/, this.onResume({
|
|
132
|
+
executionId: params.executionId,
|
|
133
|
+
nodeId: params.nodeId,
|
|
134
|
+
actionId: params.actionId,
|
|
135
|
+
data: params.data,
|
|
136
|
+
})];
|
|
137
|
+
case 2:
|
|
138
|
+
_a.sent();
|
|
139
|
+
params.next({
|
|
140
|
+
executionId: params.executionId,
|
|
141
|
+
actionId: params.actionId,
|
|
142
|
+
nodeId: this.nodeId,
|
|
143
|
+
nodeType: this.type,
|
|
144
|
+
properties: this.properties,
|
|
145
|
+
outgoing: outgoing,
|
|
146
|
+
status: ActionStatus.SUCCESS,
|
|
147
|
+
});
|
|
148
|
+
return [2 /*return*/, undefined];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
BaseNode.prototype.getOutgoing = function () {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
var outgoing, expressions, _a, _b, item, properties, result;
|
|
156
|
+
var e_1, _c;
|
|
157
|
+
var _this = this;
|
|
158
|
+
return __generator(this, function (_d) {
|
|
159
|
+
switch (_d.label) {
|
|
160
|
+
case 0:
|
|
161
|
+
outgoing = [];
|
|
162
|
+
expressions = [];
|
|
163
|
+
try {
|
|
164
|
+
for (_a = __values(this.outgoing), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
165
|
+
item = _b.value;
|
|
166
|
+
properties = item.properties;
|
|
167
|
+
expressions.push(this.isPass(properties));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
171
|
+
finally {
|
|
172
|
+
try {
|
|
173
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
174
|
+
}
|
|
175
|
+
finally { if (e_1) throw e_1.error; }
|
|
176
|
+
}
|
|
177
|
+
return [4 /*yield*/, Promise.all(expressions)];
|
|
178
|
+
case 1:
|
|
179
|
+
result = _d.sent();
|
|
180
|
+
result.forEach(function (item, index) {
|
|
181
|
+
var out = _this.outgoing[index];
|
|
182
|
+
out.result = item;
|
|
183
|
+
outgoing.push(out);
|
|
184
|
+
});
|
|
185
|
+
return [2 /*return*/, outgoing];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
BaseNode.prototype.isPass = function (properties) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
192
|
+
var conditionExpression, result, e_2;
|
|
193
|
+
return __generator(this, function (_a) {
|
|
194
|
+
switch (_a.label) {
|
|
195
|
+
case 0:
|
|
196
|
+
if (!properties)
|
|
197
|
+
return [2 /*return*/, true];
|
|
198
|
+
conditionExpression = properties.conditionExpression;
|
|
199
|
+
if (!conditionExpression)
|
|
200
|
+
return [2 /*return*/, true];
|
|
201
|
+
_a.label = 1;
|
|
202
|
+
case 1:
|
|
203
|
+
_a.trys.push([1, 3, , 4]);
|
|
204
|
+
return [4 /*yield*/, getExpressionResult("isPassResult = (" + conditionExpression + ")", __assign({}, this.globalData))];
|
|
205
|
+
case 2:
|
|
206
|
+
result = _a.sent();
|
|
207
|
+
return [2 /*return*/, result.isPassResult];
|
|
208
|
+
case 3:
|
|
209
|
+
e_2 = _a.sent();
|
|
210
|
+
return [2 /*return*/, false];
|
|
211
|
+
case 4: return [2 /*return*/];
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* 节点的执行逻辑
|
|
218
|
+
* @overridable 可以自定义节点重写此方法。
|
|
219
|
+
* @param params.executionId 流程执行记录ID
|
|
220
|
+
* @param params.actionId 此节点执行记录ID
|
|
221
|
+
* @param params.nodeId 节点ID
|
|
222
|
+
* @returns 返回下一步的执行参数
|
|
223
|
+
* 当不返回时,表示此节点执行成功,流程会继续执行下一步。
|
|
224
|
+
* 当返回时,返回格式
|
|
225
|
+
*/
|
|
226
|
+
BaseNode.prototype.action = function (params) {
|
|
227
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
228
|
+
return __generator(this, function (_a) {
|
|
229
|
+
return [2 /*return*/, null];
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* 节点的重新恢复执行逻辑
|
|
235
|
+
* @overridable 可以自定义节点重写此方法。
|
|
236
|
+
* @param params.executionId 流程执行记录ID
|
|
237
|
+
* @param params.actionId 此节点执行记录ID
|
|
238
|
+
* @param params.nodeId 节点ID
|
|
239
|
+
*/
|
|
240
|
+
BaseNode.prototype.onResume = function (params) {
|
|
241
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
242
|
+
return __generator(this, function (_a) {
|
|
243
|
+
return [2 /*return*/, undefined];
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
BaseNode.nodeTypeName = 'BaseNode';
|
|
248
|
+
return BaseNode;
|
|
249
|
+
}());
|
|
250
|
+
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;
|
package/es/recorder/index.d.ts
CHANGED
|
@@ -1,46 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
export declare const MAX_INSTANCE = 100;
|
|
4
|
-
export declare const LOGICFLOW_ENGINE_INSTANCES = "LOGICFLOW_ENGINE_INSTANCES";
|
|
5
|
-
export declare class Recorder implements Recorder.Base {
|
|
6
|
-
instanceId: Engine.Key;
|
|
1
|
+
import type { RecorderData, RecorderInterface } from '../types.d';
|
|
2
|
+
export default class Recorder implements RecorderInterface {
|
|
7
3
|
maxRecorder: number;
|
|
4
|
+
instanceId: number;
|
|
8
5
|
constructor({ instanceId }: {
|
|
9
6
|
instanceId: any;
|
|
10
7
|
});
|
|
11
|
-
setMaxRecorderNumber(
|
|
8
|
+
setMaxRecorderNumber(maxRecorder: number): void;
|
|
12
9
|
setItem(key: string | number, value: unknown): void;
|
|
13
10
|
getItem(key: string | number): any;
|
|
14
|
-
|
|
11
|
+
addActionRecord(action: RecorderData): Promise<void>;
|
|
12
|
+
getActionRecord(actionId: string): Promise<RecorderData>;
|
|
13
|
+
getExecutionActions(executionId: any): Promise<any>;
|
|
15
14
|
getExecutionList(): Promise<any>;
|
|
16
|
-
|
|
15
|
+
clear(): void;
|
|
16
|
+
clearInstance(instanceId: any): void;
|
|
17
|
+
private pushExecution;
|
|
17
18
|
private popExecution;
|
|
18
19
|
private pushActionToExecution;
|
|
19
|
-
/**
|
|
20
|
-
* @param {Object} action
|
|
21
|
-
* {
|
|
22
|
-
* actionId: '',
|
|
23
|
-
* nodeId: '',
|
|
24
|
-
* executionId: '',
|
|
25
|
-
* nodeType: '',
|
|
26
|
-
* timestamp: '',
|
|
27
|
-
* properties: {},
|
|
28
|
-
* }
|
|
29
|
-
*/
|
|
30
|
-
addActionRecord(action: Recorder.Info): Promise<void>;
|
|
31
|
-
getActionRecord(actionId: Engine.Key): Promise<Recorder.Info>;
|
|
32
|
-
clear(): void;
|
|
33
|
-
clearInstance(instanceId: Engine.Key): void;
|
|
34
|
-
}
|
|
35
|
-
export declare namespace Recorder {
|
|
36
|
-
interface Base {
|
|
37
|
-
addActionRecord: (action: Info) => Promise<void>;
|
|
38
|
-
getActionRecord: (actionId: Engine.Key) => Promise<Info>;
|
|
39
|
-
getExecutionActions: (executionId: Engine.Key) => Promise<string[]>;
|
|
40
|
-
clear: () => void;
|
|
41
|
-
}
|
|
42
|
-
type Info = {
|
|
43
|
-
timestamp: number;
|
|
44
|
-
} & Engine.NextActionParam;
|
|
45
20
|
}
|
|
46
|
-
export default Recorder;
|
package/es/recorder/index.js
CHANGED
|
@@ -1,113 +1,166 @@
|
|
|
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 };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import storage from '../util/storage';
|
|
38
|
+
var LOGICFLOW_ENGINE_INSTANCES = 'LOGICFLOW_ENGINE_INSTANCES';
|
|
39
|
+
var MAX_RECORDER = 100;
|
|
40
|
+
var MAX_INSTANCE = 100;
|
|
41
|
+
var Recorder = /** @class */ (function () {
|
|
42
|
+
function Recorder(_a) {
|
|
43
|
+
var instanceId = _a.instanceId;
|
|
9
44
|
this.maxRecorder = MAX_RECORDER;
|
|
10
|
-
|
|
45
|
+
this.instanceId = instanceId;
|
|
46
|
+
var instances = this.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
|
|
11
47
|
if (instances.indexOf(instanceId) === -1) {
|
|
12
48
|
instances.push(instanceId);
|
|
13
49
|
}
|
|
14
50
|
if (instances.length > MAX_INSTANCE) {
|
|
15
|
-
|
|
51
|
+
var clearInstance = instances.shift();
|
|
16
52
|
this.clearInstance(clearInstance);
|
|
17
53
|
}
|
|
18
54
|
this.setItem(LOGICFLOW_ENGINE_INSTANCES, instances);
|
|
19
55
|
}
|
|
20
|
-
setMaxRecorderNumber(
|
|
21
|
-
this.maxRecorder =
|
|
22
|
-
}
|
|
56
|
+
Recorder.prototype.setMaxRecorderNumber = function (maxRecorder) {
|
|
57
|
+
this.maxRecorder = maxRecorder;
|
|
58
|
+
};
|
|
23
59
|
// 将存储 storage 的方法收敛到此处,并在此处做异常处理 - setItem
|
|
24
|
-
setItem(key, value) {
|
|
60
|
+
Recorder.prototype.setItem = function (key, value) {
|
|
25
61
|
try {
|
|
26
62
|
storage.setItem(key, value);
|
|
27
63
|
}
|
|
28
64
|
catch (error) {
|
|
29
|
-
console.
|
|
65
|
+
console.log('Ops, something wrong with storage.setItem');
|
|
30
66
|
storage.clear();
|
|
31
67
|
storage.setItem(key, value);
|
|
32
68
|
}
|
|
33
|
-
}
|
|
69
|
+
};
|
|
34
70
|
// getItem 方法
|
|
35
|
-
getItem(key) {
|
|
71
|
+
Recorder.prototype.getItem = function (key) {
|
|
36
72
|
return storage.getItem(key);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
73
|
+
};
|
|
74
|
+
/*
|
|
75
|
+
* @param {Object} action
|
|
76
|
+
* {
|
|
77
|
+
* actionId: '',
|
|
78
|
+
* nodeId: '',
|
|
79
|
+
* executionId: '',
|
|
80
|
+
* nodeType: '',
|
|
81
|
+
* timestamp: '',
|
|
82
|
+
* properties: {},
|
|
83
|
+
* }
|
|
84
|
+
*/
|
|
85
|
+
Recorder.prototype.addActionRecord = function (action) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
var executionId, actionId, instanceData;
|
|
88
|
+
return __generator(this, function (_a) {
|
|
89
|
+
switch (_a.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
executionId = action.executionId, actionId = action.actionId;
|
|
92
|
+
return [4 /*yield*/, this.getExecutionActions(executionId)];
|
|
93
|
+
case 1:
|
|
94
|
+
instanceData = _a.sent();
|
|
95
|
+
if (!instanceData) {
|
|
96
|
+
this.pushExecution(executionId);
|
|
97
|
+
}
|
|
98
|
+
this.pushActionToExecution(executionId, actionId);
|
|
99
|
+
this.setItem(actionId, action);
|
|
100
|
+
return [2 /*return*/];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
41
103
|
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return __awaiter(this, void 0, void 0, function
|
|
45
|
-
return this
|
|
104
|
+
};
|
|
105
|
+
Recorder.prototype.getActionRecord = function (actionId) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
return __generator(this, function (_a) {
|
|
108
|
+
return [2 /*return*/, this.getItem(actionId)];
|
|
109
|
+
});
|
|
46
110
|
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
111
|
+
};
|
|
112
|
+
Recorder.prototype.getExecutionActions = function (executionId) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
114
|
+
return __generator(this, function (_a) {
|
|
115
|
+
return [2 /*return*/, this.getItem(executionId)];
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
Recorder.prototype.getExecutionList = function () {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
+
var instances;
|
|
122
|
+
return __generator(this, function (_a) {
|
|
123
|
+
instances = this.getItem(this.instanceId) || [];
|
|
124
|
+
return [2 /*return*/, instances];
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
Recorder.prototype.clear = function () {
|
|
129
|
+
this.clearInstance(this.instanceId);
|
|
130
|
+
};
|
|
131
|
+
Recorder.prototype.clearInstance = function (instanceId) {
|
|
132
|
+
var _this = this;
|
|
133
|
+
var instanceExecutions = this.getItem(instanceId) || [];
|
|
134
|
+
instanceExecutions.forEach(function (executionId) {
|
|
135
|
+
storage.removeItem(executionId);
|
|
136
|
+
var instanceData = _this.getItem(executionId) || [];
|
|
137
|
+
instanceData.forEach(function (actionId) {
|
|
138
|
+
storage.removeItem(actionId);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
storage.removeItem(instanceId);
|
|
142
|
+
};
|
|
143
|
+
Recorder.prototype.pushExecution = function (executionId) {
|
|
144
|
+
var instanceExecutions = this.getItem(this.instanceId) || [];
|
|
50
145
|
if (instanceExecutions.length >= this.maxRecorder) {
|
|
51
|
-
|
|
52
|
-
this.popExecution(
|
|
146
|
+
var removeItem = instanceExecutions.shift();
|
|
147
|
+
this.popExecution(removeItem);
|
|
53
148
|
}
|
|
54
149
|
instanceExecutions.push(executionId);
|
|
55
150
|
this.setItem(this.instanceId, instanceExecutions);
|
|
56
|
-
}
|
|
57
|
-
popExecution(executionId) {
|
|
58
|
-
|
|
59
|
-
instanceData.forEach((actionId)
|
|
151
|
+
};
|
|
152
|
+
Recorder.prototype.popExecution = function (executionId) {
|
|
153
|
+
var instanceData = this.getItem(executionId) || [];
|
|
154
|
+
instanceData.forEach(function (actionId) {
|
|
60
155
|
storage.removeItem(actionId);
|
|
61
156
|
});
|
|
62
157
|
storage.removeItem(executionId);
|
|
63
|
-
}
|
|
64
|
-
pushActionToExecution(executionId, actionId) {
|
|
65
|
-
|
|
158
|
+
};
|
|
159
|
+
Recorder.prototype.pushActionToExecution = function (executionId, actionId) {
|
|
160
|
+
var actions = this.getItem(executionId) || [];
|
|
66
161
|
actions.push(actionId);
|
|
67
162
|
this.setItem(executionId, actions);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* {
|
|
72
|
-
* actionId: '',
|
|
73
|
-
* nodeId: '',
|
|
74
|
-
* executionId: '',
|
|
75
|
-
* nodeType: '',
|
|
76
|
-
* timestamp: '',
|
|
77
|
-
* properties: {},
|
|
78
|
-
* }
|
|
79
|
-
*/
|
|
80
|
-
addActionRecord(action) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
const { executionId, actionId } = action;
|
|
83
|
-
const instanceData = yield this.getExecutionActions(executionId);
|
|
84
|
-
if (!instanceData) {
|
|
85
|
-
this.addExecution(executionId);
|
|
86
|
-
}
|
|
87
|
-
this.pushActionToExecution(executionId, actionId);
|
|
88
|
-
this.setItem(actionId, action);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
getActionRecord(actionId) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
return this.getItem(actionId);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
clear() {
|
|
97
|
-
this.clearInstance(this.instanceId);
|
|
98
|
-
}
|
|
99
|
-
clearInstance(instanceId) {
|
|
100
|
-
const instanceExecutions = this.getItem(instanceId) || [];
|
|
101
|
-
// TODO: 完善类型定义
|
|
102
|
-
instanceExecutions.forEach((executionId) => {
|
|
103
|
-
storage.removeItem(executionId);
|
|
104
|
-
const instanceData = this.getItem(executionId) || [];
|
|
105
|
-
instanceData.forEach((actionId) => {
|
|
106
|
-
storage.removeItem(actionId);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
storage.removeItem(instanceId);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
163
|
+
};
|
|
164
|
+
return Recorder;
|
|
165
|
+
}());
|
|
112
166
|
export default Recorder;
|
|
113
|
-
//# sourceMappingURL=index.js.map
|
package/es/util/ID.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
export var createExecId = function () {
|
|
3
|
+
var uuid = uuidv4();
|
|
4
|
+
return "exec-" + uuid;
|
|
5
|
+
};
|
|
6
|
+
export var createActionId = function () {
|
|
7
|
+
var uuid = uuidv4();
|
|
8
|
+
return "action-" + uuid;
|
|
9
|
+
};
|
|
10
|
+
export var createEngineId = function () {
|
|
11
|
+
var uuid = uuidv4();
|
|
12
|
+
return "engine-" + uuid;
|
|
13
|
+
};
|