From 95281bd63b3a370e6fb0ac7b021a93a8c48aac71 Mon Sep 17 00:00:00 2001 From: dshukertjr <18113850+dshukertjr@users.noreply.github.com> Date: Sat, 30 Sep 2023 11:57:10 +0900 Subject: [PATCH 1/7] make supabase key and supabase URL private --- .../supabase/lib/src/supabase_client.dart | 39 ++++++------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/packages/supabase/lib/src/supabase_client.dart b/packages/supabase/lib/src/supabase_client.dart index fb77e9e5..56347cec 100644 --- a/packages/supabase/lib/src/supabase_client.dart +++ b/packages/supabase/lib/src/supabase_client.dart @@ -30,8 +30,7 @@ import 'auth_http_client.dart'; /// `AuthFlowType.pkce`in order to perform auth actions with pkce flow. /// {@endtemplate} class SupabaseClient { - final String supabaseUrl; - final String supabaseKey; + final String _supabaseKey; final PostgrestClientOptions _postgrestOptions; final String _restUrl; @@ -99,27 +98,10 @@ class SupabaseClient { ..addAll(_headers); } - /// Creates a Supabase client to interact with your Supabase instance. - /// - /// [supabaseUrl] and [supabaseKey] can be found on your Supabase dashboard. - /// - /// You can access none public schema by passing different [schema]. - /// - /// Default headers can be overridden by specifying [headers]. - /// - /// Custom http client can be used by passing [httpClient] parameter. - /// - /// [storageRetryAttempts] specifies how many retry attempts there should be to - /// upload a file to Supabase storage when failed due to network interruption. - /// - /// [realtimeClientOptions] specifies different options you can pass to `RealtimeClient`. - /// - /// Pass an instance of `YAJsonIsolate` to [isolate] to use your own persisted - /// isolate instance. A new instance will be created if [isolate] is omitted. /// {@macro supabase_client} SupabaseClient( - this.supabaseUrl, - this.supabaseKey, { + String supabaseUrl, + this._supabaseKey, { PostgrestClientOptions postgrestOptions = const PostgrestClientOptions(), AuthClientOptions authOptions = const AuthClientOptions(), StorageClientOptions storageOptions = const StorageClientOptions(), @@ -144,7 +126,8 @@ class SupabaseClient { gotrueAsyncStorage: authOptions.pkceAsyncStorage, authFlowType: authOptions.authFlowType, ); - _authHttpClient = AuthHttpClient(supabaseKey, httpClient ?? Client(), auth); + _authHttpClient = + AuthHttpClient(_supabaseKey, httpClient ?? Client(), auth); rest = _initRestClient(); functions = _initFunctionsClient(); storage = _initStorageClient(storageOptions.retryAttempts); @@ -218,8 +201,8 @@ class SupabaseClient { required AuthFlowType authFlowType, }) { final authHeaders = {...headers}; - authHeaders['apikey'] = supabaseKey; - authHeaders['Authorization'] = 'Bearer $supabaseKey'; + authHeaders['apikey'] = _supabaseKey; + authHeaders['Authorization'] = 'Bearer $_supabaseKey'; return GoTrueClient( url: _authUrl, @@ -266,7 +249,7 @@ class SupabaseClient { return RealtimeClient( _realtimeUrl, params: { - 'apikey': supabaseKey, + 'apikey': _supabaseKey, if (eventsPerSecond != null) 'eventsPerSecond': '$eventsPerSecond' }, headers: headers, @@ -275,9 +258,9 @@ class SupabaseClient { } Map _getAuthHeaders() { - final authBearer = auth.currentSession?.accessToken ?? supabaseKey; + final authBearer = auth.currentSession?.accessToken ?? _supabaseKey; final defaultHeaders = { - 'apikey': supabaseKey, + 'apikey': _supabaseKey, 'Authorization': 'Bearer $authBearer', }; final headers = {...defaultHeaders, ..._headers}; @@ -305,7 +288,7 @@ class SupabaseClient { event == AuthChangeEvent.userDeleted) { // Token is removed - realtime.setAuth(supabaseKey); + realtime.setAuth(_supabaseKey); } } } From a4aae4bbc2dd6525d93db0613894c294403bc6f0 Mon Sep 17 00:00:00 2001 From: dshukertjr <18113850+dshukertjr@users.noreply.github.com> Date: Sun, 1 Oct 2023 13:32:32 +0900 Subject: [PATCH 2/7] make rest and realtime private --- .../supabase/lib/src/supabase_client.dart | 34 ++++---- packages/supabase/test/client_test.dart | 78 ++++++++++++++++--- packages/supabase/test/mock_test.dart | 4 +- 3 files changed, 85 insertions(+), 31 deletions(-) diff --git a/packages/supabase/lib/src/supabase_client.dart b/packages/supabase/lib/src/supabase_client.dart index 56347cec..7bc3f727 100644 --- a/packages/supabase/lib/src/supabase_client.dart +++ b/packages/supabase/lib/src/supabase_client.dart @@ -49,8 +49,8 @@ class SupabaseClient { /// Supabase Storage allows you to manage user-generated content, such as photos or videos. late final SupabaseStorageClient storage; - late final RealtimeClient realtime; - late final PostgrestClient rest; + late final RealtimeClient _realtime; + late final PostgrestClient _rest; String? _changedAccessToken; late StreamSubscription _authStateSubscription; late final YAJsonIsolate _isolate; @@ -71,7 +71,7 @@ class SupabaseClient { ...headers, }); - rest.headers + _rest.headers ..clear() ..addAll(_headers); @@ -93,7 +93,7 @@ class SupabaseClient { // To apply the new headers in the realtime client, // manually unsubscribe and resubscribe to all channels. - realtime.headers + _realtime.headers ..clear() ..addAll(_headers); } @@ -128,10 +128,10 @@ class SupabaseClient { ); _authHttpClient = AuthHttpClient(_supabaseKey, httpClient ?? Client(), auth); - rest = _initRestClient(); + _rest = _initRestClient(); functions = _initFunctionsClient(); storage = _initStorageClient(storageOptions.retryAttempts); - realtime = _initRealtimeClient(options: realtimeClientOptions); + _realtime = _initRealtimeClient(options: realtimeClientOptions); _listenForAuthEvents(); } @@ -141,8 +141,8 @@ class SupabaseClient { _incrementId++; return SupabaseQueryBuilder( url, - realtime, - headers: {...rest.headers, ...headers}, + _realtime, + headers: {..._rest.headers, ...headers}, schema: _postgrestOptions.schema, table: table, httpClient: _authHttpClient, @@ -155,7 +155,7 @@ class SupabaseClient { /// /// The schema needs to be on the list of exposed schemas inside Supabase. PostgrestClient useSchema(String schema) { - return rest.useSchema(schema); + return _rest.useSchema(schema); } /// Perform a stored procedure call. @@ -163,31 +163,31 @@ class SupabaseClient { String fn, { Map? params, }) { - rest.headers.addAll({...rest.headers, ...headers}); - return rest.rpc(fn, params: params); + _rest.headers.addAll({..._rest.headers, ...headers}); + return _rest.rpc(fn, params: params); } /// Creates a Realtime channel with Broadcast, Presence, and Postgres Changes. RealtimeChannel channel(String name, {RealtimeChannelConfig opts = const RealtimeChannelConfig()}) { - return realtime.channel(name, opts); + return _realtime.channel(name, opts); } /// Returns all Realtime channels. List getChannels() { - return realtime.getChannels(); + return _realtime.getChannels(); } /// Unsubscribes and removes Realtime channel from Realtime client. /// /// [channel] - The name of the Realtime channel. Future removeChannel(RealtimeChannel channel) { - return realtime.removeChannel(channel); + return _realtime.removeChannel(channel); } /// Unsubscribes and removes all Realtime channels from Realtime client. Future> removeAllChannels() { - return realtime.removeAllChannels(); + return _realtime.removeAllChannels(); } Future dispose() async { @@ -283,12 +283,12 @@ class SupabaseClient { // Token has changed _changedAccessToken = token; - realtime.setAuth(token); + _realtime.setAuth(token); } else if (event == AuthChangeEvent.signedOut || event == AuthChangeEvent.userDeleted) { // Token is removed - realtime.setAuth(_supabaseKey); + _realtime.setAuth(_supabaseKey); } } } diff --git a/packages/supabase/test/client_test.dart b/packages/supabase/test/client_test.dart index 559311b6..79d53a25 100644 --- a/packages/supabase/test/client_test.dart +++ b/packages/supabase/test/client_test.dart @@ -6,23 +6,44 @@ import 'package:test/test.dart'; import 'utils.dart'; void main() { + /// Extracts a single request sent to the realtime server + Future getRealtimeRequest({ + required HttpServer server, + required SupabaseClient supabaseClient, + }) async { + supabaseClient.channel('name').subscribe(); + + return server.first; + } + group('Standard Header', () { - const supabaseUrl = 'https://nlbsnpoablmsiwndbmer.supabase.co'; + late String supabaseUrl; const supabaseKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im53emxkenlsb2pyemdqemloZHJrIiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODQxMzI2ODAsImV4cCI6MTk5OTcwODY4MH0.MU-LVeAPic93VLcRsHktxzYtBKBUMWAQb8E-0AQETPs'; late SupabaseClient client; + late HttpServer mockServer; + + setUp(() async { + mockServer = await HttpServer.bind('localhost', 0); + supabaseUrl = 'http://${mockServer.address.host}:${mockServer.port}'; - setUp(() { client = SupabaseClient(supabaseUrl, supabaseKey); }); tearDown(() async { + await client.removeAllChannels(); await client.dispose(); }); - test('X-Client-Info header is set properly on realtime', () { + test('X-Client-Info header is set properly on realtime', () async { + final request = await getRealtimeRequest( + server: mockServer, + supabaseClient: client, + ); + final xClientHeaderBeforeSlash = - client.realtime.headers['X-Client-Info']!.split('/').first; + request.headers['X-Client-Info']?.first.split('/').first; + expect(xClientHeaderBeforeSlash, 'supabase-dart'); }); @@ -32,19 +53,33 @@ void main() { expect(xClientHeaderBeforeSlash, 'supabase-dart'); }); - test('realtime URL is properly being set', () { - var realtimeWebsocketURL = Uri.parse(client.realtime.endPointURL); + test('realtime URL is properly being set', () async { + final request = await getRealtimeRequest( + server: mockServer, + supabaseClient: client, + ); + + var realtimeWebsocketURL = request.uri; + expect( realtimeWebsocketURL.queryParameters, containsPair('apikey', supabaseKey), ); expect(realtimeWebsocketURL.queryParameters['log_level'], isNull); + }); + test('log_level query parameter is properly set', () async { client = SupabaseClient(supabaseUrl, supabaseKey, realtimeClientOptions: RealtimeClientOptions(logLevel: RealtimeLogLevel.info)); - realtimeWebsocketURL = Uri.parse(client.realtime.endPointURL); + final request = await getRealtimeRequest( + server: mockServer, + supabaseClient: client, + ); + + final realtimeWebsocketURL = request.uri; + expect( realtimeWebsocketURL.queryParameters, containsPair('apikey', supabaseKey), @@ -55,8 +90,13 @@ void main() { ); }); - test('realtime access token is set properly', () { - expect(client.realtime.accessToken, supabaseKey); + test('realtime access token is set properly', () async { + final request = await getRealtimeRequest( + server: mockServer, + supabaseClient: client, + ); + + expect(request.uri.queryParameters['apikey'], supabaseKey); }); }); @@ -163,9 +203,23 @@ void main() { ); }); - test('X-Client-Info header is set properly on realtime', () { - final xClientInfoHeader = client.realtime.headers['X-Client-Info']; - expect(xClientInfoHeader, 'supabase-flutter/0.0.0'); + test('X-Client-Info header is set properly on realtime', () async { + final mockServer = await HttpServer.bind('localhost', 0); + + final client = SupabaseClient( + 'http://${mockServer.address.host}:${mockServer.port}', + supabaseKey, + headers: { + 'X-Client-Info': 'supabase-flutter/0.0.0', + }, + ); + + final request = await getRealtimeRequest( + server: mockServer, + supabaseClient: client, + ); + + expect(request.headers['X-Client-Info']?.first, 'supabase-flutter/0.0.0'); }); test('X-Client-Info header is set properly on storage', () { diff --git a/packages/supabase/test/mock_test.dart b/packages/supabase/test/mock_test.dart index da65fc04..65a5a04b 100644 --- a/packages/supabase/test/mock_test.dart +++ b/packages/supabase/test/mock_test.dart @@ -357,8 +357,8 @@ void main() { await customHeadersClient.dispose(); //Manually disconnect the socket channel to avoid automatic retrying to reconnect. This caused failing in later executed tests. - client.realtime.disconnect(); - customHeadersClient.realtime.disconnect(); + await client.removeAllChannels(); + await customHeadersClient.removeAllChannels(); // Wait for the realtime updates to come through await Future.delayed(Duration(milliseconds: 100)); From d9e3f7300db2b471b914449d7bb80f37e95b04bd Mon Sep 17 00:00:00 2001 From: dshukertjr <18113850+dshukertjr@users.noreply.github.com> Date: Mon, 2 Oct 2023 00:19:10 +0900 Subject: [PATCH 3/7] minor dx fix with how supabase key is passes --- .../lib/src/realtime_channel.dart | 22 +++++++++---------- .../realtime_client/test/channel_test.dart | 14 ++++++------ .../supabase/lib/src/supabase_client.dart | 5 +++-- .../test/supabase_flutter_test.dart | 1 + 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/realtime_client/lib/src/realtime_channel.dart b/packages/realtime_client/lib/src/realtime_channel.dart index bed5f278..e940e4b7 100644 --- a/packages/realtime_client/lib/src/realtime_channel.dart +++ b/packages/realtime_client/lib/src/realtime_channel.dart @@ -44,14 +44,14 @@ class RealtimeChannel { _pushBuffer = []; }); - onClose(() { + _onClose(() { _rejoinTimer.reset(); socket.log('channel', 'close $topic $joinRef'); _state = ChannelStates.closed; socket.remove(this); }); - onError((String? reason) { + _onError((String? reason) { if (isLeaving || isClosed) { return; } @@ -100,10 +100,10 @@ class RealtimeChannel { final broadcast = params['config']['broadcast']; final presence = params['config']['presence']; - onError((e) { + _onError((e) { if (callback != null) callback(RealtimeSubscribeStatus.channelError, e); }); - onClose(() { + _onClose(() { if (callback != null) callback(RealtimeSubscribeStatus.closed, null); }); @@ -226,13 +226,13 @@ class RealtimeChannel { } /// Registers a callback that will be executed when the channel closes. - void onClose(Function callback) { + void _onClose(Function callback) { onEvents(ChannelEvents.close.eventName(), ChannelFilter(), (reason, [ref]) => callback()); } /// Registers a callback that will be executed when the channel encounteres an error. - void onError(void Function(String?) callback) { + void _onError(void Function(String?) callback) { onEvents(ChannelEvents.error.eventName(), ChannelFilter(), (reason, [ref]) => callback(reason?.toString())); } @@ -271,7 +271,7 @@ class RealtimeChannel { } /// Returns `true` if the socket is connected and the channel has been joined. - bool get canPush { + bool get _canPush { return socket.isConnected && isJoined; } @@ -284,7 +284,7 @@ class RealtimeChannel { throw "tried to push '${event.eventName()}' to '$topic' before joining. Use channel.subscribe() before pushing events"; } final pushEvent = Push(this, event, payload, timeout ?? _timeout); - if (canPush) { + if (_canPush) { pushEvent.send(); } else { pushEvent.startTimeout(); @@ -354,6 +354,7 @@ class RealtimeChannel { /// ``` Future unsubscribe([Duration? timeout]) { _state = ChannelStates.leaving; + void onClose() { socket.log('channel', 'leave $topic'); trigger(ChannelEvents.close.eventName(), 'leave', joinRef); @@ -385,7 +386,7 @@ class RealtimeChannel { leavePush.send(); - if (!canPush) { + if (!_canPush) { leavePush.trigger('ok', {}); } @@ -484,9 +485,6 @@ class RealtimeChannel { @internal bool get isClosed => _state == ChannelStates.closed; - @internal - bool get isErrored => _state == ChannelStates.errored; - @internal bool get isJoined => _state == ChannelStates.joined; diff --git a/packages/realtime_client/test/channel_test.dart b/packages/realtime_client/test/channel_test.dart index c3417b06..67a002fc 100644 --- a/packages/realtime_client/test/channel_test.dart +++ b/packages/realtime_client/test/channel_test.dart @@ -74,18 +74,18 @@ void main() { }); group('onError', () { - setUp(() { + test("sets state to 'errored'", () { + var isErrored = false; socket = RealtimeClient('/socket'); channel = socket.channel('topic'); - channel.subscribe(); - }); - - test("sets state to 'errored'", () { - expect(channel.isErrored, isFalse); + channel.subscribe(((status, error) { + isErrored = status == RealtimeSubscribeStatus.channelError; + })); + expect(isErrored, isFalse); channel.trigger('phx_error'); - expect(channel.isErrored, isTrue); + expect(isErrored, isTrue); }); }); diff --git a/packages/supabase/lib/src/supabase_client.dart b/packages/supabase/lib/src/supabase_client.dart index 7bc3f727..85719159 100644 --- a/packages/supabase/lib/src/supabase_client.dart +++ b/packages/supabase/lib/src/supabase_client.dart @@ -101,7 +101,7 @@ class SupabaseClient { /// {@macro supabase_client} SupabaseClient( String supabaseUrl, - this._supabaseKey, { + String supabaseKey, { PostgrestClientOptions postgrestOptions = const PostgrestClientOptions(), AuthClientOptions authOptions = const AuthClientOptions(), StorageClientOptions storageOptions = const StorageClientOptions(), @@ -109,7 +109,8 @@ class SupabaseClient { Map? headers, Client? httpClient, YAJsonIsolate? isolate, - }) : _restUrl = '$supabaseUrl/rest/v1', + }) : _supabaseKey = supabaseKey, + _restUrl = '$supabaseUrl/rest/v1', _realtimeUrl = '$supabaseUrl/realtime/v1'.replaceAll('http', 'ws'), _authUrl = '$supabaseUrl/auth/v1', _storageUrl = '$supabaseUrl/storage/v1', diff --git a/packages/supabase_flutter/test/supabase_flutter_test.dart b/packages/supabase_flutter/test/supabase_flutter_test.dart index 7ce163ed..0b0b2598 100644 --- a/packages/supabase_flutter/test/supabase_flutter_test.dart +++ b/packages/supabase_flutter/test/supabase_flutter_test.dart @@ -25,6 +25,7 @@ void main() { test('can access Supabase singleton', () async { final client = Supabase.instance.client; + client.channel('').isClosed; expect(client, isNotNull); }); From dd8b893b653e31922ceab436541767ee4c755565 Mon Sep 17 00:00:00 2001 From: dshukertjr <18113850+dshukertjr@users.noreply.github.com> Date: Mon, 2 Oct 2023 00:42:41 +0900 Subject: [PATCH 4/7] fix:revert realtime fix --- .../lib/src/realtime_channel.dart | 21 +++++++++++-------- .../realtime_client/test/channel_test.dart | 14 ++++++------- .../test/supabase_flutter_test.dart | 1 - 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/realtime_client/lib/src/realtime_channel.dart b/packages/realtime_client/lib/src/realtime_channel.dart index e940e4b7..b36f86c6 100644 --- a/packages/realtime_client/lib/src/realtime_channel.dart +++ b/packages/realtime_client/lib/src/realtime_channel.dart @@ -44,14 +44,14 @@ class RealtimeChannel { _pushBuffer = []; }); - _onClose(() { + onClose(() { _rejoinTimer.reset(); socket.log('channel', 'close $topic $joinRef'); _state = ChannelStates.closed; socket.remove(this); }); - _onError((String? reason) { + onError((String? reason) { if (isLeaving || isClosed) { return; } @@ -100,10 +100,10 @@ class RealtimeChannel { final broadcast = params['config']['broadcast']; final presence = params['config']['presence']; - _onError((e) { + onError((e) { if (callback != null) callback(RealtimeSubscribeStatus.channelError, e); }); - _onClose(() { + onClose(() { if (callback != null) callback(RealtimeSubscribeStatus.closed, null); }); @@ -226,13 +226,13 @@ class RealtimeChannel { } /// Registers a callback that will be executed when the channel closes. - void _onClose(Function callback) { + void onClose(Function callback) { onEvents(ChannelEvents.close.eventName(), ChannelFilter(), (reason, [ref]) => callback()); } /// Registers a callback that will be executed when the channel encounteres an error. - void _onError(void Function(String?) callback) { + void onError(void Function(String?) callback) { onEvents(ChannelEvents.error.eventName(), ChannelFilter(), (reason, [ref]) => callback(reason?.toString())); } @@ -271,7 +271,7 @@ class RealtimeChannel { } /// Returns `true` if the socket is connected and the channel has been joined. - bool get _canPush { + bool get canPush { return socket.isConnected && isJoined; } @@ -284,7 +284,7 @@ class RealtimeChannel { throw "tried to push '${event.eventName()}' to '$topic' before joining. Use channel.subscribe() before pushing events"; } final pushEvent = Push(this, event, payload, timeout ?? _timeout); - if (_canPush) { + if (canPush) { pushEvent.send(); } else { pushEvent.startTimeout(); @@ -386,7 +386,7 @@ class RealtimeChannel { leavePush.send(); - if (!_canPush) { + if (!canPush) { leavePush.trigger('ok', {}); } @@ -482,6 +482,9 @@ class RealtimeChannel { return 'chan_reply_$ref'; } + @internal + bool get isErrored => _state == ChannelStates.errored; + @internal bool get isClosed => _state == ChannelStates.closed; diff --git a/packages/realtime_client/test/channel_test.dart b/packages/realtime_client/test/channel_test.dart index 67a002fc..c3417b06 100644 --- a/packages/realtime_client/test/channel_test.dart +++ b/packages/realtime_client/test/channel_test.dart @@ -74,18 +74,18 @@ void main() { }); group('onError', () { - test("sets state to 'errored'", () { - var isErrored = false; + setUp(() { socket = RealtimeClient('/socket'); channel = socket.channel('topic'); - channel.subscribe(((status, error) { - isErrored = status == RealtimeSubscribeStatus.channelError; - })); - expect(isErrored, isFalse); + channel.subscribe(); + }); + + test("sets state to 'errored'", () { + expect(channel.isErrored, isFalse); channel.trigger('phx_error'); - expect(isErrored, isTrue); + expect(channel.isErrored, isTrue); }); }); diff --git a/packages/supabase_flutter/test/supabase_flutter_test.dart b/packages/supabase_flutter/test/supabase_flutter_test.dart index 0b0b2598..7ce163ed 100644 --- a/packages/supabase_flutter/test/supabase_flutter_test.dart +++ b/packages/supabase_flutter/test/supabase_flutter_test.dart @@ -25,7 +25,6 @@ void main() { test('can access Supabase singleton', () async { final client = Supabase.instance.client; - client.channel('').isClosed; expect(client, isNotNull); }); From 732acd094f7e4768ccbd396c816c244756ca06aa Mon Sep 17 00:00:00 2001 From: dshukertjr <18113850+dshukertjr@users.noreply.github.com> Date: Mon, 2 Oct 2023 00:43:28 +0900 Subject: [PATCH 5/7] reverse order of isClosed and isErrored --- packages/realtime_client/lib/src/realtime_channel.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/realtime_client/lib/src/realtime_channel.dart b/packages/realtime_client/lib/src/realtime_channel.dart index b36f86c6..ac03ceba 100644 --- a/packages/realtime_client/lib/src/realtime_channel.dart +++ b/packages/realtime_client/lib/src/realtime_channel.dart @@ -483,10 +483,10 @@ class RealtimeChannel { } @internal - bool get isErrored => _state == ChannelStates.errored; + bool get isClosed => _state == ChannelStates.closed; @internal - bool get isClosed => _state == ChannelStates.closed; + bool get isErrored => _state == ChannelStates.errored; @internal bool get isJoined => _state == ChannelStates.joined; From c851af199c9ad66ca4a30503aed193eca3015558 Mon Sep 17 00:00:00 2001 From: dshukertjr <18113850+dshukertjr@users.noreply.github.com> Date: Mon, 2 Oct 2023 00:44:15 +0900 Subject: [PATCH 6/7] remove extra space --- packages/realtime_client/lib/src/realtime_channel.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/realtime_client/lib/src/realtime_channel.dart b/packages/realtime_client/lib/src/realtime_channel.dart index ac03ceba..bed5f278 100644 --- a/packages/realtime_client/lib/src/realtime_channel.dart +++ b/packages/realtime_client/lib/src/realtime_channel.dart @@ -354,7 +354,6 @@ class RealtimeChannel { /// ``` Future unsubscribe([Duration? timeout]) { _state = ChannelStates.leaving; - void onClose() { socket.log('channel', 'leave $topic'); trigger(ChannelEvents.close.eventName(), 'leave', joinRef); From 570501f519290b268b332d1cbcec67090d844e8a Mon Sep 17 00:00:00 2001 From: dshukertjr <18113850+dshukertjr@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:13:51 +0900 Subject: [PATCH 7/7] make realtime and rest public --- .../supabase/lib/src/supabase_client.dart | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/supabase/lib/src/supabase_client.dart b/packages/supabase/lib/src/supabase_client.dart index 85719159..cfbbc208 100644 --- a/packages/supabase/lib/src/supabase_client.dart +++ b/packages/supabase/lib/src/supabase_client.dart @@ -49,8 +49,8 @@ class SupabaseClient { /// Supabase Storage allows you to manage user-generated content, such as photos or videos. late final SupabaseStorageClient storage; - late final RealtimeClient _realtime; - late final PostgrestClient _rest; + late final RealtimeClient realtime; + late final PostgrestClient rest; String? _changedAccessToken; late StreamSubscription _authStateSubscription; late final YAJsonIsolate _isolate; @@ -71,7 +71,7 @@ class SupabaseClient { ...headers, }); - _rest.headers + rest.headers ..clear() ..addAll(_headers); @@ -93,7 +93,7 @@ class SupabaseClient { // To apply the new headers in the realtime client, // manually unsubscribe and resubscribe to all channels. - _realtime.headers + realtime.headers ..clear() ..addAll(_headers); } @@ -129,10 +129,10 @@ class SupabaseClient { ); _authHttpClient = AuthHttpClient(_supabaseKey, httpClient ?? Client(), auth); - _rest = _initRestClient(); + rest = _initRestClient(); functions = _initFunctionsClient(); storage = _initStorageClient(storageOptions.retryAttempts); - _realtime = _initRealtimeClient(options: realtimeClientOptions); + realtime = _initRealtimeClient(options: realtimeClientOptions); _listenForAuthEvents(); } @@ -142,8 +142,8 @@ class SupabaseClient { _incrementId++; return SupabaseQueryBuilder( url, - _realtime, - headers: {..._rest.headers, ...headers}, + realtime, + headers: {...rest.headers, ...headers}, schema: _postgrestOptions.schema, table: table, httpClient: _authHttpClient, @@ -156,7 +156,7 @@ class SupabaseClient { /// /// The schema needs to be on the list of exposed schemas inside Supabase. PostgrestClient useSchema(String schema) { - return _rest.useSchema(schema); + return rest.useSchema(schema); } /// Perform a stored procedure call. @@ -164,31 +164,31 @@ class SupabaseClient { String fn, { Map? params, }) { - _rest.headers.addAll({..._rest.headers, ...headers}); - return _rest.rpc(fn, params: params); + rest.headers.addAll({...rest.headers, ...headers}); + return rest.rpc(fn, params: params); } /// Creates a Realtime channel with Broadcast, Presence, and Postgres Changes. RealtimeChannel channel(String name, {RealtimeChannelConfig opts = const RealtimeChannelConfig()}) { - return _realtime.channel(name, opts); + return realtime.channel(name, opts); } /// Returns all Realtime channels. List getChannels() { - return _realtime.getChannels(); + return realtime.getChannels(); } /// Unsubscribes and removes Realtime channel from Realtime client. /// /// [channel] - The name of the Realtime channel. Future removeChannel(RealtimeChannel channel) { - return _realtime.removeChannel(channel); + return realtime.removeChannel(channel); } /// Unsubscribes and removes all Realtime channels from Realtime client. Future> removeAllChannels() { - return _realtime.removeAllChannels(); + return realtime.removeAllChannels(); } Future dispose() async { @@ -284,12 +284,12 @@ class SupabaseClient { // Token has changed _changedAccessToken = token; - _realtime.setAuth(token); + realtime.setAuth(token); } else if (event == AuthChangeEvent.signedOut || event == AuthChangeEvent.userDeleted) { // Token is removed - _realtime.setAuth(_supabaseKey); + realtime.setAuth(_supabaseKey); } } }