33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import Dict, Optional
|
|
|
|
from .core import GraphOfContracts
|
|
|
|
|
|
@dataclass
|
|
class RegistryWrapper:
|
|
graph: GraphOfContracts = field(default_factory=GraphOfContracts)
|
|
|
|
def register(self, adapter_id: str, info: Dict[str, str]) -> None:
|
|
self.graph.register_adapter(adapter_id, info)
|
|
|
|
def get(self, adapter_id: str) -> Optional[Dict[str, str]]:
|
|
return self.graph.get_info(adapter_id)
|
|
|
|
def conforms(self, adapter_id: str, required_keys: Optional[list] = None) -> bool:
|
|
"""Check whether a registered adapter advert contains the required keys.
|
|
|
|
This is a lightweight conformance helper used by registries and tests to
|
|
ensure adapters expose the minimal advertised metadata. It does not
|
|
validate types beyond presence.
|
|
"""
|
|
info = self.get(adapter_id)
|
|
if info is None:
|
|
return False
|
|
if not required_keys:
|
|
# If no keys specified, consider presence in registry as conformance
|
|
return True
|
|
return all(k in info for k in required_keys)
|