cadrumo.domain.attachments.service module¶
Service-layer helpers over AttachmentStoreProtocol.
Thin orchestration on top of AttachmentStoreProtocol primitives:
ingest a file from disk, build the corresponding Attachment
manifest, persist it, and expose simple read paths for callers that
do not need the full repository API.
- class AttachmentIngestionRequest(**data)[source]¶
Bases:
BaseModelTyped manifest facts for one attachment capture.
- Parameters:
data (Any)
- kind: AttachmentKind¶
- source: AttachmentSource¶
- source_reference: str¶
- mime_type: str¶
- captured_at: UtcInstant¶
- bucket_id: BucketId | None¶
- captured_by: str | None¶
- source_command: str | None¶
- link_transaction_ids: tuple[str, ...]¶
- link_invoice_ids: tuple[str, ...]¶
- metadata: Mapping[str, str]¶
- notes: str¶
- class AttachmentFileContent(**data)[source]¶
Bases:
BaseModelOne local file supplied to the attachment custody service.
- Parameters:
data (Any)
- path: Path¶
- class AttachmentBytesContent(**data)[source]¶
Bases:
BaseModelOne already-fetched byte payload supplied to the custody service.
- Parameters:
data (bytes)
- data: bytes¶
- add_attachment(store, *, content, request)[source]¶
Store one typed file or byte payload and persist its attachment manifest.
- Return type:
- Parameters:
store (AttachmentStoreProtocol)
content (AttachmentFileContent | AttachmentBytesContent)
request (AttachmentIngestionRequest)
- link_attachment_invoice(store, *, attachment_id, invoice_id)[source]¶
Append
invoice_idto an already-persisted attachment’slinked_invoice_ids.Closes the provenance loop the other direction from
add_attachment’slink_invoice_idsparameter: that parameter can only be populated for an invoice that already exists before the evidence is captured, but the evidence-confirmation flow mints theInvoiceafter the attachment is already stored. This helper re-persists the same manifest (attachment id and bytes unchanged) through the sameAttachmentStoreProtocol.write_manifest()write path (aeat-architecture-boundaries), withinvoice_idappended.Idempotent by construction:
Attachment’slinked_invoice_idsvalidator deduplicates and preserves first-seen order, so calling this twice with the sameinvoice_idis a no-op – the manifest’s byte content after the second call is identical to after the first (a real re-confirm safely re-links without growing the tuple).- Parameters:
store (
AttachmentStoreProtocol) – BackingAttachmentStoreProtocol.attachment_id (
str) – SHA-256 of the attachment bytes to update.invoice_id (
str) – StableInvoiceidentifier to record as evidenced by this attachment.
- Return type:
- Returns:
The re-persisted
Attachmentmanifest carryinginvoice_idinAttachment.linked_invoice_ids.
- link_attachment_transaction(store, *, attachment_id, transaction_id)[source]¶
Append
transaction_idto a persisted attachment’slinked_transaction_ids.The transaction-side twin of
link_attachment_invoice(), and for the same reason:add_attachment’slink_transaction_idsparameter can only be populated for a transaction that already exists before the evidence is captured, but the ledger evidence flow attaches an already-stored attachment to an existing transaction. Without this the link was recorded on the transaction only, soiter_manifests()filtered bylinked_to=<transaction_id>could not discover an attachment the transaction itself cites – even though the manifest models the link and the surrounding workflow documents the provenance as bidirectional.Re-persists the same manifest (attachment id and bytes unchanged) through the same
AttachmentStoreProtocol.write_manifest()write path (aeat-architecture-boundaries).Idempotent by construction:
Attachment’slinked_transaction_idsvalidator deduplicates and preserves first-seen order, so a repeated attach is a no-op rather than a growing tuple.- Parameters:
store (
AttachmentStoreProtocol) – BackingAttachmentStoreProtocol.attachment_id (
str) – SHA-256 of the attachment bytes to update.transaction_id (
str) – Stable ledger transaction identifier to record as supported by this attachment.
- Return type:
- Returns:
The re-persisted
Attachmentmanifest carryingtransaction_idinAttachment.linked_transaction_ids.