-
-
Notifications
You must be signed in to change notification settings - Fork 70
feat(realtime): enhance RealtimeChannel type #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -31,6 +31,38 @@ export type RealtimeChannelOptions = { | |||||
} | ||||||
} | ||||||
|
||||||
type RealtimeBroadcastChangesPayloadBase = { | ||||||
id: string | ||||||
schema: string | ||||||
table: string | ||||||
} | ||||||
|
||||||
export type RealtimeBroadcastInsertPayload<T extends { [key: string]: any }> = | ||||||
RealtimeBroadcastChangesPayloadBase & { | ||||||
operation: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT}` | ||||||
record: T | ||||||
old_record: null | ||||||
} | ||||||
|
||||||
export type RealtimeBroadcastUpdatePayload<T extends { [key: string]: any }> = | ||||||
RealtimeBroadcastChangesPayloadBase & { | ||||||
operation: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE}` | ||||||
record: T | ||||||
old_record: T | ||||||
} | ||||||
|
||||||
export type RealtimeBroadcastDeletePayload<T extends { [key: string]: any }> = | ||||||
RealtimeBroadcastChangesPayloadBase & { | ||||||
operation: `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE}` | ||||||
record: null | ||||||
old_record: T | ||||||
} | ||||||
|
||||||
export type RealtimeBroadcastPayload<T extends { [key: string]: any }> = | ||||||
| RealtimeBroadcastInsertPayload<T> | ||||||
| RealtimeBroadcastUpdatePayload<T> | ||||||
| RealtimeBroadcastDeletePayload<T> | ||||||
|
||||||
type RealtimePostgresChangesPayloadBase = { | ||||||
schema: string | ||||||
table: string | ||||||
|
@@ -406,6 +438,42 @@ export default class RealtimeChannel { | |||||
payload: T | ||||||
}) => void | ||||||
): RealtimeChannel | ||||||
on<T extends { [key: string]: any }>( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Using
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The multiple overloads for broadcast events are largely repetitive. You could consolidate them using a single overload with conditional types on Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
type: `${REALTIME_LISTEN_TYPES.BROADCAST}`, | ||||||
filter: { event: REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.ALL }, | ||||||
callback: (payload: { | ||||||
type: `${REALTIME_LISTEN_TYPES.BROADCAST}` | ||||||
event: REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.ALL | ||||||
payload: RealtimeBroadcastPayload<T> | ||||||
}) => void | ||||||
): RealtimeChannel | ||||||
on<T extends { [key: string]: any }>( | ||||||
type: `${REALTIME_LISTEN_TYPES.BROADCAST}`, | ||||||
filter: { event: REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT }, | ||||||
callback: (payload: { | ||||||
type: `${REALTIME_LISTEN_TYPES.BROADCAST}` | ||||||
event: REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.INSERT | ||||||
payload: RealtimeBroadcastInsertPayload<T> | ||||||
}) => void | ||||||
): RealtimeChannel | ||||||
on<T extends { [key: string]: any }>( | ||||||
type: `${REALTIME_LISTEN_TYPES.BROADCAST}`, | ||||||
filter: { event: REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE }, | ||||||
callback: (payload: { | ||||||
type: `${REALTIME_LISTEN_TYPES.BROADCAST}` | ||||||
event: REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.UPDATE | ||||||
payload: RealtimeBroadcastUpdatePayload<T> | ||||||
}) => void | ||||||
): RealtimeChannel | ||||||
on<T extends { [key: string]: any }>( | ||||||
type: `${REALTIME_LISTEN_TYPES.BROADCAST}`, | ||||||
filter: { event: REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE }, | ||||||
callback: (payload: { | ||||||
type: `${REALTIME_LISTEN_TYPES.BROADCAST}` | ||||||
event: REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE | ||||||
payload: RealtimeBroadcastDeletePayload<T> | ||||||
}) => void | ||||||
): RealtimeChannel | ||||||
on<T extends { [key: string]: any }>( | ||||||
type: `${REALTIME_LISTEN_TYPES.SYSTEM}`, | ||||||
filter: {}, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] RealtimeBroadcastChangesPayloadBase overlaps with RealtimePostgresChangesPayloadBase (schema/table). Consider merging shared fields or extending one from the other to reduce duplication.
Copilot uses AI. Check for mistakes.