packages feed

servant-jsonrpc-client 1.1.0 → 1.2.0

raw patch · 4 files changed

+77/−60 lines, 4 filesdep ~aesondep ~servantdep ~servant-client-coresetup-changed

Dependency ranges changed: aeson, servant, servant-client-core, servant-jsonrpc

Files

Setup.hs view
@@ -1,2 +1,3 @@ import Distribution.Simple+ main = defaultMain
changelog.md view
@@ -1,3 +1,7 @@+# 1.2.0++* Support for user-configured content-type in generated client+ # 1.1.0  * Relax upper version bounds for `aeson` to `(>= 1.3 && < 1.6)`
servant-jsonrpc-client.cabal view
@@ -1,7 +1,7 @@ cabal-version:       2.4  name:                servant-jsonrpc-client-version:             1.1.0+version:             1.2.0 author:              Ian Shipman <ics@gambolingpangolin.com> maintainer:          Ian Shipman <ics@gambolingpangolin.com> @@ -30,8 +30,8 @@     Servant.Client.JsonRpc    build-depends:-      aeson                         >= 1.3          && < 1.6+      aeson                         >= 1.3          && < 2.3     , base                          >= 4.11         && < 5.0-    , servant                       >= 0.14         && < 0.19-    , servant-client-core           >= 0.14         && < 0.19-    , servant-jsonrpc               >= 1.0.1        && < 1.2+    , servant                       >= 0.14         && < 0.21+    , servant-client-core           >= 0.14         && < 0.21+    , servant-jsonrpc               >= 1.2          && < 1.3
src/Servant/Client/JsonRpc.hs view
@@ -1,72 +1,84 @@-{-# LANGUAGE FlexibleInstances     #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE ScopedTypeVariables   #-}-{-# LANGUAGE TypeApplications      #-}-{-# LANGUAGE TypeFamilies          #-}-+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} --- |--- Module: Servant.Client.JsonRpc------ This module provides support for generating JSON-RPC clients in the Servant framework.------ > type Mul = JsonRpc "mul" (Int, Int) String Int--- > mul :: (Int, Int) -> ClientM (JsonRpcResponse String Int)--- > mul = client $ Proxy @Mul------ Note: This client implementation runs over HTTP and the semantics of HTTP--- remove the need for the message id.-module Servant.Client.JsonRpc-    ( module Servant.JsonRpc-    ) where--import           Data.Aeson          (FromJSON, ToJSON)-import           Data.Proxy          (Proxy (..))-import           GHC.TypeLits        (KnownSymbol, symbolVal)-import           Servant.API         (NoContent)-import           Servant.Client.Core (HasClient (..), RunClient)--import           Servant.JsonRpc-+{- |+Module: Servant.Client.JsonRpc --- | The 'RawJsonRpc' construct is completely transparent to clients-instance (RunClient m, HasClient m api) => HasClient m (RawJsonRpc api) where-    type Client m (RawJsonRpc api) = Client m api-    clientWithRoute pxm _  = clientWithRoute pxm (Proxy @api)-    hoistClientMonad pxm _ = hoistClientMonad pxm (Proxy @api)+This module provides support for generating JSON-RPC clients in the Servant framework. +> type Mul = JsonRpc "mul" (Int, Int) String Int+> mul :: (Int, Int) -> ClientM (JsonRpcResponse String Int)+> mul = client $ Proxy @Mul -instance (RunClient m, KnownSymbol method, ToJSON p, FromJSON e, FromJSON r)-    => HasClient m (JsonRpc method p e r) where+Note: This client implementation runs over HTTP and the semantics of HTTP+remove the need for the message id.+-}+module Servant.Client.JsonRpc (+  module Servant.JsonRpc,+) where -    type Client m (JsonRpc method p e r)-        = p -> m (JsonRpcResponse e r)+import Data.Proxy (Proxy (..))+import GHC.TypeLits (KnownSymbol, symbolVal)+import Servant.API (MimeRender, MimeUnrender, NoContent, (:<|>))+import Servant.Client.Core (HasClient (..), RunClient) -    clientWithRoute _ _ req p =-        client req jsonRpcRequest+import Servant.JsonRpc -        where-        client = clientWithRoute (Proxy @m) endpoint-        jsonRpcRequest = Request (symbolVal $ Proxy @method) p (Just 0)+-- | The 'RawJsonRpc' construct is completely transparent to clients+instance+  (RunClient m, HasClient m (RawJsonRpc ctype apiL), HasClient m (RawJsonRpc ctype apiR)) =>+  HasClient m (RawJsonRpc ctype (apiL :<|> apiR))+  where+  type Client m (RawJsonRpc ctype (apiL :<|> apiR)) = Client m (RawJsonRpc ctype apiL :<|> RawJsonRpc ctype apiR)+  clientWithRoute pxm _ = clientWithRoute pxm (Proxy @(RawJsonRpc ctype apiL :<|> RawJsonRpc ctype apiR))+  hoistClientMonad pxm _ = hoistClientMonad pxm (Proxy @(RawJsonRpc ctype apiL :<|> RawJsonRpc ctype apiR)) -        endpoint = Proxy @(JsonRpcEndpoint (JsonRpc method p e r))+instance+  ( RunClient m+  , KnownSymbol method+  , MimeRender ctype (Request p)+  , MimeUnrender ctype (JsonRpcResponse e r)+  ) =>+  HasClient m (RawJsonRpc ctype (JsonRpc method p e r))+  where+  type+    Client m (RawJsonRpc ctype (JsonRpc method p e r)) =+      p -> m (JsonRpcResponse e r) -    hoistClientMonad _ _ f x p = f $ x p+  clientWithRoute _ _ req p =+    client req jsonRpcRequest+   where+    client = clientWithRoute (Proxy @m) endpoint+    jsonRpcRequest = Request (symbolVal $ Proxy @method) p (Just 0) +    endpoint = Proxy @(JsonRpcEndpoint ctype (JsonRpc method p e r)) -instance (RunClient m, KnownSymbol method, ToJSON p)-    => HasClient m (JsonRpcNotification method p) where+  hoistClientMonad _ _ f x p = f $ x p -    type Client m (JsonRpcNotification method p)-        = p -> m NoContent+instance+  ( RunClient m+  , KnownSymbol method+  , MimeRender ctype (Request p)+  ) =>+  HasClient m (RawJsonRpc ctype (JsonRpcNotification method p))+  where+  type+    Client m (RawJsonRpc ctype (JsonRpcNotification method p)) =+      p -> m NoContent -    clientWithRoute _ _ req p =-        client req jsonRpcRequest-        where-        client = clientWithRoute (Proxy @m) endpoint-        jsonRpcRequest = Request (symbolVal $ Proxy @method) p Nothing+  clientWithRoute _ _ req p =+    client req jsonRpcRequest+   where+    client = clientWithRoute (Proxy @m) endpoint+    jsonRpcRequest = Request (symbolVal $ Proxy @method) p Nothing -        endpoint = Proxy @(JsonRpcEndpoint (JsonRpcNotification method p))+    endpoint = Proxy @(JsonRpcEndpoint ctype (JsonRpcNotification method p)) -    hoistClientMonad _ _ f x p = f $ x p+  hoistClientMonad _ _ f x p = f $ x p