Maestro v0.0.1 Maestro.Aggregate behaviour View Source
Traditional domain entities are referred to as aggregates in the literature. The goal of this library is to greatly simplify the process of implementing a event sourcing application by owning the flow of non-domain data (i.e. commands, events, and snapshots) to allow you to focus on the business logic of evaluating commands and applying events to your domain objects.
The most crucial piece to this is the aggregate. It defines a behaviour
wherein the developer must implement the callbacks for eval_command and
apply_event. This allows the library to work through the lifecycle of a
command and its events in a controlled, consistent manner.
The aggregate behaviour provides the following utilities for managing state:
- ID and sequence tracking (to reduce duplication of effort)
- all necessary GenServer hooks (i.e.
handle_call,start_link,init) - updating state via snapshots and events
Link to this section Summary
Link to this section Types
Link to this type
t()
View Source
t() :: %Maestro.Aggregate{
id: HLClock.Timestamp.t(),
sequence: integer(),
state: any()
}
Link to this section Functions
Link to this section Callbacks
Link to this callback
apply_event(agg, event)
View Source
apply_event(agg(), event :: Maestro.Schemas.Event.t()) :: any()
Link to this callback
eval_command(agg, command)
View Source
eval_command(agg(), command :: Maestro.Command.t()) :: [ Maestro.Schemas.Event.t() ]
Link to this callback
use_snapshot(agg, snapshot)
View Source
(optional)
use_snapshot(agg(), snapshot :: Maestro.Schemas.Snapshot.t()) :: any()