CRDTStorageBackend class abstract interface

Everything one backend holds: the documents, and what each of them is made of.

CRDTDocumentStorage holds one document and knows nothing about the others, which is right for what writes it but not for an app. An app opens a database once and asks it for many documents — list them, open one, delete another. That is this.

Every adapter has one. Code written against this runs on any of them, so a note app can change backend by changing the line that opens it:

final backend = CRDTSqlite.open('notes.db');

for (final documentId in await backend.documentIds) {
  final note = await backend.readDocument(documentId);
  // ...show it in a list
}

final open = await backend.openDocument('note-1');

CRDTStorageBackendDocuments is where openDocument, readDocument, documentAt and copyDocumentTo live.

Every method returns a FutureOr. A backend that answers without touching the disk — sqlite, or a Hive box already in memory — returns the value itself and narrows the return type to say so; an asynchronous backend returns a Future. Callers that must work on any adapter use CRDTFutureOr.chain, which suspends only when there is a future to wait for.

Implementers
Available extensions

Properties

documentIds → FutureOr<Set<String>>
Every document this backend holds, in no particular order.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → FutureOr<void>
Closes the backend and everything it opened.
copyDocumentTo(CRDTStorageBackend other, String documentId) → Future<void>

Available on CRDTStorageBackend, provided by the CRDTStorageBackendDocuments extension

Copies documentId into other, identity included.
deleteDocument(String documentId) → FutureOr<void>
Deletes the changes, the snapshots and the stored identity of documentId.
documentAt(String documentId, VersionVector version, {PeerId? peerId, void onDocument(CRDTDocument document)?}) → FutureOr<CRDTDocument>

Available on CRDTStorageBackend, provided by the CRDTStorageBackendDocuments extension

The document documentId held at version.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openDocument(String documentId, {PeerId? author, void onDocument(CRDTDocument document)?, Duration writeDelay = const Duration(milliseconds: 250), int? compactAfter, int? keepSnapshots = 1, void onError(Object error, StackTrace stack)?}) → Future<PersistentDocument>

Available on CRDTStorageBackend, provided by the CRDTStorageBackendDocuments extension

Builds documentId on top of what this backend already holds.
peerIdStorageForDocument(String documentId) → FutureOr<CRDTPeerIdStorage>
The PeerId this device writes documentId under.
readDocument(String documentId, {PeerId? peerId, void onDocument(CRDTDocument document)?}) → FutureOr<CRDTDocument>

Available on CRDTStorageBackend, provided by the CRDTStorageBackendDocuments extension

The document documentId holds, built and handed over, not followed.
storageForDocument(String documentId) → FutureOr<CRDTDocumentStorage>
The changes and snapshots of documentId.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited