53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
"""Minimal Graph-of-Contracts registry for MercuryMesh MVP.
|
|
|
|
This module provides a tiny, in-process registry to model contract mappings
|
|
and adapter schemas without exposing raw data. It is intentionally small and
|
|
extensible, suitable for MVP wiring as you add two starter adapters.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, asdict
|
|
from typing import Dict, Optional, List, Any
|
|
|
|
|
|
@dataclass
|
|
class ContractSpec:
|
|
"""Specification for a contract primitive in MercuryMesh.
|
|
|
|
- name: canonical contract name (e.g., "MarketState", "Delta")
|
|
- version: contract version string
|
|
- schema: optional metadata describing the contract's data shape
|
|
"""
|
|
|
|
name: str
|
|
version: str
|
|
schema: Dict[str, Any] | None = None
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
return asdict(self)
|
|
|
|
|
|
class GraphOfContractsRegistry:
|
|
"""A lightweight in-process registry for contract specs and adapter schemas."""
|
|
|
|
def __init__(self) -> None:
|
|
self._registry: Dict[str, ContractSpec] = {}
|
|
|
|
def register_contract(self, spec: ContractSpec) -> None:
|
|
"""Register or update a contract spec by its name as the key."""
|
|
self._registry[spec.name] = spec
|
|
|
|
def get_contract(self, name: str) -> Optional[ContractSpec]:
|
|
return self._registry.get(name)
|
|
|
|
def list_contracts(self) -> List[str]:
|
|
return sorted(self._registry.keys())
|
|
|
|
def to_dict(self) -> Dict[str, Dict[str, Any]]:
|
|
return {name: spec.to_dict() for name, spec in self._registry.items()}
|
|
|
|
|
|
# Public, module-level registry instance for quick usage patterns in MVP wiring
|
|
registry = GraphOfContractsRegistry()
|