Skip to content

Commit

Permalink
fix: add types to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joel@joellee.org committed Jun 15, 2022
1 parent 005803a commit 29752d6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
30 changes: 16 additions & 14 deletions src/SupabaseClient.ts
@@ -1,6 +1,6 @@
import { DEFAULT_HEADERS, STORAGE_KEY } from './lib/constants'
import { stripTrailingSlash, isBrowser } from './lib/helpers'
import { Fetch, GenericObject, SupabaseClientOptions } from './lib/types'
import { Fetch, GenericObject, SupabaseClientOptions, SupabaseAuthClientOptions } from './lib/types'
import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
import { SupabaseQueryBuilder } from './lib/SupabaseQueryBuilder'
import { SupabaseStorageClient } from '@supabase/storage-js'
Expand Down Expand Up @@ -87,13 +87,13 @@ export default class SupabaseClient {
this.functionsUrl = `${_supabaseUrl}/functions/v1`
}

this.schema = settings.schema
this.multiTab = settings.multiTab
this.schema = settings.db?.schema || ''
this.multiTab = settings.auth?.multiTab || false
this.fetch = settings.fetch
this.headers = { ...DEFAULT_HEADERS, ...options?.headers }
this.shouldThrowOnError = settings.shouldThrowOnError || false

this.auth = this._initSupabaseAuthClient(settings)
this.auth = this._initSupabaseAuthClient(settings.auth || {}, this.headers, this.fetch)
this.realtime = this._initRealtimeClient({ headers: this.headers, ...settings.realtime })

this._listenForAuthEvents()
Expand Down Expand Up @@ -261,16 +261,18 @@ export default class SupabaseClient {
return this.realtime.channels as RealtimeSubscription[]
}

private _initSupabaseAuthClient({
autoRefreshToken,
persistSession,
detectSessionInUrl,
localStorage,
headers,
fetch,
cookieOptions,
multiTab,
}: SupabaseClientOptions) {
private _initSupabaseAuthClient(
{
autoRefreshToken,
multiTab,
persistSession,
detectSessionInUrl,
localStorage,
cookieOptions,
}: SupabaseAuthClientOptions,
headers?: GenericObject,
fetch?: Fetch
) {
const authHeaders = {
Authorization: `Bearer ${this.supabaseKey}`,
apikey: `${this.supabaseKey}`,
Expand Down
38 changes: 18 additions & 20 deletions src/lib/types.ts
Expand Up @@ -13,67 +13,65 @@ export type GenericObject = { [key: string]: string }
export type Fetch = typeof fetch

export type SupabaseClientOptions = {
pf
/**
* The Postgres schema which your tables belong to. Must be on the list of exposed schemas in Supabase. Defaults to 'public'.
*/
rest?: {
schema?: string
},
db: {
schema: string
}

auth?: {
auth: {
/**
* Automatically refreshes the token for logged in users.
*/
autoRefreshToken?: boolean,
autoRefreshToken: boolean
/**
* Allows to enable/disable multi-tab/window events
*/
multiTab?: boolean,
multiTab: boolean
/**
* Whether to persist a logged in session to storage.
*/
persistSession?: boolean,
persistSession: boolean
/**
* Detect a session from the URL. Used for OAuth login callbacks.
*/
detectSessionInUrl?: boolean,
detectSessionInUrl: boolean
/**
* A storage provider. Used to store the logged in session.
*/
localStorage?: SupabaseAuthClientOptions['localStorage'],
localStorage: SupabaseAuthClientOptions['localStorage']
/**
* Options passed to the gotrue-js instance
*/
cookieOptions?: SupabaseAuthClientOptions['cookieOptions']
},
cookieOptions: SupabaseAuthClientOptions['cookieOptions']
}

/**
* Options passed to the realtime-js instance
*/
realtime?: RealtimeClientOptions,
// TODO(Joel) -- Validate if this is needed
realtime?: RealtimeClientOptions
/**
* Options passed to the storage-js instance
*/
storage?: StorageOptions,
storage?: StorageOptions
/**
* Options passed to the functions-js instance
*/
functions?: FunctionsOptions,
functions?: FunctionsOptions
/**
* A custom `fetch` implementation.
*/
fetch?: Fetch,
fetch?: Optional<Fetch>
/**
* Optional headers for initializing the client.
*/
headers?: GenericObject,
headers?: GenericObject
/**
* Throw errors, instead of returning them.
*/
shouldThrowOnError?: boolean,


shouldThrowOnError?: boolean
}

export type SupabaseRealtimePayload<T> = {
Expand Down

0 comments on commit 29752d6

Please sign in to comment.