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

@sumicom/quicksave-message-bus

v0.8.6

Published

Transport-agnostic command + subscribe message bus for Quicksave

Readme

@sumicom/quicksave-message-bus

Transport-agnostic command + subscribe message bus. Built for Quicksave's PWA ↔ agent RPC channel, but has no Quicksave-specific code — it only needs a duplex transport that can deliver JSON frames.

What it gives you

Three primitives over a single transport:

| Primitive | Shape | | -------------- | ---------------------------------------------------------------- | | command | One-shot request/response (verb + payload → result or error) | | subscribe | Path-based (/sessions/:id/cards), delivers snapshot + updates until unsub | | publish | Server-side fan-out to every peer subscribed to a path | | getSnapshot | One-shot read of a subscribable path — resolves with the same data sub would, without creating a subscription |

Key properties:

  • Snapshot-on-subscribe: the first frame after sub is always a full snapshot. On reconnect the client auto-resends sub frames and gets a fresh snapshot, eliminating the "stale-after-reconnect" window.
  • Command queueing: command(..., { queueWhileDisconnected: true }) holds the request until the transport reconnects, then flushes.
  • Typed path params: PathParams<'/sessions/:id/cards'>{ id: string }.
  • Transport-agnostic: implement ServerTransport / ClientTransport and drop it in. A FakeTransport ships under /fake for tests.

Install

npm install @sumicom/quicksave-message-bus

Quick example

Server (Node, any transport):

import { MessageBusServer } from '@sumicom/quicksave-message-bus';

const bus = new MessageBusServer(transport);

bus.onCommand<StartPayload, StartResult>('session:start', async (payload, ctx) => {
  return await startSession(payload);
});

bus.onSubscribe<'/sessions/:id/cards', CardHistory, CardUpdate>(
  '/sessions/:id/cards',
  {
    snapshot: async ({ params }) => getCardHistory(params.id),
    onSubscribed: ({ params, peer }) => trackSubscriber(params.id, peer),
  },
);

// Push updates to all subscribers of this exact path
bus.publish('/sessions/abc123/cards', { kind: 'card', event });

Client (browser or Node):

import { MessageBusClient } from '@sumicom/quicksave-message-bus';

const bus = new MessageBusClient(transport);

const result = await bus.command<StartResult, StartPayload>(
  'session:start',
  { prompt: 'hello' },
  { timeoutMs: 30_000, queueWhileDisconnected: true },
);

const unsub = bus.subscribe<CardHistory, CardUpdate>(
  '/sessions/abc123/cards',
  {
    onSnapshot: (history) => setInitialState(history),
    onUpdate: (event) => applyUpdate(event),
    onError: (err) => console.warn('sub failed:', err),
  },
);
// later:
unsub();

Wire protocol

Frames (JSON):

// Client → Server
{ kind: 'cmd',   id, verb, payload }
{ kind: 'sub',   path }
{ kind: 'unsub', path }

// Server → Client
{ kind: 'result', id, ok: true, data }
{ kind: 'result', id, ok: false, error }
{ kind: 'snap',   path, data }
{ kind: 'upd',    path, data }
{ kind: 'sub-error', path, error }

Transports are responsible for framing, delivery, and emitting peer connect/disconnect events; the bus has no opinion on wire format below that.

Transport contract

interface ServerTransport {
  send(peer: PeerId, frame: ServerFrame): void;
  onFrame(handler: (peer: PeerId, frame: ClientFrame) => void): void;
  onPeerConnected(handler: (peer: PeerId) => void): void;
  onPeerDisconnected(handler: (peer: PeerId) => void): void;
}

interface ClientTransport {
  send(frame: ClientFrame): void;
  onFrame(handler: (frame: ServerFrame) => void): void;
  onConnected(handler: () => void): void;
  onDisconnected(handler: () => void): void;
  onReestablished(handler: () => void): void;
  isConnected(): boolean;
}

onConnected / onDisconnected track whether the transport is currently up; they should be idempotent on already-in-state. onReestablished is distinct and fires every time a fresh upstream session has just been established (e.g. a successful handshake-ack), even when the transport's connected flag never transitioned to disconnected. The bus uses it to re-send sub frames, because the server drops a peer's subscriptions per disconnect — if the wire layer masks brief blips from onDisconnected to keep in-flight commands alive, only onReestablished will tell the bus that its server-side subscription state needs rebuilding.

For an example over an existing WebSocket layer, see Quicksave's apps/agent/src/messageBus/busServerTransport.ts and apps/pwa/src/lib/busClientTransport.ts.

Testing with the fake transport

import { FakeServerTransport, FakeClientTransport } from '@sumicom/quicksave-message-bus/fake';

Pairs in-memory; lets you drive connect/disconnect manually. Used in this package's own test suite.

License

MIT