@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
@@ -1,252 +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
- var __values = (this && this.__values) || function(o) {
50
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
51
- if (m) return m.call(o);
52
- if (o && typeof o.length === "number") return {
53
- next: function () {
54
- if (o && i >= o.length) o = void 0;
55
- return { value: o && o[i++], done: !o };
56
- }
57
- };
58
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
59
- };
60
- Object.defineProperty(exports, "__esModule", { value: true });
61
- var constant_1 = require("../constant/constant");
62
- var expression_1 = require("../expression");
63
- var BaseNode = /** @class */ (function () {
64
- function BaseNode(_a) {
65
- var nodeConfig = _a.nodeConfig, context = _a.context, globalData = _a.globalData;
66
- this.outgoing = nodeConfig.outgoing;
67
- this.incoming = nodeConfig.incoming;
68
- this.nodeId = nodeConfig.id;
69
- this.type = nodeConfig.type;
70
- this.properties = nodeConfig.properties || {};
71
- this.context = context;
72
- this.globalData = globalData;
73
- this.baseType = 'base';
74
- }
75
- /**
76
- * 节点的每一次执行都会生成一个唯一的actionId
77
- */
78
- BaseNode.prototype.execute = function (params) {
79
- return __awaiter(this, void 0, void 0, function () {
80
- var r, status, outgoing, detail;
81
- return __generator(this, function (_a) {
82
- switch (_a.label) {
83
- case 0: return [4 /*yield*/, this.action({
84
- executionId: params.executionId,
85
- actionId: params.actionId,
86
- nodeId: this.nodeId,
87
- })];
88
- case 1:
89
- r = _a.sent();
90
- status = r ? r.status : 'success';
91
- if (!(status === constant_1.ActionStatus.SUCCESS)) return [3 /*break*/, 3];
92
- return [4 /*yield*/, this.getOutgoing()];
93
- case 2:
94
- outgoing = _a.sent();
95
- detail = r ? r.detail : {};
96
- params.next({
97
- status: constant_1.ActionStatus.SUCCESS,
98
- detail: detail,
99
- executionId: params.executionId,
100
- actionId: params.actionId,
101
- nodeId: this.nodeId,
102
- nodeType: this.type,
103
- properties: this.properties,
104
- outgoing: outgoing,
105
- });
106
- _a.label = 3;
107
- case 3: return [2 /*return*/, {
108
- status: status,
109
- detail: r && r.detail,
110
- executionId: params.executionId,
111
- actionId: params.actionId,
112
- nodeId: this.nodeId,
113
- nodeType: this.type,
114
- properties: this.properties,
115
- outgoing: [],
116
- }];
117
- }
118
- });
119
- });
120
- };
121
- /**
122
- * 节点在执行中断后,可以通过resume方法恢复执行。
123
- * 自定义节点时不建议重写此方法
124
- */
125
- BaseNode.prototype.resume = function (params) {
126
- return __awaiter(this, void 0, void 0, function () {
127
- var outgoing;
128
- return __generator(this, function (_a) {
129
- switch (_a.label) {
130
- case 0: return [4 /*yield*/, this.getOutgoing()];
131
- case 1:
132
- outgoing = _a.sent();
133
- return [4 /*yield*/, this.onResume({
134
- executionId: params.executionId,
135
- nodeId: params.nodeId,
136
- actionId: params.actionId,
137
- data: params.data,
138
- })];
139
- case 2:
140
- _a.sent();
141
- params.next({
142
- executionId: params.executionId,
143
- actionId: params.actionId,
144
- nodeId: this.nodeId,
145
- nodeType: this.type,
146
- properties: this.properties,
147
- outgoing: outgoing,
148
- status: constant_1.ActionStatus.SUCCESS,
149
- });
150
- return [2 /*return*/, undefined];
151
- }
152
- });
153
- });
154
- };
155
- BaseNode.prototype.getOutgoing = function () {
156
- return __awaiter(this, void 0, void 0, function () {
157
- var outgoing, expressions, _a, _b, item, properties, result;
158
- var e_1, _c;
159
- var _this = this;
160
- return __generator(this, function (_d) {
161
- switch (_d.label) {
162
- case 0:
163
- outgoing = [];
164
- expressions = [];
165
- try {
166
- for (_a = __values(this.outgoing), _b = _a.next(); !_b.done; _b = _a.next()) {
167
- item = _b.value;
168
- properties = item.properties;
169
- expressions.push(this.isPass(properties));
170
- }
171
- }
172
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
173
- finally {
174
- try {
175
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
176
- }
177
- finally { if (e_1) throw e_1.error; }
178
- }
179
- return [4 /*yield*/, Promise.all(expressions)];
180
- case 1:
181
- result = _d.sent();
182
- result.forEach(function (item, index) {
183
- var out = _this.outgoing[index];
184
- out.result = item;
185
- outgoing.push(out);
186
- });
187
- return [2 /*return*/, outgoing];
188
- }
189
- });
190
- });
191
- };
192
- BaseNode.prototype.isPass = function (properties) {
193
- return __awaiter(this, void 0, void 0, function () {
194
- var conditionExpression, result, e_2;
195
- return __generator(this, function (_a) {
196
- switch (_a.label) {
197
- case 0:
198
- if (!properties)
199
- return [2 /*return*/, true];
200
- conditionExpression = properties.conditionExpression;
201
- if (!conditionExpression)
202
- return [2 /*return*/, true];
203
- _a.label = 1;
204
- case 1:
205
- _a.trys.push([1, 3, , 4]);
206
- return [4 /*yield*/, expression_1.getExpressionResult("isPassResult = (" + conditionExpression + ")", __assign({}, this.globalData))];
207
- case 2:
208
- result = _a.sent();
209
- return [2 /*return*/, result.isPassResult];
210
- case 3:
211
- e_2 = _a.sent();
212
- return [2 /*return*/, false];
213
- case 4: return [2 /*return*/];
214
- }
215
- });
216
- });
217
- };
218
- /**
219
- * 节点的执行逻辑
220
- * @overridable 可以自定义节点重写此方法。
221
- * @param params.executionId 流程执行记录ID
222
- * @param params.actionId 此节点执行记录ID
223
- * @param params.nodeId 节点ID
224
- * @returns 返回下一步的执行参数
225
- * 当不返回时,表示此节点执行成功,流程会继续执行下一步。
226
- * 当返回时,返回格式
227
- */
228
- BaseNode.prototype.action = function (params) {
229
- return __awaiter(this, void 0, void 0, function () {
230
- return __generator(this, function (_a) {
231
- return [2 /*return*/, null];
232
- });
233
- });
234
- };
235
- /**
236
- * 节点的重新恢复执行逻辑
237
- * @overridable 可以自定义节点重写此方法。
238
- * @param params.executionId 流程执行记录ID
239
- * @param params.actionId 此节点执行记录ID
240
- * @param params.nodeId 节点ID
241
- */
242
- BaseNode.prototype.onResume = function (params) {
243
- return __awaiter(this, void 0, void 0, function () {
244
- return __generator(this, function (_a) {
245
- return [2 /*return*/, undefined];
246
- });
247
- });
248
- };
249
- BaseNode.nodeTypeName = 'BaseNode';
250
- return BaseNode;
251
- }());
252
- exports.default = BaseNode;
@@ -1,27 +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
- Object.defineProperty(exports, "__esModule", { value: true });
16
- var BaseNode_1 = require("./BaseNode");
17
- var StartNode = /** @class */ (function (_super) {
18
- __extends(StartNode, _super);
19
- function StartNode() {
20
- var _this = _super !== null && _super.apply(this, arguments) || this;
21
- _this.baseType = 'start';
22
- return _this;
23
- }
24
- StartNode.nodeTypeName = 'StartNode';
25
- return StartNode;
26
- }(BaseNode_1.default));
27
- exports.default = StartNode;
@@ -1,27 +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
- Object.defineProperty(exports, "__esModule", { value: true });
16
- var BaseNode_1 = require("./BaseNode");
17
- var TaskNode = /** @class */ (function (_super) {
18
- __extends(TaskNode, _super);
19
- function TaskNode() {
20
- var _this = _super !== null && _super.apply(this, arguments) || this;
21
- _this.baseType = 'task';
22
- return _this;
23
- }
24
- TaskNode.nodeTypeName = 'TaskNode';
25
- return TaskNode;
26
- }(BaseNode_1.default));
27
- exports.default = TaskNode;
@@ -1,168 +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
- 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 DELETED
@@ -1,16 +0,0 @@
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
- };
@@ -1,32 +0,0 @@
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;
@@ -1,28 +0,0 @@
1
- var _a, _b;
2
- export var ErrorCode;
3
- (function (ErrorCode) {
4
- // 模型数据错误
5
- ErrorCode[ErrorCode["NONE_START_NODE"] = 1000] = "NONE_START_NODE";
6
- ErrorCode[ErrorCode["NONE_NODE_ID"] = 1001] = "NONE_NODE_ID";
7
- // 表达式错误
8
- ErrorCode[ErrorCode["NO_DOCUMENT_BODY"] = 2001] = "NO_DOCUMENT_BODY";
9
- })(ErrorCode || (ErrorCode = {}));
10
- export var WarningCode;
11
- (function (WarningCode) {
12
- WarningCode[WarningCode["NONE_START_NODE_IN_DATA"] = 2000] = "NONE_START_NODE_IN_DATA";
13
- WarningCode[WarningCode["START_NODE_INCOMING"] = 2001] = "START_NODE_INCOMING";
14
- // 表达式判断异常
15
- WarningCode[WarningCode["EXPRESSION_EXEC_ERROR"] = 3000] = "EXPRESSION_EXEC_ERROR";
16
- })(WarningCode || (WarningCode = {}));
17
- var errorMsgMapCn = (_a = {},
18
- _a[ErrorCode.NONE_START_NODE] = '未找到入度为0的节点',
19
- _a[ErrorCode.NONE_NODE_ID] = '流程数据中存在没有此节点',
20
- _a[ErrorCode.NO_DOCUMENT_BODY] = '找不到document.body, 请在DOM加载完成后再执行',
21
- _a);
22
- var warningMsgMapCn = (_b = {},
23
- _b[WarningCode.NONE_START_NODE_IN_DATA] = '初始化数据中未找到入度为0的节点',
24
- _b[WarningCode.START_NODE_INCOMING] = '开始节点不允许被连入',
25
- _b[WarningCode.EXPRESSION_EXEC_ERROR] = '表达式执行异常',
26
- _b);
27
- export var getErrorMsg = function (code) { return "error[" + code + "]: " + errorMsgMapCn[code]; };
28
- export var getWarningMsg = function (code) { return "warning[" + code + "]: " + warningMsgMapCn[code]; };
@@ -1,4 +0,0 @@
1
- declare const createContext: (globalData: any) => any;
2
- declare const runInContext: (code: any, context: any) => any;
3
- declare const runInBrowserContext: (code: string, globalData?: any) => Promise<any>;
4
- export { runInBrowserContext, createContext, runInContext, };
@@ -1,76 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import { ErrorCode, WarningCode, getErrorMsg, getWarningMsg, } from '../constant/LogCode';
38
- var createContext = function (globalData) {
39
- var iframe = document.createElement('iframe');
40
- iframe.style.display = 'none';
41
- if (!document || !document.body) {
42
- console.error(getErrorMsg(ErrorCode.NO_DOCUMENT_BODY));
43
- }
44
- document.body.appendChild(iframe);
45
- var iframeWindow = iframe.contentWindow;
46
- iframeWindow.parent = null;
47
- Object.keys(globalData).forEach(function (key) {
48
- iframeWindow[key] = globalData[key];
49
- });
50
- return iframeWindow;
51
- };
52
- var runInContext = function (code, context) {
53
- try {
54
- var iframeEval = context.eval;
55
- iframeEval.call(context, code);
56
- if (context.frameElement) {
57
- document.body.removeChild(context.frameElement);
58
- }
59
- }
60
- catch (e) {
61
- console.warn(getWarningMsg(WarningCode.EXPRESSION_EXEC_ERROR), { code: code, context: context, e: e });
62
- }
63
- return context;
64
- };
65
- var runInBrowserContext = function (code, globalData) {
66
- if (globalData === void 0) { globalData = {}; }
67
- return __awaiter(void 0, void 0, void 0, function () {
68
- var context;
69
- return __generator(this, function (_a) {
70
- context = createContext(globalData);
71
- runInContext(code, context);
72
- return [2 /*return*/, context];
73
- });
74
- });
75
- };
76
- export { runInBrowserContext, createContext, runInContext, };
@@ -1,2 +0,0 @@
1
- declare const getExpressionResult: (code: string, context: any) => Promise<any>;
2
- export { getExpressionResult, };