@rudderstack/workflow-engine
Version:
A generic workflow execution engine
171 lines • 4.39 kB
TypeScript
import { type StepExecutionError } from '../errors';
export interface Executor {
execute(input: any, bindings?: ExecutionBindings): Promise<any>;
}
export declare enum LogLevel {
DEBUG = 0,
INFO = 1,
WARN = 2,
ERROR = 3
}
export type PathBinding = {
name?: string | string[];
path?: string;
exportAll?: true;
};
export type ValueBinding = {
name: string;
value: any;
};
export type ParentBinding = {
name: string;
fromParent: true;
};
export type Binding = PathBinding | ValueBinding | ParentBinding;
export type ExecutionBindings = {
[key: string]: any;
outputs: Record<string, any>;
context: Record<string, any>;
setContext: (string: any, any: any) => void;
};
export declare enum TemplateType {
JSONATA = "jsonata",
JSON_TEMPLATE = "jsontemplate"
}
export type StepOutput = {
error?: {
message: string;
status: number;
originalError: Error;
error: StepExecutionError;
};
skipped?: boolean;
output?: any;
outputs?: Record<string, any>;
};
export type LoopStepOutput = {
output: StepOutput[];
};
export type BatchResult = {
key: string;
items: any[];
indices: number[];
};
export type BatchStepOutput = {
output: BatchResult[];
};
export declare enum StepType {
Simple = "simple",
Workflow = "workflow",
Batch = "batch",
Custom = "custom",
Unknown = "unknown"
}
export declare enum StepExitAction {
Return = "return",
Continue = "continue"
}
export type StepFunction = (input: any, bindings: ExecutionBindings) => StepOutput;
export type ExternalWorkflow = {
path: string;
rootPath?: string;
bindings?: Binding[];
};
export type StepCommon = {
name: string;
description?: string;
type?: StepType;
condition?: string;
else?: Step;
inputTemplate?: string;
loopOverInput?: boolean;
loopCondition?: string;
onComplete?: StepExitAction;
onError?: StepExitAction;
debug?: boolean;
identity?: boolean;
};
export type SimpleStep = StepCommon & {
template?: string;
templatePath?: string;
mappings?: boolean;
externalWorkflow?: ExternalWorkflow;
functionName?: string;
};
export type BatchConfig = {
options?: {
size?: number;
length?: number;
};
disabled?: true;
filter?: string;
map?: string;
key: string;
};
export type BatchStep = StepCommon & {
batches?: BatchConfig[];
executor?: string;
};
export type CustomStep = StepCommon & {
provider?: string;
executor?: string;
params?: Record<string, any>;
};
export type WorkflowStep = StepCommon & {
steps?: SimpleStep[];
workflowStepPath?: string;
};
export type Step = SimpleStep | WorkflowStep | BatchStep | CustomStep;
export type Workflow = {
name: string;
bindings?: Binding[];
steps: Step[];
templateType?: TemplateType;
executor?: string;
};
export type WorkflowOutput = {
output?: any;
outputs?: Record<string, any>;
status?: number;
error?: any;
};
export type WorkflowOptions = {
bindingsPaths?: string[];
rootPath: string;
creationTimeBindings?: Record<string, any>;
templateType?: TemplateType;
executor?: WorkflowExecutor;
bindingProvider?: WorkflowBindingProvider;
};
export type WorkflowOptionsInternal = WorkflowOptions & {
currentBindings: Record<string, any>;
parentBindings?: Record<string, any>;
};
export interface WorkflowExecutor {
execute(engine: WorkflowEngine, input: any, bindings?: Record<string, any>): Promise<WorkflowOutput>;
}
export interface WorkflowBindingProvider {
provide(name: string): Promise<any>;
}
export interface StepExecutor extends Executor {
/**
* Returns the name of the step which executor is operating
*/
getStepName(): string;
/**
* Returns the step which executor is operating
*/
getStep(): Step;
/**
* Executes the step
*/
execute(input: any, executionBindings: ExecutionBindings): Promise<StepOutput>;
}
export interface WorkflowEngine extends Executor {
getName(): string;
getBindings(): Record<string, any>;
getStepExecutors(): StepExecutor[];
getStepExecutor(stepName: string): StepExecutor;
execute(input: any, executionBindings?: Record<string, any>): Promise<WorkflowOutput>;
}
//# sourceMappingURL=types.d.ts.map