Source code for cadrumo.application.aggregation.source_profile
"""Source-mesh resolver for user-profile backed registry bindings.Owns :attr:`~core.aggregation.BindingSourceKind.PROFILE` and returns theprofile-sourced values as a :class:`~.source_mesh.CalculationSourceResolution`.Accepts an optional:class:`~domain.calculations.registry.schema.RegistrySnapshot` at construction;when none is supplied the resolver fetches the matching snapshot lazily from theresident registry authority at resolution time."""from__future__importannotationsfromcollections.abcimportIterablefromtypingimportClassVarfrom...core.aggregationimportBindingSourceKindfrom...domain.calculations.registry.authorityimportPinnedAuthorityOperationfrom...domain.calculations.registry.idsimportBindingIdfrom...domain.calculations.registry.schemaimportRegistrySnapshotfrom.source_meshimport(CalculationSourceContext,CalculationSourceResolution,)
[docs]classProfileSourceResolver:"""Resolve calculation-relevant ``source = "profile"`` bindings."""resolver_id:ClassVar[str]="profile"owned_sources:ClassVar[tuple[BindingSourceKind,...]]=(BindingSourceKind.PROFILE,)def__init__(self,*,caller_binding_ids:Iterable[BindingId]=(),registry_snapshot:RegistrySnapshot|None=None,profile_record:object|None=None,operation:PinnedAuthorityOperation,)->None:"""Capture the caller-owned operation and source-precedence inputs."""self._caller_binding_ids=frozenset(caller_binding_ids)self._registry_snapshot=registry_snapshotself._profile_record=profile_recordself._operation=operation
[docs]defresolve(self,context:CalculationSourceContext)->CalculationSourceResolution:"""Resolve all ``source="profile"`` bindings for the given calculation context. Fetches the :class:`RegistrySnapshot` lazily from the resident registry authority when none was supplied at construction, then delegates to ``resolve_profile_sourced_bindings``, which returns the complete :class:`CalculationSourceResolution` (typed binding channels plus a :class:`CalculationSourceProvenance` row per profile-sourced binding). Args: context: A :class:`CalculationSourceContext` carrying the modelo, filing year, period, and bucket identifier needed to select the correct registry snapshot. Returns: A :class:`CalculationSourceResolution` with typed binding maps and a provenance tuple covering every profile-sourced binding. """snapshot=self._registry_snapshotifsnapshotisNone:snapshot=self._operation.snapshot(context.modelo,filing_year=context.filing_year,period=context.period.registry_token,)from..modelo.profile_bindingimportresolve_profile_sourced_bindingsprofile_record=self._profile_recordifprofile_recordisNoneandcontext.profileisnotNone:profile_record=context.profile.recordreturnresolve_profile_sourced_bindings(snapshot,bucket_id=context.bucket_id,profile_record=profile_record,caller_binding_ids=self._caller_binding_ids,operation=self._operation,)