R
C

Replica

tested

Generic op-based CRDT replica: owns a Lamport clock + op log, integrates local and remote ops (with causal buffering and dedup), and exposes deltas for transport-agnostic sync. The domain state lives behind {@link ReplicaHandlers}.

Signature

ts
class Replica<Op extends HasOpId>

Type Parameters

Opextends HasOpId

Properties

PropertyTypeDescription
sitereadonlystring
versionreadonlyVersionVector

Methods

nextId

Next op id for a locally-generated operation.

ts
nextId(): OpId
ReturnsOpId
commitLocal

Integrate + log a local op, then notify listeners (origin `'local'`).

ts
commitLocal(op: Op): void
ParameterTypeDescription
opOp
receive

Receive remote ops: dedup, buffer until causally ready, integrate, log, and notify with the ops actually applied. Returns the applied ops (in apply order).

ts
receive(ops: readonly Op[], origin: unknown = 'remote'): Op[]
ParameterTypeDescription
opsreadonly Op[]
origin?unknown
ReturnsOp[]
delta

Ops a remote replica (described by its version vector) is missing.

ts
delta(remote: VersionVector): Op[]
ParameterTypeDescription
remoteVersionVector
ReturnsOp[]
onUpdate

Subscribe to applied ops (local + remote). Returns an unsubscribe fn.

ts
onUpdate(listener: UpdateListener<Op>): () => void
ParameterTypeDescription
listenerUpdateListener<Op>
Returns() => void