Skip to content

AutomergeProvider

Defined in: automerge/src/peerborne-automerge.ts:332

T = any

  • CRDTProvider<Doc<T>, BinaryChange[], (doc) => void>

new AutomergeProvider<T>(): AutomergeProvider<T>

AutomergeProvider<T>

readonly actorBinding: 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.

CRDTProvider.actorBinding


readonly compactSnapshots: 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().

CRDTProvider.compactSnapshots


readonly initialInvitationCapacityProfile: "peerborne-automerge-json-subtle-p384-v1" = INITIAL_INVITATION_CAPACITY_PROFILE

Defined in: automerge/src/peerborne-automerge.ts:335

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().

Doc<T>

Current CRDT document.

Change[]

Snapshot state from getSnapshot().

Doc<T>

The updated document with the snapshot state merged in.

CRDTProvider.applySnapshot


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.

Doc<T>

A document this provider returned before the failed change.

Doc<T> | undefined

CRDTProvider.cloneDocument


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.

Doc<T>

CRDT document to inspect.

Uint8Array

Bytes from another replica’s encodeVersion().

boolean

CRDTProvider.coversVersion


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.

Doc<T>

CRDTDocumentSession<Doc<T>, Change[], (doc) => void>

CRDTProvider.createDocumentSession


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.

Doc<T>

CRDT document to describe.

Uint8Array

CRDTProvider.encodeVersion


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.

Doc<T>

CRDT document to encode.

Change[]

State that getSnapshot() returned for an earlier state.

Change[] | undefined

CRDTProvider.getChangesSinceSnapshot


getHistory(document): Change[]

Defined in: automerge/src/peerborne-automerge.ts:579

Gets all changes for the document.

Doc<T>

CRDT document to inspect.

Change[]

CRDTProvider.getHistory


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())

Doc<T>

CRDT document to snapshot.

Change[]

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

CRDTProvider.getSnapshot


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.

Doc<T>

CRDT document returned by remoteChange().

Change[]

Changes previously passed to remoteChange().

boolean

CRDTProvider.hasIntegrated


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.

Doc<T>

CRDT document to inspect.

boolean

CRDTProvider.hasPendingChanges


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.

Doc<T>

CRDT document to change.

string

A description of the change made.

(doc) => void

A function that modifies a CRDT document (provided as a parameter). This function will be run as a part of .localChange(...)

[Doc<T>, Change[]]

CRDTProvider.localChange


newDocument(): Doc<T>

Defined in: automerge/src/peerborne-automerge.ts:499

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

Doc<T>

CRDTProvider.newDocument


remoteChange(document, changes): Doc<T>

Defined in: automerge/src/peerborne-automerge.ts:521

Apply CRDT document changes made by a remote peer.

Doc<T>

CRDT document to update.

Change[]

An object describing changes made by a peer. CRDT-specific.

Doc<T>

CRDTProvider.remoteChange


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.

Doc<T>

CRDT document to update.

readonly (readonly Change[][])[]

The change sets of each frame, in delivery order.

readonly [Doc<T>, number] | undefined

CRDTProvider.remoteChangeBatch