packages feed

json-directory 0.1.0.1 → 0.1.0.2

raw patch · 4 files changed

+19/−11 lines, 4 filesdep ~aesondep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: aeson, base

API changes (from Hackage documentation)

- Data.JSON.Directory: Rule :: (FilePath -> Bool) -> (FilePath -> Text) -> (FilePath -> IO (IResult Value)) -> Rule
+ Data.JSON.Directory: Rule :: (FilePath -> Bool) -> (FilePath -> Key) -> (FilePath -> IO (IResult Value)) -> Rule
- Data.JSON.Directory: [jsonKey] :: Rule -> FilePath -> Text
+ Data.JSON.Directory: [jsonKey] :: Rule -> FilePath -> Key

Files

README.md view
@@ -1,3 +1,8 @@+# JSON Directory++[![](https://img.shields.io/hackage/v/json-directory.svg?colorB=%23999&label=json-directory)](http://hackage.haskell.org/package/json-directory)+[![](https://builds.sr.ht/~lukec/json-directory/commits/nix.yml.svg)](https://builds.sr.ht/~lukec/json-directory/commits/nix.yml)+ Provides utilities for reading JSON structures out of directories. Directory entries become keys in a map, and the values are sourced from the contets of each entry.
json-directory.cabal view
@@ -1,7 +1,7 @@ cabal-version:       2.2  name:                json-directory-version:             0.1.0.1+version:             0.1.0.2 category:            Codec synopsis:            Load JSON from files in a directory structure description:         Load JSON from files in a directory structure. The object@@ -22,12 +22,12 @@ library   exposed-modules:     Data.JSON.Directory-  build-depends:       base ^>=4.12.0.0, aeson, bytestring, directory, filepath, text, unordered-containers+  build-depends:       base >=4.11 && <5.0, aeson >= 2, bytestring, directory, filepath, text, unordered-containers   hs-source-dirs:      src   default-language:    Haskell2010  executable jsondir-  build-depends:       base ^>=4.12.0.0, json-directory, bytestring, aeson, process, filepath, text, mtl+  build-depends:       base >=4.11, json-directory, bytestring, aeson, process, filepath, text, mtl   hs-source-dirs:      jsondir   default-language:    Haskell2010   main-is: Main.hs
jsondir/Main.hs view
@@ -8,6 +8,7 @@ import Control.Monad.Writer import Control.Monad.Except import Data.Aeson+import Data.Aeson.Key import Data.Foldable import Data.JSON.Directory import Data.List (isSuffixOf)@@ -27,7 +28,7 @@         let             rule = Rule                 { predicate = isSuffixOf pat-                , jsonKey   = Text.pack . takeBaseName+                , jsonKey   = Data.Aeson.Key.fromString . takeBaseName                 , parser    =                     let                         parse fp = do
src/Data/JSON/Directory.hs view
@@ -23,6 +23,8 @@ import Data.Aeson.Types import qualified Data.ByteString as BS import Data.HashMap.Strict+import Data.Aeson.KeyMap+import Data.Aeson.Key import Data.List import Data.Maybe import Data.Text (Text)@@ -48,7 +50,7 @@ data Rule = Rule     { predicate :: FilePath -> Bool         -- ^ A predicate to see if this rule applies.-    , jsonKey   :: FilePath -> Text+    , jsonKey   :: FilePath -> Key         -- ^ A function to transform the filename into a JSON key value     , parser    :: FilePath -> IO (IResult Value)         -- ^ Turn a file into a Value.  The @JSONPath@ in the @IResult@ will be@@ -59,7 +61,7 @@ jsonRule :: Rule jsonRule = Rule     { predicate = isSuffixOf ".json"-    , jsonKey   = Text.pack . takeBaseName+    , jsonKey   = Data.Aeson.Key.fromString . takeBaseName     , parser    = idecodeFileStrict     } @@ -67,7 +69,7 @@ textRule :: Rule textRule = Rule     { predicate = const True-    , jsonKey   = Text.pack . takeFileName+    , jsonKey   = Data.Aeson.Key.fromString . takeFileName     , parser    = fmap (ISuccess . String) . Text.readFile     } @@ -80,10 +82,10 @@     = Directory     | File (FilePath -> IO (IResult Value)) -pathType :: [Rule] -> FilePath -> IO (Text, EntryType)+pathType :: [Rule] -> FilePath -> IO (Key, EntryType) pathType rules p = do     doesDirectoryExist p >>= \case-        True -> pure (Text.pack $ takeFileName p, Directory)+        True -> pure (Data.Aeson.Key.fromString $ takeFileName p, Directory)         False -> case find (\r -> predicate r p) rules of             Nothing   -> throwIO $ NoRuleFor p             Just rule -> pure (jsonKey rule p, File (parser rule))@@ -102,9 +104,9 @@                 (n, File parser) -> (n,) . addContext n <$> parser path'     time2 <- getModificationTime path     unless (time == time2) $ throwIO (ModifiedWhileReading path)-    pure $ Object <$> sequence (Data.HashMap.Strict.fromList kvs)+    pure $ Object <$> sequence (Data.Aeson.KeyMap.fromList kvs) -addContext :: Text -> IResult a -> IResult a+addContext :: Key -> IResult a -> IResult a addContext c (IError p s) = IError (Key c : p) s addContext _ x = x