Source code for cadrumo.domain.calculations.registry.handoffs
"""Declared consumption channels for cross-model relation-prefill handoffs.A handoff is a coordinate in the registry: the source and target:class:`ModeloRevision` a value crosses between, resolved against the:class:`RegistrySnapshot` the authority compiled. This module names the closedset of channels through which a folded value reaches the casilla that consumesit, so "which model feeds which, and how" is a declared fact rather than onere-derived per caller."""from__future__importannotationsfromenumimportStrEnumfromtypingimportLiteral,NamedTuplefrom.idsimportBindingIdfrom.runtime_graphimportexpression_binding_refsfrom.schemaimportModeloRevision__all__=["RelationConsumptionChannel","RelationConsumptionChannelKind","relation_consumption_channels","relation_consumption_index",]
[docs]classRelationConsumptionChannelKind(StrEnum):"""How a relation-prefill binding's value reaches the target that consumes it."""PRIMARY_BINDING="primary_binding"ALTERNATE_BINDING="alternate_binding"FORMULA_BINDING="formula_binding"
RelationConsumptionChannel=Literal[RelationConsumptionChannelKind.PRIMARY_BINDING,RelationConsumptionChannelKind.ALTERNATE_BINDING,RelationConsumptionChannelKind.FORMULA_BINDING,]"""Canonical closed channels through which a folded value feeds a casilla."""class_RelationConsumptionIndex(NamedTuple):primary_bindings:frozenset[BindingId]alternate_bindings:frozenset[BindingId]formula_bindings:frozenset[BindingId]
[docs]defrelation_consumption_index(revision:ModeloRevision)->_RelationConsumptionIndex:"""Return the binding channels that consume relation-prefill values. Core types: :class:`~cadrumo.domain.calculations.registry.schema.ModeloRevision`. """primary_bindings:set[BindingId]=set()alternate_bindings:set[BindingId]=set()forcasillainrevision.casillas:ifcasilla.bindingisnotNone:primary_bindings.add(casilla.binding)alternate_bindings.update(casilla.alternate_bindings)formula_bindings:set[BindingId]=set()forformulainrevision.formulas:formula_bindings.update(expression_binding_refs(formula.expression))return_RelationConsumptionIndex(primary_bindings=frozenset(primary_bindings),alternate_bindings=frozenset(alternate_bindings),formula_bindings=frozenset(formula_bindings),)
[docs]defrelation_consumption_channels(binding_id:BindingId,index:_RelationConsumptionIndex,)->tuple[RelationConsumptionChannel,...]:"""Return every declared channel that consumes ``binding_id`` in stable order. An empty result means the binding is declared but nothing reads it, which is the orphan condition consumers report rather than tolerate. """channels:list[RelationConsumptionChannel]=[]ifbinding_idinindex.primary_bindings:channels.append(RelationConsumptionChannelKind.PRIMARY_BINDING)ifbinding_idinindex.alternate_bindings:channels.append(RelationConsumptionChannelKind.ALTERNATE_BINDING)ifbinding_idinindex.formula_bindings:channels.append(RelationConsumptionChannelKind.FORMULA_BINDING)returntuple(channels)