Source code for cadrumo.domain.modelos.calculation_repository
"""Domain-side calculation-revision catalogue port surface.This module owns the pure calculation-revision catalogue vocabulary: the:class:`CalculationRevisionPersistenceError` raised at the storage boundary, the:func:`upsert_calculation_revision` pure mutator, and the namespace /schema-version constants that name the persisted envelope contract. The concreteencrypted SQL repository lives in the persistence adapter:class:`~cadrumo.adapters.persistence.profile.modelos_calculation.CalculationRevisionCatalogueRepository`,behind the read-side:class:`~CalculationRevisionCatalogueRepositoryProtocol`; thedomain package depends only on the structural port."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfrom.calculation_revisionimportCalculationRevision,CalculationRevisionCataloguefrom.errorsimportModeloErrorifTYPE_CHECKING:from.calculation_revision_aggregateimportCalculationRevisionAggregateContext
[docs]classCalculationRevisionPersistenceError(ModeloError):"""Raised when the calculation-revision catalogue cannot be persisted or loaded. This wraps storage-boundary failures from the persistence adapter's :class:`~cadrumo.adapters.persistence.profile.modelos_calculation.CalculationRevisionCatalogueRepository` while preserving translated recovery context for callers. """
[docs]defupsert_calculation_revision(catalogue:CalculationRevisionCatalogue,revision:CalculationRevision,*,aggregate_context:CalculationRevisionAggregateContext|None=None,)->CalculationRevisionCatalogue:"""Return a new :class:`CalculationRevisionCatalogue` with ``revision`` inserted or replaced. Args: catalogue: Source catalogue to update. revision: The :class:`CalculationRevision` to insert or replace. aggregate_context: Joined authorities required when ``revision`` is a context-bound rectificativa revision. """mapping=dict(catalogue.revisions)mapping[revision.calculation_revision_id]=revisionifaggregate_contextisNone:ifrevision.amendment_identityisnotNone:# An amendment is validated with the catalogue; refused here unless it needs no joined authority.returnCalculationRevisionCatalogue(revisions=mapping)# The carried revisions were validated, with their joined authorities,# when the catalogue was loaded; rebuilding it would re-run that# validation without them. Each stays keyed by its own id.returncatalogue.model_copy(update={"revisions":mapping})from.calculation_revision_aggregateimportCALCULATION_REVISION_AGGREGATE_CONTEXT_KEYreturnCalculationRevisionCatalogue.model_validate({"revisions":mapping},context={CALCULATION_REVISION_AGGREGATE_CONTEXT_KEY:aggregate_context},)