angzarr_client.router.decorators¶
Class-level decorators that stash metadata on handler classes.
Five kinds of components:
@command_handler(domain=…, state=…) @saga(name=…, source=…, target=…) @process_manager(name=…, pm_domain=…, sources=[…], targets=[…], state=…) @projector(name=…, domains=[…]) @upcaster(name=…, domain=…)
- Each decorator:
sets
cls.__angzarr_kind__to the kind stringsets
cls.__angzarr_meta__to a dict of the decorator kwargsraises
TypeErrorif the class was already decorated with a different kind
Required kwargs are keyword-only with no defaults so Python raises TypeError
on missing arguments — the same shape the tests rely on.
Attributes¶
Functions¶
|
Mark a class as a command handler (aggregate) for |
|
Mark a class as a saga translating events from |
|
Mark a class as a process manager. |
|
Mark a class as a projector consuming events from |
|
Mark a class as an upcaster transforming events in |
|
Register a method as a dispatch target for |
|
Register a method as a fact-event handler for |
|
Register a method as a state applier for |
|
Register a method as a compensation handler for command rejections. |
|
Mark a method as the state factory for this instance. |
|
Register a method as a transformation from |
Module Contents¶
- angzarr_client.router.decorators.T¶
- angzarr_client.router.decorators.command_handler(*, domain: str, state: type, supports_replay: bool = False) Callable[[T], T]¶
Mark a class as a command handler (aggregate) for
domain.The
statetype is the aggregate’s state type; the class must either provide a@state_factorymethod or rely onstate()as the default factory (enforced in a later round).supports_replay(defaultFalse) opts the aggregate into the coordinator’sReplayRPC, used forMERGE_COMMUTATIVEconflict detection. WhenTrue, the framework auto-implements replay using the@appliesmethods to rebuild state from a snapshot + events; the state type must be a proto Message (carry aDESCRIPTOR). WhenFalsethe gRPC adapter returnsUNIMPLEMENTEDforReplayrequests — the coordinator degrades toMERGE_STRICTsemantics. Audit #45.Fact handling is opt-in via the
@handles_fact(EventType)method decorator. Aggregates with no@handles_factmethods getUNIMPLEMENTEDfrom the gRPC adapter forHandleFact; the coordinator falls back to pass-through-persist (per the proto’s Optional contract).
- angzarr_client.router.decorators.saga(*, name: str, source: str, target: str, sync: bool = False) Callable[[T], T]¶
Mark a class as a saga translating events from
sourceto commands fortarget.Audit #74:
syncdeclares whether commands emitted totargetever use sync mode (SIMPLE / CASCADE / DECISION / ISOLATED). DefaultFalse— target commands flow through the async bus and the readiness supervisor will not probetarget’s coordinator. Flip toTruewhen the saga blocks on the downstream response.
- angzarr_client.router.decorators.process_manager(*, name: str, pm_domain: str, sources: list[str], targets: list[str], state: type, sync_targets: list[str] | None = None) Callable[[T], T]¶
Mark a class as a process manager.
pm_domainis the PM’s own state-storage domain;sourceslists incoming event domains;targetslists downstream command domains.Audit #74:
sync_targetsdeclares the subset oftargetsthe PM ever addresses with sync mode (SIMPLE / CASCADE / DECISION / ISOLATED) — those are the targets whose coordinator must be reachable for readiness. DefaultNone(no sync targets) — every command goes through the async bus and the readiness supervisor will not probe any target’s coordinator.Raises
ValueErrorifsync_targetscontains a domain that is not intargets.
- angzarr_client.router.decorators.projector(*, name: str, domains: list[str]) Callable[[T], T]¶
Mark a class as a projector consuming events from
domains.
- angzarr_client.router.decorators.upcaster(*, name: str, domain: str) Callable[[T], T]¶
Mark a class as an upcaster transforming events in
domain.Methods decorated with
@upcasts(FromType, ToType)declare individual version-to-version transformations. An upcaster with zero@upcastsmethods is allowed (passthrough).
- angzarr_client.router.decorators.F¶
- angzarr_client.router.decorators.handles(message_type: type) Callable[[F], F]¶
Register a method as a dispatch target for
message_type.For command handlers this is the command type; for sagas / process managers / projectors it is the event type. Dispatch routes by proto full-name match.
- angzarr_client.router.decorators.handles_fact(event_type: type) Callable[[F], F]¶
Register a method as a fact-event handler for
event_type.Audit #45. Triggered when the coordinator dispatches a fact (an external reality, e.g. a payment confirmation from a third party) via the
HandleFactRPC. The method receives(event, state)after state has been rebuilt from prior events; it returns the events to persist (orNonefor pure side-effects).Aggregates with at least one
@handles_factmethod opt into theHandleFactRPC. Aggregates with none getUNIMPLEMENTEDfrom the framework’s gRPC adapter — the coordinator then falls back to pass-through-persist per the proto’s Optional contract.Distinct from
@handles(which dispatches commands and returns events),@handles_factis fact-specific: facts cannot be rejected, and the method’s return shape is just events-to-persist.
- angzarr_client.router.decorators.applies(event_type: type) Callable[[F], F]¶
Register a method as a state applier for
event_type.Appliers are invoked during state rebuild, walking the prior event book and mutating the instance’s state in place.
- angzarr_client.router.decorators.rejected(source_domain: str, command: str) Callable[[F], F]¶
Register a method as a compensation handler for command rejections.
Triggered when a command originating from this component is rejected by the target aggregate.
source_domainandcommandidentify the rejected command’s proto full-name suffix split into domain/command parts.
- angzarr_client.router.decorators.state_factory(fn: F) F¶
Mark a method as the state factory for this instance.
Overrides the default factory (calling
StateType()). Useful when state construction requires parameters or custom defaults.
- angzarr_client.router.decorators.upcasts(from_type: type, to_type: type) Callable[[F], F]¶
Register a method as a transformation from
from_typetoto_type.The method must accept the old event and return the new one. Dispatch matches by exact proto type-URL on the incoming event; events without a registered transform pass through unchanged.