packages feed

json-rpc-client 0.1.4.0 → 0.2.0.0

raw patch · 7 files changed

+41/−44 lines, 7 filesdep ~json-rpc-serverdep ~mtlPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: json-rpc-server, mtl

API changes (from Hackage documentation)

- Network.JsonRpc.Client: runBatch :: (Monad m, Functor m) => Connection m -> Batch r -> RpcResult m r
+ Network.JsonRpc.Client: runBatch :: Monad m => Connection m -> Batch r -> RpcResult m r
- Network.JsonRpc.Client: toFunction :: (Monad m, Functor m, ClientFunction ps r f, ComposeMultiParam (Batch r -> RpcResult m r) f g) => Connection m -> Signature ps r -> g
+ Network.JsonRpc.Client: toFunction :: (Monad m, ClientFunction ps r f, ComposeMultiParam (Batch r -> RpcResult m r) f g) => Connection m -> Signature ps r -> g
- Network.JsonRpc.Client: toFunction_ :: (Monad m, Functor m, ClientFunction ps r f, ComposeMultiParam (Batch r -> RpcResult m ()) f g) => Connection m -> Signature ps r -> g
+ Network.JsonRpc.Client: toFunction_ :: (Monad m, ClientFunction ps r f, ComposeMultiParam (Batch r -> RpcResult m ()) f g) => Connection m -> Signature ps r -> g
- Network.JsonRpc.Client: type RpcResult (m :: * -> *) r = ErrorT RpcError m r
+ Network.JsonRpc.Client: type RpcResult (m :: * -> *) r = ExceptT RpcError m r

Files

+ changelog.md view
@@ -0,0 +1,3 @@+0.2.0.0++* Updated the error handling type from ErrorT to ExceptT.
demo/Client.hs view
@@ -10,7 +10,7 @@ import qualified Data.ByteString.Lazy.Char8 as B import Data.Traversable (sequenceA) import Control.Applicative ((<$>), (<*>))-import Control.Monad.Error (runErrorT, liftIO)+import Control.Monad.Except (runExceptT, liftIO) import Control.Monad.Reader (ReaderT, runReaderT, ask)  runRpcs :: Result ()@@ -76,5 +76,5 @@ main = do   cmd <- head <$> getArgs   (inH, outH, _, processH) <- runInteractiveCommand cmd-  runReaderT (runErrorT runRpcs) (inH, outH)+  runReaderT (runExceptT runRpcs) (inH, outH)   terminateProcess processH
demo/Server.hs view
@@ -35,4 +35,4 @@   forM_ (B.lines contents) $ \request -> do          response <- runReaderT (call methods request) count          B.putStrLn $ fromMaybe "" response-      where methods = toMethods [concatenate, increment]+      where methods = [concatenate, increment]
json-rpc-client.cabal view
@@ -1,5 +1,5 @@ name:                json-rpc-client-version:             0.1.4.0+version:             0.2.0.0 license:             MIT license-file:        LICENSE category:            Network, JSON@@ -7,9 +7,12 @@ maintainer:          Kristen Kozak <grayjay@wordroute.com> synopsis:            JSON-RPC 2.0 on the client side. build-type:          Simple+extra-source-files:  changelog.md cabal-version:       >=1.10 tested-with:         GHC == 7.0.4, GHC == 7.4.2, GHC == 7.6.3,                      GHC == 7.8.3, GHC == 7.10.1+homepage:            https://github.com/grayjay/json-rpc-client+bug-reports:         https://github.com/grayjay/json-rpc-client/issues description:         Functions for creating a JSON-RPC 2.0 client.  See                      <http://www.jsonrpc.org/specification>. This library supports                      batch requests and notifications, as well as single method@@ -24,7 +27,7 @@  source-repository head   type:              git-  location:          https://github.com/grayjay/json-rpc-client+  location:          git://github.com/grayjay/json-rpc-client.git  flag demo   description:       Builds the JSON-RPC demo client and server.@@ -35,10 +38,10 @@   exposed-modules:     Network.JsonRpc.Client                        Network.JsonRpc.ServerAdapter   build-depends:       base >=4.3.1 && <4.9,-                       json-rpc-server >=0.1.4 && <0.2,+                       json-rpc-server >=0.2 && <0.3,                        aeson >=0.7 && <0.10,                        bytestring >=0.9.1 && <0.11,-                       mtl >=2.1.1 && <2.3,+                       mtl >=2.2.1 && <2.3,                        text >=0.11.2 && <1.3,                        unordered-containers >=0.2.3 && <0.3,                        vector >=0.10 && <0.11,@@ -54,10 +57,10 @@   if flag (demo)     build-depends:       base >=4.3.1 && <4.9,                          json-rpc-client,-                         json-rpc-server >=0.1.4 && <0.2,+                         json-rpc-server >=0.2 && <0.3,                          aeson >=0.7 && <0.10,                          bytestring >=0.9.2 && <0.11,-                         mtl >=2.1.1 && <2.3,+                         mtl >=2.2.1 && <2.3,                          text >=0.11.2 && <1.3     default-language:    Haskell2010   else@@ -70,11 +73,11 @@   if flag (demo)     build-depends:       base >=4.3.1 && <4.9,                          json-rpc-client,-                         json-rpc-server >=0.1.4 && <0.2,+                         json-rpc-server >=0.2 && <0.3,                          process >=1.1.0 && <1.3,                          aeson >=0.7 && <0.10,                          bytestring >=0.9.2 && <0.11,-                         mtl >=2.1.1 && <2.3,+                         mtl >=2.2.1 && <2.3,                          text >=0.11.2 && <1.3     default-language:    Haskell2010   else@@ -87,10 +90,10 @@   type:                exitcode-stdio-1.0   build-depends:       base >=4.3.1 && <4.9,                        json-rpc-client,-                       json-rpc-server >=0.1.4 && <0.2,+                       json-rpc-server >=0.2 && <0.3,                        aeson >=0.7 && <0.10,                        bytestring >=0.9.1 && <0.11,-                       mtl >=2.1.1 && <2.3,+                       mtl >=2.2.1 && <2.3,                        scientific >=0.2 && <0.4,                        text >=0.11.2 && <1.3,                        unordered-containers >=0.2.3 && <0.3,
src/Network/JsonRpc/Client.hs view
@@ -7,10 +7,6 @@              TypeOperators,              FlexibleContexts #-} -#if MIN_VERSION_mtl(2,2,1)-{-# OPTIONS_GHC -fno-warn-deprecations #-}-#endif- -- | Functions for implementing the client side of JSON-RPC 2.0. --   See <http://www.jsonrpc.org/specification>. @@ -60,7 +56,8 @@ import qualified Data.Vector as V import qualified Data.Vector.Algorithms.Intro as VA import Control.Arrow ((&&&))-import Control.Monad.Error (ErrorT (..), throwError, lift, (<=<))+import Control.Monad (liftM)+import Control.Monad.Except (ExceptT (..), throwError, lift, (<=<)) import Control.Applicative (Alternative (..), (<|>))  #if !MIN_VERSION_base(4,8,0)@@ -121,14 +118,14 @@ toBatchFunction_ = composeWithBatch voidBatch  -- | Creates a function for calling a JSON-RPC method on the server.-toFunction :: (Monad m, Functor m, ClientFunction ps r f, ComposeMultiParam (Batch r -> RpcResult m r) f g) =>+toFunction :: (Monad m, ClientFunction ps r f, ComposeMultiParam (Batch r -> RpcResult m r) f g) =>               Connection m   -- ^ Function for sending requests to the server.            -> Signature ps r -- ^ Method signature.            -> g              -- ^ Client-side function with a return type of @'RpcResult' m r@. toFunction = composeWithBatch . runBatch  -- | Creates a function for calling a JSON-RPC method on the server as a notification.-toFunction_ :: (Monad m, Functor m, ClientFunction ps r f, ComposeMultiParam (Batch r -> RpcResult m ()) f g) =>+toFunction_ :: (Monad m, ClientFunction ps r f, ComposeMultiParam (Batch r -> RpcResult m ()) f g) =>                Connection m   -- ^ Function for sending requests to the server.             -> Signature ps r -- ^ Method signature.             -> g              -- ^ Client-side function with a return type of @'RpcResult' m ()@.@@ -144,7 +141,7 @@ -- 2. If the batch has exactly one request, it is sent as a request object. --    -- 3. If the batch has multiple requests, they are sent as an array of request objects.-runBatch :: (Monad m, Functor m) =>+runBatch :: Monad m =>             Connection m  -- ^ Function for sending requests to the server.          -> Batch r       -- ^ Batch to be evaluated.          -> RpcResult m r -- ^ Result.@@ -156,7 +153,7 @@               where ids = V.postscanl' incId 0 requests                     incId i rq = if rqIsNotification rq then i else i + 1           sort = V.modify $ VA.sortBy $ comparing rsId-          liftResult = ErrorT . return+          liftResult = ExceptT . return           validate rsps = let (results, ids) = V.unzip $ V.map (rsResult &&& rsId) rsps                           in if ids /= V.enumFromN 1 (bNonNotifications batch)                              then throwError $ clientError $@@ -168,7 +165,7 @@                           , idRqId = if rqIsNotification rq then Nothing else Just i                           , idRqParams = rqParams rq } -processRqs :: (Monad m, Functor m) =>+processRqs :: Monad m =>               Connection m -> V.Vector IdRequest -> RpcResult m (V.Vector Response) processRqs server requests | V.null requests = return V.empty                            | V.length requests == 1 = process V.singleton $ V.head requests@@ -177,7 +174,7 @@                          Right r -> return r                          Left msg -> throwError $ clientError $                                      "Client cannot parse JSON response: " ++ msg-          process f rqs = maybe (return V.empty) (fmap f . decode) =<<+          process f rqs = maybe (return V.empty) (liftM f . decode) =<<                           (lift . server . A.encode) rqs  -- | Converts all requests in a batch to notifications.@@ -205,7 +202,9 @@     empty = Batch { bNonNotifications = 0                   , bRequests = V.empty                   , bToResult = const $ throwError $ clientError "empty" }-    (<|>) = combine (<|>)+    (<|>) = combine (<||>)+        where Right x <||> _ = Right x+              _ <||> x = x  combine :: (Result a -> Result b -> Result c) -> Batch a -> Batch b -> Batch c combine f (Batch n1 rqs1 g1) (Batch n2 rqs2 g2) =
tests/Properties.hs view
@@ -7,17 +7,13 @@              FlexibleContexts,              FlexibleInstances #-} -#if MIN_VERSION_mtl(2,2,1)-{-# OPTIONS_GHC -fno-warn-deprecations #-}-#endif- module Properties (properties) where  import Network.JsonRpc.Client import Network.JsonRpc.ServerAdapter import Network.JsonRpc.Server import Data.Aeson (ToJSON, FromJSON)-import Control.Monad.Error (ErrorT (..), runErrorT, throwError)+import Control.Monad.Except (runExceptT, throwError) import Control.Monad.State (State, runState, evalState, gets, put, modify) import Data.Text (Text, pack) import Data.List (nub)@@ -60,9 +56,9 @@                  -> A -> B -> D -> Property prop_rpcVsDirect sig@(Signature _ ps) (Blind f) x y state = unique (paramNames ps) ==>                                                             run (f x y) == run (rpcFunction x y)-    where server = call $ toMethods [toServerMethod sig f]+    where server = call [toServerMethod sig f]           rpcFunction = toFunction server sig-          run result = runState (runErrorT result) state+          run result = runState (runExceptT result) state  -- A sequence of requests should yield the same result whether batched or -- sent individually in the State monad, if the server evaluates the@@ -72,10 +68,10 @@ prop_singleVsBatch :: Signature (A ::: B ::: ()) C                    -> Blind (A -> B -> RpcResult (State D) C)                    -> [(A, B)] -> D -> Bool-prop_singleVsBatch sig (Blind f) args state = let server = call $ toMethods [toServerMethod sig f]+prop_singleVsBatch sig (Blind f) args state = let server = call [toServerMethod sig f]                                                   function = toFunction server sig                                                   functionB = toBatchFunction sig-                                                  run result = evalState (runErrorT result) state+                                                  run result = evalState (runExceptT result) state                                               in run (mapM (uncurry function) args) ==                                                  run (runBatch server $ traverse (uncurry functionB) args) @@ -167,7 +163,7 @@ unique xs = nub xs == xs  myRunBatch toServer sigs state result = let server = getServer toServer sigs-                                        in runState (runErrorT $ runBatch server result) state+                                        in runState (runExceptT $ runBatch server result) state  data a :*: b = a :*: b deriving Show infixr :*:@@ -217,7 +213,7 @@     show _ = "ToServer"  instance SignatureSet ss => Arbitrary (ToServer ss S) where-    arbitrary = ToServer <$> promote (\ss -> (call . toMethods) <$> toServerMethods ss)+    arbitrary = ToServer <$> promote (\ss -> call <$> toServerMethods ss)  testError = rpcError 9999 "Test error" 
tests/Tests.hs view
@@ -2,15 +2,11 @@              OverloadedStrings,              TypeOperators #-} -#if MIN_VERSION_mtl(2,2,1)-{-# OPTIONS_GHC -fno-warn-deprecations #-}-#endif- module Tests (tests) where  import Network.JsonRpc.Client import Network.JsonRpc.ServerAdapter (toServerMethod)-import Network.JsonRpc.Server (toMethods, rpcError, call, callWithBatchStrategy)+import Network.JsonRpc.Server (rpcError, call, callWithBatchStrategy)  import qualified Data.Aeson as A import Data.Aeson ((.=))@@ -20,7 +16,7 @@ import Data.Scientific (Scientific) import qualified Data.HashMap.Strict as M import qualified Data.Vector as V-import Control.Monad.Error (runErrorT, throwError)+import Control.Monad.Except (runExceptT, throwError) import Control.Monad.State (State, runState, modify, when) import Test.HUnit hiding (State, Test) import Test.Framework (Test)@@ -184,7 +180,7 @@  -- | Returns the error code or result, and the new server state. runResult :: Result a -> (Either Int a, Int)-runResult result = runState (mapLeft errCode <$> runErrorT result) 0+runResult result = runState (mapLeft errCode <$> runExceptT result) 0     where mapLeft f (Left x) = Left $ f x           mapLeft _ (Right x) = Right x @@ -213,7 +209,7 @@ constServer :: B.ByteString -> Connection RequestCount constServer = const . return . Just -methods = toMethods [subtractMethod, divideMethod]+methods = [subtractMethod, divideMethod]  subtractMethod = toServerMethod subtractSig f     where f :: Int -> Int -> RpcResult RequestCount Int