Standalone TypeScript implementation of the HSM DSL and runtime.
This package ships a native TypeScript runtime with richer compile-time types. The current build focuses on:
- standard TypeScript source for both the DSL and runtime
- modern package outputs via
tsup - PascalCase DSL/runtime exports with camelCase compatibility aliases
Define/Redefinemodel constructionValidator/Finalizerhooks for definition-time model checks and finalizationSubmachineState,EntryPoint,ExitPoint,ShallowHistory, andDeepHistory- top-level
Attribute/Operationnamespaces withOnSet,When, andOnCallevents Observehooks for redefining a model with observation behaviorNew,Start,Started,Stop, andRestartlifecycle helpersDispatch,DispatchAll,DispatchTo,MakeGroup, and ordered group snapshots- attribute-aware
sm.get("name")value/found reads,sm.set("name", value), and Promise-returningsm.call("name")
npm install
npm run typecheck
npm run test
npm run conformance
npm run buildimport * as hsm from "@stateforward/hsm.ts";
class Counter extends hsm.Instance {}
const model = hsm.define(
"Counter",
hsm.Attribute("count", 0),
hsm.State("idle"),
hsm.Initial(hsm.Target("idle")),
);
const machine = hsm.start(new Counter(), model);
const [count] = machine.get("count"); // number
machine.set("count", count + 1);