domaindriven-0.5.0: Batteries included event sourcing and CQRS
Safe HaskellSafe-Inferred
LanguageHaskell2010

DomainDriven.Server.Class

Synopsis

Documentation

data RequestType (accessType :: ModelAccess) (contentTypes :: [Type]) (verb :: Type -> Type) Source #

data ModelAccess Source #

Constructors

Direct 
Callback 

type Cmd = RequestType 'Direct '[JSON] (Verb 'POST 200 '[JSON]) Source #

type Action = ParamPart -> Type -> Type -> Type Source #

The kind of an Action, defined with a GADT as: data MyAction :: Action where ThisAction :: P x "count" Int -> MyAction x 'Cmd Int ThatAction :: P x "description" Text -> MyAction x 'Cmd ()

type family CanMutate method :: Bool where ... Source #

Equations

CanMutate (RequestType a c (Verb 'GET code cts)) = 'False 
CanMutate (RequestType a c (Verb 'POST code cts)) = 'True 
CanMutate (RequestType a c (Verb 'PUT code cts)) = 'True 
CanMutate (RequestType a c (Verb 'PATCH code cts)) = 'True 
CanMutate (RequestType a c (Verb 'DELETE code cts)) = 'True 

data ParamPart Source #

Used as a parameter to the P type family on order to determine the focus.

Constructors

ParamName 
ParamType 

Instances

Instances details
Show ParamPart Source # 
Instance details

Defined in DomainDriven.Server.Class

type family P (x :: ParamPart) (name :: Symbol) (a :: Type) where ... Source #

P is used for specifying the parameters of the model. The name will be used as the name in the JSON encoding or the query parameter of the generated server.

Equations

P 'ParamName name ty = Proxy name 
P 'ParamType name ty = ty 

type family GetModelAccess method :: ModelAccess where ... Source #

Equations

GetModelAccess (RequestType a b c) = a 

data HandlerType method model event m a where Source #

Constructors

Query :: (CanMutate method ~ 'False, GetModelAccess method ~ 'Direct) => (model -> m a) -> HandlerType method model event m a 
CbQuery :: (CanMutate method ~ 'False, GetModelAccess method ~ 'Callback) => (m model -> m a) -> HandlerType method model event m a 
Cmd :: (CanMutate method ~ 'True, GetModelAccess method ~ 'Direct) => (model -> m (model -> a, [event])) -> HandlerType method model event m a 
CbCmd :: (CanMutate method ~ 'True, GetModelAccess method ~ 'Callback) => ((forall x. (model -> m (model -> x, [event])) -> m x) -> m a) -> HandlerType method model event m a 

type CmdCallback model event (m :: Type -> Type) = forall a. model -> m (a, [event]) Source #

mapModel :: forall m event model0 model1 method a. Monad m => (model0 -> model1) -> HandlerType method model1 event m a -> HandlerType method model0 event m a Source #

mapEvent :: forall m e0 e1 a method model. Monad m => (e0 -> e1) -> HandlerType method model e0 m a -> HandlerType method model e1 m a Source #

mapResult :: Monad m => (r0 -> r1) -> HandlerType method model e m r0 -> HandlerType method model e m r1 Source #

type ActionHandler model event m c = forall method a. c 'ParamType method a -> HandlerType method model event m a Source #

Action handler

Expects a command, specified using a one-parameter GADT where the parameter specifies the return type.

When implementing the handler you have access to IO, but in order for the library to ensure thread safety of state updates you do not have direct access to the current state. Instead the handler returns a continuation, telling the library how to perform the evaluations on the model.

The resulting events will be applied to the current state so that no other command can run and generate events on the same state.

type ActionRunner m c = forall method a. MonadUnliftIO m => c 'ParamType method a -> m a Source #

runAction :: (MonadUnliftIO m, WriteModel p, model ~ Model p, event ~ Event p) => p -> ActionHandler model event m cmd -> cmd 'ParamType method ret -> m ret Source #