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

@zudojs/events

v1.0.0

Published

Event-driven architecture with event bus, emitter, middleware, and registry for decoupled communication.

Readme

@zudojs/events

Event-driven architecture with event bus, emitter, middleware, and registry for decoupled communication.

Installation

npm install @zudojs/events

Quick Start

import { createEventBus, defineEvent } from "@zudojs/events";

interface UserCreated {
  readonly id: string;
  readonly name: string;
}

const bus = createEventBus();

const UserCreatedEvent = defineEvent<"user.created", UserCreated>("user.created");

bus.on("user.created", (event) => {
  console.log("New user:", (event.payload as UserCreated).id);
});

// Publish from an event definition …
await bus.publish(UserCreatedEvent.create({ id: "123", name: "Alice" }));

// … or from plain event input.
await bus.publishEvent({
  type: "user.created",
  payload: { id: "124", name: "Bob" },
});

bus.emit() accepts either a full Event or an EventInput and behaves like publish / publishEvent respectively.

Features

  • Event bus with a middleware pipeline (use(), constructor and per-publish middleware)
  • Sequential or parallel handler dispatch with THROW / CONTINUE error modes
  • Handler priorities, one-time handlers, per-handler timeouts
  • Wildcard subscriptions ("user.*", "*")
  • Event registry for typed definitions; handlers registered on the registry are dispatched by the bus
  • Deep-frozen events (freezeEvents, on by default) so handlers cannot alter what other handlers see
  • Listener-leak warnings (maxListeners) and an onError hook for fire-and-forget publishes
  • Typed error classes from @zudojs/errors (EventHandlerError, EventMiddlewareError, EventDispatchAbortedError, …)

Lifecycle

CREATED ──(first use / start)──▶ ACTIVE ◀──(start)── STOPPED
                                   │                     ▲
                                   └──────(stop)─────────┘
                                   ▼
                               DISPOSED
  • A CREATED bus starts itself on the first publish / on.
  • stop() moves the bus to STOPPED; publishing or subscribing then throws EventBusStoppedError until start() is called. Handlers and definitions are kept.
  • dispose() is final; every operation throws EventBusDisposedError.

Publish results

const result = await bus.publish(event);

result.handled;        // true when at least one handler succeeded
result.handlerCount;   // handlers invoked
result.succeeded;      // handlers that completed
result.failed;         // handlers that threw
result.errors;         // EventHandlerError[] (cause = the raw thrown value)
result.shortCircuited; // true when a middleware did not call next()

In the default CONTINUE error mode handler failures are collected in result.errors (and forwarded to the onError option). In THROW mode the first EventHandlerError rejects the publish. Errors thrown by a middleware itself are wrapped as EventMiddlewareError; handler errors and aborts pass through unwrapped.

Registry

bus.register(defineEvent("order.placed")) records a definition; with requireRegistration: true the bus rejects unregistered types with EventTypeNotFoundError. bus.unregister(type) removes only the definition; pass { removeHandlers: true } to also drop handlers subscribed to exactly that type.

Event types are normalised (trimmed, lower-cased) everywhere, so "User.Created" and "user.created" refer to the same event.

Use Cases

  • Decoupling application components
  • Audit logging and change tracking
  • Real-time notifications
  • CQRS event publishing (see @zudojs/cqrs)