@logicflow/engine 0.0.11-beta.0 → 0.0.12-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.
Files changed (170) hide show
  1. package/README.md +5 -2
  2. package/dist/index.js +2 -0
  3. package/dist/index.js.map +1 -0
  4. package/es/EventEmitter.d.ts +34 -4
  5. package/es/EventEmitter.js +70 -48
  6. package/es/EventEmitter.js.map +1 -0
  7. package/es/FlowModel.d.ts +75 -73
  8. package/es/FlowModel.js +130 -173
  9. package/es/FlowModel.js.map +1 -0
  10. package/es/Scheduler.d.ts +50 -34
  11. package/es/Scheduler.js +134 -209
  12. package/es/Scheduler.js.map +1 -0
  13. package/es/constant/{constant.js → index.js} +8 -7
  14. package/es/constant/index.js.map +1 -0
  15. package/es/constant/logCode.js +29 -0
  16. package/es/constant/logCode.js.map +1 -0
  17. package/es/index.d.ts +135 -38
  18. package/es/index.js +92 -144
  19. package/es/index.js.map +1 -0
  20. package/es/nodes/base.d.ts +108 -0
  21. package/es/nodes/base.js +151 -0
  22. package/es/nodes/base.js.map +1 -0
  23. package/es/nodes/index.d.ts +3 -0
  24. package/es/nodes/index.js +4 -0
  25. package/es/nodes/index.js.map +1 -0
  26. package/es/nodes/{StartNode.d.ts → start.d.ts} +3 -2
  27. package/es/nodes/start.js +11 -0
  28. package/es/nodes/start.js.map +1 -0
  29. package/es/nodes/{TaskNode.d.ts → task.d.ts} +3 -2
  30. package/es/nodes/task.js +11 -0
  31. package/es/nodes/task.js.map +1 -0
  32. package/es/platform/browser/browserVm.d.ts +1 -0
  33. package/es/platform/browser/browserVm.js +66 -0
  34. package/es/platform/browser/browserVm.js.map +1 -0
  35. package/es/platform/browser/index.d.ts +4 -0
  36. package/es/platform/browser/index.js +23 -0
  37. package/es/platform/browser/index.js.map +1 -0
  38. package/es/platform/index.d.ts +1 -0
  39. package/es/platform/index.js +2 -0
  40. package/es/platform/index.js.map +1 -0
  41. package/es/platform/node/index.d.ts +4 -0
  42. package/es/platform/node/index.js +23 -0
  43. package/es/platform/node/index.js.map +1 -0
  44. package/es/platform/node/nodeVm.d.ts +1 -0
  45. package/es/platform/node/nodeVm.js +9 -0
  46. package/es/platform/node/nodeVm.js.map +1 -0
  47. package/es/recorder/index.d.ts +36 -10
  48. package/es/recorder/index.js +82 -135
  49. package/es/recorder/index.js.map +1 -0
  50. package/es/utils/global.d.ts +5 -0
  51. package/es/utils/global.js +27 -0
  52. package/es/utils/global.js.map +1 -0
  53. package/es/utils/id.js +14 -0
  54. package/es/utils/id.js.map +1 -0
  55. package/es/utils/index.d.ts +4 -0
  56. package/es/utils/index.js +5 -0
  57. package/es/utils/index.js.map +1 -0
  58. package/es/{util → utils}/storage.js +17 -16
  59. package/es/utils/storage.js.map +1 -0
  60. package/lib/EventEmitter.d.ts +37 -0
  61. package/lib/EventEmitter.js +94 -0
  62. package/lib/EventEmitter.js.map +1 -0
  63. package/lib/FlowModel.d.ts +146 -0
  64. package/lib/FlowModel.js +236 -0
  65. package/lib/FlowModel.js.map +1 -0
  66. package/lib/Scheduler.d.ts +78 -0
  67. package/lib/Scheduler.js +179 -0
  68. package/lib/Scheduler.js.map +1 -0
  69. package/lib/constant/index.d.ts +16 -0
  70. package/{cjs/constant/constant.js → lib/constant/index.js} +4 -3
  71. package/lib/constant/index.js.map +1 -0
  72. package/lib/constant/logCode.d.ts +12 -0
  73. package/{cjs/constant/LogCode.js → lib/constant/logCode.js} +16 -13
  74. package/lib/constant/logCode.js.map +1 -0
  75. package/lib/index.d.ts +157 -0
  76. package/lib/index.js +159 -0
  77. package/lib/index.js.map +1 -0
  78. package/lib/nodes/base.d.ts +108 -0
  79. package/lib/nodes/base.js +154 -0
  80. package/lib/nodes/base.js.map +1 -0
  81. package/lib/nodes/index.d.ts +3 -0
  82. package/lib/nodes/index.js +7 -0
  83. package/lib/nodes/index.js.map +1 -0
  84. package/lib/nodes/start.d.ts +6 -0
  85. package/lib/nodes/start.js +15 -0
  86. package/lib/nodes/start.js.map +1 -0
  87. package/lib/nodes/task.d.ts +6 -0
  88. package/lib/nodes/task.js +15 -0
  89. package/lib/nodes/task.js.map +1 -0
  90. package/lib/platform/browser/browserVm.d.ts +1 -0
  91. package/lib/platform/browser/browserVm.js +70 -0
  92. package/lib/platform/browser/browserVm.js.map +1 -0
  93. package/lib/platform/browser/index.d.ts +4 -0
  94. package/lib/platform/browser/index.js +28 -0
  95. package/lib/platform/browser/index.js.map +1 -0
  96. package/lib/platform/index.d.ts +1 -0
  97. package/lib/platform/index.js +5 -0
  98. package/lib/platform/index.js.map +1 -0
  99. package/lib/platform/node/index.d.ts +4 -0
  100. package/lib/platform/node/index.js +28 -0
  101. package/lib/platform/node/index.js.map +1 -0
  102. package/lib/platform/node/nodeVm.d.ts +1 -0
  103. package/lib/platform/node/nodeVm.js +13 -0
  104. package/lib/platform/node/nodeVm.js.map +1 -0
  105. package/lib/recorder/index.d.ts +46 -0
  106. package/lib/recorder/index.js +117 -0
  107. package/lib/recorder/index.js.map +1 -0
  108. package/lib/utils/global.d.ts +5 -0
  109. package/lib/utils/global.js +31 -0
  110. package/lib/utils/global.js.map +1 -0
  111. package/lib/utils/id.d.ts +3 -0
  112. package/lib/utils/id.js +20 -0
  113. package/lib/utils/id.js.map +1 -0
  114. package/lib/utils/index.d.ts +4 -0
  115. package/lib/utils/index.js +9 -0
  116. package/lib/utils/index.js.map +1 -0
  117. package/lib/utils/storage.d.ts +7 -0
  118. package/{cjs/util → lib/utils}/storage.js +18 -17
  119. package/lib/utils/storage.js.map +1 -0
  120. package/package.json +31 -71
  121. package/src/EventEmitter.ts +103 -0
  122. package/src/FlowModel.ts +325 -0
  123. package/src/Scheduler.ts +244 -0
  124. package/src/constant/index.ts +23 -0
  125. package/src/constant/logCode.ts +34 -0
  126. package/src/index.ts +300 -0
  127. package/src/nodes/base.ts +236 -0
  128. package/src/nodes/index.ts +3 -0
  129. package/src/nodes/start.ts +8 -0
  130. package/src/nodes/task.ts +8 -0
  131. package/src/platform/browser/browserVm.ts +68 -0
  132. package/src/platform/browser/index.ts +28 -0
  133. package/src/platform/index.ts +1 -0
  134. package/src/platform/node/index.ts +28 -0
  135. package/src/platform/node/nodeVm.ts +12 -0
  136. package/src/recorder/index.ts +137 -0
  137. package/src/typings.d.ts +0 -0
  138. package/src/utils/global.ts +41 -0
  139. package/src/utils/id.ts +16 -0
  140. package/src/utils/index.ts +5 -0
  141. package/src/utils/storage.ts +55 -0
  142. package/cjs/EventEmitter.js +0 -70
  143. package/cjs/FlowModel.js +0 -277
  144. package/cjs/Scheduler.js +0 -252
  145. package/cjs/expression/browserVm.js +0 -81
  146. package/cjs/expression/index.js +0 -57
  147. package/cjs/index.js +0 -210
  148. package/cjs/nodes/BaseNode.js +0 -252
  149. package/cjs/nodes/StartNode.js +0 -27
  150. package/cjs/nodes/TaskNode.js +0 -27
  151. package/cjs/recorder/index.js +0 -168
  152. package/cjs/util/ID.js +0 -16
  153. package/cjs/util/global.js +0 -32
  154. package/es/constant/LogCode.js +0 -28
  155. package/es/expression/browserVm.d.ts +0 -4
  156. package/es/expression/browserVm.js +0 -76
  157. package/es/expression/index.d.ts +0 -2
  158. package/es/expression/index.js +0 -54
  159. package/es/nodes/BaseNode.d.ts +0 -110
  160. package/es/nodes/BaseNode.js +0 -250
  161. package/es/nodes/StartNode.js +0 -25
  162. package/es/nodes/TaskNode.js +0 -25
  163. package/es/util/ID.js +0 -13
  164. package/es/util/global.d.ts +0 -5
  165. package/es/util/global.js +0 -26
  166. package/lib/main.js +0 -1
  167. /package/es/constant/{constant.d.ts → index.d.ts} +0 -0
  168. /package/es/constant/{LogCode.d.ts → logCode.d.ts} +0 -0
  169. /package/es/{util/ID.d.ts → utils/id.d.ts} +0 -0
  170. /package/es/{util → utils}/storage.d.ts +0 -0
package/cjs/Scheduler.js DELETED
@@ -1,252 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- var __assign = (this && this.__assign) || function () {
16
- __assign = Object.assign || function(t) {
17
- for (var s, i = 1, n = arguments.length; i < n; i++) {
18
- s = arguments[i];
19
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
- t[p] = s[p];
21
- }
22
- return t;
23
- };
24
- return __assign.apply(this, arguments);
25
- };
26
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
- return new (P || (P = Promise))(function (resolve, reject) {
29
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
- step((generator = generator.apply(thisArg, _arguments || [])).next());
33
- });
34
- };
35
- var __generator = (this && this.__generator) || function (thisArg, body) {
36
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
37
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
38
- function verb(n) { return function (v) { return step([n, v]); }; }
39
- function step(op) {
40
- if (f) throw new TypeError("Generator is already executing.");
41
- while (_) try {
42
- 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;
43
- if (y = 0, t) op = [op[0] & 2, t.value];
44
- switch (op[0]) {
45
- case 0: case 1: t = op; break;
46
- case 4: _.label++; return { value: op[1], done: false };
47
- case 5: _.label++; y = op[1]; op = [0]; continue;
48
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
49
- default:
50
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
51
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
52
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
53
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
54
- if (t[2]) _.ops.pop();
55
- _.trys.pop(); continue;
56
- }
57
- op = body.call(thisArg, _);
58
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
59
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
60
- }
61
- };
62
- Object.defineProperty(exports, "__esModule", { value: true });
63
- var EventEmitter_1 = require("./EventEmitter");
64
- var constant_1 = require("./constant/constant");
65
- var ID_1 = require("./util/ID");
66
- /**
67
- * 调度器
68
- * 通过一个队列维护需要执行的节点,一个集合维护正在执行的节点
69
- */
70
- var Scheduler = /** @class */ (function (_super) {
71
- __extends(Scheduler, _super);
72
- function Scheduler(config) {
73
- var _this = _super.call(this) || this;
74
- _this.nodeQueueMap = new Map();
75
- _this.actionRunningMap = new Map();
76
- _this.flowModel = config.flowModel;
77
- _this.recorder = config.recorder;
78
- return _this;
79
- }
80
- /**
81
- * 添加一个任务到队列中。
82
- * 1. 由流程模型将所有的开始节点添加到队列中。
83
- * 2. 当一个节点执行完成后,将后续的节点添加到队列中。
84
- */
85
- Scheduler.prototype.addAction = function (nodeParam) {
86
- var executionId = nodeParam.executionId;
87
- if (!this.nodeQueueMap.has(executionId)) {
88
- this.nodeQueueMap.set(executionId, []);
89
- }
90
- var currentActionQueue = this.nodeQueueMap.get(executionId);
91
- currentActionQueue.push(nodeParam);
92
- };
93
- /**
94
- * 调度器执行下一个任务
95
- * 1. 提供给流程模型,用户开始执行第一个任务。
96
- * 2. 内部任务执行完成后,调用此方法继续执行下一个任务。
97
- * 3. 当判断没有可以继续执行的任务后,触发流程结束事件。
98
- */
99
- Scheduler.prototype.run = function (runParams) {
100
- var nodeQueue = this.nodeQueueMap.get(runParams.executionId);
101
- // 将同一个executionId当前待执行的节点一起执行
102
- // 避免出现某一个节点执行时间过长,导致其他节点等待时间过长。
103
- while (nodeQueue.length) {
104
- var currentNode = nodeQueue.pop();
105
- var actionId = ID_1.createActionId();
106
- var actionParam = __assign(__assign({}, currentNode), { actionId: actionId });
107
- this.pushActionToRunningMap(actionParam);
108
- this.exec(actionParam);
109
- }
110
- if (!this.hasRunningAction(runParams.executionId)) {
111
- // 当一个流程在nodeQueueMap和actionRunningMap中都不存在执行的节点时,说明这个流程已经执行完成。
112
- this.emit(constant_1.EVENT_INSTANCE_COMPLETE, __assign(__assign({}, runParams), { status: constant_1.FlowStatus.COMPLETED }));
113
- }
114
- };
115
- /**
116
- * 恢复某个任务的执行。
117
- * 可以自定义节点手动实现流程中断,然后通过此方法恢复流程的执行。
118
- */
119
- Scheduler.prototype.resume = function (resumeParam) {
120
- return __awaiter(this, void 0, void 0, function () {
121
- var model;
122
- return __generator(this, function (_a) {
123
- switch (_a.label) {
124
- case 0:
125
- this.pushActionToRunningMap({
126
- executionId: resumeParam.executionId,
127
- nodeId: resumeParam.nodeId,
128
- actionId: resumeParam.actionId,
129
- });
130
- model = this.flowModel.createAction(resumeParam.nodeId);
131
- return [4 /*yield*/, model.resume(__assign(__assign({}, resumeParam), { next: this.next.bind(this) }))];
132
- case 1:
133
- _a.sent();
134
- return [2 /*return*/];
135
- }
136
- });
137
- });
138
- };
139
- Scheduler.prototype.pushActionToRunningMap = function (actionParam) {
140
- var executionId = actionParam.executionId, actionId = actionParam.actionId;
141
- if (!this.actionRunningMap.has(executionId)) {
142
- var runningMap = new Map();
143
- this.actionRunningMap.set(executionId, runningMap);
144
- }
145
- this.actionRunningMap.get(executionId).set(actionId, actionParam);
146
- };
147
- Scheduler.prototype.removeActionFromRunningMap = function (actionParam) {
148
- var executionId = actionParam.executionId, actionId = actionParam.actionId;
149
- if (!actionId)
150
- return;
151
- var runningMap = this.actionRunningMap.get(executionId);
152
- if (!runningMap)
153
- return;
154
- runningMap.delete(actionId);
155
- };
156
- Scheduler.prototype.hasRunningAction = function (executionId) {
157
- var runningMap = this.actionRunningMap.get(executionId);
158
- if (!runningMap)
159
- return false;
160
- if (runningMap.size === 0) {
161
- this.actionRunningMap.delete(executionId);
162
- return false;
163
- }
164
- return true;
165
- };
166
- Scheduler.prototype.exec = function (actionParam) {
167
- return __awaiter(this, void 0, void 0, function () {
168
- var model, execResult;
169
- return __generator(this, function (_a) {
170
- switch (_a.label) {
171
- case 0:
172
- model = this.flowModel.createAction(actionParam.nodeId);
173
- return [4 /*yield*/, model.execute({
174
- executionId: actionParam.executionId,
175
- actionId: actionParam.actionId,
176
- nodeId: actionParam.nodeId,
177
- next: this.next.bind(this),
178
- })];
179
- case 1:
180
- execResult = _a.sent();
181
- if (execResult && execResult.status === constant_1.FlowStatus.INTERRUPTED) {
182
- this.interrupted(execResult);
183
- this.saveActionResult({
184
- executionId: actionParam.executionId,
185
- nodeId: actionParam.nodeId,
186
- actionId: actionParam.actionId,
187
- nodeType: execResult.nodeType,
188
- properties: execResult.properties,
189
- outgoing: execResult.outgoing,
190
- status: execResult.status,
191
- detail: execResult.detail,
192
- });
193
- this.removeActionFromRunningMap(actionParam);
194
- }
195
- if (execResult && execResult.status === constant_1.FlowStatus.ERROR) {
196
- this.error(execResult);
197
- this.saveActionResult({
198
- executionId: actionParam.executionId,
199
- nodeId: actionParam.nodeId,
200
- actionId: actionParam.actionId,
201
- nodeType: execResult.nodeType,
202
- properties: execResult.properties,
203
- outgoing: execResult.outgoing,
204
- status: execResult.status,
205
- detail: execResult.detail,
206
- });
207
- this.removeActionFromRunningMap(actionParam);
208
- }
209
- return [2 /*return*/];
210
- }
211
- });
212
- });
213
- };
214
- Scheduler.prototype.interrupted = function (execResult) {
215
- this.emit(constant_1.EVENT_INSTANCE_INTERRUPTED, execResult);
216
- };
217
- Scheduler.prototype.error = function (execResult) {
218
- this.emit(constant_1.EVENT_INSTANCE_ERROR, execResult);
219
- };
220
- Scheduler.prototype.next = function (data) {
221
- var _this = this;
222
- if (data.outgoing && data.outgoing.length > 0) {
223
- data.outgoing.forEach(function (item) {
224
- if (item.result) {
225
- _this.addAction({
226
- executionId: data.executionId,
227
- nodeId: item.target,
228
- });
229
- }
230
- });
231
- }
232
- this.saveActionResult(data);
233
- this.removeActionFromRunningMap(data);
234
- this.run(data);
235
- };
236
- Scheduler.prototype.saveActionResult = function (data) {
237
- var _a;
238
- (_a = this.recorder) === null || _a === void 0 ? void 0 : _a.addActionRecord({
239
- executionId: data.executionId,
240
- actionId: data.actionId,
241
- nodeId: data.nodeId,
242
- nodeType: data.nodeType,
243
- timestamp: Date.now(),
244
- properties: data.properties,
245
- outgoing: data.outgoing,
246
- detail: data.detail,
247
- status: data.status,
248
- });
249
- };
250
- return Scheduler;
251
- }(EventEmitter_1.default));
252
- exports.default = Scheduler;
@@ -1,81 +0,0 @@
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
- exports.runInContext = exports.createContext = exports.runInBrowserContext = void 0;
40
- var LogCode_1 = require("../constant/LogCode");
41
- var createContext = function (globalData) {
42
- var iframe = document.createElement('iframe');
43
- iframe.style.display = 'none';
44
- if (!document || !document.body) {
45
- console.error(LogCode_1.getErrorMsg(LogCode_1.ErrorCode.NO_DOCUMENT_BODY));
46
- }
47
- document.body.appendChild(iframe);
48
- var iframeWindow = iframe.contentWindow;
49
- iframeWindow.parent = null;
50
- Object.keys(globalData).forEach(function (key) {
51
- iframeWindow[key] = globalData[key];
52
- });
53
- return iframeWindow;
54
- };
55
- exports.createContext = createContext;
56
- var runInContext = function (code, context) {
57
- try {
58
- var iframeEval = context.eval;
59
- iframeEval.call(context, code);
60
- if (context.frameElement) {
61
- document.body.removeChild(context.frameElement);
62
- }
63
- }
64
- catch (e) {
65
- console.warn(LogCode_1.getWarningMsg(LogCode_1.WarningCode.EXPRESSION_EXEC_ERROR), { code: code, context: context, e: e });
66
- }
67
- return context;
68
- };
69
- exports.runInContext = runInContext;
70
- var runInBrowserContext = function (code, globalData) {
71
- if (globalData === void 0) { globalData = {}; }
72
- return __awaiter(void 0, void 0, void 0, function () {
73
- var context;
74
- return __generator(this, function (_a) {
75
- context = createContext(globalData);
76
- runInContext(code, context);
77
- return [2 /*return*/, context];
78
- });
79
- });
80
- };
81
- exports.runInBrowserContext = runInBrowserContext;
@@ -1,57 +0,0 @@
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
- exports.getExpressionResult = void 0;
40
- // import { runInNewContext } from './nodeVm';
41
- var browserVm_1 = require("./browserVm");
42
- var global_1 = require("../util/global");
43
- var getExpressionResult = function (code, context) { return __awaiter(void 0, void 0, void 0, function () {
44
- var r;
45
- return __generator(this, function (_a) {
46
- switch (_a.label) {
47
- case 0:
48
- if (!global_1.isInBrowser) return [3 /*break*/, 2];
49
- return [4 /*yield*/, browserVm_1.runInBrowserContext(code, context)];
50
- case 1:
51
- r = _a.sent();
52
- return [2 /*return*/, r];
53
- case 2: return [2 /*return*/, global_1.globalScope.eval(code)]; // eslint-disable-line no-eval
54
- }
55
- });
56
- }); };
57
- exports.getExpressionResult = getExpressionResult;
package/cjs/index.js DELETED
@@ -1,210 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.Recorder = exports.StartNode = exports.TaskNode = exports.Engine = void 0;
51
- var FlowModel_1 = require("./FlowModel");
52
- var StartNode_1 = require("./nodes/StartNode");
53
- exports.StartNode = StartNode_1.default;
54
- var TaskNode_1 = require("./nodes/TaskNode");
55
- exports.TaskNode = TaskNode_1.default;
56
- var recorder_1 = require("./recorder");
57
- exports.Recorder = recorder_1.default;
58
- var ID_1 = require("./util/ID");
59
- var Engine = /** @class */ (function () {
60
- function Engine(options) {
61
- this.nodeModelMap = new Map();
62
- this.instanceId = ID_1.createEngineId();
63
- if (options === null || options === void 0 ? void 0 : options.debug) {
64
- this.recorder = new recorder_1.default({
65
- instanceId: this.instanceId,
66
- });
67
- }
68
- this.register({
69
- type: StartNode_1.default.nodeTypeName,
70
- model: StartNode_1.default,
71
- });
72
- this.register({
73
- type: TaskNode_1.default.nodeTypeName,
74
- model: TaskNode_1.default,
75
- });
76
- this.context = (options === null || options === void 0 ? void 0 : options.context) || {};
77
- }
78
- /**
79
- * 注册节点
80
- * @param nodeConfig { type: 'custom-node', model: NodeClass }
81
- */
82
- Engine.prototype.register = function (nodeConfig) {
83
- this.nodeModelMap.set(nodeConfig.type, nodeConfig.model);
84
- };
85
- /**
86
- * 自定义执行记录的存储,默认浏览器使用 sessionStorage,nodejs 使用内存存储。
87
- * 注意:由于执行记录不会主动删除,所以需要自行清理。
88
- * nodejs环境建议自定义为持久化存储。
89
- * engine.setCustomRecorder({
90
- * async addActionRecord(task) {}
91
- * async getTask(actionId) {}
92
- * async getExecutionTasks(executionId) {}
93
- * clear(instanceId) {}
94
- * });
95
- */
96
- Engine.prototype.setCustomRecorder = function (recorder) {
97
- this.recorder = recorder;
98
- };
99
- /**
100
- * 加载流程图数据
101
- */
102
- Engine.prototype.load = function (_a) {
103
- var graphData = _a.graphData, _b = _a.startNodeType, startNodeType = _b === void 0 ? 'StartNode' : _b, _c = _a.globalData, globalData = _c === void 0 ? {} : _c;
104
- this.flowModel = new FlowModel_1.default({
105
- nodeModelMap: this.nodeModelMap,
106
- recorder: this.recorder,
107
- context: this.context,
108
- globalData: globalData,
109
- startNodeType: startNodeType,
110
- });
111
- this.flowModel.load(graphData);
112
- return this.flowModel;
113
- };
114
- /**
115
- * 执行流程,允许多次调用。
116
- */
117
- Engine.prototype.execute = function (execParam) {
118
- return __awaiter(this, void 0, void 0, function () {
119
- var _this = this;
120
- return __generator(this, function (_a) {
121
- return [2 /*return*/, new Promise(function (resolve, reject) {
122
- if (!execParam) {
123
- execParam = {};
124
- }
125
- _this.flowModel.execute(__assign(__assign({}, execParam), { callback: function (result) {
126
- resolve(result);
127
- }, onError: function (error) {
128
- reject(error);
129
- } }));
130
- })];
131
- });
132
- });
133
- };
134
- /**
135
- * 恢复执行
136
- * 注意此方法只能恢复节点后面的执行,不能恢复流程其他分支的执行。
137
- * 同理,中断执行也只能中断节点后面的执行,不会中断其他分支的执行。
138
- * 在实际项目中,如果存在中断节点,建议流程所有的节点都是排他网关,这样可以保证执行的过程不存在分支。
139
- */
140
- Engine.prototype.resume = function (resumeParam) {
141
- return __awaiter(this, void 0, void 0, function () {
142
- var _this = this;
143
- return __generator(this, function (_a) {
144
- return [2 /*return*/, new Promise(function (resolve, reject) {
145
- _this.flowModel.resume(__assign(__assign({}, resumeParam), { callback: function (result) {
146
- resolve(result);
147
- }, onError: function (error) {
148
- reject(error);
149
- } }));
150
- })];
151
- });
152
- });
153
- };
154
- Engine.prototype.getExecutionList = function () {
155
- var _a;
156
- return __awaiter(this, void 0, void 0, function () {
157
- var executionIds;
158
- return __generator(this, function (_b) {
159
- switch (_b.label) {
160
- case 0: return [4 /*yield*/, ((_a = this.recorder) === null || _a === void 0 ? void 0 : _a.getExecutionList())];
161
- case 1:
162
- executionIds = _b.sent();
163
- return [2 /*return*/, executionIds];
164
- }
165
- });
166
- });
167
- };
168
- Engine.prototype.getExecutionRecord = function (executionId) {
169
- var _a, _b;
170
- return __awaiter(this, void 0, void 0, function () {
171
- var tasks, records, i;
172
- return __generator(this, function (_c) {
173
- switch (_c.label) {
174
- case 0: return [4 /*yield*/, ((_a = this.recorder) === null || _a === void 0 ? void 0 : _a.getExecutionActions(executionId))];
175
- case 1:
176
- tasks = _c.sent();
177
- if (!tasks) {
178
- return [2 /*return*/, null];
179
- }
180
- records = [];
181
- for (i = 0; i < tasks.length; i++) {
182
- records.push((_b = this.recorder) === null || _b === void 0 ? void 0 : _b.getActionRecord(tasks[i]));
183
- }
184
- return [2 /*return*/, Promise.all(records)];
185
- }
186
- });
187
- });
188
- };
189
- Engine.prototype.destroy = function () {
190
- var _a;
191
- (_a = this.recorder) === null || _a === void 0 ? void 0 : _a.clear();
192
- };
193
- Engine.prototype.getGlobalData = function () {
194
- var _a;
195
- return (_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.globalData;
196
- };
197
- Engine.prototype.setGlobalData = function (data) {
198
- if (this.flowModel) {
199
- this.flowModel.globalData = data;
200
- }
201
- };
202
- Engine.prototype.updateGlobalData = function (data) {
203
- if (this.flowModel) {
204
- Object.assign(this.flowModel.globalData, data);
205
- }
206
- };
207
- return Engine;
208
- }());
209
- exports.Engine = Engine;
210
- exports.default = Engine;