connectbase-client 0.6.26 → 0.6.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -544,6 +544,97 @@ interface RetentionPolicy {
544
544
  schedule?: string;
545
545
  enabled: boolean;
546
546
  }
547
+ /** 데이터베이스 실시간 구독 변경 타입 */
548
+ type DatabaseChangeType = 'added' | 'modified' | 'removed';
549
+ /** 데이터베이스 실시간 변경 이벤트 */
550
+ interface DatabaseChange {
551
+ type: DatabaseChangeType;
552
+ doc_id: string;
553
+ data?: Record<string, unknown>;
554
+ old_data?: Record<string, unknown>;
555
+ metadata?: {
556
+ has_pending_writes: boolean;
557
+ updated_at: string;
558
+ };
559
+ }
560
+ /** 데이터베이스 실시간 스냅샷 */
561
+ interface DatabaseSnapshot {
562
+ id: string;
563
+ data: Record<string, unknown> | null;
564
+ exists: boolean;
565
+ metadata?: {
566
+ updated_at: string;
567
+ };
568
+ }
569
+ /** 데이터베이스 실시간 구독 옵션 */
570
+ interface DatabaseSubscribeOptions {
571
+ /** 특정 문서 ID만 구독 */
572
+ docId?: string;
573
+ /** 쿼리 필터 조건 */
574
+ where?: DatabaseRealtimeFilter[];
575
+ /** true면 자기 변경도 수신 (기본: false) */
576
+ includeSelf?: boolean;
577
+ /** 메타데이터 변경도 수신 (기본: false) */
578
+ includeMetadataChanges?: boolean;
579
+ }
580
+ /** 데이터베이스 실시간 필터 조건 */
581
+ interface DatabaseRealtimeFilter {
582
+ field: string;
583
+ operator: '==' | '!=' | '>' | '>=' | '<' | '<=' | 'in';
584
+ value: unknown;
585
+ }
586
+ /** 데이터베이스 실시간 스냅샷 메시지 */
587
+ interface DatabaseSnapshotMessage {
588
+ subscription_id: string;
589
+ docs: DatabaseSnapshot[];
590
+ total_count: number;
591
+ has_more: boolean;
592
+ }
593
+ /** 데이터베이스 실시간 변경 메시지 */
594
+ interface DatabaseChangeMessage {
595
+ subscription_id: string;
596
+ changes: DatabaseChange[];
597
+ }
598
+ /** 데이터베이스 실시간 구독 핸들러 */
599
+ interface DatabaseRealtimeHandlers {
600
+ /** 초기 스냅샷 수신 시 */
601
+ onSnapshot?: (docs: DatabaseSnapshot[], info: {
602
+ totalCount: number;
603
+ hasMore: boolean;
604
+ }) => void;
605
+ /** 변경 이벤트 수신 시 */
606
+ onChange?: (changes: DatabaseChange[]) => void;
607
+ /** 에러 발생 시 */
608
+ onError?: (error: Error) => void;
609
+ }
610
+ /** 데이터베이스 실시간 구독 객체 */
611
+ interface DatabaseRealtimeSubscription {
612
+ /** 구독 ID */
613
+ subscriptionId: string;
614
+ /** 구독 해제 */
615
+ unsubscribe(): void;
616
+ }
617
+ /** 데이터베이스 실시간 연결 옵션 */
618
+ interface DatabaseRealtimeConnectOptions {
619
+ /** JWT 액세스 토큰 (필수) */
620
+ accessToken: string;
621
+ /** data-server URL (기본: baseUrl) */
622
+ dataServerUrl?: string;
623
+ /** 자동 재연결 최대 시도 (기본: 5) */
624
+ maxRetries?: number;
625
+ /** 재연결 간격 밀리초 (기본: 1000) */
626
+ retryInterval?: number;
627
+ /** 디버그 로깅 (기본: false) */
628
+ debug?: boolean;
629
+ }
630
+ /** 데이터베이스 실시간 프레즌스 상태 */
631
+ interface DatabasePresenceState {
632
+ user_id: string;
633
+ status: 'online' | 'away' | 'offline';
634
+ last_seen: string;
635
+ device?: string;
636
+ metadata?: Record<string, unknown>;
637
+ }
547
638
  interface CreateBackupRequest {
548
639
  /** 백업 이름 */
549
640
  name?: string;
@@ -565,6 +656,16 @@ interface BackupInfo {
565
656
 
566
657
  declare class DatabaseAPI {
567
658
  private http;
659
+ private realtimeWs;
660
+ private realtimeState;
661
+ private realtimeHandlers;
662
+ private realtimeRetryCount;
663
+ private realtimeOptions;
664
+ private pendingRequests;
665
+ private pingInterval;
666
+ private realtimeOnStateChange;
667
+ private realtimeOnError;
668
+ private activeSubscriptions;
568
669
  constructor(http: HttpClient);
569
670
  /**
570
671
  * API Key 인증 시 /v1/public 접두사 반환
@@ -746,6 +847,93 @@ declare class DatabaseAPI {
746
847
  * 보관 정책 조회
747
848
  */
748
849
  getRetentionPolicy(appId: string, tableName: string): Promise<RetentionPolicy>;
850
+ /**
851
+ * 데이터베이스 실시간 연결
852
+ * data-server의 WebSocket에 연결하여 데이터 변경을 실시간으로 수신합니다.
853
+ *
854
+ * @example
855
+ * ```typescript
856
+ * // 연결
857
+ * cb.database.connectRealtime({
858
+ * accessToken: 'your-jwt-token',
859
+ * dataServerUrl: 'https://data.connectbase.world'
860
+ * })
861
+ *
862
+ * // 테이블 구독
863
+ * const sub = cb.database.subscribe('users', {
864
+ * onSnapshot: (docs, info) => {
865
+ * console.log('Initial data:', docs, 'total:', info.totalCount)
866
+ * },
867
+ * onChange: (changes) => {
868
+ * changes.forEach(change => {
869
+ * console.log(change.type, change.doc_id, change.data)
870
+ * })
871
+ * },
872
+ * onError: (error) => console.error(error)
873
+ * })
874
+ *
875
+ * // 구독 해제
876
+ * sub.unsubscribe()
877
+ *
878
+ * // 연결 해제
879
+ * cb.database.disconnectRealtime()
880
+ * ```
881
+ */
882
+ connectRealtime(options: DatabaseRealtimeConnectOptions): Promise<void>;
883
+ /**
884
+ * 데이터베이스 실시간 연결 해제
885
+ */
886
+ disconnectRealtime(): void;
887
+ /**
888
+ * 테이블 또는 문서의 실시간 변경 구독
889
+ *
890
+ * @param tableId 구독할 테이블 이름
891
+ * @param handlers 이벤트 핸들러 (onSnapshot, onChange, onError)
892
+ * @param options 구독 옵션 (docId, where, includeSelf 등)
893
+ * @returns 구독 해제 가능한 객체
894
+ */
895
+ subscribe(tableId: string, handlers: DatabaseRealtimeHandlers, options?: DatabaseSubscribeOptions): DatabaseRealtimeSubscription;
896
+ /**
897
+ * 프레즌스 상태 설정
898
+ */
899
+ setPresence(status: string, device?: string, metadata?: Record<string, unknown>): void;
900
+ /**
901
+ * 프레즌스 구독 (다른 사용자의 온라인 상태 감시)
902
+ */
903
+ subscribePresence(userIds: string[], onPresence: (states: Record<string, DatabasePresenceState>) => void): void;
904
+ /**
905
+ * 실시간 연결 상태 확인
906
+ */
907
+ isRealtimeConnected(): boolean;
908
+ /**
909
+ * 실시간 연결 상태 반환
910
+ */
911
+ getRealtimeState(): 'disconnected' | 'connecting' | 'connected';
912
+ /**
913
+ * 상태 변경 콜백 등록
914
+ */
915
+ onRealtimeStateChange(handler: (state: 'disconnected' | 'connecting' | 'connected') => void): () => void;
916
+ /**
917
+ * 에러 콜백 등록
918
+ */
919
+ onRealtimeError(handler: (error: Error) => void): () => void;
920
+ private setRealtimeState;
921
+ private doRealtimeConnect;
922
+ /**
923
+ * 서버에 subscribe 메시지를 보내고 서버 subscription_id를 반환하는 Promise
924
+ */
925
+ private sendSubscribeRequest;
926
+ /**
927
+ * 재연결 후 모든 활성 구독을 서버에 다시 등록
928
+ */
929
+ private resubscribeAll;
930
+ private handleRealtimeMessage;
931
+ private attemptRealtimeReconnect;
932
+ private startRealtimePing;
933
+ private stopRealtimePing;
934
+ private sendRealtimeMessage;
935
+ private generateRequestId;
936
+ private debugLog;
749
937
  }
750
938
 
751
939
  interface FileItem {
@@ -4798,4 +4986,4 @@ declare class ConnectBase {
4798
4986
  updateConfig(config: Partial<ConnectBaseConfig>): void;
4799
4987
  }
4800
4988
 
4801
- export { type AdReportResponse, type AdReportSummary, AdsAPI, type AggregateResult, type AggregateStage, ApiError, type ApiKeyItem, type AppStatsResponse, type AtomicOperator, type AtomicOperatorType, AuthError, type AuthSettingsResponse, type BackupInfo, type BatchOperation, type BatchSetPageMetaRequest, type BillingCycle, type BillingKeyResponse, type BiometricInfo, type BiometricResult, type BulkCreateResponse, type BulkError, type CPUInfo, type CancelPaymentRequest, type CancelPaymentResponse, type CancelSubscriptionRequest, type CategoryInfo, type Channel, type ChannelMembership, type ChargeWithBillingKeyRequest, type ChargeWithBillingKeyResponse, type ChatMessage, type ClientMessage, type ColumnSchema, type CommentListResponse, type CompleteUploadRequest, type CompleteUploadResponse, type ConfirmBillingKeyRequest, type ConfirmPaymentRequest, type ConfirmPaymentResponse, ConnectBase, type ConnectBaseConfig, type ConnectedData, type ConnectionState, type CreateApiKeyRequest, type CreateApiKeyResponse, type CreateBackupRequest, type CreateChannelRequest, type CreateColumnRequest, type CreateDataRequest, type CreateFolderRequest, type CreateFolderResponse, type CreateIndexRequest, type CreateLobbyRequest, type CreatePlaylistRequest, type CreateRelationRequest, type CreateSecurityRuleRequest, type CreateSubscriptionRequest, type CreateTableRequest, type CreateTriggerRequest, type DailyReport, type DataItem, type DataType, type DeleteWhereResponse, type DeviceInfo, type EnabledProviderInfo, type EnabledProvidersResponse, type ErrorHandler, type ErrorMessage, type ErrorReport, type ErrorTrackerConfig, type ErrorType, type FetchApiKeysResponse, type FetchDataResponse, type FetchFilesResponse, type FileItem, type FileStats, GameAPI, type GameAction, type GameClientConfig, type GameConnectionState, type GameConnectionStatus, type GameDelta, type GameEventHandlers, type GamePlayer, GameRoom, type GameRoomConfig, type GameRoomInfo, GameRoomTransport, type GameServerMessage, type GameServerMessageType, type GameState, type GameTransportConfig, type GenerateUploadURLByPathRequest, type GenerateUploadURLRequest, type GenerateUploadURLResponse, type GeoNear, type GeoPoint, type GeoPolygon, type GeoQuery, type GeoResponse, type GeoResult, type GeoWithin, type GetAuthorizationURLResponse, type GetFileByPathResponse, type GoogleConnectionStatus, type GuestMemberSignInResponse, type HistoryResponse, type ICEServer, type ICEServersResponse, type ImageResult, type IndexAnalysis, type IndexRecommendation, type InitUploadResponse, type InvokeFunctionRequest, type InvokeFunctionResponse, type IssueBillingKeyRequest, type IssueBillingKeyResponse, type JoinQueueRequest, type JoinRoomRequest, type JoinRoomResponse, type ListBillingKeysResponse, type ListPageMetasResponse, type ListSubscriptionPaymentsRequest, type ListSubscriptionPaymentsResponse, type ListSubscriptionsRequest, type ListSubscriptionsResponse, type LobbyInfo, type LobbyInvite, type LobbyMember, type LobbyVisibility, type MatchmakingTicket, type MemberSignInRequest, type MemberSignInResponse, type MemberSignUpRequest, type MemberSignUpResponse, type MembershipTier, type MemoryInfo, type MessageHandler, type MoveFileRequest, NativeAPI, type OAuthCallbackResponse, type OAuthProvider, type OpenDialogOptions, type OpenDialogResult, type PageMetaResponse, type PauseSubscriptionRequest, type PaymentDetail, type PaymentStatus, type PeerInfo, type Platform, type PlayerEvent, type Playlist, type PlaylistItem, type PongMessage, type PopulateOption, type Position, type PreparePaymentRequest, type PreparePaymentResponse, type PushPlatform, type QualityProgress, type QueryOptions, type RealtimeConnectOptions, type RealtimeMessage, type RegisterDeviceRequest, type RelationType, type RenameFileRequest, type RenameFileResponse, type RetentionPolicy, type RoomInfo, type RoomStats, type RoomsResponse, type SaveDialogOptions, type SaveDialogResult, type SearchOptions, type SearchResponse, type SearchResult, type SecurityRule, type SendOptions, type ServerMessage, type SetPageMetaRequest, type Shorts, type ShortsListResponse, type SignalingMessage, type SignalingMessageType, type SlowQueryInfo, type StateChange, type StateChangeHandler, type StreamDoneCallback, type StreamDoneData, type StreamErrorCallback, type StreamHandlers, type StreamMessage, type StreamOptions, type StreamSession, type StreamTokenCallback, type StreamURLResponse, type SubscribeOptions, type SubscribeTopicRequest, type SubscribedData, type Subscription, type SubscriptionPaymentResponse, type SubscriptionPaymentStatus, type SubscriptionResponse, type SubscriptionStatus, type SuperChat, type SystemInfo, type TTLConfig, type TableIndex, type TableRelation, type TableSchema, type TransactionRead, type TransactionWrite, type TranscodeStatus, type TransportType, type Trigger, type TriggerEvent, type TriggerHandlerType, type UpdateApiKeyRequest, type UpdateApiKeyResponse, type UpdateBillingKeyRequest, type UpdateChannelRequest, type UpdateColumnRequest, type UpdateDataRequest, type UpdateLobbyRequest, type UpdateSecurityRuleRequest, type UpdateSubscriptionRequest, type UpdateTriggerRequest, type UpdateVideoRequest, type UploadByPathOptions, type UploadFileResponse, type UploadOptions, type UploadProgress, type VAPIDPublicKeyResponse, type ValidateResponse, type Video, type VideoComment, type VideoListOptions, type VideoListResponse, VideoProcessingError, type VideoQuality, type VideoStatus, type VideoVisibility, type WaitOptions, type WatchHistoryItem, type WebPushSubscription, type WebRTCConnectOptions, type WebRTCConnectionState, type WebRTCMode, type WhereCondition, type WhereOperator, ConnectBase as default, isWebTransportSupported };
4989
+ export { type AdReportResponse, type AdReportSummary, AdsAPI, type AggregateResult, type AggregateStage, ApiError, type ApiKeyItem, type AppStatsResponse, type AtomicOperator, type AtomicOperatorType, AuthError, type AuthSettingsResponse, type BackupInfo, type BatchOperation, type BatchSetPageMetaRequest, type BillingCycle, type BillingKeyResponse, type BiometricInfo, type BiometricResult, type BulkCreateResponse, type BulkError, type CPUInfo, type CancelPaymentRequest, type CancelPaymentResponse, type CancelSubscriptionRequest, type CategoryInfo, type Channel, type ChannelMembership, type ChargeWithBillingKeyRequest, type ChargeWithBillingKeyResponse, type ChatMessage, type ClientMessage, type ColumnSchema, type CommentListResponse, type CompleteUploadRequest, type CompleteUploadResponse, type ConfirmBillingKeyRequest, type ConfirmPaymentRequest, type ConfirmPaymentResponse, ConnectBase, type ConnectBaseConfig, type ConnectedData, type ConnectionState, type CreateApiKeyRequest, type CreateApiKeyResponse, type CreateBackupRequest, type CreateChannelRequest, type CreateColumnRequest, type CreateDataRequest, type CreateFolderRequest, type CreateFolderResponse, type CreateIndexRequest, type CreateLobbyRequest, type CreatePlaylistRequest, type CreateRelationRequest, type CreateSecurityRuleRequest, type CreateSubscriptionRequest, type CreateTableRequest, type CreateTriggerRequest, type DailyReport, type DataItem, type DataType, type DatabaseChange, type DatabaseChangeMessage, type DatabaseChangeType, type DatabasePresenceState, type DatabaseRealtimeConnectOptions, type DatabaseRealtimeFilter, type DatabaseRealtimeHandlers, type DatabaseRealtimeSubscription, type DatabaseSnapshot, type DatabaseSnapshotMessage, type DatabaseSubscribeOptions, type DeleteWhereResponse, type DeviceInfo, type EnabledProviderInfo, type EnabledProvidersResponse, type ErrorHandler, type ErrorMessage, type ErrorReport, type ErrorTrackerConfig, type ErrorType, type FetchApiKeysResponse, type FetchDataResponse, type FetchFilesResponse, type FileItem, type FileStats, GameAPI, type GameAction, type GameClientConfig, type GameConnectionState, type GameConnectionStatus, type GameDelta, type GameEventHandlers, type GamePlayer, GameRoom, type GameRoomConfig, type GameRoomInfo, GameRoomTransport, type GameServerMessage, type GameServerMessageType, type GameState, type GameTransportConfig, type GenerateUploadURLByPathRequest, type GenerateUploadURLRequest, type GenerateUploadURLResponse, type GeoNear, type GeoPoint, type GeoPolygon, type GeoQuery, type GeoResponse, type GeoResult, type GeoWithin, type GetAuthorizationURLResponse, type GetFileByPathResponse, type GoogleConnectionStatus, type GuestMemberSignInResponse, type HistoryResponse, type ICEServer, type ICEServersResponse, type ImageResult, type IndexAnalysis, type IndexRecommendation, type InitUploadResponse, type InvokeFunctionRequest, type InvokeFunctionResponse, type IssueBillingKeyRequest, type IssueBillingKeyResponse, type JoinQueueRequest, type JoinRoomRequest, type JoinRoomResponse, type ListBillingKeysResponse, type ListPageMetasResponse, type ListSubscriptionPaymentsRequest, type ListSubscriptionPaymentsResponse, type ListSubscriptionsRequest, type ListSubscriptionsResponse, type LobbyInfo, type LobbyInvite, type LobbyMember, type LobbyVisibility, type MatchmakingTicket, type MemberSignInRequest, type MemberSignInResponse, type MemberSignUpRequest, type MemberSignUpResponse, type MembershipTier, type MemoryInfo, type MessageHandler, type MoveFileRequest, NativeAPI, type OAuthCallbackResponse, type OAuthProvider, type OpenDialogOptions, type OpenDialogResult, type PageMetaResponse, type PauseSubscriptionRequest, type PaymentDetail, type PaymentStatus, type PeerInfo, type Platform, type PlayerEvent, type Playlist, type PlaylistItem, type PongMessage, type PopulateOption, type Position, type PreparePaymentRequest, type PreparePaymentResponse, type PushPlatform, type QualityProgress, type QueryOptions, type RealtimeConnectOptions, type RealtimeMessage, type RegisterDeviceRequest, type RelationType, type RenameFileRequest, type RenameFileResponse, type RetentionPolicy, type RoomInfo, type RoomStats, type RoomsResponse, type SaveDialogOptions, type SaveDialogResult, type SearchOptions, type SearchResponse, type SearchResult, type SecurityRule, type SendOptions, type ServerMessage, type SetPageMetaRequest, type Shorts, type ShortsListResponse, type SignalingMessage, type SignalingMessageType, type SlowQueryInfo, type StateChange, type StateChangeHandler, type StreamDoneCallback, type StreamDoneData, type StreamErrorCallback, type StreamHandlers, type StreamMessage, type StreamOptions, type StreamSession, type StreamTokenCallback, type StreamURLResponse, type SubscribeOptions, type SubscribeTopicRequest, type SubscribedData, type Subscription, type SubscriptionPaymentResponse, type SubscriptionPaymentStatus, type SubscriptionResponse, type SubscriptionStatus, type SuperChat, type SystemInfo, type TTLConfig, type TableIndex, type TableRelation, type TableSchema, type TransactionRead, type TransactionWrite, type TranscodeStatus, type TransportType, type Trigger, type TriggerEvent, type TriggerHandlerType, type UpdateApiKeyRequest, type UpdateApiKeyResponse, type UpdateBillingKeyRequest, type UpdateChannelRequest, type UpdateColumnRequest, type UpdateDataRequest, type UpdateLobbyRequest, type UpdateSecurityRuleRequest, type UpdateSubscriptionRequest, type UpdateTriggerRequest, type UpdateVideoRequest, type UploadByPathOptions, type UploadFileResponse, type UploadOptions, type UploadProgress, type VAPIDPublicKeyResponse, type ValidateResponse, type Video, type VideoComment, type VideoListOptions, type VideoListResponse, VideoProcessingError, type VideoQuality, type VideoStatus, type VideoVisibility, type WaitOptions, type WatchHistoryItem, type WebPushSubscription, type WebRTCConnectOptions, type WebRTCConnectionState, type WebRTCMode, type WhereCondition, type WhereOperator, ConnectBase as default, isWebTransportSupported };
package/dist/index.d.ts CHANGED
@@ -544,6 +544,97 @@ interface RetentionPolicy {
544
544
  schedule?: string;
545
545
  enabled: boolean;
546
546
  }
547
+ /** 데이터베이스 실시간 구독 변경 타입 */
548
+ type DatabaseChangeType = 'added' | 'modified' | 'removed';
549
+ /** 데이터베이스 실시간 변경 이벤트 */
550
+ interface DatabaseChange {
551
+ type: DatabaseChangeType;
552
+ doc_id: string;
553
+ data?: Record<string, unknown>;
554
+ old_data?: Record<string, unknown>;
555
+ metadata?: {
556
+ has_pending_writes: boolean;
557
+ updated_at: string;
558
+ };
559
+ }
560
+ /** 데이터베이스 실시간 스냅샷 */
561
+ interface DatabaseSnapshot {
562
+ id: string;
563
+ data: Record<string, unknown> | null;
564
+ exists: boolean;
565
+ metadata?: {
566
+ updated_at: string;
567
+ };
568
+ }
569
+ /** 데이터베이스 실시간 구독 옵션 */
570
+ interface DatabaseSubscribeOptions {
571
+ /** 특정 문서 ID만 구독 */
572
+ docId?: string;
573
+ /** 쿼리 필터 조건 */
574
+ where?: DatabaseRealtimeFilter[];
575
+ /** true면 자기 변경도 수신 (기본: false) */
576
+ includeSelf?: boolean;
577
+ /** 메타데이터 변경도 수신 (기본: false) */
578
+ includeMetadataChanges?: boolean;
579
+ }
580
+ /** 데이터베이스 실시간 필터 조건 */
581
+ interface DatabaseRealtimeFilter {
582
+ field: string;
583
+ operator: '==' | '!=' | '>' | '>=' | '<' | '<=' | 'in';
584
+ value: unknown;
585
+ }
586
+ /** 데이터베이스 실시간 스냅샷 메시지 */
587
+ interface DatabaseSnapshotMessage {
588
+ subscription_id: string;
589
+ docs: DatabaseSnapshot[];
590
+ total_count: number;
591
+ has_more: boolean;
592
+ }
593
+ /** 데이터베이스 실시간 변경 메시지 */
594
+ interface DatabaseChangeMessage {
595
+ subscription_id: string;
596
+ changes: DatabaseChange[];
597
+ }
598
+ /** 데이터베이스 실시간 구독 핸들러 */
599
+ interface DatabaseRealtimeHandlers {
600
+ /** 초기 스냅샷 수신 시 */
601
+ onSnapshot?: (docs: DatabaseSnapshot[], info: {
602
+ totalCount: number;
603
+ hasMore: boolean;
604
+ }) => void;
605
+ /** 변경 이벤트 수신 시 */
606
+ onChange?: (changes: DatabaseChange[]) => void;
607
+ /** 에러 발생 시 */
608
+ onError?: (error: Error) => void;
609
+ }
610
+ /** 데이터베이스 실시간 구독 객체 */
611
+ interface DatabaseRealtimeSubscription {
612
+ /** 구독 ID */
613
+ subscriptionId: string;
614
+ /** 구독 해제 */
615
+ unsubscribe(): void;
616
+ }
617
+ /** 데이터베이스 실시간 연결 옵션 */
618
+ interface DatabaseRealtimeConnectOptions {
619
+ /** JWT 액세스 토큰 (필수) */
620
+ accessToken: string;
621
+ /** data-server URL (기본: baseUrl) */
622
+ dataServerUrl?: string;
623
+ /** 자동 재연결 최대 시도 (기본: 5) */
624
+ maxRetries?: number;
625
+ /** 재연결 간격 밀리초 (기본: 1000) */
626
+ retryInterval?: number;
627
+ /** 디버그 로깅 (기본: false) */
628
+ debug?: boolean;
629
+ }
630
+ /** 데이터베이스 실시간 프레즌스 상태 */
631
+ interface DatabasePresenceState {
632
+ user_id: string;
633
+ status: 'online' | 'away' | 'offline';
634
+ last_seen: string;
635
+ device?: string;
636
+ metadata?: Record<string, unknown>;
637
+ }
547
638
  interface CreateBackupRequest {
548
639
  /** 백업 이름 */
549
640
  name?: string;
@@ -565,6 +656,16 @@ interface BackupInfo {
565
656
 
566
657
  declare class DatabaseAPI {
567
658
  private http;
659
+ private realtimeWs;
660
+ private realtimeState;
661
+ private realtimeHandlers;
662
+ private realtimeRetryCount;
663
+ private realtimeOptions;
664
+ private pendingRequests;
665
+ private pingInterval;
666
+ private realtimeOnStateChange;
667
+ private realtimeOnError;
668
+ private activeSubscriptions;
568
669
  constructor(http: HttpClient);
569
670
  /**
570
671
  * API Key 인증 시 /v1/public 접두사 반환
@@ -746,6 +847,93 @@ declare class DatabaseAPI {
746
847
  * 보관 정책 조회
747
848
  */
748
849
  getRetentionPolicy(appId: string, tableName: string): Promise<RetentionPolicy>;
850
+ /**
851
+ * 데이터베이스 실시간 연결
852
+ * data-server의 WebSocket에 연결하여 데이터 변경을 실시간으로 수신합니다.
853
+ *
854
+ * @example
855
+ * ```typescript
856
+ * // 연결
857
+ * cb.database.connectRealtime({
858
+ * accessToken: 'your-jwt-token',
859
+ * dataServerUrl: 'https://data.connectbase.world'
860
+ * })
861
+ *
862
+ * // 테이블 구독
863
+ * const sub = cb.database.subscribe('users', {
864
+ * onSnapshot: (docs, info) => {
865
+ * console.log('Initial data:', docs, 'total:', info.totalCount)
866
+ * },
867
+ * onChange: (changes) => {
868
+ * changes.forEach(change => {
869
+ * console.log(change.type, change.doc_id, change.data)
870
+ * })
871
+ * },
872
+ * onError: (error) => console.error(error)
873
+ * })
874
+ *
875
+ * // 구독 해제
876
+ * sub.unsubscribe()
877
+ *
878
+ * // 연결 해제
879
+ * cb.database.disconnectRealtime()
880
+ * ```
881
+ */
882
+ connectRealtime(options: DatabaseRealtimeConnectOptions): Promise<void>;
883
+ /**
884
+ * 데이터베이스 실시간 연결 해제
885
+ */
886
+ disconnectRealtime(): void;
887
+ /**
888
+ * 테이블 또는 문서의 실시간 변경 구독
889
+ *
890
+ * @param tableId 구독할 테이블 이름
891
+ * @param handlers 이벤트 핸들러 (onSnapshot, onChange, onError)
892
+ * @param options 구독 옵션 (docId, where, includeSelf 등)
893
+ * @returns 구독 해제 가능한 객체
894
+ */
895
+ subscribe(tableId: string, handlers: DatabaseRealtimeHandlers, options?: DatabaseSubscribeOptions): DatabaseRealtimeSubscription;
896
+ /**
897
+ * 프레즌스 상태 설정
898
+ */
899
+ setPresence(status: string, device?: string, metadata?: Record<string, unknown>): void;
900
+ /**
901
+ * 프레즌스 구독 (다른 사용자의 온라인 상태 감시)
902
+ */
903
+ subscribePresence(userIds: string[], onPresence: (states: Record<string, DatabasePresenceState>) => void): void;
904
+ /**
905
+ * 실시간 연결 상태 확인
906
+ */
907
+ isRealtimeConnected(): boolean;
908
+ /**
909
+ * 실시간 연결 상태 반환
910
+ */
911
+ getRealtimeState(): 'disconnected' | 'connecting' | 'connected';
912
+ /**
913
+ * 상태 변경 콜백 등록
914
+ */
915
+ onRealtimeStateChange(handler: (state: 'disconnected' | 'connecting' | 'connected') => void): () => void;
916
+ /**
917
+ * 에러 콜백 등록
918
+ */
919
+ onRealtimeError(handler: (error: Error) => void): () => void;
920
+ private setRealtimeState;
921
+ private doRealtimeConnect;
922
+ /**
923
+ * 서버에 subscribe 메시지를 보내고 서버 subscription_id를 반환하는 Promise
924
+ */
925
+ private sendSubscribeRequest;
926
+ /**
927
+ * 재연결 후 모든 활성 구독을 서버에 다시 등록
928
+ */
929
+ private resubscribeAll;
930
+ private handleRealtimeMessage;
931
+ private attemptRealtimeReconnect;
932
+ private startRealtimePing;
933
+ private stopRealtimePing;
934
+ private sendRealtimeMessage;
935
+ private generateRequestId;
936
+ private debugLog;
749
937
  }
750
938
 
751
939
  interface FileItem {
@@ -4798,4 +4986,4 @@ declare class ConnectBase {
4798
4986
  updateConfig(config: Partial<ConnectBaseConfig>): void;
4799
4987
  }
4800
4988
 
4801
- export { type AdReportResponse, type AdReportSummary, AdsAPI, type AggregateResult, type AggregateStage, ApiError, type ApiKeyItem, type AppStatsResponse, type AtomicOperator, type AtomicOperatorType, AuthError, type AuthSettingsResponse, type BackupInfo, type BatchOperation, type BatchSetPageMetaRequest, type BillingCycle, type BillingKeyResponse, type BiometricInfo, type BiometricResult, type BulkCreateResponse, type BulkError, type CPUInfo, type CancelPaymentRequest, type CancelPaymentResponse, type CancelSubscriptionRequest, type CategoryInfo, type Channel, type ChannelMembership, type ChargeWithBillingKeyRequest, type ChargeWithBillingKeyResponse, type ChatMessage, type ClientMessage, type ColumnSchema, type CommentListResponse, type CompleteUploadRequest, type CompleteUploadResponse, type ConfirmBillingKeyRequest, type ConfirmPaymentRequest, type ConfirmPaymentResponse, ConnectBase, type ConnectBaseConfig, type ConnectedData, type ConnectionState, type CreateApiKeyRequest, type CreateApiKeyResponse, type CreateBackupRequest, type CreateChannelRequest, type CreateColumnRequest, type CreateDataRequest, type CreateFolderRequest, type CreateFolderResponse, type CreateIndexRequest, type CreateLobbyRequest, type CreatePlaylistRequest, type CreateRelationRequest, type CreateSecurityRuleRequest, type CreateSubscriptionRequest, type CreateTableRequest, type CreateTriggerRequest, type DailyReport, type DataItem, type DataType, type DeleteWhereResponse, type DeviceInfo, type EnabledProviderInfo, type EnabledProvidersResponse, type ErrorHandler, type ErrorMessage, type ErrorReport, type ErrorTrackerConfig, type ErrorType, type FetchApiKeysResponse, type FetchDataResponse, type FetchFilesResponse, type FileItem, type FileStats, GameAPI, type GameAction, type GameClientConfig, type GameConnectionState, type GameConnectionStatus, type GameDelta, type GameEventHandlers, type GamePlayer, GameRoom, type GameRoomConfig, type GameRoomInfo, GameRoomTransport, type GameServerMessage, type GameServerMessageType, type GameState, type GameTransportConfig, type GenerateUploadURLByPathRequest, type GenerateUploadURLRequest, type GenerateUploadURLResponse, type GeoNear, type GeoPoint, type GeoPolygon, type GeoQuery, type GeoResponse, type GeoResult, type GeoWithin, type GetAuthorizationURLResponse, type GetFileByPathResponse, type GoogleConnectionStatus, type GuestMemberSignInResponse, type HistoryResponse, type ICEServer, type ICEServersResponse, type ImageResult, type IndexAnalysis, type IndexRecommendation, type InitUploadResponse, type InvokeFunctionRequest, type InvokeFunctionResponse, type IssueBillingKeyRequest, type IssueBillingKeyResponse, type JoinQueueRequest, type JoinRoomRequest, type JoinRoomResponse, type ListBillingKeysResponse, type ListPageMetasResponse, type ListSubscriptionPaymentsRequest, type ListSubscriptionPaymentsResponse, type ListSubscriptionsRequest, type ListSubscriptionsResponse, type LobbyInfo, type LobbyInvite, type LobbyMember, type LobbyVisibility, type MatchmakingTicket, type MemberSignInRequest, type MemberSignInResponse, type MemberSignUpRequest, type MemberSignUpResponse, type MembershipTier, type MemoryInfo, type MessageHandler, type MoveFileRequest, NativeAPI, type OAuthCallbackResponse, type OAuthProvider, type OpenDialogOptions, type OpenDialogResult, type PageMetaResponse, type PauseSubscriptionRequest, type PaymentDetail, type PaymentStatus, type PeerInfo, type Platform, type PlayerEvent, type Playlist, type PlaylistItem, type PongMessage, type PopulateOption, type Position, type PreparePaymentRequest, type PreparePaymentResponse, type PushPlatform, type QualityProgress, type QueryOptions, type RealtimeConnectOptions, type RealtimeMessage, type RegisterDeviceRequest, type RelationType, type RenameFileRequest, type RenameFileResponse, type RetentionPolicy, type RoomInfo, type RoomStats, type RoomsResponse, type SaveDialogOptions, type SaveDialogResult, type SearchOptions, type SearchResponse, type SearchResult, type SecurityRule, type SendOptions, type ServerMessage, type SetPageMetaRequest, type Shorts, type ShortsListResponse, type SignalingMessage, type SignalingMessageType, type SlowQueryInfo, type StateChange, type StateChangeHandler, type StreamDoneCallback, type StreamDoneData, type StreamErrorCallback, type StreamHandlers, type StreamMessage, type StreamOptions, type StreamSession, type StreamTokenCallback, type StreamURLResponse, type SubscribeOptions, type SubscribeTopicRequest, type SubscribedData, type Subscription, type SubscriptionPaymentResponse, type SubscriptionPaymentStatus, type SubscriptionResponse, type SubscriptionStatus, type SuperChat, type SystemInfo, type TTLConfig, type TableIndex, type TableRelation, type TableSchema, type TransactionRead, type TransactionWrite, type TranscodeStatus, type TransportType, type Trigger, type TriggerEvent, type TriggerHandlerType, type UpdateApiKeyRequest, type UpdateApiKeyResponse, type UpdateBillingKeyRequest, type UpdateChannelRequest, type UpdateColumnRequest, type UpdateDataRequest, type UpdateLobbyRequest, type UpdateSecurityRuleRequest, type UpdateSubscriptionRequest, type UpdateTriggerRequest, type UpdateVideoRequest, type UploadByPathOptions, type UploadFileResponse, type UploadOptions, type UploadProgress, type VAPIDPublicKeyResponse, type ValidateResponse, type Video, type VideoComment, type VideoListOptions, type VideoListResponse, VideoProcessingError, type VideoQuality, type VideoStatus, type VideoVisibility, type WaitOptions, type WatchHistoryItem, type WebPushSubscription, type WebRTCConnectOptions, type WebRTCConnectionState, type WebRTCMode, type WhereCondition, type WhereOperator, ConnectBase as default, isWebTransportSupported };
4989
+ export { type AdReportResponse, type AdReportSummary, AdsAPI, type AggregateResult, type AggregateStage, ApiError, type ApiKeyItem, type AppStatsResponse, type AtomicOperator, type AtomicOperatorType, AuthError, type AuthSettingsResponse, type BackupInfo, type BatchOperation, type BatchSetPageMetaRequest, type BillingCycle, type BillingKeyResponse, type BiometricInfo, type BiometricResult, type BulkCreateResponse, type BulkError, type CPUInfo, type CancelPaymentRequest, type CancelPaymentResponse, type CancelSubscriptionRequest, type CategoryInfo, type Channel, type ChannelMembership, type ChargeWithBillingKeyRequest, type ChargeWithBillingKeyResponse, type ChatMessage, type ClientMessage, type ColumnSchema, type CommentListResponse, type CompleteUploadRequest, type CompleteUploadResponse, type ConfirmBillingKeyRequest, type ConfirmPaymentRequest, type ConfirmPaymentResponse, ConnectBase, type ConnectBaseConfig, type ConnectedData, type ConnectionState, type CreateApiKeyRequest, type CreateApiKeyResponse, type CreateBackupRequest, type CreateChannelRequest, type CreateColumnRequest, type CreateDataRequest, type CreateFolderRequest, type CreateFolderResponse, type CreateIndexRequest, type CreateLobbyRequest, type CreatePlaylistRequest, type CreateRelationRequest, type CreateSecurityRuleRequest, type CreateSubscriptionRequest, type CreateTableRequest, type CreateTriggerRequest, type DailyReport, type DataItem, type DataType, type DatabaseChange, type DatabaseChangeMessage, type DatabaseChangeType, type DatabasePresenceState, type DatabaseRealtimeConnectOptions, type DatabaseRealtimeFilter, type DatabaseRealtimeHandlers, type DatabaseRealtimeSubscription, type DatabaseSnapshot, type DatabaseSnapshotMessage, type DatabaseSubscribeOptions, type DeleteWhereResponse, type DeviceInfo, type EnabledProviderInfo, type EnabledProvidersResponse, type ErrorHandler, type ErrorMessage, type ErrorReport, type ErrorTrackerConfig, type ErrorType, type FetchApiKeysResponse, type FetchDataResponse, type FetchFilesResponse, type FileItem, type FileStats, GameAPI, type GameAction, type GameClientConfig, type GameConnectionState, type GameConnectionStatus, type GameDelta, type GameEventHandlers, type GamePlayer, GameRoom, type GameRoomConfig, type GameRoomInfo, GameRoomTransport, type GameServerMessage, type GameServerMessageType, type GameState, type GameTransportConfig, type GenerateUploadURLByPathRequest, type GenerateUploadURLRequest, type GenerateUploadURLResponse, type GeoNear, type GeoPoint, type GeoPolygon, type GeoQuery, type GeoResponse, type GeoResult, type GeoWithin, type GetAuthorizationURLResponse, type GetFileByPathResponse, type GoogleConnectionStatus, type GuestMemberSignInResponse, type HistoryResponse, type ICEServer, type ICEServersResponse, type ImageResult, type IndexAnalysis, type IndexRecommendation, type InitUploadResponse, type InvokeFunctionRequest, type InvokeFunctionResponse, type IssueBillingKeyRequest, type IssueBillingKeyResponse, type JoinQueueRequest, type JoinRoomRequest, type JoinRoomResponse, type ListBillingKeysResponse, type ListPageMetasResponse, type ListSubscriptionPaymentsRequest, type ListSubscriptionPaymentsResponse, type ListSubscriptionsRequest, type ListSubscriptionsResponse, type LobbyInfo, type LobbyInvite, type LobbyMember, type LobbyVisibility, type MatchmakingTicket, type MemberSignInRequest, type MemberSignInResponse, type MemberSignUpRequest, type MemberSignUpResponse, type MembershipTier, type MemoryInfo, type MessageHandler, type MoveFileRequest, NativeAPI, type OAuthCallbackResponse, type OAuthProvider, type OpenDialogOptions, type OpenDialogResult, type PageMetaResponse, type PauseSubscriptionRequest, type PaymentDetail, type PaymentStatus, type PeerInfo, type Platform, type PlayerEvent, type Playlist, type PlaylistItem, type PongMessage, type PopulateOption, type Position, type PreparePaymentRequest, type PreparePaymentResponse, type PushPlatform, type QualityProgress, type QueryOptions, type RealtimeConnectOptions, type RealtimeMessage, type RegisterDeviceRequest, type RelationType, type RenameFileRequest, type RenameFileResponse, type RetentionPolicy, type RoomInfo, type RoomStats, type RoomsResponse, type SaveDialogOptions, type SaveDialogResult, type SearchOptions, type SearchResponse, type SearchResult, type SecurityRule, type SendOptions, type ServerMessage, type SetPageMetaRequest, type Shorts, type ShortsListResponse, type SignalingMessage, type SignalingMessageType, type SlowQueryInfo, type StateChange, type StateChangeHandler, type StreamDoneCallback, type StreamDoneData, type StreamErrorCallback, type StreamHandlers, type StreamMessage, type StreamOptions, type StreamSession, type StreamTokenCallback, type StreamURLResponse, type SubscribeOptions, type SubscribeTopicRequest, type SubscribedData, type Subscription, type SubscriptionPaymentResponse, type SubscriptionPaymentStatus, type SubscriptionResponse, type SubscriptionStatus, type SuperChat, type SystemInfo, type TTLConfig, type TableIndex, type TableRelation, type TableSchema, type TransactionRead, type TransactionWrite, type TranscodeStatus, type TransportType, type Trigger, type TriggerEvent, type TriggerHandlerType, type UpdateApiKeyRequest, type UpdateApiKeyResponse, type UpdateBillingKeyRequest, type UpdateChannelRequest, type UpdateColumnRequest, type UpdateDataRequest, type UpdateLobbyRequest, type UpdateSecurityRuleRequest, type UpdateSubscriptionRequest, type UpdateTriggerRequest, type UpdateVideoRequest, type UploadByPathOptions, type UploadFileResponse, type UploadOptions, type UploadProgress, type VAPIDPublicKeyResponse, type ValidateResponse, type Video, type VideoComment, type VideoListOptions, type VideoListResponse, VideoProcessingError, type VideoQuality, type VideoStatus, type VideoVisibility, type WaitOptions, type WatchHistoryItem, type WebPushSubscription, type WebRTCConnectOptions, type WebRTCConnectionState, type WebRTCMode, type WhereCondition, type WhereOperator, ConnectBase as default, isWebTransportSupported };