@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.
- package/README.md +5 -2
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/es/EventEmitter.d.ts +34 -4
- package/es/EventEmitter.js +70 -48
- package/es/EventEmitter.js.map +1 -0
- package/es/FlowModel.d.ts +75 -73
- package/es/FlowModel.js +130 -173
- package/es/FlowModel.js.map +1 -0
- package/es/Scheduler.d.ts +50 -34
- package/es/Scheduler.js +134 -209
- package/es/Scheduler.js.map +1 -0
- package/es/constant/{constant.js → index.js} +8 -7
- package/es/constant/index.js.map +1 -0
- package/es/constant/logCode.js +29 -0
- package/es/constant/logCode.js.map +1 -0
- package/es/expression/brewserVm.d.ts +2 -0
- package/es/expression/brewserVm.js +30 -0
- package/es/expression/brewserVm.js.map +1 -0
- package/es/expression/index.d.ts +1 -1
- package/es/expression/index.js +16 -59
- package/es/expression/index.js.map +1 -0
- package/es/expression/nodeVm.d.ts +4 -2
- package/es/expression/nodeVm.js +10 -50
- package/es/expression/nodeVm.js.map +1 -0
- package/es/index.d.ts +135 -38
- package/es/index.js +92 -144
- package/es/index.js.map +1 -0
- package/es/nodes/base.d.ts +108 -0
- package/es/nodes/base.js +149 -0
- package/es/nodes/base.js.map +1 -0
- package/es/nodes/index.d.ts +3 -0
- package/es/nodes/index.js +4 -0
- package/es/nodes/index.js.map +1 -0
- package/es/nodes/{StartNode.d.ts → start.d.ts} +3 -2
- package/es/nodes/start.js +11 -0
- package/es/nodes/start.js.map +1 -0
- package/es/nodes/{TaskNode.d.ts → task.d.ts} +3 -2
- package/es/nodes/task.js +11 -0
- package/es/nodes/task.js.map +1 -0
- package/es/platform/browser/browserVm.d.ts +4 -0
- package/es/platform/browser/browserVm.js +44 -0
- package/es/platform/browser/browserVm.js.map +1 -0
- package/es/platform/browser/index.d.ts +4 -0
- package/es/platform/browser/index.js +23 -0
- package/es/platform/browser/index.js.map +1 -0
- package/es/platform/index.d.ts +1 -0
- package/es/platform/index.js +2 -0
- package/es/platform/index.js.map +1 -0
- package/es/platform/node/index.d.ts +4 -0
- package/es/platform/node/index.js +23 -0
- package/es/platform/node/index.js.map +1 -0
- package/es/platform/node/nodeVm.d.ts +1 -0
- package/es/platform/node/nodeVm.js +9 -0
- package/es/platform/node/nodeVm.js.map +1 -0
- package/es/recorder/index.d.ts +36 -10
- package/es/recorder/index.js +82 -135
- package/es/recorder/index.js.map +1 -0
- package/es/utils/global.d.ts +5 -0
- package/es/utils/global.js +27 -0
- package/es/utils/global.js.map +1 -0
- package/es/utils/id.js +14 -0
- package/es/utils/id.js.map +1 -0
- package/es/utils/index.d.ts +4 -0
- package/es/utils/index.js +5 -0
- package/es/utils/index.js.map +1 -0
- package/es/{util → utils}/storage.js +17 -16
- package/es/utils/storage.js.map +1 -0
- package/lib/EventEmitter.d.ts +37 -0
- package/lib/EventEmitter.js +94 -0
- package/lib/EventEmitter.js.map +1 -0
- package/lib/FlowModel.d.ts +146 -0
- package/lib/FlowModel.js +236 -0
- package/lib/FlowModel.js.map +1 -0
- package/lib/Scheduler.d.ts +78 -0
- package/lib/Scheduler.js +179 -0
- package/lib/Scheduler.js.map +1 -0
- package/lib/constant/index.d.ts +16 -0
- package/{cjs/constant/constant.js → lib/constant/index.js} +4 -3
- package/lib/constant/index.js.map +1 -0
- package/lib/constant/logCode.d.ts +12 -0
- package/{cjs/constant/LogCode.js → lib/constant/logCode.js} +16 -13
- package/lib/constant/logCode.js.map +1 -0
- package/lib/expression/brewserVm.d.ts +2 -0
- package/lib/expression/brewserVm.js +33 -0
- package/lib/expression/brewserVm.js.map +1 -0
- package/lib/expression/index.d.ts +2 -0
- package/lib/expression/index.js +20 -0
- package/lib/expression/index.js.map +1 -0
- package/lib/expression/nodeVm.d.ts +4 -0
- package/lib/expression/nodeVm.js +13 -0
- package/lib/expression/nodeVm.js.map +1 -0
- package/lib/index.d.ts +157 -0
- package/lib/index.js +159 -0
- package/lib/index.js.map +1 -0
- package/lib/nodes/base.d.ts +108 -0
- package/lib/nodes/base.js +152 -0
- package/lib/nodes/base.js.map +1 -0
- package/lib/nodes/index.d.ts +3 -0
- package/lib/nodes/index.js +7 -0
- package/lib/nodes/index.js.map +1 -0
- package/lib/nodes/start.d.ts +6 -0
- package/lib/nodes/start.js +15 -0
- package/lib/nodes/start.js.map +1 -0
- package/lib/nodes/task.d.ts +6 -0
- package/lib/nodes/task.js +15 -0
- package/lib/nodes/task.js.map +1 -0
- package/lib/platform/browser/browserVm.d.ts +4 -0
- package/lib/platform/browser/browserVm.js +49 -0
- package/lib/platform/browser/browserVm.js.map +1 -0
- package/lib/platform/browser/index.d.ts +4 -0
- package/lib/platform/browser/index.js +28 -0
- package/lib/platform/browser/index.js.map +1 -0
- package/lib/platform/index.d.ts +1 -0
- package/lib/platform/index.js +5 -0
- package/lib/platform/index.js.map +1 -0
- package/lib/platform/node/index.d.ts +4 -0
- package/lib/platform/node/index.js +28 -0
- package/lib/platform/node/index.js.map +1 -0
- package/lib/platform/node/nodeVm.d.ts +1 -0
- package/lib/platform/node/nodeVm.js +13 -0
- package/lib/platform/node/nodeVm.js.map +1 -0
- package/lib/recorder/index.d.ts +46 -0
- package/lib/recorder/index.js +117 -0
- package/lib/recorder/index.js.map +1 -0
- package/lib/utils/global.d.ts +5 -0
- package/lib/utils/global.js +31 -0
- package/lib/utils/global.js.map +1 -0
- package/lib/utils/id.d.ts +3 -0
- package/lib/utils/id.js +20 -0
- package/lib/utils/id.js.map +1 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +9 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/storage.d.ts +7 -0
- package/{cjs/util → lib/utils}/storage.js +18 -17
- package/lib/utils/storage.js.map +1 -0
- package/package.json +30 -71
- package/src/EventEmitter.ts +103 -0
- package/src/FlowModel.ts +325 -0
- package/src/Scheduler.ts +244 -0
- package/src/constant/index.ts +23 -0
- package/src/constant/logCode.ts +34 -0
- package/src/expression/brewserVm.ts +36 -0
- package/src/expression/index.ts +17 -0
- package/src/expression/nodeVm.ts +14 -0
- package/src/index.ts +300 -0
- package/src/nodes/base.ts +234 -0
- package/src/nodes/index.ts +3 -0
- package/src/nodes/start.ts +8 -0
- package/src/nodes/task.ts +8 -0
- package/src/platform/browser/browserVm.ts +52 -0
- package/src/platform/browser/index.ts +28 -0
- package/src/platform/index.ts +1 -0
- package/src/platform/node/index.ts +28 -0
- package/src/platform/node/nodeVm.ts +12 -0
- package/src/recorder/index.ts +137 -0
- package/src/typings.d.ts +0 -0
- package/src/utils/global.ts +41 -0
- package/src/utils/id.ts +16 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/storage.ts +55 -0
- package/cjs/EventEmitter.js +0 -70
- package/cjs/FlowModel.js +0 -277
- package/cjs/Scheduler.js +0 -252
- package/cjs/expression/browserVm.js +0 -81
- package/cjs/expression/index.js +0 -63
- package/cjs/expression/nodeVm.js +0 -53
- package/cjs/index.js +0 -210
- package/cjs/nodes/BaseNode.js +0 -252
- package/cjs/nodes/StartNode.js +0 -27
- package/cjs/nodes/TaskNode.js +0 -27
- package/cjs/recorder/index.js +0 -168
- package/cjs/util/ID.js +0 -16
- package/cjs/util/global.js +0 -32
- package/es/constant/LogCode.js +0 -28
- package/es/expression/browserVm.d.ts +0 -4
- package/es/expression/browserVm.js +0 -76
- package/es/nodes/BaseNode.d.ts +0 -110
- package/es/nodes/BaseNode.js +0 -250
- package/es/nodes/StartNode.js +0 -25
- package/es/nodes/TaskNode.js +0 -25
- package/es/util/ID.js +0 -13
- package/es/util/global.d.ts +0 -5
- package/es/util/global.js +0 -26
- package/lib/main.js +0 -1
- /package/es/constant/{constant.d.ts → index.d.ts} +0 -0
- /package/es/constant/{LogCode.d.ts → logCode.d.ts} +0 -0
- /package/es/{util/ID.d.ts → utils/id.d.ts} +0 -0
- /package/es/{util → utils}/storage.d.ts +0 -0
package/es/expression/nodeVm.js
CHANGED
|
@@ -1,50 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
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
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
15
|
-
|
|
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:
|
|
16
|
+
register(nodeConfig: Engine.NodeConfig): void;
|
|
21
17
|
/**
|
|
22
|
-
* 自定义执行记录的存储,默认浏览器使用 sessionStorage
|
|
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(
|
|
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:
|
|
43
|
+
resume(resumeParam: Engine.ResumeParam): Promise<Engine.NextActionParam | undefined>;
|
|
52
44
|
getExecutionList(): Promise<any>;
|
|
53
|
-
|
|
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,
|
|
56
|
-
setGlobalData(data:
|
|
57
|
-
updateGlobalData(data:
|
|
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
|
|
60
|
-
export
|
|
155
|
+
export * from './constant';
|
|
156
|
+
export { BaseNode, StartNode, TaskNode, Recorder };
|
|
157
|
+
export default Engine;
|
package/es/index.js
CHANGED
|
@@ -1,57 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
31
|
+
register(nodeConfig) {
|
|
77
32
|
this.nodeModelMap.set(nodeConfig.type, nodeConfig.model);
|
|
78
|
-
}
|
|
33
|
+
}
|
|
79
34
|
/**
|
|
80
|
-
* 自定义执行记录的存储,默认浏览器使用 sessionStorage
|
|
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
|
-
|
|
46
|
+
setCustomRecorder(recorder) {
|
|
91
47
|
this.recorder = recorder;
|
|
92
|
-
}
|
|
48
|
+
}
|
|
93
49
|
/**
|
|
94
50
|
* 加载流程图数据
|
|
95
51
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
|
103
|
-
startNodeType
|
|
58
|
+
globalData,
|
|
59
|
+
startNodeType,
|
|
104
60
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
61
|
+
flowModel.load(graphData);
|
|
62
|
+
this.flowModel = flowModel;
|
|
63
|
+
return flowModel;
|
|
64
|
+
}
|
|
108
65
|
/**
|
|
109
|
-
*
|
|
66
|
+
* 执行流程,允许多次调用
|
|
110
67
|
*/
|
|
111
|
-
|
|
112
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
135
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
100
|
+
}
|
|
101
|
+
getExecutionList() {
|
|
149
102
|
var _a;
|
|
150
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
-
|
|
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
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
129
|
+
}
|
|
130
|
+
destroy() {
|
|
184
131
|
var _a;
|
|
185
132
|
(_a = this.recorder) === null || _a === void 0 ? void 0 : _a.clear();
|
|
186
|
-
}
|
|
187
|
-
|
|
133
|
+
}
|
|
134
|
+
getGlobalData() {
|
|
188
135
|
var _a;
|
|
189
136
|
return (_a = this.flowModel) === null || _a === void 0 ? void 0 : _a.globalData;
|
|
190
|
-
}
|
|
191
|
-
|
|
137
|
+
}
|
|
138
|
+
setGlobalData(data) {
|
|
192
139
|
if (this.flowModel) {
|
|
193
140
|
this.flowModel.globalData = data;
|
|
194
141
|
}
|
|
195
|
-
}
|
|
196
|
-
|
|
142
|
+
}
|
|
143
|
+
updateGlobalData(data) {
|
|
197
144
|
if (this.flowModel) {
|
|
198
145
|
Object.assign(this.flowModel.globalData, data);
|
|
199
146
|
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export * from './constant';
|
|
150
|
+
export { BaseNode, StartNode, TaskNode, Recorder };
|
|
203
151
|
export default Engine;
|
|
204
|
-
|
|
152
|
+
//# sourceMappingURL=index.js.map
|
package/es/index.js.map
ADDED
|
@@ -0,0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