Source code for cadrumo.application.state_projection_ports
"""Application-owned read contracts for the operator state projection.The projection producer needs a small, profile-scoped view of persistence. Itdoes not need to know which catalogue repositories or storage-runtimeinspection serve that view. This module owns the DTOs and the required portbundle that an outer composition root supplies for one profile session.Core types::class:`~cadrumo.domain.user_profile.values.UserProfileRecord`."""from__future__importannotationsfromdataclassesimportdataclassfromtypingimportProtocolfrom..core.errors.hierarchyimportCadrumoErrorfrom..domain.user_profile.valuesimportUserProfileRecordfrom.ledger.usage_ratio_repositoryimportUsageRatioProfileLoader
[docs]@dataclass(frozen=True,slots=True)classStateProjectionWorkspaceRead:"""Counters and integrity facts read from one profile workspace."""transactions:intinvoices:intdrafts:intwork_units:intdiscarded_work_units:intcalculation_revisions:intunreadable_rows:int
[docs]@dataclass(frozen=True,slots=True)classStateProjectionProfileRead:"""The profile bucket and current record used by readiness evaluation."""bucket_id:strrecord:UserProfileRecord
[docs]classStateProjectionWorkspaceReadPort(Protocol):"""Read the workspace counters for an explicitly selected bucket."""
[docs]defread_workspace(self,*,bucket_id:str)->StateProjectionWorkspaceRead:"""Return translated workspace facts for ``bucket_id``."""...
[docs]classStateProjectionProfileReadPort(Protocol):"""Read the current profile record for an active profile identifier."""
[docs]defread_profile(self,*,profile_id:str)->StateProjectionProfileRead|None:"""Return the selected profile facts, or no pointer when absent."""...
[docs]classStateProjectionReadError(CadrumoError):"""Stable application error raised when a projection read cannot complete."""def__init__(self,operation:str)->None:"""Create a read error identified by the failed projection operation."""self.operation=operationsuper().__init__(f"state projection {operation} read failed")
[docs]@dataclass(frozen=True,slots=True)classStateProjectionReadPorts:"""Required persistence reads for one operator state projection."""workspace:StateProjectionWorkspaceReadPortprofile:StateProjectionProfileReadPort#: The persisted usage-ratio read is carried alongside profile readiness#: because the ledger preflight is part of this same projection.usage_ratio_profile_loader:UsageRatioProfileLoader