generated from coulomb/repo-seed
refactoring for canon conformity
This commit is contained in:
@@ -8,6 +8,7 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from .loader import load_declarations
|
||||
from .canon import edge_canon_mapping, node_canon_mapping
|
||||
from .model import Declaration
|
||||
|
||||
|
||||
@@ -186,6 +187,7 @@ class FabricGraph:
|
||||
edges: list[dict[str, str]] = []
|
||||
|
||||
for declaration in sorted(self.declarations, key=lambda item: (item.kind, item.id)):
|
||||
canon_mapping = node_canon_mapping(declaration.kind)
|
||||
nodes.append(
|
||||
{
|
||||
"id": declaration.id,
|
||||
@@ -194,35 +196,39 @@ class FabricGraph:
|
||||
"repo": declaration.metadata.get("repo", ""),
|
||||
"domain": declaration.metadata.get("domain", ""),
|
||||
"lifecycle": declaration.spec.get("lifecycle", ""),
|
||||
"canon_category": canon_mapping.category,
|
||||
"canon_anchor": canon_mapping.canon_anchor,
|
||||
"mapping_fit": canon_mapping.fit,
|
||||
"evidence_state": "declared",
|
||||
"attributes": _export_attributes(declaration),
|
||||
}
|
||||
)
|
||||
|
||||
for service in self.services.values():
|
||||
for capability_id in service.spec.get("provides_capabilities", []):
|
||||
edges.append({"from": service.id, "to": capability_id, "type": "provides"})
|
||||
edges.append(_export_edge(service.id, capability_id, "provides"))
|
||||
for interface_id in service.spec.get("exposes_interfaces", []):
|
||||
edges.append({"from": service.id, "to": interface_id, "type": "exposes"})
|
||||
edges.append(_export_edge(service.id, interface_id, "exposes"))
|
||||
|
||||
for capability in self.capabilities.values():
|
||||
for interface_id in capability.spec.get("interface_ids", []):
|
||||
edges.append({"from": capability.id, "to": interface_id, "type": "available_via"})
|
||||
edges.append(_export_edge(capability.id, interface_id, "available_via"))
|
||||
|
||||
for dependency in self.dependencies.values():
|
||||
consumer = str(dependency.spec.get("consumer_service_id", ""))
|
||||
if consumer:
|
||||
edges.append({"from": consumer, "to": dependency.id, "type": "consumes"})
|
||||
edges.append(_export_edge(consumer, dependency.id, "consumes"))
|
||||
for binding in self.bindings_by_dependency.get(dependency.id, []):
|
||||
edges.append(
|
||||
{
|
||||
"from": dependency.id,
|
||||
"to": str(binding.spec.get("provider_capability_id", "")),
|
||||
"type": f"binds:{binding.spec.get('status', '')}",
|
||||
}
|
||||
_export_edge(
|
||||
dependency.id,
|
||||
str(binding.spec.get("provider_capability_id", "")),
|
||||
f"binds:{binding.spec.get('status', '')}",
|
||||
)
|
||||
)
|
||||
interface_id = str(binding.spec.get("provider_interface_id", ""))
|
||||
if interface_id:
|
||||
edges.append({"from": dependency.id, "to": interface_id, "type": "uses_interface"})
|
||||
edges.append(_export_edge(dependency.id, interface_id, "uses_interface"))
|
||||
|
||||
return {
|
||||
"apiVersion": "railiance.fabric/v1alpha1",
|
||||
@@ -265,6 +271,20 @@ def _escape_mermaid(value: str) -> str:
|
||||
return value.replace('"', '\\"')
|
||||
|
||||
|
||||
def _export_edge(source: str, target: str, edge_type: str) -> dict[str, Any]:
|
||||
canon_mapping = edge_canon_mapping(edge_type)
|
||||
return {
|
||||
"from": source,
|
||||
"to": target,
|
||||
"type": edge_type,
|
||||
"canonical_type": canon_mapping.canonical_type,
|
||||
"canon_anchor": canon_mapping.canon_anchor,
|
||||
"mapping_fit": canon_mapping.fit,
|
||||
"display_only": canon_mapping.display_only,
|
||||
"evidence_state": "declared",
|
||||
}
|
||||
|
||||
|
||||
def _export_attributes(declaration: Declaration) -> dict[str, Any]:
|
||||
spec = declaration.spec
|
||||
base = _base_export_attributes(declaration)
|
||||
|
||||
Reference in New Issue
Block a user