Skip to content

Commit f802e95

Browse files
committed
fix(supabase): use replace for manipulating protocol
1 parent 746240e commit f802e95

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

packages/core/supabase-js/src/SupabaseClient.ts

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,32 @@ export default class SupabaseClient<
4040
// support both cases.
4141
// TODO: Allow setting db_schema from ClientOptions.
4242
SchemaNameOrClientOptions extends
43-
| (string & keyof Omit<Database, '__InternalSupabase'>)
44-
| { PostgrestVersion: string } = 'public' extends keyof Omit<Database, '__InternalSupabase'>
45-
? 'public'
46-
: string & keyof Omit<Database, '__InternalSupabase'>,
43+
| (string & keyof Omit<Database, '__InternalSupabase'>)
44+
| { PostgrestVersion: string } = 'public' extends keyof Omit<Database, '__InternalSupabase'>
45+
? 'public'
46+
: string & keyof Omit<Database, '__InternalSupabase'>,
4747
SchemaName extends string &
48-
keyof Omit<Database, '__InternalSupabase'> = SchemaNameOrClientOptions extends string &
49-
keyof Omit<Database, '__InternalSupabase'>
50-
? SchemaNameOrClientOptions
51-
: 'public' extends keyof Omit<Database, '__InternalSupabase'>
52-
? 'public'
53-
: string & keyof Omit<Omit<Database, '__InternalSupabase'>, '__InternalSupabase'>,
48+
keyof Omit<Database, '__InternalSupabase'> = SchemaNameOrClientOptions extends string &
49+
keyof Omit<Database, '__InternalSupabase'>
50+
? SchemaNameOrClientOptions
51+
: 'public' extends keyof Omit<Database, '__InternalSupabase'>
52+
? 'public'
53+
: string & keyof Omit<Omit<Database, '__InternalSupabase'>, '__InternalSupabase'>,
5454
Schema extends Omit<Database, '__InternalSupabase'>[SchemaName] extends GenericSchema
55-
? Omit<Database, '__InternalSupabase'>[SchemaName]
56-
: never = Omit<Database, '__InternalSupabase'>[SchemaName] extends GenericSchema
57-
? Omit<Database, '__InternalSupabase'>[SchemaName]
58-
: never,
55+
? Omit<Database, '__InternalSupabase'>[SchemaName]
56+
: never = Omit<Database, '__InternalSupabase'>[SchemaName] extends GenericSchema
57+
? Omit<Database, '__InternalSupabase'>[SchemaName]
58+
: never,
5959
ClientOptions extends { PostgrestVersion: string } = SchemaNameOrClientOptions extends string &
60-
keyof Omit<Database, '__InternalSupabase'>
61-
? // If the version isn't explicitly set, look for it in the __InternalSupabase object to infer the right version
62-
Database extends { __InternalSupabase: { PostgrestVersion: string } }
63-
? Database['__InternalSupabase']
64-
: // otherwise default to 12
65-
{ PostgrestVersion: '12' }
66-
: SchemaNameOrClientOptions extends { PostgrestVersion: string }
67-
? SchemaNameOrClientOptions
68-
: never,
60+
keyof Omit<Database, '__InternalSupabase'>
61+
? // If the version isn't explicitly set, look for it in the __InternalSupabase object to infer the right version
62+
Database extends { __InternalSupabase: { PostgrestVersion: string } }
63+
? Database['__InternalSupabase']
64+
: // otherwise default to 12
65+
{ PostgrestVersion: '12' }
66+
: SchemaNameOrClientOptions extends { PostgrestVersion: string }
67+
? SchemaNameOrClientOptions
68+
: never,
6969
> {
7070
/**
7171
* Supabase Auth allows you to create and manage user sessions for access to data that is secured by access policies.
@@ -111,12 +111,8 @@ export default class SupabaseClient<
111111
if (!supabaseKey) throw new Error('supabaseKey is required.')
112112

113113
this.realtimeUrl = new URL('realtime/v1', baseUrl)
114-
// Convert HTTP protocol to WebSocket protocol using URL object
115-
if (this.realtimeUrl.protocol === 'http:') {
116-
this.realtimeUrl.protocol = 'ws:'
117-
} else if (this.realtimeUrl.protocol === 'https:') {
118-
this.realtimeUrl.protocol = 'wss:'
119-
}
114+
this.realtimeUrl.protocol = this.realtimeUrl.protocol.replace(/^http/i, 'ws')
115+
120116
this.authUrl = new URL('auth/v1', baseUrl)
121117
this.storageUrl = new URL('storage/v1', baseUrl)
122118
this.functionsUrl = new URL('functions/v1', baseUrl)
@@ -265,10 +261,10 @@ export default class SupabaseClient<
265261
get?: boolean
266262
count?: 'exact' | 'planned' | 'estimated'
267263
} = {
268-
head: false,
269-
get: false,
270-
count: undefined,
271-
}
264+
head: false,
265+
get: false,
266+
count: undefined,
267+
}
272268
): PostgrestFilterBuilder<
273269
ClientOptions,
274270
Schema,

0 commit comments

Comments
 (0)