pub fn edges(
registry: &CapabilityRegistry,
objects: &[Object],
subject: &Object,
) -> Vec<Edge>Expand description
Every edge of one object: the references it declares, and the references that resolve to it.
Both directions come from one table — graph::RELATIONS — so a relation added there
appears as a forward edge on one page and as a backlink on the other, with nothing
declared twice and no bidirectional bookkeeping in the layer. A reference that resolves
to nothing is not an edge; it is a finding, and
graph::unresolved_relations is what reports it.
A rule that depends on another produces one edge on each of the two pages, from the one
depends_on the first of them declared:
use majordomus_cli::capability::builtin;
use majordomus_cli::capability::registry::CapabilityRegistry;
use majordomus_cli::entity::{edges, Direction};
let registry = CapabilityRegistry::builder()
.with_builtin(builtin::all())
.build()
.unwrap();
let dependant = rule("project.a@1", serde_json::json!({ "depends_on": ["project.b@1"] }));
let dependency = rule("project.b@1", serde_json::json!({}));
let objects = vec![dependant.clone(), dependency.clone()];
// the declaring end sees it run outwards
let out = edges(®istry, &objects, &dependant);
assert!(out.iter().any(|e| e.direction == Direction::Outgoing
&& e.edge == "depends_on"
&& e.label == "project.b@1"));
// the named end sees the same relation as a backlink, declared nowhere
let back = edges(®istry, &objects, &dependency);
assert!(back.iter().any(|e| e.direction == Direction::Incoming
&& e.edge == "depends_on"
&& e.label == "project.a@1"));