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

@majkapp/event-bus-types

v2.0.1

Published

Type definitions and interfaces for type-safe event bus implementations

Readme

@majkapp/event-bus-types

Core type definitions and interfaces for type-safe event bus implementations.

Overview

This package provides the fundamental interfaces and types that define the contract for event bus implementations. It contains zero implementation code - only TypeScript interfaces, types, and type definitions.

Purpose

  • Define Contracts: Establish clear interfaces for event bus implementations
  • Type Safety: Provide strong TypeScript typing across implementations
  • Portability: Enable multiple implementations (in-memory, distributed, persistent, etc.)
  • Zero Dependencies: Pure TypeScript types with no runtime dependencies

Core Types

Event

The fundamental unit of communication:

interface Event<TPayload = any, TType extends string = string> {
  type: TType;
  payload: TPayload;
  timestamp: Date;
  metadata?: Record<string, any>;
}

EventFilter

Filter events by type, metadata, or custom predicates:

interface EventFilter<TPayload = any, TType extends string = string> {
  types?: TType | TType[];
  predicate?: (event: Event<TPayload, TType>) => boolean;
  metadata?: Record<string, any>;
}

EventListener

Function that handles events:

type EventListener<TPayload = any, TType extends string = string> = (
  event: Event<TPayload, TType>
) => void | Promise<void>;

Subscription

Handle to manage event subscriptions:

interface Subscription {
  unsubscribe(): void;
  readonly id: string;
  readonly active: boolean;
}

IEventChannel

Core channel interface for event distribution:

interface IEventChannel<TPayload = any, TType extends string = string> {
  readonly channelId: string;
  subscribe(listener, filter?, options?): Subscription;
  emit(event): void;
  clear(): void;
  getListenerCount(): number;
  getDiagnostics(): ChannelDiagnostics;
}

QueryableEventChannel

Enhanced channel with query builder:

interface QueryableEventChannel<TPayload = any, TType extends string = string>
  extends IEventChannel<TPayload, TType> {
  query(): QueryBuilder<TPayload, TType>;
  onEvent(type, listener, options?): Subscription;
}

QueryBuilder

Fluent API for building complex filters:

interface QueryBuilder<TPayload = any, TType extends string = string> {
  whereType(type): QueryBuilder<TPayload, TType>;
  where(predicate): QueryBuilder<TPayload, TType>;
  whereMetadata(key, value): QueryBuilder<TPayload, TType>;
  subscribe(listener, options?): Subscription;
}

Installation

npm install @majkapp/event-bus-types

Usage

import {
  Event,
  EventFilter,
  EventListener,
  Subscription,
  IEventChannel,
  QueryableEventChannel
} from '@majkapp/event-bus-types';

// Define your domain types
interface User {
  id: string;
  name: string;
}

type UserEventType = 'created' | 'updated' | 'deleted';

// Implement the interfaces
class MyEventChannel implements QueryableEventChannel<User, UserEventType> {
  // ... implementation
}

Implementations

This types package is used by:

  • @majkapp/event-bus-local: In-memory implementation
  • Future: Distributed, persistent, and other implementations

Benefits

For Library Authors

  • Clear Contract: Implement the interfaces to create compatible event buses
  • Type Safety: Full TypeScript support with generics
  • Flexibility: Multiple implementations from one set of types

For Library Users

  • Swap Implementations: Change implementations without code changes
  • Type Consistency: Same types across all implementations
  • No Vendor Lock-in: Interface-based design enables portability

Design Philosophy

  1. Interface Segregation: Small, focused interfaces
  2. Generics First: Full generic support for type safety
  3. Zero Implementation: Only types, no runtime code
  4. Future-Proof: Extensible without breaking changes

License

MIT