@blinkdotnew/dev-sdk 2.3.2 → 2.3.4-dev.1

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
@@ -946,6 +946,10 @@ declare class HttpClient {
946
946
  dbPost<T = any>(table: string, body: any, options?: {
947
947
  returning?: boolean;
948
948
  }): Promise<BlinkResponse<T | T[]>>;
949
+ dbUpsert<T = any>(table: string, body: any, options?: {
950
+ onConflict?: string;
951
+ returning?: boolean;
952
+ }): Promise<BlinkResponse<T | T[]>>;
949
953
  dbPatch<T = any>(table: string, body: any, searchParams?: Record<string, string>, options?: {
950
954
  returning?: boolean;
951
955
  }): Promise<BlinkResponse<T[]>>;
@@ -3488,27 +3492,93 @@ declare class BlinkAIImpl implements BlinkAI {
3488
3492
  }
3489
3493
 
3490
3494
  /**
3491
- * Blink Realtime Module - Real-time messaging and presence
3492
- * Provides pub/sub messaging, presence tracking, and live updates
3495
+ * Blink Realtime Connection - Single WebSocket connection manager
3496
+ * Handles connection lifecycle, message routing, and reconnection for all channels
3493
3497
  */
3494
3498
 
3495
- declare class BlinkRealtimeChannel implements RealtimeChannel {
3496
- private channelName;
3499
+ interface ChannelHandler {
3500
+ onMessage: (message: any) => void;
3501
+ onPresence: (users: any[]) => void;
3502
+ onSubscribed: () => void;
3503
+ onError: (error: string) => void;
3504
+ }
3505
+ declare class RealtimeConnection {
3497
3506
  private httpClient;
3498
3507
  private projectId;
3499
- private messageCallbacks;
3500
- private presenceCallbacks;
3501
3508
  private websocket;
3502
- private isSubscribed;
3503
3509
  private isConnected;
3504
3510
  private isConnecting;
3505
3511
  private reconnectTimer;
3506
3512
  private heartbeatTimer;
3507
3513
  private reconnectAttempts;
3508
- private messageQueue;
3509
- private pendingSubscription;
3510
3514
  private connectionPromise;
3511
- constructor(channelName: string, httpClient: HttpClient, projectId: string);
3515
+ private channels;
3516
+ private pendingSubscriptions;
3517
+ private messageQueue;
3518
+ constructor(httpClient: HttpClient, projectId: string);
3519
+ /**
3520
+ * Check if connection is ready
3521
+ */
3522
+ isReady(): boolean;
3523
+ /**
3524
+ * Ensure WebSocket connection is established
3525
+ */
3526
+ connect(): Promise<void>;
3527
+ /**
3528
+ * Join a channel (subscribe)
3529
+ */
3530
+ joinChannel(channelName: string, handler: ChannelHandler, options?: {
3531
+ userId?: string;
3532
+ metadata?: Record<string, any>;
3533
+ }): Promise<void>;
3534
+ /**
3535
+ * Leave a channel (unsubscribe)
3536
+ */
3537
+ leaveChannel(channelName: string): Promise<void>;
3538
+ /**
3539
+ * Send a message to a channel
3540
+ */
3541
+ send(channelName: string, type: string, data: any, options?: {
3542
+ userId?: string;
3543
+ metadata?: Record<string, any>;
3544
+ }): Promise<string>;
3545
+ /**
3546
+ * Disconnect and cleanup
3547
+ */
3548
+ disconnect(): void;
3549
+ /**
3550
+ * Get count of active channels
3551
+ */
3552
+ getChannelCount(): number;
3553
+ private connectWebSocket;
3554
+ private handleMessage;
3555
+ private sendRaw;
3556
+ private sendWithResponse;
3557
+ private flushMessageQueue;
3558
+ private rejectQueuedMessages;
3559
+ private startHeartbeat;
3560
+ private scheduleReconnect;
3561
+ private resubscribeAllChannels;
3562
+ }
3563
+
3564
+ /**
3565
+ * Blink Realtime Module - Real-time messaging and presence
3566
+ * Provides pub/sub messaging, presence tracking, and live updates
3567
+ *
3568
+ * Architecture: Single WebSocket connection per client, multiplexed channels
3569
+ * (Industry standard - matches Supabase, Firebase, Pusher)
3570
+ */
3571
+
3572
+ declare class BlinkRealtimeChannel implements RealtimeChannel {
3573
+ private channelName;
3574
+ private connection;
3575
+ private httpClient;
3576
+ private projectId;
3577
+ private messageCallbacks;
3578
+ private presenceCallbacks;
3579
+ private isSubscribed;
3580
+ private subscribeOptions;
3581
+ constructor(channelName: string, connection: RealtimeConnection, httpClient: HttpClient, projectId: string);
3512
3582
  /**
3513
3583
  * Check if channel is ready for publishing
3514
3584
  */
@@ -3530,35 +3600,12 @@ declare class BlinkRealtimeChannel implements RealtimeChannel {
3530
3600
  before?: string;
3531
3601
  after?: string;
3532
3602
  }): Promise<RealtimeMessage[]>;
3533
- /**
3534
- * Ensure WebSocket connection is established and ready
3535
- */
3536
- private ensureConnected;
3537
- /**
3538
- * Send a message, queuing if socket not ready
3539
- */
3540
- private sendMessage;
3541
- /**
3542
- * Send a queued message and set up response handling
3543
- */
3544
- private sendQueuedMessage;
3545
- /**
3546
- * Flush all queued messages when connection becomes ready
3547
- */
3548
- private flushMessageQueue;
3549
- private connectWebSocket;
3550
- /**
3551
- * Reject all queued messages with the given error
3552
- */
3553
- private rejectQueuedMessages;
3554
- private handleWebSocketMessage;
3555
- private startHeartbeat;
3556
- private scheduleReconnect;
3557
3603
  private cleanup;
3558
3604
  }
3559
3605
  declare class BlinkRealtimeImpl implements BlinkRealtime {
3560
3606
  private httpClient;
3561
3607
  private projectId;
3608
+ private connection;
3562
3609
  private channels;
3563
3610
  private handlers;
3564
3611
  constructor(httpClient: HttpClient, projectId: string);
@@ -3567,6 +3614,14 @@ declare class BlinkRealtimeImpl implements BlinkRealtime {
3567
3614
  publish(channelName: string, type: string, data: any, options?: RealtimePublishOptions): Promise<string>;
3568
3615
  presence(channelName: string): Promise<PresenceUser[]>;
3569
3616
  onPresence(channelName: string, callback: (users: PresenceUser[]) => void): () => void;
3617
+ /**
3618
+ * Get the number of active WebSocket connections (should always be 0 or 1)
3619
+ */
3620
+ getConnectionCount(): number;
3621
+ /**
3622
+ * Get the number of active channels
3623
+ */
3624
+ getChannelCount(): number;
3570
3625
  }
3571
3626
 
3572
3627
  declare class BlinkConnectorsImpl implements BlinkConnectors {
package/dist/index.d.ts CHANGED
@@ -946,6 +946,10 @@ declare class HttpClient {
946
946
  dbPost<T = any>(table: string, body: any, options?: {
947
947
  returning?: boolean;
948
948
  }): Promise<BlinkResponse<T | T[]>>;
949
+ dbUpsert<T = any>(table: string, body: any, options?: {
950
+ onConflict?: string;
951
+ returning?: boolean;
952
+ }): Promise<BlinkResponse<T | T[]>>;
949
953
  dbPatch<T = any>(table: string, body: any, searchParams?: Record<string, string>, options?: {
950
954
  returning?: boolean;
951
955
  }): Promise<BlinkResponse<T[]>>;
@@ -3488,27 +3492,93 @@ declare class BlinkAIImpl implements BlinkAI {
3488
3492
  }
3489
3493
 
3490
3494
  /**
3491
- * Blink Realtime Module - Real-time messaging and presence
3492
- * Provides pub/sub messaging, presence tracking, and live updates
3495
+ * Blink Realtime Connection - Single WebSocket connection manager
3496
+ * Handles connection lifecycle, message routing, and reconnection for all channels
3493
3497
  */
3494
3498
 
3495
- declare class BlinkRealtimeChannel implements RealtimeChannel {
3496
- private channelName;
3499
+ interface ChannelHandler {
3500
+ onMessage: (message: any) => void;
3501
+ onPresence: (users: any[]) => void;
3502
+ onSubscribed: () => void;
3503
+ onError: (error: string) => void;
3504
+ }
3505
+ declare class RealtimeConnection {
3497
3506
  private httpClient;
3498
3507
  private projectId;
3499
- private messageCallbacks;
3500
- private presenceCallbacks;
3501
3508
  private websocket;
3502
- private isSubscribed;
3503
3509
  private isConnected;
3504
3510
  private isConnecting;
3505
3511
  private reconnectTimer;
3506
3512
  private heartbeatTimer;
3507
3513
  private reconnectAttempts;
3508
- private messageQueue;
3509
- private pendingSubscription;
3510
3514
  private connectionPromise;
3511
- constructor(channelName: string, httpClient: HttpClient, projectId: string);
3515
+ private channels;
3516
+ private pendingSubscriptions;
3517
+ private messageQueue;
3518
+ constructor(httpClient: HttpClient, projectId: string);
3519
+ /**
3520
+ * Check if connection is ready
3521
+ */
3522
+ isReady(): boolean;
3523
+ /**
3524
+ * Ensure WebSocket connection is established
3525
+ */
3526
+ connect(): Promise<void>;
3527
+ /**
3528
+ * Join a channel (subscribe)
3529
+ */
3530
+ joinChannel(channelName: string, handler: ChannelHandler, options?: {
3531
+ userId?: string;
3532
+ metadata?: Record<string, any>;
3533
+ }): Promise<void>;
3534
+ /**
3535
+ * Leave a channel (unsubscribe)
3536
+ */
3537
+ leaveChannel(channelName: string): Promise<void>;
3538
+ /**
3539
+ * Send a message to a channel
3540
+ */
3541
+ send(channelName: string, type: string, data: any, options?: {
3542
+ userId?: string;
3543
+ metadata?: Record<string, any>;
3544
+ }): Promise<string>;
3545
+ /**
3546
+ * Disconnect and cleanup
3547
+ */
3548
+ disconnect(): void;
3549
+ /**
3550
+ * Get count of active channels
3551
+ */
3552
+ getChannelCount(): number;
3553
+ private connectWebSocket;
3554
+ private handleMessage;
3555
+ private sendRaw;
3556
+ private sendWithResponse;
3557
+ private flushMessageQueue;
3558
+ private rejectQueuedMessages;
3559
+ private startHeartbeat;
3560
+ private scheduleReconnect;
3561
+ private resubscribeAllChannels;
3562
+ }
3563
+
3564
+ /**
3565
+ * Blink Realtime Module - Real-time messaging and presence
3566
+ * Provides pub/sub messaging, presence tracking, and live updates
3567
+ *
3568
+ * Architecture: Single WebSocket connection per client, multiplexed channels
3569
+ * (Industry standard - matches Supabase, Firebase, Pusher)
3570
+ */
3571
+
3572
+ declare class BlinkRealtimeChannel implements RealtimeChannel {
3573
+ private channelName;
3574
+ private connection;
3575
+ private httpClient;
3576
+ private projectId;
3577
+ private messageCallbacks;
3578
+ private presenceCallbacks;
3579
+ private isSubscribed;
3580
+ private subscribeOptions;
3581
+ constructor(channelName: string, connection: RealtimeConnection, httpClient: HttpClient, projectId: string);
3512
3582
  /**
3513
3583
  * Check if channel is ready for publishing
3514
3584
  */
@@ -3530,35 +3600,12 @@ declare class BlinkRealtimeChannel implements RealtimeChannel {
3530
3600
  before?: string;
3531
3601
  after?: string;
3532
3602
  }): Promise<RealtimeMessage[]>;
3533
- /**
3534
- * Ensure WebSocket connection is established and ready
3535
- */
3536
- private ensureConnected;
3537
- /**
3538
- * Send a message, queuing if socket not ready
3539
- */
3540
- private sendMessage;
3541
- /**
3542
- * Send a queued message and set up response handling
3543
- */
3544
- private sendQueuedMessage;
3545
- /**
3546
- * Flush all queued messages when connection becomes ready
3547
- */
3548
- private flushMessageQueue;
3549
- private connectWebSocket;
3550
- /**
3551
- * Reject all queued messages with the given error
3552
- */
3553
- private rejectQueuedMessages;
3554
- private handleWebSocketMessage;
3555
- private startHeartbeat;
3556
- private scheduleReconnect;
3557
3603
  private cleanup;
3558
3604
  }
3559
3605
  declare class BlinkRealtimeImpl implements BlinkRealtime {
3560
3606
  private httpClient;
3561
3607
  private projectId;
3608
+ private connection;
3562
3609
  private channels;
3563
3610
  private handlers;
3564
3611
  constructor(httpClient: HttpClient, projectId: string);
@@ -3567,6 +3614,14 @@ declare class BlinkRealtimeImpl implements BlinkRealtime {
3567
3614
  publish(channelName: string, type: string, data: any, options?: RealtimePublishOptions): Promise<string>;
3568
3615
  presence(channelName: string): Promise<PresenceUser[]>;
3569
3616
  onPresence(channelName: string, callback: (users: PresenceUser[]) => void): () => void;
3617
+ /**
3618
+ * Get the number of active WebSocket connections (should always be 0 or 1)
3619
+ */
3620
+ getConnectionCount(): number;
3621
+ /**
3622
+ * Get the number of active channels
3623
+ */
3624
+ getChannelCount(): number;
3570
3625
  }
3571
3626
 
3572
3627
  declare class BlinkConnectorsImpl implements BlinkConnectors {