Skip to main content

Module txfn

Module txfn 

Source
Expand description

User-defined transaction functions, shared by every backend (Codeberg #325, #333).

A transaction function is an ident carrying a :db/fn string: the mino source of a (fn [db & args] ...) form that returns tx-data. A transaction invokes it as [:my/fn arg ...]. Before a transactor processes the transaction, expand replaces each such invocation with the tx-data the function returns (recursively: a tx-fn may return calls to other tx-fns). The output is ordinary tx-data, so the transactor itself is unchanged.

The backend supplies two things:

  • lookup(ident) -> Option<source>: the live :db/fn of the entity whose :db/ident is ident (None when it has none, so the call is left for the transactor to accept or reject);
  • eval(form) -> printed EDN: evaluate a mino form in the backend’s sandboxed interpreter, where (mentat.store/db (mentat.store/open)) is the transacting store at the basis before this transaction.

See docs/design/325-user-defined-transaction-functions.md.

Constants§

DB_FN_IDENT
The ident of the attribute that holds a transaction function’s source.
DEFAULT_MAX_DEPTH
Default bound on tx-fns calling tx-fns (pg_mentat: mentat.txfn_max_depth; embedded: MENTAT_TXFN_MAX_DEPTH).

Functions§

expand
Expand every user tx-fn invocation in the top-level tx vector value. Input that isn’t a vector is returned unchanged (the transactor reports it). No interpreter work happens unless an item could be an invocation.
expand_str
Expand the tx-fn invocations in EDN text, returning EDN text. The common case (no candidate invocation) returns the input unchanged without re-printing it.
invocation_head
Some(keyword) if v looks like [:ns/name ...] and the keyword is not one of the transactor’s own list-form operations. Whether it actually names a tx-fn is decided by looking for a :db/fn on it.