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

@consensus-tools/storage

v0.10.0

Published

Storage layer for consensus-tools — IStorage, JsonStorage, SqliteStorage, Mutex

Readme

@consensus-tools/storage

Storage backends for consensus-tools. Provides the IStorage interface and three implementations: JSON file, SQLite, and in-memory.

Install

pnpm add @consensus-tools/storage

Peer dependency: @consensus-tools/schemas

Storage Backends

| Backend | Persistence | Best for | |---------|------------|----------| | JsonStorage | File (JSON) | Local development, single-process deployments | | SqliteStorage | SQLite database | Production use with concurrent access | | MemoryStorage | In-memory (lost on exit) | Tests, quick prototyping, CI environments |

Quick Start

For most use cases, instantiate a storage backend directly:

import { JsonStorage, SqliteStorage, MemoryStorage } from "@consensus-tools/storage";

const json = new JsonStorage("./state.json");
const sqlite = new SqliteStorage("./state.db");
const memory = new MemoryStorage();

await memory.init(); // all backends require init()

Factory (config-driven)

createStorage takes a full ConsensusToolsConfig and reads config.local.storage.kind to pick the backend:

import { createStorage } from "@consensus-tools/storage";

// config must be a full ConsensusToolsConfig with config.local.storage.kind set
const storage = await createStorage(config);

Direct Usage

import { JsonStorage, SqliteStorage, MemoryStorage } from "@consensus-tools/storage";

const store = new MemoryStorage();
await store.init();

// Read/write state
const state = await store.getState();
await store.saveState(state);

// Atomic updates with mutex protection
const { state: updated, result } = await store.update((current) => {
  current.jobs.push(newJob);
  return newJob.id;
});

IStorage Interface

All backends implement this contract:

interface IStorage {
  init(): Promise<void>;
  getState(): Promise<StorageState>;
  saveState(state: StorageState): Promise<void>;
  update<T>(fn: (state: StorageState) => T | Promise<T>): Promise<{ state: StorageState; result: T }>;
}

Exports

| Export | Description | |---|---| | createStorage(config) | Factory — creates the right backend from config | | JsonStorage | File-based JSON storage | | SqliteStorage | SQLite-based storage | | MemoryStorage | In-memory storage for dev/test | | IStorage | Storage interface type | | StorageCaps | Storage capacity limits type | | defaultState() | Returns an empty default StorageState | | applyStorageCaps(state, caps) | Trim state to capacity limits | | Mutex | Mutex for concurrent access control |

Links

consensus-tools on GitHub