AutomergeProvider
Defined in: automerge/src/peerborne-automerge.ts:332
Type Parameters
Section titled “Type Parameters”T = any
Implements
Section titled “Implements”CRDTProvider<Doc<T>,BinaryChange[], (doc) =>void>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AutomergeProvider<
T>():AutomergeProvider<T>
Returns
Section titled “Returns”AutomergeProvider<T>
Properties
Section titled “Properties”actorBinding
Section titled “actorBinding”
readonlyactorBinding:CRDTActorBinding<Doc<T>,Change[]>
Defined in: automerge/src/peerborne-automerge.ts:338
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
compactSnapshots
Section titled “compactSnapshots”
readonlycompactSnapshots:true=true
Defined in: automerge/src/peerborne-automerge.ts:341
Whether getSnapshot() encodes a document more compactly than
getHistory(), as Automerge’s save() does. A local checkpoint then
stores the document’s full state with getSnapshot() and restores it
with applySnapshot().
Implementation of
Section titled “Implementation of”CRDTProvider.compactSnapshots
initialInvitationCapacityProfile
Section titled “initialInvitationCapacityProfile”
readonlyinitialInvitationCapacityProfile:"peerborne-automerge-json-subtle-p384-v1"=INITIAL_INVITATION_CAPACITY_PROFILE
Defined in: automerge/src/peerborne-automerge.ts:335
Methods
Section titled “Methods”applySnapshot()
Section titled “applySnapshot()”applySnapshot(
document,snapshot):Doc<T>
Defined in: automerge/src/peerborne-automerge.ts:605
Apply a full-state snapshot produced by getSnapshot().
Implement this when the snapshot format differs from incremental changes
(e.g. Automerge’s save() output cannot be applied via applyChanges()).
When not implemented, the caller falls back to remoteChange().
Parameters
Section titled “Parameters”document
Section titled “document”Doc<T>
Current CRDT document.
snapshot
Section titled “snapshot”Change[]
Snapshot state from getSnapshot().
Returns
Section titled “Returns”Doc<T>
The updated document with the snapshot state merged in.
Implementation of
Section titled “Implementation of”CRDTProvider.applySnapshot
cloneDocument()
Section titled “cloneDocument()”cloneDocument(
document):Doc<T> |undefined
Defined in: automerge/src/peerborne-automerge.ts:502
Return a writable copy of document as it was when it was produced, even
after a later localChange() or remoteChange() consumed it, or
undefined when no faithful copy exists.
Implement this when those methods leave their input unusable, as
Automerge marks it outdated. A local change that fails before it is stored
and recorded in the change tree rolls back to this copy. The copy must
make its next local change under a new replica identity, so the discarded
change’s position is never reused.
Return undefined when the copy would lose state, such as remote changes
still waiting for their dependencies: the document instance is then
retired instead. When not implemented, a failed change rolls back to
document itself if localChange() returned a new document. A provider
whose localChange() returns the document it was given edits in place
and cannot roll back, so the instance is retired.
Parameters
Section titled “Parameters”document
Section titled “document”Doc<T>
A document this provider returned before the failed change.
Returns
Section titled “Returns”Doc<T> | undefined
Implementation of
Section titled “Implementation of”CRDTProvider.cloneDocument
coversVersion()
Section titled “coversVersion()”coversVersion(
document,version):boolean
Defined in: automerge/src/peerborne-automerge.ts:645
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”Doc<T>
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
createDocumentSession()
Section titled “createDocumentSession()”createDocumentSession(
initial):CRDTDocumentSession<Doc<T>,Change[], (doc) =>void>
Defined in: automerge/src/peerborne-automerge.ts:343
Required by coordinator-backed documents; never falls back to live preparation.
Parameters
Section titled “Parameters”initial
Section titled “initial”Doc<T>
Returns
Section titled “Returns”CRDTDocumentSession<Doc<T>, Change[], (doc) => void>
Implementation of
Section titled “Implementation of”CRDTProvider.createDocumentSession
encodeVersion()
Section titled “encodeVersion()”encodeVersion(
document):Uint8Array
Defined in: automerge/src/peerborne-automerge.ts:634
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”Doc<T>
CRDT document to describe.
Returns
Section titled “Returns”Uint8Array
Implementation of
Section titled “Implementation of”CRDTProvider.encodeVersion
getChangesSinceSnapshot()
Section titled “getChangesSinceSnapshot()”getChangesSinceSnapshot(
document,snapshot):Change[] |undefined
Defined in: automerge/src/peerborne-automerge.ts:589
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”Doc<T>
CRDT document to encode.
snapshot
Section titled “snapshot”Change[]
State that getSnapshot() returned for an earlier state.
Returns
Section titled “Returns”Change[] | undefined
Implementation of
Section titled “Implementation of”CRDTProvider.getChangesSinceSnapshot
getHistory()
Section titled “getHistory()”getHistory(
document):Change[]
Defined in: automerge/src/peerborne-automerge.ts:579
Gets all changes for the document.
Parameters
Section titled “Parameters”document
Section titled “document”Doc<T>
CRDT document to inspect.
Returns
Section titled “Returns”Change[]
Implementation of
Section titled “Implementation of”CRDTProvider.getHistory
getSnapshot()
Section titled “getSnapshot()”getSnapshot(
document):Change[]
Defined in: automerge/src/peerborne-automerge.ts:582
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”Doc<T>
CRDT document to snapshot.
Returns
Section titled “Returns”Change[]
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
hasIntegrated()
Section titled “hasIntegrated()”hasIntegrated(
document,changes):boolean
Defined in: automerge/src/peerborne-automerge.ts:573
Report whether document has integrated every change in changes.
Implement this when remoteChange() can buffer changes until their
causal dependencies arrive and buffered changes are missing from
getHistory(). Peerborne records a remote change as applied only after
this returns true, so a buffered change stays eligible for redelivery.
It runs for every delivered change and, after a change integrates, for
each change still waiting, of which Peerborne keeps at most 4,096 per
document. Those checks pass the same
changes object, so cache per-change decoding by it. When not
implemented, every applied change counts as integrated.
Parameters
Section titled “Parameters”document
Section titled “document”Doc<T>
CRDT document returned by remoteChange().
changes
Section titled “changes”Change[]
Changes previously passed to remoteChange().
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”CRDTProvider.hasIntegrated
hasPendingChanges()
Section titled “hasPendingChanges()”hasPendingChanges(
document):boolean
Defined in: automerge/src/peerborne-automerge.ts:631
Report whether document holds remote changes that wait for missing
causal dependencies, such as Automerge’s queued changes or Yjs pending
structs and deletions. Automatic catch-up asks peers for missed updates
while this is true. When not implemented, only failed block fetches and
advertised heads reveal a gap.
Parameters
Section titled “Parameters”document
Section titled “document”Doc<T>
CRDT document to inspect.
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”CRDTProvider.hasPendingChanges
localChange()
Section titled “localChange()”localChange(
document,message,changeFn): [Doc<T>,Change[]]
Defined in: automerge/src/peerborne-automerge.ts:510
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”Doc<T>
CRDT document to change.
message
Section titled “message”string
A description of the change made.
changeFn
Section titled “changeFn”(doc) => void
A function that modifies a CRDT document (provided as a parameter).
This function will be run as a part of .localChange(...)
Returns
Section titled “Returns”[Doc<T>, Change[]]
Implementation of
Section titled “Implementation of”CRDTProvider.localChange
newDocument()
Section titled “newDocument()”newDocument():
Doc<T>
Defined in: automerge/src/peerborne-automerge.ts:499
Create a new empty (contains the equivalent of {}) CRDT document.
Returns
Section titled “Returns”Doc<T>
Implementation of
Section titled “Implementation of”CRDTProvider.newDocument
remoteChange()
Section titled “remoteChange()”remoteChange(
document,changes):Doc<T>
Defined in: automerge/src/peerborne-automerge.ts:521
Apply CRDT document changes made by a remote peer.
Parameters
Section titled “Parameters”document
Section titled “document”Doc<T>
CRDT document to update.
changes
Section titled “changes”Change[]
An object describing changes made by a peer. CRDT-specific.
Returns
Section titled “Returns”Doc<T>
Implementation of
Section titled “Implementation of”CRDTProvider.remoteChange
remoteChangeBatch()
Section titled “remoteChangeBatch()”remoteChangeBatch(
document,batch): readonly [Doc<T>,number] |undefined
Defined in: automerge/src/peerborne-automerge.ts:525
Apply the remote changes of consecutive frames in one step. batch holds
each frame’s change sets in delivery order. Apply the longest leading run
of frames whose changes all integrate once the frames before them have,
without letting any change buffered in document integrate, and return
a new document with the number of frames applied. A frame without
changes always applies, so [[]] copies document. The result must
equal the document remoteChange() would produce from those sets one
after another and keep the replica identity of document, which stays
usable and unchanged. Return undefined when no frame applies or
applying them fails.
Implement this when remoteChange() costs more than the changes it
applies, as Automerge’s walks every object it edits, so a burst of frames
costs about one walk. Peerborne verifies each frame before batching it
and applies frames one by one when this is not implemented.
Parameters
Section titled “Parameters”document
Section titled “document”Doc<T>
CRDT document to update.
readonly (readonly Change[][])[]
The change sets of each frame, in delivery order.
Returns
Section titled “Returns”readonly [Doc<T>, number] | undefined
Implementation of
Section titled “Implementation of”CRDTProvider.remoteChangeBatch