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

@stateledger/core

v0.1.0

Published

Database-backed state machine for Node and TypeScript — core (ORM-agnostic).

Readme

@stateledger/core

npm

A database-backed state machine for Node and TypeScript. The boring, audit-friendly kind, not the blockchain kind. This package holds the core logic — defineMachine, the Adapter interface, the type system. Bring your own adapter: @stateledger/prisma for Postgres, or @stateledger/memory for tests.

What you'd write yourself vs. what stateledger does

If you've ever rolled this in production, you've written something like:

class Payment {
  state: "pending" | "authorized" | "captured" = "pending";

  authorize() {
    if (this.state !== "pending") throw new Error("Cannot authorize");
    this.state = "authorized";
  }
}

Works fine. Until you ship it. Then you discover:

| What breaks in production | What stateledger does | |---|---| | Restart kills state. It lived in memory. | Every transition is a row in your DB. Survives restarts, deploys, crashes. | | Concurrent webhooks double-charge. Two requests both pass the if check and both mutate state. | Acquires a lock on (machine, subjectId). Concurrent transitions serialize cleanly. | | No record of who/when/why. Customer asks "when did my refund fail?" — no answer. | Every row has an actor, timestamp, and free-form metadata. await machine.history() returns the full timeline. | | Compliance can't audit. Regulators ask "show every state change in Q3, who triggered it." | It's a SQL query against the transitions table. | | Bugs corrupt state silently. A bad code path writes "pending" → "settled" without going through "authorized". | Validates against declared transitions on every write. Throws InvalidTransition immediately. | | Time-travel is impossible. "What state was this in at 3am Tuesday?" | Reconstructable from history. await machine.stateAt(timestamp) (roadmapped). | | After-effects can leave you inconsistent. State updated, then ledger write failed, now you have a charge with no ledger entry. | After-callbacks run in the same transaction as the row insert. Throw → both roll back. |

You could write all this yourself. Most teams have — it takes 2–4 weeks the first time, breaks 3 months later under load, and gets rewritten. That's why GoCardless built Statesman in Ruby after the third rewrite. Node didn't have an equivalent. That's the gap.

Where this fits

Built for payments and fintech, where a missed state change is a regulatory event. The API choices reflect that — pessimistic locking by default, transactional callbacks, immutable audit trail.

The abstraction generalizes. Anywhere a business record moves between named stages and needs an audit trail: orders, subscriptions, KYC checks, document approval, loan applications, support tickets. Same library, same patterns, different rulebook.

Install

pnpm add @stateledger/core @stateledger/prisma @prisma/client

See the main repo README for a full quickstart and the examples/payments/ directory for a runnable end-to-end demo.

License

MIT