symflow
Version:
SymFlow is a powerful workflow and state machine engine for Node.js, inspired by Symfony Workflow. It allows you to define workflows, transition entities between states, and optionally log audit trails.
25 lines (24 loc) • 749 B
TypeScript
import { WorkflowEventHandler, WorkflowEventType } from './event-workflow';
export type State = string | string[];
export type Place = {
metadata?: Record<string, any>;
};
export type Transition = {
from: State;
to: State;
metadata?: Record<string, any>;
};
export type WorkflowType = 'state_machine' | 'workflow';
export interface WorkflowDefinition<T extends Record<string, any>> {
name: string;
type?: WorkflowType;
auditTrail?: boolean | {
enabled: boolean;
};
metadata?: Record<string, any>;
stateField: keyof T;
initialState: State;
places: Record<string, Place>;
transitions: Record<string, Transition>;
events?: Partial<Record<WorkflowEventType, WorkflowEventHandler<T>[]>>;
}