Skip to main content

ihsm

Class-based hierarchical state machines for TypeScript — states as classes, protocol as methods, actors with run-to-completion dispatch.

0 production dependencies100% runtime coverageNode 22+

Quick start

npm install ihsm
import { InitialState, makeActor, Port, TopState } from 'ihsm';

interface DoorCtx {
openCount: number;
}

interface DoorConfig {
context: DoorCtx;
notifications: { open(): void; close(): void };
}

class DoorTop extends TopState<DoorConfig> {}

@InitialState
class Closed extends DoorTop {
open(): void {
this.ctx.openCount += 1;
this.hsm.transition(Open);
}
}

class Open extends DoorTop {
close(): void {
this.hsm.transition(Closed);
}
}

const door = makeActor(DoorTop, { openCount: 0 });
await door.hsm.sync();

door.notify.open();
await door.hsm.sync();

Learning path

1 · Reference + playgrounds

Reference — concepts, semantics, and interactive trace panels for standard examples 01–19 (plus config 00 and testing testing-0105).

2 · Deterministic testing

Testing — runnable DST examples first, then the full technique: TestPort, mock ports, simulated time, fault injection.