cadrumo.adapters.persistence.profile.modelos_work_units module¶
Encrypted SQL repository for the modelo work-unit catalogue.
WorkUnitCatalogueRepository persists WorkUnit records in a
WorkUnitCatalogue at FINANCIAL
SensitivityClass through
SecureObjectRepository. The
catalogue is serialised as a single
Envelope-wrapped JSON payload keyed
by a stable namespace and object key; the underlying column is encrypted so no
plaintext work-unit metadata lands on disk.
This concrete repository is the persistence adapter behind the read-side
WorkUnitCatalogueRepositoryProtocol. 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 WorkUnitCatalogue model and its pure catalogue mutators.
See also
adapters.persistence.profile._modelo_runtimeBucket-id resolution and runtime secure-object factory shared by modelo persistence adapters.
WorkUnitCatalogueDomain catalogue payload encrypted by this repository.
WorkUnitCatalogueRepositoryProtocolDomain port this concrete persistence adapter implements.
MODELO_WORK_UNIT_CATALOGUE_NAMESPACECentral namespace, sensitivity, schema-version, and singleton-key contract for these secure objects.
modelos_calculationSibling calculation-revision repository referenced by work-unit current and verification lifecycle state.
modeloApplication facade that creates, calculates, verifies, files, and exports work units from this catalogue.
- class WorkUnitCatalogueRepository(*, bucket_id=None, objects=None)[source]¶
Bases:
objectRepository over encrypted SQL-backed work-unit catalogue storage.
A single envelope-wrapped catalogue object holds every work unit. Loads return an empty catalogue when no object has been persisted yet (no separate “fresh install” path is needed). The write path (
to_secure_object_write/save/exists) composesProfileEnvelopedModelSecurePersistencefor the shared one-record decode and Envelope-construction mechanics;load_revisioned()translates a classification or schema-version mismatch intoWorkUnitPersistenceErrorviaraise_catalogue_integrity_error(). This class is the concrete implementation behindWorkUnitCatalogueRepositoryProtocol.- Parameters:
bucket_id (str | None)
objects (SecureObjectRepository | None)
- load()[source]¶
Return the persisted catalogue or an empty catalogue if absent.
- Return type:
- Returns:
The deserialised
WorkUnitCatalogue, or an empty instance when no object has been persisted yet.- Raises:
WorkUnitPersistenceError – When the persisted envelope’s classification or schema version disagrees with the consumer’s contract.
- save(catalogue)[source]¶
Persist
catalogueas the encrypted singleton object.The on-disk database value is an encrypted
EnvelopeBLOB at theSensitivityClassFINANCIALclassification.- Parameters:
catalogue (
WorkUnitCatalogue) – TheWorkUnitCatalogueto persist.- Return type:
- mutate(mutation)[source]¶
Apply
mutationto the stored catalogue as one revision-guarded unit of work.The catalogue is a SINGLETON row, so touching one work unit rewrites all of them. Performed unguarded, a work unit created or advanced by a concurrent caller is discarded by whichever write lands second, and nothing reports it: the surviving entries are individually intact and the missing one leaves no hole.
mutationis re-applied to the newly-current catalogue on a conflict, so it MUST be a pure function of the catalogue it is handed – a decision closed over from an earlier read would be replayed against a catalogue it was never true of.- Return type:
- Parameters:
mutation (Callable[[WorkUnitCatalogue], WorkUnitCatalogue])
- to_secure_object_write(catalogue, *, expected_revision_id=None)[source]¶
Return the secure-object upsert for
cataloguewithout committing it.Lets a caller advance the work-unit pointer in the SAME unit of work as the calculation, filing, and event catalogues the pointer names, so a failure cannot leave an advanced pointer standing over state that never committed. The returned
SecureObjectWritecarries the sameEnvelopeandSensitivityClassclassificationsave()would persist directly.- Return type:
- Parameters:
catalogue (WorkUnitCatalogue)
expected_revision_id (str | None)
- load_revisioned()[source]¶
Return the catalogue and the revision id it was read at.
The read a guarded co-commit needs. A lifecycle transition composes this catalogue with the event that records it, so it cannot use the self-committing
mutate(), and without the revision its batch rewrites the whole singleton row over a unit another caller created.- Return type:
- save_with_secure_object_writes(catalogue, extra_writes, *, expected_revision_id=None)[source]¶
Persist
catalogueplus related secure objects in one unit of work.The catalogue save and every extra write land or fail together in a single SQL transaction. A work-unit lifecycle transition that saved the catalogue and emitted its bucket event afterwards could come to rest durable-but-unrecorded: the created, renamed, or discarded unit survived while the history had no matching entry and no marker named the gap. Folding the event’s write in here puts the state and its promised event in one transaction, so neither can land without the other.
- Parameters:
catalogue (
WorkUnitCatalogue) – TheWorkUnitCatalogueto 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 the batch already gave; the revision is what stops it writing the whole singleton row back over a work unit another caller created between the read and this call.
- Return type: