🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@ws-kit/plugins

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ws-kit/plugins

Core plugins for WS-Kit routers (messaging, RPC, pub/sub)

latest
Source
npmnpm
Version
0.10.1
Version published
Maintainers
2
Created
Source

@ws-kit/plugins

Core plugins for WS-Kit routers — framework features that add capabilities via composition.

Plugins

  • withMessaging() — Fire-and-forget unicast messaging (ctx.send())
  • withRpc() — Request-response with streaming (ctx.reply(), ctx.progress())
  • withPubSub(options) — Topic-based broadcasting (ctx.publish(), ctx.topics)

Installation

bun add @ws-kit/plugins

Quick Start

import { createRouter, withZod } from "@ws-kit/zod";
import { withPubSub, withRpc } from "@ws-kit/plugins";
import { memoryPubSub } from "@ws-kit/memory";

const router = createRouter()
  .plugin(withZod()) // Validation
  .plugin(withRpc()) // Request-response
  .plugin(
    withPubSub({
      adapter: memoryPubSub(), // In-memory pub/sub (dev)
    }),
  );

// Handlers now have:
// - ctx.send() — fire-and-forget
// - ctx.publish() — broadcast to topic
// - ctx.reply(), ctx.progress() — RPC responses

Architecture

Plugins define framework features; adapters provide backend implementations:

  • Memory (in @ws-kit/memory) — For development and testing
  • Redis (in @ws-kit/redis) — For distributed deployments
  • Cloudflare (in @ws-kit/cloudflare) — For Cloudflare Workers

Swap adapters without changing your code:

// Development
.plugin(withPubSub({ adapter: memoryPubSub() }))

// Production
.plugin(withPubSub({ adapter: redisPubSub(redis) }))

Convenience Re-exports

For convenience, validator packages re-export these plugins:

// âś… Convenient (recommended)
import { withPubSub, withRpc } from "@ws-kit/zod";

// âś… Also works (explicit)
import { withPubSub, withRpc } from "@ws-kit/plugins";

Documentation

  • docs/specs/plugins.md — Complete plugin documentation
  • ADR-031: Plugin-Adapter Architecture — Design rationale
  • docs/specs/context-methods.md — Context method API reference

TypeScript

All plugins are fully typed. The type system enforces that:

  • Methods only appear after their plugin is registered
  • Context is properly enhanced with plugin methods
  • Payloads match schema types

License

MIT

Keywords

websocket

FAQs

Package last updated on 05 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts