Source code for cadrumo.domain.calculations.registry.binding_terminal_origin
"""The authored expectation of where a binding's value ultimately comes from.Runtime provenance already records the terminal nodes a resolver actuallyreached. What it cannot say on its own is whether those nodes are the ones thedeclaration intended: a binding that silently resolves from a derivedcalculation instead of the filed casilla it names is still a complete-lookingresult. A :class:`TerminalOriginExpectation` is the compile-time half of thatpair -- the authored claim that runtime provenance is audited against, which iswhat makes the claim falsifiable rather than decorative.The expectation states four things per admitted origin: the class of terminalfact, its role in the provenance graph (reusing the existing:class:`~cadrumo.core.aggregation.CalculationSourceLineageRole`), how many suchnodes must appear, and whether each must carry an evidence fingerprint. Thecardinality axis is what keeps "no rows found" distinguishable from "rows wererequired and are missing": ``zero_or_more`` is a declaration that emptiness islegitimate, never a default."""from__future__importannotationsfromenumimportStrEnumfromtypingimportAnnotated,LiteralfrompydanticimportBeforeValidatorfrom....core.aggregationimportCalculationSourceLineageRolefrom.schema_baseimportRegistryModel,coerce_enum_member__all__=["TerminalOriginCardinality","TerminalOriginClass","TerminalOriginExpectation","TerminalOriginFingerprint",]TerminalOriginCardinality=Literal["exactly_one","at_least_one","zero_or_more"]"""How many terminal nodes of one origin class the resolved graph must carry."""TerminalOriginFingerprint=Literal["required","optional"]"""Whether each terminal node of this class must carry an evidence fingerprint."""
[docs]classTerminalOriginClass(StrEnum):"""The closed set of terminal fact classes a binding value can rest on. A terminal origin is where derivation stops: the persisted fact that is not itself computed from another registry source within the same resolution. """OPERATOR_INPUT="operator_input""""A value the operator supplied directly, answerable and attributable."""DESIGN_CONSTANT="design_constant""""A byte run AEAT fixes in the diseño de registro; no operator supplies it."""PROFILE_FIELD="profile_field""""A field of the taxpayer's censo/profile record."""FILED_MODELO_CASILLA="filed_modelo_casilla""""A casilla value of an immutable, already-filed modelo revision."""LEDGER_AGGREGATE="ledger_aggregate""""A fold over classified ledger transactions."""INVOICE_CATALOGUE="invoice_catalogue""""A fold over the invoice catalogue, in either or both directions."""PERCEPTOR_OBSERVATION="perceptor_observation""""A per-perceptor retención observation from its dedicated store."""DETAIL_RECORD="detail_record""""A row of an authored or pulled detail-record family."""DERIVED_CALCULATION="derived_calculation""""A value produced by another calculation rather than a persisted fact."""
[docs]classTerminalOriginExpectation(RegistryModel):"""One admitted terminal origin and the shape the resolved graph must show."""source_class:Annotated[TerminalOriginClass,BeforeValidator(coerce_enum_member(TerminalOriginClass))]role:Annotated[CalculationSourceLineageRole,BeforeValidator(coerce_enum_member(CalculationSourceLineageRole)),]cardinality:TerminalOriginCardinalityfingerprint:TerminalOriginFingerprint