Source code for cadrumo.application.bucket_event_repository
"""Explicit lifetime binding for bucket event-history persistence."""from__future__importannotationsfromcollections.abcimportGeneratorfromcontextlibimportcontextmanagerfromcontextvarsimportContextVarfromtypingimportProtocolfrom..core.errors.hierarchyimportInternalInvariantErrorfrom..domain.buckets.protocolsimportBucketEventHistoryRepositoryProtocol
[docs]classBucketEventHistoryRepositoryFactory(Protocol):"""Construct the event-history repository port for one profile bucket."""def__call__(self,*,bucket_id:str)->BucketEventHistoryRepositoryProtocol:"""Return the repository bound to ``bucket_id``."""...
[docs]@contextmanagerdefbind_bucket_event_history_repository_factory(factory:BucketEventHistoryRepositoryFactory,)->Generator[BucketEventHistoryRepositoryFactory]:"""Bind one outward-composed bucket event-history repository factory."""token=_BOUND_BUCKET_EVENT_HISTORY_REPOSITORY_FACTORY.set(factory)try:yieldfactoryfinally:_BOUND_BUCKET_EVENT_HISTORY_REPOSITORY_FACTORY.reset(token)
[docs]defbucket_event_history_repository(*,bucket_id:str)->BucketEventHistoryRepositoryProtocol:"""Resolve the explicitly composed event-history repository for ``bucket_id``."""try:factory=_BOUND_BUCKET_EVENT_HISTORY_REPOSITORY_FACTORY.get()exceptLookupErroraserror:raiseInternalInvariantError("bucket event-history persistence has not been composed")fromerrorreturnfactory(bucket_id=bucket_id)