cadrumo.adapters.persistence.profile.modelos_filing module¶
Encrypted SQL repository for the modelo filing-record catalogue.
ModeloRecordCatalogueRepository persists and loads
ModeloRecord entries in a ModeloRecordCatalogue via
SecureObjectRepository at
FINANCIAL SensitivityClass
using an Envelope wrapper. The
catalogue is stored as a single encrypted BLOB per profile bucket.
This concrete repository is the persistence adapter behind the read-side
ModeloRecordCatalogueRepositoryProtocol. It lives
in the persistence adapter (not in modelos) because its
secure-object coupling is SQL/crypto-bound; the domain package owns only the
typed ModeloRecordCatalogue model and its pure mutators.
See also
adapters.persistence.profile._modelo_runtimeBucket-id resolution and runtime secure-object factory shared by modelo persistence adapters.
ModeloRecordCatalogueDomain catalogue payload encrypted by this repository.
ModeloRecordCatalogueRepositoryProtocolDomain port this concrete persistence adapter implements.
MODELO_FILING_RECORD_CATALOGUE_NAMESPACECentral namespace, sensitivity, schema-version, and singleton-key contract for these secure objects.
modelos_work_unitsSibling work-unit catalogue repository whose current/filed pointers reference filing records stored here.
file_modelo_revision()Application service that writes local/internal filing state through the modelo catalogue repositories.
- class ModeloRecordCatalogueRepository(*, bucket_id=None, objects=None)[source]¶
Bases:
objectRepository over encrypted SQL-backed filing-record catalogue storage.
MODELO_FILING_RECORD_CATALOGUE_NAMESPACEis the central namespace, schema-version, sensitivity, and singleton-key contract for the encryptedModeloRecordCataloguerow. The catalogue payload keeps member-scoped current/history lookups in the domain type. The write path (to_secure_object_write/save/exists) composesProfileEnvelopedModelSecurePersistencefor the shared Envelope-construction mechanic;loadstays hand-rolled here because this repository translates a classification or schema-version mismatch intoModeloRecordPersistenceErrorviaraise_catalogue_integrity_error(), a translation the shared kernel does not perform. This class exposes the concrete load/save implementation behindModeloRecordCatalogueRepositoryProtocol.- Parameters:
bucket_id (str | None)
objects (SecureObjectRepository | None)
- property bucket_id: str | None¶
Profile bucket this repository reads from and writes to.
A bucket is the per-profile partition that isolates one taxpayer’s encrypted records from another’s. Returns the resolved bucket identifier, or
Nonewhen the repository was constructed against an injectedSecureObjectRepositoryand no bucket id was supplied.
- exists()[source]¶
Report whether a persisted filing-record catalogue exists.
Returns
Truewhen an encrypted catalogue BLOB has already been written for this bucket,Falseotherwise. This is a presence check only; it neither decrypts nor validates the stored payload. Callloadto retrieve and verify the catalogue contents.- Return type:
- load()[source]¶
Load and decrypt the filing-record catalogue from storage.
A modelo is an AEAT tax form, and each filing record is the durable receipt that a calculation revision (a dated, immutable result for that form) was filed for a given form, year, and period. The whole catalogue is persisted as one encrypted FINANCIAL-class BLOB and returned as a
ModeloRecordCatalogue.Returns an empty catalogue when nothing has been persisted yet.
- Return type:
- Returns:
The decrypted
ModeloRecordCataloguefor this bucket.- Raises:
ModeloRecordPersistenceError – If the stored envelope fails its sensitivity-class or schema-version integrity checks, or if its on-disk classification is not FINANCIAL, or if it was written at a schema version newer than this consumer supports.
- save(catalogue)[source]¶
Persist the filing-record catalogue as a single encrypted BLOB.
Wraps
cataloguein aFINANCIAL-classEnvelopestamped with the current schema version and write timestamp, then writes it through the secure object store. The entire catalogue is rewritten as one encrypted object per bucket, replacing any prior catalogue for this bucket.- Parameters:
catalogue (
ModeloRecordCatalogue) – TheModeloRecordCatalogueto encrypt and store.- Return type:
- mutate(mutation)[source]¶
Apply
mutationto the stored catalogue as one revision-guarded unit of work.The catalogue is a SINGLETON row, so stamping one filing record rewrites every other. Performed unguarded, a record another caller wrote in the interim is discarded, and nothing reports it: the survivors are each intact and the missing one leaves no hole.
The bucket-ownership check runs on the mutation’s OWN result rather than once beforehand, so a mutation introducing a foreign record is refused on every attempt rather than only the first.
mutationis re-applied to the newly-current catalogue on a conflict, so it MUST be a pure function of what it is handed.- Return type:
- Parameters:
mutation (Callable[[ModeloRecordCatalogue], ModeloRecordCatalogue])
- load_revisioned()[source]¶
Return the filing catalogue and the revision id it was read at.
The read a guarded co-commit needs: a caller composing this catalogue into a batch cannot use the self-committing
mutate(), and without the revision its write puts the whole singleton row back over any filing record another writer added in between.- Return type:
- to_secure_object_write(catalogue, *, expected_revision_id=None)[source]¶
Return the secure-object upsert for
cataloguewithout committing it.The returned
SecureObjectWritecarries the sameEnvelopeandSensitivityClassclassification thatsave()would persist directly.Pass
expected_revision_idfromload_revisioned()whenever the catalogue was DERIVED from a read; omitting it rewrites the row unconditionally.- Return type:
- Parameters:
catalogue (ModeloRecordCatalogue)
expected_revision_id (str | None)
- save_with_secure_object_writes(catalogue, extra_writes, *, expected_revision_id=None)[source]¶
Persist
catalogueplus related secure objects in one unit of work.- Parameters:
catalogue (
ModeloRecordCatalogue) – TheModeloRecordCatalogueto persist.extra_writes (
tuple[SecureObjectWrite,...]) – AdditionalSecureObjectWriteobjects to commit atomically with the catalogue.expected_revision_id (
str|None) – The revisionload_revisioned()reported for the catalogue this one was derived from. Atomicity is what this method already gave; the revision is what stops the batch discarding a filing record another writer committed between the read and this call.
- Return type: