Metakit / API
@doeixd/metakit/machine
Framework-independent declarative state machine (@doeixd/metakit/machine) built
over Transitions: one declaration drives runtime dispatch (TEA update
/ Sync journal) and per-message read/write footprints; intent and
affordances ask what a partial state allows (UI and agents).
Opaque transitions (for arbitrary JS) can coexist beside declarative
Transitions without breaking types.
Functions
affordances | Every tag of machine, as available, disabled, or pending (its guard is undecided), using options for custom operation implementations and the rewrite policy. |
attach | Return a new Machine with a resolved lifted child merged under prefix (so dispatch, update, and affordances handle ${prefix}${tag} directly without mutating… |
compose | |
diagram | The state diagram of machine, as Mermaid stateDiagram-v2 text: its start (where it has one), every phase, and one line per edge labelled by its message and,… |
each | Lift every transition of a child machine over a keyed list list: with each => each.sku, each transition's input gains { sku: Child['sku'] }, targeting the… |
intent | The intent of arm, taken from a machine's transitions: its message is tagged with the arm's name, and its can checks the guard against the values you give… |
lazyChild | Wrap a dynamic import of a child machine so callers can check isLoaded(), read current(), or await resolve() (deduplicating concurrent loads and clearing… |
lift | Lift every transition of a child machine along path, as Transition.lift does one: each reads and writes under path, and is refused where the state holds no… |
make | Construct a declarative state machine from a Schema and a map of Transitions. Its transitions are arms: copies named by their keys, so one transition given… |
phases | The phases of the field select picks from state (state => state.phase): one reference per literal, or per variant of a union of tagged structs, as phase,… |
phaseTable | For each phase of machine, which messages move it and where, and which are refused: each guard is judged knowing only the phase, so a message whose guard… |
reachability | The phases of machine its start cannot reach, and those it can never leave. It follows edges between phases and reads no guard, so a phase it calls… |
startsOf | The states a reader that needs somewhere to begin (reachability, a walk) starts from: from, each checked as Machine.make checks start, else the machine's… |
stepObserved | Run one step and return the observed state writes when it succeeds. |
Interfaces
EachLifted | A child Machine's transitions, each lifted to run on one keyed element of a list (Machine.each). |
From | The transitions that leave the phases L given to from. |
Intent | Admission and client message construction for one arm of a machine. |
LazyChild | A child machine whose code loads on demand. |
LazyMachineLike | Structural machine shape accepted as a lazy child (covariant in its transitions). |
Lifted | A child Machine's transitions, each lifted to run inside Outer (Machine.lift) and named by its tag. |
Machine | |
Phase | One phase of a machine: a literal of its phase field, or a variant of the tagged union there, named by the value Machine.phases returned (phase.Editing),… |
PhaseEdge | One edge of a phase transition: the phases it leaves, the phase it enters, and when it is taken. |
PhaseEdges | What a transition built with from records of its phases. |
PhaseRow | One phase's row of Machine.phaseTable. |
Phases | The phases of a field and the builder of transitions between them. |
PhaseTable | For each phase of a machine, what each message does. |
Reachability | What Machine.reachability found. |
Types
Alternative | An alternative of choose from the phases L, taken where when holds and no earlier one did. |
Alternatives | The alternatives of choose: conditions in order, and at most one otherwise, last. |
ArmOf | Any one arm of a machine whose transitions are Transitions. |
Arms | A machine's transitions as it holds them, each an arm: a copy of the transition it was given carrying the tag it was registered under as name. |
Composed | The transitions of a composition: its own, and each child's under its name then the child's tag. |
EmitOf | |
Entry | What a transition from L into N gives besides the phase: its writes, and, for a variant with fields, those fields as with. |
Held | What a field holding P holds in the phases named N: those literals, or those variants. |
InputOf | The input a transition takes. |
InputServicesOf | The services a transition's input Schema needs (Transition's InputServices); unknown where none is recorded. |
MessageOf | Tagged message union derived from a Record<Tag, Transition> map. A transition that declares supplied values carries them in its message, so a replay runs it… |
ObservedWrite | An observed change under a state path. A keyed field names the domain key, not a list index. |
Otherwise | The last alternative of choose, taken where no earlier one is. |
PhaseEnv | What a transition's callbacks are given: the paths of { state, input }, and variant, the phase field as it is in the phases the transition leaves. Where… |
PhaseField | What a phase field may hold: string literals, or tagged structs. |
PhaseName | The name of each phase a field holding P has: a literal, or a variant's tag. |
PhaseNameOf | The phase names of a machine's transitions built with from. |
PhaseRefs | One reference per phase of a field holding P, keyed by its name. |
PhaseTransition | A transition built with from: an ordinary Transition that also carries its edges. |
SharedTags | The tags two transitions of a composition would share; never where each is its own. |
SuppliedOf | Values the host supplies to a transition. |