Skip to content

Commit

Permalink
fix: patch types
Browse files Browse the repository at this point in the history
  • Loading branch information
joel@joellee.org committed Aug 13, 2022
1 parent f0da868 commit 72b7ff3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/lib/helpers.ts
@@ -1,4 +1,5 @@
// helpers.ts
import { SupabaseClientOptions } from './types'

export function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
Expand All @@ -14,7 +15,12 @@ export function stripTrailingSlash(url: string): string {

export const isBrowser = () => typeof window !== 'undefined'

export function applySettingDefaults(
export function applySettingDefaults<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database
>(
options: SupabaseClientOptions<SchemaName>,
defaults: SupabaseClientOptions<any>
): SupabaseClientOptions<SchemaName> {
Expand Down
9 changes: 6 additions & 3 deletions test/helpers.test.ts
Expand Up @@ -33,7 +33,10 @@ test('override setting defaults', async () => {
},
}
let settings = helpers.applySettingDefaults(options, defaults)
expect(settings.auth.autoRefreshToken).toBe(autoRefreshOption)
expect(settings.auth.persistSession).not.toBeNull()
expect(settings.db.schema).toBe(defaults.db.schema)
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)
// Existing property values should remain constant
expect(settings?.db?.schema).toBe(defaults.db.schema)
})

0 comments on commit 72b7ff3

Please sign in to comment.