xmachines-machine
The contract of a typed machine: one XState v6 machine, usually generated by xmachines-build, whose guards, actions, delays and invoked actors are Rust compiled into a guest of its own, a WASI component (xmachines-machine-wasi) or a Node.js addon (xmachines-machine-node).
When to use it
A machine crate implements TypedMachine once; each guest crate's export_machine! turns it into that guest's exports, so the same implementation builds a WASI component and a Node.js addon. Use this crate directly when you write that implementation, or a guest for another target.
What the guests share does not depend on the target, so it is here too: the machine compiled once per guest (compiled), its id and version (info), and JsonActor, the actor API of the typed world xmachines:machine with values as JSON text. Events are deserialized into the machine's Event type at the boundary; others are rejected.
Example
use ;
use ;
use ;
;
With codegen, Context and Event are the generated types, and DEFINITION, SCHEMAS and machine() are the generated module's (examples/checkout-wasi).
Contract
TypedMachine is the Rust side of the WIT package xmachines:machine@0.2.0 (wit/machine.wit of xmachines-machine-wasi): its info interface reports id, version, DEFINITION and SCHEMAS, and JsonActor implements its actor resource. JsonActor takes start options { "input"?, "id"?, "maxSteps"?, "observeSystemEmitted"? } (a typed machine compiles its children in, so it takes no children), and its snapshots, persisted systems, emitted events, logs and effects are the JSON that the package's JSON Schemas describe.
Related crates
xmachines-machine-wasi:export_machine!for a WASI component.xmachines-machine-node:export_machine!for a Node.js addon.xmachines-runtime: the runtime, andhost, the option parsing every host in another language shares.
License
MIT