packages feed

servant-waargonaut 0.5.0.1 → 0.6.0.0

raw patch · 3 files changed

+18/−30 lines, 3 filesdep −attoparsecdep ~waargonautPVP ok

version bump matches the API change (PVP)

Dependencies removed: attoparsec

Dependency ranges changed: waargonaut

API changes (from Hackage documentation)

Files

servant-waargonaut.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                servant-waargonaut-version:             0.5.0.1+version:             0.6.0.0 synopsis:            Servant Integration for Waargonaut JSON Package description:         Provides the types and instances necessary to utilise Waargonaut as the JSON handling library for your Servant API. -- license:@@ -43,8 +43,7 @@   -- other-extensions:   build-depends:       base                >= 4.9    && < 4.13                      , servant             >= 0.14.1 && < 0.16-                     , waargonaut          >= 0.5    && < 0.6-                     , attoparsec          >= 0.13.2 && < 0.14+                     , waargonaut          >= 0.6    && < 0.7                      , bytestring          >= 0.10.8 && < 0.11                      , text                >= 1.2.3  && < 1.3                      , http-media          >= 0.7.1  && < 0.8@@ -71,9 +70,8 @@                      , servant-waargonaut                      , servant-server                      , servant             >= 0.14.1 && < 0.16-                     , waargonaut          >= 0.5    && < 0.6+                     , waargonaut          >= 0.6    && < 0.7 -                     , attoparsec          >= 0.13.2 && < 0.14                      , bytestring          >= 0.10.8 && < 0.11                      , text                >= 1.2.3  && < 1.3                      , http-media          >= 0.7.1  && < 0.8
src/Servant/API/ContentTypes/Waargonaut.hs view
@@ -7,14 +7,10 @@ module Servant.API.ContentTypes.Waargonaut ( WaargJSON ) where  import           Control.Category              ((.))-import           Control.Lens                  (over, _Left)  import           Prelude                       (show) -import qualified Data.ByteString.Lazy          as BSL-import qualified Data.Text                     as Text-import qualified Data.Text.Lazy.Encoding       as TextLE-+import           Data.Bifunctor                (first) import           Data.Function                 (($)) import           Data.Proxy                    (Proxy (..)) import           Data.Typeable                 (Typeable)@@ -22,21 +18,21 @@ import qualified Data.List.NonEmpty            as NE import qualified Network.HTTP.Media            as M -import           Data.Attoparsec.ByteString    (eitherResult, parse)- import           Servant.API.ContentTypes      (Accept (..), MimeRender (..),                                                 MimeUnrender (..)) +import qualified Data.ByteString.Lazy          as BL+ import qualified Text.PrettyPrint.Annotated.WL as WL-import           Waargonaut                    (parseWaargonaut)-import           Waargonaut.Decode             (ppCursorHistory, simpleDecode)-import           Waargonaut.Decode.Error       (DecodeError (ParseFailed)) -import           Waargonaut.Encode             (simplePureEncodeNoSpaces)+import           Waargonaut.Attoparsec         (pureDecodeAttoparsecByteString) -import           Waargonaut.Generic            (JsonDecode, JsonEncode,-                                                mkDecoder, mkEncoder, proxy)+import qualified Waargonaut.Decode             as D+import qualified Waargonaut.Encode             as E +import           Waargonaut.Generic            (JsonDecode, JsonEncode)+import qualified Waargonaut.Generic            as G+ -- | Replacement for 'Servant.API.ContentTypes.JSON' that will use the relevant instances from -- Waargonaut that are tagged with the type @t@. --@@ -61,18 +57,12 @@   contentTypes _ = "application" M.// "json" M./: ("charset", "utf-8") NE.:| [ "application" M.// "json" ]  instance JsonDecode t a => MimeUnrender (WaargJSON t) a where-  mimeUnrender _ = over _Left handleErr-    . simpleDecode (proxy mkDecoder (Proxy :: Proxy t)) parser-    . BSL.toStrict-+  mimeUnrender _ = first handleErr+    . pureDecodeAttoparsecByteString (G.proxy G.mkDecoder (Proxy :: Proxy t))+    . BL.toStrict     where-      parser =-        over _Left (ParseFailed . Text.pack)-        . eitherResult-        . parse parseWaargonaut-       handleErr (dErr, hist) = WL.display . WL.renderPrettyDefault $-        WL.text (show dErr) WL.<##> ppCursorHistory hist+        WL.text (show dErr) WL.<##> D.ppCursorHistory hist  instance JsonEncode t a => MimeRender (WaargJSON t) a where-  mimeRender _ = TextLE.encodeUtf8 . simplePureEncodeNoSpaces (proxy mkEncoder (Proxy :: Proxy t))+  mimeRender _ = E.simplePureEncodeByteStringNoSpaces (G.proxy G.mkEncoder (Proxy :: Proxy t))
test/Main.hs view
@@ -27,7 +27,7 @@       assertBody (BSL.fromStrict testPersonBS) res    , testWai app "POST '/' - 200 and accepts a Waarg Decoded Person" $ do-      let bdy = W.simplePureEncodeNoSpaces (W.proxy W.mkEncoder (Proxy :: Proxy TestAARG)) testPerson+      let bdy = W.simplePureEncodeTextNoSpaces (W.proxy W.mkEncoder (Proxy :: Proxy TestAARG)) testPerson        res <- srequest $ buildRequestWithHeaders POST "/"              (TextLE.encodeUtf8 bdy)