Source code for cadrumo.application.ledger.participation_read
"""Read action: surface the modelo participations of one ledger transaction.The inverse of the forward ``source_transaction_ids`` link. Loads theper-transaction :class:`TransactionRevisionParticipationIndex` from encryptedstorage and returns it for the CLI surface to project into a typed payload. Theindex records only finalized-revision participations (borrador inclusion isdeferred), so the read is the audit-trail answer to "where was this transactiondeclared"."""from__future__importannotationsfromcollections.abcimportGeneratorfromcontextlibimportcontextmanagerfromcontextvarsimportContextVarfromtypingimportProtocolfrom...core.errors.hierarchyimportInternalInvariantErrorfrom...domain.modelos.participation_indeximportTransactionRevisionParticipationIndexfrom...domain.modelos.protocolsimportTransactionParticipationIndexRepositoryProtocol
[docs]classTransactionParticipationIndexRepositoryFactory(Protocol):"""Construct the participation-index repository port for one bucket."""def__call__(self,*,bucket_id:str|None=None,)->TransactionParticipationIndexRepositoryProtocol:"""Return the repository resolved for ``bucket_id``."""...
[docs]@contextmanagerdefbind_transaction_participation_index_repository_factory(factory:TransactionParticipationIndexRepositoryFactory,)->Generator[TransactionParticipationIndexRepositoryFactory]:"""Bind one outward-composed participation-index repository factory."""token=_BOUND_TRANSACTION_PARTICIPATION_INDEX_REPOSITORY_FACTORY.set(factory)try:yieldfactoryfinally:_BOUND_TRANSACTION_PARTICIPATION_INDEX_REPOSITORY_FACTORY.reset(token)
[docs]deftransaction_participation_index_repository(*,bucket_id:str|None=None,)->TransactionParticipationIndexRepositoryProtocol:"""Resolve the explicitly composed participation repository."""try:factory=_BOUND_TRANSACTION_PARTICIPATION_INDEX_REPOSITORY_FACTORY.get()exceptLookupErroraserror:raiseInternalInvariantError("transaction participation-index persistence has not been composed")fromerrorreturnfactory(bucket_id=bucket_id)
[docs]defget_transaction_participation(*,transaction_id:str,bucket_id:str|None=None,participation_index_repository:TransactionParticipationIndexRepositoryProtocol|None=None,)->TransactionRevisionParticipationIndex:"""Return the finalized-revision participation index for one ledger transaction. Returns an empty :class:`TransactionRevisionParticipationIndex` (no participations) when the transaction has never contributed to a finalized revision, rather than raising — an auditable "no declarations" answer. Args: transaction_id: The ledger transaction id to look up. bucket_id: Optional explicit profile bucket; resolves the active bucket when omitted. participation_index_repository: Optional repository override (tests). """repository=(participation_index_repositoryifparticipation_index_repositoryisnotNoneelsetransaction_participation_index_repository(bucket_id=bucket_id))returnrepository.load(transaction_id)