Copyright | (C) 2017 Yorick Laupa |
---|---|
License | (see the file LICENSE) |
Maintainer | Yorick Laupa <yo.eight@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
- type AggIO id command event state = Agg (Simple id command event state)
- class AggregateIO event state | event -> state where
- class AggregateIO event state => ValidateIO command event state | command -> state, command -> event where
- data Simple id command event state
- newAgg :: AggregateIO event state => SomeStore -> id -> state -> IO (AggIO id command event state)
- loadAgg :: (AggregateIO event state, StreamId id, DecodeEvent event) => SomeStore -> id -> state -> IO (Either ForEventFailure (AggIO id command event state))
- loadOrCreateAgg :: (AggregateIO event state, StreamId id, DecodeEvent event) => SomeStore -> id -> state -> IO (AggIO id command event state)
- submitCmd :: (ValidateIO command event state, StreamId id, EncodeEvent event) => AggIO id command event state -> command -> IO (Either SomeException event)
- submitEvt :: AggregateIO event state => AggIO id command event state -> event -> IO ()
- closeAgg :: AggIO id command event state -> IO ()
- snapshot :: AggIO id command event state -> IO state
- route :: AggIO id command event state -> (SomeStore -> state -> (state -> r -> IO ()) -> IO ()) -> IO r
Documentation
type AggIO id command event state = Agg (Simple id command event state) Source #
A stream aggregate. An aggregate updates its internal based on the event
it receives. You can read its current state by using snapshot
. If it
supports validation, through Validated
typeclass, it can receive
command and emits an event if the command was successful. Otherwise, it will
yield an error. When receiving valid command, an aggregate will persist the
resulting event. An aggregate is only responsible of its own stream.
class AggregateIO event state | event -> state where Source #
Represents a stream aggregate. An aggregate can rebuild its internal state by replaying all the stream's events that aggregate is responsible for.
class AggregateIO event state => ValidateIO command event state | command -> state, command -> event where Source #
Represents an aggregate that support validation. An aggregate that supports
validation can receive command and decide if it was valid or not. When the
validation is successful, The aggregate emits an event that will be
persisted and pass to apply
function.
validateIO :: state -> command -> IO (Either SomeException event) Source #
Validates a command. If the command validation succeeds, it will emits an event. Otherwise, it will returns an error.
data Simple id command event state Source #
Simple aggregate abstraction.
ValidateIO command event state => Validate (Simple id command event state) Source # | |
AggregateIO event state => Aggregate (Simple id command event state) Source # | |
type Cmd (Simple id command event state) Source # | |
type Err (Simple id command event state) Source # | |
type Id (Simple id command event state) Source # | |
type Evt (Simple id command event state) Source # | |
type M (Simple id command event state) Source # | |
newAgg :: AggregateIO event state => SomeStore -> id -> state -> IO (AggIO id command event state) Source #
Creates a new aggregate given an eventstore handle, an id and an initial state.
loadAgg :: (AggregateIO event state, StreamId id, DecodeEvent event) => SomeStore -> id -> state -> IO (Either ForEventFailure (AggIO id command event state)) Source #
Creates an aggregate and replays its entire stream to rebuild its internal state.
loadOrCreateAgg :: (AggregateIO event state, StreamId id, DecodeEvent event) => SomeStore -> id -> state -> IO (AggIO id command event state) Source #
Like loadAgg
but call loadAgg
in case of ForEventFailure
error.
submitCmd :: (ValidateIO command event state, StreamId id, EncodeEvent event) => AggIO id command event state -> command -> IO (Either SomeException event) Source #
Submits a command to the aggregate. If the command was valid, it returns an event otherwise an error. In case of a valid command, the aggregate persist the resulting event to the eventstore. The aggregate will also update its internal state accordingly.