Skip to content

Commit

Permalink
ref: Update applySettingDefaults typings to use accurate return type (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed May 15, 2024
1 parent 912f13e commit 52bf37f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/SupabaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,20 @@ export default class SupabaseClient<

const settings = applySettingDefaults(options ?? {}, DEFAULTS)

this.storageKey = settings.auth?.storageKey ?? ''
this.headers = settings.global?.headers ?? {}
this.storageKey = settings.auth.storageKey ?? ''
this.headers = settings.global.headers ?? {}

this.auth = this._initSupabaseAuthClient(
settings.auth ?? {},
this.headers,
settings.global?.fetch
settings.global.fetch
)
this.fetch = fetchWithAuth(supabaseKey, this._getAccessToken.bind(this), settings.global?.fetch)
this.fetch = fetchWithAuth(supabaseKey, this._getAccessToken.bind(this), settings.global.fetch)

this.realtime = this._initRealtimeClient({ headers: this.headers, ...settings.realtime })
this.rest = new PostgrestClient(`${_supabaseUrl}/rest/v1`, {
headers: this.headers,
schema: settings.db?.schema,
schema: settings.db.schema,
fetch: this.fetch,
})

Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function applySettingDefaults<
>(
options: SupabaseClientOptions<SchemaName>,
defaults: SupabaseClientOptions<any>
): SupabaseClientOptions<SchemaName> {
): Required<SupabaseClientOptions<SchemaName>> {
const {
db: dbOptions,
auth: authOptions,
Expand Down
8 changes: 4 additions & 4 deletions test/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ test('override setting defaults', async () => {
},
}
let settings = helpers.applySettingDefaults(options, defaults)
expect(settings?.auth?.autoRefreshToken).toBe(autoRefreshOption)
expect(settings.auth.autoRefreshToken).toBe(autoRefreshOption)
// Existing default properties should not be overwritten
expect(settings?.auth?.persistSession).not.toBeNull()
expect(settings?.global?.headers).toBe(DEFAULT_HEADERS)
expect(settings.auth.persistSession).not.toBeNull()
expect(settings.global.headers).toBe(DEFAULT_HEADERS)
// Existing property values should remain constant
expect(settings?.db?.schema).toBe(defaults.db.schema)
expect(settings.db.schema).toBe(defaults.db.schema)
})

0 comments on commit 52bf37f

Please sign in to comment.