Skip to content

Commit 6fdd914

Browse files
authored
Merge pull request #110 from leynier/jl--add-new-release
fix: update gotrue version and modify client options class
2 parents 17db56e + 4f36efa commit 6fdd914

8 files changed

+120
-111
lines changed

poetry.lock

+48-51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ classifiers = [
1818
python = "^3.7"
1919
postgrest-py = "^0.6.0"
2020
realtime = "^0.0.3"
21-
gotrue = "^0.2.0"
21+
gotrue = "^0.3.0"
2222
httpx = ">=0.19,<0.22"
2323

2424
[tool.poetry.dev-dependencies]
@@ -32,7 +32,7 @@ commitizen = "^2.20.3"
3232

3333
[tool.commitizen]
3434
name = "cz_conventional_commits"
35-
version = "0.0.3"
35+
version = "0.1.0"
3636
version_files = [
3737
"supabase/__init__.py",
3838
"pyproject.toml:version"

supabase/client.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from supabase.lib.auth_client import SupabaseAuthClient
77
from supabase.lib.client_options import ClientOptions
8-
from supabase.lib.constants import DEFAULT_OPTIONS
98
from supabase.lib.realtime_client import SupabaseRealtimeClient
109
from supabase.lib.storage_client import SupabaseStorageClient
1110

@@ -17,7 +16,7 @@ def __init__(
1716
self,
1817
supabase_url: str,
1918
supabase_key: str,
20-
**options,
19+
options: ClientOptions = ClientOptions(),
2120
):
2221
"""Instantiate the client.
2322
@@ -38,20 +37,18 @@ def __init__(
3837
raise Exception("supabase_key is required")
3938
self.supabase_url = supabase_url
4039
self.supabase_key = supabase_key
41-
42-
settings = DEFAULT_OPTIONS.replace(**options)
43-
settings.headers.update(self._get_auth_headers())
40+
options.headers.update(self._get_auth_headers())
4441
self.rest_url: str = f"{supabase_url}/rest/v1"
4542
self.realtime_url: str = f"{supabase_url}/realtime/v1".replace("http", "ws")
4643
self.auth_url: str = f"{supabase_url}/auth/v1"
4744
self.storage_url = f"{supabase_url}/storage/v1"
48-
self.schema: str = settings.schema
45+
self.schema: str = options.schema
4946

5047
# Instantiate clients.
5148
self.auth = self._init_supabase_auth_client(
5249
auth_url=self.auth_url,
5350
supabase_key=self.supabase_key,
54-
client_options=settings,
51+
client_options=options,
5552
)
5653
# TODO(fedden): Bring up to parity with JS client.
5754
# self.realtime: SupabaseRealtimeClient = self._init_realtime_client(
@@ -62,7 +59,7 @@ def __init__(
6259
self.postgrest = self._init_postgrest_client(
6360
rest_url=self.rest_url,
6461
supabase_key=self.supabase_key,
65-
headers=settings.headers,
62+
headers=options.headers,
6663
)
6764

6865
def storage(self) -> SupabaseStorageClient:
@@ -149,7 +146,6 @@ def _init_supabase_auth_client(
149146
return SupabaseAuthClient(
150147
url=auth_url,
151148
auto_refresh_token=client_options.auto_refresh_token,
152-
detect_session_in_url=client_options.detect_session_in_url,
153149
persist_session=client_options.persist_session,
154150
local_storage=client_options.local_storage,
155151
headers=client_options.headers,
@@ -175,7 +171,11 @@ def _get_auth_headers(self) -> Dict[str, str]:
175171
}
176172

177173

178-
def create_client(supabase_url: str, supabase_key: str, **options) -> Client:
174+
def create_client(
175+
supabase_url: str,
176+
supabase_key: str,
177+
options: ClientOptions = ClientOptions(),
178+
) -> Client:
179179
"""Create client function to instantiate supabase client like JS runtime.
180180
181181
Parameters
@@ -202,4 +202,4 @@ def create_client(supabase_url: str, supabase_key: str, **options) -> Client:
202202
-------
203203
Client
204204
"""
205-
return Client(supabase_url=supabase_url, supabase_key=supabase_key, **options)
205+
return Client(supabase_url=supabase_url, supabase_key=supabase_key, options=options)

supabase/lib/auth_client.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1-
from typing import Any, Dict
1+
from typing import Dict, Optional
22

3-
import gotrue
3+
from gotrue import (
4+
CookieOptions,
5+
SyncGoTrueAPI,
6+
SyncGoTrueClient,
7+
SyncMemoryStorage,
8+
SyncSupportedStorage,
9+
)
10+
from gotrue.constants import COOKIE_OPTIONS
411

512

6-
class SupabaseAuthClient(gotrue.Client):
13+
class SupabaseAuthClient(SyncGoTrueClient):
714
"""SupabaseAuthClient"""
815

916
def __init__(
1017
self,
18+
*,
1119
url: str,
12-
detect_session_in_url: bool = False,
13-
auto_refresh_token: bool = False,
14-
persist_session: bool = False,
15-
local_storage: Dict[str, Any] = {},
1620
headers: Dict[str, str] = {},
21+
auto_refresh_token: bool = True,
22+
persist_session: bool = True,
23+
local_storage: SyncSupportedStorage = SyncMemoryStorage(),
24+
cookie_options: CookieOptions = CookieOptions.parse_obj(COOKIE_OPTIONS),
25+
api: Optional[SyncGoTrueAPI] = None,
26+
replace_default_headers: bool = False,
1727
):
1828
"""Instanciate SupabaseAuthClient instance."""
19-
super().__init__(
29+
SyncGoTrueClient.__init__(
30+
self,
2031
url=url,
2132
headers=headers,
22-
detect_session_in_url=detect_session_in_url,
2333
auto_refresh_token=auto_refresh_token,
2434
persist_session=persist_session,
2535
local_storage=local_storage,
36+
cookie_options=cookie_options,
37+
api=api,
38+
replace_default_headers=replace_default_headers,
2639
)

supabase/lib/client_options.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import copy
2-
import dataclasses
1+
from dataclasses import dataclass, field
32
from typing import Any, Callable, Dict, Optional
43

4+
from gotrue import SyncMemoryStorage, SyncSupportedStorage
5+
56
from supabase import __version__
67

78
DEFAULT_HEADERS = {"X-Client-Info": f"supabase-py/{__version__}"}
89

910

10-
@dataclasses.dataclass
11+
@dataclass
1112
class ClientOptions:
1213
schema: str = "public"
1314
"""
1415
The Postgres schema which your tables belong to.
1516
Must be on the list of exposed schemas in Supabase. Defaults to 'public'.
1617
"""
1718

18-
headers: Dict[str, str] = dataclasses.field(default_factory=DEFAULT_HEADERS.copy)
19+
headers: Dict[str, str] = field(default_factory=DEFAULT_HEADERS.copy)
1920
"""Optional headers for initializing the client."""
2021

2122
auto_refresh_token: bool = True
@@ -24,14 +25,11 @@ class ClientOptions:
2425
persist_session: bool = True
2526
"""Whether to persist a logged in session to storage."""
2627

27-
detect_session_in_url: bool = True
28-
"""Detect a session from the URL. Used for OAuth login callbacks."""
29-
30-
local_storage: Dict[str, Any] = dataclasses.field(default_factory=lambda: {})
28+
local_storage: SyncSupportedStorage = field(default_factory=SyncMemoryStorage)
3129
"""A storage provider. Used to store the logged in session."""
3230

33-
"""Options passed to the realtime-py instance"""
3431
realtime: Optional[Dict[str, Any]] = None
32+
"""Options passed to the realtime-py instance"""
3533

3634
fetch: Optional[Callable] = None
3735
"""A custom `fetch` implementation."""
@@ -42,17 +40,19 @@ def replace(
4240
headers: Optional[Dict[str, str]] = None,
4341
auto_refresh_token: Optional[bool] = None,
4442
persist_session: Optional[bool] = None,
45-
detect_session_in_url: Optional[bool] = None,
46-
local_storage: Optional[Dict[str, Any]] = None,
43+
local_storage: Optional[SyncSupportedStorage] = None,
4744
realtime: Optional[Dict[str, Any]] = None,
4845
fetch: Optional[Callable] = None,
4946
) -> "ClientOptions":
5047
"""Create a new SupabaseClientOptions with changes"""
51-
changes = {
52-
key: value
53-
for key, value in locals().items()
54-
if key != "self" and value is not None
55-
}
56-
client_options = dataclasses.replace(self, **changes)
57-
client_options = copy.deepcopy(client_options)
48+
client_options = ClientOptions()
49+
client_options.schema = schema or self.schema
50+
client_options.headers = headers or self.headers
51+
client_options.auto_refresh_token = (
52+
auto_refresh_token or self.auto_refresh_token
53+
)
54+
client_options.persist_session = persist_session or self.persist_session
55+
client_options.local_storage = local_storage or self.local_storage
56+
client_options.realtime = realtime or self.realtime
57+
client_options.fetch = fetch or self.fetch
5858
return client_options

supabase/lib/constants.py

-3
This file was deleted.

0 commit comments

Comments
 (0)