packages feed

servant-jsonrpc 1.1.0 → 1.1.1

raw patch · 3 files changed

+40/−8 lines, 3 filesdep +http-mediadep +textdep ~aesondep ~servant

Dependencies added: http-media, text

Dependency ranges changed: aeson, servant

Files

changelog.md view
@@ -1,3 +1,8 @@+# 1.1.1++* Allow "application/json-rpc" as the content type+* Accept string for the `id` field+ # 1.1.0  * Relax upper version bounds for `aeson` to `(>= 1.3 && < 1.6)`
servant-jsonrpc.cabal view
@@ -1,7 +1,7 @@ cabal-version:       2.4  name:                servant-jsonrpc-version:             1.1.0+version:             1.1.1 author:              Ian Shipman <ics@gambolingpangolin.com> maintainer:          Ian Shipman <ics@gambolingpangolin.com> @@ -33,6 +33,8 @@     Servant.JsonRpc    build-depends:-      aeson                     >= 1.3              && < 1.6+      aeson                     >= 1.3              && < 2.1     , base                      >= 4.11             && < 5.0-    , servant                   >= 0.14             && < 0.19+    , http-media                >= 0.7.1.3          && < 0.9+    , servant                   >= 0.14             && < 0.20+    , text                      >= 1.2              && < 2.1
src/Servant/JsonRpc.hs view
@@ -3,6 +3,7 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings     #-} {-# LANGUAGE ScopedTypeVariables   #-}+{-# LANGUAGE TypeApplications      #-} {-# LANGUAGE TypeFamilies          #-} {-# LANGUAGE TypeOperators         #-} {-# LANGUAGE UndecidableInstances  #-}@@ -25,6 +26,7 @@       RawJsonRpc     , JsonRpc     , JsonRpcNotification+    , JSONRPC      -- * JSON-RPC messages     , Request (..)@@ -43,14 +45,20 @@     ) where  -import           Control.Applicative (liftA3)+import           Control.Applicative (liftA3, (<|>)) import           Data.Aeson          (FromJSON (..), ToJSON (..), Value (Null),                                       object, withObject, (.:), (.:?), (.=)) import           Data.Aeson.Types    (Parser)+import           Data.List.NonEmpty  (NonEmpty (..)) import           Data.Maybe          (isNothing)+import           Data.Proxy          (Proxy (..))+import           Data.Text.Read      (decimal) import           Data.Word           (Word64) import           GHC.TypeLits        (Symbol)-import           Servant.API         ((:>), JSON, NoContent, Post, ReqBody)+import           Network.HTTP.Media  ((//))+import           Servant.API         (Accept (..), JSON, MimeRender (..),+                                      MimeUnrender (..), NoContent, Post,+                                      ReqBody, (:>))   -- | Client messages@@ -132,7 +140,7 @@  instance (FromJSON e, FromJSON r) => FromJSON (JsonRpcResponse e r) where     parseJSON = withObject "Response" $ \obj -> do-        ix      <- obj .:  "id"+        ix      <- obj .:  "id" <|> (obj .: "id" >>= parseDecimalString)         version <- obj .:? "jsonrpc"         result  <- obj .:? "result"         err     <- obj .:? "error"@@ -140,6 +148,8 @@          where +        parseDecimalString = either fail (pure . fmap fst) . traverse decimal+         pack (Just ix) (Just r) Nothing = pure $ Result ix r         pack ix Nothing (Just e)        = Errors ix <$> parseErr e         pack (Just ix) Nothing Nothing  = pure $ Ack ix@@ -190,7 +200,22 @@  type family JsonRpcEndpoint a where     JsonRpcEndpoint (JsonRpc m p e r)-        = ReqBody '[JSON] (Request p) :> Post '[JSON] (JsonRpcResponse e r)+        = ReqBody '[JSONRPC] (Request p) :> Post '[JSONRPC] (JsonRpcResponse e r)      JsonRpcEndpoint (JsonRpcNotification m p)-        = ReqBody '[JSON] (Request p) :> Post '[JSON] NoContent+        = ReqBody '[JSONRPC] (Request p) :> Post '[JSONRPC] NoContent++-- | The JSON-RPC content type+data JSONRPC+++instance Accept JSONRPC where+    contentTypes _ = "application" // "json-rpc" :| ["application" // "json"]+++instance ToJSON a => MimeRender JSONRPC a where+    mimeRender _ = mimeRender (Proxy @JSON)+++instance FromJSON a => MimeUnrender JSONRPC a where+    mimeUnrender _ = mimeUnrender (Proxy @JSON)