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

@fluxstack/live

v0.9.0

Published

Real-time server-client state sync — LiveServer, LiveComponent, rooms, auth, security, and cluster coordination

Readme

@fluxstack/live

Framework-agnostic core for real-time server-client state synchronization.

Live Components turn server-side classes into reactive state that syncs automatically with connected clients over WebSocket. Write your logic once on the server, and clients receive state updates in real-time.

Installation

bun add @fluxstack/live

Quick Start

import { LiveServer, LiveComponent } from '@fluxstack/live'

// 1. Define a component
class Counter extends LiveComponent<{ count: number }> {
  static componentName = 'Counter'
  static defaultState = { count: 0 }
  static publicActions = ['increment', 'decrement'] as const

  increment() {
    this.count++
  }

  decrement() {
    this.count--
  }
}

// 2. Create server with your transport adapter
import { ElysiaTransport } from '@fluxstack/live-elysia'

const server = new LiveServer({
  transport: new ElysiaTransport(app),
  componentsPath: './src/components',
})

await server.start()

Features

  • LiveComponent — Base class with reactive state proxy, auto-sync, and lifecycle hooks
  • LiveServer — Orchestrator that wires transport, components, auth, rooms, and cluster
  • ComponentRegistry — Auto-discovers components from a directory or manual registration
  • Rooms — Built-in room system with typed events and cross-instance pub/sub
  • Auth — Per-component and per-action authorization (static auth, static actionAuth)
  • State Signing — HMAC-SHA256 state signing with hybrid nonce replay protection
  • Rate Limiting — Token bucket rate limiter per connection
  • Security — Payload sanitization against prototype pollution, message size limits
  • Binary Delta — Efficient binary state diffs for high-frequency updates
  • File Upload — Chunked file upload over WebSocket
  • ClusterIClusterAdapter interface for horizontal scaling (singleton coordination, action forwarding, state mirroring)
  • Monitoring — Performance monitor with per-component metrics

Transport Adapters

This package is framework-agnostic. Use it with any transport adapter:

| Adapter | Package | |---------|---------| | Elysia | @fluxstack/live-elysia | | Express | @fluxstack/live-express | | Fastify | @fluxstack/live-fastify |

LiveComponent

import { LiveComponent } from '@fluxstack/live'

export class TodoList extends LiveComponent<typeof TodoList.defaultState> {
  static componentName = 'TodoList'
  static singleton = true
  static publicActions = ['addTodo', 'toggleTodo'] as const
  static defaultState = {
    todos: [] as { id: string; text: string; done: boolean }[]
  }

  declare todos: typeof TodoList.defaultState['todos']

  addTodo(payload: { text: string }) {
    this.todos = [...this.todos, { id: crypto.randomUUID(), text: payload.text, done: false }]
  }

  toggleTodo(payload: { id: string }) {
    this.todos = this.todos.map(t =>
      t.id === payload.id ? { ...t, done: !t.done } : t
    )
  }
}

Lifecycle Hooks

class MyComponent extends LiveComponent<State> {
  protected onConnect() { }           // WebSocket connected
  protected async onMount() { }       // Component fully mounted (async)
  protected onRehydrate(prev) { }     // State restored from client
  protected onStateChange(changes) { } // After state mutation
  protected onRoomJoin(roomId) { }    // Joined a room
  protected onRoomLeave(roomId) { }   // Left a room
  protected onAction(action, payload) { } // Before action (return false to cancel)
  protected onDisconnect() { }        // Connection lost
  protected onDestroy() { }           // Before cleanup (sync)
}

LiveServer Options

new LiveServer({
  transport,                         // Required: transport adapter
  componentsPath: './src/live',      // Auto-discover components from directory
  components: liveComponentClasses,  // Static component classes (for production bundles)
  wsPath: '/api/live/ws',            // WebSocket endpoint (default)
  debug: false,                      // Debug mode
  rooms: [ChatRoom, CounterRoom],    // LiveRoom classes to register
  cluster: clusterAdapter,           // IClusterAdapter for horizontal scaling
  roomPubSub: roomAdapter,           // IRoomPubSubAdapter for cross-instance rooms
  allowedOrigins: ['https://...'],   // CSRF protection
  rateLimitMaxTokens: 100,           // Rate limiter max tokens
  rateLimitRefillRate: 10,           // Tokens refilled per second
  httpPrefix: '/api/live',           // HTTP monitoring routes
})

Component Registration

There are two ways to register components, designed to work together:

Auto-discovery (dev)

Pass componentsPath and LiveServer.start() will:

  1. Scan the directory for extends LiveComponent classes
  2. Generate an auto-generated-components.ts file with all imports
  3. Register all components at runtime via dynamic imports
const server = new LiveServer({
  transport,
  componentsPath: join(import.meta.dir, 'live'),
})
await server.start() // discovers and registers components automatically

Static registration (production bundles)

In dev mode, componentsPath uses dynamic import() to load components from the filesystem at runtime. This works fine in dev, but production bundlers (like bun build) compile everything into a single file — dynamic filesystem imports are lost and the bundled server starts with 0 components.

To solve this, import the auto-generated-components.ts file (created automatically on the first start() call) and pass the classes via components[]. This gives the bundler a static import chain it can follow:

Note: On the very first run, this file doesn't exist yet. Start the server with just componentsPath first — start() generates the file. Then add the import.

// Add this import AFTER first run (start() generates this file)
import { liveComponentClasses } from './live/auto-generated-components'

const server = new LiveServer({
  transport,
  componentsPath: join(import.meta.dir, 'live'),  // dev: runtime discovery
  components: liveComponentClasses,                // prod: static in bundle
})

Both options can be used together. components[] registers classes immediately in the constructor, while componentsPath triggers auto-discovery in start() (skips duplicates). In a production bundle, componentsPath still runs but finds no files (they're inside the bundle) — the components from components[] are already registered.

Build utilities

The @fluxstack/live/build subpath exports generateLiveComponentsFile() for custom build pipelines:

import { generateLiveComponentsFile } from '@fluxstack/live/build'

generateLiveComponentsFile({
  componentsDir: './src/live',
  // Optional: custom output path and import prefix
  outFile: './src/generated/components.ts',
  importPrefix: '@app/live',
})

Horizontal Scaling

import { RedisClusterAdapter, RedisRoomAdapter } from '@fluxstack/live-redis'

const server = new LiveServer({
  transport,
  cluster: new RedisClusterAdapter({ redis }),
  roomPubSub: new RedisRoomAdapter({ redis }),
})

See @fluxstack/live-redis for details.

License

MIT