@logicflow/engine 0.0.4 → 0.0.6

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,29 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.0.6](https://github.com/didi/LogicFlow/compare/@logicflow/engine@0.0.5...@logicflow/engine@0.0.6) (2023-08-24)
7
+
8
+
9
+ ### Features
10
+
11
+ * **engine:** execution record data contain outgoing and detail ([d24533c](https://github.com/didi/LogicFlow/commit/d24533ca4a6d259a3d1921c010056dd9b4db3d3c))
12
+ * **engine:** support node return error ([7373bf2](https://github.com/didi/LogicFlow/commit/7373bf2da4a90b2b7610a267259b33daa77fd9de))
13
+
14
+
15
+
16
+
17
+
18
+ ## [0.0.5](https://github.com/didi/LogicFlow/compare/@logicflow/engine@0.0.4...@logicflow/engine@0.0.5) (2023-08-23)
19
+
20
+
21
+ ### Features
22
+
23
+ * **engine:** recorder getExecutionList only return instance data ([684a2ba](https://github.com/didi/LogicFlow/commit/684a2ba90c8b94a0cce48200b69119270a3b31b7))
24
+
25
+
26
+
27
+
28
+
6
29
  ## [0.0.4](https://github.com/didi/LogicFlow/compare/@logicflow/engine@0.0.3...@logicflow/engine@0.0.4) (2023-08-21)
7
30
 
8
31
 
package/cjs/FlowModel.js CHANGED
@@ -90,6 +90,9 @@ var FlowModel = /** @class */ (function () {
90
90
  this.scheduler.on(constant_1.EVENT_INSTANCE_INTERRUPTED, function (result) {
91
91
  _this.onExecuteFinished(result);
92
92
  });
93
+ this.scheduler.on(constant_1.EVENT_INSTANCE_ERROR, function (result) {
94
+ _this.onExecuteFinished(result);
95
+ });
93
96
  }
94
97
  FlowModel.prototype.setStartNodeType = function (startNodeType) {
95
98
  this.startNodeType = startNodeType;
package/cjs/Scheduler.js CHANGED
@@ -109,12 +109,7 @@ var Scheduler = /** @class */ (function (_super) {
109
109
  }
110
110
  if (!this.hasRunningAction(runParams.executionId)) {
111
111
  // 当一个流程在nodeQueueMap和actionRunningMap中都不存在执行的节点时,说明这个流程已经执行完成。
112
- this.emit(constant_1.EVENT_INSTANCE_COMPLETE, {
113
- executionId: runParams.executionId,
114
- nodeId: runParams.nodeId,
115
- actionId: runParams.actionId,
116
- status: constant_1.FlowStatus.COMPLETED,
117
- });
112
+ this.emit(constant_1.EVENT_INSTANCE_COMPLETE, __assign(__assign({}, runParams), { status: constant_1.FlowStatus.COMPLETED }));
118
113
  }
119
114
  };
120
115
  /**
@@ -184,21 +179,30 @@ var Scheduler = /** @class */ (function (_super) {
184
179
  case 1:
185
180
  execResult = _a.sent();
186
181
  if (execResult && execResult.status === constant_1.FlowStatus.INTERRUPTED) {
187
- this.interrupted({
188
- execResult: execResult,
189
- actionParam: actionParam,
182
+ this.interrupted(execResult);
183
+ this.saveActionResult({
184
+ executionId: actionParam.executionId,
185
+ nodeId: actionParam.nodeId,
186
+ actionId: actionParam.actionId,
187
+ nodeType: execResult.nodeType,
188
+ properties: execResult.properties,
189
+ outgoing: execResult.outgoing,
190
+ status: execResult.status,
191
+ detail: execResult.detail,
190
192
  });
193
+ this.removeActionFromRunningMap(actionParam);
194
+ }
195
+ if (execResult && execResult.status === constant_1.FlowStatus.ERROR) {
196
+ this.error(execResult);
191
197
  this.saveActionResult({
192
198
  executionId: actionParam.executionId,
193
199
  nodeId: actionParam.nodeId,
194
200
  actionId: actionParam.actionId,
195
201
  nodeType: execResult.nodeType,
196
202
  properties: execResult.properties,
197
- outgoing: [],
198
- extraInfo: {
199
- status: execResult.status,
200
- detail: execResult.detail,
201
- },
203
+ outgoing: execResult.outgoing,
204
+ status: execResult.status,
205
+ detail: execResult.detail,
202
206
  });
203
207
  this.removeActionFromRunningMap(actionParam);
204
208
  }
@@ -207,33 +211,27 @@ var Scheduler = /** @class */ (function (_super) {
207
211
  });
208
212
  });
209
213
  };
210
- Scheduler.prototype.interrupted = function (_a) {
211
- var execResult = _a.execResult, actionParam = _a.actionParam;
212
- this.emit(constant_1.EVENT_INSTANCE_INTERRUPTED, {
213
- executionId: actionParam.executionId,
214
- status: constant_1.FlowStatus.INTERRUPTED,
215
- nodeId: actionParam.nodeId,
216
- actionId: actionParam.actionId,
217
- detail: execResult.detail,
218
- });
214
+ Scheduler.prototype.interrupted = function (execResult) {
215
+ this.emit(constant_1.EVENT_INSTANCE_INTERRUPTED, execResult);
216
+ };
217
+ Scheduler.prototype.error = function (execResult) {
218
+ this.emit(constant_1.EVENT_INSTANCE_ERROR, execResult);
219
219
  };
220
220
  Scheduler.prototype.next = function (data) {
221
221
  var _this = this;
222
222
  if (data.outgoing && data.outgoing.length > 0) {
223
223
  data.outgoing.forEach(function (item) {
224
- _this.addAction({
225
- executionId: data.executionId,
226
- nodeId: item.target,
227
- });
224
+ if (item.result) {
225
+ _this.addAction({
226
+ executionId: data.executionId,
227
+ nodeId: item.target,
228
+ });
229
+ }
228
230
  });
229
231
  }
230
232
  this.saveActionResult(data);
231
233
  this.removeActionFromRunningMap(data);
232
- this.run({
233
- executionId: data.executionId,
234
- nodeId: data.nodeId,
235
- actionId: data.actionId,
236
- });
234
+ this.run(data);
237
235
  };
238
236
  Scheduler.prototype.saveActionResult = function (data) {
239
237
  this.recorder.addActionRecord({
@@ -243,6 +241,9 @@ var Scheduler = /** @class */ (function (_super) {
243
241
  nodeType: data.nodeType,
244
242
  timestamp: Date.now(),
245
243
  properties: data.properties,
244
+ outgoing: data.outgoing,
245
+ detail: data.detail,
246
+ status: data.status,
246
247
  });
247
248
  };
248
249
  return Scheduler;
@@ -1,17 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActionStatus = exports.FlowStatus = exports.EVENT_INSTANCE_INTERRUPTED = exports.EVENT_INSTANCE_COMPLETE = exports.BASE_START_NODE = void 0;
3
+ exports.ActionStatus = exports.FlowStatus = exports.EVENT_INSTANCE_ERROR = exports.EVENT_INSTANCE_INTERRUPTED = exports.EVENT_INSTANCE_COMPLETE = exports.BASE_START_NODE = void 0;
4
4
  // baseType
5
5
  exports.BASE_START_NODE = 'start';
6
6
  // event name
7
7
  exports.EVENT_INSTANCE_COMPLETE = 'instance:complete';
8
8
  exports.EVENT_INSTANCE_INTERRUPTED = 'instance:interrupted';
9
+ exports.EVENT_INSTANCE_ERROR = 'instance:error';
9
10
  // flow status
10
11
  var FlowStatus;
11
12
  (function (FlowStatus) {
12
13
  FlowStatus["COMPLETED"] = "completed";
13
14
  FlowStatus["INTERRUPTED"] = "interrupted";
14
15
  FlowStatus["RUNNING"] = "running";
16
+ FlowStatus["PENDING"] = "pending";
15
17
  FlowStatus["ERROR"] = "error";
16
18
  })(FlowStatus = exports.FlowStatus || (exports.FlowStatus = {}));
17
19
  // action status
package/cjs/index.js CHANGED
@@ -47,19 +47,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  }
48
48
  };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.StartNode = exports.TaskNode = exports.Engine = void 0;
50
+ exports.Recorder = exports.StartNode = exports.TaskNode = exports.Engine = void 0;
51
51
  var FlowModel_1 = require("./FlowModel");
52
52
  var StartNode_1 = require("./nodes/StartNode");
53
53
  exports.StartNode = StartNode_1.default;
54
54
  var TaskNode_1 = require("./nodes/TaskNode");
55
55
  exports.TaskNode = TaskNode_1.default;
56
56
  var recorder_1 = require("./recorder");
57
+ exports.Recorder = recorder_1.default;
57
58
  var ID_1 = require("./util/ID");
58
59
  var Engine = /** @class */ (function () {
59
60
  function Engine(options) {
60
61
  this.nodeModelMap = new Map();
61
- this.id = ID_1.createEngineId();
62
- this.recorder = new recorder_1.default();
62
+ this.instanceId = ID_1.createEngineId();
63
+ this.recorder = new recorder_1.default({
64
+ instanceId: this.instanceId,
65
+ });
63
66
  this.register({
64
67
  type: StartNode_1.default.nodeTypeName,
65
68
  model: StartNode_1.default,
@@ -85,7 +88,7 @@ var Engine = /** @class */ (function () {
85
88
  * async addActionRecord(task) {}
86
89
  * async getTask(actionId) {}
87
90
  * async getExecutionTasks(executionId) {}
88
- * clear() {}
91
+ * clear(instanceId) {}
89
92
  * });
90
93
  */
91
94
  Engine.prototype.setCustomRecorder = function (recorder) {
@@ -179,6 +182,9 @@ var Engine = /** @class */ (function () {
179
182
  });
180
183
  });
181
184
  };
185
+ Engine.prototype.destroy = function () {
186
+ this.recorder.clear();
187
+ };
182
188
  Engine.prototype.getGlobalData = function () {
183
189
  var _a;
184
190
  return (_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.globalData;
@@ -77,7 +77,7 @@ var BaseNode = /** @class */ (function () {
77
77
  */
78
78
  BaseNode.prototype.execute = function (params) {
79
79
  return __awaiter(this, void 0, void 0, function () {
80
- var r, outgoing;
80
+ var r, status, outgoing, detail;
81
81
  return __generator(this, function (_a) {
82
82
  switch (_a.label) {
83
83
  case 0: return [4 /*yield*/, this.action({
@@ -87,11 +87,15 @@ var BaseNode = /** @class */ (function () {
87
87
  })];
88
88
  case 1:
89
89
  r = _a.sent();
90
- if (!(!r || r.status === constant_1.ActionStatus.SUCCESS)) return [3 /*break*/, 3];
90
+ status = r ? r.status : 'success';
91
+ if (!(status === constant_1.ActionStatus.SUCCESS)) return [3 /*break*/, 3];
91
92
  return [4 /*yield*/, this.getOutgoing()];
92
93
  case 2:
93
94
  outgoing = _a.sent();
95
+ detail = r ? r.detail : {};
94
96
  params.next({
97
+ status: constant_1.ActionStatus.SUCCESS,
98
+ detail: detail,
95
99
  executionId: params.executionId,
96
100
  actionId: params.actionId,
97
101
  nodeId: this.nodeId,
@@ -101,13 +105,14 @@ var BaseNode = /** @class */ (function () {
101
105
  });
102
106
  _a.label = 3;
103
107
  case 3: return [2 /*return*/, {
104
- status: r && r.status,
108
+ status: status,
105
109
  detail: r && r.detail,
106
110
  executionId: params.executionId,
107
111
  actionId: params.actionId,
108
112
  nodeId: this.nodeId,
109
113
  nodeType: this.type,
110
114
  properties: this.properties,
115
+ outgoing: [],
111
116
  }];
112
117
  }
113
118
  });
@@ -140,6 +145,7 @@ var BaseNode = /** @class */ (function () {
140
145
  nodeType: this.type,
141
146
  properties: this.properties,
142
147
  outgoing: outgoing,
148
+ status: constant_1.ActionStatus.SUCCESS,
143
149
  });
144
150
  return [2 /*return*/, undefined];
145
151
  }
@@ -174,9 +180,9 @@ var BaseNode = /** @class */ (function () {
174
180
  case 1:
175
181
  result = _d.sent();
176
182
  result.forEach(function (item, index) {
177
- if (item) {
178
- outgoing.push(_this.outgoing[index]);
179
- }
183
+ var out = _this.outgoing[index];
184
+ out.result = item;
185
+ outgoing.push(out);
180
186
  });
181
187
  return [2 /*return*/, outgoing];
182
188
  }
@@ -215,11 +221,14 @@ var BaseNode = /** @class */ (function () {
215
221
  * @param params.executionId 流程执行记录ID
216
222
  * @param params.actionId 此节点执行记录ID
217
223
  * @param params.nodeId 节点ID
224
+ * @returns 返回下一步的执行参数
225
+ * 当不返回时,表示此节点执行成功,流程会继续执行下一步。
226
+ * 当返回时,返回格式
218
227
  */
219
228
  BaseNode.prototype.action = function (params) {
220
229
  return __awaiter(this, void 0, void 0, function () {
221
230
  return __generator(this, function (_a) {
222
- return [2 /*return*/, undefined];
231
+ return [2 /*return*/, null];
223
232
  });
224
233
  });
225
234
  };
@@ -39,9 +39,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  var storage_1 = require("../util/storage");
40
40
  var LOGICFLOW_ENGINE_INSTANCES = 'LOGICFLOW_ENGINE_INSTANCES';
41
41
  var MAX_RECORDER = 100;
42
+ var MAX_INSTANCE = 100;
42
43
  var Recorder = /** @class */ (function () {
43
- function Recorder() {
44
+ function Recorder(_a) {
45
+ var instanceId = _a.instanceId;
44
46
  this.maxRecorder = MAX_RECORDER;
47
+ this.instanceId = instanceId;
48
+ var instances = storage_1.default.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
49
+ if (instances.indexOf(instanceId) === -1) {
50
+ instances.push(instanceId);
51
+ }
52
+ if (instances.length > MAX_INSTANCE) {
53
+ var clearInstance = instances.shift();
54
+ this.clearInstance(clearInstance);
55
+ }
56
+ storage_1.default.setItem(LOGICFLOW_ENGINE_INSTANCES, instances);
45
57
  }
46
58
  Recorder.prototype.setMaxRecorderNumber = function (maxRecorder) {
47
59
  this.maxRecorder = maxRecorder;
@@ -95,30 +107,33 @@ var Recorder = /** @class */ (function () {
95
107
  return __awaiter(this, void 0, void 0, function () {
96
108
  var instances;
97
109
  return __generator(this, function (_a) {
98
- instances = storage_1.default.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
110
+ instances = storage_1.default.getItem(this.instanceId) || [];
99
111
  return [2 /*return*/, instances];
100
112
  });
101
113
  });
102
114
  };
103
115
  Recorder.prototype.clear = function () {
104
- var instances = storage_1.default.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
105
- instances.forEach(function (executionId) {
116
+ this.clearInstance(this.instanceId);
117
+ };
118
+ Recorder.prototype.clearInstance = function (instanceId) {
119
+ var instanceExecutions = storage_1.default.getItem(instanceId) || [];
120
+ instanceExecutions.forEach(function (executionId) {
106
121
  storage_1.default.removeItem(executionId);
107
122
  var instanceData = storage_1.default.getItem(executionId) || [];
108
123
  instanceData.forEach(function (actionId) {
109
124
  storage_1.default.removeItem(actionId);
110
125
  });
111
126
  });
112
- storage_1.default.removeItem(LOGICFLOW_ENGINE_INSTANCES);
127
+ storage_1.default.removeItem(instanceId);
113
128
  };
114
129
  Recorder.prototype.pushExecution = function (executionId) {
115
- var instance = storage_1.default.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
116
- if (instance.length >= this.maxRecorder) {
117
- var removeItem = instance.shift();
130
+ var instanceExecutions = storage_1.default.getItem(this.instanceId) || [];
131
+ if (instanceExecutions.length >= this.maxRecorder) {
132
+ var removeItem = instanceExecutions.shift();
118
133
  this.popExecution(removeItem);
119
134
  }
120
- instance.push(executionId);
121
- storage_1.default.setItem(LOGICFLOW_ENGINE_INSTANCES, instance);
135
+ instanceExecutions.push(executionId);
136
+ storage_1.default.setItem(this.instanceId, instanceExecutions);
122
137
  };
123
138
  Recorder.prototype.popExecution = function (executionId) {
124
139
  var instanceData = storage_1.default.getItem(executionId) || [];
package/es/FlowModel.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import type { NodeConfig, NodeConstructor } from './nodes/BaseNode';
2
2
  import type Recorder from './recorder';
3
3
  import Scheduler from './Scheduler';
4
- import type { ActionParam } from './types.d';
5
- export declare type FlowResult = {
4
+ import type { ActionParam, NextActionParam } from './types.d';
5
+ export declare type FlowResult = ({
6
6
  result?: Record<string, any>;
7
- } & ActionParam;
7
+ } & ActionParam) | NextActionParam;
8
8
  export declare type ActionParams = {
9
9
  executionId?: string;
10
10
  actionId?: string;
11
11
  nodeId?: string;
12
12
  };
13
13
  export declare type ExecParams = {
14
- callback?: (result: FlowResult) => void;
14
+ callback?: (result: NextActionParam) => void;
15
15
  onError?: (error: Error) => void;
16
16
  } & ActionParams;
17
17
  export default class FlowModel {
package/es/FlowModel.js CHANGED
@@ -45,7 +45,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
- import { EVENT_INSTANCE_COMPLETE, EVENT_INSTANCE_INTERRUPTED, } from './constant/constant';
48
+ import { EVENT_INSTANCE_COMPLETE, EVENT_INSTANCE_INTERRUPTED, EVENT_INSTANCE_ERROR, } from './constant/constant';
49
49
  import { createExecId } from './util/ID';
50
50
  import Scheduler from './Scheduler';
51
51
  import { ErrorCode, getErrorMsg } from './constant/LogCode';
@@ -88,6 +88,9 @@ var FlowModel = /** @class */ (function () {
88
88
  this.scheduler.on(EVENT_INSTANCE_INTERRUPTED, function (result) {
89
89
  _this.onExecuteFinished(result);
90
90
  });
91
+ this.scheduler.on(EVENT_INSTANCE_ERROR, function (result) {
92
+ _this.onExecuteFinished(result);
93
+ });
91
94
  }
92
95
  FlowModel.prototype.setStartNodeType = function (startNodeType) {
93
96
  this.startNodeType = startNodeType;
package/es/Scheduler.d.ts CHANGED
@@ -43,8 +43,7 @@ export default class Scheduler extends EventEmitter {
43
43
  */
44
44
  run(runParams: {
45
45
  executionId: string;
46
- nodeId?: string;
47
- actionId?: string;
46
+ [key: string]: any;
48
47
  }): void;
49
48
  /**
50
49
  * 恢复某个任务的执行。
@@ -56,6 +55,7 @@ export default class Scheduler extends EventEmitter {
56
55
  private hasRunningAction;
57
56
  private exec;
58
57
  private interrupted;
58
+ private error;
59
59
  private next;
60
60
  private saveActionResult;
61
61
  }
package/es/Scheduler.js CHANGED
@@ -59,7 +59,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
59
59
  }
60
60
  };
61
61
  import EventEmitter from './EventEmitter';
62
- import { EVENT_INSTANCE_COMPLETE, EVENT_INSTANCE_INTERRUPTED, FlowStatus, } from './constant/constant';
62
+ import { EVENT_INSTANCE_COMPLETE, EVENT_INSTANCE_INTERRUPTED, EVENT_INSTANCE_ERROR, FlowStatus, } from './constant/constant';
63
63
  import { createActionId } from './util/ID';
64
64
  /**
65
65
  * 调度器
@@ -107,12 +107,7 @@ var Scheduler = /** @class */ (function (_super) {
107
107
  }
108
108
  if (!this.hasRunningAction(runParams.executionId)) {
109
109
  // 当一个流程在nodeQueueMap和actionRunningMap中都不存在执行的节点时,说明这个流程已经执行完成。
110
- this.emit(EVENT_INSTANCE_COMPLETE, {
111
- executionId: runParams.executionId,
112
- nodeId: runParams.nodeId,
113
- actionId: runParams.actionId,
114
- status: FlowStatus.COMPLETED,
115
- });
110
+ this.emit(EVENT_INSTANCE_COMPLETE, __assign(__assign({}, runParams), { status: FlowStatus.COMPLETED }));
116
111
  }
117
112
  };
118
113
  /**
@@ -182,21 +177,30 @@ var Scheduler = /** @class */ (function (_super) {
182
177
  case 1:
183
178
  execResult = _a.sent();
184
179
  if (execResult && execResult.status === FlowStatus.INTERRUPTED) {
185
- this.interrupted({
186
- execResult: execResult,
187
- actionParam: actionParam,
180
+ this.interrupted(execResult);
181
+ this.saveActionResult({
182
+ executionId: actionParam.executionId,
183
+ nodeId: actionParam.nodeId,
184
+ actionId: actionParam.actionId,
185
+ nodeType: execResult.nodeType,
186
+ properties: execResult.properties,
187
+ outgoing: execResult.outgoing,
188
+ status: execResult.status,
189
+ detail: execResult.detail,
188
190
  });
191
+ this.removeActionFromRunningMap(actionParam);
192
+ }
193
+ if (execResult && execResult.status === FlowStatus.ERROR) {
194
+ this.error(execResult);
189
195
  this.saveActionResult({
190
196
  executionId: actionParam.executionId,
191
197
  nodeId: actionParam.nodeId,
192
198
  actionId: actionParam.actionId,
193
199
  nodeType: execResult.nodeType,
194
200
  properties: execResult.properties,
195
- outgoing: [],
196
- extraInfo: {
197
- status: execResult.status,
198
- detail: execResult.detail,
199
- },
201
+ outgoing: execResult.outgoing,
202
+ status: execResult.status,
203
+ detail: execResult.detail,
200
204
  });
201
205
  this.removeActionFromRunningMap(actionParam);
202
206
  }
@@ -205,33 +209,27 @@ var Scheduler = /** @class */ (function (_super) {
205
209
  });
206
210
  });
207
211
  };
208
- Scheduler.prototype.interrupted = function (_a) {
209
- var execResult = _a.execResult, actionParam = _a.actionParam;
210
- this.emit(EVENT_INSTANCE_INTERRUPTED, {
211
- executionId: actionParam.executionId,
212
- status: FlowStatus.INTERRUPTED,
213
- nodeId: actionParam.nodeId,
214
- actionId: actionParam.actionId,
215
- detail: execResult.detail,
216
- });
212
+ Scheduler.prototype.interrupted = function (execResult) {
213
+ this.emit(EVENT_INSTANCE_INTERRUPTED, execResult);
214
+ };
215
+ Scheduler.prototype.error = function (execResult) {
216
+ this.emit(EVENT_INSTANCE_ERROR, execResult);
217
217
  };
218
218
  Scheduler.prototype.next = function (data) {
219
219
  var _this = this;
220
220
  if (data.outgoing && data.outgoing.length > 0) {
221
221
  data.outgoing.forEach(function (item) {
222
- _this.addAction({
223
- executionId: data.executionId,
224
- nodeId: item.target,
225
- });
222
+ if (item.result) {
223
+ _this.addAction({
224
+ executionId: data.executionId,
225
+ nodeId: item.target,
226
+ });
227
+ }
226
228
  });
227
229
  }
228
230
  this.saveActionResult(data);
229
231
  this.removeActionFromRunningMap(data);
230
- this.run({
231
- executionId: data.executionId,
232
- nodeId: data.nodeId,
233
- actionId: data.actionId,
234
- });
232
+ this.run(data);
235
233
  };
236
234
  Scheduler.prototype.saveActionResult = function (data) {
237
235
  this.recorder.addActionRecord({
@@ -241,6 +239,9 @@ var Scheduler = /** @class */ (function (_super) {
241
239
  nodeType: data.nodeType,
242
240
  timestamp: Date.now(),
243
241
  properties: data.properties,
242
+ outgoing: data.outgoing,
243
+ detail: data.detail,
244
+ status: data.status,
244
245
  });
245
246
  };
246
247
  return Scheduler;
@@ -1,10 +1,12 @@
1
1
  export declare const BASE_START_NODE = "start";
2
2
  export declare const EVENT_INSTANCE_COMPLETE = "instance:complete";
3
3
  export declare const EVENT_INSTANCE_INTERRUPTED = "instance:interrupted";
4
+ export declare const EVENT_INSTANCE_ERROR = "instance:error";
4
5
  export declare enum FlowStatus {
5
6
  COMPLETED = "completed",
6
7
  INTERRUPTED = "interrupted",
7
8
  RUNNING = "running",
9
+ PENDING = "pending",
8
10
  ERROR = "error"
9
11
  }
10
12
  export declare enum ActionStatus {
@@ -3,12 +3,14 @@ export var BASE_START_NODE = 'start';
3
3
  // event name
4
4
  export var EVENT_INSTANCE_COMPLETE = 'instance:complete';
5
5
  export var EVENT_INSTANCE_INTERRUPTED = 'instance:interrupted';
6
+ export var EVENT_INSTANCE_ERROR = 'instance:error';
6
7
  // flow status
7
8
  export var FlowStatus;
8
9
  (function (FlowStatus) {
9
10
  FlowStatus["COMPLETED"] = "completed";
10
11
  FlowStatus["INTERRUPTED"] = "interrupted";
11
12
  FlowStatus["RUNNING"] = "running";
13
+ FlowStatus["PENDING"] = "pending";
12
14
  FlowStatus["ERROR"] = "error";
13
15
  })(FlowStatus || (FlowStatus = {}));
14
16
  // action status
package/es/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { ResumeParams, GraphConfigData, EngineConstructorOptions } from './types.d';
1
+ import type { ResumeParams, GraphConfigData, EngineConstructorOptions, NextActionParam } from './types.d';
2
2
  import FlowModel, { ActionParams } from './FlowModel';
3
3
  import StartNode from './nodes/StartNode';
4
4
  import TaskNode from './nodes/TaskNode';
5
5
  import Recorder from './recorder';
6
6
  import { NodeConstructor } from './nodes/BaseNode';
7
7
  export default class Engine {
8
- id: string;
8
+ instanceId: string;
9
9
  global: Record<string, any>;
10
10
  graphData: GraphConfigData;
11
11
  nodeModelMap: Map<string, NodeConstructor>;
@@ -26,7 +26,7 @@ export default class Engine {
26
26
  * async addActionRecord(task) {}
27
27
  * async getTask(actionId) {}
28
28
  * async getExecutionTasks(executionId) {}
29
- * clear() {}
29
+ * clear(instanceId) {}
30
30
  * });
31
31
  */
32
32
  setCustomRecorder(recorder: Recorder): void;
@@ -41,7 +41,7 @@ export default class Engine {
41
41
  /**
42
42
  * 执行流程,允许多次调用。
43
43
  */
44
- execute(execParam?: ActionParams): Promise<unknown>;
44
+ execute(execParam?: ActionParams): Promise<NextActionParam>;
45
45
  /**
46
46
  * 恢复执行
47
47
  * 注意此方法只能恢复节点后面的执行,不能恢复流程其他分支的执行。
@@ -51,9 +51,10 @@ export default class Engine {
51
51
  resume(resumeParam: ResumeParams): Promise<unknown>;
52
52
  getExecutionList(): Promise<any>;
53
53
  getExecutionRecord(executionId: any): Promise<any[]>;
54
+ destroy(): void;
54
55
  getGlobalData(): Record<string, any>;
55
56
  setGlobalData(data: any): void;
56
57
  updateGlobalData(data: any): void;
57
58
  }
58
- export { Engine, TaskNode, StartNode, };
59
+ export { Engine, TaskNode, StartNode, Recorder, };
59
60
  export type { ActionParams, };
package/es/index.js CHANGED
@@ -53,8 +53,10 @@ import { createEngineId } from './util/ID';
53
53
  var Engine = /** @class */ (function () {
54
54
  function Engine(options) {
55
55
  this.nodeModelMap = new Map();
56
- this.id = createEngineId();
57
- this.recorder = new Recorder();
56
+ this.instanceId = createEngineId();
57
+ this.recorder = new Recorder({
58
+ instanceId: this.instanceId,
59
+ });
58
60
  this.register({
59
61
  type: StartNode.nodeTypeName,
60
62
  model: StartNode,
@@ -80,7 +82,7 @@ var Engine = /** @class */ (function () {
80
82
  * async addActionRecord(task) {}
81
83
  * async getTask(actionId) {}
82
84
  * async getExecutionTasks(executionId) {}
83
- * clear() {}
85
+ * clear(instanceId) {}
84
86
  * });
85
87
  */
86
88
  Engine.prototype.setCustomRecorder = function (recorder) {
@@ -174,6 +176,9 @@ var Engine = /** @class */ (function () {
174
176
  });
175
177
  });
176
178
  };
179
+ Engine.prototype.destroy = function () {
180
+ this.recorder.clear();
181
+ };
177
182
  Engine.prototype.getGlobalData = function () {
178
183
  var _a;
179
184
  return (_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.globalData;
@@ -191,4 +196,4 @@ var Engine = /** @class */ (function () {
191
196
  return Engine;
192
197
  }());
193
198
  export default Engine;
194
- export { Engine, TaskNode, StartNode, };
199
+ export { Engine, TaskNode, StartNode, Recorder, };