{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Servant.Server.Internal.Delayed where
import Control.Monad.IO.Class
(MonadIO (..))
import Control.Monad.Reader
(ask)
import Control.Monad.Trans.Resource
(ResourceT, runResourceT)
import Network.Wai
(Request, Response)
import Servant.Server.Internal.DelayedIO
import Servant.Server.Internal.Handler
import Servant.Server.Internal.RouteResult
import Servant.Server.Internal.ServerError
data Delayed env c where
Delayed :: { ()
capturesD :: env -> DelayedIO captures
, forall env c. Delayed env c -> DelayedIO ()
methodD :: DelayedIO ()
, ()
authD :: DelayedIO auth
, forall env c. Delayed env c -> DelayedIO ()
acceptD :: DelayedIO ()
, ()
contentD :: DelayedIO contentType
, ()
paramsD :: DelayedIO params
, :: DelayedIO headers
, ()
bodyD :: contentType -> DelayedIO body
, ()
serverD :: captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult c
} -> Delayed env c
instance Functor (Delayed env) where
fmap :: forall a b. (a -> b) -> Delayed env a -> Delayed env b
fmap a -> b
f Delayed{DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
contentType -> DelayedIO body
$sel:capturesD:Delayed :: ()
$sel:methodD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:authD:Delayed :: ()
$sel:acceptD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:contentD:Delayed :: ()
$sel:paramsD:Delayed :: ()
$sel:headersD:Delayed :: ()
$sel:bodyD:Delayed :: ()
$sel:serverD:Delayed :: ()
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
..} =
Delayed
{ $sel:serverD:Delayed :: captures
-> params -> headers -> auth -> body -> Request -> RouteResult b
serverD = \ captures
c params
p headers
h auth
a body
b Request
req -> a -> b
f (a -> b) -> RouteResult a -> RouteResult b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
serverD captures
c params
p headers
h auth
a body
b Request
req
, DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
contentType -> DelayedIO body
$sel:capturesD:Delayed :: env -> DelayedIO captures
$sel:methodD:Delayed :: DelayedIO ()
$sel:authD:Delayed :: DelayedIO auth
$sel:acceptD:Delayed :: DelayedIO ()
$sel:contentD:Delayed :: DelayedIO contentType
$sel:paramsD:Delayed :: DelayedIO params
$sel:headersD:Delayed :: DelayedIO headers
$sel:bodyD:Delayed :: contentType -> DelayedIO body
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
..
}
emptyDelayed :: RouteResult a -> Delayed env a
emptyDelayed :: forall a env. RouteResult a -> Delayed env a
emptyDelayed RouteResult a
result =
(env -> DelayedIO ())
-> DelayedIO ()
-> DelayedIO ()
-> DelayedIO ()
-> DelayedIO ()
-> DelayedIO ()
-> DelayedIO ()
-> (() -> DelayedIO ())
-> (() -> () -> () -> () -> () -> Request -> RouteResult a)
-> Delayed env a
forall env captures auth contentType params headers body c.
(env -> DelayedIO captures)
-> DelayedIO ()
-> DelayedIO auth
-> DelayedIO ()
-> DelayedIO contentType
-> DelayedIO params
-> DelayedIO headers
-> (contentType -> DelayedIO body)
-> (captures
-> params -> headers -> auth -> body -> Request -> RouteResult c)
-> Delayed env c
Delayed (DelayedIO () -> env -> DelayedIO ()
forall a b. a -> b -> a
const DelayedIO ()
r) DelayedIO ()
r DelayedIO ()
r DelayedIO ()
r DelayedIO ()
r DelayedIO ()
r DelayedIO ()
r (DelayedIO () -> () -> DelayedIO ()
forall a b. a -> b -> a
const DelayedIO ()
r) (\ ()
_ ()
_ ()
_ ()
_ ()
_ Request
_ -> RouteResult a
result)
where
r :: DelayedIO ()
r = () -> DelayedIO ()
forall a. a -> DelayedIO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return ()
addCapture :: Delayed env (a -> b)
-> (captured -> DelayedIO a)
-> Delayed (captured, env) b
addCapture :: forall env a b captured.
Delayed env (a -> b)
-> (captured -> DelayedIO a) -> Delayed (captured, env) b
addCapture Delayed{DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
contentType -> DelayedIO body
$sel:capturesD:Delayed :: ()
$sel:methodD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:authD:Delayed :: ()
$sel:acceptD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:contentD:Delayed :: ()
$sel:paramsD:Delayed :: ()
$sel:headersD:Delayed :: ()
$sel:bodyD:Delayed :: ()
$sel:serverD:Delayed :: ()
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
..} captured -> DelayedIO a
new =
Delayed
{ $sel:capturesD:Delayed :: (captured, env) -> DelayedIO (captures, a)
capturesD = \ (captured
txt, env
env) -> (,) (captures -> a -> (captures, a))
-> DelayedIO captures -> DelayedIO (a -> (captures, a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> env -> DelayedIO captures
capturesD env
env DelayedIO (a -> (captures, a))
-> DelayedIO a -> DelayedIO (captures, a)
forall a b. DelayedIO (a -> b) -> DelayedIO a -> DelayedIO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> captured -> DelayedIO a
new captured
txt
, $sel:serverD:Delayed :: (captures, a)
-> params -> headers -> auth -> body -> Request -> RouteResult b
serverD = \ (captures
x, a
v) params
p headers
h auth
a body
b Request
req -> ((a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ a
v) ((a -> b) -> b) -> RouteResult (a -> b) -> RouteResult b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
serverD captures
x params
p headers
h auth
a body
b Request
req
, DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
contentType -> DelayedIO body
$sel:methodD:Delayed :: DelayedIO ()
$sel:authD:Delayed :: DelayedIO auth
$sel:acceptD:Delayed :: DelayedIO ()
$sel:contentD:Delayed :: DelayedIO contentType
$sel:paramsD:Delayed :: DelayedIO params
$sel:headersD:Delayed :: DelayedIO headers
$sel:bodyD:Delayed :: contentType -> DelayedIO body
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
..
}
addParameterCheck :: Delayed env (a -> b)
-> DelayedIO a
-> Delayed env b
addParameterCheck :: forall env a b.
Delayed env (a -> b) -> DelayedIO a -> Delayed env b
addParameterCheck Delayed {DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
contentType -> DelayedIO body
$sel:capturesD:Delayed :: ()
$sel:methodD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:authD:Delayed :: ()
$sel:acceptD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:contentD:Delayed :: ()
$sel:paramsD:Delayed :: ()
$sel:headersD:Delayed :: ()
$sel:bodyD:Delayed :: ()
$sel:serverD:Delayed :: ()
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
..} DelayedIO a
new =
Delayed
{ $sel:paramsD:Delayed :: DelayedIO (params, a)
paramsD = (,) (params -> a -> (params, a))
-> DelayedIO params -> DelayedIO (a -> (params, a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> DelayedIO params
paramsD DelayedIO (a -> (params, a))
-> DelayedIO a -> DelayedIO (params, a)
forall a b. DelayedIO (a -> b) -> DelayedIO a -> DelayedIO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> DelayedIO a
new
, $sel:serverD:Delayed :: captures
-> (params, a)
-> headers
-> auth
-> body
-> Request
-> RouteResult b
serverD = \captures
c (params
p, a
pNew) headers
h auth
a body
b Request
req -> ((a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ a
pNew) ((a -> b) -> b) -> RouteResult (a -> b) -> RouteResult b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
serverD captures
c params
p headers
h auth
a body
b Request
req
, DelayedIO auth
DelayedIO contentType
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
contentType -> DelayedIO body
$sel:capturesD:Delayed :: env -> DelayedIO captures
$sel:methodD:Delayed :: DelayedIO ()
$sel:authD:Delayed :: DelayedIO auth
$sel:acceptD:Delayed :: DelayedIO ()
$sel:contentD:Delayed :: DelayedIO contentType
$sel:headersD:Delayed :: DelayedIO headers
$sel:bodyD:Delayed :: contentType -> DelayedIO body
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
..
}
addHeaderCheck :: Delayed env (a -> b)
-> DelayedIO a
-> Delayed env b
Delayed {DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
contentType -> DelayedIO body
$sel:capturesD:Delayed :: ()
$sel:methodD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:authD:Delayed :: ()
$sel:acceptD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:contentD:Delayed :: ()
$sel:paramsD:Delayed :: ()
$sel:headersD:Delayed :: ()
$sel:bodyD:Delayed :: ()
$sel:serverD:Delayed :: ()
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
..} DelayedIO a
new =
Delayed
{ $sel:headersD:Delayed :: DelayedIO (headers, a)
headersD = (,) (headers -> a -> (headers, a))
-> DelayedIO headers -> DelayedIO (a -> (headers, a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> DelayedIO headers
headersD DelayedIO (a -> (headers, a))
-> DelayedIO a -> DelayedIO (headers, a)
forall a b. DelayedIO (a -> b) -> DelayedIO a -> DelayedIO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> DelayedIO a
new
, $sel:serverD:Delayed :: captures
-> params
-> (headers, a)
-> auth
-> body
-> Request
-> RouteResult b
serverD = \captures
c params
p (headers
h, a
hNew) auth
a body
b Request
req -> ((a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ a
hNew) ((a -> b) -> b) -> RouteResult (a -> b) -> RouteResult b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
serverD captures
c params
p headers
h auth
a body
b Request
req
, DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO ()
env -> DelayedIO captures
contentType -> DelayedIO body
$sel:capturesD:Delayed :: env -> DelayedIO captures
$sel:methodD:Delayed :: DelayedIO ()
$sel:authD:Delayed :: DelayedIO auth
$sel:acceptD:Delayed :: DelayedIO ()
$sel:contentD:Delayed :: DelayedIO contentType
$sel:paramsD:Delayed :: DelayedIO params
$sel:bodyD:Delayed :: contentType -> DelayedIO body
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
bodyD :: contentType -> DelayedIO body
..
}
addMethodCheck :: Delayed env a
-> DelayedIO ()
-> Delayed env a
addMethodCheck :: forall env a. Delayed env a -> DelayedIO () -> Delayed env a
addMethodCheck Delayed{DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
contentType -> DelayedIO body
$sel:capturesD:Delayed :: ()
$sel:methodD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:authD:Delayed :: ()
$sel:acceptD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:contentD:Delayed :: ()
$sel:paramsD:Delayed :: ()
$sel:headersD:Delayed :: ()
$sel:bodyD:Delayed :: ()
$sel:serverD:Delayed :: ()
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
..} DelayedIO ()
new =
Delayed
{ $sel:methodD:Delayed :: DelayedIO ()
methodD = DelayedIO ()
methodD DelayedIO () -> DelayedIO () -> DelayedIO ()
forall a b. DelayedIO a -> DelayedIO b -> DelayedIO a
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* DelayedIO ()
new
, DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
contentType -> DelayedIO body
$sel:capturesD:Delayed :: env -> DelayedIO captures
$sel:authD:Delayed :: DelayedIO auth
$sel:acceptD:Delayed :: DelayedIO ()
$sel:contentD:Delayed :: DelayedIO contentType
$sel:paramsD:Delayed :: DelayedIO params
$sel:headersD:Delayed :: DelayedIO headers
$sel:bodyD:Delayed :: contentType -> DelayedIO body
$sel:serverD:Delayed :: captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
capturesD :: env -> DelayedIO captures
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
..
}
addAuthCheck :: Delayed env (a -> b)
-> DelayedIO a
-> Delayed env b
addAuthCheck :: forall env a b.
Delayed env (a -> b) -> DelayedIO a -> Delayed env b
addAuthCheck Delayed{DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
contentType -> DelayedIO body
$sel:capturesD:Delayed :: ()
$sel:methodD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:authD:Delayed :: ()
$sel:acceptD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:contentD:Delayed :: ()
$sel:paramsD:Delayed :: ()
$sel:headersD:Delayed :: ()
$sel:bodyD:Delayed :: ()
$sel:serverD:Delayed :: ()
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
..} DelayedIO a
new =
Delayed
{ $sel:authD:Delayed :: DelayedIO (auth, a)
authD = (,) (auth -> a -> (auth, a))
-> DelayedIO auth -> DelayedIO (a -> (auth, a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> DelayedIO auth
authD DelayedIO (a -> (auth, a)) -> DelayedIO a -> DelayedIO (auth, a)
forall a b. DelayedIO (a -> b) -> DelayedIO a -> DelayedIO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> DelayedIO a
new
, $sel:serverD:Delayed :: captures
-> params
-> headers
-> (auth, a)
-> body
-> Request
-> RouteResult b
serverD = \ captures
c params
p headers
h (auth
y, a
v) body
b Request
req -> ((a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ a
v) ((a -> b) -> b) -> RouteResult (a -> b) -> RouteResult b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
serverD captures
c params
p headers
h auth
y body
b Request
req
, DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
contentType -> DelayedIO body
$sel:capturesD:Delayed :: env -> DelayedIO captures
$sel:methodD:Delayed :: DelayedIO ()
$sel:acceptD:Delayed :: DelayedIO ()
$sel:contentD:Delayed :: DelayedIO contentType
$sel:paramsD:Delayed :: DelayedIO params
$sel:headersD:Delayed :: DelayedIO headers
$sel:bodyD:Delayed :: contentType -> DelayedIO body
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
..
}
addBodyCheck :: Delayed env (a -> b)
-> DelayedIO c
-> (c -> DelayedIO a)
-> Delayed env b
addBodyCheck :: forall env a b c.
Delayed env (a -> b)
-> DelayedIO c -> (c -> DelayedIO a) -> Delayed env b
addBodyCheck Delayed{DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
contentType -> DelayedIO body
$sel:capturesD:Delayed :: ()
$sel:methodD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:authD:Delayed :: ()
$sel:acceptD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:contentD:Delayed :: ()
$sel:paramsD:Delayed :: ()
$sel:headersD:Delayed :: ()
$sel:bodyD:Delayed :: ()
$sel:serverD:Delayed :: ()
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
..} DelayedIO c
newContentD c -> DelayedIO a
newBodyD =
Delayed
{ $sel:contentD:Delayed :: DelayedIO (contentType, c)
contentD = (,) (contentType -> c -> (contentType, c))
-> DelayedIO contentType -> DelayedIO (c -> (contentType, c))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> DelayedIO contentType
contentD DelayedIO (c -> (contentType, c))
-> DelayedIO c -> DelayedIO (contentType, c)
forall a b. DelayedIO (a -> b) -> DelayedIO a -> DelayedIO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> DelayedIO c
newContentD
, $sel:bodyD:Delayed :: (contentType, c) -> DelayedIO (body, a)
bodyD = \(contentType
content, c
c) -> (,) (body -> a -> (body, a))
-> DelayedIO body -> DelayedIO (a -> (body, a))
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> contentType -> DelayedIO body
bodyD contentType
content DelayedIO (a -> (body, a)) -> DelayedIO a -> DelayedIO (body, a)
forall a b. DelayedIO (a -> b) -> DelayedIO a -> DelayedIO b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> c -> DelayedIO a
newBodyD c
c
, $sel:serverD:Delayed :: captures
-> params
-> headers
-> auth
-> (body, a)
-> Request
-> RouteResult b
serverD = \ captures
c params
p headers
h auth
a (body
z, a
v) Request
req -> ((a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ a
v) ((a -> b) -> b) -> RouteResult (a -> b) -> RouteResult b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
serverD captures
c params
p headers
h auth
a body
z Request
req
, DelayedIO auth
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
$sel:capturesD:Delayed :: env -> DelayedIO captures
$sel:methodD:Delayed :: DelayedIO ()
$sel:authD:Delayed :: DelayedIO auth
$sel:acceptD:Delayed :: DelayedIO ()
$sel:paramsD:Delayed :: DelayedIO params
$sel:headersD:Delayed :: DelayedIO headers
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
paramsD :: DelayedIO params
headersD :: DelayedIO headers
..
}
addAcceptCheck :: Delayed env a
-> DelayedIO ()
-> Delayed env a
addAcceptCheck :: forall env a. Delayed env a -> DelayedIO () -> Delayed env a
addAcceptCheck Delayed{DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
contentType -> DelayedIO body
$sel:capturesD:Delayed :: ()
$sel:methodD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:authD:Delayed :: ()
$sel:acceptD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:contentD:Delayed :: ()
$sel:paramsD:Delayed :: ()
$sel:headersD:Delayed :: ()
$sel:bodyD:Delayed :: ()
$sel:serverD:Delayed :: ()
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
..} DelayedIO ()
new =
Delayed
{ $sel:acceptD:Delayed :: DelayedIO ()
acceptD = DelayedIO ()
acceptD DelayedIO () -> DelayedIO () -> DelayedIO ()
forall a b. DelayedIO a -> DelayedIO b -> DelayedIO b
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f b
*> DelayedIO ()
new
, DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
contentType -> DelayedIO body
$sel:capturesD:Delayed :: env -> DelayedIO captures
$sel:methodD:Delayed :: DelayedIO ()
$sel:authD:Delayed :: DelayedIO auth
$sel:contentD:Delayed :: DelayedIO contentType
$sel:paramsD:Delayed :: DelayedIO params
$sel:headersD:Delayed :: DelayedIO headers
$sel:bodyD:Delayed :: contentType -> DelayedIO body
$sel:serverD:Delayed :: captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
..
}
passToServer :: Delayed env (a -> b) -> (Request -> a) -> Delayed env b
passToServer :: forall env a b.
Delayed env (a -> b) -> (Request -> a) -> Delayed env b
passToServer Delayed{DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
contentType -> DelayedIO body
$sel:capturesD:Delayed :: ()
$sel:methodD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:authD:Delayed :: ()
$sel:acceptD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:contentD:Delayed :: ()
$sel:paramsD:Delayed :: ()
$sel:headersD:Delayed :: ()
$sel:bodyD:Delayed :: ()
$sel:serverD:Delayed :: ()
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
..} Request -> a
x =
Delayed
{ $sel:serverD:Delayed :: captures
-> params -> headers -> auth -> body -> Request -> RouteResult b
serverD = \ captures
c params
p headers
h auth
a body
b Request
req -> ((a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ Request -> a
x Request
req) ((a -> b) -> b) -> RouteResult (a -> b) -> RouteResult b
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> captures
-> params
-> headers
-> auth
-> body
-> Request
-> RouteResult (a -> b)
serverD captures
c params
p headers
h auth
a body
b Request
req
, DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
contentType -> DelayedIO body
$sel:capturesD:Delayed :: env -> DelayedIO captures
$sel:methodD:Delayed :: DelayedIO ()
$sel:authD:Delayed :: DelayedIO auth
$sel:acceptD:Delayed :: DelayedIO ()
$sel:contentD:Delayed :: DelayedIO contentType
$sel:paramsD:Delayed :: DelayedIO params
$sel:headersD:Delayed :: DelayedIO headers
$sel:bodyD:Delayed :: contentType -> DelayedIO body
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
..
}
runDelayed :: Delayed env a
-> env
-> Request
-> ResourceT IO (RouteResult a)
runDelayed :: forall env a.
Delayed env a -> env -> Request -> ResourceT IO (RouteResult a)
runDelayed Delayed{DelayedIO auth
DelayedIO contentType
DelayedIO params
DelayedIO headers
DelayedIO ()
env -> DelayedIO captures
captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
contentType -> DelayedIO body
$sel:capturesD:Delayed :: ()
$sel:methodD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:authD:Delayed :: ()
$sel:acceptD:Delayed :: forall env c. Delayed env c -> DelayedIO ()
$sel:contentD:Delayed :: ()
$sel:paramsD:Delayed :: ()
$sel:headersD:Delayed :: ()
$sel:bodyD:Delayed :: ()
$sel:serverD:Delayed :: ()
capturesD :: env -> DelayedIO captures
methodD :: DelayedIO ()
authD :: DelayedIO auth
acceptD :: DelayedIO ()
contentD :: DelayedIO contentType
paramsD :: DelayedIO params
headersD :: DelayedIO headers
bodyD :: contentType -> DelayedIO body
serverD :: captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
..} env
env = DelayedIO a -> Request -> ResourceT IO (RouteResult a)
forall a. DelayedIO a -> Request -> ResourceT IO (RouteResult a)
runDelayedIO (DelayedIO a -> Request -> ResourceT IO (RouteResult a))
-> DelayedIO a -> Request -> ResourceT IO (RouteResult a)
forall a b. (a -> b) -> a -> b
$ do
Request
r <- DelayedIO Request
forall r (m :: Type -> Type). MonadReader r m => m r
ask
captures
c <- env -> DelayedIO captures
capturesD env
env
DelayedIO ()
methodD
auth
a <- DelayedIO auth
authD
DelayedIO ()
acceptD
contentType
content <- DelayedIO contentType
contentD
params
p <- DelayedIO params
paramsD
headers
h <- DelayedIO headers
headersD
body
b <- contentType -> DelayedIO body
bodyD contentType
content
RouteResult a -> DelayedIO a
forall a. RouteResult a -> DelayedIO a
liftRouteResult (captures
-> params -> headers -> auth -> body -> Request -> RouteResult a
serverD captures
c params
p headers
h auth
a body
b Request
r)
runAction :: Delayed env (Handler a)
-> env
-> Request
-> (RouteResult Response -> IO r)
-> (a -> RouteResult Response)
-> IO r
runAction :: forall env a r.
Delayed env (Handler a)
-> env
-> Request
-> (RouteResult Response -> IO r)
-> (a -> RouteResult Response)
-> IO r
runAction Delayed env (Handler a)
action env
env Request
req RouteResult Response -> IO r
respond a -> RouteResult Response
k = ResourceT IO r -> IO r
forall (m :: Type -> Type) a.
MonadUnliftIO m =>
ResourceT m a -> m a
runResourceT (ResourceT IO r -> IO r) -> ResourceT IO r -> IO r
forall a b. (a -> b) -> a -> b
$
Delayed env (Handler a)
-> env -> Request -> ResourceT IO (RouteResult (Handler a))
forall env a.
Delayed env a -> env -> Request -> ResourceT IO (RouteResult a)
runDelayed Delayed env (Handler a)
action env
env Request
req ResourceT IO (RouteResult (Handler a))
-> (RouteResult (Handler a) -> ResourceT IO (RouteResult Response))
-> ResourceT IO (RouteResult Response)
forall a b.
ResourceT IO a -> (a -> ResourceT IO b) -> ResourceT IO b
forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= RouteResult (Handler a) -> ResourceT IO (RouteResult Response)
go ResourceT IO (RouteResult Response)
-> (RouteResult Response -> ResourceT IO r) -> ResourceT IO r
forall a b.
ResourceT IO a -> (a -> ResourceT IO b) -> ResourceT IO b
forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= IO r -> ResourceT IO r
forall a. IO a -> ResourceT IO a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO r -> ResourceT IO r)
-> (RouteResult Response -> IO r)
-> RouteResult Response
-> ResourceT IO r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RouteResult Response -> IO r
respond
where
go :: RouteResult (Handler a) -> ResourceT IO (RouteResult Response)
go (Fail ServerError
e) = RouteResult Response -> ResourceT IO (RouteResult Response)
forall a. a -> ResourceT IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (RouteResult Response -> ResourceT IO (RouteResult Response))
-> RouteResult Response -> ResourceT IO (RouteResult Response)
forall a b. (a -> b) -> a -> b
$ ServerError -> RouteResult Response
forall a. ServerError -> RouteResult a
Fail ServerError
e
go (FailFatal ServerError
e) = RouteResult Response -> ResourceT IO (RouteResult Response)
forall a. a -> ResourceT IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (RouteResult Response -> ResourceT IO (RouteResult Response))
-> RouteResult Response -> ResourceT IO (RouteResult Response)
forall a b. (a -> b) -> a -> b
$ ServerError -> RouteResult Response
forall a. ServerError -> RouteResult a
FailFatal ServerError
e
go (Route Handler a
a) = IO (RouteResult Response) -> ResourceT IO (RouteResult Response)
forall a. IO a -> ResourceT IO a
forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
liftIO (IO (RouteResult Response) -> ResourceT IO (RouteResult Response))
-> IO (RouteResult Response) -> ResourceT IO (RouteResult Response)
forall a b. (a -> b) -> a -> b
$ do
Either ServerError a
e <- Handler a -> IO (Either ServerError a)
forall a. Handler a -> IO (Either ServerError a)
runHandler Handler a
a
case Either ServerError a
e of
Left ServerError
err -> RouteResult Response -> IO (RouteResult Response)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (RouteResult Response -> IO (RouteResult Response))
-> (Response -> RouteResult Response)
-> Response
-> IO (RouteResult Response)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Response -> RouteResult Response
forall a. a -> RouteResult a
Route (Response -> IO (RouteResult Response))
-> Response -> IO (RouteResult Response)
forall a b. (a -> b) -> a -> b
$ ServerError -> Response
responseServerError ServerError
err
Right a
x -> RouteResult Response -> IO (RouteResult Response)
forall a. a -> IO a
forall (m :: Type -> Type) a. Monad m => a -> m a
return (RouteResult Response -> IO (RouteResult Response))
-> RouteResult Response -> IO (RouteResult Response)
forall a b. (a -> b) -> a -> b
$! a -> RouteResult Response
k a
x