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

@siran/chat-supabase-events

v0.1.16

Published

Implémentation Supabase des adaptateurs d'événements en temps réel pour le système de chat.

Downloads

650

Readme

@package/chat-supabase-events

Implémentation Supabase des adaptateurs d'événements en temps réel pour le système de chat.

Description

Ce package fournit les implémentations Supabase des ports RealTimeEventEmitter et RealTimeEventSubscriber définis dans @siran/chat-core. Il utilise Supabase Realtime pour émettre et recevoir des événements via des channels WebSocket.

Installation

bun install

Utilisation

RealTimeEventEmitter

Pour émettre des événements en temps réel :

import { createSupabaseRealTimeEventEmitter } from "@package/chat-supabase-events";
import { createClient } from "@supabase/supabase-js";

const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
const eventEmitter = createSupabaseRealTimeEventEmitter(supabase);

// Émettre un événement à une conversation
await eventEmitter.emitToConversation(conversationId, {
  type: "message.created",
  conversationId,
  payload: { message },
  timestamp: new Date(),
});

// Émettre un événement à un utilisateur
await eventEmitter.emitToUser(userId, event);

// Émettre un événement à plusieurs utilisateurs
await eventEmitter.emitToUsers([userId1, userId2], event);

RealTimeEventSubscriber

Pour s'abonner aux événements en temps réel :

import { createSupabaseRealTimeEventSubscriber } from "@package/chat-supabase-events";
import { createClient } from "@supabase/supabase-js";

const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
const subscriber = createSupabaseRealTimeEventSubscriber(supabase);

// S'abonner aux événements d'une conversation
const unsubscribe = subscriber.subscribeToConversation(
  conversationId,
  (event) => {
    console.log("Nouvel événement:", event);
    // Traiter l'événement...
  }
);

// Plus tard, se désabonner
unsubscribe();

// S'abonner aux événements d'un utilisateur
const unsubscribeUser = subscriber.subscribeToUser(userId, (event) => {
  console.log("Événement utilisateur:", event);
});

Architecture

Channels Supabase

Le package utilise deux types de channels Supabase :

  1. Channels de conversation : conversation:{conversationId}

    • Utilisés pour diffuser des événements à tous les participants d'une conversation
    • Format : conversation:{uuid}
  2. Channels utilisateur : user:{userId}

    • Utilisés pour envoyer des événements à un utilisateur spécifique
    • Format : user:{uuid}

Gestion des channels

  • Les channels sont créés à la demande et réutilisés
  • Les channels sont automatiquement nettoyés lorsqu'il n'y a plus de callbacks actifs
  • La méthode cleanup() peut être appelée pour nettoyer tous les channels manuellement

Événements supportés

Tous les types d'événements définis dans @siran/chat-core sont supportés :

  • message.created
  • message.updated
  • message.deleted
  • message.status_changed
  • conversation.created
  • conversation.updated
  • conversation.deleted
  • conversation.last_message_updated
  • user.typing
  • user.presence_changed

Configuration Supabase

Pour que ce package fonctionne, Supabase Realtime doit être activé pour les tables concernées. Les migrations SQL dans @package/chat/supabase/repo/migrations configurent automatiquement les tables nécessaires.

Notes de performance

  • Les channels sont réutilisés pour éviter de créer trop de connexions WebSocket
  • Les événements sont sérialisés en JSON avant l'envoi
  • Les callbacks sont exécutés de manière synchrone, donc les opérations longues devraient être déléguées à un worker ou une queue

Nettoyage

Il est recommandé d'appeler cleanup() lors de la destruction de l'instance pour libérer les ressources :

// Pour l'emitter
await eventEmitter.cleanup();

// Pour le subscriber
await subscriber.cleanup();