Skip to content

Commit d9ed7bb

Browse files
committed
refactor: create a new type to avoid repeat ourselves and add the correct return type for createClient method
1 parent 43986e6 commit d9ed7bb

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/SupabaseClient.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DEFAULT_HEADERS } from './lib/constants'
2-
import { SupabaseClientOptions } from './lib/types'
2+
import { GenericObject, SupabaseClientOptions } from './lib/types'
33
import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
44
import { SupabaseQueryBuilder } from './lib/SupabaseQueryBuilder'
55
import { SupabaseStorageClient } from '@supabase/storage-js'
@@ -116,7 +116,7 @@ export default class SupabaseClient {
116116
try {
117117
await this._closeSubscription(subscription)
118118

119-
const openSubscriptions = this.getSubscriptions().length
119+
const openSubscriptions = this._getSubscriptions().length
120120
if (!openSubscriptions) {
121121
const { error } = await this.realtime.disconnect()
122122
if (error) return resolve({ error })
@@ -137,7 +137,7 @@ export default class SupabaseClient {
137137
/**
138138
* Returns an array of all your subscriptions.
139139
*/
140-
getSubscriptions(): RealtimeSubscription[] {
140+
_getSubscriptions(): RealtimeSubscription[] {
141141
return this.realtime.channels
142142
}
143143

@@ -176,8 +176,8 @@ export default class SupabaseClient {
176176
})
177177
}
178178

179-
private _getAuthHeaders(): { [key: string]: string } {
180-
const headers: { [key: string]: string } = DEFAULT_HEADERS
179+
private _getAuthHeaders(): GenericObject {
180+
const headers: GenericObject = DEFAULT_HEADERS
181181
const authBearer = this.auth.session()?.access_token ?? this.supabaseKey
182182
headers['apikey'] = this.supabaseKey
183183
headers['Authorization'] = `Bearer ${authBearer}`

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const createClient = (
1717
supabaseUrl: string,
1818
supabaseKey: string,
1919
options?: SupabaseClientOptions
20-
) => {
20+
): SupabaseClient => {
2121
return new SupabaseClient(supabaseUrl, supabaseKey, options)
2222
}
2323

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 { SupabaseEventTypes, SupabaseRealtimePayload } from './types'
4+
import { GenericObject, SupabaseEventTypes, SupabaseRealtimePayload } from './types'
55

66
export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
77
private _subscription: SupabaseRealtimeClient
@@ -15,7 +15,7 @@ export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
1515
realtime,
1616
table,
1717
}: {
18-
headers?: { [key: string]: string }
18+
headers?: GenericObject
1919
schema: string
2020
realtime: RealtimeClient
2121
table: string

src/lib/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { GoTrueClient } from '@supabase/gotrue-js'
22
import { RealtimeClientOptions } from '@supabase/realtime-js'
33

4+
export type GenericObject = { [key: string]: string }
5+
46
type GoTrueClientOptions = ConstructorParameters<typeof GoTrueClient>[0]
57

68
export interface SupabaseAuthClientOptions extends GoTrueClientOptions {}
@@ -13,7 +15,7 @@ export type SupabaseClientOptions = {
1315
/**
1416
* Optional headers for initializing the client.
1517
*/
16-
headers?: { [key: string]: string }
18+
headers?: GenericObject
1719
/**
1820
* Automatically refreshes the token for logged in users.
1921
*/

0 commit comments

Comments
 (0)