Leaf.Collab.Store.File (Leaf v0.6.1)

Copy Markdown View Source

A markdown file on disk, which is what a vault of notes actually is.

The reference implementation, and the one the collaboration spec describes: with nobody editing, the file is the document; while a session is live, the room holds it and the file is a lagging export.

save/2 does nothing here. A file is the expensive copy, not the cheap one — writing it on every keystroke would be wasteful and would defeat the point of having two callbacks. A host wanting to lose seconds rather than a session puts a row in a table behind save/2 and keeps this behaviour for flush/2.

Edits made behind the session's back

The hash of the file is recorded when it is read, and checked again before it is written. If it changed in between, somebody edited the note outside the editor and the two copies have both moved. That is answered with {:error, :conflict} rather than a write: the work in the file is somebody's, and this session's copy is not more entitled to exist than theirs.

Reconciling them needs a person, or at least a policy, and neither belongs in a store.

Summary

Functions

Where a document with this id lives. Public so a host can configure it.

Functions

path(id)

Where a document with this id lives. Public so a host can configure it.

root()