Skip to content
@tde.io/plexis  ·  npm install @tde.io/plexis  ·  npm  ·  GitHub

Pipeline Instance

Pipeline — returned by definePipeline(). Represents a finite, single-run workflow that executes nodes in order, following fork conditions until a terminal node is reached.

PropertyTypeDescription
idstringPipeline identifier
graphPipelineGraphGraph query API; see PipelineGraph methods

Execute the pipeline from its initial node.

context TContext

Initial context. Merged with patches as nodes execute.

input unknown (optional)

Arbitrary value passed to each node’s action and fork conditions via PipelineActionInput.input and PipelineConditionInput.input.

Promise<PipelineRunResult<TContext>> — see PipelineRunResult.

import { definePipeline, node, action, fork, target, terminal } from '@tde.io/plexis';
type Ctx = { validated: boolean; charged: boolean };
const payment = definePipeline<Ctx>('payment', () => {
node('validate', () => {
action(async (ctx) => ({ validated: true }));
fork('charge', target('charge'), (ctx) => ctx.validated);
fork('decline', target('decline'));
});
node('charge', terminal(async () => ({ charged: true })));
node('decline', terminal());
return { initial: 'validate' };
});
const result = await payment.run({ validated: false, charged: false });
console.log(result.status); // 'completed'
console.log(result.finalNode); // 'charge'
console.log(result.context.charged); // true

Return a static graph descriptor.

GraphDescriptor — see GraphDescriptor.

const descriptor = payment.describe();
console.log(descriptor.nodes.map((n) => n.id)); // ['validate', 'charge', 'decline']

Export trace data for this pipeline.

format 'json' | 'text' | 'tree' (optional)

Export format.

unknown

const tree = payment.trace('tree');
const json = payment.trace('json');

Inspect a node’s paths.

node string | GraphNodeRef

Node ID or graph node reference.

options PathQueryOptions (optional)

See PathQueryOptions below.

NodeInspection — see NodeInspection.

const info = payment.inspectNode('validate');
console.log(info.outbound.length); // edges from 'validate'
console.log(info.pathsFrom.length); // paths reachable from 'validate'

Accessed via pipeline.graph.

MethodParametersReturnsDescription
describe()GraphDescriptorStatic graph descriptor for this pipeline
node(id)id: stringGraphNode | undefinedLook up a graph node by ID
inbound(id)id: stringGraphEdge[]All edges pointing to the given node
outbound(id)id: stringGraphEdge[]All edges pointing from the given node
pathsTo(id, options?)id: string, options?: PathQueryOptionsGraphPath[]All paths leading to the given node
pathsFrom(id, options?)id: string, options?: PathQueryOptionsGraphPath[]All paths starting from the given node
reachableFrom(id, options?)id: string, options?: PathQueryOptionsGraphNode[]All nodes reachable from the given node
const graph = payment.graph;
const node = graph.node('validate');
const outgoing = graph.outbound('validate');
const reachable = graph.reachableFrom('validate');
const paths = graph.pathsTo('charge');

Used by inspectNode() and the graph query methods to control traversal behavior.

FieldTypeRequiredDescription
maxDepthnumberNoMaximum path depth to traverse
includeCyclesbooleanNoWhen true, cyclic paths are included in results
includeCrossBoundarybooleanNoWhen true, paths crossing domain/pipeline boundaries are included
direction'inbound' | 'outbound'NoTraversal direction for reachability queries
const paths = payment.graph.pathsFrom('validate', {
maxDepth: 5,
includeCycles: false,
});