@gftdcojp/gftd-orm
Version:
Enterprise-grade real-time data platform with ksqlDB, inspired by Supabase architecture
121 lines • 3.31 kB
TypeScript
/**
* Realtime Module - リアルタイム通信機能(WebSocketベース)
*/
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: Realtime);
/**
* データベースの変更を監視
*/
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;
}
/**
* Realtime クラス - メインのリアルタイム管理
*/
export declare class Realtime {
private config;
private channels;
constructor(config: RealtimeConfig);
/**
* チャンネルを作成または取得
*/
channel(topic: string): RealtimeChannel;
/**
* すべてのチャンネルを切断
*/
disconnect(): void;
/**
* 接続状態を取得
*/
getConnectionStatus(): Record<string, boolean>;
}
/**
* デフォルトRealtimeインスタンスを作成
*/
export declare function createRealtime(config: RealtimeConfig): Realtime;
//# sourceMappingURL=realtime.d.ts.map