@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,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var storage_1 = require("../util/storage");
|
|
40
|
+
var LOGICFLOW_ENGINE_INSTANCES = 'LOGICFLOW_ENGINE_INSTANCES';
|
|
41
|
+
var MAX_RECORDER = 100;
|
|
42
|
+
var MAX_INSTANCE = 100;
|
|
43
|
+
var Recorder = /** @class */ (function () {
|
|
44
|
+
function Recorder(_a) {
|
|
45
|
+
var instanceId = _a.instanceId;
|
|
46
|
+
this.maxRecorder = MAX_RECORDER;
|
|
47
|
+
this.instanceId = instanceId;
|
|
48
|
+
var instances = this.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
|
|
49
|
+
if (instances.indexOf(instanceId) === -1) {
|
|
50
|
+
instances.push(instanceId);
|
|
51
|
+
}
|
|
52
|
+
if (instances.length > MAX_INSTANCE) {
|
|
53
|
+
var clearInstance = instances.shift();
|
|
54
|
+
this.clearInstance(clearInstance);
|
|
55
|
+
}
|
|
56
|
+
this.setItem(LOGICFLOW_ENGINE_INSTANCES, instances);
|
|
57
|
+
}
|
|
58
|
+
Recorder.prototype.setMaxRecorderNumber = function (maxRecorder) {
|
|
59
|
+
this.maxRecorder = maxRecorder;
|
|
60
|
+
};
|
|
61
|
+
// 将存储 storage 的方法收敛到此处,并在此处做异常处理 - setItem
|
|
62
|
+
Recorder.prototype.setItem = function (key, value) {
|
|
63
|
+
try {
|
|
64
|
+
storage_1.default.setItem(key, value);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.log('Ops, something wrong with storage.setItem');
|
|
68
|
+
storage_1.default.clear();
|
|
69
|
+
storage_1.default.setItem(key, value);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
// getItem 方法
|
|
73
|
+
Recorder.prototype.getItem = function (key) {
|
|
74
|
+
return storage_1.default.getItem(key);
|
|
75
|
+
};
|
|
76
|
+
/*
|
|
77
|
+
* @param {Object} action
|
|
78
|
+
* {
|
|
79
|
+
* actionId: '',
|
|
80
|
+
* nodeId: '',
|
|
81
|
+
* executionId: '',
|
|
82
|
+
* nodeType: '',
|
|
83
|
+
* timestamp: '',
|
|
84
|
+
* properties: {},
|
|
85
|
+
* }
|
|
86
|
+
*/
|
|
87
|
+
Recorder.prototype.addActionRecord = function (action) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var executionId, actionId, instanceData;
|
|
90
|
+
return __generator(this, function (_a) {
|
|
91
|
+
switch (_a.label) {
|
|
92
|
+
case 0:
|
|
93
|
+
executionId = action.executionId, actionId = action.actionId;
|
|
94
|
+
return [4 /*yield*/, this.getExecutionActions(executionId)];
|
|
95
|
+
case 1:
|
|
96
|
+
instanceData = _a.sent();
|
|
97
|
+
if (!instanceData) {
|
|
98
|
+
this.pushExecution(executionId);
|
|
99
|
+
}
|
|
100
|
+
this.pushActionToExecution(executionId, actionId);
|
|
101
|
+
this.setItem(actionId, action);
|
|
102
|
+
return [2 /*return*/];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
Recorder.prototype.getActionRecord = function (actionId) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
return [2 /*return*/, this.getItem(actionId)];
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
Recorder.prototype.getExecutionActions = function (executionId) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
return [2 /*return*/, this.getItem(executionId)];
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
Recorder.prototype.getExecutionList = function () {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
123
|
+
var instances;
|
|
124
|
+
return __generator(this, function (_a) {
|
|
125
|
+
instances = this.getItem(this.instanceId) || [];
|
|
126
|
+
return [2 /*return*/, instances];
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
Recorder.prototype.clear = function () {
|
|
131
|
+
this.clearInstance(this.instanceId);
|
|
132
|
+
};
|
|
133
|
+
Recorder.prototype.clearInstance = function (instanceId) {
|
|
134
|
+
var _this = this;
|
|
135
|
+
var instanceExecutions = this.getItem(instanceId) || [];
|
|
136
|
+
instanceExecutions.forEach(function (executionId) {
|
|
137
|
+
storage_1.default.removeItem(executionId);
|
|
138
|
+
var instanceData = _this.getItem(executionId) || [];
|
|
139
|
+
instanceData.forEach(function (actionId) {
|
|
140
|
+
storage_1.default.removeItem(actionId);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
storage_1.default.removeItem(instanceId);
|
|
144
|
+
};
|
|
145
|
+
Recorder.prototype.pushExecution = function (executionId) {
|
|
146
|
+
var instanceExecutions = this.getItem(this.instanceId) || [];
|
|
147
|
+
if (instanceExecutions.length >= this.maxRecorder) {
|
|
148
|
+
var removeItem = instanceExecutions.shift();
|
|
149
|
+
this.popExecution(removeItem);
|
|
150
|
+
}
|
|
151
|
+
instanceExecutions.push(executionId);
|
|
152
|
+
this.setItem(this.instanceId, instanceExecutions);
|
|
153
|
+
};
|
|
154
|
+
Recorder.prototype.popExecution = function (executionId) {
|
|
155
|
+
var instanceData = this.getItem(executionId) || [];
|
|
156
|
+
instanceData.forEach(function (actionId) {
|
|
157
|
+
storage_1.default.removeItem(actionId);
|
|
158
|
+
});
|
|
159
|
+
storage_1.default.removeItem(executionId);
|
|
160
|
+
};
|
|
161
|
+
Recorder.prototype.pushActionToExecution = function (executionId, actionId) {
|
|
162
|
+
var actions = this.getItem(executionId) || [];
|
|
163
|
+
actions.push(actionId);
|
|
164
|
+
this.setItem(executionId, actions);
|
|
165
|
+
};
|
|
166
|
+
return Recorder;
|
|
167
|
+
}());
|
|
168
|
+
exports.default = Recorder;
|
package/cjs/util/ID.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEngineId = exports.createActionId = exports.createExecId = void 0;
|
|
4
|
+
var uuid_1 = require("uuid");
|
|
5
|
+
exports.createExecId = function () {
|
|
6
|
+
var uuid = uuid_1.v4();
|
|
7
|
+
return "exec-" + uuid;
|
|
8
|
+
};
|
|
9
|
+
exports.createActionId = function () {
|
|
10
|
+
var uuid = uuid_1.v4();
|
|
11
|
+
return "action-" + uuid;
|
|
12
|
+
};
|
|
13
|
+
exports.createEngineId = function () {
|
|
14
|
+
var uuid = uuid_1.v4();
|
|
15
|
+
return "engine-" + uuid;
|
|
16
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The one and only way of getting global scope in all environments
|
|
3
|
+
// https://stackoverflow.com/q/3277182/1008999
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.isInNodeJS = exports.isInWebWorker = exports.isInBrowser = exports.globalScope = void 0;
|
|
6
|
+
var isInBrowser = typeof window === 'object' && window.window === window;
|
|
7
|
+
exports.isInBrowser = isInBrowser;
|
|
8
|
+
var isInNodeJS = typeof global === 'object' && global.global === global;
|
|
9
|
+
exports.isInNodeJS = isInNodeJS;
|
|
10
|
+
// eslint-disable-next-line no-restricted-globals
|
|
11
|
+
var isInWebWorker = !isInBrowser && typeof self === 'object' && self.constructor;
|
|
12
|
+
exports.isInWebWorker = isInWebWorker;
|
|
13
|
+
var globalScope = (function () {
|
|
14
|
+
if (isInBrowser) {
|
|
15
|
+
return window;
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line no-restricted-globals
|
|
18
|
+
if (typeof self === 'object' && self.self === self) { // web workers
|
|
19
|
+
// eslint-disable-next-line no-restricted-globals
|
|
20
|
+
return self;
|
|
21
|
+
}
|
|
22
|
+
if (isInNodeJS) {
|
|
23
|
+
return global;
|
|
24
|
+
}
|
|
25
|
+
if (typeof globalThis === 'object') {
|
|
26
|
+
return globalThis;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
eval: function () { return undefined; },
|
|
30
|
+
};
|
|
31
|
+
})();
|
|
32
|
+
exports.globalScope = globalScope;
|
|
@@ -3,46 +3,45 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
/**
|
|
4
4
|
* 存储执行记录
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
var global_1 = require("./global");
|
|
7
7
|
if (!global_1.globalScope.sessionStorage) {
|
|
8
|
-
|
|
8
|
+
var storage_1 = {
|
|
9
9
|
data: {},
|
|
10
|
-
setItem(key, value) {
|
|
11
|
-
|
|
10
|
+
setItem: function (key, value) {
|
|
11
|
+
storage_1.data[key] = value;
|
|
12
12
|
},
|
|
13
|
-
getItem(key) {
|
|
14
|
-
return
|
|
13
|
+
getItem: function (key) {
|
|
14
|
+
return storage_1.data[key];
|
|
15
15
|
},
|
|
16
|
-
removeItem(key) {
|
|
17
|
-
delete
|
|
16
|
+
removeItem: function (key) {
|
|
17
|
+
delete storage_1.data[key];
|
|
18
18
|
},
|
|
19
|
-
clear() {
|
|
20
|
-
|
|
19
|
+
clear: function () {
|
|
20
|
+
storage_1.data = {};
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
|
-
global_1.globalScope.sessionStorage =
|
|
23
|
+
global_1.globalScope.sessionStorage = storage_1;
|
|
24
24
|
}
|
|
25
25
|
exports.default = {
|
|
26
|
-
setItem(key, value) {
|
|
26
|
+
setItem: function (key, value) {
|
|
27
27
|
if (typeof value === 'object') {
|
|
28
28
|
value = JSON.stringify(value);
|
|
29
29
|
}
|
|
30
30
|
global_1.globalScope.sessionStorage.setItem(key, value);
|
|
31
31
|
},
|
|
32
|
-
getItem(key) {
|
|
33
|
-
|
|
32
|
+
getItem: function (key) {
|
|
33
|
+
var value = global_1.globalScope.sessionStorage.getItem(key);
|
|
34
34
|
try {
|
|
35
35
|
return JSON.parse(value);
|
|
36
36
|
}
|
|
37
|
-
catch (
|
|
37
|
+
catch (e) {
|
|
38
38
|
return value;
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
-
removeItem(key) {
|
|
41
|
+
removeItem: function (key) {
|
|
42
42
|
global_1.globalScope.sessionStorage.removeItem(key);
|
|
43
43
|
},
|
|
44
|
-
clear() {
|
|
44
|
+
clear: function () {
|
|
45
45
|
global_1.globalScope.sessionStorage.clear();
|
|
46
46
|
},
|
|
47
47
|
};
|
|
48
|
-
//# sourceMappingURL=storage.js.map
|
package/es/EventEmitter.d.ts
CHANGED
|
@@ -1,37 +1,7 @@
|
|
|
1
|
-
export interface EventType {
|
|
2
|
-
readonly callback: (params?: any) => void;
|
|
3
|
-
readonly once: boolean;
|
|
4
|
-
}
|
|
5
|
-
export type EventArgs = Record<string, unknown>;
|
|
6
|
-
export type EventsType = Record<string, EventType[]>;
|
|
7
|
-
export type CallbackType = (...args: unknown[]) => void;
|
|
8
1
|
export default class EventEmitter {
|
|
9
|
-
|
|
2
|
+
_events: Record<string, any>;
|
|
10
3
|
constructor();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @param callback 回调方法
|
|
15
|
-
* @param once 是否触发一次
|
|
16
|
-
* @returns 当前 EventEmitter 实例
|
|
17
|
-
*/
|
|
18
|
-
on(evtKey: string, callback: CallbackType, once?: boolean): void;
|
|
19
|
-
/**
|
|
20
|
-
* 取消监听一个事件,或者一个 Channel
|
|
21
|
-
* @param evtKey
|
|
22
|
-
* @param callback
|
|
23
|
-
*/
|
|
24
|
-
off(evtKey: string, callback?: CallbackType): void;
|
|
25
|
-
/**
|
|
26
|
-
* 主动触发事件
|
|
27
|
-
* @param evtKey 触发事件名称
|
|
28
|
-
* @param eventArgs 事件参数
|
|
29
|
-
*/
|
|
30
|
-
emit(evtKey: string, eventArgs: EventArgs): void;
|
|
31
|
-
/**
|
|
32
|
-
* 获取当前所有事件
|
|
33
|
-
* @returns _events
|
|
34
|
-
*/
|
|
35
|
-
getEvents(): EventsType;
|
|
4
|
+
on(evKey: any, callback: any, once?: boolean): void;
|
|
5
|
+
emit(evt: any, eventArgs: any): void;
|
|
6
|
+
off(evt: any, callback: any): void;
|
|
36
7
|
}
|
|
37
|
-
export { EventEmitter };
|
package/es/EventEmitter.js
CHANGED
|
@@ -1,90 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var EventEmitter = /** @class */ (function () {
|
|
2
|
+
function EventEmitter() {
|
|
3
3
|
this._events = {};
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @returns 当前 EventEmitter 实例
|
|
11
|
-
*/
|
|
12
|
-
on(evtKey, callback, once) {
|
|
13
|
-
evtKey = evtKey.trim();
|
|
14
|
-
if (!this._events[evtKey]) {
|
|
15
|
-
this._events[evtKey] = [];
|
|
5
|
+
EventEmitter.prototype.on = function (evKey, callback, once) {
|
|
6
|
+
if (once === void 0) { once = false; }
|
|
7
|
+
evKey = evKey.trim();
|
|
8
|
+
if (!this._events[evKey]) {
|
|
9
|
+
this._events[evKey] = [];
|
|
16
10
|
}
|
|
17
|
-
this._events[
|
|
18
|
-
callback,
|
|
11
|
+
this._events[evKey].push({
|
|
12
|
+
callback: callback,
|
|
19
13
|
once: !!once,
|
|
20
14
|
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @param callback
|
|
26
|
-
*/
|
|
27
|
-
off(evtKey, callback) {
|
|
28
|
-
if (!evtKey) {
|
|
29
|
-
// evtKey 为空全部清除
|
|
30
|
-
this._events = {};
|
|
31
|
-
}
|
|
32
|
-
if (!callback) {
|
|
33
|
-
// evtKey 存在,callback 为空,清除事件所有方法
|
|
34
|
-
delete this._events[evtKey];
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
// evtKey 存在,callback 存在,清除匹配的
|
|
38
|
-
const events = this._events[evtKey] || [];
|
|
39
|
-
let { length } = events;
|
|
40
|
-
for (let i = 0; i < length; i++) {
|
|
41
|
-
if (events[i].callback === callback) {
|
|
42
|
-
events.splice(i, 1);
|
|
43
|
-
length--;
|
|
44
|
-
i--;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (events.length === 0) {
|
|
48
|
-
delete this._events[evtKey];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* 主动触发事件
|
|
54
|
-
* @param evtKey 触发事件名称
|
|
55
|
-
* @param eventArgs 事件参数
|
|
56
|
-
*/
|
|
57
|
-
emit(evtKey, eventArgs) {
|
|
58
|
-
const events = this._events[evtKey] || [];
|
|
15
|
+
};
|
|
16
|
+
EventEmitter.prototype.emit = function (evt, eventArgs) {
|
|
17
|
+
var _this = this;
|
|
18
|
+
var events = this._events[evt] || [];
|
|
59
19
|
// 实际的处理 emit 方法
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
for (
|
|
20
|
+
var doEmit = function (es) {
|
|
21
|
+
var length = es.length;
|
|
22
|
+
for (var i = 0; i < length; i++) {
|
|
63
23
|
if (!es[i]) {
|
|
64
24
|
// eslint-disable-next-line no-continue
|
|
65
25
|
continue;
|
|
66
26
|
}
|
|
67
|
-
|
|
27
|
+
var _a = es[i], callback = _a.callback, once = _a.once;
|
|
68
28
|
if (once) {
|
|
69
29
|
es.splice(i, 1);
|
|
70
30
|
if (es.length === 0) {
|
|
71
|
-
delete
|
|
31
|
+
delete _this._events[evt];
|
|
72
32
|
}
|
|
73
33
|
length--;
|
|
74
34
|
i--;
|
|
75
35
|
}
|
|
76
|
-
callback.apply(
|
|
36
|
+
callback.apply(_this, [eventArgs]);
|
|
77
37
|
}
|
|
78
38
|
};
|
|
79
39
|
doEmit(events);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
40
|
+
};
|
|
41
|
+
EventEmitter.prototype.off = function (evt, callback) {
|
|
42
|
+
if (!evt) {
|
|
43
|
+
// evt 为空全部清除
|
|
44
|
+
this._events = {};
|
|
45
|
+
}
|
|
46
|
+
if (!callback) {
|
|
47
|
+
// evt 存在,callback 为空,清除事件所有方法
|
|
48
|
+
delete this._events[evt];
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// evt 存在,callback 存在,清除匹配的
|
|
52
|
+
var events = this._events[evt] || [];
|
|
53
|
+
var length_1 = events.length;
|
|
54
|
+
for (var i = 0; i < length_1; i++) {
|
|
55
|
+
if (events[i].callback === callback) {
|
|
56
|
+
events.splice(i, 1);
|
|
57
|
+
length_1--;
|
|
58
|
+
i--;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (events.length === 0) {
|
|
62
|
+
delete this._events[evt];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
return EventEmitter;
|
|
67
|
+
}());
|
|
68
|
+
export default EventEmitter;
|
package/es/FlowModel.d.ts
CHANGED
|
@@ -1,58 +1,76 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
export declare
|
|
1
|
+
import type { NodeConfig, NodeConstructor } from './nodes/BaseNode';
|
|
2
|
+
import type Recorder from './recorder';
|
|
3
|
+
import Scheduler from './Scheduler';
|
|
4
|
+
import type { ActionParam, NextActionParam } from './types.d';
|
|
5
|
+
export declare type FlowResult = ({
|
|
6
|
+
result?: Record<string, any>;
|
|
7
|
+
} & ActionParam) | NextActionParam;
|
|
8
|
+
export declare type ActionParams = {
|
|
9
|
+
executionId?: string;
|
|
10
|
+
actionId?: string;
|
|
11
|
+
nodeId?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare type ExecParams = {
|
|
14
|
+
callback?: (result: NextActionParam) => void;
|
|
15
|
+
onError?: (error: Error) => void;
|
|
16
|
+
} & ActionParams;
|
|
17
|
+
export default class FlowModel {
|
|
6
18
|
/**
|
|
7
|
-
*
|
|
19
|
+
* 流程支持的节点类型
|
|
8
20
|
*/
|
|
9
|
-
nodeModelMap: Map<string,
|
|
21
|
+
nodeModelMap: Map<string, NodeConstructor>;
|
|
10
22
|
/**
|
|
11
|
-
*
|
|
23
|
+
* 调度器,用于调度节点的执行。
|
|
12
24
|
*/
|
|
13
25
|
scheduler: Scheduler;
|
|
14
26
|
/**
|
|
15
|
-
*
|
|
27
|
+
* 待执行的队列,当流程正在执行时,如果再次触发执行。那么会将执行参数放入到队列中,等待上一次执行完成后再执行。
|
|
16
28
|
*/
|
|
17
|
-
executeList:
|
|
29
|
+
executeList: ExecParams[];
|
|
18
30
|
/**
|
|
19
|
-
*
|
|
31
|
+
* 当前正在执行。当监听到调度器执行完成时,出触发执行参数中的回调,告知外部执行完成。
|
|
20
32
|
*/
|
|
21
|
-
executingInstance
|
|
33
|
+
executingInstance: ExecParams;
|
|
22
34
|
/**
|
|
23
|
-
* 当前流程模型中的所有节点,边会被转换成节点的
|
|
35
|
+
* 当前流程模型中的所有节点,边会被转换成节点的incoming和outgoing属性。
|
|
24
36
|
*/
|
|
25
|
-
nodeConfigMap: Map<
|
|
37
|
+
nodeConfigMap: Map<string, NodeConfig>;
|
|
26
38
|
/**
|
|
27
39
|
* 当流程正在执行时,如果再次触发执行。那么会将执行参数放入到队列中,等待上一次执行完成后再执行。
|
|
28
40
|
*/
|
|
29
41
|
isRunning: boolean;
|
|
30
42
|
/**
|
|
31
|
-
*
|
|
43
|
+
* 开始节点类型,在执行流程时,会从这些节点开始执行。
|
|
32
44
|
*/
|
|
33
45
|
startNodeType: string;
|
|
34
46
|
/**
|
|
35
|
-
*
|
|
47
|
+
* 当前流程中开始节点组成的数组。
|
|
36
48
|
*/
|
|
37
|
-
startNodes:
|
|
49
|
+
startNodes: NodeConfig[];
|
|
38
50
|
/**
|
|
39
|
-
*
|
|
51
|
+
* 用于存储全局数据,可以在流程中共享。
|
|
40
52
|
*/
|
|
41
|
-
globalData: Record<string,
|
|
53
|
+
globalData: Record<string, any>;
|
|
42
54
|
/**
|
|
43
55
|
* 外部传入的上下文,最终会传递给每个节点
|
|
44
56
|
* 例如:
|
|
45
57
|
* const context = {
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* },
|
|
58
|
+
* request: {
|
|
59
|
+
* get: (url) => {
|
|
60
|
+
* return fetch(url);
|
|
61
|
+
* }
|
|
51
62
|
* }
|
|
52
|
-
*
|
|
63
|
+
* 在节点内部可以通过 this.context.request.get(url) 来调用。
|
|
53
64
|
*/
|
|
54
|
-
context: Record<string,
|
|
55
|
-
constructor({ nodeModelMap, recorder, context, globalData, startNodeType, }:
|
|
65
|
+
context: Record<string, any>;
|
|
66
|
+
constructor({ nodeModelMap, recorder, context, globalData, startNodeType, }: {
|
|
67
|
+
nodeModelMap: Map<string, NodeConstructor>;
|
|
68
|
+
recorder: Recorder;
|
|
69
|
+
context?: Record<string, any>;
|
|
70
|
+
globalData?: Record<string, any>;
|
|
71
|
+
startNodeType?: string;
|
|
72
|
+
});
|
|
73
|
+
setStartNodeType(startNodeType: any): void;
|
|
56
74
|
/**
|
|
57
75
|
* 解析LogicFlow图数据,将nodes和edges转换成节点格式。
|
|
58
76
|
* 例如:
|
|
@@ -86,61 +104,41 @@ export declare class FlowModel {
|
|
|
86
104
|
* 同时此方法还会找到所有的开始节点,方便后续执行时,从开始节点开始执行。
|
|
87
105
|
* @param graphData 流程图数据
|
|
88
106
|
*/
|
|
89
|
-
load(graphData:
|
|
107
|
+
load(graphData: any): void;
|
|
90
108
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
109
|
+
* 执行流程, 每次执行都会生成一个唯一的executionId,用于区分不同的执行。
|
|
110
|
+
* 同一次执行,这次执行内部的节点执行顺序为并行。内部并行是为了避免异步节点阻塞其他节点的执行。
|
|
111
|
+
* 多次执行,多次执行之间为串行,这里选择串行的原因是避免多次执行之间的数据冲突。
|
|
112
|
+
* example:
|
|
113
|
+
* 一个流程存在着两个开始节点,A和B,A和B的下一个节点都是C,C的下两个节点是D和E。
|
|
114
|
+
* 外部分别触发了A和B的执行,那么A和B的执行是串行的(也就是需要A执行完成后再执行B),但是D和E的执行是并行的。
|
|
115
|
+
* 如果希望A和B的执行是并行的,就不能使用同一个流程模型执行,应该初始化两个。
|
|
116
|
+
* TODO: 去掉此处的对列,直接使用调度器的队列。
|
|
97
117
|
*/
|
|
98
|
-
|
|
118
|
+
execute(params: ExecParams): Promise<void>;
|
|
119
|
+
resume(params: ExecParams): Promise<void>;
|
|
99
120
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* 一个流程存在两个开始节点,A 和 B,A 和 B 的下一个节点都是 C,C 的下两个节点是 D 和 E
|
|
105
|
-
* 外部分别触发了 A 和 B 的执行,那么 A 和 B 的执行是串行(即 A 执行完再执行 B),但是 D 和 E 的执行是并行的。
|
|
106
|
-
* 如果希望 A 和 B 的执行时并行的,就不能使用同一个流程模型执行,应该初始化两个。
|
|
107
|
-
* 下面直接使用调度器的队列
|
|
108
|
-
* @param params
|
|
121
|
+
* 创建节点实例, 每个节点实例都会有一个唯一的actionId。
|
|
122
|
+
* 通过executionId、nodeId、actionId可以唯一确定一个节点的某一次执行。
|
|
123
|
+
* @param nodeId 节点Id
|
|
124
|
+
* @returns 节点示例
|
|
109
125
|
*/
|
|
110
|
-
|
|
111
|
-
resume(params: Partial<FlowModel.ExecParam>): Promise<void>;
|
|
126
|
+
createAction(nodeId: string): import("./nodes/BaseNode").default;
|
|
112
127
|
/**
|
|
113
|
-
*
|
|
114
|
-
* 通过 executionId, nodeId, actionId 可以唯一确定一个节点的某一次执行
|
|
115
|
-
* @param nodeId
|
|
116
|
-
* @returns 节点实例
|
|
128
|
+
* 更新流程全局数据
|
|
117
129
|
*/
|
|
118
|
-
|
|
119
|
-
setStartNodeType(type: string): void;
|
|
120
|
-
updateGlobalData(data: Record<string, unknown>): Record<string, unknown>;
|
|
130
|
+
updateGlobalData(data: any): void;
|
|
121
131
|
/**
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* @param result
|
|
125
|
-
* @private
|
|
132
|
+
* 在执行完成后,通知外部此次执行完成。
|
|
133
|
+
* 如果还存在待执行的任务,那么继续执行。
|
|
126
134
|
*/
|
|
127
135
|
private onExecuteFinished;
|
|
136
|
+
/**
|
|
137
|
+
* 从待执行队列中取出需要执行的内容。
|
|
138
|
+
* 会依次判断是否有taskId、nodeId、executionId。
|
|
139
|
+
* 若存在taskId,那么表示恢复执行。
|
|
140
|
+
* 若存在nodeId,那么表示从指定节点开始执行。
|
|
141
|
+
* 若都不存在,那么新建一个executionId,从开始节点开始执行。
|
|
142
|
+
*/
|
|
143
|
+
private createExecution;
|
|
128
144
|
}
|
|
129
|
-
export declare namespace FlowModel {
|
|
130
|
-
type FlowResult = ({
|
|
131
|
-
result?: Record<string, unknown>;
|
|
132
|
-
} & Engine.ActionParam) | Engine.NextActionParam;
|
|
133
|
-
type ActionParam = Scheduler.ActionParam;
|
|
134
|
-
type ExecParam = {
|
|
135
|
-
callback?: (result: Engine.NextActionParam) => void;
|
|
136
|
-
onError?: (error: Error) => void;
|
|
137
|
-
} & ActionParam;
|
|
138
|
-
interface IFlowModelProps {
|
|
139
|
-
nodeModelMap: Map<string, BaseNode.NodeConstructor>;
|
|
140
|
-
recorder?: Recorder;
|
|
141
|
-
context?: Record<string, unknown>;
|
|
142
|
-
globalData?: Record<string, unknown>;
|
|
143
|
-
startNodeType?: string;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
export default FlowModel;
|