diff --git a/CHANGELOG.md b/CHANGELOG.md index 578d08a..b40903b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,21 @@ # Changelog +### v0.4.0 + +Update dependencies, in particular, aeson v2. + + ### v0.3.11 -- Add CHANGELOG and README to the stack tarball +Add CHANGELOG and README to the stack tarball. ### v0.3.10 -- Added missing test files to the stack tarball +Added missing test files to the stack tarball. ### v0.3.9 -- Adjusted version ranges for test dependencies +Adjusted version ranges for test dependencies. ### v0.3.8 @@ -52,6 +57,7 @@ - Added `listRelative` and it's flipped relative - Updated dependencies + ### v0.2.1 - Fix order of the `list` function parameters @@ -62,6 +68,7 @@ - Add more `Utilities` (sequence utils, metadata helpers, etc.) - Clean up code + ### v0.1.3 - Fix `Contrib.prefixDirname` which didn't change `pathToRoot` and `parentPath` like it should diff --git a/package.yaml b/package.yaml index 9c4140a..29a1f14 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: shikensu -version: 0.3.11 +version: 0.4.0 maintainer: Steven Vandevelde category: Filesystem @@ -17,9 +17,9 @@ default-extensions: dependencies: - - aeson == 1.* + - aeson == 2.* - base >= 4.9 && < 5 - - bytestring == 0.10.* + - bytestring >= 0.10 && < 0.12 - directory == 1.* - filepath == 1.* - flow == 1.* diff --git a/src/Shikensu.hs b/src/Shikensu.hs index a0548be..de2483a 100644 --- a/src/Shikensu.hs +++ b/src/Shikensu.hs @@ -20,7 +20,7 @@ import Shikensu.Internal.Types import Shikensu.Internal.Utilities import System.FilePath -import qualified Data.HashMap.Strict as HashMap (empty) +import qualified Data.Aeson.KeyMap as KeyMap (empty) import qualified Data.List as List (concatMap, map, zip) import qualified System.Directory as Dir (canonicalizePath) import qualified System.FilePath.Glob as Glob (compile, globDir1) @@ -115,7 +115,7 @@ Example definition, given: > , workingDirname = "example" > > , content = Nothing -> , metadata = HashMap.empty +> , metadata = KeyMap.empty > , parentPath = "../" > , pathToRoot = "../../" > } @@ -140,7 +140,7 @@ makeDefinition rootDirname pattern absolutePath = -- Additional properties , content = Nothing - , metadata = HashMap.empty + , metadata = KeyMap.empty , parentPath = compileParentPath $ takeDirName theLocalPath , pathToRoot = compilePathToRoot $ takeDirName theLocalPath } diff --git a/src/Shikensu/Contrib.hs b/src/Shikensu/Contrib.hs index c693ac5..3afd219 100644 --- a/src/Shikensu/Contrib.hs +++ b/src/Shikensu/Contrib.hs @@ -36,7 +36,7 @@ import Shikensu.Internal.Utilities (compileParentPath, compilePathToRoot) import Shikensu.Metadata (transposeToMetadata) import System.FilePath (FilePath, combine) -import qualified Data.HashMap.Strict as HashMap (empty, union) +import qualified Data.Aeson.KeyMap as KeyMap (empty, union) {-| Clear metadata. @@ -50,7 +50,7 @@ clearMetadata = clearMetadataDef :: Definition -> Definition clearMetadataDef def = - def { metadata = HashMap.empty } + def { metadata = KeyMap.empty } @@ -87,7 +87,7 @@ copyPropsToMetadata = copyPropsToMetadataDef :: Definition -> Definition copyPropsToMetadataDef def = def - { metadata = HashMap.union (transposeToMetadata def) (metadata def) } + { metadata = KeyMap.union (transposeToMetadata def) (metadata def) } @@ -112,7 +112,7 @@ insertMetadata a = insertMetadataDef :: Metadata -> Definition -> Definition insertMetadataDef given def = - def { metadata = HashMap.union given (metadata def) } + def { metadata = KeyMap.union given (metadata def) } diff --git a/src/Shikensu/Internal/Types.hs b/src/Shikensu/Internal/Types.hs index 12b062d..315c354 100644 --- a/src/Shikensu/Internal/Types.hs +++ b/src/Shikensu/Internal/Types.hs @@ -5,11 +5,12 @@ module Shikensu.Internal.Types where import Data.Aeson ((.=), toJSON) +import Data.Aeson.KeyMap (KeyMap) import Data.ByteString (ByteString) import Data.Monoid ((<>)) import System.FilePath (joinPath) -import qualified Data.Aeson as Aeson (Object, ToJSON, object) +import qualified Data.Aeson as Aeson (ToJSON, Value, object) {-| A file definition, along with some additional properties. @@ -49,7 +50,7 @@ instance Aeson.ToJSON Definition where type Dictionary = [Definition] -type Metadata = Aeson.Object +type Metadata = KeyMap Aeson.Value diff --git a/src/Shikensu/Metadata.hs b/src/Shikensu/Metadata.hs index 382e839..0f3d14d 100644 --- a/src/Shikensu/Metadata.hs +++ b/src/Shikensu/Metadata.hs @@ -10,7 +10,7 @@ import Flow import Shikensu.Internal.Types import qualified Data.Aeson as Aeson (FromJSON, Result(..), ToJSON, fromJSON, toJSON) -import qualified Data.HashMap.Strict as HashMap (empty) +import qualified Data.Aeson.KeyMap as KeyMap (empty, fromList) {-| Transpose metadata. @@ -22,15 +22,15 @@ which implements the Aeson.FromJSON instance. > Example { some :: Text } > deriving (Generic, FromJSON) > -> hashMap = HashMap.fromList [ ("some", "metadata") ] +> keyMap = KeyMap.fromList [ ("some", "metadata") ] > defaultEx = Example { some = "default" } -> example = transposeMetadata hashMap defaultEx :: Example +> example = transposeMetadata keyMap defaultEx :: Example -} transposeMetadata :: Aeson.FromJSON a => Metadata -> a -> a -transposeMetadata hashMap fallback = +transposeMetadata keyMap fallback = let - result = hashMap + result = keyMap |> Aeson.toJSON |> Aeson.fromJSON :: Aeson.FromJSON b => Aeson.Result b in @@ -50,4 +50,4 @@ transposeToMetadata generic = in case result of Aeson.Success x -> x - Aeson.Error _ -> HashMap.empty + Aeson.Error _ -> KeyMap.empty diff --git a/src/Shikensu/Utilities.hs b/src/Shikensu/Utilities.hs index 9bba193..8cc2d90 100644 --- a/src/Shikensu/Utilities.hs +++ b/src/Shikensu/Utilities.hs @@ -14,7 +14,8 @@ import Flow import Shikensu.Internal.Types import qualified Data.Aeson as Json (Object, Result(..), encode) -import qualified Data.HashMap.Strict as HashMap (lookup) +import qualified Data.Aeson.KeyMap as KeyMap (lookup) +import qualified Data.Aeson.Key as Key (fromText) import qualified Data.List as List (unzip, zip) import qualified Data.Text as Text (unpack) import qualified Data.Text.Lazy as Lazy.Text (unpack) @@ -72,7 +73,8 @@ lsequence list = -} (~>) :: (FromJSON a, ToJSON a) => Metadata -> Text -> Maybe a (~>) obj key = - HashMap.lookup key obj + obj + |> KeyMap.lookup (Key.fromText key) |> fmap fromJSON |> fmap fromJSONResult diff --git a/stack.yaml b/stack.yaml index 68e0c1c..5ff4c7a 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1 +1,3 @@ -resolver: nightly-2020-09-19 +resolver: nightly-2021-12-26 +extra-deps: + - aeson-2.0.2.0 diff --git a/stack.yaml.lock b/stack.yaml.lock index d5c6b98..4ea8f7c 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -3,10 +3,17 @@ # For more information, please see the documentation at: # https://docs.haskellstack.org/en/stable/lock_files -packages: [] +packages: +- completed: + hackage: aeson-2.0.2.0@sha256:bb41f39762d6f755431097ce0fa88d817108036e7f1c1ec06fd5990230860c76,6343 + pantry-tree: + size: 37910 + sha256: 5303edc2f9516c7999c21fbfb218ad180dd91c2ceea570f8bc54818ea9ec1692 + original: + hackage: aeson-2.0.2.0 snapshots: - completed: - size: 531498 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2020/9/19.yaml - sha256: e39020cba3f67726df5d467ee7ddda6887f4be3a07fe3ece0eb2bdef801138c3 - original: nightly-2020-09-19 + size: 621066 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2021/12/26.yaml + sha256: b0ce4f7d53851f1e875b52df2a8a20d77c65883d8350b997580ded88eec0a4b2 + original: nightly-2021-12-26 diff --git a/tests/Test/Contrib.hs b/tests/Test/Contrib.hs index 2c79df3..6e7b5c4 100644 --- a/tests/Test/Contrib.hs +++ b/tests/Test/Contrib.hs @@ -11,9 +11,10 @@ import Test.Tasty import Test.Tasty.HUnit import qualified Data.Aeson.Types as Aeson (Value(..)) +import qualified Data.Aeson.Key as Key (fromText) import qualified Data.ByteString as B (empty) import qualified Data.ByteString.Char8 as BS (intercalate, pack) -import qualified Data.HashMap.Strict as HashMap (fromList, lookup) +import qualified Data.Aeson.KeyMap as KeyMap (fromList, lookup) import qualified Data.List as List (head, reverse) import qualified Data.Text as Text (pack, unpack) import qualified Data.Text.Encoding as Text (decodeUtf8, encodeUtf8) @@ -100,16 +101,16 @@ testExclude = testMetadata :: TestTree testMetadata = let - keyA = Text.pack "title" + keyA = Key.fromText (Text.pack "title") valueA = Aeson.String (Text.pack "Hello world!") - keyB = Text.pack "hello" + keyB = Key.fromText (Text.pack "hello") valueB = Aeson.String (Text.pack "Guardian.") - keyC = Text.pack "removed" + keyC = Key.fromText (Text.pack "removed") valueC = Aeson.String (Text.pack "Me.") - keyBase = Text.pack "basename" + keyBase = Key.fromText (Text.pack "basename") valueBase = Aeson.String (Text.pack "example") -- 1. Insert C @@ -117,19 +118,19 @@ testMetadata = -- 3. Insert B dictionary = fmap ( id - .> Contrib.insertMetadata (HashMap.fromList [ (keyC, valueC) ]) - .> Contrib.replaceMetadata (HashMap.fromList [ (keyA, valueA) ]) + .> Contrib.insertMetadata (KeyMap.fromList [ (keyC, valueC) ]) + .> Contrib.replaceMetadata (KeyMap.fromList [ (keyA, valueA) ]) .> Contrib.copyPropsToMetadata - .> Contrib.insertMetadata (HashMap.fromList [ (keyB, valueB) ]) + .> Contrib.insertMetadata (KeyMap.fromList [ (keyB, valueB) ]) ) example_md definition = fmap (List.reverse .> List.head) dictionary - lookupTitle def = HashMap.lookup keyA (Shikensu.metadata def) - lookupHello def = HashMap.lookup keyB (Shikensu.metadata def) - lookupRemoved def = HashMap.lookup keyC (Shikensu.metadata def) - lookupBasename def = HashMap.lookup keyBase (Shikensu.metadata def) + lookupTitle def = KeyMap.lookup keyA (Shikensu.metadata def) + lookupHello def = KeyMap.lookup keyB (Shikensu.metadata def) + lookupRemoved def = KeyMap.lookup keyC (Shikensu.metadata def) + lookupBasename def = KeyMap.lookup keyBase (Shikensu.metadata def) in testGroup "Metadata" diff --git a/tests/Test/Utilities.hs b/tests/Test/Utilities.hs index 7c4215f..26ca727 100644 --- a/tests/Test/Utilities.hs +++ b/tests/Test/Utilities.hs @@ -10,7 +10,7 @@ import Test.Helpers import Test.Tasty import Test.Tasty.HUnit -import qualified Data.HashMap.Strict as HashMap (singleton) +import qualified Data.Aeson.KeyMap as KeyMap (singleton) import qualified Data.List as List (head) import qualified Data.Tuple as Tuple (fst) import qualified Shikensu.Contrib as Contrib @@ -54,7 +54,7 @@ testMetadataAccessors = definition = "." |> define thePattern - |> fmap (Contrib.insertMetadataDef $ HashMap.singleton "a" "Hi!") + |> fmap (Contrib.insertMetadataDef $ KeyMap.singleton "a" "Hi!") resultExisting = fmap (\d -> metadata d ~> "a" :: Maybe String) definition