UNPKG

@synet/patterns

Version:

Robust, battle-tested collection of stable patterns used in Synet packages

43 lines (42 loc) 1.46 kB
import type { RealtimeChannel } from "./realtime-channel"; import type { RealtimeEvent } from "../common/realtime-event"; /** * Options for configuring a realtime provider */ export interface RealtimeProviderOptions<TTransportOptions = unknown> { authToken?: string; auth?: { enabled: boolean; validateToken?: (token: string) => Promise<boolean>; extractClaims?: (token: string) => Promise<Record<string, unknown>>; }; reconnect?: { enabled: boolean; maxAttempts?: number; initialDelayMs?: number; maxDelayMs?: number; }; transportOptions?: TTransportOptions; } export interface RealtimeProvider { /** * Create a channel for the specified topic * @param topic The topic to create a channel for * @param options Channel configuration options */ createChannel<TIn extends RealtimeEvent = RealtimeEvent, TOut extends RealtimeEvent = RealtimeEvent>(topic: string, options?: RealtimeProviderOptions): RealtimeChannel<TIn, TOut>; /*** * Remove a channel and stop receiving events * @param channel The channel to remove * @returns Promise that resolves when the channel is removed */ removeChannel(channel: RealtimeChannel): Promise<void>; /** * Get all active channels */ getChannels(): RealtimeChannel[]; /** * Close all channels and clean up resources */ disconnect(): Promise<void>; }