polysemy-fskvstore 0.1.0.0 → 0.1.1.0
raw patch · 4 files changed
+69/−49 lines, 4 filesdep +polysemy-kvstoredep −polysemy-zoodep ~bytestringdep ~pathdep ~polysemysetup-changedPVP ok
version bump matches the API change (PVP)
Dependencies added: polysemy-kvstore
Dependencies removed: polysemy-zoo
Dependency ranges changed: bytestring, path, polysemy, rio, unliftio-path
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−0
- Setup.hs +0/−2
- polysemy-fskvstore.cabal +8/−8
- src/Polysemy/FSKVStore.hs +57/−39
ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for polysemy-fskvstore +## v0.1.1.0++* Fix inlining.+ ## v0.1.0.0 * Add interpreters for running a kvstore as a filesystem.
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
polysemy-fskvstore.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.2.+-- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack name: polysemy-fskvstore-version: 0.1.0.0+version: 0.1.1.0 synopsis: Run a KVStore as a filesystem in polysemy. category: Polysemy author: Daniel Firth@@ -31,10 +31,10 @@ src build-depends: base >=4.7 && <5- , bytestring- , path- , polysemy- , polysemy-zoo- , rio- , unliftio-path+ , bytestring >=0.9 && <0.12+ , path >=0.7.0 && <0.10+ , polysemy >=1.4.0.0 && <1.7+ , polysemy-kvstore >=0.1.2.0 && <0.2+ , rio >=0.1.0.0 && <=0.2+ , unliftio-path >=0.0.2.0 && <0.1 default-language: Haskell2010
src/Polysemy/FSKVStore.hs view
@@ -1,34 +1,39 @@ {-# LANGUAGE BlockArguments #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE LambdaCase #-}-{-# LANGUAGE PolyKinds #-}-{-# LANGUAGE TypeOperators #-}-module Polysemy.FSKVStore (- FSKVStore-, runFSKVStoreRelBS-, runFSKVStoreAbsBS-, runFSKVStoreRelUtf8-, runFSKVStoreAbsUtf8-) where+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE TypeOperators #-} -import Data.ByteString as BS-import Path-import Polysemy-import Polysemy.KVStore-import RIO (Text, readFileUtf8, writeFileUtf8)+module Polysemy.FSKVStore+ ( FSKVStore,+ runFSKVStoreRelBS,+ runFSKVStoreAbsBS,+ runFSKVStoreRelUtf8,+ runFSKVStoreAbsUtf8,+ )+where++import Data.ByteString as BS+import Path+import Polysemy+import Polysemy.KVStore+import RIO (Text, readFileUtf8, writeFileUtf8) import qualified UnliftIO.Path.Directory as U -- | Type synonym for a KVStore indexed by files. type FSKVStore b a = KVStore (Path b File) a -- | Run an `FSKVStore Rel ByteString` in the supplied directory in IO.-runFSKVStoreRelBS :: Members '[Embed IO] r- => Path b Dir- -> Sem (FSKVStore Rel ByteString ': r) a- -> Sem r a+--+-- @since 0.1.0.0+runFSKVStoreRelBS ::+ Members '[Embed IO] r =>+ Path b Dir ->+ Sem (FSKVStore Rel ByteString ': r) a ->+ Sem r a runFSKVStoreRelBS d = interpret \case- LookupKV k -> embed $ do+ LookupKV k -> embed $ do z <- U.doesFileExist (d </> k) if z then fmap Just . BS.readFile $ toFilePath $ d </> k@@ -37,14 +42,18 @@ U.createDirectoryIfMissing True (d </> parent k) case v of Nothing -> pure ()- Just x -> BS.writeFile (toFilePath (d </> k)) x+ Just x -> BS.writeFile (toFilePath (d </> k)) x+{-# INLINE runFSKVStoreRelBS #-} -- | Run an `FSKVStore Abs ByteString` in IO.-runFSKVStoreAbsBS :: Members '[Embed IO] r- => Sem (FSKVStore Abs ByteString ': r) a- -> Sem r a+--+-- @since 0.1.0.0+runFSKVStoreAbsBS ::+ Members '[Embed IO] r =>+ Sem (FSKVStore Abs ByteString ': r) a ->+ Sem r a runFSKVStoreAbsBS = interpret \case- LookupKV k -> embed $ do+ LookupKV k -> embed $ do z <- U.doesFileExist k if z then fmap Just . BS.readFile $ toFilePath k@@ -53,15 +62,19 @@ U.createDirectoryIfMissing True (parent k) case v of Nothing -> pure ()- Just x -> BS.writeFile (toFilePath k) x+ Just x -> BS.writeFile (toFilePath k) x+{-# INLINE runFSKVStoreAbsBS #-} -- | Run an `FSKVStore Rel Text` in the supplied directory in IO as UTF8.-runFSKVStoreRelUtf8 :: Members '[Embed IO] r- => Path b Dir- -> Sem (FSKVStore Rel Text ': r) a- -> Sem r a+--+-- @since 0.1.0.0+runFSKVStoreRelUtf8 ::+ Members '[Embed IO] r =>+ Path b Dir ->+ Sem (FSKVStore Rel Text ': r) a ->+ Sem r a runFSKVStoreRelUtf8 d = interpret \case- LookupKV k -> do+ LookupKV k -> do z <- U.doesFileExist (d </> k) if z then fmap Just . readFileUtf8 $ toFilePath $ d </> k@@ -70,14 +83,18 @@ U.createDirectoryIfMissing True (d </> parent k) case v of Nothing -> pure ()- Just x -> writeFileUtf8 (toFilePath (d </> k)) x+ Just x -> writeFileUtf8 (toFilePath (d </> k)) x+{-# INLINE runFSKVStoreRelUtf8 #-} -- | Run an `FSKVStore Abs Text` in IO as UTF8.-runFSKVStoreAbsUtf8 :: Members '[Embed IO] r- => Sem (FSKVStore Abs Text ': r) a- -> Sem r a+--+-- @since 0.1.0.0+runFSKVStoreAbsUtf8 ::+ Members '[Embed IO] r =>+ Sem (FSKVStore Abs Text ': r) a ->+ Sem r a runFSKVStoreAbsUtf8 = interpret \case- LookupKV k -> do+ LookupKV k -> do z <- U.doesFileExist k if z then fmap Just . readFileUtf8 $ toFilePath k@@ -86,4 +103,5 @@ U.createDirectoryIfMissing True (parent k) case v of Nothing -> pure ()- Just x -> writeFileUtf8 (toFilePath k) x+ Just x -> writeFileUtf8 (toFilePath k) x+{-# INLINE runFSKVStoreAbsUtf8 #-}