Behaviour module for event stores.
An event store is responsible for storing and retrieving events in a stream. Each event has a sequence number that is strictly increasing within a stream. Events must be appended in order.
Summary
Callbacks
Append a single event to the given stream.
Get all events from the stream starting from the given sequence number (exclusive).
Functions
Appends an event to the specified stream in the given event store.
Validates that the given module implements the required functions of the Hume.EventStore
behaviour.
Types
Callbacks
Append a single event to the given stream.
Parameters
stream- The stream identifier where the event will be appended.payload- The event payload to be stored.expect- The expected last sequence number in the stream, ornilto skip the check. If a sequence number is provided, the implementation must only append the event if the current last sequence number in the stream equalsexpect. Otherwise it must return an error.
The implementation must assign the next strictly increasing sequence number and return
it in the {:ok, seq()} tuple on success.
@callback events(stream(), from :: seq()) :: Enumerable.t(event())
Get all events from the stream starting from the given sequence number (exclusive).
The events are returned in strictly ascending order by sequence number.
Functions
@spec append(module(), stream(), payload(), expect_seq :: seq() | nil) :: {:ok, seq()} | {:error, term()}
Appends an event to the specified stream in the given event store.
Parameters
- event_store: The module implementing the event store (must use
Hume.EventStore). - stream: The stream identifier where the event will be appended.
- payload: The event payload to be appended.
- expect_seq: Optional expected sequence number for optimistic concurrency control. If provided, the append will only succeed if the current last sequence number in the stream matches this value.
@spec validate(module()) :: :ok | {:error, :invalid_module}
Validates that the given module implements the required functions of the Hume.EventStore
behaviour.