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

@teliagen/events

v0.4.2

Published

Type-safe event system for Teliagen Framework

Readme

@teliagen/events

Event system for the Teliagen Framework.

npm version TypeScript License: Apache-2.0

Overview

@teliagen/events provides a lightweight, type-safe event bus for decoupled communication:

  • EventBus – Global pub/sub event system
  • Typed Events – Full TypeScript support
  • Async Handlers – Support for async event handlers
  • Wildcard Patterns – Listen to event groups

Installation

npm install @teliagen/events
# or
pnpm add @teliagen/events

Quick Start

import { EventBus } from '@teliagen/events';

// Subscribe to an event
EventBus.on('user:created', async (data) => {
  console.log('New user created:', data.user.email);
  await sendWelcomeEmail(data.user.email);
});

// Emit an event
EventBus.emit('user:created', {
  user: { id: '123', email: '[email protected]' }
});

API Reference

EventBus

// Subscribe to an event
EventBus.on(event: string, handler: (data: any) => void | Promise<void>): () => void;

// Subscribe once (auto-unsubscribe after first call)
EventBus.once(event: string, handler: (data: any) => void | Promise<void>): () => void;

// Unsubscribe
EventBus.off(event: string, handler: Function): void;

// Emit an event
EventBus.emit(event: string, data?: any): Promise<void>;

// Clear all handlers for an event
EventBus.clear(event?: string): void;

Usage Examples

Basic Events

import { EventBus } from '@teliagen/events';

// Subscribe
const unsubscribe = EventBus.on('order:created', (data) => {
  console.log('Order created:', data.orderId);
});

// Emit
await EventBus.emit('order:created', { orderId: '123', total: 99.99 });

// Unsubscribe when done
unsubscribe();

One-Time Subscription

EventBus.once('app:ready', () => {
  console.log('App is ready!');
  initializeServices();
});

// Handler is automatically removed after first emit

Async Handlers

EventBus.on('user:registered', async (data) => {
  await sendWelcomeEmail(data.email);
  await createDefaultSettings(data.userId);
  await notifyAdmins(data);
});

// Emit waits for all handlers to complete
await EventBus.emit('user:registered', { userId: '123', email: '[email protected]' });
console.log('All handlers completed');

Error Handling

EventBus.on('payment:processed', async (data) => {
  try {
    await updateOrderStatus(data.orderId, 'paid');
  } catch (error) {
    console.error('Failed to update order:', error);
    // Error is caught, doesn't break other handlers
  }
});

Event Naming Conventions

Use namespaced event names:

// Format: domain:action
'user:created'
'user:updated'
'user:deleted'
'order:placed'
'order:shipped'
'payment:processed'
'auth:login'
'auth:logout'

Framework Events

Teliagen plugins emit events you can listen to:

Auth Plugin

EventBus.on('auth:registered', async ({ user }) => { ... });
EventBus.on('auth:login', async ({ user }) => { ... });
EventBus.on('auth:logout', async ({ userId }) => { ... });
EventBus.on('auth:passwordReset', async ({ user, token }) => { ... });

Tenant Plugin

EventBus.on('tenant:created', async ({ tenant, owner }) => { ... });
EventBus.on('tenant:memberAdded', async ({ tenantId, userId, role }) => { ... });
EventBus.on('tenant:invitationSent', async ({ invitation }) => { ... });

RBAC Plugin

EventBus.on('rbac:roleAssigned', async ({ userId, roleId }) => { ... });
EventBus.on('rbac:roleRevoked', async ({ userId, roleId }) => { ... });

Storage Plugin

EventBus.on('storage:uploaded', async ({ disk, path, size }) => { ... });
EventBus.on('storage:deleted', async ({ disk, path }) => { ... });

Mail Plugin

EventBus.on('mail:sent', async ({ to, subject }) => { ... });
EventBus.on('mail:failed', async ({ to, error }) => { ... });

Usage in Actions

import { Action, ActionProvider, Input } from '@teliagen/commons';
import { EventBus } from '@teliagen/events';

@ActionProvider('orders', 'OrderActions')
class OrderActions {
  @Action('createOrder')
  async createOrder(@Input() input: CreateOrderInput) {
    const order = await Order.create(input);
    
    // Emit event for other systems to react
    await EventBus.emit('order:created', {
      orderId: order.id,
      userId: input.userId,
      total: order.total
    });
    
    return order;
  }
}

Type-Safe Events

// Define event types
interface AppEvents {
  'user:created': { user: User };
  'order:placed': { orderId: string; total: number };
  'notification:send': { userId: string; message: string };
}

// Create typed event bus
import { createTypedEventBus } from '@teliagen/events';

const events = createTypedEventBus<AppEvents>();

// Now fully typed!
events.on('user:created', (data) => {
  console.log(data.user.email);  // TypeScript knows about user
});

events.emit('order:placed', { 
  orderId: '123', 
  total: 99.99 
});

Requirements

  • Node.js >= 18.0.0
  • TypeScript >= 5.0.0 (for typed events)

Documentation

For full documentation, visit docs.teliagen.org.

License

Apache-2.0