packages feed

servant-js 0.7.1 → 0.8

raw patch · 5 files changed

+32/−28 lines, 5 filesdep ~servantdep ~servant-foreigndep ~servant-server

Dependency ranges changed: servant, servant-foreign, servant-server

Files

servant-js.cabal view
@@ -1,5 +1,5 @@ name:                servant-js-version:             0.7.1+version:             0.8 synopsis:            Automatically derive javascript functions to query servant webservices. description:   Automatically derive javascript functions to query servant webservices.@@ -45,7 +45,8 @@                      , base-compat     >= 0.9                      , charset         >= 0.3                      , lens            >= 4-                     , servant-foreign == 0.7.*+                     , servant-foreign == 0.8.*+                     , servant         == 0.8.*                      , text            >= 1.2  && < 1.3    hs-source-dirs:      src@@ -67,8 +68,8 @@                   , aeson            >= 0.7  && < 0.12                   , filepath         >= 1                   , lens             >= 4-                  , servant          == 0.7.*-                  , servant-server   == 0.7.*+                  , servant          == 0.8.*+                  , servant-server   == 0.8.*                   , servant-js                   , stm                   , transformers
src/Servant/JS.hs view
@@ -118,6 +118,7 @@ import           Data.Proxy import           Data.Text import           Data.Text.IO        (writeFile)+import           Servant.API.ContentTypes import           Servant.JS.Angular import           Servant.JS.Axios import           Servant.JS.Internal@@ -128,22 +129,22 @@ -- | Generate the data necessary to generate javascript code --   for all the endpoints of an API, as ':<|>'-separated values --   of type 'AjaxReq'.-javascript :: HasForeign NoTypes () layout => Proxy layout -> Foreign () layout-javascript p = foreignFor (Proxy :: Proxy NoTypes) (Proxy :: Proxy ()) p defReq+javascript :: HasForeign NoTypes NoContent api => Proxy api -> Foreign NoContent api+javascript p = foreignFor (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) p defReq  -- | Directly generate all the javascript functions for your API --   from a 'Proxy' for your API type. You can then write it to --   a file or integrate it in a page, for example.-jsForAPI :: (HasForeign NoTypes () api, GenerateList () (Foreign () api))+jsForAPI :: (HasForeign NoTypes NoContent api, GenerateList NoContent (Foreign NoContent api))          => Proxy api -- ^ proxy for your API type          -> JavaScriptGenerator -- ^ js code generator to use (angular, vanilla js, jquery, others)          -> Text                -- ^ a text that you can embed in your pages or write to a file-jsForAPI p gen = gen (listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy ()) p)+jsForAPI p gen = gen (listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) p)  -- | Directly generate all the javascript functions for your API --   from a 'Proxy' for your API type using the given generator --   and write the resulting code to a file at the given path.-writeJSForAPI :: (HasForeign NoTypes () api, GenerateList () (Foreign () api))+writeJSForAPI :: (HasForeign NoTypes NoContent api, GenerateList NoContent (Foreign NoContent api))               => Proxy api -- ^ proxy for your API type               -> JavaScriptGenerator -- ^ js code generator to use (angular, vanilla js, jquery, others)               -> FilePath -- ^ path to the file you want to write the resulting javascript code into
src/Servant/JS/Internal.hs view
@@ -54,12 +54,12 @@ import           Data.Text (Text) import           Servant.Foreign -type AjaxReq = Req ()+type AjaxReq = Req NoContent  -- A 'JavascriptGenerator' just takes the data found in the API type -- for each endpoint and generates Javascript code in a Text. Several -- generators are available in this package.-type JavaScriptGenerator = [Req ()] -> Text+type JavaScriptGenerator = [Req NoContent] -> Text  -- | This structure is used by specific implementations to let you -- customize the output
test/Servant/JSSpec.hs view
@@ -21,6 +21,7 @@ import           Test.Hspec  hiding (shouldContain, shouldNotContain)  import           Servant.API.Internal.Test.ComprehensiveAPI+import           Servant.API.ContentTypes import           Servant.JS import           Servant.JS.Internal import qualified Servant.JS.Angular           as NG@@ -105,7 +106,7 @@  axiosSpec :: Spec axiosSpec = describe specLabel $ do-    let reqList = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy ()) (Proxy :: Proxy TestAPI)+    let reqList = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) (Proxy :: Proxy TestAPI)     it "should add withCredentials when needed" $ do         let jsText = genJS withCredOpts $ reqList         output jsText@@ -129,7 +130,7 @@  angularSpec :: TestNames -> Spec angularSpec test = describe specLabel $ do-    let reqList = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy ()) (Proxy :: Proxy TestAPI)+    let reqList = listFromAPI (Proxy :: Proxy NoTypes) (Proxy :: Proxy NoContent) (Proxy :: Proxy TestAPI)     it "should implement a service globally" $ do         let jsText = genJS reqList         output jsText
test/Servant/JSSpec/CustomHeaders.hs view
@@ -16,6 +16,7 @@ import           Data.Proxy import           Data.Text (pack) import           GHC.TypeLits+import           Servant.API.ContentTypes import           Servant.JS.Internal  -- | This is a hypothetical combinator that fetches an Authorization header.@@ -23,13 +24,13 @@ -- using -- Basic, Digest, whatever. data Authorization (sym :: Symbol) a -instance (KnownSymbol sym, HasForeign lang () sublayout)-    => HasForeign lang () (Authorization sym a :> sublayout) where-    type Foreign () (Authorization sym a :> sublayout) = Foreign () sublayout+instance (KnownSymbol sym, HasForeign lang NoContent api)+    => HasForeign lang NoContent (Authorization sym a :> api) where+    type Foreign NoContent (Authorization sym a :> api) = Foreign NoContent api -    foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy sublayout) $+    foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $         req & reqHeaders <>~-          [ ReplaceHeaderArg (Arg "Authorization" ())+          [ ReplaceHeaderArg (Arg "Authorization" NoContent)           $ tokenType (pack . symbolVal $ (Proxy :: Proxy sym)) ]       where         tokenType t = t <> " {Authorization}"@@ -37,23 +38,23 @@ -- | This is a combinator that fetches an X-MyLovelyHorse header. data MyLovelyHorse a -instance (HasForeign lang () sublayout)-    => HasForeign lang () (MyLovelyHorse a :> sublayout) where-    type Foreign () (MyLovelyHorse a :> sublayout) = Foreign () sublayout+instance (HasForeign lang NoContent api)+    => HasForeign lang NoContent (MyLovelyHorse a :> api) where+    type Foreign NoContent (MyLovelyHorse a :> api) = Foreign NoContent api -    foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy sublayout) $-        req & reqHeaders <>~ [ ReplaceHeaderArg (Arg "X-MyLovelyHorse" ()) tpl ]+    foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $+        req & reqHeaders <>~ [ ReplaceHeaderArg (Arg "X-MyLovelyHorse" NoContent) tpl ]       where         tpl = "I am good friends with {X-MyLovelyHorse}"  -- | This is a combinator that fetches an X-WhatsForDinner header. data WhatsForDinner a -instance (HasForeign lang () sublayout)-    => HasForeign lang () (WhatsForDinner a :> sublayout) where-    type Foreign () (WhatsForDinner a :> sublayout) = Foreign () sublayout+instance (HasForeign lang NoContent api)+    => HasForeign lang NoContent (WhatsForDinner a :> api) where+    type Foreign NoContent (WhatsForDinner a :> api) = Foreign NoContent api -    foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy sublayout) $-        req & reqHeaders <>~ [ ReplaceHeaderArg (Arg "X-WhatsForDinner" ()) tpl ]+    foreignFor lang ftype Proxy req = foreignFor lang ftype (Proxy :: Proxy api) $+        req & reqHeaders <>~ [ ReplaceHeaderArg (Arg "X-WhatsForDinner" NoContent) tpl ]       where         tpl = "I would like {X-WhatsForDinner} with a cherry on top."