|
1 | 1 | from dataclasses import dataclass, field
|
2 | 2 | from typing import Any, Dict, Optional, Union
|
3 | 3 |
|
4 |
| -from gotrue import AuthFlowType, SyncMemoryStorage, SyncSupportedStorage |
| 4 | +from gotrue import ( |
| 5 | + AsyncMemoryStorage, |
| 6 | + AuthFlowType, |
| 7 | + SyncMemoryStorage, |
| 8 | + SyncSupportedStorage, |
| 9 | +) |
5 | 10 | from httpx import Timeout
|
6 | 11 | from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
|
7 | 12 | from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT
|
@@ -85,3 +90,82 @@ def replace(
|
85 | 90 | )
|
86 | 91 | client_options.flow_type = flow_type or self.flow_type
|
87 | 92 | return client_options
|
| 93 | + |
| 94 | + |
| 95 | +@dataclass |
| 96 | +class AsyncClientOptions(ClientOptions): |
| 97 | + storage: SyncSupportedStorage = field(default_factory=AsyncMemoryStorage) |
| 98 | + """A storage provider. Used to store the logged in session.""" |
| 99 | + |
| 100 | + def replace( |
| 101 | + self, |
| 102 | + schema: Optional[str] = None, |
| 103 | + headers: Optional[Dict[str, str]] = None, |
| 104 | + auto_refresh_token: Optional[bool] = None, |
| 105 | + persist_session: Optional[bool] = None, |
| 106 | + storage: Optional[SyncSupportedStorage] = None, |
| 107 | + realtime: Optional[Dict[str, Any]] = None, |
| 108 | + postgrest_client_timeout: Union[ |
| 109 | + int, float, Timeout |
| 110 | + ] = DEFAULT_POSTGREST_CLIENT_TIMEOUT, |
| 111 | + storage_client_timeout: Union[ |
| 112 | + int, float, Timeout |
| 113 | + ] = DEFAULT_STORAGE_CLIENT_TIMEOUT, |
| 114 | + flow_type: Optional[AuthFlowType] = None, |
| 115 | + ) -> "AsyncClientOptions": |
| 116 | + """Create a new SupabaseClientOptions with changes""" |
| 117 | + client_options = AsyncClientOptions() |
| 118 | + client_options.schema = schema or self.schema |
| 119 | + client_options.headers = headers or self.headers |
| 120 | + client_options.auto_refresh_token = ( |
| 121 | + auto_refresh_token or self.auto_refresh_token |
| 122 | + ) |
| 123 | + client_options.persist_session = persist_session or self.persist_session |
| 124 | + client_options.storage = storage or self.storage |
| 125 | + client_options.realtime = realtime or self.realtime |
| 126 | + client_options.postgrest_client_timeout = ( |
| 127 | + postgrest_client_timeout or self.postgrest_client_timeout |
| 128 | + ) |
| 129 | + client_options.storage_client_timeout = ( |
| 130 | + storage_client_timeout or self.storage_client_timeout |
| 131 | + ) |
| 132 | + client_options.flow_type = flow_type or self.flow_type |
| 133 | + return client_options |
| 134 | + |
| 135 | + |
| 136 | +@dataclass |
| 137 | +class SyncClientOptions(ClientOptions): |
| 138 | + def replace( |
| 139 | + self, |
| 140 | + schema: Optional[str] = None, |
| 141 | + headers: Optional[Dict[str, str]] = None, |
| 142 | + auto_refresh_token: Optional[bool] = None, |
| 143 | + persist_session: Optional[bool] = None, |
| 144 | + storage: Optional[SyncSupportedStorage] = None, |
| 145 | + realtime: Optional[Dict[str, Any]] = None, |
| 146 | + postgrest_client_timeout: Union[ |
| 147 | + int, float, Timeout |
| 148 | + ] = DEFAULT_POSTGREST_CLIENT_TIMEOUT, |
| 149 | + storage_client_timeout: Union[ |
| 150 | + int, float, Timeout |
| 151 | + ] = DEFAULT_STORAGE_CLIENT_TIMEOUT, |
| 152 | + flow_type: Optional[AuthFlowType] = None, |
| 153 | + ) -> "SyncClientOptions": |
| 154 | + """Create a new SupabaseClientOptions with changes""" |
| 155 | + client_options = SyncClientOptions() |
| 156 | + client_options.schema = schema or self.schema |
| 157 | + client_options.headers = headers or self.headers |
| 158 | + client_options.auto_refresh_token = ( |
| 159 | + auto_refresh_token or self.auto_refresh_token |
| 160 | + ) |
| 161 | + client_options.persist_session = persist_session or self.persist_session |
| 162 | + client_options.storage = storage or self.storage |
| 163 | + client_options.realtime = realtime or self.realtime |
| 164 | + client_options.postgrest_client_timeout = ( |
| 165 | + postgrest_client_timeout or self.postgrest_client_timeout |
| 166 | + ) |
| 167 | + client_options.storage_client_timeout = ( |
| 168 | + storage_client_timeout or self.storage_client_timeout |
| 169 | + ) |
| 170 | + client_options.flow_type = flow_type or self.flow_type |
| 171 | + return client_options |
0 commit comments