Safe Haskell | None |
---|---|
Language | Haskell2010 |
Module to import for the Command side of the application.
- type AggregateAction a e = Maybe a -> e -> a
- data Repository a e
- data CommandT a e m b
- createAggregate :: (MonadIO m, Monad m) => UUID -> (UnitOfWorkT a e (CommandT a e m) (Maybe a) -> UnitOfWorkT a e (CommandT a e m) b) -> CommandT a e m b
- execCommandT :: MonadIO m => Repository a e -> CommandT a e m b -> m ()
- freshUUID :: MonadIO m => CommandT a e m UUID
- publishEvent :: (MonadIO m, NFData a, NFData e) => e -> UnitOfWorkT a e (CommandT a e m) ()
- readAggregate :: MonadIO m => UUID -> CommandT a e m (Maybe a)
- runCommandT :: MonadIO m => Repository a e -> CommandT a e m b -> m b
- data UnitOfWorkT a e m b
- updateAggregate :: MonadIO m => UUID -> (UnitOfWorkT a e (CommandT a e m) a -> UnitOfWorkT a e (CommandT a e m) b) -> CommandT a e m (Maybe b)
Documentation
type AggregateAction a e = Maybe a -> e -> a Source
An aggregate action is just a function for applying an event to
an aggregate. Aggregates that have not been created yet will be
passed in as Nothing
and aggregates which are being updated
will be passed in as Just x
.
data Repository a e Source
Repository consisting of an event store and an event bus.
Command monad transformer.
createAggregate :: (MonadIO m, Monad m) => UUID -> (UnitOfWorkT a e (CommandT a e m) (Maybe a) -> UnitOfWorkT a e (CommandT a e m) b) -> CommandT a e m b Source
Create a new aggregate using the supplied unit of work. Throws a
VersionConflict
exception if there is already an
aggregate with the given aggregate ID. NOTE: The exception may
be thrown at the END of the unit of work, and so any operations
in the unit of work that are lifted into the nested monad may be
performed regardless. (This is due to optimistic concurrency
control.)
execCommandT :: MonadIO m => Repository a e -> CommandT a e m b -> m () Source
Run a command against a repository, ignoring the result.
publishEvent :: (MonadIO m, NFData a, NFData e) => e -> UnitOfWorkT a e (CommandT a e m) () Source
Publish event for the current aggregate.
readAggregate :: MonadIO m => UUID -> CommandT a e m (Maybe a) Source
Read value of an aggregate if it exists. If any update needs to
be performed on the aggregate, use of the getter
function (see
createAggregate
and updateAggregate
) should be preferred.
runCommandT :: MonadIO m => Repository a e -> CommandT a e m b -> m b Source
Run a command against a repository.
data UnitOfWorkT a e m b Source
Unit of work monad transformer.
MonadTrans (UnitOfWorkT a e) Source | |
Monad m => Monad (UnitOfWorkT a e m) Source | |
Functor m => Functor (UnitOfWorkT a e m) Source | |
Monad m => Applicative (UnitOfWorkT a e m) Source | |
MonadIO m => MonadIO (UnitOfWorkT a e m) Source |
updateAggregate :: MonadIO m => UUID -> (UnitOfWorkT a e (CommandT a e m) a -> UnitOfWorkT a e (CommandT a e m) b) -> CommandT a e m (Maybe b) Source
Update aggregate with the supplied unit of work. The unit of work
is given a function to get the current value of the aggregate.
Returns the value returned by the unit of work, or Nothing
if
there was no aggregate with the given ID. Throws a
VersionConflict
exception if a version conflict
occurs during commit. NOTE: The exception may be thrown at the
END of the unit of work, and so any operations in the unit of work
that are lifted into the nested monad may be performed
regardless. (This is due to optimistic concurrency control.)