conferer-aeson 1.1.0.1 → 1.1.0.2
raw patch · 3 files changed
+54/−16 lines, 3 filesdep ~aesondep ~basedep ~bytestringPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: aeson, base, bytestring, text
API changes (from Hackage documentation)
Files
- CHANGELOG.md +8/−1
- conferer-aeson.cabal +3/−3
- src/Conferer/Source/Aeson.hs +43/−12
CHANGELOG.md view
@@ -8,9 +8,15 @@ Nothing +## [v1.1.0.2] 2021-12-03++### Changed++* Allow using aeson-2.0+ ## [v1.1.0.1] 2021-03-14 -## Changed+### Changed * Make the `keys` special key always return sorted keys (because of the change from hashable-1.3.1.0) @@ -31,6 +37,7 @@ First release [Unreleased]: https://github.com/ludat/conferer/compare/conferer-aeson_v1.1.0.1...HEAD+[v1.1.0.2]: https://github.com/ludat/conferer/compare/conferer-aeson_v1.1.0.1...conferer-aeson_v1.1.0.2 [v1.1.0.1]: https://github.com/ludat/conferer/compare/conferer-aeson_v1.1.0.0...conferer-aeson_v1.1.0.1 [v1.1.0.0]: https://github.com/ludat/conferer/compare/conferer-aeson_v1.0.0.0...conferer-aeson_v1.1.0.0 [v1.0.0.0]: https://github.com/ludat/conferer/compare/v0.0.0.0...conferer-aeson_v1.0.0.0
conferer-aeson.cabal view
@@ -7,7 +7,7 @@ -- hash: d73d44df61f4d56a6aa0b89b1ce6a27123ce674091a311ce30c992d64be6ef56 name: conferer-aeson-version: 1.1.0.1+version: 1.1.0.2 synopsis: conferer's source for reading json files description: Library to abstract the parsing of many haskell config values from different config sources@@ -36,7 +36,7 @@ default-extensions: OverloadedStrings LambdaCase QuasiQuotes ScopedTypeVariables RecordWildCards StrictData ghc-options: -Wall -Wredundant-constraints -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns build-depends:- aeson >=0.10 && <2.0+ aeson >=0.10 && <2.1 , base >=4.3 && <5 , bytestring >=0.10 && <0.11 , conferer >=1.1.0.0 && <2.0.0.0@@ -60,7 +60,7 @@ default-extensions: OverloadedStrings LambdaCase QuasiQuotes ScopedTypeVariables RecordWildCards StrictData ghc-options: -Wall -Wredundant-constraints -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns build-depends:- aeson >=0.10 && <2.0+ aeson >=0.10 && <2.1 , aeson-qq , base >=4.3 && <5 , bytestring >=0.10 && <0.11
src/Conferer/Source/Aeson.hs view
@@ -6,12 +6,19 @@ -- Portability: portable -- -- Source for json config files using Aeson+{-# LANGUAGE CPP #-} {-# LANGUAGE RecordWildCards #-} module Conferer.Source.Aeson where +#if MIN_VERSION_aeson(2,0,0)+import Data.Aeson hiding (Key)+import qualified Data.Aeson.KeyMap as KeyMap+import qualified Data.Aeson.Key as Key+#else import Data.Aeson+import qualified Data.HashMap.Strict as KeyMap+#endif import Control.Applicative-import qualified Data.HashMap.Strict as HashMap import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Encoding as Text@@ -110,15 +117,24 @@ (Nothing, v) -> Just v (Just ("keys", ""), Object o) ->- HashMap.lookup "keys" o+ KeyMap.lookup "keys" o <|> pure ( String $+#if MIN_VERSION_aeson(2,0,0)+ Key.toText $+#endif mconcat $ intersperse "," $ sort $- HashMap.keys o)+ KeyMap.keys o) (Just (c, ks), Object o) ->- HashMap.lookup c o >>= traverseJSON ks+ KeyMap.lookup+#if MIN_VERSION_aeson(2,0,0)+ (Key.fromText c)+#else+ c+#endif+ o >>= traverseJSON ks (Just ("keys", ""), Array vs) -> Just $ String $@@ -143,13 +159,19 @@ (_, Object o) -> let self =- case valueToText <$> HashMap.lookup "_self" o of+ case valueToText <$> KeyMap.lookup "_self" o of Just _ -> [key] Nothing -> [] in self ++ do- (k, v) <- HashMap.toList o- guard $ isValidKeyFragment k- go (key /. fromText k) v+ (k, v) <- KeyMap.toList o+ let textK =+#if MIN_VERSION_aeson(2,0,0)+ Key.toText k+#else+ k+#endif+ guard $ isValidKeyFragment textK+ go (key /. fromText textK) v (_, Array as) -> do (index :: Integer, v) <- zip [0..] $ Vector.toList as go (key /. mkKey (show index)) v@@ -160,7 +182,7 @@ valueToText :: Value -> Maybe Text valueToText (String t) = Just t valueToText (Object o) = do- selfValue <- HashMap.lookup "_self" o+ selfValue <- KeyMap.lookup "_self" o valueToText selfValue valueToText (Array _as) = Nothing valueToText (Number n) = Just $ Text.decodeUtf8 $ L.toStrict $ encode $ Number n@@ -203,11 +225,20 @@ let keys = fmap (\t -> rawkey ++ [t])- . HashMap.keys+#if MIN_VERSION_aeson(2,0,0)+ . fmap Key.toText+#endif+ . KeyMap.keys $ o in keys ++ do- (k, v) <- HashMap.toList o- let subkey = rawkey ++ [k]+ (k, v) <- KeyMap.toList o+ let textK =+#if MIN_VERSION_aeson(2,0,0)+ Key.toText k+#else+ k+#endif+ let subkey = rawkey ++ [textK] go subkey v Array as -> do (index :: Integer, v) <- zip [0..] $ Vector.toList as