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