Traits
Sourcing uses Raku's trait_mod:<is> system for declarative configuration of projections, aggregations, and their members.
is command
Marks a method as a command. The method is wrapped in a retry loop that:
- Calls
^updateto reset and replay the aggregate from the event store - Executes the command body (validation and event emission)
- If
X::OptimisticLockedis thrown, retries from step 1 (up to 5 attempts) - Non-locking exceptions are re-thrown immediately without retry
- After exhausting all 5 attempts, the last
X::OptimisticLockedis re-thrown
method withdraw(Rat $amount) is command {
die "Insufficient funds" if $!balance < $amount;
$.amount-withdrawn: :$amount;
}
is command(False)
Marks a method as explicitly NOT a command. Prevents AggregationHOW from auto-generating an event-emitting method with the same name. Use this when you want a method name that would otherwise conflict with an auto-generated emit method.
is projection-id (on Attribute)
Marks an attribute as a projection identifier. This attribute's value is used to correlate events with specific projection instances.
has Int $.id is projection-id;
is projection-id<> (on Method)
Shorthand for mapping the projection's single ID attribute to a specific event field name. Requires exactly one is projection-id attribute on the class.
method apply(MyEvent $e) is projection-id< x > { }
# Maps the event's 'x' field to the projection's ID attribute
is projection-id-map (on Method)
Associates a method with a projection ID map, allowing custom event-to-attribute mappings.
method apply(MyEvent $e) is projection-id-map{ id => "x" } { }
# Maps the event's 'x' field to the projection's 'id' attribute
See Also
- Commands Concept — detailed explanation of command behavior
- Projections Concept — ID mapping explanation