bankai/mnesia_store

Bankai’s narrow Mnesia repository boundary. Records are canonical JSON so Gleam’s Task layout never leaks into the persisted Erlang schema.

Values

pub fn change_tail(
  workspace: String,
  offset: Int,
) -> Result(List(String), String)

Returns canonical committed change records after offset, in ascending non-gapped workspace order. Event IDs make delivery replay-safe.

pub fn create(
  workspace: String,
  task: types.Task,
) -> Result(types.Task, String)

Every task creation is a committed-change source event.

pub fn current_store(
  workspace: String,
) -> Result(store.Store, String)
pub fn exportable_versions(
  workspace: String,
) -> Result(store.Store, String)
pub fn get_current(
  workspace: String,
  id: String,
) -> Result(types.Task, String)
pub fn idempotent_result(
  workspace: String,
  idempotency_key: String,
  namespace: String,
) -> Result(option.Option(#(String, String)), String)
pub fn import_legacy_if_needed(
  workspace: String,
  legacy: store.Store,
) -> Result(Nil, String)

Lazily imports the legacy JSONL history exactly once. The version rows retain every immutable hash; current rows are derived by the existing Store rules.

pub fn import_replica_snapshot(
  workspace: String,
  versions: store.Store,
  heads: List(types.Task),
) -> Result(Nil, String)

Import a portable JSONL snapshot. It validates every record before crossing the FFI, unions versions by hash, and refuses same-ID head divergence rather than silently choosing a winner.

pub fn import_snapshot(
  workspace: String,
  incoming: store.Store,
) -> Result(Nil, String)

Import a portable JSONL snapshot, projecting its heads from the immutable version set. Peer replication uses import_replica_snapshot so it never loses the sender’s explicit head view.

pub fn init(workspace: String) -> Result(Nil, String)
pub fn projection_checkpoint(
  workspace: String,
  projection: String,
) -> Result(Int, String)

Durable projection cursors are metadata beside, never inside, task state.

pub fn projection_snapshot(
  workspace: String,
) -> Result(String, String)

Returns canonical snapshot/tail JSON payloads for AaronDB adapters. The payloads are already canonical bytes from the persistence boundary; callers choose their own decoder without widening Bankai’s authority surface.

pub fn projection_snapshot_rows(
  workspace: String,
) -> Result(#(Int, List(types.Task)), String)

Typed current-head snapshot paired with its exact committed event watermark. Unlike projection_snapshot, consumers never need to reparse the task JSON.

pub fn replace(
  workspace: String,
  previous: types.Task,
  updated: types.Task,
) -> Result(types.Task, String)

Atomically advances one stable task head and writes exactly one matching committed change record. A stale head leaves neither mutation nor event.

pub fn replace_committed(
  workspace: String,
  command_id: String,
  previous: types.Task,
  updated: types.Task,
) -> Result(types.Task, String)

Apply a cluster-committed task transition exactly once. The command ID and expected head are validated atomically with version/head/event persistence.

pub fn replace_current_snapshot(
  workspace: String,
  current: store.Store,
) -> Result(Nil, String)

Replace active heads after an explicit archival operation while retaining all immutable versions for inspect/history. Inputs are validated before FFI.

pub fn replace_many(
  workspace: String,
  replacements: List(#(types.Task, types.Task)),
) -> Result(Nil, String)

Atomically advances a related set of task heads and emits one batch event. The FFI validates every expected hash before writing any version/current pair, so an incomplete duplicate merge cannot leak a half-rewritten graph.

pub fn replace_many_idempotent(
  workspace: String,
  idempotency_key: String,
  fingerprint: String,
  replacements: List(#(types.Task, types.Task)),
) -> Result(String, String)
pub fn reset_workspace_for_test(
  workspace: String,
) -> Result(Nil, String)

Scoped test harness cleanup. Never used by application commands; it clears only this workspace’s Mnesia rows so repeatable tests do not leak history.

pub fn set_projection_checkpoint(
  workspace: String,
  projection: String,
  offset: Int,
) -> Result(Nil, String)
pub fn version_store(
  workspace: String,
) -> Result(store.Store, String)
Search Document