summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-10-30 21:42:35 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2024-11-06 21:03:16 +0100
commitd144e1d0b45421d102751cdf584126810ab33ba5 (patch)
treee2e8bb8d068a89ce814d4fdc25ebbebabfdf43a5
parentc4ff2f54c52e9ebb1c47aeb79284faf3fcbad4e3 (diff)
Create new Object, Storable and Storage modules
Changelog: API: Split Erebos.Storage into multiple modules
-rw-r--r--erebos.cabal5
-rw-r--r--main/Main.hs4
-rw-r--r--main/Test.hs4
-rw-r--r--main/Test/Service.hs3
-rw-r--r--src/Erebos/Object.hs22
-rw-r--r--src/Erebos/Storable.hs39
-rw-r--r--src/Erebos/Storage.hs27
7 files changed, 100 insertions, 4 deletions
diff --git a/erebos.cabal b/erebos.cabal
index 5f3f33d..f16c879 100644
--- a/erebos.cabal
+++ b/erebos.cabal
@@ -102,20 +102,23 @@ library
Erebos.Message
Erebos.Network
Erebos.Network.Protocol
+ Erebos.Object
Erebos.Pairing
Erebos.PubKey
Erebos.Service
Erebos.Set
Erebos.State
+ Erebos.Storable
+ Erebos.Storage
Erebos.Storage.Key
Erebos.Storage.Merge
Erebos.Sync
-- Used by test tool:
- Erebos.Object.Internal
Erebos.Storage.Internal
other-modules:
Erebos.Flow
+ Erebos.Object.Internal
Erebos.Storage.Platform
Erebos.Util
diff --git a/main/Main.hs b/main/Main.hs
index b2aca21..b148aa6 100644
--- a/main/Main.hs
+++ b/main/Main.hs
@@ -47,11 +47,13 @@ import Erebos.ICE
import Erebos.Identity
import Erebos.Message hiding (formatMessage)
import Erebos.Network
-import Erebos.Object.Internal
+import Erebos.Object
import Erebos.PubKey
import Erebos.Service
import Erebos.Set
import Erebos.State
+import Erebos.Storable
+import Erebos.Storage
import Erebos.Storage.Merge
import Erebos.Sync
diff --git a/main/Test.hs b/main/Test.hs
index 7dc7e43..4c23453 100644
--- a/main/Test.hs
+++ b/main/Test.hs
@@ -37,12 +37,14 @@ import Erebos.Contact
import Erebos.Identity
import Erebos.Message
import Erebos.Network
-import Erebos.Object.Internal
+import Erebos.Object
import Erebos.Pairing
import Erebos.PubKey
import Erebos.Service
import Erebos.Set
import Erebos.State
+import Erebos.Storable
+import Erebos.Storage
import Erebos.Storage.Internal (unsafeStoreRawBytes)
import Erebos.Storage.Merge
import Erebos.Sync
diff --git a/main/Test/Service.hs b/main/Test/Service.hs
index c81722d..8c58dee 100644
--- a/main/Test/Service.hs
+++ b/main/Test/Service.hs
@@ -8,8 +8,9 @@ import Control.Monad.Reader
import Data.ByteString.Lazy.Char8 qualified as BL
import Erebos.Network
-import Erebos.Object.Internal
+import Erebos.Object
import Erebos.Service
+import Erebos.Storable
data TestMessage = TestMessage (Stored Object)
diff --git a/src/Erebos/Object.hs b/src/Erebos/Object.hs
new file mode 100644
index 0000000..26ca09f
--- /dev/null
+++ b/src/Erebos/Object.hs
@@ -0,0 +1,22 @@
+{-|
+Description: Core Erebos objects and references
+
+Data types and functions for working with "raw" Erebos objects and references.
+-}
+
+module Erebos.Object (
+ Object, PartialObject, Object'(..),
+ serializeObject, deserializeObject, deserializeObjects,
+ ioLoadObject, ioLoadBytes,
+ storeRawBytes, lazyLoadBytes,
+
+ RecItem, RecItem'(..),
+
+ Ref, PartialRef, RefDigest,
+ refDigest,
+ readRef, showRef, showRefDigest,
+ refDigestFromByteString, hashToRefDigest,
+ copyRef, partialRef, partialRefFromDigest,
+) where
+
+import Erebos.Object.Internal
diff --git a/src/Erebos/Storable.hs b/src/Erebos/Storable.hs
new file mode 100644
index 0000000..15f43b3
--- /dev/null
+++ b/src/Erebos/Storable.hs
@@ -0,0 +1,39 @@
+{-|
+Description: Encoding custom types into Erebos objects
+
+Module provides the 'Storable' class for types that can be serialized to/from
+Erebos objects, along with various helpers, mostly for encoding using records.
+
+The 'Stored' wrapper for objects actually encoded and stored in some storage is
+defined here as well.
+-}
+
+module Erebos.Storable (
+ Storable(..), ZeroStorable(..),
+ StorableText(..), StorableDate(..), StorableUUID(..),
+
+ Store, StoreRec,
+ storeBlob, storeRec, storeZero,
+ storeEmpty, storeInt, storeNum, storeText, storeBinary, storeDate, storeUUID, storeRef, storeRawRef,
+ storeMbEmpty, storeMbInt, storeMbNum, storeMbText, storeMbBinary, storeMbDate, storeMbUUID, storeMbRef, storeMbRawRef,
+ storeZRef,
+ storeRecItems,
+
+ Load, LoadRec,
+ loadCurrentRef, loadCurrentObject,
+ loadRecCurrentRef, loadRecItems,
+
+ loadBlob, loadRec, loadZero,
+ loadEmpty, loadInt, loadNum, loadText, loadBinary, loadDate, loadUUID, loadRef, loadRawRef,
+ loadMbEmpty, loadMbInt, loadMbNum, loadMbText, loadMbBinary, loadMbDate, loadMbUUID, loadMbRef, loadMbRawRef,
+ loadTexts, loadBinaries, loadRefs, loadRawRefs,
+ loadZRef,
+
+ Stored,
+ fromStored, storedRef,
+ wrappedStore, wrappedLoad,
+ copyStored,
+ unsafeMapStored,
+) where
+
+import Erebos.Object.Internal
diff --git a/src/Erebos/Storage.hs b/src/Erebos/Storage.hs
new file mode 100644
index 0000000..3b2ce4a
--- /dev/null
+++ b/src/Erebos/Storage.hs
@@ -0,0 +1,27 @@
+{-|
+Description: Working with storage and heads
+
+Provides functions for opening 'Storage' backed either by disk or memory. For
+conveniance also function for working with 'Head's are reexported here.
+-}
+
+module Erebos.Storage (
+ Storage, PartialStorage,
+ openStorage, memoryStorage,
+ deriveEphemeralStorage, derivePartialStorage,
+
+ Head, HeadType(..),
+ HeadTypeID, mkHeadTypeID,
+ headId, headStorage, headRef, headObject, headStoredObject,
+ loadHeads, loadHead, reloadHead,
+ storeHead, replaceHead, updateHead, updateHead_,
+ loadHeadRaw, storeHeadRaw, replaceHeadRaw,
+
+ WatchedHead,
+ watchHead, watchHeadWith, unwatchHead,
+ watchHeadRaw,
+
+ MonadStorage(..),
+) where
+
+import Erebos.Object.Internal