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

@eleven-am/pondsocket-nest

v0.0.138

Published

NestJS decorators and dependency-injection integration for PondSocket.

Readme

PondSocket NestJS

NestJS integration for PondSocket endpoints and channels.

Install

npm install @eleven-am/pondsocket @eleven-am/pondsocket-common @eleven-am/pondsocket-nest

@nestjs/common, @nestjs/core, and rxjs are peer dependencies.

Shared schema

Define a channel once in code shared by the server and client. Schema use is optional; the legacy string decorators and channel APIs remain supported.

import {
    definePondChannel,
    definePondEndpoint,
    definePondSchema,
} from '@eleven-am/pondsocket-common';

interface ChatSchema {
    events: {
        'message/:messageId': { text: string };
        ping: [{ sentAt: number }, { receivedAt: number }];
    };
    presence: {
        online: boolean;
    };
    assigns: {
        role: 'admin' | 'member';
    };
    joinParams: {
        token: string;
    };
}

export const Socket = definePondEndpoint('/v1/socket');
export const Chat = definePondChannel(
    definePondSchema<ChatSchema>(),
    '/chat/:roomId',
);

The optional second argument to definePondChannel is the runtime channel pattern. It is inferred as a literal type, so it is never repeated as a generic.

Nest handlers

Endpoint association uses the endpoint class. If an application has exactly one endpoint, { endpoint: SocketEndpoint } may be omitted.

import type {
    PondConnectionContext,
    PondEventContext,
    PondJoinContext,
    PondOutgoingContext,
} from '@eleven-am/pondsocket-nest';
import { Chat, Socket } from './pond-definitions';

@Socket.Endpoint()
export class SocketEndpoint {
    @Socket.OnConnection()
    connect(@Socket.GetContext() ctx: PondConnectionContext<typeof Socket>) {
        ctx.accept();
    }
}

@Chat.Channel({ endpoint: SocketEndpoint })
export class ChatController {
    @Chat.OnJoin()
    join(@Chat.GetContext() ctx: PondJoinContext<typeof Chat>) {
        ctx.joinParams.token.toUpperCase();
        ctx.params.roomId.toUpperCase();
        ctx.accept({ role: 'member' }).trackPresence({ online: true });
    }

    @Chat.OnEvent('message/:messageId')
    message(
        @Chat.GetContext()
        ctx: PondEventContext<typeof Chat, 'message/:messageId'>,
    ) {
        ctx.params.messageId.toUpperCase();
        ctx.payload.text.toUpperCase();
        ctx.broadcast(ctx.event.event, ctx.payload);
    }

    @Chat.OnEvent('ping')
    ping(
        @Chat.GetContext()
        ctx: PondEventContext<typeof Chat, 'ping'>,
    ) {
        ctx.reply({ receivedAt: Date.now() });
    }

    @Chat.OnOutgoingEvent('message/:messageId')
    outgoing(
        @Chat.GetContext()
        ctx: PondOutgoingContext<typeof Chat, 'message/:messageId'>,
    ) {
        ctx.transform({ text: ctx.payload.text.trim() });
    }
}

Every handler parameter must use a PondSocket parameter decorator. @Chat.GetContext() and @Socket.GetContext() explicitly inject the definition-bound context; the TypeScript annotation narrows it to the handler lifecycle and event. Extraction decorators such as @GetEventPayload(), @GetEventParams(), and custom decorators remain available for individual values.

Outgoing handlers run once per recipient. They must call ctx.transform(payload) or ctx.block() explicitly; return values are ignored. For request/response tuple events, ctx.action discriminates the payload: BROADCAST carries the request payload and SYSTEM carries the response payload.

Module

import { Module } from '@nestjs/common';
import { PondSocketModule } from '@eleven-am/pondsocket-nest';

@Module({
    imports: [
        PondSocketModule.forRoot({
            providers: [SocketEndpoint, ChatController],
            isExclusiveSocketServer: false,
        }),
    ],
})
export class AppModule {}

forRootAsync accepts the same Nest module metadata plus inject and useFactory. Its factory can return backend, maxMessageSize, and heartbeatInterval.

Client

import { PondClient } from '@eleven-am/pondsocket-client';
import { Chat } from './pond-definitions';

const client = new PondClient('wss://example.com/v1/socket');
const channel = client.createChannel(Chat, {
    params: { roomId: 'general' },
    joinParams: { token: 'secret' },
});

channel.onMessageEvent('message/:messageId', (payload) => {
    payload.text.toUpperCase();
});

channel.onError((error) => console.error(error.code, error.status, error.message));
channel.join();

Required route and join parameters are derived from the definition. Presence, assigns, event names, event payloads, and request/response tuples are derived from the same schema.

Responses and errors

A handler can use the context directly or return a declarative response. The nested payload form avoids collisions with control fields:

return {
    event: 'message/:messageId',
    eventParams: { messageId: 'message-1' },
    payload: { text: 'saved' },
    assigns: { role: 'member' },
    presence: { online: true },
};

Connection and join handlers can decline declaratively:

return { decline: { message: 'Invalid token', status: 401 } };

Unhandled exceptions are logged through Nest's Logger. Event failures reply with INTERNAL_SERVER_ERROR; rejected event guards reply with UNAUTHORIZED_BROADCAST.

Operations

PondSocketService is exported and injectable. pondSocket exposes the underlying server and isHealthy() reports backend/server health. Module initialization waits for the distributed backend, and module shutdown awaits PondSocket cleanup without closing Nest's shared HTTP server.

constructor(private readonly sockets: PondSocketService) {}

health() {
    return this.sockets.isHealthy();
}

Channel patterns use path syntax: /jobs/:id and whole-segment * are supported. Patterns such as job:* are rejected at startup. A valid join that matches no registered channel receives a correlated CHANNEL_NOT_FOUND error instead of remaining in JOINING.

Legacy API

@Endpoint(path), @Channel(path), @OnConnectionRequest(), @OnJoinRequest(), @OnEvent(event), @OnOutgoingEvent(event), and @OnLeave() remain available. In applications with multiple endpoints, shared definitions are recommended because they provide explicit endpoint ownership and schema-derived types.