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
@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
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear(BaileysEx.Auth.KeyStore.Ref.t() | BaileysEx.Auth.KeyStore.TxRef.t()) :: :ok
Clears all keys from persistence.
@spec get( BaileysEx.Auth.KeyStore.Ref.t() | BaileysEx.Auth.KeyStore.TxRef.t(), BaileysEx.Signal.Store.data_type(), [String.t()] ) :: BaileysEx.Signal.Store.data_entries()
Fetches an array of identifiers for a given data type.
@spec in_transaction?( BaileysEx.Auth.KeyStore.Ref.t() | BaileysEx.Auth.KeyStore.TxRef.t() ) :: boolean()
Returns true if the current process is in an active transaction context.
@spec set( BaileysEx.Auth.KeyStore.Ref.t() | BaileysEx.Auth.KeyStore.TxRef.t(), BaileysEx.Signal.Store.data_set() ) :: :ok
Sets arbitrary mutations into the persistence backend.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the transactional key store linked to the current process.
Options:
:persistence_module- module implementingBaileysEx.Auth.Persistence(defaults toBaileysEx.Auth.NativeFilePersistence):persistence_context- backend-specific context passed to the built-in context-aware persistence callbacks when exported
@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.
@spec wrap(pid()) :: BaileysEx.Auth.KeyStore.Ref.t()
Creates a read-only query ref struct to pass directly into reads.