@logicflow/engine 0.0.1 → 0.0.3

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 (46) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +3 -15
  3. package/cjs/FlowModel.js +77 -55
  4. package/cjs/Scheduler.js +68 -96
  5. package/cjs/constant/constant.js +8 -8
  6. package/cjs/expression/browserVm.js +30 -22
  7. package/cjs/expression/nodeVm.js +1 -1
  8. package/cjs/index.js +34 -9
  9. package/cjs/nodes/BaseNode.js +10 -10
  10. package/cjs/recorder/index.js +33 -17
  11. package/cjs/util/ID.js +7 -3
  12. package/es/FlowModel.d.ts +59 -19
  13. package/es/FlowModel.js +77 -55
  14. package/es/Scheduler.d.ts +26 -15
  15. package/es/Scheduler.js +69 -97
  16. package/es/constant/constant.d.ts +1 -1
  17. package/es/constant/constant.js +7 -7
  18. package/es/expression/browserVm.d.ts +3 -1
  19. package/es/expression/browserVm.js +28 -22
  20. package/es/expression/nodeVm.js +1 -1
  21. package/es/index.d.ts +22 -11
  22. package/es/index.js +34 -9
  23. package/es/nodes/BaseNode.d.ts +19 -8
  24. package/es/nodes/BaseNode.js +11 -11
  25. package/es/recorder/index.d.ts +8 -4
  26. package/es/recorder/index.js +33 -17
  27. package/es/util/ID.d.ts +2 -1
  28. package/es/util/ID.js +6 -2
  29. package/lib/main.js +1 -1
  30. package/package.json +4 -1
  31. package/types/EventEmitter.d.ts +0 -7
  32. package/types/FlowModel.d.ts +0 -104
  33. package/types/Scheduler.d.ts +0 -51
  34. package/types/constant/LogCode.d.ts +0 -12
  35. package/types/constant/constant.d.ts +0 -14
  36. package/types/expression/browserVm.d.ts +0 -2
  37. package/types/expression/index.d.ts +0 -2
  38. package/types/expression/nodeVm.d.ts +0 -2
  39. package/types/index.d.ts +0 -47
  40. package/types/nodes/BaseNode.d.ts +0 -109
  41. package/types/nodes/StartNode.d.ts +0 -5
  42. package/types/nodes/TaskNode.d.ts +0 -5
  43. package/types/recorder/index.d.ts +0 -9
  44. package/types/util/ID.d.ts +0 -2
  45. package/types/util/global.d.ts +0 -5
  46. package/types/util/storage.d.ts +0 -6
@@ -5,7 +5,7 @@ export interface BaseNodeInterface {
5
5
  nodeId: string;
6
6
  type: string;
7
7
  readonly baseType: string;
8
- execute(taskParam: any): Promise<NodeExecResult>;
8
+ execute(actionParam: any): Promise<NodeExecResult>;
9
9
  }
10
10
  export declare type NodeConstructor = {
11
11
  new (config: {
@@ -13,6 +13,17 @@ export declare type NodeConstructor = {
13
13
  context: Record<string, any>;
14
14
  globalData: Record<string, any>;
15
15
  }): BaseNode;
16
+ action(params: {
17
+ executionId: string;
18
+ actionId: string;
19
+ nodeId: string;
20
+ }): Promise<ActionResult>;
21
+ onResume(params: {
22
+ executionId: string;
23
+ actionId: string;
24
+ nodeId: string;
25
+ data?: Record<string, any>;
26
+ }): Promise<void>;
16
27
  };
17
28
  export declare type IncomingConfig = {
18
29
  id: string;
@@ -31,10 +42,10 @@ export declare type NodeConfig = {
31
42
  incoming: IncomingConfig[];
32
43
  outgoing: OutgoingConfig[];
33
44
  };
34
- export declare type NextTaskParam = {
45
+ export declare type NextActionParam = {
35
46
  executionId: string;
36
47
  nodeId: string;
37
- taskId: string;
48
+ actionId: string;
38
49
  nodeType: string;
39
50
  outgoing: OutgoingConfig[];
40
51
  properties?: Record<string, any>;
@@ -71,7 +82,7 @@ export default class BaseNode implements BaseNodeInterface {
71
82
  globalData: any;
72
83
  });
73
84
  /**
74
- * 节点的每一次执行都会生成一个唯一的taskId
85
+ * 节点的每一次执行都会生成一个唯一的actionId
75
86
  */
76
87
  execute(params: ExecParams): Promise<NodeExecResult>;
77
88
  /**
@@ -85,24 +96,24 @@ export default class BaseNode implements BaseNodeInterface {
85
96
  * 节点的执行逻辑
86
97
  * @overridable 可以自定义节点重写此方法。
87
98
  * @param params.executionId 流程执行记录ID
88
- * @param params.taskId 此节点执行记录ID
99
+ * @param params.actionId 此节点执行记录ID
89
100
  * @param params.nodeId 节点ID
90
101
  */
91
102
  action(params: {
92
103
  executionId: string;
93
- taskId: string;
104
+ actionId: string;
94
105
  nodeId: string;
95
106
  }): Promise<ActionResult>;
96
107
  /**
97
108
  * 节点的重新恢复执行逻辑
98
109
  * @overridable 可以自定义节点重写此方法。
99
110
  * @param params.executionId 流程执行记录ID
100
- * @param params.taskId 此节点执行记录ID
111
+ * @param params.actionId 此节点执行记录ID
101
112
  * @param params.nodeId 节点ID
102
113
  */
103
114
  onResume(params: {
104
115
  executionId: string;
105
- taskId: string;
116
+ actionId: string;
106
117
  nodeId: string;
107
118
  data?: Record<string, any>;
108
119
  }): Promise<void>;
@@ -56,7 +56,7 @@ var __values = (this && this.__values) || function(o) {
56
56
  };
57
57
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
58
58
  };
59
- import { TaskStatus } from '../constant/constant';
59
+ import { ActionStatus } from '../constant/constant';
60
60
  import { getExpressionResult } from '../expression';
61
61
  var BaseNode = /** @class */ (function () {
62
62
  function BaseNode(_a) {
@@ -65,13 +65,13 @@ var BaseNode = /** @class */ (function () {
65
65
  this.incoming = nodeConfig.incoming;
66
66
  this.nodeId = nodeConfig.id;
67
67
  this.type = nodeConfig.type;
68
- this.properties = nodeConfig.properties;
68
+ this.properties = nodeConfig.properties || {};
69
69
  this.context = context;
70
70
  this.globalData = globalData;
71
71
  this.baseType = 'base';
72
72
  }
73
73
  /**
74
- * 节点的每一次执行都会生成一个唯一的taskId
74
+ * 节点的每一次执行都会生成一个唯一的actionId
75
75
  */
76
76
  BaseNode.prototype.execute = function (params) {
77
77
  return __awaiter(this, void 0, void 0, function () {
@@ -80,18 +80,18 @@ var BaseNode = /** @class */ (function () {
80
80
  switch (_a.label) {
81
81
  case 0: return [4 /*yield*/, this.action({
82
82
  executionId: params.executionId,
83
- taskId: params.taskId,
83
+ actionId: params.actionId,
84
84
  nodeId: this.nodeId,
85
85
  })];
86
86
  case 1:
87
87
  r = _a.sent();
88
- if (!(!r || r.status === TaskStatus.SUCCESS)) return [3 /*break*/, 3];
88
+ if (!(!r || r.status === ActionStatus.SUCCESS)) return [3 /*break*/, 3];
89
89
  return [4 /*yield*/, this.getOutgoing()];
90
90
  case 2:
91
91
  outgoing = _a.sent();
92
92
  params.next({
93
93
  executionId: params.executionId,
94
- taskId: params.taskId,
94
+ actionId: params.actionId,
95
95
  nodeId: this.nodeId,
96
96
  nodeType: this.type,
97
97
  properties: this.properties,
@@ -102,7 +102,7 @@ var BaseNode = /** @class */ (function () {
102
102
  status: r && r.status,
103
103
  detail: r && r.detail,
104
104
  executionId: params.executionId,
105
- taskId: params.taskId,
105
+ actionId: params.actionId,
106
106
  nodeId: this.nodeId,
107
107
  nodeType: this.type,
108
108
  properties: this.properties,
@@ -126,14 +126,14 @@ var BaseNode = /** @class */ (function () {
126
126
  return [4 /*yield*/, this.onResume({
127
127
  executionId: params.executionId,
128
128
  nodeId: params.nodeId,
129
- taskId: params.taskId,
129
+ actionId: params.actionId,
130
130
  data: params.data,
131
131
  })];
132
132
  case 2:
133
133
  _a.sent();
134
134
  params.next({
135
135
  executionId: params.executionId,
136
- taskId: params.taskId,
136
+ actionId: params.actionId,
137
137
  nodeId: this.nodeId,
138
138
  nodeType: this.type,
139
139
  properties: this.properties,
@@ -211,7 +211,7 @@ var BaseNode = /** @class */ (function () {
211
211
  * 节点的执行逻辑
212
212
  * @overridable 可以自定义节点重写此方法。
213
213
  * @param params.executionId 流程执行记录ID
214
- * @param params.taskId 此节点执行记录ID
214
+ * @param params.actionId 此节点执行记录ID
215
215
  * @param params.nodeId 节点ID
216
216
  */
217
217
  BaseNode.prototype.action = function (params) {
@@ -225,7 +225,7 @@ var BaseNode = /** @class */ (function () {
225
225
  * 节点的重新恢复执行逻辑
226
226
  * @overridable 可以自定义节点重写此方法。
227
227
  * @param params.executionId 流程执行记录ID
228
- * @param params.taskId 此节点执行记录ID
228
+ * @param params.actionId 此节点执行记录ID
229
229
  * @param params.nodeId 节点ID
230
230
  */
231
231
  BaseNode.prototype.onResume = function (params) {
@@ -1,9 +1,13 @@
1
1
  import type { RecorderData, RecorderInterface } from '../types.d';
2
2
  export default class Recorder implements RecorderInterface {
3
- addTask(task: RecorderData): Promise<void>;
4
- getTask(taskId: string): Promise<RecorderData>;
5
- getExecutionTasks(executionId: any): Promise<any>;
3
+ maxRecorder: number;
4
+ constructor();
5
+ setMaxRecorderNumber(maxRecorder: number): void;
6
+ addActionRecord(action: RecorderData): Promise<void>;
7
+ getActionRecord(actionId: string): Promise<RecorderData>;
8
+ getExecutionActions(executionId: any): Promise<any>;
6
9
  clear(): void;
7
10
  private pushExecution;
8
- private pushTaskToExecution;
11
+ private popExecution;
12
+ private pushActionToExecution;
9
13
  }
@@ -36,13 +36,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  import storage from '../util/storage';
38
38
  var LOGICFLOW_ENGINE_INSTANCES = 'LOGICFLOW_ENGINE_INSTANCES';
39
+ var MAX_RECORDER = 100;
39
40
  var Recorder = /** @class */ (function () {
40
41
  function Recorder() {
42
+ this.maxRecorder = MAX_RECORDER;
41
43
  }
44
+ Recorder.prototype.setMaxRecorderNumber = function (maxRecorder) {
45
+ this.maxRecorder = maxRecorder;
46
+ };
42
47
  /*
43
- * @param {Object} task
48
+ * @param {Object} action
44
49
  * {
45
- * taskId: '',
50
+ * actionId: '',
46
51
  * nodeId: '',
47
52
  * executionId: '',
48
53
  * nodeType: '',
@@ -50,34 +55,34 @@ var Recorder = /** @class */ (function () {
50
55
  * properties: {},
51
56
  * }
52
57
  */
53
- Recorder.prototype.addTask = function (task) {
58
+ Recorder.prototype.addActionRecord = function (action) {
54
59
  return __awaiter(this, void 0, void 0, function () {
55
- var executionId, taskId, instanceData;
60
+ var executionId, actionId, instanceData;
56
61
  return __generator(this, function (_a) {
57
62
  switch (_a.label) {
58
63
  case 0:
59
- executionId = task.executionId, taskId = task.taskId;
60
- return [4 /*yield*/, this.getExecutionTasks(executionId)];
64
+ executionId = action.executionId, actionId = action.actionId;
65
+ return [4 /*yield*/, this.getExecutionActions(executionId)];
61
66
  case 1:
62
67
  instanceData = _a.sent();
63
68
  if (!instanceData) {
64
69
  this.pushExecution(executionId);
65
70
  }
66
- this.pushTaskToExecution(executionId, taskId);
67
- storage.setItem(taskId, task);
71
+ this.pushActionToExecution(executionId, actionId);
72
+ storage.setItem(actionId, action);
68
73
  return [2 /*return*/];
69
74
  }
70
75
  });
71
76
  });
72
77
  };
73
- Recorder.prototype.getTask = function (taskId) {
78
+ Recorder.prototype.getActionRecord = function (actionId) {
74
79
  return __awaiter(this, void 0, void 0, function () {
75
80
  return __generator(this, function (_a) {
76
- return [2 /*return*/, storage.getItem(taskId)];
81
+ return [2 /*return*/, storage.getItem(actionId)];
77
82
  });
78
83
  });
79
84
  };
80
- Recorder.prototype.getExecutionTasks = function (executionId) {
85
+ Recorder.prototype.getExecutionActions = function (executionId) {
81
86
  return __awaiter(this, void 0, void 0, function () {
82
87
  return __generator(this, function (_a) {
83
88
  return [2 /*return*/, storage.getItem(executionId)];
@@ -89,21 +94,32 @@ var Recorder = /** @class */ (function () {
89
94
  instance.forEach(function (executionId) {
90
95
  storage.removeItem(executionId);
91
96
  var instanceData = storage.getItem(executionId) || [];
92
- instanceData.forEach(function (taskId) {
93
- storage.removeItem(taskId);
97
+ instanceData.forEach(function (actionId) {
98
+ storage.removeItem(actionId);
94
99
  });
95
100
  });
96
101
  storage.removeItem(LOGICFLOW_ENGINE_INSTANCES);
97
102
  };
98
103
  Recorder.prototype.pushExecution = function (executionId) {
99
104
  var instance = storage.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
105
+ if (instance.length >= this.maxRecorder) {
106
+ var removeItem = instance.shift();
107
+ this.popExecution(removeItem);
108
+ }
100
109
  instance.push(executionId);
101
110
  storage.setItem(LOGICFLOW_ENGINE_INSTANCES, instance);
102
111
  };
103
- Recorder.prototype.pushTaskToExecution = function (executionId, taskId) {
104
- var tasks = storage.getItem(executionId) || [];
105
- tasks.push(taskId);
106
- storage.setItem(executionId, tasks);
112
+ Recorder.prototype.popExecution = function (executionId) {
113
+ var instanceData = storage.getItem(executionId) || [];
114
+ instanceData.forEach(function (actionId) {
115
+ storage.removeItem(actionId);
116
+ });
117
+ storage.removeItem(executionId);
118
+ };
119
+ Recorder.prototype.pushActionToExecution = function (executionId, actionId) {
120
+ var actions = storage.getItem(executionId) || [];
121
+ actions.push(actionId);
122
+ storage.setItem(executionId, actions);
107
123
  };
108
124
  return Recorder;
109
125
  }());
package/es/util/ID.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare const createExecId: () => string;
2
- export declare const createTaskId: () => string;
2
+ export declare const createActionId: () => string;
3
+ export declare const createEngineId: () => string;
package/es/util/ID.js CHANGED
@@ -3,7 +3,11 @@ export var createExecId = function () {
3
3
  var uuid = uuidv4();
4
4
  return "exec-" + uuid;
5
5
  };
6
- export var createTaskId = function () {
6
+ export var createActionId = function () {
7
7
  var uuid = uuidv4();
8
- return "task-" + uuid;
8
+ return "action-" + uuid;
9
+ };
10
+ export var createEngineId = function () {
11
+ var uuid = uuidv4();
12
+ return "engine-" + uuid;
9
13
  };