DocStore

interface DocStore

A byte-oriented, async storage seam for a dev.yorkie.document.Document's persisted state. Ported from yorkie-js-sdk doc-store.ts (aaa5cb15/#1354), replacing the single-blob shape from 2291bf67/#1338.

It is deliberately a snapshot plus an append-only change log rather than one opaque blob. Re-serializing the whole document on every edit costs time proportional to the document — hundreds of milliseconds on a large one — and a document is at its largest while it is being edited, which is exactly when the writes happen. Appending costs the size of one change, which does not grow with the document at all.

The interface stays byte-oriented and suspending so a durable backend (file, Room, DataStore) fits behind it without the client knowing which storage it talks to, and so a backend is free to compress or encrypt what it is handed. The SDK ships no persistent implementation of its own — MemoryDocStore is process-local and dies with the process; a durable store is an app concern. Keyed by an opaque store key the Client derives from the API key, client key, and document key (see Client.storeKey) — this interface itself is unaware of that scheme.

This shape breaks the previous one (save is gone) with no deprecation shim: DocStore exists only on the unmerged 771/772/779 stack (unreleased API), so there is nothing released to preserve compatibility with — mirrors iOS's own unshimmed break at 4213eecc67.

Inheritors

Functions

Link copied to clipboard
abstract suspend fun appendChange(docKey: String, change: StoredChange)

Appends one local change. This is the hot path — frequent and small — so an implementation must not rewrite the whole entry to satisfy it.

Link copied to clipboard
abstract suspend fun load(docKey: String): StoredDoc?

Returns the persisted state for docKey, or null when nothing has been stored for it. StoredDoc.changes is ordered by ascending StoredChange.clientSeq.

Link copied to clipboard
abstract suspend fun remove(docKey: String)

Deletes everything persisted for docKey. A no-op when nothing is stored.

Link copied to clipboard
abstract suspend fun saveMeta(docKey: String, bytes: ByteArray)

Records the post-sync header. It leaves the snapshot alone — an online client syncs constantly, and re-snapshotting per sync would reintroduce the cost this interface exists to avoid — and it leaves the log alone too.

Link copied to clipboard
abstract suspend fun saveSnapshot(docKey: String, bytes: ByteArray)

Replaces the snapshot and atomically drops every appended change and any stored meta. This is compaction: the new snapshot already contains those changes, so keeping them would replay them twice, and it embeds a newer header than meta holds — a snapshot envelope embeds its own checkpoint and changeID, newer than whatever meta held; applying the old header over the new snapshot would regress serverSeq and — worse — lamport, whose regression makes the next edit mint tickets that collide with identities already in the restored root.