IF Commons GitHub

graph

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-core FR-005

Graphs of work: an order in which each node comes after the nodes it needs (or the cycle that makes one impossible), and a schedule that runs each node the moment the nodes it needs are done, as many at once as asked, skipping what depends on a failure and holding back nothing else (0001-core FR-005). Taken from erga's lib/ts/graph (the build graph), with nodes of any string type.

import { order } from "./graph.ts";
order(new Map([["test", ["build"]], ["build", ["fetch"]], ["fetch", []]])); // { kind: "ok", value: ["fetch", "build", "test"] }

Source: commons/core/src/graph.ts

3 of 5 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

orderfunction
function order<N extends string>(graph: Graph<N>): Result<readonly N[], Cycle<N>>

The nodes in an order where each comes after every node it needs; ties broken by name, so the order is the same every time. Or the first cycle found.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

schedulefunction
function schedule<N extends string>(graph: Graph<N>, jobs: number, start: (n: N) => Promise<boolean>, skip?: (n: N, because: N) => void): Promise<ReadonlyMap<N, Ran>>

Every node of an acyclic graph run, each after the nodes it needs, at most jobs at once: start runs a node and says whether it succeeded; a node whose needed node failed or was skipped is skipped, and skip is told which node it waited for. How each node ended. A cycle, or a start that rejects, rejects the schedule.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Cycletypeno test imports it
type Cycle<N extends string> = { readonly kind: "cycle"; readonly nodes: readonly N[] };

A cycle among nodes: the nodes in it, in order, the first repeated at the end.

Graphtype
type Graph<N extends string> = ReadonlyMap<N, readonly N[]>;

A graph: each node and the nodes it needs. A needed node that is not a key of the graph is outside it, and ignored.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Rantypeno test imports it
type Ran = "done" | "failed" | "skipped";

How one node of a scheduled run ended.

Titles, headings, exports, tables, columns and requirements. Esc closes.