Skip to content

Commit d786a15

Browse files
chore: Minor types/constants refactoring (#796)
Co-authored-by: Kamil Ogórek <[email protected]>
1 parent f6bf008 commit d786a15

File tree

4 files changed

+30
-27
lines changed

4 files changed

+30
-27
lines changed

src/SupabaseClient.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,17 @@ import {
88
RealtimeClientOptions,
99
} from '@supabase/realtime-js'
1010
import { StorageClient as SupabaseStorageClient } from '@supabase/storage-js'
11-
import { DEFAULT_HEADERS } from './lib/constants'
11+
import {
12+
DEFAULT_GLOBAL_OPTIONS,
13+
DEFAULT_DB_OPTIONS,
14+
DEFAULT_AUTH_OPTIONS,
15+
DEFAULT_REALTIME_OPTIONS,
16+
} from './lib/constants'
1217
import { fetchWithAuth } from './lib/fetch'
1318
import { stripTrailingSlash, applySettingDefaults } from './lib/helpers'
1419
import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
1520
import { Fetch, GenericSchema, SupabaseClientOptions, SupabaseAuthClientOptions } from './lib/types'
1621

17-
const DEFAULT_GLOBAL_OPTIONS = {
18-
headers: DEFAULT_HEADERS,
19-
}
20-
21-
const DEFAULT_DB_OPTIONS = {
22-
schema: 'public',
23-
}
24-
25-
const DEFAULT_AUTH_OPTIONS: SupabaseAuthClientOptions = {
26-
autoRefreshToken: true,
27-
persistSession: true,
28-
detectSessionInUrl: true,
29-
flowType: 'implicit',
30-
}
31-
32-
const DEFAULT_REALTIME_OPTIONS: RealtimeClientOptions = {}
33-
3422
/**
3523
* Supabase Client.
3624
*
@@ -60,9 +48,7 @@ export default class SupabaseClient<
6048
protected fetch?: Fetch
6149
protected changedAccessToken?: string
6250

63-
protected headers: {
64-
[key: string]: string
65-
}
51+
protected headers: Record<string, string>
6652

6753
/**
6854
* Create a new client for use in the browser.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ export const createClient = <
3535
supabaseKey: string,
3636
options?: SupabaseClientOptions<SchemaName>
3737
): SupabaseClient<Database, SchemaName, Schema> => {
38-
return new SupabaseClient(supabaseUrl, supabaseKey, options)
38+
return new SupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, options)
3939
}

src/lib/constants.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// constants.ts
2+
import { RealtimeClientOptions } from '@supabase/realtime-js'
3+
import { SupabaseAuthClientOptions } from './types'
24
import { version } from './version'
5+
36
let JS_ENV = ''
47
// @ts-ignore
58
if (typeof Deno !== 'undefined') {
@@ -11,4 +14,22 @@ if (typeof Deno !== 'undefined') {
1114
} else {
1215
JS_ENV = 'node'
1316
}
17+
1418
export const DEFAULT_HEADERS = { 'X-Client-Info': `supabase-js-${JS_ENV}/${version}` }
19+
20+
export const DEFAULT_GLOBAL_OPTIONS = {
21+
headers: DEFAULT_HEADERS,
22+
}
23+
24+
export const DEFAULT_DB_OPTIONS = {
25+
schema: 'public',
26+
}
27+
28+
export const DEFAULT_AUTH_OPTIONS: SupabaseAuthClientOptions = {
29+
autoRefreshToken: true,
30+
persistSession: true,
31+
detectSessionInUrl: true,
32+
flowType: 'implicit',
33+
}
34+
35+
export const DEFAULT_REALTIME_OPTIONS: RealtimeClientOptions = {}

src/lib/types.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,7 @@ export type GenericTable = {
7474
Update: Record<string, unknown>
7575
}
7676

77-
export type GenericUpdatableView = {
78-
Row: Record<string, unknown>
79-
Insert: Record<string, unknown>
80-
Update: Record<string, unknown>
81-
}
77+
export type GenericUpdatableView = GenericTable
8278

8379
export type GenericNonUpdatableView = {
8480
Row: Record<string, unknown>

0 commit comments

Comments
 (0)