decisions/memory
A single-process, in-memory store for tests and examples. It implements
the whole storage port and passes decisions/conformance.
It keeps nothing but text, so restart is honest: only what a
database would hold survives it. A transaction is transaction: when
its body returns Error, or raises, every row is put back. The
transaction value tx is the Memory itself.
It is safe only for one process at a time: it serialises nothing, so
two processes using one Memory at once can interleave their
transactions. The lock the port promises (on an occurrence, and on an
id that does not exist yet) holds here only because one process runs
one transaction at a time. For concurrent tests use the process-safe
store of decisions_otp.
The same table also holds an application’s own rows (get and
put), so a gated tool’s writes commit and roll back with the verdict
that released them, as they would in one database.
import decisions/memory
let store = memory.new()
let desk = decisions.desk(point, drives:, under:, over: memory.port())
let assert Ok(waiting) =
memory.transaction(store, decisions.recommend(desk, _, proposal))
memory.queue(store, "finance")
Target-independent: builds for Erlang (an ETS table) and JavaScript (a
Map).
Types
Values
pub fn entries(memory: Memory, id: String) -> List(store.Stored)
The stored entries of a record, in sequence order.
pub fn evidence() -> model.Evidence(Memory)
Evidence kept in the same table, for decisions/model.capture.
pub fn get(memory: Memory, key: String) -> Result(String, Nil)
An application’s own row, read in the same transactions as the record.
pub fn heads(memory: Memory) -> List(#(String, store.Head))
Every record’s head, in the order the records were first written.
pub fn inspection() -> store.Inspection(Memory)
What decisions/conformance and decisions/testing read.
pub fn notices(memory: Memory) -> List(store.Notice)
Every settlement notice, in the order admitted.
pub fn now(memory: Memory) -> timestamp.Timestamp
The store’s clock. It moves only when a test moves it.
pub fn put(memory: Memory, key: String, value: String) -> Nil
Write an application’s own row. It commits and rolls back with the transaction it is written in.
pub fn queue(memory: Memory, set: String) -> List(String)
The occurrences waiting for a holder of set: the soonest due first,
those with no due time last, then in arrival order.
pub fn queue_for(
memory: Memory,
validator: vocabulary.Validator,
) -> List(String)
The occurrences a validator may decide: waiting for a set they hold,
not already approved by them, and not among those the head says may
not decide (their own request under SomeoneElseHolding), in queue
order.
pub fn restart(memory: Memory) -> Memory
A new table holding only the old one’s text, as a database would after a restart. Everything built on the old handle must be built again.
pub fn review_queue(memory: Memory) -> List(String)
Sampled occurrences waiting for a review after the fact.
pub fn set_clock(memory: Memory, at: timestamp.Timestamp) -> Nil
Set the clock, forwards or backwards.
pub fn snooze(
memory: Memory,
wake: store.Wake,
until: timestamp.Timestamp,
) -> Nil
Put a delivered wake-up back for until, as a job queue snoozes a job
that decisions.wake found early (NotDue(until)).
pub fn take_due(memory: Memory) -> List(store.Wake)
The wake-ups due now, removed as a delivered job would be.
pub fn tamper(
memory: Memory,
id: String,
seq: Int,
text: String,
) -> Nil
Replace the stored text of one entry, bypassing every rule of the port. It exists to test what a desk does with a record it cannot read.