signalvault-verifiable-priv.../signalvault_verifiable_priv.../registry.py

27 lines
919 B
Python

from __future__ import annotations
from typing import Dict, Optional
from .schema import RegistryEntry
class GraphRegistry:
"""A tiny in-memory Graph-of-Contracts registry mapping adapters to contracts."""
def __init__(self) -> None:
self._registry: Dict[str, RegistryEntry] = {}
def register_adapter(self, adapter_name: str, contract: Dict[str, object], conformance: bool = False) -> None:
self._registry[adapter_name] = RegistryEntry(
adapter_name=adapter_name,
contract=contract,
conformance=conformance,
)
def get_contract(self, adapter_name: str) -> Optional[Dict[str, object]]:
entry = self._registry.get(adapter_name)
return entry.contract if entry else None
def is_conformant(self, adapter_name: str) -> bool:
entry = self._registry.get(adapter_name)
return bool(entry and entry.conformance)