json-rpc-generic 0.2.1.5 → 0.2.1.6
raw patch · 4 files changed
+31/−28 lines, 4 filesdep −dlistPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: dlist
API changes (from Hackage documentation)
- Data.JsonRpc: Error :: !ErrorStatus -> !Text -> !(Maybe e) -> Error e
+ Data.JsonRpc: Error :: !ErrorStatus -> !Text -> !Maybe e -> Error e
- Data.JsonRpc: Failure :: !Text -> !(Maybe Id) -> !(Error e) -> Failure e
+ Data.JsonRpc: Failure :: !Text -> !Maybe Id -> !Error e -> Failure e
- Data.JsonRpc: [_data] :: Error e -> !(Maybe e)
+ Data.JsonRpc: [_data] :: Error e -> !Maybe e
- Data.JsonRpc.Failure: Error :: !ErrorStatus -> !Text -> !(Maybe e) -> Error e
+ Data.JsonRpc.Failure: Error :: !ErrorStatus -> !Text -> !Maybe e -> Error e
- Data.JsonRpc.Failure: Failure :: !Text -> !(Maybe Id) -> !(Error e) -> Failure e
+ Data.JsonRpc.Failure: Failure :: !Text -> !Maybe Id -> !Error e -> Failure e
- Data.JsonRpc.Failure: [_data] :: Error e -> !(Maybe e)
+ Data.JsonRpc.Failure: [_data] :: Error e -> !Maybe e
- Data.JsonRpc.Failure: [_error] :: Failure e -> !(Error e)
+ Data.JsonRpc.Failure: [_error] :: Failure e -> !Error e
- Data.JsonRpc.Failure: [_id] :: Failure e -> !(Maybe Id)
+ Data.JsonRpc.Failure: [_id] :: Failure e -> !Maybe Id
- Data.JsonRpc.Request: Request :: !Text -> !Text -> !(Maybe a) -> !(Maybe Id) -> Request a
+ Data.JsonRpc.Request: Request :: !Text -> !Text -> !Maybe a -> !Maybe Id -> Request a
- Data.JsonRpc.Request: [id] :: Request a -> !(Maybe Id)
+ Data.JsonRpc.Request: [id] :: Request a -> !Maybe Id
- Data.JsonRpc.Request: [params] :: Request a -> !(Maybe a)
+ Data.JsonRpc.Request: [params] :: Request a -> !Maybe a
- Data.JsonRpc.Response: Response :: (Either (Failure e) (Success a)) -> Response e a
+ Data.JsonRpc.Response: Response :: Either (Failure e) (Success a) -> Response e a
Files
- json-rpc-generic.cabal +7/−14
- src/Data/JsonRpc/Generic.hs +5/−6
- test/Instances.hs +17/−6
- test/testMain.hs +2/−2
json-rpc-generic.cabal view
@@ -1,5 +1,5 @@ name: json-rpc-generic-version: 0.2.1.5+version: 0.2.1.6 synopsis: Generic encoder and decode for JSON-RPC description: This package contains generic encoder and decode for JSON-RPC homepage: http://github.com/khibino/haskell-json-rpc-generic@@ -7,12 +7,16 @@ license-file: LICENSE author: Kei Hibino maintainer: ex8k.hibino@gmail.com-copyright: Copyright (c) 2016-2017 Kei Hibino+copyright: Copyright (c) 2016-2021 Kei Hibino category: Network build-type: Simple -- extra-source-files: cabal-version: >=1.10-tested-with: GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3+tested-with: GHC == 9.0.1+ , GHC == 8.10.1, GHC == 8.10.2, GHC == 8.10.3, GHC == 8.10.4+ , GHC == 8.8.1, GHC == 8.8.2, GHC == 8.8.3, GHC == 8.8.4+ , GHC == 8.6.1, GHC == 8.6.2, GHC == 8.6.3, GHC == 8.6.4, GHC == 8.6.5+ , GHC == 8.4.1, GHC == 8.4.2, GHC == 8.4.3, GHC == 8.4.4 , GHC == 8.2.1, GHC == 8.2.2 , GHC == 8.0.1, GHC == 8.0.2 , GHC == 7.10.1, GHC == 7.10.2, GHC == 7.10.3@@ -33,22 +37,11 @@ other-modules: Data.JsonRpc.Integral - other-extensions:- TypeOperators- FlexibleContexts- OverloadedStrings- DeriveFunctor- DeriveFoldable- DeriveTraversable- -- DeriveGeneric -- compat with Cabal 1.16- StandaloneDeriving- build-depends: base >=4.6 && <5 , transformers , containers , unordered-containers , text- , dlist , scientific , vector >=0.10 , aeson >=0.7
src/Data/JsonRpc/Generic.hs view
@@ -12,13 +12,12 @@ ) where import GHC.Generics-import Control.Applicative ((<$>), pure, (<*>), (<*), empty, (<|>))+import Control.Applicative ((<$>), (<*>), (<*), empty, (<|>)) import Control.Monad (guard) import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Writer (Writer, runWriter, tell) import Control.Monad.Trans.State (StateT, runStateT, get, put)-import Data.DList (DList)-import qualified Data.DList as DList+import Data.Monoid (Endo (..)) import Data.Set ((\\)) import qualified Data.Set as Set import qualified Data.HashMap.Strict as HashMap@@ -51,7 +50,7 @@ type FieldName = String-type FieldsW = Writer (DList FieldName)+type FieldsW = Writer (Endo [FieldName]) class GFieldSetJSON f where gFieldSet :: FieldsW (f a)@@ -84,7 +83,7 @@ => S1 s a p -> FieldsW (S1 s a p) saveQueriedField m1 = do- tell (pure $ selName m1)+ tell (Endo (selName m1 :)) return m1 instance GFieldSetJSON (K1 i a) where@@ -99,7 +98,7 @@ d rpcOpts opts v@(Object m) = do let (px, fs) = runWriter gFieldSet inv = Set.fromList (HashMap.keys m) \\- Set.fromList (map (T.pack . fieldLabelModifier opts) $ DList.toList fs)+ Set.fromList (map (T.pack . fieldLabelModifier opts) $ appEndo fs []) guard (allowNonExistField rpcOpts || Set.null inv) <|> fail ("object has illegal field: " ++ show (Set.toList inv)) j <- genericParseJSON opts v
test/Instances.hs view
@@ -3,12 +3,13 @@ module Instances (Example (..)) where -import Test.QuickCheck (Arbitrary (..), Gen, frequency, choose)+import Test.QuickCheck (Arbitrary (..), Gen, frequency, choose, listOf) import GHC.Generics (Generic) import Control.Applicative ((<$>), pure, (<*>)) import Data.Text (Text) import qualified Data.Text as T+import qualified Data.Text.Encoding as T import Data.Aeson (FromJSON, ToJSON) import qualified Data.Aeson.Types as Aeson @@ -20,14 +21,25 @@ genericParseJSONRPC, defaultJsonRpcOptions, ) +{- decoder of some text versions are COMPLETELY BROKEN !!+ only 7bit cases are working -}+genString :: Gen String+genString+ | good = arbitrary+ | otherwise = gen7bits+ where+ x = T.pack "\128"+ good = T.decodeUtf8' (T.encodeUtf8 x) == Right x+ gen7bits = listOf $ choose ('\000', '\127')+ genText :: Gen Text-genText = T.pack <$> arbitrary+genText = T.pack <$> genString instance Arbitrary Id where arbitrary = frequency [ (3, NumberId <$> arbitrary)- , (2, StringId . T.pack <$> arbitrary)+ , (2, StringId . T.pack <$> genString) ] instance Arbitrary a => Arbitrary (Request a) where@@ -90,7 +102,6 @@ , (3, Response . Left <$> arbitrary) ] - data Example = Example { p :: Int@@ -104,8 +115,8 @@ instance Arbitrary Example where arbitrary = Example- <$> arbitrary <*> arbitrary <*> arbitrary- <*> arbitrary <*> arbitrary <*> arbitrary+ <$> arbitrary <*> genString <*> arbitrary+ <*> arbitrary <*> arbitrary <*> frequency [(1, return Nothing), (3, Just <$> genString)] instance FromJSON Example where parseJSON = genericParseJSONRPC defaultJsonRpcOptions Aeson.defaultOptions
test/testMain.hs view
@@ -1,7 +1,7 @@ import qualified Eq import qualified Iso-import Test.QuickCheck.Simple (defaultMain')+import Test.QuickCheck.Simple (defaultMain_) main :: IO ()-main = defaultMain' True $ Eq.tests ++ Iso.tests+main = defaultMain_ True $ Eq.tests ++ Iso.tests