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.
Implements
Section titled “Implements”CRDTProvider<LoroDoc,Uint8Array,LoroChange>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new LoroProvider():
LoroProvider
Returns
Section titled “Returns”LoroProvider
Properties
Section titled “Properties”actorBinding
Section titled “actorBinding”
readonlyactorBinding: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.
Implementation of
Section titled “Implementation of”CRDTProvider.actorBinding
Methods
Section titled “Methods”applySnapshot()
Section titled “applySnapshot()”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.
Parameters
Section titled “Parameters”document
Section titled “document”LoroDoc
snapshot
Section titled “snapshot”Uint8Array
Returns
Section titled “Returns”LoroDoc
Implementation of
Section titled “Implementation of”CRDTProvider.applySnapshot
coversVersion()
Section titled “coversVersion()”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.
Parameters
Section titled “Parameters”document
Section titled “document”LoroDoc
CRDT document to inspect.
version
Section titled “version”Uint8Array
Bytes from another replica’s encodeVersion().
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”CRDTProvider.coversVersion
encodeVersion()
Section titled “encodeVersion()”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.
Parameters
Section titled “Parameters”document
Section titled “document”LoroDoc
CRDT document to describe.
Returns
Section titled “Returns”Uint8Array
Implementation of
Section titled “Implementation of”CRDTProvider.encodeVersion
getChangesSinceSnapshot()
Section titled “getChangesSinceSnapshot()”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.
Parameters
Section titled “Parameters”document
Section titled “document”LoroDoc
CRDT document to encode.
snapshot
Section titled “snapshot”Uint8Array
State that getSnapshot() returned for an earlier state.
Returns
Section titled “Returns”Uint8Array<ArrayBufferLike> | undefined
Implementation of
Section titled “Implementation of”CRDTProvider.getChangesSinceSnapshot
getHistory()
Section titled “getHistory()”getHistory(
document):Uint8Array
Defined in: index.ts:632
Gets all changes for the document.
Parameters
Section titled “Parameters”document
Section titled “document”LoroDoc
CRDT document to inspect.
Returns
Section titled “Returns”Uint8Array
Implementation of
Section titled “Implementation of”CRDTProvider.getHistory
getSnapshot()
Section titled “getSnapshot()”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())
Parameters
Section titled “Parameters”document
Section titled “document”LoroDoc
CRDT document to snapshot.
Returns
Section titled “Returns”Uint8Array
A snapshot representation. If the snapshot format differs from the
incremental change format, implement applySnapshot() as well.
Implementation of
Section titled “Implementation of”CRDTProvider.getSnapshot
hasDiscarded()
Section titled “hasDiscarded()”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.
Parameters
Section titled “Parameters”document
Section titled “document”LoroDoc
changes
Section titled “changes”Uint8Array
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”CRDTProvider.hasDiscarded
hasIntegrated()
Section titled “hasIntegrated()”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.
Parameters
Section titled “Parameters”document
Section titled “document”LoroDoc
changes
Section titled “changes”Uint8Array
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”CRDTProvider.hasIntegrated
localChange()
Section titled “localChange()”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.
Parameters
Section titled “Parameters”document
Section titled “document”LoroDoc
CRDT document to change.
message
Section titled “message”string
A description of the change made.
change
Section titled “change”Returns
Section titled “Returns”[LoroDoc<Record<string, Container>>, Uint8Array<ArrayBufferLike>]
Implementation of
Section titled “Implementation of”CRDTProvider.localChange
newDocument()
Section titled “newDocument()”newDocument():
LoroDoc
Defined in: index.ts:520
Create a new empty (contains the equivalent of {}) CRDT document.
Returns
Section titled “Returns”LoroDoc
Implementation of
Section titled “Implementation of”CRDTProvider.newDocument
remoteChange()
Section titled “remoteChange()”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.
Parameters
Section titled “Parameters”document
Section titled “document”LoroDoc
changes
Section titled “changes”Uint8Array
Returns
Section titled “Returns”LoroDoc
Implementation of
Section titled “Implementation of”CRDTProvider.remoteChange