ProjectionStorage

Special aggregation that maintains a registry of all projections and enables automatic projection updates. Declared as an aggregation so it can emit ProjectionRegistered events while also consuming events to route them to registered projections.

Attributes

AttributeTypeDescription
$.idIntProjection ID (always 1)
%.registriesHashMaps event type names to Registry entries
$.supplySupplyThe event processing supply

Methods

method start

Starts the supply and returns a Promise that resolves when the supply completes. The supply listens to $*SourcingConfig.supply and applies events to this storage projection.

my $storage = Sourcing::ProjectionStorage.new;
await $storage.start;

method register(Mu:U $type)

Registers a projection type. Emits a ProjectionRegistered event that gets stored in the registry.

$storage.register: MyProjection;

multi method apply(ProjectionRegistered (Mu:U :$type, Str :$name, :%map, :@ids))

Registers a new projection type by adding entries to %!registries for each event type.

multi method apply(Any $event)

Routes events to all matching projections. For each registered projection, extracts ID values from the event and calls sourcing to get/create the projection instance.

Performance Note

This has O(n²) performance for large event streams since each event triggers a full replay of all events for every registered projection. For production use with large event streams, consider implementing incremental projection updates.

Usage

use Sourcing::ProjectionStorage;

my $storage = Sourcing::ProjectionStorage.new;
await $storage.start;

$storage.register: MyProjection;

# Now any emitted event will automatically update MyProjection instances

See Also