UNPKG

chrono-forge

Version:

A comprehensive framework for building resilient Temporal workflows, advanced state management, and real-time streaming activities in TypeScript. Designed for a seamless developer experience with powerful abstractions, dynamic orchestration, and full cont

71 lines (70 loc) 2.58 kB
import { DirectedGraph } from 'eventemitter3-graphology'; import { StepMetadata } from '../decorators/Step'; export type DSLDefinition = { variables: Record<string, unknown>; plan: Statement; }; export type StatementConditions = { when?: (variables: Record<string, unknown>, plan: Statement) => boolean; wait?: ((variables: Record<string, unknown>, plan: Statement) => boolean) | [(variables: Record<string, unknown>, plan: Statement) => boolean, number]; timeout?: number; retries?: number; required?: boolean; }; export type Statement = { sequence?: Sequence; parallel?: Parallel; execute?: Execute; foreach?: ForEach; while?: While; doWhile?: DoWhile; } & StatementConditions; export type Sequence = { elements: Statement[]; } & StatementConditions; export type Parallel = { branches: Statement[]; } & StatementConditions; export type Execute = { name?: string; code?: string; step?: string; activity?: string; workflow?: string; with?: string[]; store?: string; } & StatementConditions; export type DSLGeneration = { nodeId: string; graph: DirectedGraph; bindings: Record<string, string>; acts: Record<string, (...args: string[]) => Promise<string | undefined>>; steps: Record<string, (...args: string[]) => Promise<string | undefined>>; nodeIds: string[]; execute: () => Promise<unknown>; }; export type ForEach = { in: string; as: string; body: Statement; }; export type While = { condition: (variables: Record<string, unknown>, plan: Statement) => boolean; body: Statement; }; export type DoWhile = { body: Statement; condition: (variables: Record<string, unknown>, plan: Statement) => boolean; }; export declare function DSLInterpreter(dsl: DSLDefinition, injectedActivities?: Record<string, (...args: string[]) => Promise<string | undefined>>, injectedSteps?: Record<string, (...args: string[]) => Promise<string | undefined>>, options?: { visualizationFormat?: 'list' | 'tree'; }): AsyncGenerator<DSLGeneration, void, unknown>; /** * Adapter function to convert StepMetadata from the @Step decorator into DSLDefinition format * * @param steps Array of step metadata from a Workflow class * @param initialVariables Initial variables for the DSL * @param workflowInstance The workflow instance (optional) * @returns DSLDefinition object representing the workflow steps */ export declare function convertStepsToDSL(steps: StepMetadata[], initialVariables?: Record<string, unknown>, workflowInstance?: any): DSLDefinition;