Expand description
Graphs, canonically: a node and edge model in Rust, derived from the registry and the
index, and projected to whatever a reader wants. Nothing here knows about Cytoscape,
Mermaid or Graphviz; a rendering library is a consumer of Graph, never its shape.
Every graph is derived. None is authored: a node exists because a capability, an object or a projection exists, and an edge exists because one of them names another. A derivation that would need a file listing its own nodes belongs somewhere else.
use majordomus_cli::graph::{Builder, Node};
fn thing(id: &str) -> Node {
Node { id: id.into(), kind: "thing".into(), label: id.to_uppercase(), summary: None,
route: None, source: None, status: None, external: false, facts: Default::default() }
}
let mut builder = Builder::new("demo", "Demo", "Two things and the edge between them.", "example")
.node_kind("thing", "one of the things")
.edge_kind("names", "the source names the target");
builder.node(thing("a"));
builder.node(thing("b"));
builder.edge("a", "b", "names");
// an edge to something the derivation never added is dropped rather than dangling
builder.edge("a", "never-added", "names");
let graph = builder.finish();
assert_eq!(graph.nodes.len(), 2);
assert_eq!(graph.edges.len(), 1, "the dangling edge is gone");
assert!(graph.nodes.windows(2).all(|w| w[0].id <= w[1].id), "sorted, so two runs agree");Determinism is a contract: the same tree and the same executable produce the same bytes. Nodes and edges are sorted by their identities, never by discovery order, and no derivation reads a clock.
Structs§
- Builder
- A graph under construction. Adding an edge whose ends are not both present is refused
by
Builder::finish, not silently dropped: an edge to nothing is a derivation bug. - Edge
- One directed edge. Both ends are node ids of the same graph; a derivation that cannot resolve an end adds an external node rather than a dangling edge.
- Graph
- A derived graph: what it is, where it came from, what its vocabularies mean, and the nodes and edges themselves.
- Graph
Info - One graph the executable can derive: what it is, without deriving it.
- Graph
Metadata - What a reader needs to know about the graph as a whole before drawing it.
- Node
- One node.
idis unique within the graph;kindis what the graph’snode_kindsdeclares it to be;routeis where the Cockpit shows the thing itself, when it shows it anywhere. - Node
State - One node’s runtime state: what a process observed, never what a file declared.
- Observed
Graph - The second projection of a graph: the definitions a static build publishes, and beside them what a process observes about them now.
- Runtime
State - What is true of a node in a running process, and of nothing on a published page.
- Unresolved
- One reference that names something this repository does not hold.
Enums§
- Fact
- One fact a node carries from its object’s front matter, in the shapes a node can hold.
Constants§
- COMPOSED
- The id of the composed graph: the one derivation that joins every registry, and the one a generated artifact carries. Named here because the generator asks for it by id.
- MAX_
NODES - The most nodes a derivation emits. A graph past this is unreadable in a browser and unhelpful in a terminal; the derivation stops, says so in the metadata, and the page that shows it says so too.
Functions§
- capability_
page - The Cockpit route of a capability.
- composed_
complete - The composed graph whole, every object of the index in it: what the generated
docs/generated/graph.jsoncarries and what the development-context compiler selects from.MAX_NODESbounds a graph a person is shown; a reader of the graph as data — the site’s entity pages and catalogue counts, a context selection — would take a prefix for the repository and miss whatever sorted past it. - derive
- Derive one graph by id;
Nonewhen no such graph exists. - derive_
whole derive(), for a graph committed as data:Errwhen no such graph exists or when it stopped atMAX_NODES(whole).- ids
- The ids of every graph, in the order they are listed.
- is_
acyclic - Does the edge set form a directed acyclic graph? Kahn’s algorithm over the node set.
- list
- Every graph, described but not derived. Deriving all of them to list them would read the whole index for a menu.
- routes
- Where the Cockpit shows an object of the index, and where it shows a capability: the one place a route is built from an identity, so a page that moves moves once.
- unresolved_
relations - Every reference the layer declares that resolves to nothing this repository holds.
- whole
- A graph that is to be committed as data, refused if it is a prefix: a graph past
MAX_NODESis shown to a person truncated, but a projection written to the repository that silently stopped at the bound would drop whatever sorted past it from every reader.