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

@openknot-ts/knot-pubsub

v0.0.6-preview

Published

In-memory pub/sub delivery for OpenKnot topic and broadcast ports.

Readme

@openknot-ts/knot-pubsub

Local delivery for Flow's topic() and broadcast() contracts over an EventEmitter the application provides. Each subscription is a native bounded ReadableStream. Flow owns admission and recipients; this package owns subscription resources and delivery.

Usage

import { inMemoryBroadcast, inMemoryTopic } from "@openknot-ts/knot-pubsub";
import { plug, resource, unit } from "@openknot-ts/wire";
import { EventEmitter } from "node:events";

const events = unit({ factory: () => new EventEmitter() });

const roleDelivery = resource({
  requirements: { events },
  initialize: ({ events }) =>
    inMemoryTopic<RoleAudience, RoleEvent>({
      events,
      event: (key) => `roles:${JSON.stringify([key.userId, key.roleId])}`,
      capacity: 64,
    }),
});

const logDelivery = resource({
  requirements: { events },
  initialize: ({ events }) => inMemoryBroadcast<LogEvent>({ events, event: "logs" }),
});

const roleBinding = plug({ port: roleTopic, requirements: { roleDelivery }, bind: ({ roleDelivery }) => roleDelivery });
const logBinding = plug({ port: logBroadcast, requirements: { logDelivery }, bind: ({ logDelivery }) => logDelivery });

List them through providePlugs(); Wire acquires the deliveries as resources. examples/topics.ts shows the full composition with guarded subscriptions.

API

| Export | Description | | --- | --- | | inMemoryTopic<Key, Message>({ events, event, capacity? }) | A topic. event(key) encodes a key to a native event name (NodeEventName): equal names share a route. Exposes keys(), subscriberCount(key) and interrupt(reason). | | inMemoryBroadcast<Message>({ events, event, capacity? }) | A broadcast. Exposes subscriberCount() and interrupt(reason). | | SlowSubscriberError | Ends a subscription whose queue is full. | | InMemoryTopic, InMemoryTopicOptions, InMemoryBroadcast, InMemoryBroadcastOptions, InMemoryPubSubOptions | Types. |

interrupt(reason) ends every active subscription with reason and discards its queue; later subscriptions open as usual. A delivery that loses its source, such as @openknot-ts/redis-pubsub, uses it.

keys() is a current view of active routes. To let Flow choose recipients, expose it through an ordinary reader plug:

plug({ port: roleRecipients, bind: () => (roleId) => roleDelivery.keys().filter((key) => key.roleId === roleId) });

With tRPC

Subscription procedures return the native iterable; access is the port's named guard input.

roles: trpc.procedure.input(roleAudienceSchema).subscription(({ input, ctx, signal }) =>
  roleTopic.subscribe({ input, access: ctx.token, signal: AbortSignal.any([ctx.signal, signal ?? ctx.signal]) }),
),

Flow runs the guards in a short scope before opening delivery, and releases admission resources before the stream is consumed.

Delivery

  • A subscription registers immediately: publications after subscribe() returns are queued before the first next().
  • Each queue holds capacity messages (default 64). A full queue ends that subscriber with SlowSubscriberError; others continue.
  • Iterator return, break, the lifetime signal and resource release remove native listeners and discard queued messages.
  • Publication emits synchronously to current listeners and does not wait for receipt.
  • Transient and in-process: no history, replay, acknowledgment or cross-process delivery. The emitter and its listener limit stay application-owned.

Example and tests

pnpm build
pnpm --filter @openknot-ts/knot-pubsub example
pnpm --filter @openknot-ts/knot-pubsub test

The tests cover routing, recipient inspection, overflow, cancellation, Flow admission, commit staging and real tRPC WebSockets (test/trpc.test.ts).