pub struct GraphIndex { /* private fields */ }Expand description
An in-memory default graph with distinct facts and authored assertions.
use morphir_core::metadata::{Assertion, AssertionKey, Carrier, DocumentId,
Fact, GraphIndex, GraphName, ObjectTerm};
use morphir_core::node_address::NodeUri;
use serde_json::json;
let subject = NodeUri::parse(
"morphir://ir/pkg/acme/orders?format=4.0.0#/module/api/value/submit-order"
).unwrap();
let predicate = NodeUri::parse(
"morphir://ir/pkg/acme/metadata?format=4.0.0#/module/naming/value/aliases"
).unwrap();
let fact = Fact::new(subject.clone(), predicate, ObjectTerm::value(json!("placeOrder")),
GraphName::Default);
let owner = DocumentId::new("orders/spec.json").unwrap();
let key = AssertionKey::new(owner, Carrier::AttributesFacts(subject.clone()), fact).unwrap();
let mut graph = GraphIndex::new();
graph.insert(Assertion::new(key)).unwrap();
assert_eq!(graph.outgoing(&subject).len(), 1);Implementations§
Source§impl GraphIndex
impl GraphIndex
Sourcepub fn insert(&mut self, assertion: Assertion) -> Result<(), MetadataError>
pub fn insert(&mut self, assertion: Assertion) -> Result<(), MetadataError>
Insert one assertion, coalescing equal facts and repeated same-carrier assertions.
A duplicate key with mixed explicit and implicit source knowledge is
rejected because merging it could hide an unknown contributor. Named
graphs remain representable in Fact but are rejected here.
Sourcepub fn assertions(&self) -> &[Assertion]
pub fn assertions(&self) -> &[Assertion]
Distinct document-and-carrier assertions in first-insertion order.
Sourcepub fn try_map_node_uris<E>(
&self,
map: impl FnMut(&NodeUri) -> Result<NodeUri, E>,
) -> Result<Self, GraphMapError<E>>
pub fn try_map_node_uris<E>( &self, map: impl FnMut(&NodeUri) -> Result<NodeUri, E>, ) -> Result<Self, GraphMapError<E>>
Rebind every addressed term and carrier in one transaction. Source detail travels with its assertion, so a published selector cannot be left referring to the authoring identity. Literal data is never scanned for URI-looking strings.
Sourcepub fn apply_source_records(
&mut self,
owner: &DocumentId,
records: &[SourceRecord],
) -> Result<(), MetadataError>
pub fn apply_source_records( &mut self, owner: &DocumentId, records: &[SourceRecord], ) -> Result<(), MetadataError>
Apply one document’s optional detailed source table after all selectors validate.
Selectors use the already-expanded assertion identity. Any invalid row rejects the entire table without changing source ownership.
Sourcepub fn rewrite_assertion(
&mut self,
old: &AssertionKey,
replacement: Fact,
) -> Result<(), MetadataError>
pub fn rewrite_assertion( &mut self, old: &AssertionKey, replacement: Fact, ) -> Result<(), MetadataError>
Replace one authored fact and its selector in one graph update.
Existing explicit sources move with the assertion. A failed replacement leaves both the graph and its source table association untouched.
Sourcepub fn remove_source_from_owner(
&mut self,
owner: &DocumentId,
source: &AssertionSource,
) -> Result<usize, MetadataError>
pub fn remove_source_from_owner( &mut self, owner: &DocumentId, source: &AssertionSource, ) -> Result<usize, MetadataError>
Remove a known source’s contribution to one document’s assertions.
An assertion with only the implicit document source has unknown detailed ownership, so source-dependent removal fails before changing anything. Assertions without remaining sources are removed from the graph.
Sourcepub fn assertions_for_fact(&self, fact: &Fact) -> Vec<&Assertion>
pub fn assertions_for_fact(&self, fact: &Fact) -> Vec<&Assertion>
All document-and-carrier assertions for one expanded fact.
Sourcepub fn outgoing(&self, subject: &NodeUri) -> Vec<&Fact>
pub fn outgoing(&self, subject: &NodeUri) -> Vec<&Fact>
All distinct default-graph facts whose subject is this node.