Open prescience-data opened 2 years ago
Super late reply here, sorry about that. I wonder if custom fetch would do the job:
const supabase = createClient('...', '...', {
global: {
fetch: (...args) => {
emitPreRequest()
return fetch(...args).then((res) => {
emitPostRequest()
return res
}
}
}
})
Feature request
It would be handy for the SupabaseClient class to include an event emitter which emits before and after each query or rpc call.
Below is a quick sketch of some initial thoughts, but actual implementation would require more planning if interested.
Given Supabase already has emitters for
auth
events, it seems logical that queries might get the same treatment.Describe the solution you'd like
Add an
events
property to SupabaseClient:Create type signatures and export events names:
export interface SupabaseClient { on( eventName: typeof RPC_REQUEST, listener: (fn: string, params?: object) => void ): this }
Describe alternatives you've considered
Making my own emitter and hooks pre and post request. This is becoming unwieldy across several projects trying to keep changes in sync.