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:

  1. Calls ^update to reset and replay the aggregate from the event store
  2. Executes the command body (validation and event emission)
  3. If X::OptimisticLocked is thrown, retries from step 1 (up to 5 attempts)
  4. Non-locking exceptions are re-thrown immediately without retry
  5. After exhausting all 5 attempts, the last X::OptimisticLocked is 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