@logicflow/engine 0.0.2 → 0.0.4

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.
@@ -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,14 @@
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>;
9
+ getExecutionList(): Promise<any>;
6
10
  clear(): void;
7
11
  private pushExecution;
8
- private pushTaskToExecution;
12
+ private popExecution;
13
+ private pushActionToExecution;
9
14
  }
@@ -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,55 +55,80 @@ 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
- executionId = task.executionId, taskId = task.taskId;
58
- instanceData = this.getExecutionTasks(executionId);
59
- if (!instanceData) {
60
- this.pushExecution(executionId);
62
+ switch (_a.label) {
63
+ case 0:
64
+ executionId = action.executionId, actionId = action.actionId;
65
+ return [4 /*yield*/, this.getExecutionActions(executionId)];
66
+ case 1:
67
+ instanceData = _a.sent();
68
+ if (!instanceData) {
69
+ this.pushExecution(executionId);
70
+ }
71
+ this.pushActionToExecution(executionId, actionId);
72
+ storage.setItem(actionId, action);
73
+ return [2 /*return*/];
61
74
  }
62
- this.pushTaskToExecution(executionId, taskId);
63
- storage.setItem(taskId, task);
64
- return [2 /*return*/];
65
75
  });
66
76
  });
67
77
  };
68
- Recorder.prototype.getTask = function (taskId) {
78
+ Recorder.prototype.getActionRecord = function (actionId) {
69
79
  return __awaiter(this, void 0, void 0, function () {
70
80
  return __generator(this, function (_a) {
71
- return [2 /*return*/, storage.getItem(taskId)];
81
+ return [2 /*return*/, storage.getItem(actionId)];
72
82
  });
73
83
  });
74
84
  };
75
- Recorder.prototype.getExecutionTasks = function (executionId) {
85
+ Recorder.prototype.getExecutionActions = function (executionId) {
76
86
  return __awaiter(this, void 0, void 0, function () {
77
87
  return __generator(this, function (_a) {
78
88
  return [2 /*return*/, storage.getItem(executionId)];
79
89
  });
80
90
  });
81
91
  };
92
+ Recorder.prototype.getExecutionList = function () {
93
+ return __awaiter(this, void 0, void 0, function () {
94
+ var instances;
95
+ return __generator(this, function (_a) {
96
+ instances = storage.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
97
+ return [2 /*return*/, instances];
98
+ });
99
+ });
100
+ };
82
101
  Recorder.prototype.clear = function () {
83
- var instance = storage.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
84
- instance.forEach(function (executionId) {
102
+ var instances = storage.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
103
+ instances.forEach(function (executionId) {
85
104
  storage.removeItem(executionId);
86
105
  var instanceData = storage.getItem(executionId) || [];
87
- instanceData.forEach(function (taskId) {
88
- storage.removeItem(taskId);
106
+ instanceData.forEach(function (actionId) {
107
+ storage.removeItem(actionId);
89
108
  });
90
109
  });
91
110
  storage.removeItem(LOGICFLOW_ENGINE_INSTANCES);
92
111
  };
93
112
  Recorder.prototype.pushExecution = function (executionId) {
94
113
  var instance = storage.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
114
+ if (instance.length >= this.maxRecorder) {
115
+ var removeItem = instance.shift();
116
+ this.popExecution(removeItem);
117
+ }
95
118
  instance.push(executionId);
96
119
  storage.setItem(LOGICFLOW_ENGINE_INSTANCES, instance);
97
120
  };
98
- Recorder.prototype.pushTaskToExecution = function (executionId, taskId) {
99
- var tasks = storage.getItem(executionId) || [];
100
- tasks.push(taskId);
101
- storage.setItem(executionId, tasks);
121
+ Recorder.prototype.popExecution = function (executionId) {
122
+ var instanceData = storage.getItem(executionId) || [];
123
+ instanceData.forEach(function (actionId) {
124
+ storage.removeItem(actionId);
125
+ });
126
+ storage.removeItem(executionId);
127
+ };
128
+ Recorder.prototype.pushActionToExecution = function (executionId, actionId) {
129
+ var actions = storage.getItem(executionId) || [];
130
+ actions.push(actionId);
131
+ storage.setItem(executionId, actions);
102
132
  };
103
133
  return Recorder;
104
134
  }());
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
  };