Issho.Store behaviour (Issho v0.1.0)

Copy Markdown View Source

Where documents last. Your app implements it on its database; Issho.Store.Memory is for development and tests.

load/2 gives the document as last saved, or nil for one that has never been saved. save/5 must compare the stored {epoch, revision} with expected and save the document and its content together, in one atomic write, and answer {:error, :conflict} to a stale writer. The authority confirms an edit to its author only after save/5 answers :ok, so answering before the write is durable breaks that promise.

The document is a map of JSON values (save it as a JSON or map column). The content is what the engine's Issho.Engine.validate/2 gave: keep it beside the document for your app to read and publish.

The context is your app's, given with the store: a repo, an options map.

{Issho, name: MyApp.Issho, store: {MyApp.CollabStore, MyApp.Repo}, ...}

Summary

Callbacks

The document as last saved, or nil.

Saves the document and its content, if the stored version is expected.

Types

document()

@type document() :: map()

expected()

@type expected() :: {epoch :: String.t(), revision :: non_neg_integer()} | nil

Callbacks

load(context, document_id)

@callback load(context :: term(), document_id :: String.t()) ::
  {:ok, document() | nil} | {:error, term()}

The document as last saved, or nil.

save(context, document_id, expected, document, content)

@callback save(
  context :: term(),
  document_id :: String.t(),
  expected(),
  document(),
  content :: term()
) ::
  :ok | {:error, :conflict} | {:error, term()}

Saves the document and its content, if the stored version is expected.