import type { PubSubAdapter, PublishEnvelope, PublishOptions, PublishResult } from "@ws-kit/core"; import type { Server } from "bun"; /** * Bun-native Pub/Sub adapter leveraging server.publish(). * * Uses Bun's event-loop integrated broadcasting with zero-copy semantics. * All WebSocket connections that have called `ws.subscribe(topic)` will * receive messages published via this adapter. * * **Performance characteristics**: * - Zero-copy: Messages are broadcast directly without serialization overhead * - In-process: All subscribers must be in the same Bun instance * - Synchronous: Messages are delivered immediately to all subscribers * * **Scope**: Messages published to a topic are received by ALL WebSocket * connections in this Bun process that have subscribed to that topic. * For multi-process deployments (load-balanced cluster), each instance has * its own scope—use RedisPubSubAdapter for cross-process broadcasting. * * **Limitations**: * - excludeSelf is not supported (returns UNSUPPORTED). Bun's server.publish() * broadcasts directly with no way to intercept or filter delivery. * Use memory or Redis adapter if excludeSelf is required. * * **Note**: For public API, use `bunPubSub()` factory function instead. * * @internal Use `bunPubSub(server)` factory for creating instances. */ export declare class BunPubSub implements PubSubAdapter { private server; constructor(server: Server); /** * Publish a message to a topic. * * All WebSocket connections subscribed to this topic (via ws.subscribe) * will receive the message immediately. * * **excludeSelf limitation**: Bun's native pub/sub broadcasts directly via * server.publish() with no way to intercept delivery or enumerate subscribers. * This makes excludeSelf impossible - use memory or Redis adapter if needed. * * @param envelope - Validated message with topic, payload, type, meta * @param options - Publish options (excludeSelf returns UNSUPPORTED) */ publish(envelope: PublishEnvelope, options?: PublishOptions): Promise; /** * Subscribe a client to a topic. * * **Note**: Bun's pub/sub is connection-based; subscriptions happen via * `ws.subscribe(topic)` on the WebSocket. This is a no-op since actual * subscription management is handled per-connection by the platform. * * @param clientId - Client identifier (unused; Bun handles per-connection) * @param topic - Topic name */ subscribe(clientId: string, topic: string): Promise; /** * Unsubscribe a client from a topic. * * **Note**: Like subscribe, this is a no-op for Bun as subscriptions are * connection-based and managed via ws.unsubscribe(topic). * * @param clientId - Client identifier (unused) * @param topic - Topic name (unused) */ unsubscribe(clientId: string, topic: string): Promise; /** * Get local subscribers for a topic. * * **Note**: Bun's pub/sub doesn't expose subscriber tracking. This always * returns an empty async iterable since we cannot enumerate subscribers. * The router will attempt delivery to all connections separately. * * @param topic - Topic name (unused; no subscriber tracking) */ getSubscribers(topic: string): AsyncIterable; } //# sourceMappingURL=pubsub.d.ts.map