@logicflow/engine 0.0.1 → 0.0.2
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 +23 -0
- package/README.md +3 -15
- package/cjs/FlowModel.js +57 -21
- package/cjs/Scheduler.js +21 -48
- package/cjs/recorder/index.js +7 -12
- package/es/FlowModel.d.ts +50 -10
- package/es/FlowModel.js +57 -21
- package/es/Scheduler.d.ts +18 -7
- package/es/Scheduler.js +21 -48
- package/es/recorder/index.js +7 -12
- package/lib/main.js +1 -1
- package/package.json +1 -1
- package/types/EventEmitter.d.ts +0 -7
- package/types/FlowModel.d.ts +0 -104
- package/types/Scheduler.d.ts +0 -51
- package/types/constant/LogCode.d.ts +0 -12
- package/types/constant/constant.d.ts +0 -14
- package/types/expression/browserVm.d.ts +0 -2
- package/types/expression/index.d.ts +0 -2
- package/types/expression/nodeVm.d.ts +0 -2
- package/types/index.d.ts +0 -47
- package/types/nodes/BaseNode.d.ts +0 -109
- package/types/nodes/StartNode.d.ts +0 -5
- package/types/nodes/TaskNode.d.ts +0 -5
- package/types/recorder/index.d.ts +0 -9
- package/types/util/ID.d.ts +0 -2
- package/types/util/global.d.ts +0 -5
- package/types/util/storage.d.ts +0 -6
package/types/EventEmitter.d.ts
DELETED
package/types/FlowModel.d.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import type { NodeConfig, NodeConstructor } from './nodes/BaseNode';
|
|
2
|
-
import type Recorder from './recorder';
|
|
3
|
-
import Scheduler from './Scheduler';
|
|
4
|
-
import type { TaskParam } from './types.d';
|
|
5
|
-
export declare type FlowResult = {
|
|
6
|
-
result?: Record<string, any>;
|
|
7
|
-
} & TaskParam;
|
|
8
|
-
export declare type TaskParams = {
|
|
9
|
-
executionId?: string;
|
|
10
|
-
taskId?: string;
|
|
11
|
-
nodeId?: string;
|
|
12
|
-
data?: Record<string, any>;
|
|
13
|
-
};
|
|
14
|
-
export declare type ExecParams = {
|
|
15
|
-
callback?: (result: FlowResult) => void;
|
|
16
|
-
onError?: (error: Error) => void;
|
|
17
|
-
} & TaskParams;
|
|
18
|
-
export default class FlowModel {
|
|
19
|
-
/**
|
|
20
|
-
* 流程支持的节点类型
|
|
21
|
-
*/
|
|
22
|
-
nodeModelMap: Map<string, NodeConstructor>;
|
|
23
|
-
/**
|
|
24
|
-
* 每一次执行流程都会生成一个唯一的executionId。
|
|
25
|
-
*/
|
|
26
|
-
executionId: string;
|
|
27
|
-
/**
|
|
28
|
-
* 调度器,用于调度节点的执行。
|
|
29
|
-
*/
|
|
30
|
-
scheduler: Scheduler;
|
|
31
|
-
/**
|
|
32
|
-
* 待执行的队列,当流程正在执行时,如果再次触发执行。那么会将执行参数放入到队列中,等待上一次执行完成后再执行。
|
|
33
|
-
*/
|
|
34
|
-
executeQueue: ExecParams[];
|
|
35
|
-
/**
|
|
36
|
-
* 当前正在执行。当监听到调度器执行完成时,出触发执行参数中的回调,告知外部执行完成。
|
|
37
|
-
*/
|
|
38
|
-
executingInstance: ExecParams;
|
|
39
|
-
/**
|
|
40
|
-
* 当前流程模型中的所有节点,边会被转换成节点的incoming和outgoing属性。
|
|
41
|
-
*/
|
|
42
|
-
nodeConfigMap: Map<string, NodeConfig>;
|
|
43
|
-
/**
|
|
44
|
-
* 当流程正在执行时,如果再次触发执行。那么会将执行参数放入到队列中,等待上一次执行完成后再执行。
|
|
45
|
-
*/
|
|
46
|
-
isRunning: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* 开始节点类型,在执行流程时,会从这些节点开始执行。
|
|
49
|
-
*/
|
|
50
|
-
startNodeType: string;
|
|
51
|
-
/**
|
|
52
|
-
* 当前流程中开始节点组成的数组。
|
|
53
|
-
*/
|
|
54
|
-
startNodes: NodeConfig[];
|
|
55
|
-
/**
|
|
56
|
-
* 用于存储全局数据,可以在流程中共享。
|
|
57
|
-
*/
|
|
58
|
-
globalData: Record<string, any>;
|
|
59
|
-
/**
|
|
60
|
-
* 外部传入的上下文,最终会传递给每个节点
|
|
61
|
-
* 例如:
|
|
62
|
-
* const context = {
|
|
63
|
-
* request: {
|
|
64
|
-
* get: (url) => {
|
|
65
|
-
* return fetch(url);
|
|
66
|
-
* }
|
|
67
|
-
* }
|
|
68
|
-
* 在节点内部可以通过 this.context.request.get(url) 来调用。
|
|
69
|
-
*/
|
|
70
|
-
context: Record<string, any>;
|
|
71
|
-
constructor({ nodeModelMap, recorder, context, globalData, startNodeType, }: {
|
|
72
|
-
nodeModelMap: Map<string, NodeConstructor>;
|
|
73
|
-
recorder: Recorder;
|
|
74
|
-
context?: Record<string, any>;
|
|
75
|
-
globalData?: Record<string, any>;
|
|
76
|
-
startNodeType?: string;
|
|
77
|
-
});
|
|
78
|
-
setStartNodeType(startNodeType: any): void;
|
|
79
|
-
load(graphData: any): void;
|
|
80
|
-
/**
|
|
81
|
-
* 执行流程
|
|
82
|
-
* 同一次执行,这次执行内部的节点执行顺序为并行。
|
|
83
|
-
* 多次执行,多次执行之间为串行。
|
|
84
|
-
* 允许一个流程多次执行,效率更高。
|
|
85
|
-
* 例如:
|
|
86
|
-
* 一个流程存在着两个开始节点,A和B,A和B的下一个节点都是C,C的下两个节点是D和E。
|
|
87
|
-
* 外部分别触发了A和B的执行,那么A和B的执行是串行的(也就是需要A执行完成后再执行B),但是D和E的执行是并行的。
|
|
88
|
-
* 如果希望A和B的执行是并行的,就不能使用同一个流程模型执行,应该初始化两个。
|
|
89
|
-
*/
|
|
90
|
-
execute(params: ExecParams): Promise<void>;
|
|
91
|
-
resume(params: ExecParams): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* 创建节点实例
|
|
94
|
-
* @param nodeId 节点Id
|
|
95
|
-
* @returns 节点示例
|
|
96
|
-
*/
|
|
97
|
-
createTask(nodeId: string): import("./nodes/BaseNode").default;
|
|
98
|
-
/**
|
|
99
|
-
* 更新流程全局数据
|
|
100
|
-
*/
|
|
101
|
-
updateGlobalData(data: any): void;
|
|
102
|
-
private onTaskFinished;
|
|
103
|
-
private createExecution;
|
|
104
|
-
}
|
package/types/Scheduler.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import EventEmitter from './EventEmitter';
|
|
2
|
-
import type { TaskParam, NodeParam, ResumeParam } from './types.d';
|
|
3
|
-
import type FlowModel from './FlowModel';
|
|
4
|
-
import type Recorder from './recorder';
|
|
5
|
-
declare type TaskParamMap = Map<string, TaskParam>;
|
|
6
|
-
/**
|
|
7
|
-
* 调度器
|
|
8
|
-
* 通过一个队列维护需要执行的节点,一个集合维护正在执行的节点
|
|
9
|
-
*/
|
|
10
|
-
export default class Scheduler extends EventEmitter {
|
|
11
|
-
nodeQueueMap: Map<string, NodeParam[]>;
|
|
12
|
-
taskRunningMap: Map<string, TaskParamMap>;
|
|
13
|
-
flowModel: FlowModel;
|
|
14
|
-
recorder: Recorder;
|
|
15
|
-
currentTask: TaskParam | null;
|
|
16
|
-
constructor(config: any);
|
|
17
|
-
/**
|
|
18
|
-
* 添加一个任务到队列中。
|
|
19
|
-
* 1. 由流程模型将所有的开始节点添加到队列中。
|
|
20
|
-
* 2. 当一个节点执行完成后,将后续的节点添加到队列中。
|
|
21
|
-
*/
|
|
22
|
-
addTask(nodeParam: NodeParam): void;
|
|
23
|
-
/**
|
|
24
|
-
* 调度器执行下一个任务
|
|
25
|
-
* 1. 提供给流程模型,用户开始执行第一个任务。
|
|
26
|
-
* 2. 内部任务执行完成后,调用此方法继续执行下一个任务。
|
|
27
|
-
* 3. 当判断没有可以继续执行的任务后,触发流程结束事件。
|
|
28
|
-
*/
|
|
29
|
-
run(runParams: {
|
|
30
|
-
executionId: string;
|
|
31
|
-
nodeId?: string;
|
|
32
|
-
taskId?: string;
|
|
33
|
-
}): void;
|
|
34
|
-
/**
|
|
35
|
-
* 恢复某个任务的执行。
|
|
36
|
-
* 可以自定义节点手动实现流程中断,然后通过此方法恢复流程的执行。
|
|
37
|
-
*/
|
|
38
|
-
resume(resumeParam: ResumeParam): Promise<void>;
|
|
39
|
-
stop(data: any): void;
|
|
40
|
-
private pushTaskToRunningMap;
|
|
41
|
-
private removeTaskFromRunningMap;
|
|
42
|
-
private hasRunningTask;
|
|
43
|
-
private exec;
|
|
44
|
-
private interrupted;
|
|
45
|
-
private next;
|
|
46
|
-
/**
|
|
47
|
-
* 为了防止多次添加导致
|
|
48
|
-
*/
|
|
49
|
-
private saveTaskResult;
|
|
50
|
-
}
|
|
51
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare enum ErrorCode {
|
|
2
|
-
NONE_START_NODE = 1000,
|
|
3
|
-
NONE_NODE_ID = 1001,
|
|
4
|
-
NO_DOCUMENT_BODY = 2001
|
|
5
|
-
}
|
|
6
|
-
export declare enum WarningCode {
|
|
7
|
-
NONE_START_NODE_IN_DATA = 2000,
|
|
8
|
-
START_NODE_INCOMING = 2001,
|
|
9
|
-
EXPRESSION_EXEC_ERROR = 3000
|
|
10
|
-
}
|
|
11
|
-
export declare const getErrorMsg: (code: ErrorCode) => string;
|
|
12
|
-
export declare const getWarningMsg: (code: WarningCode) => string;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const BASE_START_NODE = "start";
|
|
2
|
-
export declare const EVENT_INSTANCE_COMPLETE = "instance:complete";
|
|
3
|
-
export declare const EVENT_INSTANCE_INTERRUPTED = "instance:interrupted";
|
|
4
|
-
export declare enum FlowStatus {
|
|
5
|
-
COMPLETED = "completed",
|
|
6
|
-
INTERRUPTED = "interrupted",
|
|
7
|
-
RUNNING = "running",
|
|
8
|
-
ERROR = "error"
|
|
9
|
-
}
|
|
10
|
-
export declare enum TaskStatus {
|
|
11
|
-
SUCCESS = "success",
|
|
12
|
-
ERROR = "error",
|
|
13
|
-
INTERRUPTED = "interrupted"
|
|
14
|
-
}
|
package/types/index.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { ResumeParams, GraphConfigData } from './types.d';
|
|
2
|
-
import FlowModel, { TaskParams } from './FlowModel';
|
|
3
|
-
import StartNode from './nodes/StartNode';
|
|
4
|
-
import TaskNode from './nodes/TaskNode';
|
|
5
|
-
import Recorder from './recorder';
|
|
6
|
-
export default class Engine {
|
|
7
|
-
global: Record<string, any>;
|
|
8
|
-
graphData: GraphConfigData;
|
|
9
|
-
nodeModelMap: Map<string, any>;
|
|
10
|
-
flowModel: FlowModel;
|
|
11
|
-
recorder: Recorder;
|
|
12
|
-
constructor();
|
|
13
|
-
/**
|
|
14
|
-
* 注册节点
|
|
15
|
-
* @param nodeConfig { type: 'custom-node', model: Class }
|
|
16
|
-
*/
|
|
17
|
-
register(nodeConfig: any): void;
|
|
18
|
-
/**
|
|
19
|
-
* 自定义执行记录的存储,默认浏览器使用 sessionStorage,nodejs 使用内存存储。
|
|
20
|
-
* 注意:由于执行记录不会主动删除,所以需要自行清理。
|
|
21
|
-
* nodejs环境建议自定义为持久化存储。
|
|
22
|
-
* engine.setCustomRecorder({
|
|
23
|
-
* async addTask(task) {}
|
|
24
|
-
* async getTask(taskId) {}
|
|
25
|
-
* async getExecutionTasks(executionId) {}
|
|
26
|
-
* clear() {}
|
|
27
|
-
* });
|
|
28
|
-
*/
|
|
29
|
-
setCustomRecorder(recorder: Recorder): void;
|
|
30
|
-
/**
|
|
31
|
-
* 加载流程图数据
|
|
32
|
-
*/
|
|
33
|
-
load({ graphData, startNodeType, globalData, context, }: {
|
|
34
|
-
graphData: any;
|
|
35
|
-
startNodeType?: string;
|
|
36
|
-
globalData?: {};
|
|
37
|
-
context?: {};
|
|
38
|
-
}): FlowModel;
|
|
39
|
-
/**
|
|
40
|
-
* 执行流程,允许多次调用。
|
|
41
|
-
*/
|
|
42
|
-
execute(execParam?: TaskParams): Promise<unknown>;
|
|
43
|
-
resume(resumeParam: ResumeParams): Promise<unknown>;
|
|
44
|
-
getExecutionRecord(executionId: any): Promise<any[]>;
|
|
45
|
-
}
|
|
46
|
-
export { Engine, TaskNode, StartNode, };
|
|
47
|
-
export type { TaskParams, };
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type { ActionResult, NodeExecResult, ExecResumeParams, ExecParams } from '../types.d';
|
|
2
|
-
export interface BaseNodeInterface {
|
|
3
|
-
outgoing: Record<string, any>[];
|
|
4
|
-
incoming: Record<string, any>[];
|
|
5
|
-
nodeId: string;
|
|
6
|
-
type: string;
|
|
7
|
-
readonly baseType: string;
|
|
8
|
-
execute(taskParam: any): Promise<NodeExecResult>;
|
|
9
|
-
}
|
|
10
|
-
export declare type NodeConstructor = {
|
|
11
|
-
new (config: {
|
|
12
|
-
nodeConfig: NodeConfig;
|
|
13
|
-
context: Record<string, any>;
|
|
14
|
-
globalData: Record<string, any>;
|
|
15
|
-
}): BaseNode;
|
|
16
|
-
};
|
|
17
|
-
export declare type IncomingConfig = {
|
|
18
|
-
id: string;
|
|
19
|
-
properties?: Record<string, any>;
|
|
20
|
-
source: string;
|
|
21
|
-
};
|
|
22
|
-
export declare type OutgoingConfig = {
|
|
23
|
-
id: string;
|
|
24
|
-
target: string;
|
|
25
|
-
properties?: Record<string, any>;
|
|
26
|
-
};
|
|
27
|
-
export declare type NodeConfig = {
|
|
28
|
-
id: string;
|
|
29
|
-
type: string;
|
|
30
|
-
properties?: Record<string, any>;
|
|
31
|
-
incoming: IncomingConfig[];
|
|
32
|
-
outgoing: OutgoingConfig[];
|
|
33
|
-
};
|
|
34
|
-
export declare type NextTaskParam = {
|
|
35
|
-
executionId: string;
|
|
36
|
-
nodeId: string;
|
|
37
|
-
taskId: string;
|
|
38
|
-
nodeType: string;
|
|
39
|
-
outgoing: OutgoingConfig[];
|
|
40
|
-
properties?: Record<string, any>;
|
|
41
|
-
};
|
|
42
|
-
export default class BaseNode implements BaseNodeInterface {
|
|
43
|
-
static nodeTypeName: string;
|
|
44
|
-
/**
|
|
45
|
-
* 节点的出边
|
|
46
|
-
*/
|
|
47
|
-
outgoing: OutgoingConfig[];
|
|
48
|
-
/**
|
|
49
|
-
* 节点的入边
|
|
50
|
-
*/
|
|
51
|
-
incoming: IncomingConfig[];
|
|
52
|
-
/**
|
|
53
|
-
* 节点的属性
|
|
54
|
-
*/
|
|
55
|
-
properties?: Record<string, any>;
|
|
56
|
-
nodeId: string;
|
|
57
|
-
type: string;
|
|
58
|
-
/**
|
|
59
|
-
* 节点的上下文,是调用流程时传入的上下文
|
|
60
|
-
*/
|
|
61
|
-
context: Record<string, any>;
|
|
62
|
-
/**
|
|
63
|
-
* 节点的全局数据,是调用流程时传入的全局数据。
|
|
64
|
-
* 在计算表达式时,即基于全局数据进行计算。
|
|
65
|
-
*/
|
|
66
|
-
globalData: Record<string, any>;
|
|
67
|
-
readonly baseType: string;
|
|
68
|
-
constructor({ nodeConfig, context, globalData }: {
|
|
69
|
-
nodeConfig: any;
|
|
70
|
-
context: any;
|
|
71
|
-
globalData: any;
|
|
72
|
-
});
|
|
73
|
-
/**
|
|
74
|
-
* 节点的每一次执行都会生成一个唯一的taskId
|
|
75
|
-
*/
|
|
76
|
-
execute(params: ExecParams): Promise<NodeExecResult>;
|
|
77
|
-
/**
|
|
78
|
-
* 节点在执行中断后,可以通过resume方法恢复执行。
|
|
79
|
-
* 自定义节点时不建议重写此方法
|
|
80
|
-
*/
|
|
81
|
-
resume(params: ExecResumeParams): Promise<undefined>;
|
|
82
|
-
private getOutgoing;
|
|
83
|
-
private isPass;
|
|
84
|
-
/**
|
|
85
|
-
* 节点的执行逻辑
|
|
86
|
-
* @overridable 可以自定义节点重写此方法。
|
|
87
|
-
* @param params.executionId 流程执行记录ID
|
|
88
|
-
* @param params.taskId 此节点执行记录ID
|
|
89
|
-
* @param params.nodeId 节点ID
|
|
90
|
-
*/
|
|
91
|
-
action(params: {
|
|
92
|
-
executionId: string;
|
|
93
|
-
taskId: string;
|
|
94
|
-
nodeId: string;
|
|
95
|
-
}): Promise<ActionResult>;
|
|
96
|
-
/**
|
|
97
|
-
* 节点的重新恢复执行逻辑
|
|
98
|
-
* @overridable 可以自定义节点重写此方法。
|
|
99
|
-
* @param params.executionId 流程执行记录ID
|
|
100
|
-
* @param params.taskId 此节点执行记录ID
|
|
101
|
-
* @param params.nodeId 节点ID
|
|
102
|
-
*/
|
|
103
|
-
onResume(params: {
|
|
104
|
-
executionId: string;
|
|
105
|
-
taskId: string;
|
|
106
|
-
nodeId: string;
|
|
107
|
-
data?: Record<string, any>;
|
|
108
|
-
}): Promise<void>;
|
|
109
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { RecorderData, RecorderInterface } from '../types.d';
|
|
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>;
|
|
6
|
-
clear(): void;
|
|
7
|
-
private pushExecution;
|
|
8
|
-
private pushTaskToExecution;
|
|
9
|
-
}
|
package/types/util/ID.d.ts
DELETED
package/types/util/global.d.ts
DELETED