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

@sovereignbase/station-client

v1.0.0

Published

Local-first station client for tabs and workers sharing an opportunistic Sovereignbase base station transport.

Readme

npm version CI codecov license

station-client

Local-first station client for same-origin tabs and workers that share an opportunistic Sovereignbase base station transport. It uses BroadcastChannel for immediate local delivery and elects a single leader context to own the upstream WebSocket connection.

Compatibility

  • Runtimes: web browsers and web workers with the APIs below.
  • Module format: ESM and CJS builds.
  • Required globals / APIs: BroadcastChannel, WebSocket, AbortSignal, EventTarget, CustomEvent, MessageEvent, DOMException, crypto.randomUUID; upstream leadership additionally requires navigator.locks and navigator.onLine.
  • TypeScript: bundled types.

Goals

  • Local-first coordination across same-origin contexts.
  • A single upstream owner per coordination group.
  • Fire-and-forget relay() and request/response transact().
  • Generic message payloads without package-defined application semantics.
  • Small public API with explicit shutdown and cancellation behavior.

Installation

npm install @sovereignbase/station-client
# or
pnpm add @sovereignbase/station-client
# or
yarn add @sovereignbase/station-client
# or
bun add @sovereignbase/station-client
# or
deno add jsr:@sovereignbase/station-client
# or
vlt install jsr:@sovereignbase/station-client

Usage

import { StationClient } from '@sovereignbase/station-client'
import { OOStruct } from '@sovereignbase/convergent-replicated-struct'

type State = {
  name: string
  amount: number
  flag: boolean
}

const station = new StationClient<Partial<State>>()
const snapshot =
  JSON.parse(localStorage.getItem('state') ?? 'null') ?? undefined
const state = new OOStruct<State>(
  {
    name: '',
    amount: 0,
    flag: false,
  },
  snapshot
)

const nameInput = document.getElementById('name') as HTMLInputElement
const amountInput = document.getElementById('amount') as HTMLInputElement
const flagInput = document.getElementById('flag') as HTMLInputElement

nameInput.value = state.read('name')
amountInput.value = state.read('amount')
flagInput.checked = state.read('flag')

nameInput.addEventListener('change', (event) => {
  state.update('name', (event.target as HTMLInputElement).value)
  state.snapshot()
})

amountInput.addEventListener('change', (event) => {
  state.update('amount', (event.target as HTMLInputElement).valueAsNumber)
  state.snapshot()
})

flagInput.addEventListener('change', (event) => {
  state.update('flag', (event.target as HTMLInputElement).checked)
  state.snapshot()
})

state.addEventListener('snapshot', (event) => {
  localStorage.setItem('state', JSON.stringify(event.detail))
})

state.addEventListener('delta', (event) => {
  station.relay(event.detail)
})

station.addEventListener('message', (event) => {
  state.merge(event.detail)
})

state.addEventListener('change', (event) => {
  const { name, amount, flag } = event.detail
  if (name !== undefined) nameInput.value = name
  if (amount !== undefined) amountInput.value = amount
  if (flag !== undefined) flagInput.checked = flag
})

Events

message events are emitted for:

  • relayed messages received from other same-origin contexts
  • non-transaction messages received from the base station

relay() does not loop a message event back into the same instance. Transaction responses resolve the promise returned by transact() instead of emitting a message event.

Runtime behavior

Local coordination

Every instance joins a BroadcastChannel derived from its configured base station URL. One context becomes leader through the Web Locks API and owns the active upstream transport for that coordination group.

Upstream transport

The leader attempts to keep a WebSocket open while the host is online. Outbound messages are MessagePack-encoded before transport.

Transactions

transact(message, options) returns Promise<T | false>.

  • It resolves with false when the request cannot presently be issued.
  • It rejects when options.signal is aborted.
  • options.ttlMs controls stale leader-side routing cleanup for follower requests. It is not a general request timeout.

Wire convention

The current JavaScript binding uses these MessagePack payload shapes:

  • ordinary upstream messages: the application message value itself
  • transaction request: ['station-client-request', id, message]
  • transaction response: ['station-client-response', id, message]

Tests

Command: npm run test

  • Build tooling: npm run build
  • Coverage tooling: node test/run-coverage.mjs
  • Browser E2E tooling: node test/e2e/run.mjs
  • Playwright matrix: Chromium, Firefox, WebKit, Pixel 5, iPhone 12

The package runtime target is web browsers and web workers. The repository uses Node-based tooling to build and run automated tests for that binding.

License

Apache-2.0