Source code for cadrumo.application.ledger.import_ports
"""Application-owned capabilities for ledger source imports.The ledger import action coordinates source parsing and persistence, but itdoes not choose a provider implementation or know the secure-object namespaceused by the transaction catalogue. Those choices are supplied by an outercomposition root through the two capabilities in :class:`LedgerImportPorts`.The value records in this module are the small application boundary DTOs. Aninbound adapter may use richer parser records internally, but it must translatethem to these records before handing control to the application action."""from__future__importannotationsfromcollections.abcimportMappingfromdataclassesimportdataclassfrompathlibimportPathfromtypingimportProtocol,runtime_checkablefrom...domain.transactions.enumsimportTransactionDirectionfrom...domain.transactions.raw_transactionimportRawTransactionfrom.protocolsimportFinancialProviderProtocol
[docs]@dataclass(frozen=True,slots=True)classLedgerParsedRow:"""Application view of one parsed source row."""raw:RawTransactiondirection:TransactionDirection
[docs]@dataclass(frozen=True,slots=True)classLedgerProviderValidation:"""Application view of provider validation facts."""is_valid:boolwarnings:tuple[str,...]=()detected_encoding:str|None=Nonedetected_dialect:str|None=Noneunavailable_optional_extra:Mapping[str,str|bool]|None=None
[docs]@runtime_checkableclassLedgerProviderResolverProtocol(Protocol):"""Resolve one canonical provider ID to an application source port."""
[docs]defresolve(self,*,provider_id:str,path:Path)->FinancialProviderProtocol|None:"""Return a source provider, or ``None`` when detection declines it. Implementations translate all provider-specific parser errors to the application transaction-validation error before they cross this port. """...
[docs]@runtime_checkableclassTransactionCatalogueLocationProtocol(Protocol):"""Render the application-facing location of a persisted catalogue."""
[docs]defpath_for(self,*,bucket_id:str)->str:"""Return the stable display/reference path for one bucket catalogue."""...
[docs]@dataclass(frozen=True,slots=True)classLedgerImportPorts:"""Required source and catalogue-location capabilities for ledger import."""provider_resolver:LedgerProviderResolverProtocolcatalogue_location:TransactionCatalogueLocationProtocol