topology-runner
Version:
Run a topology consisting of a directed acyclic graph
90 lines (89 loc) • 2.91 kB
TypeScript
import EventEmitter from 'eventemitter3';
declare type UpdateState = (state: any) => void;
export declare type Initialized = Record<string, any>;
export interface BaseInput {
data: any[];
node: string;
context?: any;
}
export interface WorkInput extends BaseInput {
updateState: UpdateState;
state?: any;
signal: AbortSignal;
}
export declare type WorkOutput = Promise<any>;
export declare type RunFn = (arg: WorkInput) => WorkOutput;
export interface WorkNodeDef {
run: RunFn;
deps: string[];
type?: 'work';
}
export interface BranchingInput extends BaseInput {
branch: (node: string, reason?: string) => BranchingOutput;
none: (reason?: string) => BranchingOutput;
}
export interface BranchingOutput {
node: string | symbol;
reason?: string;
}
export interface BranchingNodeDef {
run: (arg: BranchingInput) => BranchingOutput;
deps: string[];
type: 'branching';
}
export declare type SuspensionInput = WorkInput;
export declare type SuspensionOutput = Promise<void>;
export interface SuspensionNodeDef {
run?: (arg: SuspensionInput) => SuspensionOutput;
deps: string[];
type: 'suspension';
}
export declare type NodeType = 'work' | 'branching' | 'suspension';
export declare type Input = BranchingInput | SuspensionInput | WorkInput;
export declare type Output = BranchingOutput | SuspensionOutput | WorkOutput;
export declare type NodeDef = BranchingNodeDef | SuspensionNodeDef | WorkNodeDef;
export declare type DAG = Record<string, {
deps: string[];
type: NodeType;
}>;
export declare type Spec = Record<string, NodeDef>;
export interface Options {
includeNodes?: string[];
excludeNodes?: string[];
data?: any;
context?: any;
}
export declare type Response = {
start(): Promise<void>;
stop(): void;
emitter: EventEmitter<Events, any>;
getSnapshot(): Snapshot;
};
export declare type Status = 'pending' | 'running' | 'completed' | 'suspended' | 'errored';
export declare type NodeStatus = Status | 'skipped';
export interface NodeData {
type: NodeType;
deps: string[];
status: NodeStatus;
started?: Date;
finished?: Date;
input?: any[];
output?: any;
state?: any;
error?: any;
selected?: string;
reason?: string;
}
export declare type SnapshotData = Record<string, NodeData>;
export interface Snapshot {
status: Status;
started: Date;
finished?: Date;
data: SnapshotData;
}
export declare type ObjectOfPromises = Record<string | number, Promise<any>>;
export declare type Events = 'data' | 'error' | 'done';
export declare type RunTopology = (spec: Spec, options?: Options) => Response;
export declare type RunTopologyInternal = (spec: Spec, dag: DAG, snapshot: Snapshot, context: any) => Response;
export declare type ResumeTopology = (spec: Spec, snapshot?: Snapshot, options?: Pick<Options, 'context'>) => Response;
export {};