Graph
Graph:
object
Defined in: Core/Graph.ts:25
Runs asynchronous tasks after their dependencies succeed.
Shared dependencies run once per execution. Independent nodes can run concurrently, and failures signal active tasks to stop.
Type Declaration
Section titled “Type Declaration”make: <
Id,E,Out,Input>(target,options?) =>Graph<E,Out,Input> =makeGraph
Builds a reusable execution plan for a target node and its dependencies.
Checks for duplicate node IDs and cycles when called. Invalid graphs throw an error.
Type Parameters
Section titled “Type Parameters”Id extends string
E
Out
Input
Parameters
Section titled “Parameters”target
Section titled “target”WithKind<"GraphNode"> & object & (unknown extends Input ? never : unknown)
options?
Section titled “options?”Returns
Section titled “Returns”Graph<E, Out, Input>
- Graph.node for defining upstream DAG nodes.
- Graph.run for executing compiled graphs.
Example
Section titled “Example”node: {<
Id,Input,E,Out>(id,run):Node<Id,E,Out,unknownextendsInput?void:Input>; <Id,Deps,Input,E,Out>(id,deps,run):Node<Id,E|NodeErrorOf<Deps[keyofDeps]>,Out,NodeInput<Deps,Input>>; } =makeNode
Call Signature
Section titled “Call Signature”<
Id,Input,E,Out>(id,run):Node<Id,E,Out,unknownextendsInput?void:Input>
Creates an individual node descriptor for inclusion in a DAG.
Dependencies are declared as an object dictionary of upstream nodes.
The run callback receives the per-run input in ctx and dependency outputs in deps.
Type Parameters
Section titled “Type Parameters”Id extends string
Input = unknown
E = never
Out = never
Parameters
Section titled “Parameters”Id
NodeRun<undefined, Input, E, Out>
Returns
Section titled “Returns”Node<Id, E, Out, unknown extends Input ? void : Input>
- Graph.make to compile declared nodes into a validated execution graph.
- Graph.run for executing compiled graphs.
Example
Section titled “Example”Call Signature
Section titled “Call Signature”<
Id,Deps,Input,E,Out>(id,deps,run):Node<Id,E|NodeErrorOf<Deps[keyofDeps]>,Out,NodeInput<Deps,Input>>
Creates an individual node descriptor for inclusion in a DAG.
Dependencies are declared as an object dictionary of upstream nodes.
The run callback receives the per-run input in ctx and dependency outputs in deps.
Type Parameters
Section titled “Type Parameters”Id extends string
Deps extends Record<string, AnyNode<never>>
Input = unknown
E = never
Out = never
Parameters
Section titled “Parameters”Id
Deps
NodeRun<Deps, Input, E, Out>
Returns
Section titled “Returns”Node<Id, E | NodeErrorOf<Deps[keyof Deps]>, Out, NodeInput<Deps, Input>>
- Graph.make to compile declared nodes into a validated execution graph.
- Graph.run for executing compiled graphs.
Example
Section titled “Example”nodeFactory
Section titled “nodeFactory”nodeFactory: <
Input>() =>NodeFactory<Input>
Creates a node constructor with a shared input type.
Type Parameters
Section titled “Type Parameters”Input
Returns
Section titled “Returns”NodeFactory<Input>
Example
Section titled “Example”run: {(): <
E,Out>(graph) =>Deferred<Result<Aborted|E,Out>>; <Input>(input,options?): <E,Out>(graph) =>Deferred<Result<Aborted|E,Out>>; } =runGraph
Call Signature
Section titled “Call Signature”Starts a compiled graph and returns a deferred result.
Runs independent nodes concurrently, subject to the configured limit, and runs each shared
dependency once per graph execution. If a node returns an error, the graph settles with that
error and signals active tasks to abort. Tasks must respond to the signal to stop their work.
A caller’s abort signal settles the graph with Aborted even if active tasks ignore it.
Returns
Section titled “Returns”<E, Out>(graph) => Deferred<Result<Aborted | E, Out>>
- Graph.make to compile a target node into a validated graph.
- Graph.node for defining upstream DAG nodes.
A graph with no input is run as Graph.run()(graph). Pass undefined as the input when such a
graph also needs run options: Graph.run(undefined, { signal })(graph).
Example
Section titled “Example”Call Signature
Section titled “Call Signature”<
Input>(input,options?): <E,Out>(graph) =>Deferred<Result<Aborted|E,Out>>
Starts a compiled graph and returns a deferred result.
Runs independent nodes concurrently, subject to the configured limit, and runs each shared
dependency once per graph execution. If a node returns an error, the graph settles with that
error and signals active tasks to abort. Tasks must respond to the signal to stop their work.
A caller’s abort signal settles the graph with Aborted even if active tasks ignore it.
Type Parameters
Section titled “Type Parameters”Input
Parameters
Section titled “Parameters”Input
options?
Section titled “options?”Returns
Section titled “Returns”<E, Out>(graph) => Deferred<Result<Aborted | E, Out>>
- Graph.make to compile a target node into a validated graph.
- Graph.node for defining upstream DAG nodes.
A graph with no input is run as Graph.run()(graph). Pass undefined as the input when such a
graph also needs run options: Graph.run(undefined, { signal })(graph).