@logicflow/engine
Version:
a process engine for javascript
158 lines (157 loc) • 4.68 kB
TypeScript
import { BaseNode, StartNode, TaskNode } from './nodes';
import { FlowModel } from './FlowModel';
import { Recorder } from './recorder';
export declare class Engine {
readonly instanceId: string;
graphData?: Engine.GraphConfigData;
flowModel?: FlowModel;
recorder?: Recorder;
context?: Record<string, unknown>;
nodeModelMap: Map<string, BaseNode.NodeConstructor>;
constructor(options?: Engine.Options);
/**
* 注册节点
* @param nodeConfig { type: 'custom-node', model: NodeClass }
*/
register(nodeConfig: Engine.NodeConfig): void;
/**
* 自定义执行记录的存储,默认浏览器使用 sessionStorage, nodejs 使用内存存储
* 注意:由于执行记录不全会主动删除,所以需要自行清理。
* nodejs 环境建议自定义为持久化存储。
* engine.setCustomRecorder({{
* async addActionRecord(task) {}
* async getTask(actionId) {}
* async getExecutionTasks(executionId) {}
* clear(instanceId) {}
* }}
* @param recorder
*/
setCustomRecorder(recorder: Recorder): void;
/**
* 加载流程图数据
*/
load({ graphData, startNodeType, globalData, }: Engine.LoadGraphParam): FlowModel;
/**
* 执行流程,允许多次调用
*/
execute(param?: Partial<Engine.ActionParam>): Promise<Engine.NextActionParam>;
/**
* 中断流程恢复
* @param resumeParam
* @returns
*/
resume(resumeParam: Engine.ResumeParam): Promise<Engine.NextActionParam | undefined>;
getExecutionList(): Promise<any>;
/**
* 获取执行任务记录
* @param executionId
* @returns
*/
getExecutionRecord(executionId: Engine.Key): Promise<Recorder.Info[] | null>;
destroy(): void;
getGlobalData(): Record<string, unknown> | undefined;
setGlobalData(data: Record<string, unknown>): void;
updateGlobalData(data: Record<string, unknown>): void;
}
export declare namespace Engine {
type Point = {
id?: string;
x: number;
y: number;
[key: string]: unknown;
};
type TextConfig = {
value: string;
} & Point;
type NodeData = {
id: string;
type: string;
x?: number;
y?: number;
text?: TextConfig | string;
zIndex?: number;
properties?: Record<string, unknown>;
};
type EdgeData = {
id: string;
/**
* 边的类型,不传默认为lf.setDefaultEdgeType(type)传入的类型。
* LogicFlow内部默认为polyline
*/
type?: string;
sourceNodeId: string;
sourceAnchorId?: string;
targetNodeId: string;
targetAnchorId?: string;
startPoint?: {
x: number;
y: number;
};
endPoint?: {
x: number;
y: number;
};
text?: {
x: number;
y: number;
value: string;
} | string;
pointsList?: Point[];
zIndex?: number;
properties?: Record<string, unknown>;
};
type GraphConfigData = {
nodes: NodeData[];
edges: EdgeData[];
};
type LoadGraphParam = {
graphData: GraphConfigData;
startNodeType?: string;
globalData?: Record<string, unknown>;
};
type Options = {
context?: Record<string, unknown>;
debug?: boolean;
};
type Key = string | number;
type NodeConfig = {
type: string;
model: any;
};
type NodeParam = {
executionId: Key;
nodeId: Key;
};
type CommonActionInfo = {
actionId: Key;
} & NodeParam;
type ActionParam = CommonActionInfo;
type ResumeParam = {
data?: Record<string, unknown>;
} & CommonActionInfo;
type ExecParam = {
next: (data: NextActionParam) => void;
} & ActionParam;
type ExecResumeParam = {
next: (data: NextActionParam) => void;
} & ResumeParam;
type ActionStatus = 'success' | 'error' | 'interrupted' | '';
type NextActionParam = {
executionId: Key;
nodeId: Key;
actionId: Key;
nodeType: string;
outgoing: BaseNode.OutgoingConfig[];
properties?: Record<string, unknown>;
detail?: Record<string, unknown>;
status?: ActionStatus;
};
type ActionResult = NextActionParam;
type NodeExecResult = {
nodeType: string;
properties?: Record<string, unknown>;
} & CommonActionInfo & ActionResult;
}
export * from './constant';
export { BaseNode, StartNode, TaskNode, Recorder };
export default Engine;