Skip to content

Commit

Permalink
chore: Minor types/constants refactoring (#796)
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Ogórek <kamil.ogorek@gmail.com>
  • Loading branch information
Ananya2001-an and kamilogorek authored Jan 23, 2024
1 parent f6bf008 commit d786a15
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
28 changes: 7 additions & 21 deletions src/SupabaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,17 @@ import {
RealtimeClientOptions,
} from '@supabase/realtime-js'
import { StorageClient as SupabaseStorageClient } from '@supabase/storage-js'
import { DEFAULT_HEADERS } from './lib/constants'
import {
DEFAULT_GLOBAL_OPTIONS,
DEFAULT_DB_OPTIONS,
DEFAULT_AUTH_OPTIONS,
DEFAULT_REALTIME_OPTIONS,
} from './lib/constants'
import { fetchWithAuth } from './lib/fetch'
import { stripTrailingSlash, applySettingDefaults } from './lib/helpers'
import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
import { Fetch, GenericSchema, SupabaseClientOptions, SupabaseAuthClientOptions } from './lib/types'

const DEFAULT_GLOBAL_OPTIONS = {
headers: DEFAULT_HEADERS,
}

const DEFAULT_DB_OPTIONS = {
schema: 'public',
}

const DEFAULT_AUTH_OPTIONS: SupabaseAuthClientOptions = {
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: true,
flowType: 'implicit',
}

const DEFAULT_REALTIME_OPTIONS: RealtimeClientOptions = {}

/**
* Supabase Client.
*
Expand Down Expand Up @@ -60,9 +48,7 @@ export default class SupabaseClient<
protected fetch?: Fetch
protected changedAccessToken?: string

protected headers: {
[key: string]: string
}
protected headers: Record<string, string>

/**
* Create a new client for use in the browser.
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ export const createClient = <
supabaseKey: string,
options?: SupabaseClientOptions<SchemaName>
): SupabaseClient<Database, SchemaName, Schema> => {
return new SupabaseClient(supabaseUrl, supabaseKey, options)
return new SupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, options)
}
21 changes: 21 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// constants.ts
import { RealtimeClientOptions } from '@supabase/realtime-js'
import { SupabaseAuthClientOptions } from './types'
import { version } from './version'

let JS_ENV = ''
// @ts-ignore
if (typeof Deno !== 'undefined') {
Expand All @@ -11,4 +14,22 @@ if (typeof Deno !== 'undefined') {
} else {
JS_ENV = 'node'
}

export const DEFAULT_HEADERS = { 'X-Client-Info': `supabase-js-${JS_ENV}/${version}` }

export const DEFAULT_GLOBAL_OPTIONS = {
headers: DEFAULT_HEADERS,
}

export const DEFAULT_DB_OPTIONS = {
schema: 'public',
}

export const DEFAULT_AUTH_OPTIONS: SupabaseAuthClientOptions = {
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: true,
flowType: 'implicit',
}

export const DEFAULT_REALTIME_OPTIONS: RealtimeClientOptions = {}
6 changes: 1 addition & 5 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ export type GenericTable = {
Update: Record<string, unknown>
}

export type GenericUpdatableView = {
Row: Record<string, unknown>
Insert: Record<string, unknown>
Update: Record<string, unknown>
}
export type GenericUpdatableView = GenericTable

export type GenericNonUpdatableView = {
Row: Record<string, unknown>
Expand Down

0 comments on commit d786a15

Please sign in to comment.