@@ -34,27 +34,27 @@ export class SupabaseRealtimeClient {
34
34
* @param filter An object that specifies what you want to listen to from the event.
35
35
* @param callback A callback function that is called whenever the event occurs.
36
36
*/
37
- on (
38
- event : string ,
39
- filter ?: Record < string , string > ,
40
- callback ?: ( payload : SupabaseRealtimePayload < any > ) => void
41
- ) {
42
- this . channel . on ( event , filter ?? { } , ( payload : any ) => {
43
- const { schema, table, commit_timestamp, type, errors } = payload . payload
44
- let enrichedPayload : SupabaseRealtimePayload < any > = {
45
- schema : schema ,
46
- table : table ,
47
- commit_timestamp : commit_timestamp ,
48
- eventType : type ,
49
- new : { } ,
50
- old : { } ,
51
- errors : errors ,
52
- }
37
+ on ( event : string , filter ?: Record < string , string > , callback ?: ( payload : any ) => void ) {
38
+ this . channel . on ( event , filter ?? { } , ( { payload } : { payload : any } ) => {
39
+ let enrichedPayload = payload
53
40
54
- enrichedPayload = { ...enrichedPayload , ...this . getPayloadRecords ( payload . payload ) }
41
+ if ( event === 'realtime' ) {
42
+ const { schema, table, commit_timestamp, type, errors } = enrichedPayload
43
+ enrichedPayload = {
44
+ schema : schema ,
45
+ table : table ,
46
+ commit_timestamp : commit_timestamp ,
47
+ eventType : type ,
48
+ new : { } ,
49
+ old : { } ,
50
+ errors : errors ,
51
+ }
52
+ enrichedPayload = { ...enrichedPayload , ...this . getPayloadRecords ( payload ) }
53
+ }
55
54
56
55
callback && callback ( enrichedPayload )
57
56
} )
57
+
58
58
return this
59
59
}
60
60
0 commit comments