Skip to content

Commit

Permalink
fix: only enrich payload for database changes
Browse files Browse the repository at this point in the history
  • Loading branch information
w3b6x9 committed Jul 6, 2022
1 parent 53decab commit ddb6676
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/lib/SupabaseRealtimeClient.ts
Expand Up @@ -34,27 +34,27 @@ export class SupabaseRealtimeClient {
* @param filter An object that specifies what you want to listen to from the event.
* @param callback A callback function that is called whenever the event occurs.
*/
on(
event: string,
filter?: Record<string, string>,
callback?: (payload: SupabaseRealtimePayload<any>) => void
) {
this.channel.on(event, filter ?? {}, (payload: any) => {
const { schema, table, commit_timestamp, type, errors } = payload.payload
let enrichedPayload: SupabaseRealtimePayload<any> = {
schema: schema,
table: table,
commit_timestamp: commit_timestamp,
eventType: type,
new: {},
old: {},
errors: errors,
}
on(event: string, filter?: Record<string, string>, callback?: (payload: any) => void) {
this.channel.on(event, filter ?? {}, ({ payload }: { payload: any }) => {
let enrichedPayload = payload

enrichedPayload = { ...enrichedPayload, ...this.getPayloadRecords(payload.payload) }
if (event === 'realtime') {
const { schema, table, commit_timestamp, type, errors } = enrichedPayload
enrichedPayload = {
schema: schema,
table: table,
commit_timestamp: commit_timestamp,
eventType: type,
new: {},
old: {},
errors: errors,
}
enrichedPayload = { ...enrichedPayload, ...this.getPayloadRecords(payload) }
}

callback && callback(enrichedPayload)
})

return this
}

Expand Down

0 comments on commit ddb6676

Please sign in to comment.