R
C

Rga

tested

Replicated Growable Array — a sequence CRDT. Each element is inserted after a left-origin element (or at the start) and tombstoned on delete. Concurrent inserts at the same origin are ordered higher-op-id-first, a deterministic tie-break that makes every replica converge to the same order. Operations must be integrated in causal order (an insert's origin must already be present); {@link integrateInsert} returns `false` when the origin is missing so the caller can buffer and retry.

Signature

ts
class Rga<T>

Type Parameters

T

Properties

PropertyTypeDescription
lengthreadonlynumberNumber of visible elements.

Methods

has
ts
has(id: OpId): boolean
ParameterTypeDescription
idOpId
Returnsboolean
integrateInsert

Integrate an insert after `originLeft` (`null` = start). Idempotent.

ts
integrateInsert(id: OpId, value: T, originLeft: OpId | null): boolean
ParameterTypeDescription
idOpId
valueT
originLeftOpId | null
Returnsboolean
integrateDelete

Tombstone an element. Idempotent; returns false if the element is unknown.

ts
integrateDelete(id: OpId): boolean
ParameterTypeDescription
idOpId
Returnsboolean
gc

Drop tombstoned nodes whose insert is covered by `stable`. Call ONLY at quiescence — when every replica has fully synced and no operations are in flight — otherwise a late op that uses a dropped node as its origin can no longer integrate. `keep` protects ids still referenced elsewhere (e.g. mark span endpoints). Returns the number of nodes removed.

ts
gc(stable: VersionVector, keep?: (id: OpId) => boolean): number
ParameterTypeDescription
stableVersionVector
keep?((id: OpId) => boolean) | undefined
Returnsnumber
toArray

Visible values in document order.

ts
toArray(): T[]
ReturnsT[]
visible

Visible nodes in document order (read ids for cursor anchoring).

ts
visible(): Array<RgaNode<T>>
ReturnsRgaNode<T>[]
all

All nodes including tombstones (for state encoding).

ts
all(): ReadonlyArray<RgaNode<T>>
Returnsreadonly RgaNode<T>[]
idAt

Op id of the visible element at `index`, or `null` if out of range.

ts
idAt(index: number): OpId | null
ParameterTypeDescription
indexnumber
ReturnsOpId | null