Skip to content

LoroProvider

Defined in: index.ts:513

Experimental document provider. Snapshots retain history so offline replicas can merge without introducing a shallow-history compatibility boundary. ACL, keychain and wire serializers are supplied independently by the caller.

Remote updates and snapshots are untrusted even when authenticated, because Loro’s checksum is not a MAC. An update waits outside the document until its dependencies arrive, and is then validated on a fork with the updates it releases before any of them reach the document. Validation reads the whole document, so it costs O(document) per integrated remote update.

new LoroProvider(): LoroProvider

LoroProvider

readonly actorBinding: CRDTActorBinding<LoroDoc<Record<string, Container>>, Uint8Array<ArrayBufferLike>> = loroActorBinding

Defined in: index.ts:518

Binds this provider’s actor identifiers to change signers. When present, ordinary documents sign every change, write under derived actors and reject a change that adds operations under an actor its signer does not own. Coordinator-backed documents do not use it.

CRDTProvider.actorBinding

applySnapshot(document, snapshot): LoroDoc

Defined in: index.ts:674

Applies only the operation history of a full snapshot, as a validated update. The snapshot’s encoded state is never loaded into document.

LoroDoc

Uint8Array

LoroDoc

CRDTProvider.applySnapshot


coversVersion(document, version): boolean

Defined in: index.ts:644

Report whether document holds all of the state that version, from encodeVersion() on another replica, describes. Every insertion and deletion counts, so a replica that lacks a deletion is not covered. Return false, without throwing, for a malformed version.

LoroDoc

CRDT document to inspect.

Uint8Array

Bytes from another replica’s encodeVersion().

boolean

CRDTProvider.coversVersion


encodeVersion(document): Uint8Array

Defined in: index.ts:640

Encode a compact version of document’s state, such as Automerge heads, a Loro version vector or a Yjs state vector with its delete set. A writer whose catch-up reply does not fit a frame sends it, and the requester loads only when coversVersion() reports that it lacks some of that state. When not implemented, the requester always loads.

LoroDoc

CRDT document to describe.

Uint8Array

CRDTProvider.encodeVersion


getChangesSinceSnapshot(document, snapshot): Uint8Array<ArrayBufferLike> | undefined

Defined in: index.ts:655

Encode the changes document holds beyond snapshot, a state from getSnapshot() without an actor manifest, so that remoteChange() applies them to a new document that snapshot was applied to. Return undefined when document does not hold every change in snapshot, or when applying the changes would take longer than restoring the full state. A local checkpoint stores a document that its latest snapshot covers in part as that snapshot and these changes, so it holds the state once.

LoroDoc

CRDT document to encode.

Uint8Array

State that getSnapshot() returned for an earlier state.

Uint8Array<ArrayBufferLike> | undefined

CRDTProvider.getChangesSinceSnapshot


getHistory(document): Uint8Array

Defined in: index.ts:632

Gets all changes for the document.

LoroDoc

CRDT document to inspect.

Uint8Array

CRDTProvider.getHistory


getSnapshot(document): Uint8Array

Defined in: index.ts:636

Get a compacted state snapshot of the document. Used for onboarding new members without replaying individual changes.

For Yjs: Y.encodeStateAsUpdateV2(doc) (directly applicable via remoteChange()) For Automerge: Automerge.save(doc) (requires applySnapshot() since save format differs from the incremental change format used by remoteChange())

LoroDoc

CRDT document to snapshot.

Uint8Array

A snapshot representation. If the snapshot format differs from the incremental change format, implement applySnapshot() as well.

CRDTProvider.getSnapshot


hasDiscarded(document, changes): boolean

Defined in: index.ts:625

An update is discarded once it is neither integrated nor waiting: it failed validation after its dependencies arrived, depends on one that did, the waiting queue evicted it, or remoteChange rejected it.

LoroDoc

Uint8Array

boolean

CRDTProvider.hasDiscarded


hasIntegrated(document, changes): boolean

Defined in: index.ts:616

An update is integrated once the oplog covers the end of every peer range it carries. One still waiting for a dependency is not.

LoroDoc

Uint8Array

boolean

CRDTProvider.hasIntegrated


localChange(document, message, change): [LoroDoc<Record<string, Container>>, Uint8Array<ArrayBufferLike>]

Defined in: index.ts:524

Apply locally made changes to provided CRDT document as defined by changeFn.

If changeFn throws, leave document without its edits and rethrow the error. A provider that edits in place and cannot roll back throws PartialLocalChangeError instead when the callback edited anything.

LoroDoc

CRDT document to change.

string

A description of the change made.

LoroChange

[LoroDoc<Record<string, Container>>, Uint8Array<ArrayBufferLike>]

CRDTProvider.localChange


newDocument(): LoroDoc

Defined in: index.ts:520

Create a new empty (contains the equivalent of {}) CRDT document.

LoroDoc

CRDTProvider.newDocument


remoteChange(document, changes): LoroDoc

Defined in: index.ts:553

Rejects a blob that is not a valid update and leaves document unchanged. An update whose dependencies are missing waits and is validated once they arrive, together with the update that released it. When that batch fails but the releasing update passes on its own, the waiting updates are validated one at a time, each after its dependencies. The ones that fail, and those that depend on them, are discarded.

LoroDoc

Uint8Array

LoroDoc

CRDTProvider.remoteChange