krisspy-sdk 0.3.0 → 0.3.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 +261 -2
- package/dist/index.d.ts +261 -2
- package/dist/index.js +432 -2
- package/dist/index.mjs +430 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -346,6 +346,31 @@ interface StorageUrlResponse {
|
|
|
346
346
|
/**
|
|
347
347
|
* Storage bucket interface for file operations
|
|
348
348
|
*/
|
|
349
|
+
interface UploadAndLinkOptions {
|
|
350
|
+
/** Table to insert/update the record */
|
|
351
|
+
table: string;
|
|
352
|
+
/** Column name to store the URL (default: 'url') */
|
|
353
|
+
column?: string;
|
|
354
|
+
/** Additional data to insert with the record */
|
|
355
|
+
data?: Record<string, any>;
|
|
356
|
+
/** If provided, update existing record instead of insert */
|
|
357
|
+
recordId?: string;
|
|
358
|
+
/** Content type of the file */
|
|
359
|
+
contentType?: string;
|
|
360
|
+
}
|
|
361
|
+
interface UploadAndLinkResponse {
|
|
362
|
+
data: {
|
|
363
|
+
file: {
|
|
364
|
+
path: string;
|
|
365
|
+
url: string;
|
|
366
|
+
bucket: string;
|
|
367
|
+
contentType: string;
|
|
368
|
+
size: number;
|
|
369
|
+
};
|
|
370
|
+
record: Record<string, any>;
|
|
371
|
+
} | null;
|
|
372
|
+
error: KrisspyError | null;
|
|
373
|
+
}
|
|
349
374
|
declare class StorageBucket {
|
|
350
375
|
private http;
|
|
351
376
|
private backendId;
|
|
@@ -438,6 +463,34 @@ declare class StorageBucket {
|
|
|
438
463
|
* .createSignedUrl('document.pdf', 3600)
|
|
439
464
|
*/
|
|
440
465
|
createSignedUrl(path: string, expiresIn?: number): Promise<StorageUrlResponse>;
|
|
466
|
+
/**
|
|
467
|
+
* Upload a file and link it to a database record in one operation
|
|
468
|
+
*
|
|
469
|
+
* @param path - Path/filename for the file
|
|
470
|
+
* @param file - File data
|
|
471
|
+
* @param options - Link options (table, column, additional data)
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* // Upload image and create new item record
|
|
475
|
+
* const { data, error } = await krisspy.storage
|
|
476
|
+
* .from('media')
|
|
477
|
+
* .uploadAndLink('products/phone.jpg', file, {
|
|
478
|
+
* table: 'items',
|
|
479
|
+
* column: 'image_url',
|
|
480
|
+
* data: { name: 'iPhone', price: 999 }
|
|
481
|
+
* })
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* // Upload avatar and update existing user
|
|
485
|
+
* const { data, error } = await krisspy.storage
|
|
486
|
+
* .from('avatars')
|
|
487
|
+
* .uploadAndLink('user123.jpg', file, {
|
|
488
|
+
* table: 'users',
|
|
489
|
+
* column: 'avatar_url',
|
|
490
|
+
* recordId: 'user123'
|
|
491
|
+
* })
|
|
492
|
+
*/
|
|
493
|
+
uploadAndLink(path: string, file: Blob | File | ArrayBuffer | string, options: UploadAndLinkOptions): Promise<UploadAndLinkResponse>;
|
|
441
494
|
private blobToBase64;
|
|
442
495
|
private arrayBufferToBase64;
|
|
443
496
|
private detectMimeType;
|
|
@@ -489,6 +542,159 @@ declare class KrisspyStorage {
|
|
|
489
542
|
}>;
|
|
490
543
|
}
|
|
491
544
|
|
|
545
|
+
/**
|
|
546
|
+
* Krisspy Realtime - WebSocket subscriptions for real-time data changes
|
|
547
|
+
*
|
|
548
|
+
* Similar to Supabase Realtime, allows subscribing to database changes.
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* // Subscribe to all changes on a table
|
|
552
|
+
* const channel = krisspy.channel('messages-changes')
|
|
553
|
+
* .on('postgres_changes', { event: '*', table: 'messages' }, (payload) => {
|
|
554
|
+
* console.log('Change:', payload)
|
|
555
|
+
* })
|
|
556
|
+
* .subscribe()
|
|
557
|
+
*
|
|
558
|
+
* // Subscribe to INSERT only
|
|
559
|
+
* const channel = krisspy.channel('new-messages')
|
|
560
|
+
* .on('postgres_changes', { event: 'INSERT', table: 'messages' }, (payload) => {
|
|
561
|
+
* console.log('New message:', payload.new)
|
|
562
|
+
* })
|
|
563
|
+
* .subscribe()
|
|
564
|
+
*
|
|
565
|
+
* // Unsubscribe
|
|
566
|
+
* channel.unsubscribe()
|
|
567
|
+
*/
|
|
568
|
+
type RealtimeEvent = 'INSERT' | 'UPDATE' | 'DELETE' | '*';
|
|
569
|
+
interface PostgresChangesConfig {
|
|
570
|
+
event: RealtimeEvent;
|
|
571
|
+
schema?: string;
|
|
572
|
+
table: string;
|
|
573
|
+
filter?: string;
|
|
574
|
+
}
|
|
575
|
+
interface RealtimePayload<T = any> {
|
|
576
|
+
eventType: 'INSERT' | 'UPDATE' | 'DELETE';
|
|
577
|
+
new: T | null;
|
|
578
|
+
old: T | null;
|
|
579
|
+
table: string;
|
|
580
|
+
schema: string;
|
|
581
|
+
commitTimestamp: string;
|
|
582
|
+
}
|
|
583
|
+
type RealtimeCallback<T = any> = (payload: RealtimePayload<T>) => void;
|
|
584
|
+
type ChannelState = 'closed' | 'connecting' | 'connected' | 'error';
|
|
585
|
+
/**
|
|
586
|
+
* Realtime Channel - represents a subscription to database changes
|
|
587
|
+
*/
|
|
588
|
+
declare class RealtimeChannel {
|
|
589
|
+
private name;
|
|
590
|
+
private realtime;
|
|
591
|
+
private subscriptions;
|
|
592
|
+
private _state;
|
|
593
|
+
constructor(name: string, realtime: KrisspyRealtime);
|
|
594
|
+
/**
|
|
595
|
+
* Get channel state
|
|
596
|
+
*/
|
|
597
|
+
get state(): ChannelState;
|
|
598
|
+
/**
|
|
599
|
+
* Subscribe to postgres changes
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* channel.on('postgres_changes', { event: 'INSERT', table: 'messages' }, (payload) => {
|
|
603
|
+
* console.log('New message:', payload.new)
|
|
604
|
+
* })
|
|
605
|
+
*/
|
|
606
|
+
on<T = any>(type: 'postgres_changes', config: PostgresChangesConfig, callback: RealtimeCallback<T>): RealtimeChannel;
|
|
607
|
+
/**
|
|
608
|
+
* Activate the channel and start receiving events
|
|
609
|
+
*/
|
|
610
|
+
subscribe(callback?: (status: ChannelState, error?: Error) => void): RealtimeChannel;
|
|
611
|
+
/**
|
|
612
|
+
* Unsubscribe from the channel
|
|
613
|
+
*/
|
|
614
|
+
unsubscribe(): Promise<void>;
|
|
615
|
+
/**
|
|
616
|
+
* Handle incoming message (called by KrisspyRealtime)
|
|
617
|
+
*/
|
|
618
|
+
handleMessage(payload: RealtimePayload): void;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Krisspy Realtime - manages WebSocket connection and channels
|
|
622
|
+
*/
|
|
623
|
+
declare class KrisspyRealtime {
|
|
624
|
+
private url;
|
|
625
|
+
private backendId;
|
|
626
|
+
private ws;
|
|
627
|
+
private channels;
|
|
628
|
+
private token;
|
|
629
|
+
private reconnectAttempts;
|
|
630
|
+
private maxReconnectAttempts;
|
|
631
|
+
private reconnectDelay;
|
|
632
|
+
private pingInterval;
|
|
633
|
+
private connectionPromise;
|
|
634
|
+
private debug;
|
|
635
|
+
constructor(baseUrl: string, backendId: string, debug?: boolean);
|
|
636
|
+
/**
|
|
637
|
+
* Set auth token for authenticated subscriptions
|
|
638
|
+
*/
|
|
639
|
+
setAuth(token: string | null): void;
|
|
640
|
+
/**
|
|
641
|
+
* Create a new channel
|
|
642
|
+
*/
|
|
643
|
+
channel(name: string): RealtimeChannel;
|
|
644
|
+
/**
|
|
645
|
+
* Connect to WebSocket server
|
|
646
|
+
*/
|
|
647
|
+
connect(): Promise<void>;
|
|
648
|
+
/**
|
|
649
|
+
* Disconnect from WebSocket server
|
|
650
|
+
*/
|
|
651
|
+
disconnect(): void;
|
|
652
|
+
/**
|
|
653
|
+
* Send subscribe message
|
|
654
|
+
*/
|
|
655
|
+
sendSubscribe(channel: string, config: PostgresChangesConfig): void;
|
|
656
|
+
/**
|
|
657
|
+
* Send unsubscribe message
|
|
658
|
+
*/
|
|
659
|
+
sendUnsubscribe(channel: string): void;
|
|
660
|
+
/**
|
|
661
|
+
* Register a channel for receiving messages
|
|
662
|
+
*/
|
|
663
|
+
registerChannel(name: string, channel: RealtimeChannel): void;
|
|
664
|
+
/**
|
|
665
|
+
* Unregister a channel
|
|
666
|
+
*/
|
|
667
|
+
unregisterChannel(name: string): void;
|
|
668
|
+
/**
|
|
669
|
+
* Remove all subscriptions
|
|
670
|
+
*/
|
|
671
|
+
removeAllChannels(): void;
|
|
672
|
+
/**
|
|
673
|
+
* Handle incoming WebSocket message
|
|
674
|
+
*/
|
|
675
|
+
private handleMessage;
|
|
676
|
+
/**
|
|
677
|
+
* Send message to WebSocket server
|
|
678
|
+
*/
|
|
679
|
+
private send;
|
|
680
|
+
/**
|
|
681
|
+
* Start ping interval to keep connection alive
|
|
682
|
+
*/
|
|
683
|
+
private startPing;
|
|
684
|
+
/**
|
|
685
|
+
* Stop ping interval
|
|
686
|
+
*/
|
|
687
|
+
private stopPing;
|
|
688
|
+
/**
|
|
689
|
+
* Attempt to reconnect
|
|
690
|
+
*/
|
|
691
|
+
private reconnect;
|
|
692
|
+
/**
|
|
693
|
+
* Log debug message
|
|
694
|
+
*/
|
|
695
|
+
private log;
|
|
696
|
+
}
|
|
697
|
+
|
|
492
698
|
/**
|
|
493
699
|
* Query Builder - Supabase-style fluent API for database queries
|
|
494
700
|
*/
|
|
@@ -636,9 +842,12 @@ declare class QueryBuilder<T = any> {
|
|
|
636
842
|
declare class KrisspyClient {
|
|
637
843
|
private http;
|
|
638
844
|
private backendId;
|
|
845
|
+
private baseUrl;
|
|
639
846
|
private _auth;
|
|
640
847
|
private _storage;
|
|
848
|
+
private _realtime;
|
|
641
849
|
private useRLS;
|
|
850
|
+
private debug;
|
|
642
851
|
constructor(options: KrisspyClientOptions);
|
|
643
852
|
/**
|
|
644
853
|
* Auth module for user authentication
|
|
@@ -685,6 +894,49 @@ declare class KrisspyClient {
|
|
|
685
894
|
* const { error } = await krisspy.storage.from('uploads').remove(['old.jpg'])
|
|
686
895
|
*/
|
|
687
896
|
get storage(): KrisspyStorage;
|
|
897
|
+
/**
|
|
898
|
+
* Create a realtime channel for subscribing to database changes
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* // Subscribe to all changes on a table
|
|
902
|
+
* const channel = krisspy.channel('messages-changes')
|
|
903
|
+
* .on('postgres_changes', { event: '*', table: 'messages' }, (payload) => {
|
|
904
|
+
* console.log('Change:', payload)
|
|
905
|
+
* })
|
|
906
|
+
* .subscribe()
|
|
907
|
+
*
|
|
908
|
+
* // Subscribe to INSERT only
|
|
909
|
+
* const channel = krisspy.channel('new-messages')
|
|
910
|
+
* .on('postgres_changes', { event: 'INSERT', table: 'messages' }, (payload) => {
|
|
911
|
+
* console.log('New message:', payload.new)
|
|
912
|
+
* })
|
|
913
|
+
* .subscribe()
|
|
914
|
+
*
|
|
915
|
+
* // Subscribe with status callback
|
|
916
|
+
* const channel = krisspy.channel('my-channel')
|
|
917
|
+
* .on('postgres_changes', { event: '*', table: 'items' }, (payload) => {
|
|
918
|
+
* console.log('Item changed:', payload)
|
|
919
|
+
* })
|
|
920
|
+
* .subscribe((status, error) => {
|
|
921
|
+
* if (status === 'connected') {
|
|
922
|
+
* console.log('Connected to realtime!')
|
|
923
|
+
* } else if (status === 'error') {
|
|
924
|
+
* console.error('Connection error:', error)
|
|
925
|
+
* }
|
|
926
|
+
* })
|
|
927
|
+
*
|
|
928
|
+
* // Unsubscribe
|
|
929
|
+
* await channel.unsubscribe()
|
|
930
|
+
*/
|
|
931
|
+
channel(name: string): RealtimeChannel;
|
|
932
|
+
/**
|
|
933
|
+
* Remove all realtime subscriptions
|
|
934
|
+
*/
|
|
935
|
+
removeAllChannels(): void;
|
|
936
|
+
/**
|
|
937
|
+
* Get the realtime instance for advanced usage
|
|
938
|
+
*/
|
|
939
|
+
get realtime(): KrisspyRealtime;
|
|
688
940
|
/**
|
|
689
941
|
* Create a query builder for a table
|
|
690
942
|
*
|
|
@@ -769,7 +1021,7 @@ declare class KrisspyClient {
|
|
|
769
1021
|
/**
|
|
770
1022
|
* @krisspy/sdk - Krisspy Cloud SDK
|
|
771
1023
|
*
|
|
772
|
-
* Database, Auth, Storage, and
|
|
1024
|
+
* Database, Auth, Storage, Functions, and Realtime for your apps.
|
|
773
1025
|
* A simpler alternative to Supabase.
|
|
774
1026
|
*
|
|
775
1027
|
* @example
|
|
@@ -801,6 +1053,13 @@ declare class KrisspyClient {
|
|
|
801
1053
|
*
|
|
802
1054
|
* // Functions
|
|
803
1055
|
* await krisspy.functions.invoke('hello', { body: { name: 'World' } })
|
|
1056
|
+
*
|
|
1057
|
+
* // Realtime
|
|
1058
|
+
* const channel = krisspy.channel('messages')
|
|
1059
|
+
* .on('postgres_changes', { event: '*', table: 'messages' }, (payload) => {
|
|
1060
|
+
* console.log('Change:', payload)
|
|
1061
|
+
* })
|
|
1062
|
+
* .subscribe()
|
|
804
1063
|
*/
|
|
805
1064
|
|
|
806
1065
|
/**
|
|
@@ -818,4 +1077,4 @@ declare class KrisspyClient {
|
|
|
818
1077
|
*/
|
|
819
1078
|
declare function createClient(options: KrisspyClientOptions): KrisspyClient;
|
|
820
1079
|
|
|
821
|
-
export { type AuthChangeEvent, type AuthResponse, type FileObject, type FileUploadOptions, type Filter, type FilterOperator, type FunctionInvokeOptions, type FunctionResponse, HttpClient, KrisspyAuth, KrisspyClient, type KrisspyClientOptions, type KrisspyError, KrisspyStorage, type MutationResponse, type OAuthProvider, type OrderBy, QueryBuilder, type QueryOptions, type QueryResponse, type Session, type SignInCredentials, type SignUpCredentials, type SingleResponse, StorageBucket, type User, createClient };
|
|
1080
|
+
export { type AuthChangeEvent, type AuthResponse, type ChannelState, type FileObject, type FileUploadOptions, type Filter, type FilterOperator, type FunctionInvokeOptions, type FunctionResponse, HttpClient, KrisspyAuth, KrisspyClient, type KrisspyClientOptions, type KrisspyError, KrisspyRealtime, KrisspyStorage, type MutationResponse, type OAuthProvider, type OrderBy, type PostgresChangesConfig, QueryBuilder, type QueryOptions, type QueryResponse, RealtimeChannel, type RealtimeEvent, type RealtimePayload, type Session, type SignInCredentials, type SignUpCredentials, type SingleResponse, StorageBucket, type UploadAndLinkOptions, type UploadAndLinkResponse, type User, createClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -346,6 +346,31 @@ interface StorageUrlResponse {
|
|
|
346
346
|
/**
|
|
347
347
|
* Storage bucket interface for file operations
|
|
348
348
|
*/
|
|
349
|
+
interface UploadAndLinkOptions {
|
|
350
|
+
/** Table to insert/update the record */
|
|
351
|
+
table: string;
|
|
352
|
+
/** Column name to store the URL (default: 'url') */
|
|
353
|
+
column?: string;
|
|
354
|
+
/** Additional data to insert with the record */
|
|
355
|
+
data?: Record<string, any>;
|
|
356
|
+
/** If provided, update existing record instead of insert */
|
|
357
|
+
recordId?: string;
|
|
358
|
+
/** Content type of the file */
|
|
359
|
+
contentType?: string;
|
|
360
|
+
}
|
|
361
|
+
interface UploadAndLinkResponse {
|
|
362
|
+
data: {
|
|
363
|
+
file: {
|
|
364
|
+
path: string;
|
|
365
|
+
url: string;
|
|
366
|
+
bucket: string;
|
|
367
|
+
contentType: string;
|
|
368
|
+
size: number;
|
|
369
|
+
};
|
|
370
|
+
record: Record<string, any>;
|
|
371
|
+
} | null;
|
|
372
|
+
error: KrisspyError | null;
|
|
373
|
+
}
|
|
349
374
|
declare class StorageBucket {
|
|
350
375
|
private http;
|
|
351
376
|
private backendId;
|
|
@@ -438,6 +463,34 @@ declare class StorageBucket {
|
|
|
438
463
|
* .createSignedUrl('document.pdf', 3600)
|
|
439
464
|
*/
|
|
440
465
|
createSignedUrl(path: string, expiresIn?: number): Promise<StorageUrlResponse>;
|
|
466
|
+
/**
|
|
467
|
+
* Upload a file and link it to a database record in one operation
|
|
468
|
+
*
|
|
469
|
+
* @param path - Path/filename for the file
|
|
470
|
+
* @param file - File data
|
|
471
|
+
* @param options - Link options (table, column, additional data)
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* // Upload image and create new item record
|
|
475
|
+
* const { data, error } = await krisspy.storage
|
|
476
|
+
* .from('media')
|
|
477
|
+
* .uploadAndLink('products/phone.jpg', file, {
|
|
478
|
+
* table: 'items',
|
|
479
|
+
* column: 'image_url',
|
|
480
|
+
* data: { name: 'iPhone', price: 999 }
|
|
481
|
+
* })
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* // Upload avatar and update existing user
|
|
485
|
+
* const { data, error } = await krisspy.storage
|
|
486
|
+
* .from('avatars')
|
|
487
|
+
* .uploadAndLink('user123.jpg', file, {
|
|
488
|
+
* table: 'users',
|
|
489
|
+
* column: 'avatar_url',
|
|
490
|
+
* recordId: 'user123'
|
|
491
|
+
* })
|
|
492
|
+
*/
|
|
493
|
+
uploadAndLink(path: string, file: Blob | File | ArrayBuffer | string, options: UploadAndLinkOptions): Promise<UploadAndLinkResponse>;
|
|
441
494
|
private blobToBase64;
|
|
442
495
|
private arrayBufferToBase64;
|
|
443
496
|
private detectMimeType;
|
|
@@ -489,6 +542,159 @@ declare class KrisspyStorage {
|
|
|
489
542
|
}>;
|
|
490
543
|
}
|
|
491
544
|
|
|
545
|
+
/**
|
|
546
|
+
* Krisspy Realtime - WebSocket subscriptions for real-time data changes
|
|
547
|
+
*
|
|
548
|
+
* Similar to Supabase Realtime, allows subscribing to database changes.
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* // Subscribe to all changes on a table
|
|
552
|
+
* const channel = krisspy.channel('messages-changes')
|
|
553
|
+
* .on('postgres_changes', { event: '*', table: 'messages' }, (payload) => {
|
|
554
|
+
* console.log('Change:', payload)
|
|
555
|
+
* })
|
|
556
|
+
* .subscribe()
|
|
557
|
+
*
|
|
558
|
+
* // Subscribe to INSERT only
|
|
559
|
+
* const channel = krisspy.channel('new-messages')
|
|
560
|
+
* .on('postgres_changes', { event: 'INSERT', table: 'messages' }, (payload) => {
|
|
561
|
+
* console.log('New message:', payload.new)
|
|
562
|
+
* })
|
|
563
|
+
* .subscribe()
|
|
564
|
+
*
|
|
565
|
+
* // Unsubscribe
|
|
566
|
+
* channel.unsubscribe()
|
|
567
|
+
*/
|
|
568
|
+
type RealtimeEvent = 'INSERT' | 'UPDATE' | 'DELETE' | '*';
|
|
569
|
+
interface PostgresChangesConfig {
|
|
570
|
+
event: RealtimeEvent;
|
|
571
|
+
schema?: string;
|
|
572
|
+
table: string;
|
|
573
|
+
filter?: string;
|
|
574
|
+
}
|
|
575
|
+
interface RealtimePayload<T = any> {
|
|
576
|
+
eventType: 'INSERT' | 'UPDATE' | 'DELETE';
|
|
577
|
+
new: T | null;
|
|
578
|
+
old: T | null;
|
|
579
|
+
table: string;
|
|
580
|
+
schema: string;
|
|
581
|
+
commitTimestamp: string;
|
|
582
|
+
}
|
|
583
|
+
type RealtimeCallback<T = any> = (payload: RealtimePayload<T>) => void;
|
|
584
|
+
type ChannelState = 'closed' | 'connecting' | 'connected' | 'error';
|
|
585
|
+
/**
|
|
586
|
+
* Realtime Channel - represents a subscription to database changes
|
|
587
|
+
*/
|
|
588
|
+
declare class RealtimeChannel {
|
|
589
|
+
private name;
|
|
590
|
+
private realtime;
|
|
591
|
+
private subscriptions;
|
|
592
|
+
private _state;
|
|
593
|
+
constructor(name: string, realtime: KrisspyRealtime);
|
|
594
|
+
/**
|
|
595
|
+
* Get channel state
|
|
596
|
+
*/
|
|
597
|
+
get state(): ChannelState;
|
|
598
|
+
/**
|
|
599
|
+
* Subscribe to postgres changes
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* channel.on('postgres_changes', { event: 'INSERT', table: 'messages' }, (payload) => {
|
|
603
|
+
* console.log('New message:', payload.new)
|
|
604
|
+
* })
|
|
605
|
+
*/
|
|
606
|
+
on<T = any>(type: 'postgres_changes', config: PostgresChangesConfig, callback: RealtimeCallback<T>): RealtimeChannel;
|
|
607
|
+
/**
|
|
608
|
+
* Activate the channel and start receiving events
|
|
609
|
+
*/
|
|
610
|
+
subscribe(callback?: (status: ChannelState, error?: Error) => void): RealtimeChannel;
|
|
611
|
+
/**
|
|
612
|
+
* Unsubscribe from the channel
|
|
613
|
+
*/
|
|
614
|
+
unsubscribe(): Promise<void>;
|
|
615
|
+
/**
|
|
616
|
+
* Handle incoming message (called by KrisspyRealtime)
|
|
617
|
+
*/
|
|
618
|
+
handleMessage(payload: RealtimePayload): void;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Krisspy Realtime - manages WebSocket connection and channels
|
|
622
|
+
*/
|
|
623
|
+
declare class KrisspyRealtime {
|
|
624
|
+
private url;
|
|
625
|
+
private backendId;
|
|
626
|
+
private ws;
|
|
627
|
+
private channels;
|
|
628
|
+
private token;
|
|
629
|
+
private reconnectAttempts;
|
|
630
|
+
private maxReconnectAttempts;
|
|
631
|
+
private reconnectDelay;
|
|
632
|
+
private pingInterval;
|
|
633
|
+
private connectionPromise;
|
|
634
|
+
private debug;
|
|
635
|
+
constructor(baseUrl: string, backendId: string, debug?: boolean);
|
|
636
|
+
/**
|
|
637
|
+
* Set auth token for authenticated subscriptions
|
|
638
|
+
*/
|
|
639
|
+
setAuth(token: string | null): void;
|
|
640
|
+
/**
|
|
641
|
+
* Create a new channel
|
|
642
|
+
*/
|
|
643
|
+
channel(name: string): RealtimeChannel;
|
|
644
|
+
/**
|
|
645
|
+
* Connect to WebSocket server
|
|
646
|
+
*/
|
|
647
|
+
connect(): Promise<void>;
|
|
648
|
+
/**
|
|
649
|
+
* Disconnect from WebSocket server
|
|
650
|
+
*/
|
|
651
|
+
disconnect(): void;
|
|
652
|
+
/**
|
|
653
|
+
* Send subscribe message
|
|
654
|
+
*/
|
|
655
|
+
sendSubscribe(channel: string, config: PostgresChangesConfig): void;
|
|
656
|
+
/**
|
|
657
|
+
* Send unsubscribe message
|
|
658
|
+
*/
|
|
659
|
+
sendUnsubscribe(channel: string): void;
|
|
660
|
+
/**
|
|
661
|
+
* Register a channel for receiving messages
|
|
662
|
+
*/
|
|
663
|
+
registerChannel(name: string, channel: RealtimeChannel): void;
|
|
664
|
+
/**
|
|
665
|
+
* Unregister a channel
|
|
666
|
+
*/
|
|
667
|
+
unregisterChannel(name: string): void;
|
|
668
|
+
/**
|
|
669
|
+
* Remove all subscriptions
|
|
670
|
+
*/
|
|
671
|
+
removeAllChannels(): void;
|
|
672
|
+
/**
|
|
673
|
+
* Handle incoming WebSocket message
|
|
674
|
+
*/
|
|
675
|
+
private handleMessage;
|
|
676
|
+
/**
|
|
677
|
+
* Send message to WebSocket server
|
|
678
|
+
*/
|
|
679
|
+
private send;
|
|
680
|
+
/**
|
|
681
|
+
* Start ping interval to keep connection alive
|
|
682
|
+
*/
|
|
683
|
+
private startPing;
|
|
684
|
+
/**
|
|
685
|
+
* Stop ping interval
|
|
686
|
+
*/
|
|
687
|
+
private stopPing;
|
|
688
|
+
/**
|
|
689
|
+
* Attempt to reconnect
|
|
690
|
+
*/
|
|
691
|
+
private reconnect;
|
|
692
|
+
/**
|
|
693
|
+
* Log debug message
|
|
694
|
+
*/
|
|
695
|
+
private log;
|
|
696
|
+
}
|
|
697
|
+
|
|
492
698
|
/**
|
|
493
699
|
* Query Builder - Supabase-style fluent API for database queries
|
|
494
700
|
*/
|
|
@@ -636,9 +842,12 @@ declare class QueryBuilder<T = any> {
|
|
|
636
842
|
declare class KrisspyClient {
|
|
637
843
|
private http;
|
|
638
844
|
private backendId;
|
|
845
|
+
private baseUrl;
|
|
639
846
|
private _auth;
|
|
640
847
|
private _storage;
|
|
848
|
+
private _realtime;
|
|
641
849
|
private useRLS;
|
|
850
|
+
private debug;
|
|
642
851
|
constructor(options: KrisspyClientOptions);
|
|
643
852
|
/**
|
|
644
853
|
* Auth module for user authentication
|
|
@@ -685,6 +894,49 @@ declare class KrisspyClient {
|
|
|
685
894
|
* const { error } = await krisspy.storage.from('uploads').remove(['old.jpg'])
|
|
686
895
|
*/
|
|
687
896
|
get storage(): KrisspyStorage;
|
|
897
|
+
/**
|
|
898
|
+
* Create a realtime channel for subscribing to database changes
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* // Subscribe to all changes on a table
|
|
902
|
+
* const channel = krisspy.channel('messages-changes')
|
|
903
|
+
* .on('postgres_changes', { event: '*', table: 'messages' }, (payload) => {
|
|
904
|
+
* console.log('Change:', payload)
|
|
905
|
+
* })
|
|
906
|
+
* .subscribe()
|
|
907
|
+
*
|
|
908
|
+
* // Subscribe to INSERT only
|
|
909
|
+
* const channel = krisspy.channel('new-messages')
|
|
910
|
+
* .on('postgres_changes', { event: 'INSERT', table: 'messages' }, (payload) => {
|
|
911
|
+
* console.log('New message:', payload.new)
|
|
912
|
+
* })
|
|
913
|
+
* .subscribe()
|
|
914
|
+
*
|
|
915
|
+
* // Subscribe with status callback
|
|
916
|
+
* const channel = krisspy.channel('my-channel')
|
|
917
|
+
* .on('postgres_changes', { event: '*', table: 'items' }, (payload) => {
|
|
918
|
+
* console.log('Item changed:', payload)
|
|
919
|
+
* })
|
|
920
|
+
* .subscribe((status, error) => {
|
|
921
|
+
* if (status === 'connected') {
|
|
922
|
+
* console.log('Connected to realtime!')
|
|
923
|
+
* } else if (status === 'error') {
|
|
924
|
+
* console.error('Connection error:', error)
|
|
925
|
+
* }
|
|
926
|
+
* })
|
|
927
|
+
*
|
|
928
|
+
* // Unsubscribe
|
|
929
|
+
* await channel.unsubscribe()
|
|
930
|
+
*/
|
|
931
|
+
channel(name: string): RealtimeChannel;
|
|
932
|
+
/**
|
|
933
|
+
* Remove all realtime subscriptions
|
|
934
|
+
*/
|
|
935
|
+
removeAllChannels(): void;
|
|
936
|
+
/**
|
|
937
|
+
* Get the realtime instance for advanced usage
|
|
938
|
+
*/
|
|
939
|
+
get realtime(): KrisspyRealtime;
|
|
688
940
|
/**
|
|
689
941
|
* Create a query builder for a table
|
|
690
942
|
*
|
|
@@ -769,7 +1021,7 @@ declare class KrisspyClient {
|
|
|
769
1021
|
/**
|
|
770
1022
|
* @krisspy/sdk - Krisspy Cloud SDK
|
|
771
1023
|
*
|
|
772
|
-
* Database, Auth, Storage, and
|
|
1024
|
+
* Database, Auth, Storage, Functions, and Realtime for your apps.
|
|
773
1025
|
* A simpler alternative to Supabase.
|
|
774
1026
|
*
|
|
775
1027
|
* @example
|
|
@@ -801,6 +1053,13 @@ declare class KrisspyClient {
|
|
|
801
1053
|
*
|
|
802
1054
|
* // Functions
|
|
803
1055
|
* await krisspy.functions.invoke('hello', { body: { name: 'World' } })
|
|
1056
|
+
*
|
|
1057
|
+
* // Realtime
|
|
1058
|
+
* const channel = krisspy.channel('messages')
|
|
1059
|
+
* .on('postgres_changes', { event: '*', table: 'messages' }, (payload) => {
|
|
1060
|
+
* console.log('Change:', payload)
|
|
1061
|
+
* })
|
|
1062
|
+
* .subscribe()
|
|
804
1063
|
*/
|
|
805
1064
|
|
|
806
1065
|
/**
|
|
@@ -818,4 +1077,4 @@ declare class KrisspyClient {
|
|
|
818
1077
|
*/
|
|
819
1078
|
declare function createClient(options: KrisspyClientOptions): KrisspyClient;
|
|
820
1079
|
|
|
821
|
-
export { type AuthChangeEvent, type AuthResponse, type FileObject, type FileUploadOptions, type Filter, type FilterOperator, type FunctionInvokeOptions, type FunctionResponse, HttpClient, KrisspyAuth, KrisspyClient, type KrisspyClientOptions, type KrisspyError, KrisspyStorage, type MutationResponse, type OAuthProvider, type OrderBy, QueryBuilder, type QueryOptions, type QueryResponse, type Session, type SignInCredentials, type SignUpCredentials, type SingleResponse, StorageBucket, type User, createClient };
|
|
1080
|
+
export { type AuthChangeEvent, type AuthResponse, type ChannelState, type FileObject, type FileUploadOptions, type Filter, type FilterOperator, type FunctionInvokeOptions, type FunctionResponse, HttpClient, KrisspyAuth, KrisspyClient, type KrisspyClientOptions, type KrisspyError, KrisspyRealtime, KrisspyStorage, type MutationResponse, type OAuthProvider, type OrderBy, type PostgresChangesConfig, QueryBuilder, type QueryOptions, type QueryResponse, RealtimeChannel, type RealtimeEvent, type RealtimePayload, type Session, type SignInCredentials, type SignUpCredentials, type SingleResponse, StorageBucket, type UploadAndLinkOptions, type UploadAndLinkResponse, type User, createClient };
|