Skip to content

Commit

Permalink
fix: add shadow method
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Feb 21, 2023
1 parent 20cc55d commit 7e7cc36
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
13 changes: 12 additions & 1 deletion supabase/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from httpx import Timeout
from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT
from supafunc import FunctionsClient

from .lib.auth_client import SupabaseAuthClient
Expand Down Expand Up @@ -89,7 +90,10 @@ def __init__(
supabase_key=self.supabase_key,
headers=options.headers,
schema=options.schema,
timeout=options.timeout,
timeout=options.postgrest_client_timeout,
)
self.storage = self._init_storage_client(
self.storage_url, self._get_auth_headers(), options.storage_client_timeout
)

def functions(self) -> FunctionsClient:
Expand Down Expand Up @@ -168,6 +172,13 @@ def rpc(self, fn: str, params: Dict[Any, Any]) -> SyncFilterRequestBuilder:
# return SupabaseRealtimeClient(
# realtime_url, {"params": {"apikey": supabase_key}}
# )
@staticmethod
def _init_storage_client(
storage_url: str,
headers: Dict[str, str],
storage_client_timeout: int = DEFAULT_STORAGE_CLIENT_TIMEOUT,
) -> SupabaseStorageClient:
return SupabaseStorageClient(storage_url, headers, storage_client_timeout)

@staticmethod
def _init_supabase_auth_client(
Expand Down
22 changes: 19 additions & 3 deletions supabase/lib/client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from gotrue import SyncMemoryStorage, SyncSupportedStorage
from httpx import Timeout
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT

from supabase import __version__

Expand Down Expand Up @@ -36,9 +37,14 @@ class ClientOptions:
fetch: Optional[Callable] = None
"""A custom `fetch` implementation."""

timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT
postgrest_client_timeout: Union[
int, float, Timeout
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT
"""Timeout passed to the SyncPostgrestClient instance."""

storage_client_timeout: Uniont[int, float, Timeout] = DEFAULT_STORAGE_CLIENT_TIMEOUT
"""Timeout passed to the SyncStorageClient instance"""

def replace(
self,
schema: Optional[str] = None,
Expand All @@ -48,7 +54,12 @@ def replace(
storage: Optional[SyncSupportedStorage] = None,
realtime: Optional[Dict[str, Any]] = None,
fetch: Optional[Callable] = None,
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
postgrest_client_timeout: Union[
int, float, Timeout
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
storage_client_timeout: Union[
int, float, Timeout
] = DEFAULT_STORAGE_CLIENT_TIMEOUT,
) -> "ClientOptions":
"""Create a new SupabaseClientOptions with changes"""
client_options = ClientOptions()
Expand All @@ -61,5 +72,10 @@ def replace(
client_options.storage = storage or self.storage
client_options.realtime = realtime or self.realtime
client_options.fetch = fetch or self.fetch
client_options.timeout = timeout or self.timeout
client_options.postgrest_client_timeout = (
postgrest_client_timeout or self.postgrest_client_timeout
)
client_options.storage_client_timeout = (
storage_client_timeout or self.storage_client_timeout
)
return client_options

0 comments on commit 7e7cc36

Please sign in to comment.