@@ -6,6 +6,7 @@
6{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE MultiParamTypeClasses #-}
7{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE OverloadedStrings #-}
8{-# LANGUAGE PolyKinds #-}
8{-# LANGUAGE PolyKinds #-}
9+{-# LANGUAGE RankNTypes #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE TypeFamilies #-}
11{-# LANGUAGE TypeFamilies #-}
11{-# LANGUAGE TypeOperators #-}
12{-# LANGUAGE TypeOperators #-}
@@ -97,6 +98,12 @@ clientIn p pm = clientWithRoute pm p defaultRequest
97class RunClient m => HasClient m api where
98class RunClient m => HasClient m api where
98 type Client (m :: * -> *) (api :: *) :: *
99 type Client (m :: * -> *) (api :: *) :: *
99 clientWithRoute :: Proxy m -> Proxy api -> Request -> Client m api
100 clientWithRoute :: Proxy m -> Proxy api -> Request -> Client m api
104+ -> (forall x. mon x -> mon' x)
102-- | A client querying function for @a ':<|>' b@ will actually hand you
109-- | A client querying function for @a ':<|>' b@ will actually hand you
@@ -118,6 +125,10 @@ instance (HasClient m a, HasClient m b) => HasClient m (a :<|> b) where
118 clientWithRoute pm (Proxy :: Proxy a) req :<|>
125 clientWithRoute pm (Proxy :: Proxy a) req :<|>
119 clientWithRoute pm (Proxy :: Proxy b) req
126 clientWithRoute pm (Proxy :: Proxy b) req
128+ hoistClientMonad pm _ f (ca :<|> cb) =
129+ hoistClientMonad pm (Proxy :: Proxy a) f ca :<|>
130+ hoistClientMonad pm (Proxy :: Proxy b) f cb
121-- | Singleton type representing a client for an empty API.
132-- | Singleton type representing a client for an empty API.
122data EmptyClient = EmptyClient deriving (Eq, Show, Bounded, Enum)
133data EmptyClient = EmptyClient deriving (Eq, Show, Bounded, Enum)
@@ -134,6 +145,7 @@ data EmptyClient = EmptyClient deriving (Eq, Show, Bounded, Enum)
134instance RunClient m => HasClient m EmptyAPI where
145instance RunClient m => HasClient m EmptyAPI where
135 type Client m EmptyAPI = EmptyClient
146 type Client m EmptyAPI = EmptyClient
136 clientWithRoute _pm Proxy _ = EmptyClient
147 clientWithRoute _pm Proxy _ = EmptyClient
148+ hoistClientMonad _ _ _ EmptyClient = EmptyClient
138-- | If you use a 'Capture' in one of your endpoints in your API,
150-- | If you use a 'Capture' in one of your endpoints in your API,
139-- the corresponding querying function will automatically take
151-- the corresponding querying function will automatically take
@@ -166,6 +178,9 @@ instance (KnownSymbol capture, ToHttpApiData a, HasClient m api)
167 where p = (toUrlPiece val)
179 where p = (toUrlPiece val)
181+ hoistClientMonad pm _ f cl = \a ->
182+ hoistClientMonad pm (Proxy :: Proxy api) f (cl a)
169-- | If you use a 'CaptureAll' in one of your endpoints in your API,
184-- | If you use a 'CaptureAll' in one of your endpoints in your API,
170-- the corresponding querying function will automatically take an
185-- the corresponding querying function will automatically take an
171-- additional argument of a list of the type specified by your
186-- additional argument of a list of the type specified by your
@@ -198,6 +213,9 @@ instance (KnownSymbol capture, ToHttpApiData a, HasClient m sublayout)
199 where ps = map (toUrlPiece) vals
214 where ps = map (toUrlPiece) vals
216+ hoistClientMonad pm _ f cl = \as ->
217+ hoistClientMonad pm (Proxy :: Proxy sublayout) f (cl as)
201instance OVERLAPPABLE_
219instance OVERLAPPABLE_
202 -- Note [Non-Empty Content Types]
220 -- Note [Non-Empty Content Types]
203 ( RunClient m, MimeUnrender ct a, ReflectMethod method, cts' ~ (ct ': cts)
221 ( RunClient m, MimeUnrender ct a, ReflectMethod method, cts' ~ (ct ': cts)
@@ -213,6 +231,8 @@ instance OVERLAPPABLE_
213 accept = contentTypes (Proxy :: Proxy ct)
231 accept = contentTypes (Proxy :: Proxy ct)
214 method = reflectMethod (Proxy :: Proxy method)
232 method = reflectMethod (Proxy :: Proxy method)
234+ hoistClientMonad _ _ f ma = f ma
216instance OVERLAPPING_
236instance OVERLAPPING_
217 ( RunClient m, ReflectMethod method
237 ( RunClient m, ReflectMethod method
218 ) => HasClient m (Verb method status cts NoContent) where
238 ) => HasClient m (Verb method status cts NoContent) where
@@ -223,6 +243,8 @@ instance OVERLAPPING_
223 return NoContent
243 return NoContent
224 where method = reflectMethod (Proxy :: Proxy method)
244 where method = reflectMethod (Proxy :: Proxy method)
246+ hoistClientMonad _ _ f ma = f ma
226instance OVERLAPPING_
248instance OVERLAPPING_
227 -- Note [Non-Empty Content Types]
249 -- Note [Non-Empty Content Types]
228 ( RunClient m, MimeUnrender ct a, BuildHeadersTo ls
250 ( RunClient m, MimeUnrender ct a, BuildHeadersTo ls
@@ -244,6 +266,8 @@ instance OVERLAPPING_
244 where method = reflectMethod (Proxy :: Proxy method)
266 where method = reflectMethod (Proxy :: Proxy method)
245 accept = contentTypes (Proxy :: Proxy ct)
267 accept = contentTypes (Proxy :: Proxy ct)
269+ hoistClientMonad _ _ f ma = f ma
247instance OVERLAPPING_
271instance OVERLAPPING_
248 ( RunClient m, BuildHeadersTo ls, ReflectMethod method
272 ( RunClient m, BuildHeadersTo ls, ReflectMethod method
249 ) => HasClient m (Verb method status cts (Headers ls NoContent)) where
273 ) => HasClient m (Verb method status cts (Headers ls NoContent)) where
@@ -256,6 +280,8 @@ instance OVERLAPPING_
256 , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
280 , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
283+ hoistClientMonad _ _ f ma = f ma
259instance OVERLAPPABLE_
285instance OVERLAPPABLE_
260 ( RunClient m, MimeUnrender ct a, ReflectMethod method,
286 ( RunClient m, MimeUnrender ct a, ReflectMethod method,
261 FramingUnrender framing a, BuildFromStream a (f a)
287 FramingUnrender framing a, BuildFromStream a (f a)
@@ -304,6 +330,7 @@ instance OVERLAPPABLE_
304 processResult (Left err, _) = Just (Left err)
330 processResult (Left err, _) = Just (Left err)
333+ hoistClientMonad _ _ f ma = f ma
308-- | If you use a 'Header' in one of your endpoints in your API,
335-- | If you use a 'Header' in one of your endpoints in your API,
309-- the corresponding querying function will automatically take
336-- the corresponding querying function will automatically take
@@ -345,6 +372,9 @@ instance (KnownSymbol sym, ToHttpApiData a, HasClient m api, SBoolI (FoldRequire
345 add :: a -> Request
372 add :: a -> Request
346 add value = addHeader hname value req
373 add value = addHeader hname value req
375+ hoistClientMonad pm _ f cl = \arg ->
376+ hoistClientMonad pm (Proxy :: Proxy api) f (cl arg)
348-- | Using a 'HttpVersion' combinator in your API doesn't affect the client
378-- | Using a 'HttpVersion' combinator in your API doesn't affect the client
349-- functions.
379-- functions.
350instance HasClient m api
380instance HasClient m api
@@ -356,18 +386,24 @@ instance HasClient m api
356 clientWithRoute pm Proxy =
386 clientWithRoute pm Proxy =
357 clientWithRoute pm (Proxy :: Proxy api)
387 clientWithRoute pm (Proxy :: Proxy api)
389+ hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy api) f cl
359-- | Ignore @'Summary'@ in client functions.
391-- | Ignore @'Summary'@ in client functions.
360instance HasClient m api => HasClient m (Summary desc :> api) where
392instance HasClient m api => HasClient m (Summary desc :> api) where
361 type Client m (Summary desc :> api) = Client m api
393 type Client m (Summary desc :> api) = Client m api
363 clientWithRoute pm _ = clientWithRoute pm (Proxy :: Proxy api)
395 clientWithRoute pm _ = clientWithRoute pm (Proxy :: Proxy api)
397+ hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy api) f cl
365-- | Ignore @'Description'@ in client functions.
399-- | Ignore @'Description'@ in client functions.
366instance HasClient m api => HasClient m (Description desc :> api) where
400instance HasClient m api => HasClient m (Description desc :> api) where
367 type Client m (Description desc :> api) = Client m api
401 type Client m (Description desc :> api) = Client m api
369 clientWithRoute pm _ = clientWithRoute pm (Proxy :: Proxy api)
403 clientWithRoute pm _ = clientWithRoute pm (Proxy :: Proxy api)
405+ hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy api) f cl
371-- | If you use a 'QueryParam' in one of your endpoints in your API,
407-- | If you use a 'QueryParam' in one of your endpoints in your API,
372-- the corresponding querying function will automatically take
408-- the corresponding querying function will automatically take
373-- an additional argument of the type specified by your 'QueryParam',
409-- an additional argument of the type specified by your 'QueryParam',
@@ -410,6 +446,9 @@ instance (KnownSymbol sym, ToHttpApiData a, HasClient m api, SBoolI (FoldRequire
410 pname :: Text
446 pname :: Text
411 pname = pack $ symbolVal (Proxy :: Proxy sym)
447 pname = pack $ symbolVal (Proxy :: Proxy sym)
449+ hoistClientMonad pm _ f cl = \arg ->
450+ hoistClientMonad pm (Proxy :: Proxy api) f (cl arg)
413-- | If you use a 'QueryParams' in one of your endpoints in your API,
452-- | If you use a 'QueryParams' in one of your endpoints in your API,
414-- the corresponding querying function will automatically take
453-- the corresponding querying function will automatically take
415-- an additional argument, a list of values of the type specified
454-- an additional argument, a list of values of the type specified
@@ -453,6 +492,9 @@ instance (KnownSymbol sym, ToHttpApiData a, HasClient m api)
453 where pname = pack $ symbolVal (Proxy :: Proxy sym)
492 where pname = pack $ symbolVal (Proxy :: Proxy sym)
454 paramlist' = map (Just . toQueryParam) paramlist
493 paramlist' = map (Just . toQueryParam) paramlist
495+ hoistClientMonad pm _ f cl = \as ->
496+ hoistClientMonad pm (Proxy :: Proxy api) f (cl as)
456-- | If you use a 'QueryFlag' in one of your endpoints in your API,
498-- | If you use a 'QueryFlag' in one of your endpoints in your API,
457-- the corresponding querying function will automatically take
499-- the corresponding querying function will automatically take
458-- an additional 'Bool' argument.
500-- an additional 'Bool' argument.
@@ -489,6 +531,8 @@ instance (KnownSymbol sym, HasClient m api)
490 where paramname = pack $ symbolVal (Proxy :: Proxy sym)
532 where paramname = pack $ symbolVal (Proxy :: Proxy sym)
534+ hoistClientMonad pm _ f cl = \b ->
535+ hoistClientMonad pm (Proxy :: Proxy api) f (cl b)
493-- | Pick a 'Method' and specify where the server you want to query is. You get
537-- | Pick a 'Method' and specify where the server you want to query is. You get
494-- back the full `Response`.
538-- back the full `Response`.
@@ -500,6 +544,8 @@ instance RunClient m => HasClient m Raw where
500 clientWithRoute _pm Proxy req httpMethod = do
544 clientWithRoute _pm Proxy req httpMethod = do
501 runRequest req { requestMethod = httpMethod }
545 runRequest req { requestMethod = httpMethod }
547+ hoistClientMonad _ _ f cl = \meth -> f (cl meth)
503-- | If you use a 'ReqBody' in one of your endpoints in your API,
549-- | If you use a 'ReqBody' in one of your endpoints in your API,
504-- the corresponding querying function will automatically take
550-- the corresponding querying function will automatically take
505-- an additional argument of the type specified by your 'ReqBody'.
551-- an additional argument of the type specified by your 'ReqBody'.
@@ -533,6 +579,9 @@ instance (MimeRender ct a, HasClient m api)
582+ hoistClientMonad pm _ f cl = \a ->
583+ hoistClientMonad pm (Proxy :: Proxy api) f (cl a)
536-- | Make the querying function append @path@ to the request path.
585-- | Make the querying function append @path@ to the request path.
537instance (KnownSymbol path, HasClient m api) => HasClient m (path :> api) where
586instance (KnownSymbol path, HasClient m api) => HasClient m (path :> api) where
538 type Client m (path :> api) = Client m api
587 type Client m (path :> api) = Client m api
@@ -543,30 +592,40 @@ instance (KnownSymbol path, HasClient m api) => HasClient m (path :> api) where
544 where p = pack $ symbolVal (Proxy :: Proxy path)
593 where p = pack $ symbolVal (Proxy :: Proxy path)
595+ hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy api) f cl
546instance HasClient m api => HasClient m (Vault :> api) where
597instance HasClient m api => HasClient m (Vault :> api) where
547 type Client m (Vault :> api) = Client m api
598 type Client m (Vault :> api) = Client m api
549 clientWithRoute pm Proxy req =
600 clientWithRoute pm Proxy req =
550 clientWithRoute pm (Proxy :: Proxy api) req
601 clientWithRoute pm (Proxy :: Proxy api) req
603+ hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy api) f cl
552instance HasClient m api => HasClient m (RemoteHost :> api) where
605instance HasClient m api => HasClient m (RemoteHost :> api) where
553 type Client m (RemoteHost :> api) = Client m api
606 type Client m (RemoteHost :> api) = Client m api
555 clientWithRoute pm Proxy req =
608 clientWithRoute pm Proxy req =
556 clientWithRoute pm (Proxy :: Proxy api) req
609 clientWithRoute pm (Proxy :: Proxy api) req
611+ hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy api) f cl
558instance HasClient m api => HasClient m (IsSecure :> api) where
613instance HasClient m api => HasClient m (IsSecure :> api) where
559 type Client m (IsSecure :> api) = Client m api
614 type Client m (IsSecure :> api) = Client m api
561 clientWithRoute pm Proxy req =
616 clientWithRoute pm Proxy req =
562 clientWithRoute pm (Proxy :: Proxy api) req
617 clientWithRoute pm (Proxy :: Proxy api) req
619+ hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy api) f cl
564instance HasClient m subapi =>
621instance HasClient m subapi =>
565 HasClient m (WithNamedContext name context subapi) where
622 HasClient m (WithNamedContext name context subapi) where
567 type Client m (WithNamedContext name context subapi) = Client m subapi
624 type Client m (WithNamedContext name context subapi) = Client m subapi
568 clientWithRoute pm Proxy = clientWithRoute pm (Proxy :: Proxy subapi)
625 clientWithRoute pm Proxy = clientWithRoute pm (Proxy :: Proxy subapi)
627+ hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy subapi) f cl
570instance ( HasClient m api
629instance ( HasClient m api
571 ) => HasClient m (AuthProtect tag :> api) where
630 ) => HasClient m (AuthProtect tag :> api) where
572 type Client m (AuthProtect tag :> api)
631 type Client m (AuthProtect tag :> api)
@@ -575,6 +634,9 @@ instance ( HasClient m api
575 clientWithRoute pm Proxy req (AuthenticatedRequest (val,func)) =
634 clientWithRoute pm Proxy req (AuthenticatedRequest (val,func)) =
576 clientWithRoute pm (Proxy :: Proxy api) (func val req)
635 clientWithRoute pm (Proxy :: Proxy api) (func val req)
637+ hoistClientMonad pm _ f cl = \authreq ->
638+ hoistClientMonad pm (Proxy :: Proxy api) f (cl authreq)
578-- * Basic Authentication
640-- * Basic Authentication
580instance HasClient m api => HasClient m (BasicAuth realm usr :> api) where
642instance HasClient m api => HasClient m (BasicAuth realm usr :> api) where
@@ -583,6 +645,9 @@ instance HasClient m api => HasClient m (BasicAuth realm usr :> api) where
583 clientWithRoute pm Proxy req val =
645 clientWithRoute pm Proxy req val =
584 clientWithRoute pm (Proxy :: Proxy api) (basicAuthReq val req)
646 clientWithRoute pm (Proxy :: Proxy api) (basicAuthReq val req)
648+ hoistClientMonad pm _ f cl = \bauth ->
649+ hoistClientMonad pm (Proxy :: Proxy api) f (cl bauth)
587{- Note [Non-Empty Content Types]
652{- Note [Non-Empty Content Types]
588~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
653~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~