@logicflow/engine 0.0.10-beta.0 → 0.0.11-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/README.md +2 -5
  2. package/cjs/EventEmitter.js +70 -0
  3. package/cjs/FlowModel.js +277 -0
  4. package/cjs/Scheduler.js +252 -0
  5. package/{lib/constant/logCode.js → cjs/constant/LogCode.js} +13 -16
  6. package/{lib/constant/index.js → cjs/constant/constant.js} +3 -4
  7. package/cjs/expression/browserVm.js +81 -0
  8. package/cjs/expression/index.js +57 -0
  9. package/cjs/index.js +210 -0
  10. package/cjs/nodes/BaseNode.js +252 -0
  11. package/cjs/nodes/StartNode.js +27 -0
  12. package/cjs/nodes/TaskNode.js +27 -0
  13. package/cjs/recorder/index.js +168 -0
  14. package/cjs/util/ID.js +16 -0
  15. package/cjs/util/global.js +32 -0
  16. package/{lib/utils → cjs/util}/storage.js +17 -18
  17. package/es/EventEmitter.d.ts +4 -34
  18. package/es/EventEmitter.js +48 -70
  19. package/es/FlowModel.d.ts +73 -75
  20. package/es/FlowModel.js +173 -130
  21. package/es/Scheduler.d.ts +34 -50
  22. package/es/Scheduler.js +209 -134
  23. package/es/constant/LogCode.js +28 -0
  24. package/es/constant/{index.js → constant.js} +7 -8
  25. package/es/expression/browserVm.d.ts +4 -0
  26. package/es/expression/browserVm.js +76 -0
  27. package/es/expression/index.d.ts +1 -1
  28. package/es/expression/index.js +53 -16
  29. package/es/index.d.ts +38 -135
  30. package/es/index.js +144 -92
  31. package/es/nodes/BaseNode.d.ts +110 -0
  32. package/es/nodes/BaseNode.js +250 -0
  33. package/es/nodes/{start.d.ts → StartNode.d.ts} +2 -3
  34. package/es/nodes/StartNode.js +25 -0
  35. package/es/nodes/{task.d.ts → TaskNode.d.ts} +2 -3
  36. package/es/nodes/TaskNode.js +25 -0
  37. package/es/recorder/index.d.ts +10 -36
  38. package/es/recorder/index.js +135 -82
  39. package/es/util/ID.js +13 -0
  40. package/es/util/global.d.ts +5 -0
  41. package/es/util/global.js +26 -0
  42. package/es/{utils → util}/storage.js +16 -17
  43. package/lib/main.js +1 -0
  44. package/package.json +71 -30
  45. package/dist/index.js +0 -2
  46. package/dist/index.js.map +0 -1
  47. package/es/EventEmitter.js.map +0 -1
  48. package/es/FlowModel.js.map +0 -1
  49. package/es/Scheduler.js.map +0 -1
  50. package/es/constant/index.js.map +0 -1
  51. package/es/constant/logCode.js +0 -29
  52. package/es/constant/logCode.js.map +0 -1
  53. package/es/expression/brewserVm.d.ts +0 -2
  54. package/es/expression/brewserVm.js +0 -30
  55. package/es/expression/brewserVm.js.map +0 -1
  56. package/es/expression/index.js.map +0 -1
  57. package/es/expression/nodeVm.d.ts +0 -4
  58. package/es/expression/nodeVm.js +0 -10
  59. package/es/expression/nodeVm.js.map +0 -1
  60. package/es/index.js.map +0 -1
  61. package/es/nodes/base.d.ts +0 -108
  62. package/es/nodes/base.js +0 -149
  63. package/es/nodes/base.js.map +0 -1
  64. package/es/nodes/index.d.ts +0 -3
  65. package/es/nodes/index.js +0 -4
  66. package/es/nodes/index.js.map +0 -1
  67. package/es/nodes/start.js +0 -11
  68. package/es/nodes/start.js.map +0 -1
  69. package/es/nodes/task.js +0 -11
  70. package/es/nodes/task.js.map +0 -1
  71. package/es/platform/browser/browserVm.d.ts +0 -4
  72. package/es/platform/browser/browserVm.js +0 -44
  73. package/es/platform/browser/browserVm.js.map +0 -1
  74. package/es/platform/browser/index.d.ts +0 -4
  75. package/es/platform/browser/index.js +0 -23
  76. package/es/platform/browser/index.js.map +0 -1
  77. package/es/platform/index.d.ts +0 -1
  78. package/es/platform/index.js +0 -2
  79. package/es/platform/index.js.map +0 -1
  80. package/es/platform/node/index.d.ts +0 -4
  81. package/es/platform/node/index.js +0 -23
  82. package/es/platform/node/index.js.map +0 -1
  83. package/es/platform/node/nodeVm.d.ts +0 -1
  84. package/es/platform/node/nodeVm.js +0 -9
  85. package/es/platform/node/nodeVm.js.map +0 -1
  86. package/es/recorder/index.js.map +0 -1
  87. package/es/utils/global.d.ts +0 -5
  88. package/es/utils/global.js +0 -27
  89. package/es/utils/global.js.map +0 -1
  90. package/es/utils/id.js +0 -14
  91. package/es/utils/id.js.map +0 -1
  92. package/es/utils/index.d.ts +0 -4
  93. package/es/utils/index.js +0 -5
  94. package/es/utils/index.js.map +0 -1
  95. package/es/utils/storage.js.map +0 -1
  96. package/lib/EventEmitter.d.ts +0 -37
  97. package/lib/EventEmitter.js +0 -94
  98. package/lib/EventEmitter.js.map +0 -1
  99. package/lib/FlowModel.d.ts +0 -146
  100. package/lib/FlowModel.js +0 -236
  101. package/lib/FlowModel.js.map +0 -1
  102. package/lib/Scheduler.d.ts +0 -78
  103. package/lib/Scheduler.js +0 -179
  104. package/lib/Scheduler.js.map +0 -1
  105. package/lib/constant/index.d.ts +0 -16
  106. package/lib/constant/index.js.map +0 -1
  107. package/lib/constant/logCode.d.ts +0 -12
  108. package/lib/constant/logCode.js.map +0 -1
  109. package/lib/expression/brewserVm.d.ts +0 -2
  110. package/lib/expression/brewserVm.js +0 -33
  111. package/lib/expression/brewserVm.js.map +0 -1
  112. package/lib/expression/index.d.ts +0 -2
  113. package/lib/expression/index.js +0 -20
  114. package/lib/expression/index.js.map +0 -1
  115. package/lib/expression/nodeVm.d.ts +0 -4
  116. package/lib/expression/nodeVm.js +0 -13
  117. package/lib/expression/nodeVm.js.map +0 -1
  118. package/lib/index.d.ts +0 -157
  119. package/lib/index.js +0 -159
  120. package/lib/index.js.map +0 -1
  121. package/lib/nodes/base.d.ts +0 -108
  122. package/lib/nodes/base.js +0 -152
  123. package/lib/nodes/base.js.map +0 -1
  124. package/lib/nodes/index.d.ts +0 -3
  125. package/lib/nodes/index.js +0 -7
  126. package/lib/nodes/index.js.map +0 -1
  127. package/lib/nodes/start.d.ts +0 -6
  128. package/lib/nodes/start.js +0 -15
  129. package/lib/nodes/start.js.map +0 -1
  130. package/lib/nodes/task.d.ts +0 -6
  131. package/lib/nodes/task.js +0 -15
  132. package/lib/nodes/task.js.map +0 -1
  133. package/lib/platform/browser/browserVm.d.ts +0 -4
  134. package/lib/platform/browser/browserVm.js +0 -49
  135. package/lib/platform/browser/browserVm.js.map +0 -1
  136. package/lib/platform/browser/index.d.ts +0 -4
  137. package/lib/platform/browser/index.js +0 -28
  138. package/lib/platform/browser/index.js.map +0 -1
  139. package/lib/platform/index.d.ts +0 -1
  140. package/lib/platform/index.js +0 -5
  141. package/lib/platform/index.js.map +0 -1
  142. package/lib/platform/node/index.d.ts +0 -4
  143. package/lib/platform/node/index.js +0 -28
  144. package/lib/platform/node/index.js.map +0 -1
  145. package/lib/platform/node/nodeVm.d.ts +0 -1
  146. package/lib/platform/node/nodeVm.js +0 -13
  147. package/lib/platform/node/nodeVm.js.map +0 -1
  148. package/lib/recorder/index.d.ts +0 -46
  149. package/lib/recorder/index.js +0 -117
  150. package/lib/recorder/index.js.map +0 -1
  151. package/lib/utils/global.d.ts +0 -5
  152. package/lib/utils/global.js +0 -31
  153. package/lib/utils/global.js.map +0 -1
  154. package/lib/utils/id.d.ts +0 -3
  155. package/lib/utils/id.js +0 -20
  156. package/lib/utils/id.js.map +0 -1
  157. package/lib/utils/index.d.ts +0 -4
  158. package/lib/utils/index.js +0 -9
  159. package/lib/utils/index.js.map +0 -1
  160. package/lib/utils/storage.d.ts +0 -7
  161. package/lib/utils/storage.js.map +0 -1
  162. package/src/EventEmitter.ts +0 -103
  163. package/src/FlowModel.ts +0 -325
  164. package/src/Scheduler.ts +0 -244
  165. package/src/constant/index.ts +0 -23
  166. package/src/constant/logCode.ts +0 -34
  167. package/src/expression/brewserVm.ts +0 -36
  168. package/src/expression/index.ts +0 -17
  169. package/src/expression/nodeVm.ts +0 -14
  170. package/src/index.ts +0 -300
  171. package/src/nodes/base.ts +0 -234
  172. package/src/nodes/index.ts +0 -3
  173. package/src/nodes/start.ts +0 -8
  174. package/src/nodes/task.ts +0 -8
  175. package/src/platform/browser/browserVm.ts +0 -52
  176. package/src/platform/browser/index.ts +0 -28
  177. package/src/platform/index.ts +0 -1
  178. package/src/platform/node/index.ts +0 -28
  179. package/src/platform/node/nodeVm.ts +0 -12
  180. package/src/recorder/index.ts +0 -137
  181. package/src/typings.d.ts +0 -0
  182. package/src/utils/global.ts +0 -41
  183. package/src/utils/id.ts +0 -16
  184. package/src/utils/index.ts +0 -5
  185. package/src/utils/storage.ts +0 -55
  186. /package/es/constant/{logCode.d.ts → LogCode.d.ts} +0 -0
  187. /package/es/constant/{index.d.ts → constant.d.ts} +0 -0
  188. /package/es/{utils/id.d.ts → util/ID.d.ts} +0 -0
  189. /package/es/{utils → util}/storage.d.ts +0 -0
package/es/index.d.ts CHANGED
@@ -1,157 +1,60 @@
1
- import { BaseNode, StartNode, TaskNode } from './nodes';
2
- import { FlowModel } from './FlowModel';
3
- import { Recorder } from './recorder';
4
- export declare class Engine {
5
- readonly instanceId: string;
6
- graphData?: Engine.GraphConfigData;
7
- flowModel?: FlowModel;
1
+ import type { ResumeParams, GraphConfigData, EngineConstructorOptions, NextActionParam } from './types.d';
2
+ import FlowModel, { ActionParams } from './FlowModel';
3
+ import StartNode from './nodes/StartNode';
4
+ import TaskNode from './nodes/TaskNode';
5
+ import Recorder from './recorder';
6
+ import { NodeConstructor } from './nodes/BaseNode';
7
+ export default class Engine {
8
+ instanceId: string;
9
+ global: Record<string, any>;
10
+ graphData: GraphConfigData;
11
+ nodeModelMap: Map<string, NodeConstructor>;
12
+ flowModel: FlowModel;
8
13
  recorder?: Recorder;
9
- context?: Record<string, unknown>;
10
- nodeModelMap: Map<string, BaseNode.NodeConstructor>;
11
- constructor(options?: Engine.Options);
14
+ context: Record<string, any>;
15
+ constructor(options?: EngineConstructorOptions);
12
16
  /**
13
17
  * 注册节点
14
18
  * @param nodeConfig { type: 'custom-node', model: NodeClass }
15
19
  */
16
- register(nodeConfig: Engine.NodeConfig): void;
20
+ register(nodeConfig: any): void;
17
21
  /**
18
- * 自定义执行记录的存储,默认浏览器使用 sessionStorage, nodejs 使用内存存储
19
- * 注意:由于执行记录不全会主动删除,所以需要自行清理。
20
- * nodejs 环境建议自定义为持久化存储。
21
- * engine.setCustomRecorder({{
22
+ * 自定义执行记录的存储,默认浏览器使用 sessionStoragenodejs 使用内存存储。
23
+ * 注意:由于执行记录不会主动删除,所以需要自行清理。
24
+ * nodejs环境建议自定义为持久化存储。
25
+ * engine.setCustomRecorder({
22
26
  * async addActionRecord(task) {}
23
27
  * async getTask(actionId) {}
24
28
  * async getExecutionTasks(executionId) {}
25
29
  * clear(instanceId) {}
26
- * }}
27
- * @param recorder
30
+ * });
28
31
  */
29
32
  setCustomRecorder(recorder: Recorder): void;
30
33
  /**
31
34
  * 加载流程图数据
32
35
  */
33
- load({ graphData, startNodeType, globalData, }: Engine.LoadGraphParam): FlowModel;
36
+ load({ graphData, startNodeType, globalData, }: {
37
+ graphData: any;
38
+ startNodeType?: string;
39
+ globalData?: {};
40
+ }): FlowModel;
34
41
  /**
35
- * 执行流程,允许多次调用
42
+ * 执行流程,允许多次调用。
36
43
  */
37
- execute(param?: Partial<Engine.ActionParam>): Promise<Engine.NextActionParam>;
44
+ execute(execParam?: ActionParams): Promise<NextActionParam>;
38
45
  /**
39
- * 中断流程恢复
40
- * @param resumeParam
41
- * @returns
46
+ * 恢复执行
47
+ * 注意此方法只能恢复节点后面的执行,不能恢复流程其他分支的执行。
48
+ * 同理,中断执行也只能中断节点后面的执行,不会中断其他分支的执行。
49
+ * 在实际项目中,如果存在中断节点,建议流程所有的节点都是排他网关,这样可以保证执行的过程不存在分支。
42
50
  */
43
- resume(resumeParam: Engine.ResumeParam): Promise<Engine.NextActionParam | undefined>;
51
+ resume(resumeParam: ResumeParams): Promise<unknown>;
44
52
  getExecutionList(): Promise<any>;
45
- /**
46
- * 获取执行任务记录
47
- * @param executionId
48
- * @returns
49
- */
50
- getExecutionRecord(executionId: Engine.Key): Promise<Recorder.Info[] | null>;
53
+ getExecutionRecord(executionId: any): Promise<any[]>;
51
54
  destroy(): void;
52
- getGlobalData(): Record<string, unknown> | undefined;
53
- setGlobalData(data: Record<string, unknown>): void;
54
- updateGlobalData(data: Record<string, unknown>): void;
55
- }
56
- export declare namespace Engine {
57
- type Point = {
58
- id?: string;
59
- x: number;
60
- y: number;
61
- [key: string]: unknown;
62
- };
63
- type TextConfig = {
64
- value: string;
65
- } & Point;
66
- type NodeData = {
67
- id: string;
68
- type: string;
69
- x?: number;
70
- y?: number;
71
- text?: TextConfig | string;
72
- zIndex?: number;
73
- properties?: Record<string, unknown>;
74
- };
75
- type EdgeData = {
76
- id: string;
77
- /**
78
- * 边的类型,不传默认为lf.setDefaultEdgeType(type)传入的类型。
79
- * LogicFlow内部默认为polyline
80
- */
81
- type?: string;
82
- sourceNodeId: string;
83
- sourceAnchorId?: string;
84
- targetNodeId: string;
85
- targetAnchorId?: string;
86
- startPoint?: {
87
- x: number;
88
- y: number;
89
- };
90
- endPoint?: {
91
- x: number;
92
- y: number;
93
- };
94
- text?: {
95
- x: number;
96
- y: number;
97
- value: string;
98
- } | string;
99
- pointsList?: Point[];
100
- zIndex?: number;
101
- properties?: Record<string, unknown>;
102
- };
103
- type GraphConfigData = {
104
- nodes: NodeData[];
105
- edges: EdgeData[];
106
- };
107
- type LoadGraphParam = {
108
- graphData: GraphConfigData;
109
- startNodeType?: string;
110
- globalData?: Record<string, unknown>;
111
- };
112
- type Options = {
113
- context?: Record<string, unknown>;
114
- debug?: boolean;
115
- };
116
- type Key = string | number;
117
- type NodeConfig = {
118
- type: string;
119
- model: any;
120
- };
121
- type NodeParam = {
122
- executionId: Key;
123
- nodeId: Key;
124
- };
125
- type CommonActionInfo = {
126
- actionId: Key;
127
- } & NodeParam;
128
- type ActionParam = CommonActionInfo;
129
- type ResumeParam = {
130
- data?: Record<string, unknown>;
131
- } & CommonActionInfo;
132
- type ExecParam = {
133
- next: (data: NextActionParam) => void;
134
- } & ActionParam;
135
- type ExecResumeParam = {
136
- next: (data: NextActionParam) => void;
137
- } & ResumeParam;
138
- type ActionStatus = 'success' | 'error' | 'interrupted' | '';
139
- type NextActionParam = {
140
- executionId: Key;
141
- nodeId: Key;
142
- actionId: Key;
143
- nodeType: string;
144
- outgoing: BaseNode.OutgoingConfig[];
145
- properties?: Record<string, unknown>;
146
- detail?: Record<string, unknown>;
147
- status?: ActionStatus;
148
- };
149
- type ActionResult = NextActionParam;
150
- type NodeExecResult = {
151
- nodeType: string;
152
- properties?: Record<string, unknown>;
153
- } & CommonActionInfo & ActionResult;
55
+ getGlobalData(): Record<string, any>;
56
+ setGlobalData(data: any): void;
57
+ updateGlobalData(data: any): void;
154
58
  }
155
- export * from './constant';
156
- export { BaseNode, StartNode, TaskNode, Recorder };
157
- export default Engine;
59
+ export { Engine, TaskNode, StartNode, Recorder, };
60
+ export type { ActionParams, };
package/es/index.js CHANGED
@@ -1,11 +1,57 @@
1
- import { __awaiter } from "tslib";
2
- // import { LogicFlow } from '@logicflow/core';
3
- import { BaseNode, StartNode, TaskNode } from './nodes';
4
- import { FlowModel } from './FlowModel';
5
- import { Recorder } from './recorder';
6
- import { createEngineId } from './utils';
7
- export class Engine {
8
- constructor(options) {
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ 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;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import FlowModel from './FlowModel';
49
+ import StartNode from './nodes/StartNode';
50
+ import TaskNode from './nodes/TaskNode';
51
+ import Recorder from './recorder';
52
+ import { createEngineId } from './util/ID';
53
+ var Engine = /** @class */ (function () {
54
+ function Engine(options) {
9
55
  this.nodeModelMap = new Map();
10
56
  this.instanceId = createEngineId();
11
57
  if (options === null || options === void 0 ? void 0 : options.debug) {
@@ -13,7 +59,6 @@ export class Engine {
13
59
  instanceId: this.instanceId,
14
60
  });
15
61
  }
16
- // 默认注册节点 register default nodes
17
62
  this.register({
18
63
  type: StartNode.nodeTypeName,
19
64
  model: StartNode,
@@ -28,125 +73,132 @@ export class Engine {
28
73
  * 注册节点
29
74
  * @param nodeConfig { type: 'custom-node', model: NodeClass }
30
75
  */
31
- register(nodeConfig) {
76
+ Engine.prototype.register = function (nodeConfig) {
32
77
  this.nodeModelMap.set(nodeConfig.type, nodeConfig.model);
33
- }
78
+ };
34
79
  /**
35
- * 自定义执行记录的存储,默认浏览器使用 sessionStorage, nodejs 使用内存存储
36
- * 注意:由于执行记录不全会主动删除,所以需要自行清理。
37
- * nodejs 环境建议自定义为持久化存储。
38
- * engine.setCustomRecorder({{
80
+ * 自定义执行记录的存储,默认浏览器使用 sessionStoragenodejs 使用内存存储。
81
+ * 注意:由于执行记录不会主动删除,所以需要自行清理。
82
+ * nodejs环境建议自定义为持久化存储。
83
+ * engine.setCustomRecorder({
39
84
  * async addActionRecord(task) {}
40
85
  * async getTask(actionId) {}
41
86
  * async getExecutionTasks(executionId) {}
42
87
  * clear(instanceId) {}
43
- * }}
44
- * @param recorder
88
+ * });
45
89
  */
46
- setCustomRecorder(recorder) {
90
+ Engine.prototype.setCustomRecorder = function (recorder) {
47
91
  this.recorder = recorder;
48
- }
92
+ };
49
93
  /**
50
94
  * 加载流程图数据
51
95
  */
52
- load({ graphData, startNodeType = 'StartNode', globalData = {}, }) {
53
- this.graphData = graphData;
54
- const flowModel = new FlowModel({
96
+ Engine.prototype.load = function (_a) {
97
+ var graphData = _a.graphData, _b = _a.startNodeType, startNodeType = _b === void 0 ? 'StartNode' : _b, _c = _a.globalData, globalData = _c === void 0 ? {} : _c;
98
+ this.flowModel = new FlowModel({
55
99
  nodeModelMap: this.nodeModelMap,
56
100
  recorder: this.recorder,
57
101
  context: this.context,
58
- globalData,
59
- startNodeType,
102
+ globalData: globalData,
103
+ startNodeType: startNodeType,
60
104
  });
61
- flowModel.load(graphData);
62
- this.flowModel = flowModel;
63
- return flowModel;
64
- }
105
+ this.flowModel.load(graphData);
106
+ return this.flowModel;
107
+ };
65
108
  /**
66
- * 执行流程,允许多次调用
109
+ * 执行流程,允许多次调用。
67
110
  */
68
- execute(param) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- return new Promise((resolve, reject) => {
71
- var _a;
72
- let execParam = param;
73
- if (!param) {
74
- execParam = {};
75
- }
76
- (_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.execute(Object.assign(Object.assign({}, execParam), { callback: (result) => {
77
- resolve(result);
78
- }, onError: (error) => {
79
- reject(error);
80
- } }));
111
+ Engine.prototype.execute = function (execParam) {
112
+ return __awaiter(this, void 0, void 0, function () {
113
+ var _this = this;
114
+ return __generator(this, function (_a) {
115
+ return [2 /*return*/, new Promise(function (resolve, reject) {
116
+ if (!execParam) {
117
+ execParam = {};
118
+ }
119
+ _this.flowModel.execute(__assign(__assign({}, execParam), { callback: function (result) {
120
+ resolve(result);
121
+ }, onError: function (error) {
122
+ reject(error);
123
+ } }));
124
+ })];
81
125
  });
82
126
  });
83
- }
127
+ };
84
128
  /**
85
- * 中断流程恢复
86
- * @param resumeParam
87
- * @returns
129
+ * 恢复执行
130
+ * 注意此方法只能恢复节点后面的执行,不能恢复流程其他分支的执行。
131
+ * 同理,中断执行也只能中断节点后面的执行,不会中断其他分支的执行。
132
+ * 在实际项目中,如果存在中断节点,建议流程所有的节点都是排他网关,这样可以保证执行的过程不存在分支。
88
133
  */
89
- resume(resumeParam) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- return new Promise((resolve, reject) => {
92
- var _a;
93
- (_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.resume(Object.assign(Object.assign({}, resumeParam), { callback: (result) => {
94
- resolve(result);
95
- }, onError: (error) => {
96
- reject(error);
97
- } }));
134
+ Engine.prototype.resume = function (resumeParam) {
135
+ return __awaiter(this, void 0, void 0, function () {
136
+ var _this = this;
137
+ return __generator(this, function (_a) {
138
+ return [2 /*return*/, new Promise(function (resolve, reject) {
139
+ _this.flowModel.resume(__assign(__assign({}, resumeParam), { callback: function (result) {
140
+ resolve(result);
141
+ }, onError: function (error) {
142
+ reject(error);
143
+ } }));
144
+ })];
98
145
  });
99
146
  });
100
- }
101
- getExecutionList() {
147
+ };
148
+ Engine.prototype.getExecutionList = function () {
102
149
  var _a;
103
- return __awaiter(this, void 0, void 0, function* () {
104
- return yield ((_a = this.recorder) === null || _a === void 0 ? void 0 : _a.getExecutionList());
150
+ return __awaiter(this, void 0, void 0, function () {
151
+ var executionIds;
152
+ return __generator(this, function (_b) {
153
+ switch (_b.label) {
154
+ case 0: return [4 /*yield*/, ((_a = this.recorder) === null || _a === void 0 ? void 0 : _a.getExecutionList())];
155
+ case 1:
156
+ executionIds = _b.sent();
157
+ return [2 /*return*/, executionIds];
158
+ }
159
+ });
105
160
  });
106
- }
107
- /**
108
- * 获取执行任务记录
109
- * @param executionId
110
- * @returns
111
- */
112
- getExecutionRecord(executionId) {
161
+ };
162
+ Engine.prototype.getExecutionRecord = function (executionId) {
113
163
  var _a, _b;
114
- return __awaiter(this, void 0, void 0, function* () {
115
- const actions = yield ((_a = this.recorder) === null || _a === void 0 ? void 0 : _a.getExecutionActions(executionId));
116
- if (!actions) {
117
- return null;
118
- }
119
- // DONE: 确认 records 的类型
120
- const records = [];
121
- for (let i = 0; i < (actions === null || actions === void 0 ? void 0 : actions.length); i++) {
122
- const action = actions[i];
123
- if (this.recorder) {
124
- records.push((_b = this.recorder) === null || _b === void 0 ? void 0 : _b.getActionRecord(action));
164
+ return __awaiter(this, void 0, void 0, function () {
165
+ var tasks, records, i;
166
+ return __generator(this, function (_c) {
167
+ switch (_c.label) {
168
+ case 0: return [4 /*yield*/, ((_a = this.recorder) === null || _a === void 0 ? void 0 : _a.getExecutionActions(executionId))];
169
+ case 1:
170
+ tasks = _c.sent();
171
+ if (!tasks) {
172
+ return [2 /*return*/, null];
173
+ }
174
+ records = [];
175
+ for (i = 0; i < tasks.length; i++) {
176
+ records.push((_b = this.recorder) === null || _b === void 0 ? void 0 : _b.getActionRecord(tasks[i]));
177
+ }
178
+ return [2 /*return*/, Promise.all(records)];
125
179
  }
126
- }
127
- return Promise.all(records);
180
+ });
128
181
  });
129
- }
130
- destroy() {
182
+ };
183
+ Engine.prototype.destroy = function () {
131
184
  var _a;
132
185
  (_a = this.recorder) === null || _a === void 0 ? void 0 : _a.clear();
133
- }
134
- getGlobalData() {
186
+ };
187
+ Engine.prototype.getGlobalData = function () {
135
188
  var _a;
136
189
  return (_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.globalData;
137
- }
138
- setGlobalData(data) {
190
+ };
191
+ Engine.prototype.setGlobalData = function (data) {
139
192
  if (this.flowModel) {
140
193
  this.flowModel.globalData = data;
141
194
  }
142
- }
143
- updateGlobalData(data) {
195
+ };
196
+ Engine.prototype.updateGlobalData = function (data) {
144
197
  if (this.flowModel) {
145
198
  Object.assign(this.flowModel.globalData, data);
146
199
  }
147
- }
148
- }
149
- export * from './constant';
150
- export { BaseNode, StartNode, TaskNode, Recorder };
200
+ };
201
+ return Engine;
202
+ }());
151
203
  export default Engine;
152
- //# sourceMappingURL=index.js.map
204
+ export { Engine, TaskNode, StartNode, Recorder, };
@@ -0,0 +1,110 @@
1
+ import type { NextActionParam, ActionResult, ExecResumeParams, ExecParams, OutgoingConfig } from '../types.d';
2
+ export interface BaseNodeInterface {
3
+ outgoing: Record<string, any>[];
4
+ incoming: Record<string, any>[];
5
+ nodeId: string;
6
+ type: string;
7
+ readonly baseType: string;
8
+ execute(actionParam: any): Promise<NextActionParam>;
9
+ }
10
+ export declare type NodeConstructor = {
11
+ new (config: {
12
+ nodeConfig: NodeConfig;
13
+ context: Record<string, any>;
14
+ globalData: Record<string, any>;
15
+ }): BaseNode;
16
+ action(params: {
17
+ executionId: string;
18
+ actionId: string;
19
+ nodeId: string;
20
+ }): Promise<NextActionParam>;
21
+ onResume(params: {
22
+ executionId: string;
23
+ actionId: string;
24
+ nodeId: string;
25
+ data?: Record<string, any>;
26
+ }): Promise<void>;
27
+ };
28
+ export declare type IncomingConfig = {
29
+ id: string;
30
+ properties?: Record<string, any>;
31
+ source: string;
32
+ };
33
+ export declare type NodeConfig = {
34
+ id: string;
35
+ type: string;
36
+ properties?: Record<string, any>;
37
+ incoming: IncomingConfig[];
38
+ outgoing: OutgoingConfig[];
39
+ };
40
+ export default class BaseNode implements BaseNodeInterface {
41
+ static nodeTypeName: string;
42
+ /**
43
+ * 节点的出边
44
+ */
45
+ outgoing: OutgoingConfig[];
46
+ /**
47
+ * 节点的入边
48
+ */
49
+ incoming: IncomingConfig[];
50
+ /**
51
+ * 节点的属性
52
+ */
53
+ properties?: Record<string, any>;
54
+ nodeId: string;
55
+ type: string;
56
+ /**
57
+ * 节点的上下文,是调用流程时传入的上下文
58
+ */
59
+ context: Record<string, any>;
60
+ /**
61
+ * 节点的全局数据,是调用流程时传入的全局数据。
62
+ * 在计算表达式时,即基于全局数据进行计算。
63
+ */
64
+ globalData: Record<string, any>;
65
+ readonly baseType: string;
66
+ constructor({ nodeConfig, context, globalData }: {
67
+ nodeConfig: any;
68
+ context: any;
69
+ globalData: any;
70
+ });
71
+ /**
72
+ * 节点的每一次执行都会生成一个唯一的actionId
73
+ */
74
+ execute(params: ExecParams): Promise<NextActionParam>;
75
+ /**
76
+ * 节点在执行中断后,可以通过resume方法恢复执行。
77
+ * 自定义节点时不建议重写此方法
78
+ */
79
+ resume(params: ExecResumeParams): Promise<undefined>;
80
+ private getOutgoing;
81
+ private isPass;
82
+ /**
83
+ * 节点的执行逻辑
84
+ * @overridable 可以自定义节点重写此方法。
85
+ * @param params.executionId 流程执行记录ID
86
+ * @param params.actionId 此节点执行记录ID
87
+ * @param params.nodeId 节点ID
88
+ * @returns 返回下一步的执行参数
89
+ * 当不返回时,表示此节点执行成功,流程会继续执行下一步。
90
+ * 当返回时,返回格式
91
+ */
92
+ action(params: {
93
+ executionId: string;
94
+ actionId: string;
95
+ nodeId: string;
96
+ }): Promise<ActionResult>;
97
+ /**
98
+ * 节点的重新恢复执行逻辑
99
+ * @overridable 可以自定义节点重写此方法。
100
+ * @param params.executionId 流程执行记录ID
101
+ * @param params.actionId 此节点执行记录ID
102
+ * @param params.nodeId 节点ID
103
+ */
104
+ onResume(params: {
105
+ executionId: string;
106
+ actionId: string;
107
+ nodeId: string;
108
+ data?: Record<string, any>;
109
+ }): Promise<void>;
110
+ }