MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / lift_ref

Function lift_ref

atomic-canonical/src/lift.rs:353–387  ·  view source on GitHub ↗

Lift a `:::ref{to= edge=}` leaf into a typed reference edge. Both `to` and `edge` are required (a ref with no target or no edge type is a lift error), and `edge` must be a known *ref* edge: a dependency edge (`depends`/ `blockedBy`), review/remediation edge, or an evidence-bearing explicit implementation declaration. Edges like `verifiedBy`/`about` are rejected even though they are valid edges els

(d: &Directive)

Source from the content-addressed store, hash-verified

351/// implementation declaration. Edges like
352/// `verifiedBy`/`about` are rejected even though they are valid edges elsewhere.
353fn lift_ref(d: &Directive) -> Result<Ref> {
354 let to = d
355 .attr("to")
356 .ok_or_else(|| CanonicalError::Lift("':::ref' is missing required 'to'".into()))?
357 .to_string();
358 let edge = d
359 .attr("edge")
360 .ok_or_else(|| CanonicalError::Lift("':::ref' is missing required 'edge'".into()))?
361 .to_string();
362 if !vocab::is_known_ref_edge(&edge) {
363 return Err(CanonicalError::Lift(format!(
364 "':::ref' edge '{edge}' is not a valid ref edge (dependency {:?}, remediation {:?}, review {:?}, or implementation {:?})",
365 vocab::DEPENDENCY_EDGES,
366 vocab::REMEDIATION_EDGES,
367 vocab::REVIEW_EDGES,
368 vocab::IMPLEMENTATION_EDGES
369 )));
370 }
371 let declaration_evidence = d.attr("declarationEvidence").map(str::to_owned);
372 if edge == "declaresImplementation"
373 && (!vocab::is_canonical_change_iri(&to)
374 || declaration_evidence
375 .as_deref()
376 .is_none_or(|e| e.trim().is_empty()))
377 {
378 return Err(CanonicalError::Lift("implementation declarations require a canonical full-hash change IRI and nonempty declarationEvidence".into()));
379 }
380 Ok(Ref {
381 type_: d.id.as_ref().map(|_| NodeType::Ref.as_str().to_string()),
382 id: d.id.as_ref().map(|id| as_urn("ref", id)),
383 to,
384 edge,
385 declaration_evidence,
386 })
387}
388
389/// Wrap a local id into `urn:atomic:<kind>:<local>` unless already a urn.
390fn as_urn(kind: &str, local: &str) -> String {

Callers 1

lift_intentFunction · 0.85

Calls 7

is_known_ref_edgeFunction · 0.85
is_canonical_change_iriFunction · 0.85
as_urnFunction · 0.85
attrMethod · 0.80
as_refMethod · 0.80
is_emptyMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected