UNPKG

@gftdcojp/gftd-orm

Version:

Enterprise-grade real-time data platform with ksqlDB, inspired by Supabase architecture

112 lines 3.2 kB
/** * クライアントサイド用リアルタイム通信(ブラウザ環境) */ import { EventEmitter } from 'events'; export interface RealtimeConfig { url: string; apiKey?: string; autoReconnect?: boolean; reconnectInterval?: number; maxReconnectAttempts?: number; } export interface RealtimeMessage { event: string; topic: string; payload: any; timestamp: number; } export interface SubscriptionOptions { event?: string; schema?: string; table?: string; filter?: string; } export type RealtimeEventType = 'INSERT' | 'UPDATE' | 'DELETE' | 'STREAM' | 'BROADCAST' | 'PRESENCE' | 'presence:change' | '*'; /** * クライアントサイド用リアルタイムチャンネル */ export declare class RealtimeChannel extends EventEmitter { private topic; private config; private realtime; private ws; private subscriptions; private isConnected; private reconnectAttempts; constructor(topic: string, config: RealtimeConfig, realtime: RealtimeClient); /** * データベースの変更を監視 */ on(event: string, callback: (...args: any[]) => void): this; /** * テーブルの変更を監視 */ onTable(table: string, event: RealtimeEventType, callback: (payload: any) => void, options?: { schema?: string; filter?: string; }): this; /** * ストリームイベントを監視 */ onStream(stream: string, callback: (payload: any) => void, options?: { filter?: string; }): this; /** * ブロードキャストイベントを監視 */ onBroadcast(event: string, callback: (payload: any) => void): this; /** * プレゼンス機能(ユーザーのオンライン状態管理) */ presence: { track: (state: Record<string, any>) => Promise<void>; untrack: () => Promise<void>; onChange: (callback: (payload: any) => void) => void; }; /** * メッセージをブロードキャスト */ broadcast(event: string, payload: any): Promise<void>; /** * チャンネルに接続 */ connect(): Promise<void>; /** * チャンネルから切断 */ disconnect(): void; /** * サブスクリプションを解除 */ unsubscribe(subscriptionId?: string): void; private buildWebSocketUrl; private send; private sendSubscription; private handleMessage; private attemptReconnect; } /** * クライアントサイド用リアルタイムクライアント */ export declare class RealtimeClient { private config; private channels; constructor(config: RealtimeConfig); /** * チャンネルを作成または取得 */ channel(topic: string): RealtimeChannel; /** * すべてのチャンネルを切断 */ disconnect(): void; /** * 接続状態を取得 */ getConnectionStatus(): Record<string, boolean>; } /** * クライアントサイド用Realtimeインスタンスを作成 */ export declare function createRealtimeClient(config: RealtimeConfig): RealtimeClient; //# sourceMappingURL=realtime-client.d.ts.map