API Reference: Orchestration & Combinators
The Orchestration & Combinators API in Siglo provides functional combinators and workflow orchestrators to compose modular, resilient, and type-safe async workflows. Siglo combines sequential pipelines, parallel fan-out/fan-in, conditional branching, dynamic collections mapping, durable event suspension, and workflow AST inspection.Table of Contents
- Core Orchestration
- Parallel Combinators
- Branching and Routing
- Dynamic Mapping
- Durable Waits and Event Resumption
- Graph Inspection and Visualization
Core Orchestration
flow(...steps)
Composes sequential execution units (Step, nested Flow, or combinator steps) into an executable workflow with compile-time accumulated context inference and typed step history ($steps).
Signatures
Parameters
...steps:(Step | Flow | Array<Step | Flow>)[]— Variable list or nested arrays of steps to execute sequentially.
Returns
AFlow<TInput, TOutput> object exposing execution method (.run()), durable controls (.resume(), .compensate()), guardrails (.networkPolicy()), live monitoring (.monitor(), .hook()), and export utilities (.toMermaid(), .toJSON()).
Context Accumulation & $steps
As each step executes, its output is shallow-merged into the accumulated context. Earlier step outputs remain accessible to subsequent steps. In addition, the return context includes a typed $steps property containing each step’s output keyed by step name.
Example
isFlow(item)
Type guard verifying whether a value implements the Flow interface.
Signature
Example
toPOJO(context)
Strips internal tracked proxy wrappers, getters, and metadata from an execution context, returning a clean, serializable JavaScript object.
Signature
Example
Parallel Combinators
parallel(steps, options?)
Executes multiple steps, flows, or functions concurrently. By default, it operates in fail-fast mode: if any branch fails, all other in-flight branches are aborted via an internal AbortController.
Signature
Options
Merge Strategies
'shallow'(default):Object.assign(target, branchOutput).'deep': Recursively merges nested objects.'error': ThrowsFieldCollisionExceptionif two branches output differing values for the same key.'namespace': Scopes each branch’s output under its branch name (target[branchName] = branchOutput).(target, source, branchKey) => merged: Custom callback to resolve branch collisions.
Context Isolation
Each branch receives an isolated clone of the input context. Mutating context in one branch does not bleed into sibling branches.Example
all(steps, options?)
Convenience alias for parallel(steps, { ...options, mode: 'fail-fast' }).
Signature
Example
allSettled(steps, options?)
Executes all branches concurrently without failing fast. Collects all results and errors, ensuring that every branch runs to completion or failure.
Signature
Return Context Additions
$branches:BranchExecutionSummary[]containing execution duration, status, output, and error for each branch.$settled:PromiseSettledResult<any>[]standard settled result objects.- Each branch output or error object keyed by branch name (e.g.
result.auditStep = { error: ... }).
Example
race(...steps)
Executes multiple branches concurrently. Settles as soon as the first branch resolves or rejects. Losing branches are immediately aborted via cooperative AbortSignal cancellation.
Signature
Example
Branching and Routing
when(predicate, thenStep, elseStep?)
Conditional branching combinator that evaluates a predicate function against the current context. If true, executes thenStep; otherwise executes elseStep (if provided).
Signatures
Metadata
The output context is enriched with:$branchSelected:'then'|'else'|undefined$skippedBranches: Array of branch route names that were bypassed.$skipped:trueif predicate evaluated tofalseand noelseStepwas configured.
Example
branch(selectorOrBranches, branchesMap?, defaultBranch?)
Dynamic multi-path router that selects a branch from a map using a selector function or context key.
Signatures
Example
Dynamic Mapping
map(itemsOrAccessor, processItem, options?)
Maps an array or async iterable through an item processing step or subflow with bounded worker concurrency, error aggregation, and order preservation.
Signatures
Process Item Context
InsideprocessItem, the step parameter receives { item, index, total, ...meta }.
Output
The map step outputs:items: Array of processed results.count: Total count of items.errors: Array of caught errors (whenstopOnError: false).
Example
Durable Waits and Event Resumption
waitForEvent(eventName, options)
Suspends workflow execution in durable mode until an external event is delivered via resumeWorkflow(), or an optional timeout window elapses.
Signature
Semantics
- When
options.durable: true, reachingwaitForEventpersists an execution checkpoint to storage and throwsWorkflowSuspendedException. - The waiting instance is registered under
eventNameand the computedcorrelationKey. - If no event arrives before
timeout, subsequent resumption throwsExpiredWaitException.
Example
wait(durationOrMs)
Pauses workflow execution for a duration string (e.g. '5m', '2h', '1d') or millisecond count. In durable mode, suspends execution to storage. In in-memory mode, pauses using a timer.
Signature
Example
resumeWorkflow(flow, key, payload?, options?)
Restores and resumes a suspended durable workflow from storage using its correlation key or stack ID.
Signature
Example
Graph Inspection and Visualization
toGraph(item)
Compiles any step, flow, or combinator into a JSON-serializable WorkflowNode AST.
Signature
Node Types (WorkflowNodeType)
'step': Single step execution unit.'sequence': Sequential chain (Flow).'parallel': Concurrent fan-out.'branch': Conditional or multi-path router.'wait': Durable wait or event suspension.'map': Dynamic array/iterable mapping.
inspectGraph(item)
Analyzes workflow AST topology and returns structural metrics including node count, depth, and directed edges.
Signature
Example
validateGraph(node)
Validates graph structure, checking for cycles and unreachable nodes without throwing.
Signature
assertValidGraph(node)
Asserts graph validity, throwing GraphValidationException if any cycles or structural defects are detected. Note that flow.run() does not automatically run graph assertions at runtime; validation is an explicit utility.
Signature
toMermaid(item, options?)
Renders workflow structure as a Mermaid flowchart diagram with policy badges (e.g. [⏱️ 3000ms], [🔁 retry(3)], [⏪ saga]).
Signature
Example
toDot(item, options?)
Exports Graphviz DOT representation (options.graphName).
