git.iko.soy/typeable/servant-reflex
on 11cb165 help sign in
.gitignore−2
since splitsnapshots
unifiedsplit
@@ -7,5 +7,3 @@ log
7*.stats
7*.stats
8out
8out
9/.stack-work/
9/.stack-work/
10−TAGS
11−dist-newstyle
README.md+1−1
@@ -7,7 +7,7 @@
7Keeping your frontend in sync with your API server can be difficult - when the
7Keeping your frontend in sync with your API server can be difficult - when the
8API changes its input parameters or return type, XHR requests from the
8API changes its input parameters or return type, XHR requests from the
9frontend will fail at runtime. If your API is defined by
9frontend will fail at runtime. If your API is defined by
10−[servant](https://haskell-servant.readthedocs.io) combinators, you can use
10+[servant](haskell-servant.readthedocs.io) combinators, you can use
11`servant-reflex` to share the API between the server and frontend.
11`servant-reflex` to share the API between the server and frontend.
12Syncronization between is checked at compile time, and rather than building XHR
12Syncronization between is checked at compile time, and rather than building XHR
13requests by hand, API endpoints are available behind `reflex`'s FRP semantics.
13requests by hand, API endpoints are available behind `reflex`'s FRP semantics.
nix/reflex-platform.nix+2−2
@@ -1,7 +1,7 @@
1let
1let
2− rev = "1aba6f367982bd6dd78ec2fda75ab246a62d32c5" ;
2+ rev = "df0bdcca5eb2a3236ec0496e4430d91876b29cf5";
3in import (builtins.fetchTarball
3in import (builtins.fetchTarball
4 {
4 {
5 url = "https://github.com/reflex-frp/reflex-platform/archive/${rev}.tar.gz";
5 url = "https://github.com/reflex-frp/reflex-platform/archive/${rev}.tar.gz";
6− sha256 = "137vg6i8yy4lp6rz4wbvvhfcc9d9qf7j1b3fnng3r7sj63k7j664" ;
6+ sha256 = "1ja3vkq9px8f9iyiazq44mamaahgiphi9l236pvzbl5jvhi5c4qr";
7 }) {}
7 }) {}
servant-reflex.cabal+2−2
@@ -37,9 +37,9 @@ library
37 mtl >= 2.2.1 && < 2.3,
37 mtl >= 2.2.1 && < 2.3,
38 network-uri >= 2.6 && < 2.7,
38 network-uri >= 2.6 && < 2.7,
39 reflex >= 0.5 && < 0.9,
39 reflex >= 0.5 && < 0.9,
40− reflex-dom-core >= 0.6 && < 0.8,
40+ reflex-dom-core >= 0.6 && < 0.7,
41 safe >= 0.3.9 && < 0.4,
41 safe >= 0.3.9 && < 0.4,
42− servant >= 0.16 && < 0.19,
42+ servant >= 0.16 && < 0.18,
43 servant-auth >= 0.2.1 && < 0.4,
43 servant-auth >= 0.2.1 && < 0.4,
44 string-conversions >= 0.4 && < 0.5,
44 string-conversions >= 0.4 && < 0.5,
45 text >= 1.2 && < 1.3,
45 text >= 1.2 && < 1.3,
src/Servant/Common/BaseUrl.hs+1−5
@@ -1,5 +1,4 @@
1{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
2−{-# LANGUAGE CPP #-}
3{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE DeriveDataTypeable #-}
4{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
5{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleContexts #-}
@@ -32,11 +31,8 @@ import Reflex
32import Reflex.Dom.Core
31import Reflex.Dom.Core
33import Text.Read
32import Text.Read
34
33
35−#if !MIN_VERSION_reflex_dom_core(0,7,0)
34+
36type SupportsServantReflex t m = (Reflex t, TriggerEvent t m, PerformEvent t m, HasWebView (Performable m), MonadJSM (Performable m))
35type SupportsServantReflex t m = (Reflex t, TriggerEvent t m, PerformEvent t m, HasWebView (Performable m), MonadJSM (Performable m))
37−#else
38−type SupportsServantReflex t m = (Reflex t, TriggerEvent t m, PerformEvent t m, MonadJSM (Performable m))
39−#endif
40
36
41-- | URI scheme to use
37-- | URI scheme to use
42data Scheme =
38data Scheme =
src/Servant/Common/Req.hs+1−2
@@ -298,9 +298,7 @@ performRequests reqMeth rs reqHost opts trigger = do
298performSomeRequestsAsync
298performSomeRequestsAsync
299 :: (MonadIO (Performable m),
299 :: (MonadIO (Performable m),
300 MonadJSM (Performable m),
300 MonadJSM (Performable m),
301−#if !MIN_VERSION_reflex_dom_core(0,7,0)
302 HasWebView (Performable m),
301 HasWebView (Performable m),
303−#endif
304 PerformEvent t m,
302 PerformEvent t m,
305 TriggerEvent t m,
303 TriggerEvent t m,
306 Traversable f,
304 Traversable f,
@@ -430,3 +428,4 @@ builderToText = TE.decodeUtf8 . BL.toStrict . Builder.toLazyByteString
430
428
431escape :: T.Text -> T.Text
429escape :: T.Text -> T.Text
432escape = T.pack . N.escapeURIString (not . N.isReserved) . T.unpack . TE.decodeUtf8 . BL.toStrict . Builder.toLazyByteString . toEncodedUrlPiece
430escape = T.pack . N.escapeURIString (not . N.isReserved) . T.unpack . TE.decodeUtf8 . BL.toStrict . Builder.toLazyByteString . toEncodedUrlPiece
431+
src/Servant/Reflex.hs+20−34
@@ -39,36 +39,34 @@ module Servant.Reflex
39
39
40------------------------------------------------------------------------------
40------------------------------------------------------------------------------
41import Control.Applicative
41import Control.Applicative
42+import Data.Monoid ((<>))
43+import qualified Data.Set as Set
44+import qualified Data.Text.Encoding as E
42import qualified Data.CaseInsensitive as CI
45import qualified Data.CaseInsensitive as CI
43import Data.Functor.Identity
46import Data.Functor.Identity
44−import qualified Data.Map as Map
45−import Data.Monoid ((<>))
46import Data.Proxy (Proxy (..))
47import Data.Proxy (Proxy (..))
47−import qualified Data.Set as Set
48+import qualified Data.Map as Map
48import Data.Text (Text)
49import Data.Text (Text)
49import qualified Data.Text as T
50import qualified Data.Text as T
50−import qualified Data.Text.Encoding as E
51import GHC.Exts (Constraint)
51import GHC.Exts (Constraint)
52import GHC.TypeLits (KnownSymbol, symbolVal)
52import GHC.TypeLits (KnownSymbol, symbolVal)
53−import Servant.API ((:<|>) (..), (:>), BasicAuth,
53+import Servant.API ((:<|>)(..),(:>), BasicAuth,
54− BasicAuthData, BuildHeadersTo (..),
54+ BasicAuthData, BuildHeadersTo(..),
55− Capture, Header, Headers (..),
55+ Capture, contentType, Header,
56− HttpVersion, IsSecure,
56+ Headers(..), HttpVersion, IsSecure,
57− MimeRender (..), MimeUnrender,
57+ MimeRender(..), MimeUnrender,
58− NoContent, QueryFlag, QueryParam',
58+ NoContent, QueryFlag, QueryParam,
59− QueryParams, Raw, ReflectMethod (..),
59+ QueryParams, Raw, ReflectMethod(..),
60 RemoteHost, ReqBody,
60 RemoteHost, ReqBody,
61− ToHttpApiData (..), Vault, Verb,
61+ ToHttpApiData(..), Vault, Verb)
62− contentType)
63−import Servant.API.Description (Summary)
64import qualified Servant.Auth as Auth
62import qualified Servant.Auth as Auth
65
63
66import Reflex.Dom.Core (Dynamic, Event, Reflex,
64import Reflex.Dom.Core (Dynamic, Event, Reflex,
67− XhrRequest (..), XhrResponse (..),
65+ XhrRequest(..),
68− XhrResponseHeaders (..),
66+ XhrResponseHeaders(..),
69− attachPromptlyDynWith, constDyn, ffor,
67+ XhrResponse(..), attachPromptlyDynWith, constDyn, ffor, fmapMaybe,
70− fmapMaybe, leftmost,
71− performRequestsAsync)
68+ leftmost, performRequestsAsync,
69+ )
72------------------------------------------------------------------------------
70------------------------------------------------------------------------------
73import Servant.Common.BaseUrl (BaseUrl(..), Scheme(..), baseUrlWidget,
71import Servant.Common.BaseUrl (BaseUrl(..), Scheme(..), baseUrlWidget,
74 showBaseUrl,
72 showBaseUrl,
@@ -329,19 +327,6 @@ instance HasClient t m sublayout tag
329 clientWithRouteAndResultHandler Proxy =
327 clientWithRouteAndResultHandler Proxy =
330 clientWithRouteAndResultHandler (Proxy :: Proxy sublayout)
328 clientWithRouteAndResultHandler (Proxy :: Proxy sublayout)
331
329
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−
344−
345
330
346-- | If you use a 'QueryParam' in one of your endpoints in your API,
331-- | If you use a 'QueryParam' in one of your endpoints in your API,
347-- the corresponding querying function will automatically take
332-- the corresponding querying function will automatically take
@@ -370,9 +355,9 @@ instance (HasClient t m sublayout tag, KnownSymbol sym)
370-- > -- 'getBooksBy Nothing' for all books
355-- > -- 'getBooksBy Nothing' for all books
371-- > -- 'getBooksBy (Just "Isaac Asimov")' to get all books by Isaac Asimov
356-- > -- 'getBooksBy (Just "Isaac Asimov")' to get all books by Isaac Asimov
372instance (KnownSymbol sym, ToHttpApiData a, HasClient t m sublayout tag, Reflex t)
357instance (KnownSymbol sym, ToHttpApiData a, HasClient t m sublayout tag, Reflex t)
373− => HasClient t m (QueryParam' mods sym a :> sublayout) tag where
358+ => HasClient t m (QueryParam sym a :> sublayout) tag where
374
359
375− type Client t m (QueryParam' mods sym a :> sublayout) tag =
360+ type Client t m (QueryParam sym a :> sublayout) tag =
376 Dynamic t (QParam a) -> Client t m sublayout tag
361 Dynamic t (QParam a) -> Client t m sublayout tag
377
362
378 -- if mparam = Nothing, we don't add it to the query string
363 -- if mparam = Nothing, we don't add it to the query string
@@ -622,3 +607,4 @@ type family HasCookieAuth xs :: Constraint where
622 HasCookieAuth '[] = CookieAuthNotEnabled
607 HasCookieAuth '[] = CookieAuthNotEnabled
623
608
624class CookieAuthNotEnabled
609class CookieAuthNotEnabled
610+
src/Servant/Reflex/Multi.hs+22−35
@@ -37,30 +37,28 @@ module Servant.Reflex.Multi (
37 ) where
37 ) where
38
38
39------------------------------------------------------------------------------
39------------------------------------------------------------------------------
40−import Control.Applicative (liftA2)
40+import Control.Applicative (liftA2)
41−import Data.Functor.Compose (Compose (..), getCompose)
41+import Data.Functor.Compose (Compose (..), getCompose)
42−import Data.Proxy (Proxy (..))
42+import Data.Proxy (Proxy (..))
43−import qualified Data.Set as Set
43+import qualified Data.Set as Set
44−import Data.Text (Text)
44+import Data.Text (Text)
45−import qualified Data.Text as T
45+import qualified Data.Text as T
46−import qualified Data.Text.Encoding as E
46+import qualified Data.Text.Encoding as E
47−import GHC.TypeLits (KnownSymbol, symbolVal)
47+import GHC.TypeLits (KnownSymbol, symbolVal)
48−import Servant.API ((:<|>) (..), (:>), BasicAuth,
48+import Servant.API ((:<|>) (..), (:>), BasicAuth,
49− BasicAuthData, BuildHeadersTo (..),
49+ BasicAuthData, BuildHeadersTo (..),
50− Capture, Header, Headers (..),
50+ Capture, Header, Headers (..),
51− HttpVersion, IsSecure,
51+ HttpVersion, IsSecure, MimeRender (..),
52− MimeRender (..), MimeUnrender,
53− NoContent, QueryFlag, QueryParam,
52+ MimeUnrender, NoContent, QueryFlag,
54− QueryParams, Raw, ReflectMethod (..),
53+ QueryParam, QueryParams, Raw,
55− RemoteHost, ReqBody,
54+ ReflectMethod (..), RemoteHost,
56− ToHttpApiData (..), Vault, Verb,
55+ ReqBody, ToHttpApiData (..), Vault,
57− contentType)
56+ Verb, contentType)
58−import Servant.API.Description (Summary)
57+
59−
60−import Reflex.Dom.Core (Dynamic, Event, Reflex,
58+import Reflex.Dom.Core (Dynamic, Event, Reflex,
61− XhrRequest (..),
59+ XhrRequest (..),
62− XhrResponseHeaders (..),
60+ XhrResponseHeaders (..),
63− attachPromptlyDynWith, constDyn)
61+ attachPromptlyDynWith, constDyn)
64------------------------------------------------------------------------------
62------------------------------------------------------------------------------
65import Servant.Common.BaseUrl (BaseUrl (..), Scheme (..),
63import Servant.Common.BaseUrl (BaseUrl (..), Scheme (..),
66 SupportsServantReflex)
64 SupportsServantReflex)
@@ -242,17 +240,6 @@ instance HasClientMulti t m sublayout f tag
242 clientWithRouteMulti (Proxy :: Proxy sublayout) q f tag
240 clientWithRouteMulti (Proxy :: Proxy sublayout) q f tag
243
241
244
242
245−------------------------------------------------------------------------------
246−instance (HasClientMulti t m sublayout f tag, KnownSymbol sym)
247− => HasClientMulti t m (Summary sym :> sublayout) f tag where
248−
249− type ClientMulti t m (Summary sym :> sublayout) f tag =
250− ClientMulti t m sublayout f tag
251−
252− clientWithRouteMulti Proxy q f tag =
253− clientWithRouteMulti (Proxy :: Proxy sublayout) q f tag
254−
255−
256------------------------------------------------------------------------------
243------------------------------------------------------------------------------
257instance (KnownSymbol sym,
244instance (KnownSymbol sym,
258 ToHttpApiData a,
245 ToHttpApiData a,