@logicflow/engine 0.0.9 → 0.0.10

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,50 +1,10 @@
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
- /* eslint-disable global-require */
38
- var vm = require('vm');
39
- var runInNewContext = function (code, globalData) {
40
- if (globalData === void 0) { globalData = {}; }
41
- return __awaiter(void 0, void 0, void 0, function () {
42
- var context;
43
- return __generator(this, function (_a) {
44
- context = vm.createContext(globalData);
45
- vm.runInContext(code, context);
46
- return [2 /*return*/, context];
47
- });
48
- });
49
- };
50
- export { runInNewContext, };
1
+ import { __awaiter } from "tslib";
2
+ import vm from 'node:vm';
3
+ // const vm = require('node:vm');
4
+ const runInNodeContext = (code, globalData = {}) => __awaiter(void 0, void 0, void 0, function* () {
5
+ const context = vm.createContext(globalData);
6
+ vm.runInContext(code, context);
7
+ return context;
8
+ });
9
+ export { runInNodeContext };
10
+ //# sourceMappingURL=nodeVm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeVm.js","sourceRoot":"","sources":["../../src/expression/nodeVm.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,iCAAiC;AAEjC,MAAM,gBAAgB,GAAG,CACvB,IAAY,EACZ,aAAsC,EAAE,EACxC,EAAE;IACF,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;IAC5C,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAE9B,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA,CAAA;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
package/es/index.d.ts CHANGED
@@ -1,60 +1,157 @@
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;
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;
13
8
  recorder?: Recorder;
14
- context: Record<string, any>;
15
- constructor(options?: EngineConstructorOptions);
9
+ context?: Record<string, unknown>;
10
+ nodeModelMap: Map<string, BaseNode.NodeConstructor>;
11
+ constructor(options?: Engine.Options);
16
12
  /**
17
13
  * 注册节点
18
14
  * @param nodeConfig { type: 'custom-node', model: NodeClass }
19
15
  */
20
- register(nodeConfig: any): void;
16
+ register(nodeConfig: Engine.NodeConfig): void;
21
17
  /**
22
- * 自定义执行记录的存储,默认浏览器使用 sessionStoragenodejs 使用内存存储。
23
- * 注意:由于执行记录不会主动删除,所以需要自行清理。
24
- * nodejs环境建议自定义为持久化存储。
25
- * engine.setCustomRecorder({
18
+ * 自定义执行记录的存储,默认浏览器使用 sessionStorage, nodejs 使用内存存储
19
+ * 注意:由于执行记录不全会主动删除,所以需要自行清理。
20
+ * nodejs 环境建议自定义为持久化存储。
21
+ * engine.setCustomRecorder({{
26
22
  * async addActionRecord(task) {}
27
23
  * async getTask(actionId) {}
28
24
  * async getExecutionTasks(executionId) {}
29
25
  * clear(instanceId) {}
30
- * });
26
+ * }}
27
+ * @param recorder
31
28
  */
32
29
  setCustomRecorder(recorder: Recorder): void;
33
30
  /**
34
31
  * 加载流程图数据
35
32
  */
36
- load({ graphData, startNodeType, globalData, }: {
37
- graphData: any;
38
- startNodeType?: string;
39
- globalData?: {};
40
- }): FlowModel;
33
+ load({ graphData, startNodeType, globalData, }: Engine.LoadGraphParam): FlowModel;
41
34
  /**
42
- * 执行流程,允许多次调用。
35
+ * 执行流程,允许多次调用
43
36
  */
44
- execute(execParam?: ActionParams): Promise<NextActionParam>;
37
+ execute(param?: Partial<Engine.ActionParam>): Promise<Engine.NextActionParam>;
45
38
  /**
46
- * 恢复执行
47
- * 注意此方法只能恢复节点后面的执行,不能恢复流程其他分支的执行。
48
- * 同理,中断执行也只能中断节点后面的执行,不会中断其他分支的执行。
49
- * 在实际项目中,如果存在中断节点,建议流程所有的节点都是排他网关,这样可以保证执行的过程不存在分支。
39
+ * 中断流程恢复
40
+ * @param resumeParam
41
+ * @returns
50
42
  */
51
- resume(resumeParam: ResumeParams): Promise<unknown>;
43
+ resume(resumeParam: Engine.ResumeParam): Promise<Engine.NextActionParam | undefined>;
52
44
  getExecutionList(): Promise<any>;
53
- getExecutionRecord(executionId: any): Promise<any[]>;
45
+ /**
46
+ * 获取执行任务记录
47
+ * @param executionId
48
+ * @returns
49
+ */
50
+ getExecutionRecord(executionId: Engine.Key): Promise<Recorder.Info[] | null>;
54
51
  destroy(): void;
55
- getGlobalData(): Record<string, any>;
56
- setGlobalData(data: any): void;
57
- updateGlobalData(data: any): 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;
58
154
  }
59
- export { Engine, TaskNode, StartNode, Recorder, };
60
- export type { ActionParams, };
155
+ export * from './constant';
156
+ export { BaseNode, StartNode, TaskNode, Recorder };
157
+ export default Engine;
package/es/index.js CHANGED
@@ -1,57 +1,11 @@
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) {
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) {
55
9
  this.nodeModelMap = new Map();
56
10
  this.instanceId = createEngineId();
57
11
  if (options === null || options === void 0 ? void 0 : options.debug) {
@@ -59,6 +13,7 @@ var Engine = /** @class */ (function () {
59
13
  instanceId: this.instanceId,
60
14
  });
61
15
  }
16
+ // 默认注册节点 register default nodes
62
17
  this.register({
63
18
  type: StartNode.nodeTypeName,
64
19
  model: StartNode,
@@ -73,132 +28,125 @@ var Engine = /** @class */ (function () {
73
28
  * 注册节点
74
29
  * @param nodeConfig { type: 'custom-node', model: NodeClass }
75
30
  */
76
- Engine.prototype.register = function (nodeConfig) {
31
+ register(nodeConfig) {
77
32
  this.nodeModelMap.set(nodeConfig.type, nodeConfig.model);
78
- };
33
+ }
79
34
  /**
80
- * 自定义执行记录的存储,默认浏览器使用 sessionStoragenodejs 使用内存存储。
81
- * 注意:由于执行记录不会主动删除,所以需要自行清理。
82
- * nodejs环境建议自定义为持久化存储。
83
- * engine.setCustomRecorder({
35
+ * 自定义执行记录的存储,默认浏览器使用 sessionStorage, nodejs 使用内存存储
36
+ * 注意:由于执行记录不全会主动删除,所以需要自行清理。
37
+ * nodejs 环境建议自定义为持久化存储。
38
+ * engine.setCustomRecorder({{
84
39
  * async addActionRecord(task) {}
85
40
  * async getTask(actionId) {}
86
41
  * async getExecutionTasks(executionId) {}
87
42
  * clear(instanceId) {}
88
- * });
43
+ * }}
44
+ * @param recorder
89
45
  */
90
- Engine.prototype.setCustomRecorder = function (recorder) {
46
+ setCustomRecorder(recorder) {
91
47
  this.recorder = recorder;
92
- };
48
+ }
93
49
  /**
94
50
  * 加载流程图数据
95
51
  */
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({
52
+ load({ graphData, startNodeType = 'StartNode', globalData = {}, }) {
53
+ this.graphData = graphData;
54
+ const flowModel = new FlowModel({
99
55
  nodeModelMap: this.nodeModelMap,
100
56
  recorder: this.recorder,
101
57
  context: this.context,
102
- globalData: globalData,
103
- startNodeType: startNodeType,
58
+ globalData,
59
+ startNodeType,
104
60
  });
105
- this.flowModel.load(graphData);
106
- return this.flowModel;
107
- };
61
+ flowModel.load(graphData);
62
+ this.flowModel = flowModel;
63
+ return flowModel;
64
+ }
108
65
  /**
109
- * 执行流程,允许多次调用。
66
+ * 执行流程,允许多次调用
110
67
  */
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
- })];
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
+ } }));
125
81
  });
126
82
  });
127
- };
83
+ }
128
84
  /**
129
- * 恢复执行
130
- * 注意此方法只能恢复节点后面的执行,不能恢复流程其他分支的执行。
131
- * 同理,中断执行也只能中断节点后面的执行,不会中断其他分支的执行。
132
- * 在实际项目中,如果存在中断节点,建议流程所有的节点都是排他网关,这样可以保证执行的过程不存在分支。
85
+ * 中断流程恢复
86
+ * @param resumeParam
87
+ * @returns
133
88
  */
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
- })];
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
+ } }));
145
98
  });
146
99
  });
147
- };
148
- Engine.prototype.getExecutionList = function () {
100
+ }
101
+ getExecutionList() {
149
102
  var _a;
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
- });
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ return yield ((_a = this.recorder) === null || _a === void 0 ? void 0 : _a.getExecutionList());
160
105
  });
161
- };
162
- Engine.prototype.getExecutionRecord = function (executionId) {
106
+ }
107
+ /**
108
+ * 获取执行任务记录
109
+ * @param executionId
110
+ * @returns
111
+ */
112
+ getExecutionRecord(executionId) {
163
113
  var _a, _b;
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)];
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));
179
125
  }
180
- });
126
+ }
127
+ return Promise.all(records);
181
128
  });
182
- };
183
- Engine.prototype.destroy = function () {
129
+ }
130
+ destroy() {
184
131
  var _a;
185
132
  (_a = this.recorder) === null || _a === void 0 ? void 0 : _a.clear();
186
- };
187
- Engine.prototype.getGlobalData = function () {
133
+ }
134
+ getGlobalData() {
188
135
  var _a;
189
136
  return (_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.globalData;
190
- };
191
- Engine.prototype.setGlobalData = function (data) {
137
+ }
138
+ setGlobalData(data) {
192
139
  if (this.flowModel) {
193
140
  this.flowModel.globalData = data;
194
141
  }
195
- };
196
- Engine.prototype.updateGlobalData = function (data) {
142
+ }
143
+ updateGlobalData(data) {
197
144
  if (this.flowModel) {
198
145
  Object.assign(this.flowModel.globalData, data);
199
146
  }
200
- };
201
- return Engine;
202
- }());
147
+ }
148
+ }
149
+ export * from './constant';
150
+ export { BaseNode, StartNode, TaskNode, Recorder };
203
151
  export default Engine;
204
- export { Engine, TaskNode, StartNode, Recorder, };
152
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAExC,MAAM,OAAO,MAAM;IASjB,YAAY,OAAwB;QAClC,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAA;QAC7B,IAAI,CAAC,UAAU,GAAG,cAAc,EAAE,CAAA;QAClC,IAAI,OAAO,aAAP,OAAO,u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