preludes / cluster.lisp
cluster
Effect Cluster entities. Entities with pure state transitions and checked delivery rules, emitted as native Effect 4 Entity.make and toLayer.
In-memory state only. Runners, message storage, and process wiring remain native Effect code.
From the source
Purpose: Effect 4 Cluster entities: message protocols, delivery rules, and pure state transitions. Requires: compiler.lisp; the cluster linker checks each transition as an ordinary Effect function. Used by: The optional TypeScript cluster linker. Runners, message storage, and process wiring belong to hosts.
Forms 3
Keywords this prelude adds. Each is a form descriptor: its slots, their types, and the IR it produces.
(command name {:keys [payload success error delivery dedupe-by guard reject update reply]})cluster.lisp:30
Declares a message that may change the entity's state. :guard, :reject, :update, and :reply are pure expressions over state and the payload fields; :reply sees the updated state. A persisted command that updates state must name its :dedupe-by field.
| Slot | Type |
|---|---|
| name | Symbol |
| payload | (Option Type) |
| success | Type |
| error | (Option Type) |
| delivery | (Union :persisted :volatile) |
| dedupe-by | (Option Keyword) |
| guard | (Option Syntax) |
| reject | (Option Syntax) |
| update | (Option Syntax) |
| reply | Syntax |
Produces ClusterCommandIR
Example
(entity Counter
:state {:count Int} :initial {:count 0} :storage :memory
(command Increment :payload {:by Int} :success Int :delivery :volatile
:update {:count (+ state.count by)} :reply state.count))(query name {:keys [payload success reply update]})cluster.lisp:65
Declares a read-only message. Queries are volatile and run concurrently with the entity's commands, so they cannot update state.
| Slot | Type |
|---|---|
| name | Symbol |
| payload | (Option Type) |
| success | Type |
| reply | Syntax |
| update | (Option Syntax) |
Produces ClusterQueryIR
Example
(entity Counter
:state {:count Int} :initial {:count 0} :storage :memory
(query Count :success Int :reply state.count))(entity name {:keys [state initial storage accept-state-loss max-idle]} message ...)cluster.lisp:84
Declares an Effect Cluster entity: its state, its messages, and how its state is stored. The cluster linker emits Entity.make and a toLayer handler layer.
| Slot | Type |
|---|---|
| name | (Declares ClusterEntityDecl) |
| state | Type |
| initial | Syntax |
| storage | (Union :memory) |
| accept-state-loss | (Option Bool) |
| max-idle | (Option (String :pattern "^[0-9]+ (millis|seconds|minutes|hours|days)$")) |
| message | (List message) |
Produces ClusterEntityIR · has a TypeScript :emit hook
Example
(entity Counter
:state {:count Int} :initial {:count 0} :storage :memory
(command Increment :payload {:by Int} :success Int :delivery :volatile
:update {:count (+ state.count by)} :reply state.count)
(query Count :success Int :reply state.count))Functions 1
Ordinary typed definitions that programs and elaboration hooks can call.
cluster-lower-firstcluster.lisp:26
Target names: (cluster-lower-first "OrderBook") is "orderBook".
(define cluster-lower-first [s] …)
Types 4
Payload contracts and IR shapes, shown as authored.
ClusterCommandIRcluster.lisp:11
(type ClusterCommandIR
{:kind "ClusterCommand" :name Symbol :payload (Option Type) :success Type
:error (Option Type) :delivery Keyword :dedupe-by (Option Keyword)
:guard (Option RuntimeExpr) :reject (Option RuntimeExpr)
:update (Option RuntimeExpr) :reply RuntimeExpr :handler (Option String)})ClusterQueryIRcluster.lisp:16
(type ClusterQueryIR
{:kind "ClusterQuery" :name Symbol :payload (Option Type) :success Type
:reply RuntimeExpr :handler (Option String)})messagecluster.lisp:19
(type message (Union ClusterCommandIR ClusterQueryIR))ClusterEntityIRcluster.lisp:20
(type ClusterEntityIR
{:kind "ClusterEntity" :name Symbol :state Type :initial RuntimeExpr
:storage Keyword :accept-state-loss (Option Bool) :max-idle (Option String)
:state-type String :initial-name String :messages (List message)})