BaileysEx.Auth.KeyStore (baileys_ex v0.1.0-alpha.7)

Copy Markdown View Source

Persistence-backed transactional Signal key store.

This module wraps an auth persistence backend with the same get/3, set/2, and transaction/3 shape used by the runtime Signal.Store contract. Reads go through ETS, transaction work is cached on an explicit transaction handle, and commit failures roll back to the previous persisted snapshot before surfacing an error to the caller. When a persistence backend exports context-aware callbacks such as load_keys/3 or save_keys/4, the store passes the configured :persistence_context as the first argument; otherwise it falls back to the behaviour's context-free callbacks.

Summary

Functions

Returns a specification to start this module under a supervisor.

Clears all keys from persistence.

Fetches an array of identifiers for a given data type.

Returns true if the current process is in an active transaction context.

Sets arbitrary mutations into the persistence backend.

Starts the transactional key store linked to the current process.

Acquires an exclusive lock tied to key before running the fun. Errors safely roll back changes if commit fails.

Creates a read-only query ref struct to pass directly into reads.

Types

state()

@type state() :: %{
  table: :ets.tid(),
  persistence_module: module(),
  persistence_context: term(),
  locks: map(),
  monitor_keys: map(),
  known_ids: map(),
  max_commit_retries: pos_integer(),
  delay_between_tries_ms: non_neg_integer()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear(ref)

Clears all keys from persistence.

get(ref, type, ids)

Fetches an array of identifiers for a given data type.

in_transaction?(arg1)

Returns true if the current process is in an active transaction context.

set(ref, data)

Sets arbitrary mutations into the persistence backend.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the transactional key store linked to the current process.

Options:

transaction(ref, key, fun)

@spec transaction(
  BaileysEx.Auth.KeyStore.Ref.t() | BaileysEx.Auth.KeyStore.TxRef.t(),
  String.t(),
  (BaileysEx.Auth.KeyStore.TxRef.t() -> result)
) :: result
when result: var

Acquires an exclusive lock tied to key before running the fun. Errors safely roll back changes if commit fails.

wrap(pid)

@spec wrap(pid()) :: BaileysEx.Auth.KeyStore.Ref.t()

Creates a read-only query ref struct to pass directly into reads.