Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: did some refactoring #796

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions src/SupabaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,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 @@ -64,9 +52,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)
}
20 changes: 20 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// constants.ts
import { RealtimeClientOptions } from '@supabase/realtime-js'
import { SupabaseAuthClientOptions } from './types'
import { version } from './version'

export const DEFAULT_HEADERS = { 'X-Client-Info': `supabase-js/${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 @@ -63,11 +63,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