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
9 changes: 5 additions & 4 deletions src/SupabaseClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DEFAULT_HEADERS, STORAGE_KEY } from './lib/constants'
import { stripTrailingSlash, isBrowser } from './lib/helpers'
import { Fetch, SupabaseClientOptions } from './lib/types'
import { Fetch, GenericObject, SupabaseClientOptions } from './lib/types'
import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
import { SupabaseQueryBuilder } from './lib/SupabaseQueryBuilder'
import { SupabaseStorageClient } from '@supabase/storage-js'
Expand Down Expand Up @@ -179,7 +179,6 @@ export default class SupabaseClient {
}

const allSubscriptions = this.getSubscriptions()
const openSubscriptionsCount = allSubscriptions.filter((chan) => chan.isJoined()).length

if (allSubscriptions.length === 0) {
const { error } = await this.realtime.disconnect()
Expand All @@ -189,6 +188,8 @@ export default class SupabaseClient {
}
}

const openSubscriptionsCount = allSubscriptions.filter((chan) => chan.isJoined()).length

return resolve({
data: { openSubscriptions: openSubscriptionsCount },
error: null,
Expand Down Expand Up @@ -254,8 +255,8 @@ export default class SupabaseClient {
})
}

private _getAuthHeaders(): { [key: string]: string } {
const headers: { [key: string]: string } = this.headers
private _getAuthHeaders(): GenericObject {
const headers: GenericObject = this.headers
const authBearer = this.auth.session()?.access_token ?? this.supabaseKey
headers['apikey'] = this.supabaseKey
headers['Authorization'] = `Bearer ${authBearer}`
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const createClient = (
supabaseUrl: string,
supabaseKey: string,
options?: SupabaseClientOptions
) => {
): SupabaseClient => {
return new SupabaseClient(supabaseUrl, supabaseKey, options)
}

Expand Down
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 { Fetch, SupabaseEventTypes, SupabaseRealtimePayload } from './types'
import { Fetch, GenericObject, SupabaseEventTypes, SupabaseRealtimePayload } from './types'

export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
private _subscription: SupabaseRealtimeClient | null = null
Expand All @@ -19,7 +19,7 @@ export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
table,
fetch,
}: {
headers?: { [key: string]: string }
headers?: GenericObject
schema: string
realtime: RealtimeClient
table: string
Expand Down
8 changes: 5 additions & 3 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { GoTrueClient } from '@supabase/gotrue-js'
import { RealtimeClientOptions } from '@supabase/realtime-js'

export type Fetch = typeof fetch

type GoTrueClientOptions = ConstructorParameters<typeof GoTrueClient>[0]

export interface SupabaseAuthClientOptions extends GoTrueClientOptions {}

export type GenericObject = { [key: string]: string }

export type Fetch = typeof fetch

export type SupabaseClientOptions = {
/**
* The Postgres schema which your tables belong to. Must be on the list of exposed schemas in Supabase. Defaults to 'public'.
Expand All @@ -15,7 +17,7 @@ export type SupabaseClientOptions = {
/**
* Optional headers for initializing the client.
*/
headers?: { [key: string]: string }
headers?: GenericObject
/**
* Automatically refreshes the token for logged in users.
*/
Expand Down