-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | RON, RON-RDT, and RON-Schema -- -- Replicated Object Notation (RON), data types (RDT), and RON-Schema -- -- Typical usage: -- --
-- import RON.Data
-- import RON.Schema.TH
-- import RON.Storage.IO 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
@version 0.4
-- | Common types for binary format (parser and serializer)
module RON.Binary.Types
type Size = Word32
-- | Data block descriptor
data Desc
DOpRaw :: Desc
DOpReduced :: Desc
DOpHeader :: Desc
DOpQueryHeader :: Desc
DUuidType :: Desc
DUuidObject :: Desc
DUuidEvent :: Desc
DUuidRef :: Desc
DAtomUuidZip :: Desc
DUuidZipObject :: Desc
DUuidZipEvent :: Desc
DUuidZipRef :: Desc
DAtomUuid :: Desc
DAtomInteger :: Desc
DAtomString :: Desc
DAtomFloat :: Desc
-- | Does the descriptor refer to an op
descIsOp :: Desc -> Bool
instance GHC.Show.Show RON.Binary.Types.Desc
instance GHC.Classes.Eq RON.Binary.Types.Desc
instance GHC.Enum.Enum RON.Binary.Types.Desc
module RON.Schema
data CaseTransform
TitleCase :: CaseTransform
data Declaration
DEnum :: TEnum -> Declaration
DOpaque :: Opaque -> Declaration
DStructLww :: StructLww -> Declaration
newtype Field
Field :: RonType -> Field
[fieldType] :: Field -> RonType
data Opaque
Opaque :: Bool -> Text -> OpaqueAnnotations -> Opaque
[opaqueIsObject] :: Opaque -> Bool
[opaqueName] :: Opaque -> Text
[opaqueAnnotations] :: Opaque -> OpaqueAnnotations
newtype OpaqueAnnotations
OpaqueAnnotations :: Maybe Text -> OpaqueAnnotations
[oaHaskellType] :: OpaqueAnnotations -> Maybe Text
data RonType
TAtom :: TAtom -> RonType
TComposite :: TComposite -> RonType
TObject :: TObject -> RonType
TOpaque :: Opaque -> RonType
type Schema = [Declaration]
data StructAnnotations
StructAnnotations :: Text -> Maybe CaseTransform -> StructAnnotations
[saHaskellFieldPrefix] :: StructAnnotations -> Text
[saHaskellFieldCaseTransform] :: StructAnnotations -> Maybe CaseTransform
data StructLww
StructLww :: Text -> Map Text Field -> StructAnnotations -> StructLww
[structName] :: StructLww -> Text
[structFields] :: StructLww -> Map Text Field
[structAnnotations] :: StructLww -> StructAnnotations
data TAtom
TAInteger :: TAtom
TAString :: TAtom
data TEnum
Enum :: Text -> [Text] -> TEnum
[enumName] :: TEnum -> Text
[enumItems] :: TEnum -> [Text]
data TComposite
TOption :: RonType -> TComposite
TEnum :: TEnum -> TComposite
data TObject
TORSet :: RonType -> TObject
TRga :: RonType -> TObject
TStructLww :: StructLww -> TObject
TVersionVector :: TObject
defaultOpaqueAnnotations :: OpaqueAnnotations
defaultStructAnnotations :: StructAnnotations
opaqueAtoms :: Text -> OpaqueAnnotations -> RonType
opaqueAtoms_ :: Text -> RonType
opaqueObject :: Text -> OpaqueAnnotations -> RonType
instance GHC.Show.Show RON.Schema.TComposite
instance GHC.Show.Show RON.Schema.Field
instance GHC.Show.Show RON.Schema.StructLww
instance GHC.Show.Show RON.Schema.TObject
instance GHC.Show.Show RON.Schema.RonType
instance GHC.Show.Show RON.Schema.Opaque
instance GHC.Show.Show RON.Schema.OpaqueAnnotations
instance GHC.Show.Show RON.Schema.StructAnnotations
instance GHC.Show.Show RON.Schema.CaseTransform
instance GHC.Show.Show RON.Schema.TEnum
instance GHC.Show.Show RON.Schema.TAtom
module RON.Util.Word
data Word2
b00 :: Word2
b01 :: Word2
b10 :: Word2
b11 :: Word2
pattern B00 :: Word2
pattern B01 :: Word2
pattern B10 :: Word2
pattern B11 :: Word2
-- | Word2 smart constructor dropping upper bits
leastSignificant2 :: Integral integral => integral -> Word2
data Word4
b0000 :: Word4
b0001 :: Word4
b0010 :: Word4
b0011 :: Word4
b0100 :: Word4
b0101 :: Word4
b0110 :: Word4
b0111 :: Word4
b1000 :: Word4
b1001 :: Word4
b1010 :: Word4
b1011 :: Word4
b1100 :: Word4
b1101 :: Word4
b1110 :: Word4
b1111 :: Word4
pattern B0000 :: Word4
-- | Word4 smart constructor dropping upper bits
leastSignificant4 :: Integral integral => integral -> Word4
newtype Word6
W6 :: Word8 -> Word6
-- | Word6 smart constructor dropping upper bits
leastSignificant6 :: Integral integral => integral -> Word6
-- | leastSignificant6 specialized for Word8
ls6 :: Word8 -> Word6
-- | 8-bit unsigned integer type
data Word8
data Word12
-- | Word12 smart constructor dropping upper bits
leastSignificant12 :: Integral integral => integral -> Word12
-- | leastSignificant12 specialized for Word16
ls12 :: Word16 -> Word12
-- | 16-bit unsigned integer type
data Word16
data Word24
-- | Word24 smart constructor dropping upper bits
leastSignificant24 :: Integral integral => integral -> Word24
-- | leastSignificant24 specialized for Word32
ls24 :: Word32 -> Word24
-- | 32-bit unsigned integer type
data Word32
data Word60
-- | Word60 smart constructor dropping upper bits
leastSignificant60 :: Integral integral => integral -> Word60
-- | leastSignificant60 specialized for Word64
ls60 :: Word64 -> Word60
-- | Word60 smart constructor checking domain
toWord60 :: Word64 -> Maybe Word60
word60add :: Word60 -> Word60 -> Word60
-- | 64-bit unsigned integer type
data Word64
class SafeCast v w
safeCast :: SafeCast v w => v -> w
instance GHC.Show.Show RON.Util.Word.Word60
instance GHC.Classes.Ord RON.Util.Word.Word60
instance GHC.Classes.Eq RON.Util.Word.Word60
instance GHC.Enum.Enum RON.Util.Word.Word60
instance GHC.Show.Show RON.Util.Word.Word24
instance GHC.Classes.Ord RON.Util.Word.Word24
instance GHC.Classes.Eq RON.Util.Word.Word24
instance GHC.Show.Show RON.Util.Word.Word12
instance GHC.Classes.Ord RON.Util.Word.Word12
instance GHC.Classes.Eq RON.Util.Word.Word12
instance GHC.Show.Show RON.Util.Word.Word6
instance GHC.Classes.Ord RON.Util.Word.Word6
instance GHC.Classes.Eq RON.Util.Word.Word6
instance GHC.Show.Show RON.Util.Word.Word4
instance GHC.Classes.Ord RON.Util.Word.Word4
instance GHC.Classes.Eq RON.Util.Word.Word4
instance GHC.Show.Show RON.Util.Word.Word2
instance GHC.Classes.Ord RON.Util.Word.Word2
instance GHC.Classes.Eq RON.Util.Word.Word2
instance RON.Util.Word.SafeCast RON.Util.Word.Word2 GHC.Types.Int
instance RON.Util.Word.SafeCast RON.Util.Word.Word2 RON.Util.Word.Word4
instance RON.Util.Word.SafeCast RON.Util.Word.Word2 GHC.Word.Word8
instance RON.Util.Word.SafeCast RON.Util.Word.Word2 GHC.Word.Word64
instance RON.Util.Word.SafeCast RON.Util.Word.Word4 GHC.Types.Int
instance RON.Util.Word.SafeCast RON.Util.Word.Word4 GHC.Word.Word64
instance RON.Util.Word.SafeCast RON.Util.Word.Word4 GHC.Word.Word8
instance RON.Util.Word.SafeCast RON.Util.Word.Word6 GHC.Types.Int
instance RON.Util.Word.SafeCast RON.Util.Word.Word6 GHC.Word.Word8
instance RON.Util.Word.SafeCast RON.Util.Word.Word6 RON.Util.Word.Word60
instance RON.Util.Word.SafeCast RON.Util.Word.Word6 GHC.Word.Word64
instance RON.Util.Word.SafeCast GHC.Word.Word8 GHC.Word.Word32
instance RON.Util.Word.SafeCast GHC.Word.Word8 GHC.Word.Word64
instance RON.Util.Word.SafeCast RON.Util.Word.Word12 GHC.Word.Word64
instance RON.Util.Word.SafeCast RON.Util.Word.Word24 GHC.Word.Word64
instance RON.Util.Word.SafeCast RON.Util.Word.Word24 GHC.Word.Word32
instance RON.Util.Word.SafeCast RON.Util.Word.Word60 GHC.Word.Word64
instance RON.Util.Word.SafeCast GHC.Word.Word64 GHC.Integer.Type.Integer
instance Data.Fixed.HasResolution e => RON.Util.Word.SafeCast GHC.Word.Word64 (Data.Fixed.Fixed e)
instance GHC.Enum.Bounded RON.Util.Word.Word60
instance Data.Hashable.Class.Hashable RON.Util.Word.Word60
-- | RON version of Base64 encoding
module RON.Base64
-- | Base64 alphabet
alphabet :: ByteString
-- | Decode a blob from a Base64 string
decode :: ByteStringL -> Maybe ByteStringL
-- | Decode a 60-bit number from a Base64 string
decode60 :: ByteString -> Maybe Word60
-- | Decode a 60-bit number from a Base32 string
decode60base32 :: ByteString -> Maybe Word60
-- | Decode a 64-bit number from a Base64 string
decode64 :: ByteString -> Maybe Word64
-- | Decode a 64-bit number from a Base32 string
decode64base32 :: ByteString -> Maybe Word64
-- | Convert a Base64 letter to a number [0-63]
decodeLetter :: Word8 -> Maybe Word6
-- | Convert a subset [0-F] of Base64 letters to a number [0-15]
decodeLetter4 :: Word8 -> Maybe Word4
-- | Encode a blob to a Base64 string
encode :: ByteStringL -> ByteStringL
-- | Encode a 60-bit number to a Base64 string
encode60 :: Word60 -> ByteString
-- | Encode a 60-bit number to a Base64 string, dropping trailing zeroes
encode60short :: Word60 -> ByteString
-- | Encode a 64-bit number to a Base64 string
encode64 :: Word64 -> ByteString
-- | Encode a 64-bit number to a Base32 string, dropping trailing zeroes
encode64base32short :: Word64 -> ByteString
-- | Convert a number from [0..63] to a single letter
encodeLetter :: Word6 -> Word8
-- | Convert a number from [0..15] to a single letter
encodeLetter4 :: Word4 -> Word8
-- | Check if a character is in the Base64 alphabet.
isLetter :: Word8 -> Bool
module RON.UUID
-- | Universally unique identifier of anything
data UUID
UUID :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> UUID
-- | UUID split in parts
data UuidFields
UuidFields :: !Word4 -> !Word60 -> !Word2 -> !Word2 -> !Word60 -> UuidFields
[uuidVariety] :: UuidFields -> !Word4
[uuidValue] :: UuidFields -> !Word60
[uuidVariant] :: UuidFields -> !Word2
[uuidVersion] :: UuidFields -> !Word2
[uuidOrigin] :: UuidFields -> !Word60
-- | Build UUID from parts
build :: UuidFields -> UUID
-- | Build former 64 bits of UUID from parts
buildX :: Word4 -> Word60 -> Word64
-- | Build latter 64 bits of UUID from parts
buildY :: Word2 -> Word2 -> Word60 -> Word64
-- | Split UUID into parts
split :: UUID -> UuidFields
-- | Increment field uuidValue of a UUID
succValue :: UUID -> UUID
-- | UUID with all zero fields
zero :: UUID
-- | UUID with all zero fields
pattern Zero :: UUID
-- | Convert UUID to a name
getName :: UUID -> Maybe (ByteString, ByteString)
-- | Make an unscoped (unqualified) name
mkName :: Monad m => ByteString -> m UUID
-- | Make a scoped (qualified) name
mkScopedName :: Monad m => ByteString -> ByteString -> m UUID
-- | Decode a UUID from a Base32 string
decodeBase32 :: FilePath -> Maybe UUID
-- | Encode a UUID to a Base32 string
encodeBase32 :: UUID -> FilePath
instance GHC.Show.Show RON.UUID.UuidFields
instance GHC.Classes.Eq RON.UUID.UuidFields
instance GHC.Classes.Ord RON.UUID.UUID
instance Data.Hashable.Class.Hashable RON.UUID.UUID
instance GHC.Generics.Generic RON.UUID.UUID
instance GHC.Classes.Eq RON.UUID.UUID
instance Data.Data.Data RON.UUID.UUID
instance GHC.Show.Show RON.UUID.UUID
-- | RON model types
module RON.Types
-- | Atom — a payload element
data Atom
AFloat :: Double -> Atom
AInteger :: Int64 -> Atom
AString :: Text -> Atom
AUuid :: UUID -> Atom
-- | Reference to an object inside a frame.
data Object a
Object :: UUID -> StateFrame -> Object a
[objectId] :: Object a -> UUID
[objectFrame] :: Object a -> StateFrame
-- | A pair of (type, object)
type ObjectId = (UUID, UUID)
-- | Specific field or item in an object, identified by UUID.
data ObjectPart obj part
ObjectPart :: UUID -> UUID -> StateFrame -> ObjectPart obj part
[partObject] :: ObjectPart obj part -> UUID
[partLocation] :: ObjectPart obj part -> UUID
[partFrame] :: ObjectPart obj part -> StateFrame
-- | “Reduced” op (op from reduced chunk)
data Op
Op :: UUID -> UUID -> [Atom] -> Op
-- | event id (usually timestamp)
[opEvent] :: Op -> UUID
-- | reference to other op; actual semantics depends on the type
[opRef] :: Op -> UUID
-- | payload
[opPayload] :: Op -> [Atom]
-- | Op terminator
data OpTerm
TRaw :: OpTerm
TReduced :: OpTerm
THeader :: OpTerm
TQuery :: OpTerm
-- | Raw op
data RawOp
RawOp :: UUID -> UUID -> Op -> RawOp
-- | type
[opType] :: RawOp -> UUID
-- | object id
[opObject] :: RawOp -> UUID
-- | other keys and payload, that are common with reduced op
[op] :: RawOp -> Op
-- | Reduced chunk representing an object state (i. e. high-level value)
data StateChunk
StateChunk :: UUID -> [Op] -> StateChunk
[stateVersion] :: StateChunk -> UUID
[stateBody] :: StateChunk -> [Op]
-- | Frame containing only state chunks
type StateFrame = Map ObjectId StateChunk
-- | Universally unique identifier of anything
data UUID
UUID :: {-# UNPACK #-} !Word64 -> {-# UNPACK #-} !Word64 -> UUID
-- | Common chunk
data WireChunk
Raw :: RawOp -> WireChunk
Value :: WireReducedChunk -> WireChunk
Query :: WireReducedChunk -> WireChunk
-- | Common frame
type WireFrame = [WireChunk]
-- | Common reduced chunk
data WireReducedChunk
WireReducedChunk :: RawOp -> [Op] -> WireReducedChunk
[wrcHeader] :: WireReducedChunk -> RawOp
[wrcBody] :: WireReducedChunk -> [Op]
instance GHC.Show.Show (RON.Types.Object a)
instance GHC.Classes.Eq (RON.Types.Object a)
instance GHC.Show.Show RON.Types.StateChunk
instance GHC.Classes.Eq RON.Types.StateChunk
instance GHC.Show.Show RON.Types.OpTerm
instance GHC.Classes.Eq RON.Types.OpTerm
instance GHC.Show.Show RON.Types.WireChunk
instance GHC.Generics.Generic RON.Types.WireChunk
instance GHC.Classes.Eq RON.Types.WireChunk
instance Data.Data.Data RON.Types.WireChunk
instance GHC.Show.Show RON.Types.WireReducedChunk
instance GHC.Generics.Generic RON.Types.WireReducedChunk
instance GHC.Classes.Eq RON.Types.WireReducedChunk
instance Data.Data.Data RON.Types.WireReducedChunk
instance GHC.Generics.Generic RON.Types.RawOp
instance GHC.Classes.Eq RON.Types.RawOp
instance Data.Data.Data RON.Types.RawOp
instance GHC.Show.Show RON.Types.Op
instance Data.Hashable.Class.Hashable RON.Types.Op
instance GHC.Generics.Generic RON.Types.Op
instance GHC.Classes.Eq RON.Types.Op
instance Data.Data.Data RON.Types.Op
instance GHC.Show.Show RON.Types.Atom
instance Data.Hashable.Class.Hashable RON.Types.Atom
instance GHC.Generics.Generic RON.Types.Atom
instance GHC.Classes.Eq RON.Types.Atom
instance Data.Data.Data RON.Types.Atom
instance GHC.Show.Show RON.Types.RawOp
-- | Binary serializer elements
module RON.Binary.Serialize
-- | Serialize a frame
serialize :: WireFrame -> Either String ByteStringL
-- | Serialize an Atom
serializeAtom :: Atom -> Either String ByteStringL
-- | Serialize a string atom
serializeString :: Text -> ByteStringL
-- | Binary parser elements
module RON.Binary.Parse
-- | Parse frame
parse :: ByteStringL -> Either String WireFrame
-- | Parse an Atom
parseAtom :: ByteStringL -> Either String Atom
-- | Parse a string atom
parseString :: ByteStringL -> Either String Text
-- | RON-Binary wire format
module RON.Binary
-- | Parse frame
parse :: ByteStringL -> Either String WireFrame
-- | Serialize a frame
serialize :: WireFrame -> Either String ByteStringL
module RON.Event
-- | Calendar format. See https://github.com/gritzko/ron/issues/19.
-- Year range is 2010—2350. Precision is 100 ns.
data CalendarTime
CalendarTime :: Word12 -> Word6 -> Word6 -> Word6 -> Word6 -> Word24 -> CalendarTime
[months] :: CalendarTime -> Word12
[days] :: CalendarTime -> Word6
[hours] :: CalendarTime -> Word6
[minutes] :: CalendarTime -> Word6
[seconds] :: CalendarTime -> Word6
[nanosecHundreds] :: CalendarTime -> Word24
-- | Calendar-based Lamport time event, specific case of Event.
data CalendarEvent
CalendarEvent :: !CalendarTime -> !ReplicaId -> CalendarEvent
-- | Epoch-based Lamport time event, specific case of Event.
data EpochEvent
EpochEvent :: !EpochTime -> !ReplicaId -> EpochEvent
-- | RFC 4122 epoch, hundreds of nanoseconds since 1582. Year range is
-- 1582—5235.
type EpochTime = Word60
-- | Generic Lamport time event. Cannot be Ord because we can't
-- compare different types of clocks. If you want comparable events, use
-- specific EpochEvent.
data Event
Event :: !LocalTime -> !ReplicaId -> Event
-- | Clock type is encoded in 2 higher bits of variety, value in uuidValue
data LocalTime
TCalendar :: !CalendarTime -> LocalTime
-- | https://en.wikipedia.org/wiki/Logical_clock
TLogical :: !Word60 -> LocalTime
TEpoch :: !EpochTime -> LocalTime
TUnknown :: !Word60 -> LocalTime
-- | Replica id assignment style
data Naming
TrieForked :: Naming
CryptoForked :: Naming
RecordForked :: Naming
ApplicationSpecific :: Naming
class Monad m => ReplicaClock m
-- | Get current replica id
getPid :: ReplicaClock m => m ReplicaId
-- | Get sequential timestamps.
--
-- Laws:
--
-- t <- getEvents n (t !! i) == head t + i
t1 <- getEvent t2 <- getEvent t2 >= -- t1 + 1
getEvents 0 == getEvents 1
-- runNetworkSim $ do -- runReplicaSim r1 $ do -- actions... -- runReplicaSim r2 $ do -- actions... -- runReplicaSim r1 $ ... ---- -- Each runNetworkSim starts its own networks. One shouldn't use -- in one network events generated in another. runNetworkSim :: NetworkSim a -> a runNetworkSimT :: Monad m => NetworkSimT m a -> m a runReplicaSim :: ReplicaId -> ReplicaSim a -> NetworkSim a runReplicaSimT :: ReplicaId -> ReplicaSimT m a -> NetworkSimT m a instance GHC.Base.Monad m => GHC.Base.Monad (RON.Event.Simulation.ReplicaSimT m) instance GHC.Base.Functor m => GHC.Base.Functor (RON.Event.Simulation.ReplicaSimT m) instance GHC.Base.Monad m => GHC.Base.Applicative (RON.Event.Simulation.ReplicaSimT m) instance GHC.Base.Monad m => GHC.Base.Monad (RON.Event.Simulation.NetworkSimT m) instance GHC.Base.Functor m => GHC.Base.Functor (RON.Event.Simulation.NetworkSimT m) instance GHC.Base.Monad m => GHC.Base.Applicative (RON.Event.Simulation.NetworkSimT m) instance Control.Monad.Trans.Class.MonadTrans RON.Event.Simulation.ReplicaSimT instance GHC.Base.Monad m => RON.Event.ReplicaClock (RON.Event.Simulation.ReplicaSimT m) instance Control.Monad.Trans.Class.MonadTrans RON.Event.Simulation.NetworkSimT module RON.Epoch -- | Real epoch clock. Uses kind of global variable to ensure strict -- monotonicity. data EpochClock a -- | Decode date and time from UUID epoch timestamp decode :: EpochTime -> UTCTime encode :: POSIXTime -> EpochTime -- | Get current time in EpochTime format (with 100 ns resolution). -- Monotonicity is not guaranteed. getCurrentEpochTime :: IO EpochTime -- | Convert unix time in hundreds of milliseconds to RFC 4122 time. localEpochTimeFromUnix :: Word64 -> LocalTime -- | Run EpochClock action with explicit time variable. runEpochClock :: ReplicaId -> IORef EpochTime -> EpochClock a -> IO a -- | Like runEpochClock, but initialize time variable with current -- wall time. runEpochClockFromCurrentTime :: ReplicaId -> EpochClock a -> IO a instance Control.Monad.IO.Class.MonadIO RON.Epoch.EpochClock instance GHC.Base.Monad RON.Epoch.EpochClock instance GHC.Base.Functor RON.Epoch.EpochClock instance GHC.Base.Applicative RON.Epoch.EpochClock instance RON.Event.ReplicaClock RON.Epoch.EpochClock -- | Version Vector module RON.Data.VersionVector -- | Version Vector type. May be used both in typed and untyped contexts. data VersionVector instance GHC.Show.Show RON.Data.VersionVector.VersionVector instance GHC.Classes.Eq RON.Data.VersionVector.VersionVector instance Data.Hashable.Class.Hashable RON.Data.VersionVector.VersionVector instance GHC.Base.Semigroup RON.Data.VersionVector.VersionVector instance GHC.Base.Monoid RON.Data.VersionVector.VersionVector instance RON.Data.Internal.Reducible RON.Data.VersionVector.VersionVector instance RON.Data.Internal.Replicated RON.Data.VersionVector.VersionVector instance RON.Data.Internal.ReplicatedAsObject RON.Data.VersionVector.VersionVector -- | Replicated Growable Array (RGA) module RON.Data.RGA -- | Typed RGA newtype RGA a RGA :: [a] -> RGA a -- | Untyped RGA data RgaRaw -- | Speciaization of RGA to Char. This is the recommended -- way to store a string. type RgaString = RGA Char -- | Replace content of the RGA throug introducing changes detected by -- getGroupedDiffBy. edit :: (Replicated a, ReplicatedAsPayload a, ReplicaClock m, MonadError String m, MonadState (Object (RGA a)) m) => [a] -> m () -- | Speciaization of edit for ErrorMessage editText :: (ReplicaClock m, MonadError String m, MonadState (Object RgaString) m) => Text -> m () -- | Read elements from RGA getList :: Replicated a => Object (RGA a) -> Either String [a] -- | Read characters from RgaString getText :: Object RgaString -> Either String Text -- | Create an RGA from a list newFromList :: (Replicated a, ReplicaClock m) => [a] -> m (Object (RGA a)) -- | Create an RgaString from a text newFromText :: ReplicaClock m => Text -> m (Object RgaString) -- | Name-UUID to use as RGA type marker. rgaType :: UUID instance GHC.Classes.Eq a => GHC.Classes.Eq (RON.Data.RGA.RGA a) instance GHC.Show.Show RON.Data.RGA.PatchSet instance GHC.Classes.Eq RON.Data.RGA.PatchSet instance GHC.Show.Show RON.Data.RGA.RgaRaw instance GHC.Base.Semigroup RON.Data.RGA.RgaRaw instance GHC.Base.Monoid RON.Data.RGA.RgaRaw instance GHC.Classes.Eq RON.Data.RGA.RgaRaw instance GHC.Show.Show RON.Data.RGA.VertexList instance GHC.Classes.Eq RON.Data.RGA.VertexList instance GHC.Show.Show RON.Data.RGA.VertexListItem instance GHC.Classes.Eq RON.Data.RGA.VertexListItem instance RON.Data.Internal.Replicated a => RON.Data.Internal.Replicated (RON.Data.RGA.RGA a) instance RON.Data.Internal.Replicated a => RON.Data.Internal.ReplicatedAsObject (RON.Data.RGA.RGA a) instance GHC.Base.Semigroup RON.Data.RGA.PatchSet instance GHC.Base.Monoid RON.Data.RGA.PatchSet instance RON.Data.Internal.Reducible RON.Data.RGA.RgaRaw instance GHC.Base.Semigroup RON.Data.RGA.VertexList -- | Observed-Remove Set (OR-Set) module RON.Data.ORSet -- | Type-directing wrapper for typed OR-Set of atomic values newtype ORSet a ORSet :: [a] -> ORSet a -- | Type-directing wrapper for typed OR-Set of objects newtype ObjectORSet a ObjectORSet :: [a] -> ObjectORSet a -- | Untyped OR-Set. Implementation: a map from the last change (creation -- or deletion) to the original op. data ORSetRaw -- | Encode an object and add a reference to it to the OR-Set addNewRef :: forall a m. (ReplicatedAsObject a, ReplicaClock m, MonadError String m) => a -> StateT (Object (ObjectORSet a)) m () -- | Add a reference to the object to the OR-Set addRef :: (ReplicatedAsObject a, ReplicaClock m, MonadError String m) => Object a -> StateT (Object (ObjectORSet a)) m () -- | Add atomic value to the OR-Set addValue :: (ReplicatedAsPayload a, ReplicaClock m, MonadError String m) => a -> StateT (Object (ORSet a)) m () -- | Remove an object reference from the OR-Set removeRef :: Object a -> StateT (Object (ORSet a)) m () -- | Remove an atomic value from the OR-Set removeValue :: ReplicatedAsPayload a => a -> StateT (Object (ORSet a)) m () instance GHC.Show.Show RON.Data.ORSet.ORSetRaw instance GHC.Classes.Eq RON.Data.ORSet.ORSetRaw instance GHC.Show.Show RON.Data.ORSet.SetItem instance GHC.Classes.Eq RON.Data.ORSet.SetItem instance RON.Data.Internal.ReplicatedAsObject a => RON.Data.Internal.Replicated (RON.Data.ORSet.ObjectORSet a) instance RON.Data.Internal.ReplicatedAsObject a => RON.Data.Internal.ReplicatedAsObject (RON.Data.ORSet.ObjectORSet a) instance RON.Data.Internal.ReplicatedAsPayload a => RON.Data.Internal.Replicated (RON.Data.ORSet.ORSet a) instance RON.Data.Internal.ReplicatedAsPayload a => RON.Data.Internal.ReplicatedAsObject (RON.Data.ORSet.ORSet a) instance GHC.Base.Semigroup RON.Data.ORSet.ORSetRaw instance GHC.Base.Monoid RON.Data.ORSet.ORSetRaw instance RON.Data.Internal.Reducible RON.Data.ORSet.ORSetRaw instance GHC.Base.Semigroup RON.Data.ORSet.SetItem -- | LWW-per-field RDT module RON.Data.LWW -- | Untyped LWW. Implementation: a map from opRef to the original -- op. newtype LwwPerField LwwPerField :: Map UUID Op -> LwwPerField -- | Assign a value to a field assignField :: forall a b m. (ReplicatedAsObject a, Replicated b, ReplicaClock m, MonadError String m, MonadState (Object a) m) => UUID -> b -> m () -- | Name-UUID to use as LWW type marker. lwwType :: UUID -- | Create LWW object from a list of named fields. newObject :: ReplicaClock m => [(UUID, I Replicated)] -> m (Object a) -- | Decode field value readField :: (MonadError String m, MonadState (Object a) m, ReplicatedAsObject a, Replicated b) => UUID -> m b -- | Decode field value viewField :: Replicated a => UUID -> StateChunk -> StateFrame -> Either String a -- | Anti-lens to an object inside a specified field zoomField :: (ReplicatedAsObject outer, MonadError String m) => UUID -> StateT (Object inner) m a -> StateT (Object outer) m a instance GHC.Show.Show RON.Data.LWW.LwwPerField instance GHC.Base.Monoid RON.Data.LWW.LwwPerField instance GHC.Classes.Eq RON.Data.LWW.LwwPerField instance GHC.Base.Semigroup RON.Data.LWW.LwwPerField instance RON.Data.Internal.Reducible RON.Data.LWW.LwwPerField -- | Typed and untyped RON tools module RON.Data -- | Untyped-reducible types. Untyped means if this type is a container -- then the types of data contained in it is not considered. class (Eq a, Monoid a) => Reducible a -- | UUID of the type reducibleOpType :: Reducible a => UUID -- | Load a state from a state chunk stateFromChunk :: Reducible a => [Op] -> a -- | Store a state to a state chunk stateToChunk :: Reducible a => a -> StateChunk -- | Merge a state with patches and raw ops applyPatches :: Reducible a => a -> Unapplied -> (a, Unapplied) -- | Merge patches and raw ops into bigger patches or throw obsolete ops reduceUnappliedPatches :: Reducible a => Unapplied -> Unapplied -- | Base class for typed encoding class Replicated a -- | Instances SHOULD implement encoding either as -- objectEncoding or as payloadEncoding encoding :: Replicated a => Encoding a -- | Instances of this class are encoded as objects. An enclosing object's -- payload will be filled with this object's id. class ReplicatedAsObject a -- | UUID of the type objectOpType :: ReplicatedAsObject a => UUID -- | Encode data newObject :: (ReplicatedAsObject a, ReplicaClock m) => a -> m (Object a) -- | Decode data getObject :: ReplicatedAsObject a => Object a -> Either String a -- | Instances of this class are encoded as payload only. class ReplicatedAsPayload a -- | Encode data toPayload :: ReplicatedAsPayload a => a -> [Atom] -- | Decode data fromPayload :: ReplicatedAsPayload a => [Atom] -> Either String a -- | Decode typed data from a payload. The implementation may use other -- objects in the frame to resolve references. fromRon :: Replicated a => [Atom] -> StateFrame -> Either String a mkStateChunk :: [Op] -> StateChunk -- | Encode typed data to a payload with possible addition objects newRon :: (Replicated a, ReplicaClock m) => a -> WriterT StateFrame m [Atom] -- | Standard implementation of Replicated for -- ReplicatedAsObject types. objectEncoding :: ReplicatedAsObject a => Encoding a -- | Standard implementation of Replicated for -- ReplicatedAsPayload types. payloadEncoding :: ReplicatedAsPayload a => Encoding a -- | Reduce object with frame from another version of the same object. reduceObject :: Object a -> Object a -> Either String (Object a) reduceStateFrame :: StateFrame -> StateFrame -> Either String StateFrame reduceWireFrame :: WireFrame -> WireFrame -- | Day instances module RON.Data.Time -- | The Modified Julian Day is a standard count of days, with zero being -- the day 1858-11-17. data Day -- | RON-Schema type for Day day :: RonType instance RON.Data.Internal.Replicated Data.Time.Calendar.Days.Day instance RON.Data.Internal.ReplicatedAsPayload Data.Time.Calendar.Days.Day module RON.Schema.TH mkReplicated :: HasCallStack => QuasiQuoter -- | Generate Haskell types from RON-Schema mkReplicated' :: HasCallStack => Schema -> DecsQ module RON.Text.Serialize.UUID -- | Serialize UUID without context (used for test) serializeUuid :: UUID -> ByteStringL -- | Serialize UUID in op value (atom) context serializeUuidAtom :: UUID -> UUID -> ByteStringL -- | Serialize UUID in op key context serializeUuidKey :: UUID -> UUID -> UUID -> ByteStringL -- | RON-Text serialization module RON.Text.Serialize -- | Serialize a context-free atom serializeAtom :: Atom -> ByteStringL -- | Serialize an object. Return object id that must be stored separately. serializeObject :: Object a -> (UUID, ByteStringL) -- | Serialize a context-free raw op serializeRawOp :: RawOp -> ByteStringL -- | Serialize a state frame serializeStateFrame :: StateFrame -> ByteStringL -- | Serialize a string atom serializeString :: Text -> ByteStringL -- | Serialize UUID without context (used for test) serializeUuid :: UUID -> ByteStringL -- | Serialize a common frame serializeWireFrame :: WireFrame -> ByteStringL -- | Serialize a sequence of common frames serializeWireFrames :: [WireFrame] -> ByteStringL -- | RON-Text parsing module RON.Text.Parse -- | Parse an atom parseAtom :: ByteStringL -> Either String Atom -- | Parse a state frame as an object parseObject :: UUID -> ByteStringL -> Either String (Object a) -- | Parse a single context-free op parseOp :: ByteStringL -> Either String RawOp -- | Parse a state frame parseStateFrame :: ByteStringL -> Either String StateFrame -- | Parse a string atom parseString :: ByteStringL -> Either String Text -- | Parse a single context-free UUID parseUuid :: ByteStringL -> Either String UUID -- | Parse a UUID in key position parseUuidKey :: UUID -> UUID -> ByteStringL -> Either String UUID -- | Parse a UUID in value (atom) position parseUuidAtom :: UUID -> ByteStringL -> Either String UUID -- | Parse a common frame parseWireFrame :: ByteStringL -> Either String WireFrame -- | Parse a sequence of common frames parseWireFrames :: ByteStringL -> Either String [WireFrame] -- | RON-Text wire format module RON.Text -- | Parse a state frame as an object parseObject :: UUID -> ByteStringL -> Either String (Object a) -- | Parse a state frame parseStateFrame :: ByteStringL -> Either String StateFrame -- | Parse a common frame parseWireFrame :: ByteStringL -> Either String WireFrame -- | Parse a sequence of common frames parseWireFrames :: ByteStringL -> Either String [WireFrame] -- | Serialize an object. Return object id that must be stored separately. serializeObject :: Object a -> (UUID, ByteStringL) -- | Serialize a state frame serializeStateFrame :: StateFrame -> ByteStringL -- | Serialize a common frame serializeWireFrame :: WireFrame -> ByteStringL -- | Serialize a sequence of common frames serializeWireFrames :: [WireFrame] -> ByteStringL -- | RON File Storage. For usage, see RON.Storage.IO. 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 => UUID -> ByteString -> Either String (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 -- | Storage backend interface class (ReplicaClock m, MonadError String 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 -> ByteString -> m () loadVersionContent :: (MonadStorage m, Collection a) => DocId a -> DocVersion -> m ByteString deleteVersion :: (MonadStorage m, Collection a) => DocId a -> DocVersion -> m () changeDocId :: (MonadStorage m, Collection a) => DocId a -> DocId a -> m () -- | 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) -- | Load document version as an object readVersion :: MonadStorage m => Collection a => DocId a -> DocVersion -> m (Object a, IsTouched) instance GHC.Show.Show (RON.Storage.Document a) instance GHC.Show.Show RON.Storage.IsTouched instance GHC.Classes.Ord (RON.Storage.DocId a) instance GHC.Classes.Eq (RON.Storage.DocId a) instance RON.Storage.Collection a => GHC.Show.Show (RON.Storage.DocId a) module RON.Storage.Test type TestDB = Map CollectionName (Map DocumentId (Map DocVersion Document)) runStorageSim :: TestDB -> StorageSim a -> Either String (a, TestDB) instance RON.Event.ReplicaClock RON.Storage.Test.StorageSim instance Control.Monad.Error.Class.MonadError GHC.Base.String 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.MonadStorage RON.Storage.Test.StorageSim -- | A real-world file storage. -- -- Typical usage: -- --
-- import RON.Storage.IO 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.IO
-- | Storage handle (uses the “Handle pattern”).
data Handle
-- | The handler is called as onDocumentChanged docid, where
-- docid is the changed document id.
newtype OnDocumentChanged
OnDocumentChanged :: (forall a. Collection a => DocId a -> IO ()) -> OnDocumentChanged
-- | Create new storage handle
newHandle :: FilePath -> IO Handle
setOnDocumentChanged :: Handle -> OnDocumentChanged -> IO ()
-- | Environment is the dataDir
data Storage a
-- | Run a Storage action
runStorage :: Handle -> Storage a -> IO a
instance Control.Monad.IO.Class.MonadIO RON.Storage.IO.Storage
instance Control.Monad.Error.Class.MonadError GHC.Base.String RON.Storage.IO.Storage
instance GHC.Base.Monad RON.Storage.IO.Storage
instance GHC.Base.Functor RON.Storage.IO.Storage
instance GHC.Base.Applicative RON.Storage.IO.Storage
instance RON.Event.ReplicaClock RON.Storage.IO.Storage
instance RON.Storage.MonadStorage RON.Storage.IO.Storage