@logicflow/engine 0.0.9 → 0.0.10-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 (190) 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/expression/brewserVm.d.ts +2 -0
  18. package/es/expression/brewserVm.js +30 -0
  19. package/es/expression/brewserVm.js.map +1 -0
  20. package/es/expression/index.d.ts +1 -1
  21. package/es/expression/index.js +16 -59
  22. package/es/expression/index.js.map +1 -0
  23. package/es/expression/nodeVm.d.ts +4 -2
  24. package/es/expression/nodeVm.js +10 -50
  25. package/es/expression/nodeVm.js.map +1 -0
  26. package/es/index.d.ts +135 -38
  27. package/es/index.js +92 -144
  28. package/es/index.js.map +1 -0
  29. package/es/nodes/base.d.ts +108 -0
  30. package/es/nodes/base.js +149 -0
  31. package/es/nodes/base.js.map +1 -0
  32. package/es/nodes/index.d.ts +3 -0
  33. package/es/nodes/index.js +4 -0
  34. package/es/nodes/index.js.map +1 -0
  35. package/es/nodes/{StartNode.d.ts → start.d.ts} +3 -2
  36. package/es/nodes/start.js +11 -0
  37. package/es/nodes/start.js.map +1 -0
  38. package/es/nodes/{TaskNode.d.ts → task.d.ts} +3 -2
  39. package/es/nodes/task.js +11 -0
  40. package/es/nodes/task.js.map +1 -0
  41. package/es/platform/browser/browserVm.d.ts +4 -0
  42. package/es/platform/browser/browserVm.js +44 -0
  43. package/es/platform/browser/browserVm.js.map +1 -0
  44. package/es/platform/browser/index.d.ts +4 -0
  45. package/es/platform/browser/index.js +23 -0
  46. package/es/platform/browser/index.js.map +1 -0
  47. package/es/platform/index.d.ts +1 -0
  48. package/es/platform/index.js +2 -0
  49. package/es/platform/index.js.map +1 -0
  50. package/es/platform/node/index.d.ts +4 -0
  51. package/es/platform/node/index.js +23 -0
  52. package/es/platform/node/index.js.map +1 -0
  53. package/es/platform/node/nodeVm.d.ts +1 -0
  54. package/es/platform/node/nodeVm.js +9 -0
  55. package/es/platform/node/nodeVm.js.map +1 -0
  56. package/es/recorder/index.d.ts +36 -10
  57. package/es/recorder/index.js +82 -135
  58. package/es/recorder/index.js.map +1 -0
  59. package/es/utils/global.d.ts +5 -0
  60. package/es/utils/global.js +27 -0
  61. package/es/utils/global.js.map +1 -0
  62. package/es/utils/id.js +14 -0
  63. package/es/utils/id.js.map +1 -0
  64. package/es/utils/index.d.ts +4 -0
  65. package/es/utils/index.js +5 -0
  66. package/es/utils/index.js.map +1 -0
  67. package/es/{util → utils}/storage.js +17 -16
  68. package/es/utils/storage.js.map +1 -0
  69. package/lib/EventEmitter.d.ts +37 -0
  70. package/lib/EventEmitter.js +94 -0
  71. package/lib/EventEmitter.js.map +1 -0
  72. package/lib/FlowModel.d.ts +146 -0
  73. package/lib/FlowModel.js +236 -0
  74. package/lib/FlowModel.js.map +1 -0
  75. package/lib/Scheduler.d.ts +78 -0
  76. package/lib/Scheduler.js +179 -0
  77. package/lib/Scheduler.js.map +1 -0
  78. package/lib/constant/index.d.ts +16 -0
  79. package/{cjs/constant/constant.js → lib/constant/index.js} +4 -3
  80. package/lib/constant/index.js.map +1 -0
  81. package/lib/constant/logCode.d.ts +12 -0
  82. package/{cjs/constant/LogCode.js → lib/constant/logCode.js} +16 -13
  83. package/lib/constant/logCode.js.map +1 -0
  84. package/lib/expression/brewserVm.d.ts +2 -0
  85. package/lib/expression/brewserVm.js +33 -0
  86. package/lib/expression/brewserVm.js.map +1 -0
  87. package/lib/expression/index.d.ts +2 -0
  88. package/lib/expression/index.js +20 -0
  89. package/lib/expression/index.js.map +1 -0
  90. package/lib/expression/nodeVm.d.ts +4 -0
  91. package/lib/expression/nodeVm.js +13 -0
  92. package/lib/expression/nodeVm.js.map +1 -0
  93. package/lib/index.d.ts +157 -0
  94. package/lib/index.js +159 -0
  95. package/lib/index.js.map +1 -0
  96. package/lib/nodes/base.d.ts +108 -0
  97. package/lib/nodes/base.js +152 -0
  98. package/lib/nodes/base.js.map +1 -0
  99. package/lib/nodes/index.d.ts +3 -0
  100. package/lib/nodes/index.js +7 -0
  101. package/lib/nodes/index.js.map +1 -0
  102. package/lib/nodes/start.d.ts +6 -0
  103. package/lib/nodes/start.js +15 -0
  104. package/lib/nodes/start.js.map +1 -0
  105. package/lib/nodes/task.d.ts +6 -0
  106. package/lib/nodes/task.js +15 -0
  107. package/lib/nodes/task.js.map +1 -0
  108. package/lib/platform/browser/browserVm.d.ts +4 -0
  109. package/lib/platform/browser/browserVm.js +49 -0
  110. package/lib/platform/browser/browserVm.js.map +1 -0
  111. package/lib/platform/browser/index.d.ts +4 -0
  112. package/lib/platform/browser/index.js +28 -0
  113. package/lib/platform/browser/index.js.map +1 -0
  114. package/lib/platform/index.d.ts +1 -0
  115. package/lib/platform/index.js +5 -0
  116. package/lib/platform/index.js.map +1 -0
  117. package/lib/platform/node/index.d.ts +4 -0
  118. package/lib/platform/node/index.js +28 -0
  119. package/lib/platform/node/index.js.map +1 -0
  120. package/lib/platform/node/nodeVm.d.ts +1 -0
  121. package/lib/platform/node/nodeVm.js +13 -0
  122. package/lib/platform/node/nodeVm.js.map +1 -0
  123. package/lib/recorder/index.d.ts +46 -0
  124. package/lib/recorder/index.js +117 -0
  125. package/lib/recorder/index.js.map +1 -0
  126. package/lib/utils/global.d.ts +5 -0
  127. package/lib/utils/global.js +31 -0
  128. package/lib/utils/global.js.map +1 -0
  129. package/lib/utils/id.d.ts +3 -0
  130. package/lib/utils/id.js +20 -0
  131. package/lib/utils/id.js.map +1 -0
  132. package/lib/utils/index.d.ts +4 -0
  133. package/lib/utils/index.js +9 -0
  134. package/lib/utils/index.js.map +1 -0
  135. package/lib/utils/storage.d.ts +7 -0
  136. package/{cjs/util → lib/utils}/storage.js +18 -17
  137. package/lib/utils/storage.js.map +1 -0
  138. package/package.json +30 -71
  139. package/src/EventEmitter.ts +103 -0
  140. package/src/FlowModel.ts +325 -0
  141. package/src/Scheduler.ts +244 -0
  142. package/src/constant/index.ts +23 -0
  143. package/src/constant/logCode.ts +34 -0
  144. package/src/expression/brewserVm.ts +36 -0
  145. package/src/expression/index.ts +17 -0
  146. package/src/expression/nodeVm.ts +14 -0
  147. package/src/index.ts +300 -0
  148. package/src/nodes/base.ts +234 -0
  149. package/src/nodes/index.ts +3 -0
  150. package/src/nodes/start.ts +8 -0
  151. package/src/nodes/task.ts +8 -0
  152. package/src/platform/browser/browserVm.ts +52 -0
  153. package/src/platform/browser/index.ts +28 -0
  154. package/src/platform/index.ts +1 -0
  155. package/src/platform/node/index.ts +28 -0
  156. package/src/platform/node/nodeVm.ts +12 -0
  157. package/src/recorder/index.ts +137 -0
  158. package/src/typings.d.ts +0 -0
  159. package/src/utils/global.ts +41 -0
  160. package/src/utils/id.ts +16 -0
  161. package/src/utils/index.ts +5 -0
  162. package/src/utils/storage.ts +55 -0
  163. package/cjs/EventEmitter.js +0 -70
  164. package/cjs/FlowModel.js +0 -277
  165. package/cjs/Scheduler.js +0 -252
  166. package/cjs/expression/browserVm.js +0 -81
  167. package/cjs/expression/index.js +0 -63
  168. package/cjs/expression/nodeVm.js +0 -53
  169. package/cjs/index.js +0 -210
  170. package/cjs/nodes/BaseNode.js +0 -252
  171. package/cjs/nodes/StartNode.js +0 -27
  172. package/cjs/nodes/TaskNode.js +0 -27
  173. package/cjs/recorder/index.js +0 -168
  174. package/cjs/util/ID.js +0 -16
  175. package/cjs/util/global.js +0 -32
  176. package/es/constant/LogCode.js +0 -28
  177. package/es/expression/browserVm.d.ts +0 -4
  178. package/es/expression/browserVm.js +0 -76
  179. package/es/nodes/BaseNode.d.ts +0 -110
  180. package/es/nodes/BaseNode.js +0 -250
  181. package/es/nodes/StartNode.js +0 -25
  182. package/es/nodes/TaskNode.js +0 -25
  183. package/es/util/ID.js +0 -13
  184. package/es/util/global.d.ts +0 -5
  185. package/es/util/global.js +0 -26
  186. package/lib/main.js +0 -1
  187. /package/es/constant/{constant.d.ts → index.d.ts} +0 -0
  188. /package/es/constant/{LogCode.d.ts → logCode.d.ts} +0 -0
  189. /package/es/{util/ID.d.ts → utils/id.d.ts} +0 -0
  190. /package/es/{util → utils}/storage.d.ts +0 -0
package/es/Scheduler.js CHANGED
@@ -1,158 +1,66 @@
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
- var __assign = (this && this.__assign) || function () {
15
- __assign = Object.assign || function(t) {
16
- for (var s, i = 1, n = arguments.length; i < n; i++) {
17
- s = arguments[i];
18
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
19
- t[p] = s[p];
20
- }
21
- return t;
22
- };
23
- return __assign.apply(this, arguments);
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (_) try {
41
- 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;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
1
+ import { __awaiter } from "tslib";
61
2
  import EventEmitter from './EventEmitter';
62
- import { EVENT_INSTANCE_COMPLETE, EVENT_INSTANCE_INTERRUPTED, EVENT_INSTANCE_ERROR, FlowStatus, } from './constant/constant';
63
- import { createActionId } from './util/ID';
3
+ import { createActionId } from './utils';
4
+ import { EVENT_INSTANCE_ERROR, EVENT_INSTANCE_COMPLETE, EVENT_INSTANCE_INTERRUPTED, FlowStatus, } from './constant';
64
5
  /**
65
6
  * 调度器
66
7
  * 通过一个队列维护需要执行的节点,一个集合维护正在执行的节点
67
8
  */
68
- var Scheduler = /** @class */ (function (_super) {
69
- __extends(Scheduler, _super);
70
- function Scheduler(config) {
71
- var _this = _super.call(this) || this;
72
- _this.nodeQueueMap = new Map();
73
- _this.actionRunningMap = new Map();
74
- _this.flowModel = config.flowModel;
75
- _this.recorder = config.recorder;
76
- return _this;
9
+ export class Scheduler extends EventEmitter {
10
+ constructor(config) {
11
+ super();
12
+ this.nodeQueueMap = new Map();
13
+ this.actionRunningMap = new Map();
14
+ this.flowModel = config.flowModel;
15
+ this.recorder = config.recorder;
77
16
  }
78
17
  /**
79
18
  * 添加一个任务到队列中。
80
- * 1. 由流程模型将所有的开始节点添加到队列中。
81
- * 2. 当一个节点执行完成后,将后续的节点添加到队列中。
19
+ * 1. 由流程模型将所有的开始及诶带你添加到队列中
20
+ * 2. 当一个节点执行完成后,将后续的节点添加到队列中
21
+ * @param nodeParam
82
22
  */
83
- Scheduler.prototype.addAction = function (nodeParam) {
84
- var executionId = nodeParam.executionId;
23
+ addAction(nodeParam) {
24
+ const { executionId } = nodeParam;
85
25
  if (!this.nodeQueueMap.has(executionId)) {
86
26
  this.nodeQueueMap.set(executionId, []);
87
27
  }
88
- var currentActionQueue = this.nodeQueueMap.get(executionId);
89
- currentActionQueue.push(nodeParam);
90
- };
91
- /**
92
- * 调度器执行下一个任务
93
- * 1. 提供给流程模型,用户开始执行第一个任务。
94
- * 2. 内部任务执行完成后,调用此方法继续执行下一个任务。
95
- * 3. 当判断没有可以继续执行的任务后,触发流程结束事件。
96
- */
97
- Scheduler.prototype.run = function (runParams) {
98
- var nodeQueue = this.nodeQueueMap.get(runParams.executionId);
99
- // 将同一个executionId当前待执行的节点一起执行
100
- // 避免出现某一个节点执行时间过长,导致其他节点等待时间过长。
101
- while (nodeQueue.length) {
102
- var currentNode = nodeQueue.pop();
103
- var actionId = createActionId();
104
- var actionParam = __assign(__assign({}, currentNode), { actionId: actionId });
105
- this.pushActionToRunningMap(actionParam);
106
- this.exec(actionParam);
107
- }
108
- if (!this.hasRunningAction(runParams.executionId)) {
109
- // 当一个流程在nodeQueueMap和actionRunningMap中都不存在执行的节点时,说明这个流程已经执行完成。
110
- this.emit(EVENT_INSTANCE_COMPLETE, __assign(__assign({}, runParams), { status: FlowStatus.COMPLETED }));
28
+ const currentActionQueue = this.nodeQueueMap.get(executionId);
29
+ if (currentActionQueue) {
30
+ currentActionQueue.push(nodeParam);
111
31
  }
112
- };
113
- /**
114
- * 恢复某个任务的执行。
115
- * 可以自定义节点手动实现流程中断,然后通过此方法恢复流程的执行。
116
- */
117
- Scheduler.prototype.resume = function (resumeParam) {
118
- return __awaiter(this, void 0, void 0, function () {
119
- var model;
120
- return __generator(this, function (_a) {
121
- switch (_a.label) {
122
- case 0:
123
- this.pushActionToRunningMap({
124
- executionId: resumeParam.executionId,
125
- nodeId: resumeParam.nodeId,
126
- actionId: resumeParam.actionId,
127
- });
128
- model = this.flowModel.createAction(resumeParam.nodeId);
129
- return [4 /*yield*/, model.resume(__assign(__assign({}, resumeParam), { next: this.next.bind(this) }))];
130
- case 1:
131
- _a.sent();
132
- return [2 /*return*/];
133
- }
134
- });
135
- });
136
- };
137
- Scheduler.prototype.pushActionToRunningMap = function (actionParam) {
138
- var executionId = actionParam.executionId, actionId = actionParam.actionId;
32
+ console.log('this.nodeQueueMap--->>>', this.nodeQueueMap);
33
+ }
34
+ pushActionToRunningMap(actionParam) {
35
+ var _a;
36
+ const { executionId, actionId } = actionParam;
139
37
  if (!this.actionRunningMap.has(executionId)) {
140
- var runningMap = new Map();
38
+ const runningMap = new Map();
141
39
  this.actionRunningMap.set(executionId, runningMap);
142
40
  }
143
- this.actionRunningMap.get(executionId).set(actionId, actionParam);
144
- };
145
- Scheduler.prototype.removeActionFromRunningMap = function (actionParam) {
146
- var executionId = actionParam.executionId, actionId = actionParam.actionId;
41
+ if (actionId) {
42
+ (_a = this.actionRunningMap.get(executionId)) === null || _a === void 0 ? void 0 : _a.set(actionId, actionParam);
43
+ }
44
+ }
45
+ removeActionFromRunningMap(actionParam) {
46
+ const { executionId, actionId } = actionParam;
147
47
  if (!actionId)
148
48
  return;
149
- var runningMap = this.actionRunningMap.get(executionId);
49
+ const runningMap = this.actionRunningMap.get(executionId);
150
50
  if (!runningMap)
151
51
  return;
152
52
  runningMap.delete(actionId);
153
- };
154
- Scheduler.prototype.hasRunningAction = function (executionId) {
155
- var runningMap = this.actionRunningMap.get(executionId);
53
+ }
54
+ /**
55
+ * 为了防止多次添加导致
56
+ * @param actionParam
57
+ */
58
+ saveActionResult(actionParam) {
59
+ var _a;
60
+ (_a = this.recorder) === null || _a === void 0 ? void 0 : _a.addActionRecord(Object.assign({ timestamp: Date.now() }, actionParam));
61
+ }
62
+ hasRunningAction(executionId) {
63
+ const runningMap = this.actionRunningMap.get(executionId);
156
64
  if (!runningMap)
157
65
  return false;
158
66
  if (runningMap.size === 0) {
@@ -160,67 +68,35 @@ var Scheduler = /** @class */ (function (_super) {
160
68
  return false;
161
69
  }
162
70
  return true;
163
- };
164
- Scheduler.prototype.exec = function (actionParam) {
165
- return __awaiter(this, void 0, void 0, function () {
166
- var model, execResult;
167
- return __generator(this, function (_a) {
168
- switch (_a.label) {
169
- case 0:
170
- model = this.flowModel.createAction(actionParam.nodeId);
171
- return [4 /*yield*/, model.execute({
172
- executionId: actionParam.executionId,
173
- actionId: actionParam.actionId,
174
- nodeId: actionParam.nodeId,
175
- next: this.next.bind(this),
176
- })];
177
- case 1:
178
- execResult = _a.sent();
179
- if (execResult && execResult.status === FlowStatus.INTERRUPTED) {
180
- this.interrupted(execResult);
181
- this.saveActionResult({
182
- executionId: actionParam.executionId,
183
- nodeId: actionParam.nodeId,
184
- actionId: actionParam.actionId,
185
- nodeType: execResult.nodeType,
186
- properties: execResult.properties,
187
- outgoing: execResult.outgoing,
188
- status: execResult.status,
189
- detail: execResult.detail,
190
- });
191
- this.removeActionFromRunningMap(actionParam);
192
- }
193
- if (execResult && execResult.status === FlowStatus.ERROR) {
194
- this.error(execResult);
195
- this.saveActionResult({
196
- executionId: actionParam.executionId,
197
- nodeId: actionParam.nodeId,
198
- actionId: actionParam.actionId,
199
- nodeType: execResult.nodeType,
200
- properties: execResult.properties,
201
- outgoing: execResult.outgoing,
202
- status: execResult.status,
203
- detail: execResult.detail,
204
- });
205
- this.removeActionFromRunningMap(actionParam);
206
- }
207
- return [2 /*return*/];
208
- }
209
- });
210
- });
211
- };
212
- Scheduler.prototype.interrupted = function (execResult) {
213
- this.emit(EVENT_INSTANCE_INTERRUPTED, execResult);
214
- };
215
- Scheduler.prototype.error = function (execResult) {
216
- this.emit(EVENT_INSTANCE_ERROR, execResult);
217
- };
218
- Scheduler.prototype.next = function (data) {
219
- var _this = this;
71
+ }
72
+ /**
73
+ * 调度器执行下一个任务
74
+ * 1. 提供给流程模型,用户开始执行第一个任务
75
+ * 2. 内部任务执行完成后,调用此方法继续执行下一个任务
76
+ * 3. 当判断没有可以继续执行的任务后,触发流程结束事件
77
+ * @param runParam
78
+ */
79
+ run(runParam) {
80
+ const nodeQueue = this.nodeQueueMap.get(runParam.executionId);
81
+ // 将同一个 executionId 当前待执行的节点一起执行
82
+ // 避免出现某一个节点执行时间过长,导致其他节点等待时间过长
83
+ while (nodeQueue === null || nodeQueue === void 0 ? void 0 : nodeQueue.length) {
84
+ const currentNode = nodeQueue.pop();
85
+ const actionId = createActionId();
86
+ const actionParam = Object.assign(Object.assign({}, currentNode), { actionId });
87
+ this.pushActionToRunningMap(actionParam);
88
+ this.exec(actionParam);
89
+ }
90
+ if (!this.hasRunningAction(runParam.executionId)) {
91
+ // 当一个流程在 nodeQueueMap 和 actionRunningMap 中都不存在执行的节点时,说明这个流程已经执行完成。
92
+ this.emit(EVENT_INSTANCE_COMPLETE, Object.assign(Object.assign({}, runParam), { status: FlowStatus.COMPLETED }));
93
+ }
94
+ }
95
+ next(data) {
220
96
  if (data.outgoing && data.outgoing.length > 0) {
221
- data.outgoing.forEach(function (item) {
97
+ data.outgoing.forEach((item) => {
222
98
  if (item.result) {
223
- _this.addAction({
99
+ this.addAction({
224
100
  executionId: data.executionId,
225
101
  nodeId: item.target,
226
102
  });
@@ -230,21 +106,70 @@ var Scheduler = /** @class */ (function (_super) {
230
106
  this.saveActionResult(data);
231
107
  this.removeActionFromRunningMap(data);
232
108
  this.run(data);
233
- };
234
- Scheduler.prototype.saveActionResult = function (data) {
235
- var _a;
236
- (_a = this.recorder) === null || _a === void 0 ? void 0 : _a.addActionRecord({
237
- executionId: data.executionId,
238
- actionId: data.actionId,
239
- nodeId: data.nodeId,
240
- nodeType: data.nodeType,
241
- timestamp: Date.now(),
242
- properties: data.properties,
243
- outgoing: data.outgoing,
244
- detail: data.detail,
245
- status: data.status,
109
+ }
110
+ /**
111
+ * 恢复某个任务的执行
112
+ * 可以自定义节点手动实现流程中断,然后通过此方法恢复流程的执行
113
+ * @param resumeParam
114
+ */
115
+ resume(resumeParam) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ const { executionId, actionId, nodeId } = resumeParam;
118
+ this.pushActionToRunningMap({
119
+ executionId,
120
+ actionId,
121
+ nodeId,
122
+ });
123
+ const model = this.flowModel.createAction(nodeId);
124
+ yield (model === null || model === void 0 ? void 0 : model.resume(Object.assign(Object.assign({}, resumeParam), { next: this.next.bind(this) })));
246
125
  });
247
- };
248
- return Scheduler;
249
- }(EventEmitter));
126
+ }
127
+ // 中断时,触发事件
128
+ interrupted(execResult) {
129
+ this.emit(EVENT_INSTANCE_INTERRUPTED, execResult);
130
+ }
131
+ // 报错时,触发事件
132
+ error(execResult) {
133
+ this.emit(EVENT_INSTANCE_ERROR, execResult);
134
+ }
135
+ exec(actionParam) {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ const { executionId, actionId, nodeId } = actionParam;
138
+ const model = this.flowModel.createAction(nodeId);
139
+ const execResult = yield (model === null || model === void 0 ? void 0 : model.execute({
140
+ executionId,
141
+ actionId,
142
+ nodeId,
143
+ next: this.next.bind(this),
144
+ }));
145
+ if (execResult) {
146
+ const { nodeType, properties, outgoing, status, detail } = execResult;
147
+ const actionResult = {
148
+ // actionParam
149
+ executionId,
150
+ actionId,
151
+ nodeId,
152
+ // execResult
153
+ nodeType,
154
+ properties,
155
+ outgoing,
156
+ status,
157
+ detail,
158
+ };
159
+ if ((execResult === null || execResult === void 0 ? void 0 : execResult.status) === FlowStatus.INTERRUPTED) {
160
+ this.interrupted(execResult);
161
+ this.saveActionResult(actionResult);
162
+ this.removeActionFromRunningMap(actionParam);
163
+ }
164
+ if ((execResult === null || execResult === void 0 ? void 0 : execResult.status) === FlowStatus.ERROR) {
165
+ this.error(execResult);
166
+ this.saveActionResult(actionResult);
167
+ this.removeActionFromRunningMap(actionParam);
168
+ }
169
+ }
170
+ // TODO: 考虑停下所有的任务
171
+ });
172
+ }
173
+ }
250
174
  export default Scheduler;
175
+ //# sourceMappingURL=Scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Scheduler.js","sourceRoot":"","sources":["../src/Scheduler.ts"],"names":[],"mappings":";AAGA,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC1B,UAAU,GACX,MAAM,YAAY,CAAA;AAEnB;;;GAGG;AACH,MAAM,OAAO,SAAU,SAAQ,YAAY;IAqBzC,YAAY,MAAiC;QAC3C,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAA;QAC7B,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAA;QACjC,IAAI,CAAC,SAAS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;iBAC7C;aACF;YACD,kBAAkB;QACpB,CAAC;KAAA;CACF;AAkBD,eAAe,SAAS,CAAA"}
@@ -1,10 +1,10 @@
1
1
  // baseType
2
- export var BASE_START_NODE = 'start';
3
- // event name
4
- export var EVENT_INSTANCE_COMPLETE = 'instance:complete';
5
- export var EVENT_INSTANCE_INTERRUPTED = 'instance:interrupted';
6
- export var EVENT_INSTANCE_ERROR = 'instance:error';
7
- // flow status
2
+ export const BASE_START_NODE = 'start';
3
+ // eventType
4
+ export const EVENT_INSTANCE_COMPLETE = 'instance:complete';
5
+ export const EVENT_INSTANCE_INTERRUPTED = 'instance:interrupted';
6
+ export const EVENT_INSTANCE_ERROR = 'instance:error';
7
+ // flowStatus
8
8
  export var FlowStatus;
9
9
  (function (FlowStatus) {
10
10
  FlowStatus["COMPLETED"] = "completed";
@@ -13,10 +13,11 @@ export var FlowStatus;
13
13
  FlowStatus["PENDING"] = "pending";
14
14
  FlowStatus["ERROR"] = "error";
15
15
  })(FlowStatus || (FlowStatus = {}));
16
- // action status
16
+ // actionStatus
17
17
  export var ActionStatus;
18
18
  (function (ActionStatus) {
19
19
  ActionStatus["SUCCESS"] = "success";
20
20
  ActionStatus["ERROR"] = "error";
21
21
  ActionStatus["INTERRUPTED"] = "interrupted";
22
22
  })(ActionStatus || (ActionStatus = {}));
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAA;AAEtC,YAAY;AACZ,MAAM,CAAC,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAC1D,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAA;AAChE,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAA;AAEpD,aAAa;AACb,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,qCAAuB,CAAA;IACvB,yCAA2B,CAAA;IAC3B,iCAAmB,CAAA;IACnB,iCAAmB,CAAA;IACnB,6BAAe,CAAA;AACjB,CAAC,EANW,UAAU,KAAV,UAAU,QAMrB;AAED,eAAe;AACf,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,mCAAmB,CAAA;IACnB,+BAAe,CAAA;IACf,2CAA2B,CAAA;AAC7B,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB"}
@@ -0,0 +1,29 @@
1
+ export var ErrorCode;
2
+ (function (ErrorCode) {
3
+ // 模型数据错误
4
+ ErrorCode[ErrorCode["NONE_START_NODE"] = 1000] = "NONE_START_NODE";
5
+ ErrorCode[ErrorCode["NONE_NODE_ID"] = 1001] = "NONE_NODE_ID";
6
+ // 表达式错误
7
+ ErrorCode[ErrorCode["NO_DOCUMENT_BODY"] = 2001] = "NO_DOCUMENT_BODY";
8
+ })(ErrorCode || (ErrorCode = {}));
9
+ export var WarningCode;
10
+ (function (WarningCode) {
11
+ WarningCode[WarningCode["NONE_START_NODE_IN_DATA"] = 2000] = "NONE_START_NODE_IN_DATA";
12
+ WarningCode[WarningCode["START_NODE_INCOMING"] = 2001] = "START_NODE_INCOMING";
13
+ // 表达式判断异常
14
+ WarningCode[WarningCode["EXPRESSION_EXEC_ERROR"] = 3000] = "EXPRESSION_EXEC_ERROR";
15
+ })(WarningCode || (WarningCode = {}));
16
+ // TODO: 感觉这块可以用个国际化插件,这样配置不同语言加文件就可以了。
17
+ const errorMsgMapCn = {
18
+ [ErrorCode.NONE_START_NODE]: '未找到入度为0的节点',
19
+ [ErrorCode.NONE_NODE_ID]: '流程数据中存在没有此节点',
20
+ [ErrorCode.NO_DOCUMENT_BODY]: '找不到document.body, 请在DOM加载完成后再执行',
21
+ };
22
+ const warningMsgMapCn = {
23
+ [WarningCode.NONE_START_NODE_IN_DATA]: '初始化数据中未找到入度为0的节点',
24
+ [WarningCode.START_NODE_INCOMING]: '开始节点不允许被连入',
25
+ [WarningCode.EXPRESSION_EXEC_ERROR]: '表达式执行异常',
26
+ };
27
+ export const getErrorMsg = (code) => `error[${code}]: ${errorMsgMapCn[code]}`;
28
+ export const getWarningMsg = (code) => `warning[${code}]: ${warningMsgMapCn[code]}`;
29
+ //# sourceMappingURL=logCode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logCode.js","sourceRoot":"","sources":["../../src/constant/logCode.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,SAAS;IACT,kEAAsB,CAAA;IACtB,4DAAmB,CAAA;IAEnB,QAAQ;IACR,oEAAuB,CAAA;AACzB,CAAC,EAPW,SAAS,KAAT,SAAS,QAOpB;AAED,MAAM,CAAN,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,sFAA8B,CAAA;IAC9B,8EAA0B,CAAA;IAE1B,UAAU;IACV,kFAA4B,CAAA;AAC9B,CAAC,EANW,WAAW,KAAX,WAAW,QAMtB;AAED,uCAAuC;AACvC,MAAM,aAAa,GAAG;IACpB,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,YAAY;IACzC,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,cAAc;IACxC,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAAE,iCAAiC;CAChE,CAAA;AAED,MAAM,eAAe,GAAG;IACtB,CAAC,WAAW,CAAC,uBAAuB,CAAC,EAAE,kBAAkB;IACzD,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,YAAY;IAC/C,CAAC,WAAW,CAAC,qBAAqB,CAAC,EAAE,SAAS;CAC/C,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAe,EAAE,EAAE,CAC7C,SAAS,IAAI,MAAM,aAAa,CAAC,IAAI,CAAC,EAAE,CAAA;AAC1C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAiB,EAAE,EAAE,CACjD,WAAW,IAAI,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ declare const runInBrowserContext: (code: string, globalData?: {}) => Promise<null>;
2
+ export { runInBrowserContext };
@@ -0,0 +1,30 @@
1
+ import { __awaiter } from "tslib";
2
+ import { ErrorCode, WarningCode, getErrorMsg, getWarningMsg, } from '../constant/logCode';
3
+ const runInBrowserContext = (code, globalData = {}) => __awaiter(void 0, void 0, void 0, function* () {
4
+ const iframe = document.createElement('iframe');
5
+ iframe.style.display = 'none';
6
+ if (!document || !document.body) {
7
+ console.error(getErrorMsg(ErrorCode.NO_DOCUMENT_BODY));
8
+ }
9
+ document.body.appendChild(iframe);
10
+ const iframeWindow = iframe.contentWindow;
11
+ const iframeEval = iframeWindow.eval;
12
+ Object.keys(globalData).forEach((key) => {
13
+ iframeWindow[key] = globalData[key];
14
+ });
15
+ let res = null;
16
+ try {
17
+ res = iframeEval.call(iframeWindow, code);
18
+ }
19
+ catch (e) {
20
+ console.warn(getWarningMsg(WarningCode.EXPRESSION_EXEC_ERROR), {
21
+ code,
22
+ globalData,
23
+ e,
24
+ });
25
+ }
26
+ document.body.removeChild(iframe);
27
+ return res;
28
+ });
29
+ export { runInBrowserContext };
30
+ //# sourceMappingURL=brewserVm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brewserVm.js","sourceRoot":"","sources":["../../src/expression/brewserVm.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,SAAS,EACT,WAAW,EACX,WAAW,EACX,aAAa,GACd,MAAM,qBAAqB,CAAA;AAE5B,MAAM,mBAAmB,GAAG,CAAO,IAAY,EAAE,UAAU,GAAG,EAAE,EAAE,EAAE;IAClE,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;IAC/C,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAA;IAC7B,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;QAC/B,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,CAAA;KACvD;IACD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAEjC,MAAM,YAAY,GAAG,MAAM,CAAC,aAAoB,CAAA;IAChD,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAA;IACpC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;QAC9C,YAAY,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;IAEF,IAAI,GAAG,GAAG,IAAI,CAAA;IACd,IAAI;QACF,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;KAC1C;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,qBAAqB,CAAC,EAAE;YAC7D,IAAI;YACJ,UAAU;YACV,CAAC;SACF,CAAC,CAAA;KACH;IACD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACjC,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA,CAAA;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
@@ -1,2 +1,2 @@
1
1
  declare const getExpressionResult: (code: string, context: any) => Promise<any>;
2
- export { getExpressionResult, };
2
+ export { getExpressionResult };
@@ -1,60 +1,17 @@
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 };
1
+ import { __awaiter } from "tslib";
2
+ import { runInNodeContext } from './nodeVm';
3
+ import { runInBrowserContext } from './brewserVm';
4
+ import { isInNodeJS, isInBrowser, globalScope } from '../utils';
5
+ const getExpressionResult = (code, context) => __awaiter(void 0, void 0, void 0, function* () {
6
+ if (isInNodeJS) {
7
+ const r = yield runInNodeContext(code, context);
8
+ return r;
35
9
  }
36
- };
37
- import { runInNewContext } from './nodeVm';
38
- import { runInBrowserContext } from './browserVm';
39
- import { isInNodeJS, isInBrowser, globalScope } from '../util/global';
40
- var getExpressionResult = function (code, context) { return __awaiter(void 0, void 0, void 0, function () {
41
- var r, r;
42
- return __generator(this, function (_a) {
43
- switch (_a.label) {
44
- case 0:
45
- if (!isInNodeJS) return [3 /*break*/, 2];
46
- return [4 /*yield*/, runInNewContext(code, context)];
47
- case 1:
48
- r = _a.sent();
49
- return [2 /*return*/, r];
50
- case 2:
51
- if (!isInBrowser) return [3 /*break*/, 4];
52
- return [4 /*yield*/, runInBrowserContext(code, context)];
53
- case 3:
54
- r = _a.sent();
55
- return [2 /*return*/, r];
56
- case 4: return [2 /*return*/, globalScope.eval(code)]; // eslint-disable-line no-eval
57
- }
58
- });
59
- }); };
60
- export { getExpressionResult, };
10
+ if (isInBrowser) {
11
+ const r = yield runInBrowserContext(code, context);
12
+ return r;
13
+ }
14
+ return globalScope.eval(code);
15
+ });
16
+ export { getExpressionResult };
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/expression/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE/D,MAAM,mBAAmB,GAAG,CAAO,IAAY,EAAE,OAAY,EAAE,EAAE;IAC/D,IAAI,UAAU,EAAE;QACd,MAAM,CAAC,GAAG,MAAM,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAC/C,OAAO,CAAC,CAAA;KACT;IACD,IAAI,WAAW,EAAE;QACf,MAAM,CAAC,GAAG,MAAM,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAClD,OAAO,CAAC,CAAA;KACT;IACD,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC,CAAA,CAAA;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
@@ -1,2 +1,4 @@
1
- declare const runInNewContext: (code: string, globalData?: any) => Promise<any>;
2
- export { runInNewContext, };
1
+ /// <reference types="node" />
2
+ import vm from 'node:vm';
3
+ declare const runInNodeContext: (code: string, globalData?: Record<string, unknown>) => Promise<vm.Context>;
4
+ export { runInNodeContext };