Source code for cadrumo.adapters.persistence.profile.translated_bucket_event_history
"""Bucket-event history exposed through an application-owned failure contract.Several declaration lifecycles commit their bucket events beside their ownrecords. Each binds the same encrypted history repository to the applicationport and differs only in which application error a storage failure becomes, sothe binding is written once and the translation is supplied by the caller."""from__future__importannotationsfromcollections.abcimportCallablefromtypingimportProtocol,overridefrom....core.secure_object_writeimportSecureObjectWritefrom....domain.buckets.eventimportBucketEventHistoryCataloguefrom....domain.buckets.protocolsimportBucketEventHistoryRepositoryProtocolfrom.bucketsimportBucketEventHistoryRepository
[docs]classAdapterFailureTranslator(Protocol):"""Run one adapter operation, re-raising storage failures as an application error."""def__call__[T](self,operation:str,action:Callable[[],T],/)->T:"""Return ``action()`` or raise the caller's application-contract error."""...
[docs]classTranslatedBucketEventHistoryRepository(BucketEventHistoryRepositoryProtocol):"""Translate bucket-event persistence to one application contract."""def__init__(self,*,repository:BucketEventHistoryRepository,translate:AdapterFailureTranslator)->None:"""Bind the encrypted history repository and the caller's failure translation."""self._repository=repositoryself._translate=translate
[docs]@overridedefexists(self)->bool:"""Report event-history presence without exposing storage failures."""returnself._translate("bucket_event_history_exists",self._repository.exists)
[docs]@overridedefload(self)->BucketEventHistoryCatalogue:"""Load event history through the application-facing port."""returnself._translate("bucket_event_history_load",self._repository.load)
[docs]defload_revisioned(self)->tuple[BucketEventHistoryCatalogue,str]:"""Load event history together with its optimistic-concurrency revision."""returnself._translate("bucket_event_history_load_revisioned",self._repository.load_revisioned)
[docs]@overridedefsave(self,catalogue:BucketEventHistoryCatalogue)->None:"""Persist event history while translating storage failures."""self._translate("bucket_event_history_save",lambda:self._repository.save(catalogue))
[docs]@overridedefto_secure_object_write(self,catalogue:BucketEventHistoryCatalogue,*,expected_revision_id:str|None=None,)->SecureObjectWrite:"""Prepare an event-history secure write for an atomic commit."""returnself._translate("bucket_event_history_prepare_write",lambda:self._repository.to_secure_object_write(catalogue,expected_revision_id=expected_revision_id,),)