Source code for cadrumo.application.ledger.protocols
"""Application-layer port protocols for the ledger service.Defines structural :class:`typing.Protocol` interfaces consumed by:mod:`cadrumo.application.ledger.actions_import` so that the application layerdepends only on these protocol types, not on concrete adapter classes."""from__future__importannotationsfromcollections.abcimportIterator,MappingfrompathlibimportPathfromtypingimportProtocol,runtime_checkablefrom...core.secure_object_writeimportSecureObjectWritefrom...domain.buckets.eventimportBucketEventHistoryCataloguefrom...domain.buckets.protocolsimportBucketEventHistoryRepositoryProtocolfrom...domain.invoices.modelsimportInvoiceCataloguefrom...domain.invoices.protocolsimportInvoiceCatalogueRepositoryProtocolfrom...domain.transactions.enumsimportTransactionDirectionfrom...domain.transactions.modelsimportTransactionCataloguefrom...domain.transactions.protocolsimportTransactionCatalogueRepositoryProtocolfrom...domain.transactions.raw_transactionimportRawTransaction
[docs]@runtime_checkableclassParsedLedgerRowProtocol(Protocol):"""Structural view of one parsed financial source row."""@propertydefraw(self)->RawTransaction:"""Return the domain raw transaction carried by this row."""...@propertydefdirection(self)->TransactionDirection:"""Return the authoritative flow direction for this row."""...
[docs]@runtime_checkableclassProviderValidationProtocol(Protocol):"""Structural validation result returned by a financial source port."""@propertydefis_valid(self)->bool:"""Whether the source can be ingested."""...@propertydefwarnings(self)->tuple[str,...]:"""Warnings produced while validating the source."""...@propertydefdetected_encoding(self)->str|None:"""Detected source encoding, when the provider reports one."""...@propertydefdetected_dialect(self)->str|None:"""Detected source dialect or layout, when available."""...@propertydefunavailable_optional_extra(self)->Mapping[str,str|bool]|None:"""Optional-extra facts when the provider cannot run locally."""...
[docs]@runtime_checkableclassFinancialProviderProtocol(Protocol):"""Protocol satisfied by any file-backed raw transaction provider. Covers exactly the two methods called by the ledger import service: :meth:`ingest` and :meth:`validate_source`. Adapter-internal helpers (``build_provenance``, ``_read_source_bytes``, etc.) remain private to the adapter implementation. """
[docs]defingest(self,path:Path)->Iterator[ParsedLedgerRowProtocol]:"""Yield parsed ledger rows from ``path``. Each yielded item carries a magnitude :class:`RawTransaction` plus its :class:`TransactionDirection`, parsed from the provider-format file. """...
[docs]defvalidate_source(self,path:Path)->ProviderValidationProtocol:"""Validate ``path`` and return a structured validation result."""...
[docs]classTransactionCatalogueCoCommitWriterProtocol(TransactionCatalogueRepositoryProtocol,Protocol):"""Transaction-catalogue port for an atomic multi-object ledger write."""
[docs]defsave_with_secure_object_writes(self,catalogue:TransactionCatalogue,extra_writes:tuple[SecureObjectWrite,...],)->None:"""Persist the catalogue and related secure objects atomically. Core types: :class:`~cadrumo.domain.transactions.models.TransactionCatalogue`. """...
[docs]classInvoiceCatalogueCoCommitWriterProtocol(InvoiceCatalogueRepositoryProtocol,Protocol):"""Invoice-catalogue port for an atomic ledger co-commit."""
[docs]defload_revisioned(self)->tuple[InvoiceCatalogue,str]:"""Load the catalogue with the secure-object revision observed."""...
[docs]defto_secure_object_write(self,catalogue:InvoiceCatalogue,*,expected_revision_id:str|None=None,)->SecureObjectWrite:"""Build the invoice secure-object write without committing it. Core types: :class:`~cadrumo.domain.invoices.models.InvoiceCatalogue`. """...
[docs]classBucketEventHistoryCoCommitWriterProtocol(BucketEventHistoryRepositoryProtocol,Protocol):"""Bucket-event port for a revision-guarded ledger co-commit."""
[docs]defload_revisioned(self)->tuple[BucketEventHistoryCatalogue,str]:"""Load event history with the secure-object revision observed."""...