dirfiles 0.1.0.1 → 0.1.0.2
raw patch · 3 files changed
+46/−40 lines, 3 filesdep +hblockdep −special-keysdep ~aesondep ~containersdep ~safecopy
Dependencies added: hblock
Dependencies removed: special-keys
Dependency ranges changed: aeson, containers, safecopy, text, time
Files
- Data/Library.hs +33/−32
- Data/Library/UUIRI.hs +4/−6
- dirfiles.cabal +9/−2
Data/Library.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE OverloadedStrings,TemplateHaskell #-}+{-# LANGUAGE OverloadedStrings,TemplateHaskell, BangPatterns #-} module Data.Library ( Library , ItemId@@ -20,21 +20,19 @@ import Data.Text (Text) import Data.IntSet (IntSet, insert, empty) import qualified Data.IntSet as IS-import Data.Sequence (Seq, adjust, (|>))+import Data.Sequence (Seq, (|>)) import qualified Data.Sequence as Seq import Data.Time.Clock (UTCTime) import Data.Library.UUIRI (UUIRI, iri, uuid, toUUIRI)-import Data.Foldable (toList)-import Data.Aeson (ToJSON(toJSON), FromJSON(parseJSON), object, (.=), (.:), (.:?), (.!=), Value(Object, Null))-import Data.Aeson.Types (Parser) import Control.Applicative ((<$>), (<*>)) import Control.Monad (mzero)-import qualified Data.HashMap.Strict as HM import Data.SafeCopy (deriveSafeCopy, base) import Data.Maybe (fromMaybe)+import Data.Aeson ( ToJSON(toJSON), FromJSON(parseJSON), object+ , (.=), (.:), (.:?), Value(Object, Null)) -import Keys.UUID (nil, UUID(..))-import Data.UUID hiding (nil, UUID)+import Data.Indexation.UUID hiding (fromText)+import Data.Indexation.Constraints (Text256, Text4096, fromText) -- | A Library is just a rebranded Seq type Library = Seq LibraryItem@@ -70,14 +68,14 @@ -- | Changes the name of an item rename :: Library -> ItemId -> Text -> UTCTime -> Library-rename lib target name t = Seq.adjust (setName t name) target lib+rename lib target name t = Seq.adjust (setName t $ fromText name) target lib where setName t' n i = i { itemDateModified = t', itemName = n } -- | Sets the description of an item describe :: Library -> ItemId -> Text -> UTCTime -> Library describe lib target description t = - Seq.adjust (setDescription t description) target lib+ Seq.adjust (setDescription t $ fromText description) target lib where setDescription t' d i = i { itemDateModified = t' , itemDescription = Just d }@@ -86,7 +84,7 @@ touch :: Library -> ItemId -> UTCTime -> Library touch lib target t = Seq.adjust (setTime t) target lib where- setTime t i = i { itemDateModified = t }+ setTime t' i = i { itemDateModified = t' } -- | Create a new item in the library -- If createing a directory then uuiri must be Nothing@@ -98,8 +96,9 @@ return $ Seq.update parent up -- updates the library with it $ lib |> i -- adds the new item to the library where- i = Item (Seq.length lib) name description creationTime creationTime - parent $ maybe (Left (empty, empty)) Right uuiri+ i = Item (Seq.length lib) (fromText name) (fmap fromText description) + creationTime creationTime parent $ + maybe (Left $ Dir empty empty) Right uuiri -- | No bounds checking and doesn't filter deleted items -- returns an exception error when the item is not found@@ -121,13 +120,13 @@ itemOpInDir op item dir t = case itemType dir of Right _ -> Left $ InvalidDestination (itemId dir)- Left (files, dirs) -> Right $ + Left (Dir files dirs) -> Right $ if isDir item then dir { itemDateModified = t- , itemType = Left (files, op (itemId item) dirs) + , itemType = Left $ Dir files (op (itemId item) dirs) } else dir { itemDateModified = t- , itemType = Left (op (itemId item) files, dirs) + , itemType = Left $ Dir (op (itemId item) files) dirs } addItemInDir :: LibraryItem -> LibraryItem -> UTCTime @@ -144,16 +143,15 @@ data LibraryItem = Deleted | Item - { itemId :: ItemId -- root dir is 0- , itemName :: Text- , itemDescription :: Maybe Text -- short description- , itemDateCreated :: UTCTime- , itemDateModified :: UTCTime- , itemParent :: ItemId -- root dir has parent = 0- , itemType :: Either Directory UUIRI+ { itemId :: !ItemId -- root dir is 0+ , itemName :: !Text256+ , itemDescription :: !(Maybe Text4096) -- short description+ , itemDateCreated :: !UTCTime+ , itemDateModified :: !UTCTime+ , itemParent :: !ItemId -- root dir has parent = 0+ , itemType :: !(Either Directory UUIRI) } - {- testItems t = [ Item 0 "teste" (Just "isto eh um teste") t t 0 (Left (IS.singleton 1,IS.singleton 2))@@ -169,9 +167,10 @@ case itype of Right f -> ("uuid", toJSON (uuid f)) : ("url", toJSON (iri f)) : ("subdirectories", Null) : ("files",Null) : common- Left (f,d) -> ("uuid", Null) : ("url", Null) : - ("subdirectories", toJSON d) : ("files", toJSON f) : - common+ Left (Dir f d) -> + ("uuid", Null) : ("url", Null) : + ("subdirectories", toJSON d) : ("files", toJSON f) : + common where common = ["id" .= iid, "name" .= iname, "description" .= idesc , "created" .= icreated, "modified" .= imodified@@ -195,9 +194,10 @@ Just f -> makeUUIRI fuuid f where makeDir :: Maybe IntSet -> Maybe IntSet -> Either Directory UUIRI- makeDir i1 i2 = Left (fromMaybe (IS.empty) i1, fromMaybe (IS.empty) i2)+ makeDir i1 i2 = Left $ Dir (fromMaybe (IS.empty) i1) + (fromMaybe (IS.empty) i2) makeUUIRI :: Maybe UUID -> Text -> Either Directory UUIRI- makeUUIRI u iri = Right $ toUUIRI (fromMaybe nil u) iri+ makeUUIRI u iri' = Right $ toUUIRI (fromMaybe nil u) iri' parseJSON _ = mzero isDir :: LibraryItem -> Bool@@ -205,9 +205,9 @@ Right _ -> True _ -> False --- | A directory is just a tuple of IntSet's where the first one has the+-- | A directory is just a pair of IntSet's where the first one has the -- files, and the second has the subdirectories -type Directory = (IntSet, IntSet) +data Directory = Dir !IntSet !IntSet -- | Some errors that might occur@@ -225,4 +225,5 @@ return $ newFileText n t c -} -deriveSafeCopy 0 'base ''LibraryItem+$(deriveSafeCopy 0 'base ''Directory)+$(deriveSafeCopy 0 'base ''LibraryItem)
Data/Library/UUIRI.hs view
@@ -14,19 +14,16 @@ ) where -import Data.Text (Text, breakOn, split, splitOn)-import qualified Data.Text as T -import Data.Maybe+import Data.Text (Text) import Data.Library.IRI (IRI, fromIRI) import qualified Data.Library.IRI as IRI-import Keys.UUID (UUID) import Data.Aeson (ToJSON(toJSON), FromJSON(parseJSON), object, (.=), (.:), Value(Object)) import Control.Applicative ((<$>), (<*>)) import Control.Monad (mzero) import Data.SafeCopy (deriveSafeCopy, base)+import Data.Indexation.UUID (UUID) newtype UUIRI = UUIRI (UUID, IRI) -deriveSafeCopy 0 'base ''UUIRI -- from Data.SafeCopy instance Eq UUIRI where uuiri1 == uuiri2 = uuid uuiri1 == uuid uuiri2@@ -52,7 +49,7 @@ -- | returns the UUIRI tuple with the IRI translated to Text fromUUIRI :: UUIRI -> (UUID, Text)-fromUUIRI (UUIRI (u,iri)) = (u, IRI.fromIRI iri)+fromUUIRI (UUIRI (u,iri')) = (u, IRI.fromIRI iri') -- | is the IRI part of the UUIRI a relative IRI ? isRelative :: UUIRI -> Bool@@ -78,3 +75,4 @@ dirs :: UUIRI -> [Text] dirs = IRI.dirs . iri +$(deriveSafeCopy 0 'base ''UUIRI) -- from Data.SafeCopy
dirfiles.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: dirfiles-version: 0.1.0.1+version: 0.1.0.2 -- synopsis: description: Simple datatype to represent a library with files and folders license: BSD3@@ -19,6 +19,13 @@ exposed-modules: Data.Library, Data.Library.UUIRI, Data.Library.IRI -- other-modules: other-extensions: OverloadedStrings, TemplateHaskell- build-depends: base >=4.6 && <4.7, text >=0.11 && <0.12, containers >=0.5 && <0.6, time >=1.4 && <1.5, aeson >=0.6 && <0.7, unordered-containers >=0.2 && <0.3, safecopy >=0.8 && <0.9, special-keys >=0.1 && <0.2+ build-depends: base >=4.6 && <4.7+ , text >=0.11 + , containers >=0.5 + , time >=1.4 + , aeson >=0.6 + , unordered-containers >=0.2 && <0.3+ , safecopy >=0.8 + , hblock >=0.1 -- hs-source-dirs: default-language: Haskell2010