Source code for cadrumo.application.modelo.filing_repository
"""Explicit lifetime binding for Modelo filing-record persistence."""from__future__importannotationsfromcollections.abcimportGeneratorfromcontextlibimportcontextmanagerfromcontextvarsimportContextVarfromtypingimportProtocolfrom...core.errors.hierarchyimportInternalInvariantErrorfrom...domain.modelos.protocolsimportModeloRecordCatalogueRepositoryProtocol
[docs]classModeloRecordCatalogueRepositoryFactory(Protocol):"""Construct the filing-record repository port for one profile bucket."""def__call__(self,*,bucket_id:str)->ModeloRecordCatalogueRepositoryProtocol:"""Return the repository bound to ``bucket_id``."""...
[docs]@contextmanagerdefbind_modelo_record_catalogue_repository_factory(factory:ModeloRecordCatalogueRepositoryFactory,)->Generator[ModeloRecordCatalogueRepositoryFactory]:"""Bind one outward-composed filing-record repository factory."""token=_BOUND_MODELO_RECORD_CATALOGUE_REPOSITORY_FACTORY.set(factory)try:yieldfactoryfinally:_BOUND_MODELO_RECORD_CATALOGUE_REPOSITORY_FACTORY.reset(token)
[docs]defmodelo_record_catalogue_repository(*,bucket_id:str)->ModeloRecordCatalogueRepositoryProtocol:"""Resolve the explicitly composed filing repository for ``bucket_id``."""try:factory=_BOUND_MODELO_RECORD_CATALOGUE_REPOSITORY_FACTORY.get()exceptLookupErroraserror:raiseInternalInvariantError("modelo filing-record catalogue persistence has not been composed")fromerrorreturnfactory(bucket_id=bucket_id)