npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@yaebal/state-machine

v0.0.2

Published

yaebal state-machine plugin — declarative finite-state machines: typed events, guarded transitions, onEnter/onLeave hooks.

Readme

@yaebal/state-machine

a declarative finite-state machine backed by @yaebal/sklad storage: typed events, guarded transitions, onEnter/onLeave hooks. unlike @yaebal/scenes, there are no steps and no explicit enter() — a key's machine is always active, starting at initial the first time it's seen, and moves only when a typed event you send matches a transition declared for the current state.

install

pnpm add @yaebal/state-machine

usage

import { defineMachine, stateMachine } from "@yaebal/state-machine";
import { createBot, type Context } from "yaebal";

type OrderEvent = { type: "PAY" } | { type: "SHIP" } | { type: "CANCEL" };

const order = defineMachine<Context, OrderEvent, { paidAt?: number }>({
	initial: "created",
	states: {
		created: {
			on: {
				PAY: {
					target: "paid",
					actions: (ctx) => {
						ctx.machine.context.paidAt = Date.now();
					},
				},
				CANCEL: { target: "cancelled" },
			},
		},
		paid: {
			onEnter: (ctx) => ctx.send("payment received — shipping soon"),
			on: {
				SHIP: { target: "shipped" },
				CANCEL: { target: "cancelled", guard: (ctx) => ctx.machine.context.paidAt !== undefined },
			},
		},
		shipped: {
			onEnter: (ctx) => ctx.send("your order shipped 📦"),
		},
		cancelled: {
			onEnter: (ctx) => ctx.send("order cancelled"),
		},
	},
});

const bot = createBot(token).install(stateMachine(order));

bot.command("pay", (ctx) => ctx.machine.send({ type: "PAY" }));
bot.command("ship", (ctx) => ctx.machine.send({ type: "SHIP" }));
bot.command("status", (ctx) => ctx.reply(`order is ${ctx.machine.state}`));

behavior

  • always active — every key starts in initial the moment it's first seen; there is no enter()/leave() lifecycle like @yaebal/scenes. onEnter fires on that first activation too, with info.from === undefined.
  • typed eventson is keyed by your event union's type field, so ctx.machine.send(...) only accepts events the current state's type signature allows, and guards/actions receive the narrowed event.
  • guarded transitions — a state can declare several transitions for the same event as an array; they're tried in order, and a guard returning false skips to the next candidate. send() resolves true only if a transition actually fired.
  • extended statectx.machine.context is a plain, mutable, json-serializable bag (built by def.context(ctx)), persisted after every transition alongside the current state name.
  • durable snapshots — state + context persist as one json snapshot per chat:user key in any StorageAdapter (see @yaebal/sklad); restarts resume a key in the same state. ttl resets an inactive machine to initial lazily; snapshots pointing at a state a deploy removed self-heal instead of shadowing the key.
  • hooksonEnter(ctx, { from, event }) / onLeave(ctx, { to, event }) fire on every transition into/out of the state they're declared on.

options

stateMachine(order, {
	storage: myStorageAdapter, // defaults to in-memory (lost on restart)
	getKey: (ctx) => ctx.chat?.id?.toString(), // defaults to `chat.id:from.id`
	ttl: 24 * 60 * 60 * 1000, // reset an inactive machine after a day
});

part of yaebal — a type-safe, runtime-agnostic Telegram Bot API framework. MIT.