@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
@@ -1,63 +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
- var nodeVm_1 = require("./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, r;
45
- return __generator(this, function (_a) {
46
- switch (_a.label) {
47
- case 0:
48
- if (!global_1.isInNodeJS) return [3 /*break*/, 2];
49
- return [4 /*yield*/, nodeVm_1.runInNewContext(code, context)];
50
- case 1:
51
- r = _a.sent();
52
- return [2 /*return*/, r];
53
- case 2:
54
- if (!global_1.isInBrowser) return [3 /*break*/, 4];
55
- return [4 /*yield*/, browserVm_1.runInBrowserContext(code, context)];
56
- case 3:
57
- r = _a.sent();
58
- return [2 /*return*/, r];
59
- case 4: return [2 /*return*/, global_1.globalScope.eval(code)]; // eslint-disable-line no-eval
60
- }
61
- });
62
- }); };
63
- exports.getExpressionResult = getExpressionResult;
@@ -1,53 +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.runInNewContext = void 0;
40
- /* eslint-disable global-require */
41
- var vm = require('vm');
42
- var runInNewContext = function (code, globalData) {
43
- if (globalData === void 0) { globalData = {}; }
44
- return __awaiter(void 0, void 0, void 0, function () {
45
- var context;
46
- return __generator(this, function (_a) {
47
- context = vm.createContext(globalData);
48
- vm.runInContext(code, context);
49
- return [2 /*return*/, context];
50
- });
51
- });
52
- };
53
- exports.runInNewContext = runInNewContext;
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;
@@ -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;