Skip to content

Commit 0095777

Browse files
authored
Merge pull request #116 from ftonato/feature/add-type-event-types
feat: add EventTypes as a Type
2 parents f1b3686 + ca3d111 commit 0095777

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/lib/SupabaseQueryBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
22
import { SupabaseRealtimeClient } from './SupabaseRealtimeClient'
33
import { RealtimeClient } from '@supabase/realtime-js'
4-
import { SupabaseRealtimePayload } from './types'
4+
import { SupabaseEventTypes, SupabaseRealtimePayload } from './types'
55

66
export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
77
private _subscription: SupabaseRealtimeClient
@@ -33,7 +33,7 @@ export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
3333
* @param callback A callback that will handle the payload that is sent whenever your database changes.
3434
*/
3535
on(
36-
event: 'INSERT' | 'UPDATE' | 'DELETE' | '*',
36+
event: SupabaseEventTypes,
3737
callback: (payload: SupabaseRealtimePayload<T>) => void
3838
): SupabaseRealtimeClient {
3939
if (!this._realtime.isConnected()) {

src/lib/SupabaseRealtimeClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RealtimeSubscription, RealtimeClient, Transformers } from '@supabase/realtime-js'
2-
import { SupabaseRealtimePayload } from './types'
2+
import { SupabaseEventTypes, SupabaseRealtimePayload } from './types'
33

44
export class SupabaseRealtimeClient {
55
subscription: RealtimeSubscription
@@ -39,7 +39,7 @@ export class SupabaseRealtimeClient {
3939
* @param event The event
4040
* @param callback A callback function that is called whenever the event occurs.
4141
*/
42-
on(event: 'INSERT' | 'UPDATE' | 'DELETE' | '*', callback: Function) {
42+
on(event: SupabaseEventTypes, callback: Function) {
4343
this.subscription.on(event, (payload: any) => {
4444
let enrichedPayload: SupabaseRealtimePayload<any> = {
4545
schema: payload.schema,

src/lib/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ export type SupabaseRealtimePayload<T> = {
3535
/** The previous record. Present for 'UPDATE' and 'DELETE' events. */
3636
old: T
3737
}
38+
39+
export type SupabaseEventTypes = 'INSERT' | 'UPDATE' | 'DELETE' | '*'

0 commit comments

Comments
 (0)