Skip to content

Graph

Graph: object

Defined in: Core/Graph.ts:26

Directed Acyclic Graph (DAG) task orchestration module.

Provides declarative step definition with dependency tracking, compile-time acyclicity verification, automatic diamond-dependency deduplication, bounded concurrency, and immediate sibling cancellation.

make: <Id, E, Out>(target) => Graph<E, Out> = makeGraph

Compiles a target sink node into an immutable, validated Graph plan.

Validates acyclicity using Kahn’s algorithm at compilation time and pre-computes reverse-dependency adjacency lists for optimal runtime scheduling throughput.

Id extends string

E

Out

Node<Id, E, Out>

Graph<E, Out>

const dashboardGraph = Graph.make(summaryNode);

node: <Id, Deps, E, Out, ETimeout>(config) => Node<Id, E | ETimeout | [Deps] extends [Record<string, AnyNode>] ? DepsErrors<Deps> : never, Out> = makeNode

Creates an individual node descriptor for inclusion in a DAG.

Dependencies are declared as an object dictionary of upstream nodes. The run callback contextually receives the strongly typed outputs of those dependencies.

Id extends string

Deps extends Record<string, AnyNode> | undefined

E

Out

ETimeout = never

NodeConfig<Id, Deps, E, Out, ETimeout>

Node<Id, E | ETimeout | [Deps] extends [Record<string, AnyNode>] ? DepsErrors<Deps> : never, Out>

  • Graph.make to compile declared nodes into a validated execution graph.
  • Graph.run for executing compiled graphs.
const user = Graph.node({
  id: "user",
  run: () => fetchUser("u_1"),
});

const permissions = Graph.node({
  id: "permissions",
  deps: { user },
  run: ({ user }) => fetchPermissions(user.roleId),
});

run: <E, Out>(graph, options?) => Result<E, Out> = runGraph

Executes a compiled Graph within a managed execution context, returning an infallible lazy Task.Result.

Maximizes concurrency across independent branches while guaranteeing that diamond dependencies execute exactly once. If any node fails or throws, all remaining in-flight sibling tasks are immediately aborted via an internal AbortController.

E

Out

Graph<E, Out>

RunOptions

Result<E, Out>

  • Graph.make to compile a target node into a validated graph.
  • Graph.node for defining upstream DAG nodes.
const outcome = await Graph.run(dashboardGraph, { concurrency: 4 })();