-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | RON Storage -- -- Replicated Object Notation (RON), data types (RDT), and RON-Schema -- -- Typical usage: -- --
-- import RON.Data
-- import RON.Schema.TH
-- import RON.Storage.FS as Storage
--
-- [mkReplicated|
-- (struct_lww Note
-- active Boole
-- text RgaString)
-- |]
--
-- instance Collection Note where
-- collectionName = "note"
--
-- main :: IO ()
-- main = do
-- let dataDir = "./data/"
-- h <- Storage.newHandle dataDir
-- runStorage h $ do
-- obj <- newObject
-- Note{active = True, text = "Write a task manager"}
-- createDocument obj
--
@package ron-storage
@version 0.7
-- | RON Storage details. Use of this module only to implement a backend.
module RON.Storage.Backend
-- | A type that intended to be put in a separate collection must define a
-- Collection instance.
class (ReplicatedAsObject a, Typeable a) => Collection a
collectionName :: Collection a => CollectionName
-- | Called when RON parser fails.
fallbackParse :: (Collection a, MonadE m) => UUID -> ByteStringL -> m (Object a)
-- | Collection (directory name)
type CollectionName = FilePath
-- | Document identifier (directory name), should be a RON-Base32-encoded
-- RON-UUID.
newtype DocId a
DocId :: FilePath -> DocId a
-- | Result of DB reading, loaded document with information about its
-- versions
data Document a
Document :: Object a -> NonEmpty DocVersion -> IsTouched -> Document a
-- | Merged value.
[value] :: Document a -> Object a
[versions] :: Document a -> NonEmpty DocVersion
[isTouched] :: Document a -> IsTouched
-- | Document version identifier (file name)
type DocVersion = FilePath
-- | A thing (e.g. document) was fixed during loading. It it was fixed
-- during loading it must be saved to the storage.
newtype IsTouched
IsTouched :: Bool -> IsTouched
-- | Storage backend interface
class (ReplicaClock m, MonadE m) => MonadStorage m
getCollections :: MonadStorage m => m [CollectionName]
-- | Must return [] for non-existent collection
getDocuments :: (MonadStorage m, Collection a) => m [DocId a]
-- | Must return [] for non-existent document
getDocumentVersions :: (MonadStorage m, Collection a) => DocId a -> m [DocVersion]
-- | Must create collection and document if not exist
saveVersionContent :: (MonadStorage m, Collection a) => DocId a -> DocVersion -> ByteStringL -> m ()
loadVersionContent :: (MonadStorage m, Collection a) => DocId a -> DocVersion -> m ByteStringL
deleteVersion :: (MonadStorage m, Collection a) => DocId a -> DocVersion -> m ()
changeDocId :: (MonadStorage m, Collection a) => DocId a -> DocId a -> m ()
-- | Create new version of an object/document. If the document doesn't
-- exist yet, it will be created.
createVersion :: forall a m. (Collection a, MonadStorage m) => Maybe (DocId a, Document a) -> Object a -> m ()
-- | Try decode UUID from a file name
decodeDocId :: DocId a -> Maybe (Bool, UUID)
-- | Load document version as an object
readVersion :: MonadStorage m => Collection a => DocId a -> DocVersion -> m (Object a, IsTouched)
instance GHC.Show.Show (RON.Storage.Backend.Document a)
instance GHC.Show.Show RON.Storage.Backend.IsTouched
instance GHC.Classes.Ord (RON.Storage.Backend.DocId a)
instance GHC.Classes.Eq (RON.Storage.Backend.DocId a)
instance RON.Storage.Backend.Collection a => GHC.Show.Show (RON.Storage.Backend.DocId a)
-- | RON Storage interface. For usage, see RON.Storage.FS.
module RON.Storage
-- | A type that intended to be put in a separate collection must define a
-- Collection instance.
class (ReplicatedAsObject a, Typeable a) => Collection a
collectionName :: Collection a => CollectionName
-- | Called when RON parser fails.
fallbackParse :: (Collection a, MonadE m) => UUID -> ByteStringL -> m (Object a)
data CollectionDocId
CollectionDocId :: DocId a -> CollectionDocId
-- | Collection (directory name)
type CollectionName = FilePath
-- | Document identifier (directory name), should be a RON-Base32-encoded
-- RON-UUID.
data DocId a
-- | Create document assuming it doesn't exist yet.
createDocument :: (Collection a, MonadStorage m) => Object a -> m ()
-- | Try decode UUID from a file name
decodeDocId :: DocId a -> Maybe (Bool, UUID)
docIdFromUuid :: UUID -> DocId a
-- | Load all versions of a document
loadDocument :: (Collection a, MonadStorage m) => DocId a -> m (Document a)
-- | Load document, apply changes and put it back to storage
modify :: (Collection a, MonadStorage m) => DocId a -> StateT (Object a) m () -> m (Object a)
-- | A real-world file storage.
--
-- Typical usage:
--
--
-- import RON.Storage.FS as Storage
--
-- main = do
-- let dataDir = "./data/"
-- h <- Storage.newHandle dataDir
-- runStorage h $ do
-- obj <- newObject Note{active = True, text = "Write an example"}
-- createDocument obj
--
module RON.Storage.FS
-- | Storage handle (uses the “Handle pattern”).
data Handle
-- | Create new storage handle
newHandle :: FilePath -> IO Handle
-- | Environment is the dataDir
data Storage a
-- | Run a Storage action
runStorage :: Handle -> Storage a -> IO a
subscribeForever :: Handle -> (CollectionDocId -> IO ()) -> IO ()
instance Control.Monad.IO.Class.MonadIO RON.Storage.FS.Storage
instance Control.Monad.Error.Class.MonadError RON.Error.Error RON.Storage.FS.Storage
instance GHC.Base.Monad RON.Storage.FS.Storage
instance GHC.Base.Functor RON.Storage.FS.Storage
instance GHC.Base.Applicative RON.Storage.FS.Storage
instance RON.Event.ReplicaClock RON.Storage.FS.Storage
instance RON.Storage.Backend.MonadStorage RON.Storage.FS.Storage
module RON.Storage.Test
type TestDB = Map CollectionName (Map DocumentId (Map DocVersion Document))
runStorageSim :: TestDB -> StorageSim a -> Either Error (a, TestDB)
instance RON.Event.ReplicaClock RON.Storage.Test.StorageSim
instance Control.Monad.Error.Class.MonadError RON.Error.Error RON.Storage.Test.StorageSim
instance GHC.Base.Monad RON.Storage.Test.StorageSim
instance GHC.Base.Functor RON.Storage.Test.StorageSim
instance GHC.Base.Applicative RON.Storage.Test.StorageSim
instance RON.Storage.Backend.MonadStorage RON.Storage.Test.StorageSim