vlt / docs

  • PricingBenchmarks (opens in new window)Community (opens in new window)Feedback
  • Overview
    • Overview
    • Reference
  • Classes
  • Runner<Node, Result>
  • abstract RunnerBase<Node, Result, Sync, O>
  • RunnerSync<Node, Result>
  • Interfaces
  • RunnerOptions<Node, Result>
  • RunnerOptionsSync<Node, Result>
  • Type Aliases
  • Callable
  • DepResults<Node, Result>
  • ErrorCause<Node>
  • ErrorCode
  • SettledMap<Node, Result>
  • Functions
  • allSettled()
  • allSettledSync()
  • any()
  • anySync()
  • graphRun()
  • graphRunSync()
  • isGraphRunError()
  • race()
  • raceSync()
  1. Client
  2. /
  3. API Reference
  4. /
  5. @vltpkg/graph-run
  6. /
  7. Reference

Reference

Classes

Runner<Node, Result>

Defined in: index.ts:370

Asynchronous graph runner

Extends

  • RunnerBase<Node, Result, false, RunnerOptions<Node, Result>>

Type Parameters

Type Parameter
Node
Result

Constructors

new Runner()
TypeScript
new Runner<Node, Result>(options, from?): Runner<Node, Result>

Defined in: index.ts:201

Parameters
ParameterType
optionsRunnerOptions
from?Callable
Returns

Runner<Node, Result>

Inherited from

RunnerBase.constructor

Properties

PropertyTypeDefault valueDescriptionInherited from
dependentsMap<Node, Set<Node>>undefinedSet of dependents (direct & transitive) on each nodeRunnerBase.dependents
directDependentsMap<Node, Set<Node>>undefinedSet of direct dependents on each nodeRunnerBase.directDependents
errorsunknown[][]Rejections and Errors encountered in the traversalRunnerBase.errors
failFastbooleanundefinedTrue if we are in failFast modeRunnerBase.failFast
fromCallableundefinedFunction defining the callsite where the traversal was initiated, used for Error.captureStackTrace.RunnerBase.from
optionsRunnerOptionsundefinedOptions provided to constructorRunnerBase.options
promiseWaitingMap<Node, Set<Node>>undefinedTrack which node's promise is waiting for which other nodes-
resultsMap<Node, Result>undefinedThe map of traversal resultsRunnerBase.results
runningMap<Node, Promise<void>>undefinedMap of nodes currently awaiting completion-
settledSettledMap<Node, Result>undefinedThe map of PromiseSettledResult objectsRunnerBase.settled

Methods

getDeps()
TypeScript
getDeps(n): Promise<Node[]>

Defined in: index.ts:382

Get the dependencies of a given node

Parameters
ParameterType
nNode
Returns

Promise<Node[]>

Overrides

RunnerBase.getDeps

onCycle()
TypeScript
onCycle(
   n, 
   cycle, 
path): Promise<void>

Defined in: index.ts:406

Calls the options.onCycle() method when a cycle is detected.

Parameters
ParameterType
nNode
cycleNode[]
pathNode[]
Returns

Promise<void>

Overrides

RunnerBase.onCycle

route()
TypeScript
route(n, d): undefined | [Node, ...path: Node[]]

Defined in: index.ts:264

For a Node n that depends directly or transitively on Node d, find the shortest known dependency path from n to d. This is done by walking backwards breadth-first up the dependency relations from d until n is found.

If no known path can be found, then undefined is returned. Otherwise, a path array is returned that starts with n and ends with d.

Note that self-referential links are never considered, since they're by definition cyclical.

Parameters
ParameterType
nNode
dNode
Returns

undefined | [Node, ...path: Node[]]

Inherited from

RunnerBase.route

run()
TypeScript
run(): Promise<void>

Defined in: index.ts:507

Initiate the graph traversal, resolving/returning when complete

Returns

Promise<void>

Overrides

RunnerBase.run

visit()
TypeScript
visit(
   n, 
   path, 
depResults): Promise<Result>

Defined in: index.ts:397

Visit a node. Calls options.visit()

Parameters
ParameterType
nNode
pathNode[]
depResultsDepResults<Node, Result>
Returns

Promise<Result>

Overrides

RunnerBase.visit


abstract RunnerBase<Node, Result, Sync, O>

Defined in: index.ts:151

Base class of Runner and RunnerSync

Extended by

  • Runner
  • RunnerSync

Type Parameters

Type ParameterDefault type
Node-
Resultvoid
Sync extends booleanfalse
O extends Sync extends true ? RunnerOptionsSync<Node, Result> : RunnerOptions<Node, Result>Sync extends true ? RunnerOptionsSync<Node, Result> : RunnerOptions<Node, Result>

Constructors

new RunnerBase()
TypeScript
new RunnerBase<Node, Result, Sync, O>(options, from?): RunnerBase<Node, Result, Sync, O>

Defined in: index.ts:201

Parameters
ParameterType
optionsO
from?Callable
Returns

RunnerBase<Node, Result, Sync, O>

Properties

PropertyTypeDefault valueDescription
dependentsMap<Node, Set<Node>>undefinedSet of dependents (direct & transitive) on each node
directDependentsMap<Node, Set<Node>>undefinedSet of direct dependents on each node
errorsunknown[][]Rejections and Errors encountered in the traversal
failFastbooleanundefinedTrue if we are in failFast mode
fromCallableundefinedFunction defining the callsite where the traversal was initiated, used for Error.captureStackTrace.
optionsOundefinedOptions provided to constructor
resultsMap<Node, Result>undefinedThe map of traversal results
settledSettledMap<Node, Result>undefinedThe map of PromiseSettledResult objects

Methods

getDeps()
TypeScript
abstract getDeps(n): Sync extends true ? Node[] : Promise<Node[]>

Defined in: index.ts:232

Get the dependencies of a given node

Parameters
ParameterType
nNode
Returns

Sync extends true ? Node[] : Promise<Node[]>

onCycle()
TypeScript
abstract onCycle(
   n, 
   cycle, 
path): Sync extends true ? void : void | Promise<void>

Defined in: index.ts:246

Calls the options.onCycle() method when a cycle is detected.

Parameters
ParameterType
nNode
cycleNode[]
pathNode[]
Returns

Sync extends true ? void : void | Promise<void>

route()
TypeScript
route(n, d): undefined | [Node, ...path: Node[]]

Defined in: index.ts:264

For a Node n that depends directly or transitively on Node d, find the shortest known dependency path from n to d. This is done by walking backwards breadth-first up the dependency relations from d until n is found.

If no known path can be found, then undefined is returned. Otherwise, a path array is returned that starts with n and ends with d.

Note that self-referential links are never considered, since they're by definition cyclical.

Parameters
ParameterType
nNode
dNode
Returns

undefined | [Node, ...path: Node[]]

run()
TypeScript
abstract run(): Sync extends true ? void : Promise<void>

Defined in: index.ts:229

Initiate the graph traversal, resolving/returning when complete

Returns

Sync extends true ? void : Promise<void>

visit()
TypeScript
abstract visit(
   n, 
   path, 
depResults): Sync extends true ? Result : Promise<Result>

Defined in: index.ts:237

Visit a node. Calls options.visit()

Parameters
ParameterType
nNode
pathNode[]
depResultsDepResults<Node, Result>
Returns

Sync extends true ? Result : Promise<Result>


RunnerSync<Node, Result>

Defined in: index.ts:517

Synchronous graph runner

Extends

  • RunnerBase<Node, Result, true, RunnerOptionsSync<Node, Result>>

Type Parameters

Type Parameter
Node
Result

Constructors

new RunnerSync()
TypeScript
new RunnerSync<Node, Result>(options, from?): RunnerSync<Node, Result>

Defined in: index.ts:201

Parameters
ParameterType
optionsRunnerOptionsSync
from?Callable
Returns

RunnerSync<Node, Result>

Inherited from

RunnerBase.constructor

Properties

PropertyTypeDefault valueDescriptionInherited from
dependentsMap<Node, Set<Node>>undefinedSet of dependents (direct & transitive) on each nodeRunnerBase.dependents
directDependentsMap<Node, Set<Node>>undefinedSet of direct dependents on each nodeRunnerBase.directDependents
errorsunknown[][]Rejections and Errors encountered in the traversalRunnerBase.errors
failFastbooleanundefinedTrue if we are in failFast modeRunnerBase.failFast
fromCallableundefinedFunction defining the callsite where the traversal was initiated, used for Error.captureStackTrace.RunnerBase.from
optionsRunnerOptionsSyncundefinedOptions provided to constructorRunnerBase.options
resultsMap<Node, Result>undefinedThe map of traversal resultsRunnerBase.results
settledSettledMap<Node, Result>undefinedThe map of PromiseSettledResult objectsRunnerBase.settled

Methods

getDeps()
TypeScript
getDeps(n): Node[]

Defined in: index.ts:523

Get the dependencies of a given node

Parameters
ParameterType
nNode
Returns

Node[]

Overrides

RunnerBase.getDeps

onCycle()
TypeScript
onCycle(
   n, 
   cycle, 
   path): void

Defined in: index.ts:533

Calls the options.onCycle() method when a cycle is detected.

Parameters
ParameterType
nNode
cycleNode[]
pathNode[]
Returns

void

Overrides

RunnerBase.onCycle

route()
TypeScript
route(n, d): undefined | [Node, ...path: Node[]]

Defined in: index.ts:264

For a Node n that depends directly or transitively on Node d, find the shortest known dependency path from n to d. This is done by walking backwards breadth-first up the dependency relations from d until n is found.

If no known path can be found, then undefined is returned. Otherwise, a path array is returned that starts with n and ends with d.

Note that self-referential links are never considered, since they're by definition cyclical.

Parameters
ParameterType
nNode
dNode
Returns

undefined | [Node, ...path: Node[]]

Inherited from

RunnerBase.route

run()
TypeScript
run(): Map<Node, Result>

Defined in: index.ts:571

Initiate the graph traversal, resolving/returning when complete

Returns

Map<Node, Result>

Overrides

RunnerBase.run

visit()
TypeScript
visit(
   n, 
   path, 
   depResults): Result

Defined in: index.ts:528

Visit a node. Calls options.visit()

Parameters
ParameterType
nNode
pathNode[]
depResultsDepResults<Node, Result>
Returns

Result

Overrides

RunnerBase.visit

Interfaces

RunnerOptions<Node, Result>

Defined in: index.ts:63

Options that define the graph and how to traverse it

Extended by

  • RunnerOptionsSync

Type Parameters

Type ParameterDefault type
Node-
Resultvoid

Properties

PropertyTypeDescription
failFast?booleanSet to false to continue operations even if errors occur. If set to false, then an AggregateError will be raised on failure containing all failures (even if only one). If true, then a normal Error will be raised on failure. Default true
getDeps(node: Node) => Node[] | Promise<Node[]>get the dependencies of a given node
graph[Node, ...rest: Node[]]Array of one or more entry nodes.
onCycle?(node: Node, cycle: Node[], path: Node[]) => void | Promise<void>Called when a cycle is encountered. Throw in this method to enforce a DAG graph. If left undefined, then cycles are silently ignored and skipped. node parameter is the dependency that is being skipped. cycle is the route from the dependent back to itself via the parent. path is the path to the dependent who wanted this dep to be loaded.
signal?AbortSignala signal that will trigger the graph traversal to end prematurely
visit(node: Node, signal: AbortSignal, path: Node[], depResults: DepResults<Node, Result>) => Result | Promise<Result>action to take on each node

RunnerOptionsSync<Node, Result>

Defined in: index.ts:118

Options that can define a synchronous graph traversal.

Note that if the visit() method is async, then the promises themselves will be used as the Result type, which is likely not what you want!

Extends

  • RunnerOptions<Node, Result>

Type Parameters

Type ParameterDefault type
Node-
Resultvoid

Properties

PropertyTypeDescriptionOverridesInherited from
failFast?booleanSet to false to continue operations even if errors occur. If set to false, then an AggregateError will be raised on failure containing all failures (even if only one). If true, then a normal Error will be raised on failure. Default true-RunnerOptions.failFast
getDeps(node: Node) => Node[]Get a set of dependency nodes synchronouslyRunnerOptions.getDeps-
graph[Node, ...rest: Node[]]Array of one or more entry nodes.-RunnerOptions.graph
onCycle?(node: Node, cycle: Node[], path: Node[]) => voidHandle cycles synchronouslyRunnerOptions.onCycle-
signal?AbortSignala signal that will trigger the graph traversal to end prematurely-RunnerOptions.signal
visit(node: Node, signal: AbortSignal, path: Node[], depResults: DepResults<Node, Result>) => ResultVisit a node synchronouslyRunnerOptions.visit-

Type Aliases

Callable

TypeScript
type Callable = Function | (...a) => unknown | (...a) => unknown;

Defined in: index.ts:144

Any function or class. Used for Error.captureStackTrace


DepResults<Node, Result>

TypeScript
type DepResults<Node, Result> = Map<Node, Result | undefined>;

Defined in: index.ts:110

Type Parameters

Type Parameter
Node
Result

ErrorCause<Node>

TypeScript
type ErrorCause<Node> = object & 
  | {
  code: "GRAPHRUN_NO_NODES";
  found: unknown;
  wanted: string;
 }
  | {
  code: "GRAPHRUN_CYCLE_WITHOUT_PATH";
 }
  | {
  cause: Error;
  code: "GRAPHRUN_TRAVERSAL";
  node: Node;
  path: Node[];
};

Defined in: index.ts:23

Type declaration

NameType
codeErrorCode

Type Parameters

Type Parameter
Node

ErrorCode

TypeScript
type ErrorCode = 
  | "GRAPHRUN_NO_NODES"
  | "GRAPHRUN_CYCLE_WITHOUT_PATH"
  | "GRAPHRUN_TRAVERSAL";

Defined in: index.ts:18

Codes indicating the type of error that was encountered. These are found on the Error.cause.code field.

They are:

  • 'GRAPHRUN_TRAVERSAL' The command run on a given node has failed, either by throwing an error, or by returning a rejected promise.
  • 'GRAPHRUN_NO_NODES' An empty list of initial nodes was provided to the graph run operation. At least one starting node must be present in the list.
  • 'GRAPHRUN_CYCLE_WITHOUT_PATH' - A cycle in the graph was detected, but the path to the node where the cycle was detected could not be determined. This is impossible, and cannot ever happen.

SettledMap<Node, Result>

TypeScript
type SettledMap<Node, Result> = Map<Node, PromiseSettledResult<Result>>;

Defined in: index.ts:138

A map of nodes to their PromiseSettledResult value

Type Parameters

Type ParameterDefault type
Node-
Resultvoid

Functions

allSettled()

TypeScript
function allSettled<Node, Result>(options): Promise<SettledMap<Node, Result>>

Defined in: index.ts:629

Asynchronous graph traversal, capturing all error/result statuses.

Type Parameters

Type Parameter
Node
Result

Parameters

ParameterType
optionsRunnerOptions<Node, Result>

Returns

Promise<SettledMap<Node, Result>>


allSettledSync()

TypeScript
function allSettledSync<Node, Result>(options): SettledMap<Node, Result>

Defined in: index.ts:644

Synchronous graph traversal, capturing all error/result statuses.

Type Parameters

Type Parameter
Node
Result

Parameters

ParameterType
optionsRunnerOptionsSync<Node, Result>

Returns

SettledMap<Node, Result>


any()

TypeScript
function any<Node, Result>(options): Promise<Result>

Defined in: index.ts:660

Asynchronous graph traversal, returning the first successful visit. If all visits fail, then an AggregateError is raised with all errors encountered.

Type Parameters

Type Parameter
Node
Result

Parameters

ParameterType
optionsRunnerOptions<Node, Result>

Returns

Promise<Result>


anySync()

TypeScript
function anySync<Node, Result>(options): Result

Defined in: index.ts:700

Synchronous graph traversal, returning the first successful visit. If all visits fail, then an AggregateError is thrown with all errors encountered.

Type Parameters

Type Parameter
Node
Result

Parameters

ParameterType
optionsRunnerOptionsSync<Node, Result>

Returns

Result


graphRun()

TypeScript
function graphRun<Node, Result>(options): Promise<Map<Node, Result>>

Defined in: index.ts:586

Asynchronous graph traversal method

If failFast:false is set in the options, then an AggregateError will be raised if there were any failures. Otherwise, a normal Error is raised on failure.

Type Parameters

Type Parameter
Node
Result

Parameters

ParameterType
optionsRunnerOptions<Node, Result>

Returns

Promise<Map<Node, Result>>


graphRunSync()

TypeScript
function graphRunSync<Node, Result>(options): Map<Node, Result>

Defined in: index.ts:609

Synchronous graph traversal method

If failFast:false is set in the options, then an AggregateError will be thrown if there were any failures. Otherwise, a normal Error is thrown on failure.

Type Parameters

Type Parameter
Node
Result

Parameters

ParameterType
optionsRunnerOptionsSync<Node, Result>

Returns

Map<Node, Result>


isGraphRunError()

TypeScript
function isGraphRunError<Node>(er): er is Error & { cause: ErrorCause<Node> }

Defined in: index.ts:40

Type Parameters

Type Parameter
Node

Parameters

ParameterType
erunknown

Returns

er is Error & { cause: ErrorCause<Node> }


race()

TypeScript
function race<Node, Result>(options): Promise<Result>

Defined in: index.ts:739

Asynchronous graph traversal, resolving or rejecting when the first visit resolves or rejects.

Type Parameters

Type Parameter
Node
Result

Parameters

ParameterType
optionsRunnerOptions<Node, Result>

Returns

Promise<Result>


raceSync()

TypeScript
function raceSync<Node, Result>(options): Result

Defined in: index.ts:768

Synchronous graph traversal, returning or throwing when the first visit is completed.

Type Parameters

Type Parameter
Node
Result

Parameters

ParameterType
optionsRunnerOptionsSync<Node, Result>

Returns

Result


Previous@vltpkg/graph-runNext@vltpkg/init

On this page

  • Classes
  • Runner<Node, Result>
  • abstract RunnerBase<Node, Result, Sync, O>
  • RunnerSync<Node, Result>
  • Interfaces
  • RunnerOptions<Node, Result>
  • RunnerOptionsSync<Node, Result>
  • Type Aliases
  • Callable
  • DepResults<Node, Result>
  • ErrorCause<Node>
  • ErrorCode
  • SettledMap<Node, Result>
  • Functions
  • allSettled()
  • allSettledSync()
  • any()
  • anySync()
  • graphRun()
  • graphRunSync()
  • isGraphRunError()
  • race()
  • raceSync()

Deploy your package on vlt.io

Publish scoped and private packages, manage organizations and access, and give every developer and CI environment a consistent source for public and private JavaScript dependencies.

Publish now