Source code for cadrumo.application.ledger.transaction_repository
"""Explicit lifetime binding for ledger transaction catalogue persistence."""from__future__importannotationsfromcollections.abcimportGeneratorfromcontextlibimportcontextmanagerfromcontextvarsimportContextVarfromtypingimportProtocolfrom...core.errors.hierarchyimportInternalInvariantErrorfrom...domain.transactions.protocolsimportTransactionCatalogueRepositoryProtocol
[docs]classTransactionCatalogueRepositoryFactory(Protocol):"""Construct the transaction repository port for one profile bucket."""def__call__(self,*,bucket_id:str)->TransactionCatalogueRepositoryProtocol:"""Return the repository bound to ``bucket_id``."""...
[docs]@contextmanagerdefbind_transaction_catalogue_repository_factory(factory:TransactionCatalogueRepositoryFactory,)->Generator[TransactionCatalogueRepositoryFactory]:"""Bind one outward-composed transaction repository factory."""token=_BOUND_TRANSACTION_CATALOGUE_REPOSITORY_FACTORY.set(factory)try:yieldfactoryfinally:_BOUND_TRANSACTION_CATALOGUE_REPOSITORY_FACTORY.reset(token)
[docs]deftransaction_catalogue_repository(*,bucket_id:str)->TransactionCatalogueRepositoryProtocol:"""Resolve the explicitly composed transaction repository for ``bucket_id``."""try:factory=_BOUND_TRANSACTION_CATALOGUE_REPOSITORY_FACTORY.get()exceptLookupErroraserror:raiseInternalInvariantError("transaction catalogue persistence has not been composed")fromerrorreturnfactory(bucket_id=bucket_id)