Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/SupabaseQueryBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
import { SupabaseRealtimeClient } from './SupabaseRealtimeClient'
import { RealtimeClient } from '@supabase/realtime-js'
import { SupabaseRealtimePayload } from './types'
import { SupabaseEventTypes, SupabaseRealtimePayload } from './types'

export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
private _subscription: SupabaseRealtimeClient
Expand Down Expand Up @@ -33,7 +33,7 @@ export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
* @param callback A callback that will handle the payload that is sent whenever your database changes.
*/
on(
event: 'INSERT' | 'UPDATE' | 'DELETE' | '*',
event: SupabaseEventTypes,
callback: (payload: SupabaseRealtimePayload<T>) => void
): SupabaseRealtimeClient {
if (!this._realtime.isConnected()) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/SupabaseRealtimeClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RealtimeSubscription, RealtimeClient, Transformers } from '@supabase/realtime-js'
import { SupabaseRealtimePayload } from './types'
import { SupabaseEventTypes, SupabaseRealtimePayload } from './types'

export class SupabaseRealtimeClient {
subscription: RealtimeSubscription
Expand All @@ -15,7 +15,7 @@ export class SupabaseRealtimeClient {
* @param event The event
* @param callback A callback function that is called whenever the event occurs.
*/
on(event: 'INSERT' | 'UPDATE' | 'DELETE' | '*', callback: Function) {
on(event: SupabaseEventTypes, callback: Function) {
this.subscription.on(event, (payload: any) => {
let enrichedPayload: SupabaseRealtimePayload<any> = {
schema: payload.schema,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ export type SupabaseRealtimePayload<T> = {
/** The previous record. Present for 'UPDATE' and 'DELETE' events. */
old: T
}

export type SupabaseEventTypes = 'INSERT' | 'UPDATE' | 'DELETE' | '*'