crdt_lf_persistence 0.2.0
crdt_lf_persistence: ^0.2.0 copied to clipboard
The storage contract behind the crdt_lf persistence adapters, and the consumer that keeps a document on disk as it changes.
0.2.0 #
Date: 2026-10-04
Added #
keepSnapshotsonopen,openSyncandopenDocument: how many snapshots stay on the disk (1 by default,nullfor all).whenStored(version)completes once the disk can bring back that version, changes or snapshot;storedVersionis what the disk holds now.flush(throwOnError: true)throws a failed write instead of returning.
Changed #
compact()throws when the snapshot or the prune fails to write.- Needs Dart 3.3 and
crdt_lf5.1.0 or later.
Fixed #
openthrows when the document and the storage hold concurrent snapshots, instead of dropping one side; a failedopenstops following the document.- A snapshot the document took before
openis written; the next open lost it. - A failed snapshot write no longer lets its prune delete the changes it covers, and is retried.
- Two concurrent
flush()calls no longer hide a failed write from each other. flush()waits only for what was queued when it was called: with edits arriving faster than the writes it never returned, and neither diddispose()orcompact().documentAtthrows instead of answering a version whose history was pruned with an older state.
0.1.1 #
Date: 2026-09-19
Widens the crdt_lf constraint to >=4.2.0 <6.0.0, so this package resolves against
crdt_lf 5.0.0 as well as 4.x. No functional changes.
0.1.0 #
Date: 2026-09-07
First release. The storage contract behind the crdt_lf persistence adapters — the
README has the
API and the examples.
Added #
-
CRDTChangeStorage,CRDTSnapshotStorage,CRDTDocumentStorageandCRDTPeerIdStorage: what one document has on disk.crdt_lf_hive,crdt_lf_driftandcrdt_lf_sqliteimplement them, so code written against the contract runs on any adapter. -
CRDTStorageBackend: the database itself —storageForDocument,peerIdStorageForDocument,documentIds,deleteDocument,close. -
CRDTDocumentPersistence: keeps aCRDTDocumenton disk as it changes. Writes are batched, a failed write is retried with a growing delay (250 ms, doubling, capped at 30 s),hasUnwrittenChangessays whether anything is still waiting, andcompact()snapshots and prunes on demand.openSyncrestores before it returns, on a backend whose reads are synchronous, so a Flutter app builds its first frame from stored state. -
On the backend, everything an app does with a stored document:
openDocument(id)(identity, document and restore in one call),readDocument(id)for a preview or a read-only view,documentAt(id, version)for a history view, andcopyDocumentTo(other, id)for a backup or a move to another adapter. The three read-and-copy calls are also on a singleCRDTDocumentStorage. -
CRDTChangeStorage.getChangestakesnewerThanandupTo, bothVersionVectors;filterByVersionis the fallback for a backend that cannot ask its own query language. -
newestSnapshot: which snapshot to restore from when a crash left two. Settled by version vector, then by the smaller id, so every backend answers the same from the same bytes. -
Every storage method returns a
FutureOr, so a backend that answers without touching the disk never suspends;CRDTFutureOr.chainworks on either. -
CRDTDocumentStorage.close()andtransaction(), both with a working default, so an adapter only fills in what its backend can do.