@@ -8,6 +8,7 @@
88{-# LANGUAGE MultiParamTypeClasses #-}
99{-# LANGUAGE OverloadedStrings #-}
1010{-# LANGUAGE PolyKinds #-}
11+{-# LANGUAGE Rank2Types #-}
1112{-# LANGUAGE ScopedTypeVariables #-}
1213{-# LANGUAGE TupleSections #-}
1314{-# LANGUAGE TypeFamilies #-}
@@ -25,7 +26,9 @@
2526module Servant.Reflex
2627 ( client
2728 , clientWithOpts
29+ , clientWithOptsAndResultHandler
2830 , clientWithRoute
31+ , clientWithRouteAndResultHandler
2932 , BuildHeaderKeysTo(..)
3033 , toHeaders
3134 , HasClient
@@ -36,39 +39,41 @@ module Servant.Reflex
3639
3740------------------------------------------------------------------------------
3841import Control.Applicative
39−import Data.Monoid ((<>))
40−import qualified Data.Set as Set
41−import qualified Data.Text.Encoding as E
42−import Data.CaseInsensitive (mk)
42+import qualified Data.CaseInsensitive as CI
4343import Data.Functor.Identity
44−import Data.Proxy (Proxy (..))
4544import qualified Data.Map as Map
45+import Data.Monoid ((<>))
46+import Data.Proxy (Proxy (..))
47+import qualified Data.Set as Set
4648import Data.Text (Text)
4749import qualified Data.Text as T
50+import qualified Data.Text.Encoding as E
4851import GHC.Exts (Constraint)
4952import GHC.TypeLits (KnownSymbol, symbolVal)
50−import Servant.API ((:<|>)(..),(:>), BasicAuth,
51− BasicAuthData, BuildHeadersTo(..),
52− Capture, contentType, Header,
53− Headers(..), HttpVersion, IsSecure,
54− MimeRender(..),
53+import Servant.API ((:<|>) (..), (:>), BasicAuth,
54+ BasicAuthData, BuildHeadersTo (..),
55+ Capture, Header, Headers (..),
56+ HttpVersion, IsSecure,
57+ MimeRender (..), MimeUnrender,
5558 NoContent, QueryFlag, QueryParam,
56− QueryParams, Raw, ReflectMethod(..),
59+ QueryParams, Raw, ReflectMethod (..),
5760 RemoteHost, ReqBody,
58− ToHttpApiData(..), Vault, Verb)
61+ ToHttpApiData (..), Vault, Verb,
62+ contentType)
63+import Servant.API.Description (Summary)
5964import qualified Servant.Auth as Auth
6065
6166import Reflex.Dom.Core (Dynamic, Event, Reflex,
62− XhrRequest(..),
63− XhrResponseHeaders(..),
64− XhrResponse(..), attachPromptlyDynWith, constDyn, ffor, fmapMaybe,
65− leftmost, performRequestsAsync,
66− )
67+ XhrRequest (..), XhrResponse (..),
68+ XhrResponseHeaders (..),
69+ attachPromptlyDynWith, constDyn, ffor,
70+ fmapMaybe, leftmost,
71+ performRequestsAsync)
6772------------------------------------------------------------------------------
6873import Servant.Common.BaseUrl (BaseUrl(..), Scheme(..), baseUrlWidget,
6974 showBaseUrl,
7075 SupportsServantReflex)
71−import Servant.Common.Req (ClientOptions(..), MimeUnrender(..),
76+import Servant.Common.Req (ClientOptions(..),
7277 defaultClientOptions,
7378 Req, ReqResult(..), QParam(..),
7479 QueryPart(..), addHeader, authData,
@@ -84,8 +89,6 @@ import Servant.Common.Req (ClientOptions(..), MimeUnrender(..),
8489 response,
8590 reqTag,
8691 qParams, withCredentials)
87−import Servant.Checked.Exceptions.Internal.Envelope (Envelope)
88−import Servant.Checked.Exceptions.Internal.Servant.API (NoThrow, Throws, Throwing, ThrowingNonterminal)
8992
9093
9194-- * Accessing APIs as a Client
@@ -100,7 +103,7 @@ import Servant.Checked.Exceptions.Internal.Servant.API (NoThrow, Throws, Throwin
100103-- >
101104-- > getAllBooks :: Event t l -> m (Event t (l, ReqResult [Book]))
102105-- > postNewBook :: Dynamic t (Maybe Book) -> Event t l
103−-- -> m (Event t (l, ReqResult Book)))
106+-- > -> m (Event t (l, ReqResult Book)))
104107-- > (getAllBooks :<|> postNewBook) = client myApi host
105108-- > where host = constDyn $ BaseUrl Http "localhost" 8080
106109client
@@ -122,21 +125,53 @@ clientWithOpts
122125 -> Client t m layout tag
123126clientWithOpts p q t baseurl = clientWithRoute p q t defReq baseurl
124127
128+-- | Like 'clientWithOpts' but allows passing a function which will process the
129+-- result event in some way. This can be used to handle errors in a uniform way
130+-- across call sites.
131+clientWithOptsAndResultHandler
132+ :: (HasClient t m layout tag)
133+ => Proxy layout
134+ -> Proxy m
135+ -> Proxy tag
136+ -> Dynamic t BaseUrl
137+ -> ClientOptions
138+ -> (forall a. Event t (ReqResult tag a) -> m (Event t (ReqResult tag a)))
139+ -> Client t m layout tag
140+clientWithOptsAndResultHandler p q t = clientWithRouteAndResultHandler p q t defReq
141+
125142
126143-- | This class lets us define how each API combinator
127144-- influences the creation of an HTTP request. It's mostly
128145-- an internal class, you can just use 'client'.
129−class HasClient t m layout (tag :: *) where
146+class Monad m => HasClient t m layout (tag :: *) where
130147 type Client t m layout tag :: *
131− clientWithRoute :: Proxy layout -> Proxy m -> Proxy tag -> Req t -> Dynamic t BaseUrl -> ClientOptions -> Client t m layout tag
148+ clientWithRoute
149+ :: Proxy layout
150+ -> Proxy m
151+ -> Proxy tag
152+ -> Req t
153+ -> Dynamic t BaseUrl
154+ -> ClientOptions
155+ -> Client t m layout tag
156+ clientWithRoute l m t r b o = clientWithRouteAndResultHandler l m t r b o return
157+
158+ clientWithRouteAndResultHandler
159+ :: Proxy layout
160+ -> Proxy m
161+ -> Proxy tag
162+ -> Req t
163+ -> Dynamic t BaseUrl
164+ -> ClientOptions
165+ -> (forall a. Event t (ReqResult tag a) -> m (Event t (ReqResult tag a)))
166+ -> Client t m layout tag
132167
133168
134169instance (HasClient t m a tag, HasClient t m b tag) => HasClient t m (a :<|> b) tag where
135170 type Client t m (a :<|> b) tag = Client t m a tag :<|> Client t m b tag
136171
137− clientWithRoute Proxy q pTag req baseurl opts =
138− clientWithRoute (Proxy :: Proxy a) q pTag req baseurl opts :<|>
139− clientWithRoute (Proxy :: Proxy b) q pTag req baseurl opts
172+ clientWithRouteAndResultHandler Proxy q pTag req baseurl opts wrap =
173+ clientWithRouteAndResultHandler (Proxy :: Proxy a) q pTag req baseurl opts wrap :<|>
174+ clientWithRouteAndResultHandler (Proxy :: Proxy b) q pTag req baseurl opts wrap
140175
141176
142177-- Capture. Example:
@@ -157,11 +192,9 @@ instance (SupportsServantReflex t m, ToHttpApiData a, HasClient t m sublayout ta
157192 type Client t m (Capture capture a :> sublayout) tag =
158193 Dynamic t (Either Text a) -> Client t m sublayout tag
159194
160− clientWithRoute Proxy q t req baseurl opts val =
161− clientWithRoute (Proxy :: Proxy sublayout)
162− q t
163− (prependToPathParts p req)
164− baseurl opts
195+ clientWithRouteAndResultHandler Proxy q t req baseurl opts wrap val =
196+ clientWithRouteAndResultHandler
197+ (Proxy :: Proxy sublayout) q t (prependToPathParts p req) baseurl opts wrap
165198 where p = (fmap . fmap) (toUrlPiece) val
166199
167200
@@ -174,8 +207,8 @@ instance {-# OVERLAPPABLE #-}
174207 Event t tag -> m (Event t (ReqResult tag a))
175208 -- TODO how to access input types here?
176209 -- ExceptT ServantError IO a
177− clientWithRoute Proxy _ _ req baseurl opts trigs =
178− fmap runIdentity <$> performRequestsCT (Proxy :: Proxy ct) method (constDyn $ Identity $ req') baseurl opts trigs
210+ clientWithRouteAndResultHandler Proxy _ _ req baseurl opts wrap trigs =
211+ wrap =<< fmap runIdentity <$> performRequestsCT (Proxy :: Proxy ct) method (constDyn $ Identity $ req') baseurl opts trigs
179212 where method = E.decodeUtf8 $ reflectMethod (Proxy :: Proxy method)
180213 req' = req { reqMethod = method }
181214
@@ -188,29 +221,33 @@ instance {-# OVERLAPPING #-}
188221 Event t tag -> m (Event t (ReqResult tag NoContent))
189222 -- TODO: how to access input types here?
190223 -- ExceptT ServantError IO NoContent
191− clientWithRoute Proxy _ _ req baseurl opts =
192− (fmap . fmap) runIdentity . performRequestsNoBody method (constDyn $ Identity req) baseurl opts
224+ clientWithRouteAndResultHandler Proxy _ _ req baseurl opts wrap trigs =
225+ wrap =<< fmap runIdentity <$> performRequestsNoBody method (constDyn $ Identity req) baseurl opts trigs
193226 where method = E.decodeUtf8 $ reflectMethod (Proxy :: Proxy method)
194227
195228
196229toHeaders :: BuildHeadersTo ls => ReqResult tag a -> ReqResult tag (Headers ls a)
197230toHeaders r =
198− let toBS = E.encodeUtf8
199− hdrs = maybe []
200− (\xhr -> fmap (\(h,v) -> (mk (toBS h), toBS v))
231+ let hdrs = maybe []
232+ (\xhr -> fmap (\(h,v) -> (CI.map E.encodeUtf8 h, E.encodeUtf8 v))
201233 (Map.toList $ _xhrResponse_headers xhr))
202234 (response r)
203235 in ffor r $ \a -> Headers {getResponse = a ,getHeadersHList = buildHeadersTo hdrs}
204236
237+
205238class BuildHeaderKeysTo hs where
206− buildHeaderKeysTo :: Proxy hs -> [T.Text]
239+ buildHeaderKeysTo :: Proxy hs -> [CI.CI T.Text]
207240
208241instance {-# OVERLAPPABLE #-} BuildHeaderKeysTo '[]
209242 where buildHeaderKeysTo _ = []
210243
211244instance {-# OVERLAPPABLE #-} (BuildHeaderKeysTo xs, KnownSymbol h)
212245 => BuildHeaderKeysTo ((Header h v) ': xs) where
213− buildHeaderKeysTo _ = T.pack (symbolVal (Proxy :: Proxy h)) : buildHeaderKeysTo (Proxy :: Proxy xs)
246+ buildHeaderKeysTo _ =
247+ let
248+ thisKey = CI.mk $ T.pack (symbolVal (Proxy :: Proxy h))
249+ in thisKey : buildHeaderKeysTo (Proxy :: Proxy xs)
250+
214251
215252-- HEADERS Verb (Content) --
216253-- Headers combinator not treated in fully general case,
@@ -225,10 +262,10 @@ instance {-# OVERLAPPABLE #-}
225262 ) => HasClient t m (Verb method status cts' (Headers ls a)) tag where
226263 type Client t m (Verb method status cts' (Headers ls a)) tag =
227264 Event t tag -> m (Event t (ReqResult tag (Headers ls a)))
228− clientWithRoute Proxy _ _ req baseurl opts trigs = do
265+ clientWithRouteAndResultHandler Proxy _ _ req baseurl opts wrap trigs = do
229266 let method = E.decodeUtf8 $ reflectMethod (Proxy :: Proxy method)
230267 resp <- fmap runIdentity <$> performRequestsCT (Proxy :: Proxy ct) method (constDyn $ Identity req') baseurl opts trigs
231− return $ toHeaders <$> resp
268+ wrap $ toHeaders <$> resp
232269 where req' = req { respHeaders =
233270 OnlyHeaders (Set.fromList (buildHeaderKeysTo (Proxy :: Proxy ls)))
234271 }
@@ -241,10 +278,10 @@ instance {-# OVERLAPPABLE #-}
241278 ) => HasClient t m (Verb method status cts (Headers ls NoContent)) tag where
242279 type Client t m (Verb method status cts (Headers ls NoContent)) tag
243280 = Event t tag -> m (Event t (ReqResult tag (Headers ls NoContent)))
244− clientWithRoute Proxy _ _ req baseurl opts trigs = do
281+ clientWithRouteAndResultHandler Proxy _ _ req baseurl opts wrap trigs = do
245282 let method = E.decodeUtf8 $ reflectMethod (Proxy :: Proxy method)
246283 resp <- fmap runIdentity <$> performRequestsNoBody method (constDyn $ Identity req') baseurl opts trigs
247− return $ toHeaders <$> resp
284+ wrap $ toHeaders <$> resp
248285 where req' = req {respHeaders =
249286 OnlyHeaders (Set.fromList (buildHeaderKeysTo (Proxy :: Proxy ls)))
250287 }
@@ -271,11 +308,11 @@ instance (KnownSymbol sym, ToHttpApiData a,
271308 type Client t m (Header sym a :> sublayout) tag =
272309 Dynamic t (Either Text a) -> Client t m sublayout tag
273310
274− clientWithRoute Proxy q t req baseurl opts eVal =
275− clientWithRoute (Proxy :: Proxy sublayout)
276− q t
277− (Servant.Common.Req.addHeader hname eVal req)
278− baseurl opts
311+ clientWithRouteAndResultHandler Proxy q t req baseurl opts wrap eVal =
312+ clientWithRouteAndResultHandler
313+ (Proxy :: Proxy sublayout) q t
314+ (Servant.Common.Req.addHeader hname eVal req)
315+ baseurl opts wrap
279316 where hname = T.pack $ symbolVal (Proxy :: Proxy sym)
280317
281318
@@ -289,8 +326,21 @@ instance HasClient t m sublayout tag
289326 type Client t m (HttpVersion :> sublayout) tag =
290327 Client t m sublayout tag
291328
292− clientWithRoute Proxy q t =
293− clientWithRoute (Proxy :: Proxy sublayout) q t
329+ clientWithRouteAndResultHandler Proxy =
330+ clientWithRouteAndResultHandler (Proxy :: Proxy sublayout)
331+
332+-- | Using a 'Summary' combinator in your API doesn't affect the client
333+-- functions.
334+instance (HasClient t m sublayout tag, KnownSymbol sym)
335+ => HasClient t m (Summary sym :> sublayout) tag where
336+
337+ type Client t m (Summary sym :> sublayout) tag =
338+ Client t m sublayout tag
339+
340+ clientWithRouteAndResultHandler Proxy =
341+ clientWithRouteAndResultHandler (Proxy :: Proxy sublayout)
342+
343+
294344
295345
296346-- | If you use a 'QueryParam' in one of your endpoints in your API,
@@ -326,9 +376,9 @@ instance (KnownSymbol sym, ToHttpApiData a, HasClient t m sublayout tag, Reflex
326376 Dynamic t (QParam a) -> Client t m sublayout tag
327377
328378 -- if mparam = Nothing, we don't add it to the query string
329− clientWithRoute Proxy q t req baseurl opts mparam =
330− clientWithRoute (Proxy :: Proxy sublayout) q t
331− (req {qParams = paramPair : qParams req}) baseurl opts
379+ clientWithRouteAndResultHandler Proxy q t req baseurl opts wrap mparam =
380+ clientWithRouteAndResultHandler (Proxy :: Proxy sublayout) q t
381+ (req {qParams = paramPair : qParams req}) baseurl opts wrap
332382
333383 where pname = symbolVal (Proxy :: Proxy sym)
334384 --p prm = QueryPartParam $ (fmap . fmap) (toQueryParam) prm
@@ -372,8 +422,8 @@ instance (KnownSymbol sym, ToHttpApiData a, HasClient t m sublayout tag, Reflex
372422 type Client t m (QueryParams sym a :> sublayout) tag =
373423 Dynamic t [a] -> Client t m sublayout tag
374424
375− clientWithRoute Proxy q t req baseurl opts paramlist =
376− clientWithRoute (Proxy :: Proxy sublayout) q t req' baseurl opts
425+ clientWithRouteAndResultHandler Proxy q t req baseurl opts wrap paramlist =
426+ clientWithRouteAndResultHandler (Proxy :: Proxy sublayout) q t req' baseurl opts wrap
377427
378428 where req' = req { qParams = (T.pack pname, params') : qParams req }
379429 pname = symbolVal (Proxy :: Proxy sym)
@@ -412,8 +462,8 @@ instance (KnownSymbol sym, HasClient t m sublayout tag, Reflex t)
412462 type Client t m (QueryFlag sym :> sublayout) tag =
413463 Dynamic t Bool -> Client t m sublayout tag
414464
415− clientWithRoute Proxy q t req baseurl opts flag =
416− clientWithRoute (Proxy :: Proxy sublayout) q t req' baseurl opts
465+ clientWithRouteAndResultHandler Proxy q t req baseurl opts wrap flag =
466+ clientWithRouteAndResultHandler (Proxy :: Proxy sublayout) q t req' baseurl opts wrap
417467
418468 where req' = req { qParams = thisPair : qParams req }
419469 thisPair = (T.pack pName, QueryPartFlag flag) :: (Text, QueryPart t)
@@ -427,7 +477,7 @@ instance SupportsServantReflex t m => HasClient t m Raw tag where
427477 -> Event t tag
428478 -> m (Event t (ReqResult tag ()))
429479
430− clientWithRoute _ _ _ _ baseurl _ xhrs triggers = do
480+ clientWithRouteAndResultHandler _ _ _ _ baseurl _ wrap xhrs triggers = do
431481
432482 let xhrs' = liftA2 (\x path -> case x of
433483 Left e -> Left e
@@ -438,7 +488,7 @@ instance SupportsServantReflex t m => HasClient t m Raw tag where
438488 okReq = fmapMaybe (\(t,x) -> either (const Nothing) (Just . (t,)) x) xhrs'' :: Event t (tag, XhrRequest ())
439489
440490 resps <- performRequestsAsync okReq
441− return $ leftmost [ uncurry RequestFailure <$> badReq
491+ wrap $ leftmost [ uncurry RequestFailure <$> badReq
442492 , evalResponse (const $ Right ()) <$> resps
443493 ]
444494
@@ -469,8 +519,8 @@ instance (MimeRender ct a, HasClient t m sublayout tag, Reflex t)
469519 type Client t m (ReqBody (ct ': cts) a :> sublayout) tag =
470520 Dynamic t (Either Text a) -> Client t m sublayout tag
471521
472− clientWithRoute Proxy q t req baseurl opts body =
473− clientWithRoute (Proxy :: Proxy sublayout) q t req' baseurl opts
522+ clientWithRouteAndResultHandler Proxy q t req baseurl opts wrap body =
523+ clientWithRouteAndResultHandler (Proxy :: Proxy sublayout) q t req' baseurl opts wrap
474524 where req' = req { reqBody = bodyBytesCT }
475525 ctProxy = Proxy :: Proxy ct
476526 ctString = T.pack $ show $ contentType ctProxy
@@ -484,9 +534,9 @@ instance (MimeRender ct a, HasClient t m sublayout tag, Reflex t)
484534instance (KnownSymbol path, HasClient t m sublayout tag, Reflex t) => HasClient t m (path :> sublayout) tag where
485535 type Client t m (path :> sublayout) tag = Client t m sublayout tag
486536
487− clientWithRoute Proxy q t req baseurl opts =
488− clientWithRoute (Proxy :: Proxy sublayout) q t
489− (prependToPathParts (pure (Right $ T.pack p)) req) baseurl opts
537+ clientWithRouteAndResultHandler Proxy q t req baseurl opts wrap =
538+ clientWithRouteAndResultHandler (Proxy :: Proxy sublayout) q t
539+ (prependToPathParts (pure (Right $ T.pack p)) req) baseurl opts wrap
490540
491541 where p = symbolVal (Proxy :: Proxy path)
492542
@@ -494,23 +544,23 @@ instance (KnownSymbol path, HasClient t m sublayout tag, Reflex t) => HasClient
494544instance HasClient t m api tag => HasClient t m (Vault :> api) tag where
495545 type Client t m (Vault :> api) tag = Client t m api tag
496546
497− clientWithRoute Proxy q t req baseurl =
498− clientWithRoute (Proxy :: Proxy api) q t req baseurl
547+ clientWithRouteAndResultHandler Proxy =
548+ clientWithRouteAndResultHandler (Proxy :: Proxy api)
499549
500550
501551instance HasClient t m api tag => HasClient t m (RemoteHost :> api) tag where
502552 type Client t m (RemoteHost :> api) tag = Client t m api tag
503553
504− clientWithRoute Proxy q t req baseurl =
505− clientWithRoute (Proxy :: Proxy api) q t req baseurl
554+ clientWithRouteAndResultHandler Proxy =
555+ clientWithRouteAndResultHandler (Proxy :: Proxy api)
506556
507557
508558
509559instance HasClient t m api tag => HasClient t m (IsSecure :> api) tag where
510560 type Client t m (IsSecure :> api) tag = Client t m api tag
511561
512− clientWithRoute Proxy q t req baseurl =
513− clientWithRoute (Proxy :: Proxy api) q t req baseurl
562+ clientWithRouteAndResultHandler Proxy =
563+ clientWithRouteAndResultHandler (Proxy :: Proxy api)
514564
515565
516566instance (HasClient t m api tag, Reflex t)
@@ -519,8 +569,8 @@ instance (HasClient t m api tag, Reflex t)
519569 type Client t m (BasicAuth realm usr :> api) tag = Dynamic t (Maybe BasicAuthData)
520570 -> Client t m api tag
521571
522− clientWithRoute Proxy q t req baseurl opts authdata =
523− clientWithRoute (Proxy :: Proxy api) q t req' baseurl opts
572+ clientWithRouteAndResultHandler Proxy q t req baseurl opts wrap authdata =
573+ clientWithRouteAndResultHandler (Proxy :: Proxy api) q t req' baseurl opts wrap
524574 where
525575 req' = req { authData = Just authdata }
526576
@@ -563,7 +613,7 @@ for empty and one for non-empty lists).
563613instance (HasCookieAuth auths, HasClient t m api tag) => HasClient t m (Auth.Auth auths a :> api) tag where
564614
565615 type Client t m (Auth.Auth auths a :> api) tag = Client t m api tag
566− clientWithRoute Proxy = clientWithRoute (Proxy :: Proxy api)
616+ clientWithRouteAndResultHandler Proxy = clientWithRouteAndResultHandler (Proxy :: Proxy api)
567617
568618
569619type family HasCookieAuth xs :: Constraint where
@@ -573,136 +623,3 @@ type family HasCookieAuth xs :: Constraint where
573623
574624class CookieAuthNotEnabled
575625
576−{- servant-checked-exceptions
577−~~~~~~~~~~~~~~~~~~~~~
578−-}
579−
580−-- | Change a 'Throws' into 'Throwing'.
581−instance (HasClient t m (Throwing '[e] :> api) tag) => HasClient t m (Throws e :> api) tag where
582− type Client t m (Throws e :> api) tag = Client t m (Throwing '[e] :> api) tag
583−
584− clientWithRoute
585− :: Proxy (Throws e :> api)
586− -> Proxy m
587− -> Proxy tag
588− -> Req t
589− -> Dynamic t BaseUrl
590− -> ClientOptions
591− -> Client t m (Throwing '[e] :> api) tag
592− clientWithRoute _ = clientWithRoute (Proxy :: Proxy (Throwing '[e] :> api))
593−
594−-- | When @'Throwing' es@ comes before a 'Verb', change it into the same 'Verb'
595−-- but returning an @'Envelope' es@.
596−instance (HasClient t m (Verb method status ctypes (Envelope es a)) tag) =>
597− HasClient t m (Throwing es :> Verb method status ctypes a) tag where
598−
599− type Client t m (Throwing es :> Verb method status ctypes a) tag =
600− Client t m (Verb method status ctypes (Envelope es a)) tag
601−
602− clientWithRoute
603− :: Proxy (Throwing es :> Verb method status ctypes a)
604− -> Proxy m
605− -> Proxy tag
606− -> Req t
607− -> Dynamic t BaseUrl
608− -> ClientOptions
609− -> Client t m (Verb method status ctypes (Envelope es a)) tag
610− clientWithRoute Proxy =
611− clientWithRoute (Proxy :: Proxy (Verb method status ctypes (Envelope es a)))
612−
613−-- | When 'NoThrow' comes before a 'Verb', change it into the same 'Verb'
614−-- but returning an @'Envelope' \'[]@.
615−instance (HasClient t m (Verb method status ctypes (Envelope '[] a)) tag) =>
616− HasClient t m (NoThrow :> Verb method status ctypes a) tag where
617−
618− type Client t m (NoThrow :> Verb method status ctypes a) tag =
619− Client t m (Verb method status ctypes (Envelope '[] a)) tag
620−
621− clientWithRoute
622− :: Proxy (NoThrow :> Verb method status ctypes a)
623− -> Proxy m
624− -> Proxy tag
625− -> Req t
626− -> Dynamic t BaseUrl
627− -> ClientOptions
628− -> Client t m (Verb method status ctypes (Envelope '[] a)) tag
629− clientWithRoute Proxy =
630− clientWithRoute (Proxy :: Proxy (Verb method status ctypes (Envelope '[] a)))
631−
632−-- | When @'Throwing' es@ comes before ':<|>', push @'Throwing' es@ into each
633−-- branch of the API.
634−instance HasClient t m ((Throwing es :> api1) :<|> (Throwing es :> api2)) tag =>
635− HasClient t m (Throwing es :> (api1 :<|> api2)) tag where
636−
637− type Client t m (Throwing es :> (api1 :<|> api2)) tag =
638− Client t m ((Throwing es :> api1) :<|> (Throwing es :> api2)) tag
639−
640− clientWithRoute
641− :: Proxy (Throwing es :> (api1 :<|> api2))
642− -> Proxy m
643− -> Proxy tag
644− -> Req t
645− -> Dynamic t BaseUrl
646− -> ClientOptions
647− -> Client t m ((Throwing es :> api1) :<|> (Throwing es :> api2)) tag
648− clientWithRoute _ =
649− clientWithRoute (Proxy :: Proxy ((Throwing es :> api1) :<|> (Throwing es :> api2)))
650−
651−-- | When 'NoThrow' comes before ':<|>', push 'NoThrow' into each branch of the
652−-- API.
653−instance HasClient t m ((NoThrow :> api1) :<|> (NoThrow :> api2)) tag =>
654− HasClient t m (NoThrow :> (api1 :<|> api2)) tag where
655−
656− type Client t m (NoThrow :> (api1 :<|> api2)) tag =
657− Client t m ((NoThrow :> api1) :<|> (NoThrow :> api2)) tag
658−
659− clientWithRoute
660− :: Proxy (NoThrow :> (api1 :<|> api2))
661− -> Proxy m
662− -> Proxy tag
663− -> Req t
664− -> Dynamic t BaseUrl
665− -> ClientOptions
666− -> Client t m ((NoThrow :> api1) :<|> (NoThrow :> api2)) tag
667− clientWithRoute _ =
668− clientWithRoute (Proxy :: Proxy ((NoThrow :> api1) :<|> (NoThrow :> api2)))
669−
670−-- | When a @'Throws' e@ comes immediately after a @'Throwing' es@, 'Snoc' the
671−-- @e@ onto the @es@. Otherwise, if @'Throws' e@ comes before any other
672−-- combinator, push it down so it is closer to the 'Verb'.
673−instance HasClient t m (ThrowingNonterminal (Throwing es :> api :> apis)) tag =>
674− HasClient t m (Throwing es :> api :> apis) tag where
675−
676− type Client t m (Throwing es :> api :> apis) tag =
677− Client t m (ThrowingNonterminal (Throwing es :> api :> apis)) tag
678−
679− clientWithRoute
680− :: Proxy (Throwing es :> api :> apis)
681− -> Proxy m
682− -> Proxy tag
683− -> Req t
684− -> Dynamic t BaseUrl
685− -> ClientOptions
686− -> Client t m (ThrowingNonterminal (Throwing es :> api :> apis)) tag
687− clientWithRoute _ =
688− clientWithRoute (Proxy :: Proxy (ThrowingNonterminal (Throwing es :> api :> apis)))
689−
690−-- | When 'NoThrow' comes before any other combinator, push it down so it is
691−-- closer to the 'Verb'.
692−instance HasClient t m (api :> NoThrow :> apis) tag =>
693− HasClient t m (NoThrow :> api :> apis) tag where
694−
695− type Client t m (NoThrow :> api :> apis) tag =
696− Client t m (api :> NoThrow :> apis) tag
697−
698− clientWithRoute
699− :: Proxy (NoThrow :> api :> apis)
700− -> Proxy m
701− -> Proxy tag
702− -> Req t
703− -> Dynamic t BaseUrl
704− -> ClientOptions
705− -> Client t m (api :> NoThrow :> apis) tag
706− clientWithRoute _ =
707− clientWithRoute (Proxy :: Proxy (api :> NoThrow :> apis))
708−