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

@selfagency/stately

v0.1.6

Published

Pinia-inspired state management for Svelte 5 and SvelteKit with persistence, history, sync, and async orchestration.

Readme

Stately

CI codecov

Stately is a Pinia-inspired state management library built specifically for Svelte 5 runes and SvelteKit. It provides a familiar defineStore() API, direct mutation ergonomics, and SSR-safe patterns, with an extensible plugin system for advanced features.

If you’ve used Pinia, you’ll feel at home. Stately provides a structured way to define shared state, mutate it directly, and observe changes. It includes built-in support for persistence, history, synchronization, and async orchestration without the boilerplate of manual state management.

Why Stately?

Stately is designed for those that need a store model that scales from simple counters to complex application workflows while maintaining Svelte 5 semantics and avoiding SSR pitfalls.

It bridges the gap between simple writable stores and complex state frameworks, offering an API that is powerful yet intuitive.

Key Features

  • Flexible Definitions: defineStore() supporting both option stores and setup stores.
  • Intuitive API: Direct mutations plus $patch(), $reset(), $subscribe(), and $onAction().
  • SSR Ready: Request-scoped state managers designed for SvelteKit safety.
  • Persistence: Support for localStorage, sessionStorage, IndexedDB, and custom serializers with TTL and compression.
  • History: Built-in undo, redo, and time-travel debugging.
  • Finite State Machines: Manage complex UI logic with transitions and lifecycle hooks.
  • Multi-tab Sync: Synchronize state across tabs using BroadcastChannel.
  • Async Workflow: Track loading/error states with built-in concurrency policies (restartable, drop, enqueue, etc.).
  • Validation: Prevent invalid state updates with pre-commit validation.
  • Typed Plugins: History, validation, persistence, and sync hooks preserve concrete store state types.
  • DevTools: A dedicated inspector drawer and Vite integration for real-time debugging.

Stability Warning ⚠️

Stately is in its early stages and may contain bugs. Feel free to push it to its limits and open GitHub issues, but be careful using it in production until it's been thoroughly battle-tested.

Installation

pnpm add @selfagency/stately

Quick Start

import { createStateManager, defineStore } from '@selfagency/stately';

const manager = createStateManager();

export const useCounterStore = defineStore('counter', {
  state: () => ({ count: 0 }),
  getters: {
    doubleCount(state) {
      return state.count * 2;
    }
  },
  actions: {
    increment() {
      this.count += 1;
    }
  }
});

const counter = useCounterStore(manager);
counter.increment();

For option stores, state() must return a plain object at runtime. Stately rejects common non-plain shapes like arrays, Date, Map, Set, and promises at compile time for option stores, while setup stores remain the escape hatch for class instances and other custom prototypes.

Note for SvelteKit: When using SSR, avoid getDefaultStateManager(). Instead, create a request-scoped manager and provide it via Svelte context. See the SSR documentation for details.

The Inspector

Stately includes a development-only inspector that allows you to visualize your state, track mutations in real-time, and test history playback.

Enable it in your vite.config.ts:

import { defineConfig } from 'vite';
import { sveltekit } from '@sveltejs/kit/vite';
import { statelyVitePlugin } from '@selfagency/stately/inspector/vite';

export default defineConfig({
  plugins: [
    sveltekit(),
    statelyVitePlugin({
      buttonPosition: 'right-bottom',
      panelSide: 'right'
    })
  ]
});

Advanced Usage

Stately is built for real-world complexity. You can easily compose plugins to handle persistence, history, and sync in a single store:

import {
  createAsyncPlugin,
  createHistoryPlugin,
  createPersistencePlugin,
  createStateManager,
  createSyncPlugin
} from '@selfagency/stately';

const manager = createStateManager()
  .use(createPersistencePlugin())
  .use(createHistoryPlugin())
  .use(createSyncPlugin({ origin: 'app-instance' }))
  .use(createAsyncPlugin());

Plugin callbacks preserve concrete store state types through history snapshots, validation callbacks, persistence envelopes, and store-facing sync helpers, which makes interface-shaped application state much easier to keep fully typed.

For complex workflows, use the Finite State Machine (FSM) plugin to replace "boolean soup" with explicit states:

import { createFsmPlugin, createStateManager, defineStore } from '@selfagency/stately';

const manager = createStateManager().use(createFsmPlugin());

export const useWizardStore = defineStore('wizard', {
  state: () => ({ step: 1 }),
  fsm: {
    initial: 'editing',
    states: {
      editing: { next: 'review' },
      review: { back: 'editing', submit: 'submitted' },
      submitted: {}
    }
  }
});

const wizard = useWizardStore(manager);

// Check current state
console.log(wizard.$fsm.current); // 'editing'

// Transition to the next state
wizard.$fsm.send('next');
console.log(wizard.$fsm.matches('review')); // true

Examples & Resources

The repository includes several practical examples under src/lib/examples/:

  • Counter: Simple option store usage.
  • Preferences: Setup store using Svelte runes.
  • Persistence: SSR-safe storage with compression.
  • History: Time-travel and undo/redo setup.
  • Async: Request cancellation and concurrency management.
  • FSM: Manage complex workflows and validation.

Documentation

Visit stately.self.agency for the full documentation:

AI Agent Skill

Stately ships an AI agent skill that helps LLM coding agents (Cursor, Windsurf, GitHub Copilot, etc.) work with the library correctly. See the AI Agent Skill guide for setup instructions.