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

@bazariodev/fsm-persist

v1.0.0

Published

Persistence helpers for @bazariodev/fsm snapshots with write-through storage and rehydrate-by-construction restore.

Readme

@bazariodev/fsm-persist

Persistence helpers for @bazariodev/fsm and hierarchy-shaped sources.

Full design rationale: Persist.md ADR.

pnpm add @bazariodev/fsm-persist @bazariodev/fsm

Flat machines

import { Fsm } from '@bazariodev/fsm';
import { persistFsm, restoreFsmConfig } from '@bazariodev/fsm-persist';

const restored = restoreFsmConfig(callConfig, {
  storage: localStorage,
  key: 'call',
});

const machine = new Fsm(restored.config);
const persist = persistFsm(machine, {
  storage: localStorage,
  key: 'call',
  name: callConfig.name,
});

Restore is by construction: restoreFsmConfig returns a config whose initial and context come from storage when the record is valid. Construct the machine normally. A restored machine starts at version: 0 and previousValue: null.

Hierarchies

import { FsmHierarchy } from '@bazariodev/fsm-hierarchy';
import {
  persistHierarchy,
  restoreHierarchyConfig,
} from '@bazariodev/fsm-persist';

const restored = restoreHierarchyConfig(rootConfig, {
  storage: localStorage,
  key: 'call-tree',
});

const hierarchy = new FsmHierarchy(restored.config);
const persist = persistHierarchy(hierarchy, {
  storage: localStorage,
  key: 'call-tree',
  name: rootConfig.name,
});

Hierarchy restore walks the stored active spine top-down. If the root state no longer exists, nothing is restored. If a deeper level no longer matches the current config, the valid prefix restores and everything below it starts fresh at the declared initial.

API

import type { FsmSubscribable } from '@bazariodev/fsm';

type PersistStorage = {
  getItem(key: string): string | null;
  setItem(key: string, value: string): void;
  removeItem(key: string): void;
};

localStorage and sessionStorage satisfy PersistStorage directly. The source port is structural and exported by @bazariodev/fsm; Fsm, FsmHierarchy, and hierarchy node handles satisfy it.

Writers:

  • persistFsm(source, options)
  • persistHierarchy(source, options)
  • new FsmPersist(source, toState, options) for custom projected state

Readers:

  • loadRecord(options) validates and returns the versioned envelope only
  • restoreFsmConfig(config, options)
  • restoreHierarchyConfig(config, options)

FsmPersist writes once at construction and then on each committed notification. filter gates all writes. stop() unsubscribes without removing the record; clear() removes the record without stopping.

Recovery model

Only state-at-rest is persisted: active state value and context. Effects, timers, subscribers, and in-flight work are not persisted. After restore, state onEnter runs normally, and attaching effects or delays re-fires the restored state's effects. That re-entry is the recovery model.

Only recovery-safe states belong in persisted records. For flows that cannot be meaningfully re-entered after a reload, use filter or a custom FsmPersist projection to persist a safe restore point instead.

Security

Persisted context is plaintext web storage. Credentials, tokens, and PII do not belong in persisted machine context. filter is not redaction: when a snapshot is filtered out, the previous record remains in storage. Keep secrets out of persisted context, project a reduced state with custom toState / serialize, and call clear() on logout.

Error policy

Bad storage data never bricks startup. Missing, corrupt, stale, wrong-name, wrong-kind, and unknown-state records degrade to a fresh start and log through the injected Logger.

Write failures are contained too. A throwing filter, toState, now, serialize, setItem, or removeItem is logged and does not affect the machine.