maca / crdt-replicated-graph / RG

RG is a Replicated Graph, it keeps the local replica state. The timestamp for adding nodes is calculated by adding maxReplicas count to the last timestamp, and the initial timestamp corresponds to the ReplicaId. This sets two constraints: the ReplicaId has to be unique for each replica, and the maximum number of replicas has to be declared.


type alias RG a =
{ replicaId : Operation.ReplicaId
, maxReplicas : Basics.Int
, root : Node a
, timestamp : Basics.Int
, pointer : Node.Path
, operations : List (Operation a)
, replicas : Dict Basics.Int Basics.Int
, lastOperation : Operation a 
}

Represent a Replicated Graph

replicaId is the local replica id

maxReplicas maximum number of replicas

root root node

timestamp timestamp of the last operation

pointer path of the last added node

operations cache of all applied operations

replicas known replicas and their last known timestamp

lastOperation last succesfully applied operation or batch


type alias Error =
{ replicaId : Operation.ReplicaId
, timestamp : Basics.Int
, path : Node.Path 
}

Extra information about a failure when applying an operation

replicaId is the id of the replica where the operation was generated

timestamp is the timestamp of the attempted operation

path is the path of the existing node, either a node intended to be deleted or the previous node for an add operation

If an operation fails it is usefull knowing the replica where the operation was generated, to request the operations since the last know operation.

init : { replicaId : Basics.Int, maxReplicas : Basics.Int } -> RG a

Build a RG

add : Maybe a -> RG a -> Result Error (RG a)

Build and add a node after pointer position

addBranch : Maybe a -> RG a -> Result Error (RG a)

Build and add a branch after pointer position

delete : Node.Path -> RG a -> Result Error (RG a)

Mark a RG node as a Tombstone

batch : List (RG a -> Result Error (RG a)) -> RG a -> Result Error (RG a)

Apply a list of functions that edit a RG to a RG

apply : Operation a -> RG a -> Result Error (RG a)

Apply a remote operation