"""Encrypted SQL repository for the modelo work-unit catalogue.:class:`~adapters.persistence.profile.modelos_work_units.WorkUnitCatalogueRepository` persists:class:`WorkUnit` records in a :class:`WorkUnitCatalogue` at``FINANCIAL`` :class:`~cadrumo.core.classification.policies.SensitivityClass`through:class:`~cadrumo.adapters.persistence.storage.sql.secure_objects.SecureObjectRepository`. Thecatalogue is serialised as a single:class:`~cadrumo.adapters.persistence.storage.Envelope`-wrapped JSON payload keyedby a stable namespace and object key; the underlying column is encrypted so noplaintext work-unit metadata lands on disk.The storage contract is declared by:data:`cadrumo.adapters.persistence.storage.secure_object_namespaces.MODELO_WORK_UNIT_CATALOGUE_NAMESPACE`;its default object key is the singleton ``catalogue`` row."""from__future__importannotationsfrom.errorsimportModeloErrorfrom.work_unitimportWorkUnit,WorkUnitCatalogue
[docs]classWorkUnitPersistenceError(ModeloError):"""Raised when the work-unit catalogue cannot be loaded or saved. This wraps storage-boundary failures from :class:`~adapters.persistence.profile.modelos_work_units.WorkUnitCatalogueRepository` while preserving translated recovery context for callers. """
[docs]defupsert_work_unit(catalogue:WorkUnitCatalogue,unit:WorkUnit)->WorkUnitCatalogue:"""Return a new :class:`WorkUnitCatalogue` with ``unit`` inserted or replaced. The input catalogue is not mutated. The returned catalogue carries the same work units as the input plus ``unit`` at its deterministic ``work_unit_id``; any existing entry under that id is replaced. """mapping=dict(catalogue.work_units)mapping[unit.work_unit_id]=unitreturnWorkUnitCatalogue(work_units=mapping)