corebase 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- corebase/__init__.py +108 -0
- corebase/_async/__init__.py +1 -0
- corebase/_async/auth_client.py +55 -0
- corebase/_async/client.py +398 -0
- corebase/_sync/__init__.py +1 -0
- corebase/_sync/auth_client.py +55 -0
- corebase/_sync/client.py +393 -0
- corebase/auth/__init__.py +20 -0
- corebase/auth/_async/__init__.py +1 -0
- corebase/auth/_async/gotrue_admin_api.py +356 -0
- corebase/auth/_async/gotrue_admin_mfa_api.py +32 -0
- corebase/auth/_async/gotrue_admin_oauth_api.py +93 -0
- corebase/auth/_async/gotrue_base_api.py +78 -0
- corebase/auth/_async/gotrue_client.py +1404 -0
- corebase/auth/_async/gotrue_mfa_api.py +94 -0
- corebase/auth/_async/storage.py +31 -0
- corebase/auth/_sync/__init__.py +1 -0
- corebase/auth/_sync/gotrue_admin_api.py +356 -0
- corebase/auth/_sync/gotrue_admin_mfa_api.py +32 -0
- corebase/auth/_sync/gotrue_admin_oauth_api.py +93 -0
- corebase/auth/_sync/gotrue_base_api.py +78 -0
- corebase/auth/_sync/gotrue_client.py +1394 -0
- corebase/auth/_sync/gotrue_mfa_api.py +94 -0
- corebase/auth/_sync/storage.py +31 -0
- corebase/auth/constants.py +15 -0
- corebase/auth/errors.py +259 -0
- corebase/auth/helpers.py +288 -0
- corebase/auth/py.typed +0 -0
- corebase/auth/timer.py +53 -0
- corebase/auth/types.py +1021 -0
- corebase/auth/version.py +1 -0
- corebase/client.py +12 -0
- corebase/functions/__init__.py +47 -0
- corebase/functions/_async/__init__.py +1 -0
- corebase/functions/_async/functions_client.py +218 -0
- corebase/functions/_sync/__init__.py +1 -0
- corebase/functions/_sync/functions_client.py +218 -0
- corebase/functions/errors.py +62 -0
- corebase/functions/py.typed +0 -0
- corebase/functions/utils.py +33 -0
- corebase/functions/version.py +1 -0
- corebase/lib/__init__.py +3 -0
- corebase/lib/client_options.py +189 -0
- corebase/migrate/__init__.py +374 -0
- corebase/migrate/__main__.py +7 -0
- corebase/postgrest/__init__.py +62 -0
- corebase/postgrest/_async/__init__.py +1 -0
- corebase/postgrest/_async/client.py +206 -0
- corebase/postgrest/_async/request_builder.py +503 -0
- corebase/postgrest/_sync/__init__.py +1 -0
- corebase/postgrest/_sync/client.py +206 -0
- corebase/postgrest/_sync/request_builder.py +503 -0
- corebase/postgrest/base_client.py +61 -0
- corebase/postgrest/base_request_builder.py +787 -0
- corebase/postgrest/constants.py +6 -0
- corebase/postgrest/exceptions.py +115 -0
- corebase/postgrest/py.typed +0 -0
- corebase/postgrest/types.py +72 -0
- corebase/postgrest/utils.py +91 -0
- corebase/postgrest/version.py +1 -0
- corebase/py.typed +0 -0
- corebase/realtime/__init__.py +17 -0
- corebase/realtime/_async/__init__.py +0 -0
- corebase/realtime/_async/channel.py +766 -0
- corebase/realtime/_async/client.py +498 -0
- corebase/realtime/_async/presence.py +185 -0
- corebase/realtime/_async/push.py +162 -0
- corebase/realtime/_async/timer.py +41 -0
- corebase/realtime/_sync/__init__.py +0 -0
- corebase/realtime/_sync/channel.py +30 -0
- corebase/realtime/_sync/client.py +71 -0
- corebase/realtime/_sync/presence.py +10 -0
- corebase/realtime/exceptions.py +38 -0
- corebase/realtime/message.py +176 -0
- corebase/realtime/py.typed +0 -0
- corebase/realtime/transformers.py +9 -0
- corebase/realtime/types.py +246 -0
- corebase/realtime/utils.py +5 -0
- corebase/realtime/version.py +1 -0
- corebase/storage/__init__.py +56 -0
- corebase/storage/_async/__init__.py +1 -0
- corebase/storage/_async/analytics.py +82 -0
- corebase/storage/_async/bucket.py +142 -0
- corebase/storage/_async/client.py +106 -0
- corebase/storage/_async/file_api.py +630 -0
- corebase/storage/_async/request.py +32 -0
- corebase/storage/_async/vectors.py +213 -0
- corebase/storage/_sync/__init__.py +1 -0
- corebase/storage/_sync/analytics.py +80 -0
- corebase/storage/_sync/bucket.py +142 -0
- corebase/storage/_sync/client.py +106 -0
- corebase/storage/_sync/file_api.py +630 -0
- corebase/storage/_sync/request.py +32 -0
- corebase/storage/_sync/vectors.py +199 -0
- corebase/storage/constants.py +16 -0
- corebase/storage/exceptions.py +84 -0
- corebase/storage/py.typed +0 -0
- corebase/storage/types.py +313 -0
- corebase/storage/utils.py +26 -0
- corebase/storage/version.py +1 -0
- corebase/types.py +8 -0
- corebase/version.py +1 -0
- corebase-1.0.0.dist-info/METADATA +78 -0
- corebase-1.0.0.dist-info/RECORD +106 -0
- corebase-1.0.0.dist-info/WHEEL +4 -0
- corebase-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import logging
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Literal, assert_never, overload
|
|
7
|
+
|
|
8
|
+
from ..message import Message, ReplyPostgresChanges
|
|
9
|
+
from ..types import DEFAULT_TIMEOUT, Callback, RealtimeAcknowledgementStatus
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from .channel import AsyncRealtimeChannel
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AsyncPush:
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
channel: AsyncRealtimeChannel,
|
|
21
|
+
event: str,
|
|
22
|
+
payload: Mapping[str, Any] | None = None,
|
|
23
|
+
timeout: int = DEFAULT_TIMEOUT,
|
|
24
|
+
) -> None:
|
|
25
|
+
self.channel = channel
|
|
26
|
+
self.event = event
|
|
27
|
+
self.payload = payload or {}
|
|
28
|
+
self.timeout = timeout
|
|
29
|
+
self.ref: str | None = None
|
|
30
|
+
self.received_resp: (
|
|
31
|
+
tuple[RealtimeAcknowledgementStatus, dict[str, Any]] | None
|
|
32
|
+
) = None
|
|
33
|
+
self.sent = False
|
|
34
|
+
self.timeout_task: asyncio.Task | None = None
|
|
35
|
+
self.ok_callbacks: list[Callback[[ReplyPostgresChanges], None]] = []
|
|
36
|
+
self.error_callbacks: list[Callback[[dict[str, Any]], None]] = []
|
|
37
|
+
self.timeout_callbacks: list[Callback[[], None]] = []
|
|
38
|
+
|
|
39
|
+
async def resend(self) -> None:
|
|
40
|
+
self.ref = None
|
|
41
|
+
self.received_resp = None
|
|
42
|
+
self.sent = False
|
|
43
|
+
await self.send()
|
|
44
|
+
|
|
45
|
+
async def send(self) -> None:
|
|
46
|
+
if (
|
|
47
|
+
self.received_resp
|
|
48
|
+
and self.received_resp[0] == RealtimeAcknowledgementStatus.Timeout
|
|
49
|
+
):
|
|
50
|
+
return
|
|
51
|
+
|
|
52
|
+
self.ref = self.channel.socket._make_ref()
|
|
53
|
+
self.channel.messages_waiting_for_ack[self.ref] = self
|
|
54
|
+
self.start_timeout()
|
|
55
|
+
self.sent = True
|
|
56
|
+
|
|
57
|
+
message = Message(
|
|
58
|
+
topic=self.channel.topic,
|
|
59
|
+
event=self.event,
|
|
60
|
+
ref=self.ref,
|
|
61
|
+
join_ref=self.channel.join_push.ref,
|
|
62
|
+
payload=self.payload,
|
|
63
|
+
)
|
|
64
|
+
await self.channel.socket.send(message)
|
|
65
|
+
|
|
66
|
+
def update_payload(self, payload: dict[str, Any]) -> None:
|
|
67
|
+
self.payload = {**self.payload, **payload}
|
|
68
|
+
|
|
69
|
+
@overload
|
|
70
|
+
def receive(
|
|
71
|
+
self,
|
|
72
|
+
status: Literal[RealtimeAcknowledgementStatus.Ok],
|
|
73
|
+
callback: Callback[[ReplyPostgresChanges], None],
|
|
74
|
+
) -> AsyncPush: ...
|
|
75
|
+
@overload
|
|
76
|
+
def receive(
|
|
77
|
+
self,
|
|
78
|
+
status: Literal[RealtimeAcknowledgementStatus.Error],
|
|
79
|
+
callback: Callback[[dict[str, Any]], None],
|
|
80
|
+
) -> AsyncPush: ...
|
|
81
|
+
|
|
82
|
+
@overload
|
|
83
|
+
def receive(
|
|
84
|
+
self,
|
|
85
|
+
status: Literal[RealtimeAcknowledgementStatus.Timeout],
|
|
86
|
+
callback: Callback[[], None],
|
|
87
|
+
) -> AsyncPush: ...
|
|
88
|
+
|
|
89
|
+
def receive(self, status, callback) -> AsyncPush:
|
|
90
|
+
if (received := self.received_resp) and received[0] == status:
|
|
91
|
+
if status == RealtimeAcknowledgementStatus.Timeout:
|
|
92
|
+
callback()
|
|
93
|
+
else:
|
|
94
|
+
callback(received[1])
|
|
95
|
+
else:
|
|
96
|
+
if status == RealtimeAcknowledgementStatus.Ok:
|
|
97
|
+
self.ok_callbacks.append(callback)
|
|
98
|
+
elif status == RealtimeAcknowledgementStatus.Error:
|
|
99
|
+
self.error_callbacks.append(callback)
|
|
100
|
+
elif status == RealtimeAcknowledgementStatus.Timeout:
|
|
101
|
+
self.timeout_callbacks.append(callback)
|
|
102
|
+
else:
|
|
103
|
+
assert_never(status)
|
|
104
|
+
return self
|
|
105
|
+
|
|
106
|
+
def start_timeout(self) -> None:
|
|
107
|
+
if self.timeout_task:
|
|
108
|
+
return
|
|
109
|
+
|
|
110
|
+
async def timeout(self) -> None:
|
|
111
|
+
await asyncio.sleep(self.timeout)
|
|
112
|
+
self.timeout_task = None
|
|
113
|
+
self.trigger(RealtimeAcknowledgementStatus.Timeout, {})
|
|
114
|
+
if self.ref and self.ref in self.channel.messages_waiting_for_ack:
|
|
115
|
+
del self.channel.messages_waiting_for_ack[self.ref]
|
|
116
|
+
|
|
117
|
+
self.timeout_task = asyncio.create_task(timeout(self))
|
|
118
|
+
|
|
119
|
+
@overload
|
|
120
|
+
def trigger(
|
|
121
|
+
self,
|
|
122
|
+
status: Literal[RealtimeAcknowledgementStatus.Ok],
|
|
123
|
+
response: ReplyPostgresChanges,
|
|
124
|
+
) -> None: ...
|
|
125
|
+
@overload
|
|
126
|
+
def trigger(
|
|
127
|
+
self,
|
|
128
|
+
status: Literal[RealtimeAcknowledgementStatus.Error],
|
|
129
|
+
response: dict[str, Any],
|
|
130
|
+
) -> None: ...
|
|
131
|
+
@overload
|
|
132
|
+
def trigger(
|
|
133
|
+
self,
|
|
134
|
+
status: Literal[RealtimeAcknowledgementStatus.Timeout],
|
|
135
|
+
response: dict[str, Any],
|
|
136
|
+
) -> None: ...
|
|
137
|
+
|
|
138
|
+
def trigger(self, status: RealtimeAcknowledgementStatus, response) -> None:
|
|
139
|
+
self.received_resp = (status, response)
|
|
140
|
+
if status == RealtimeAcknowledgementStatus.Ok:
|
|
141
|
+
self._cancel_timeout()
|
|
142
|
+
for ok_callback in self.ok_callbacks:
|
|
143
|
+
ok_callback(response)
|
|
144
|
+
elif status == RealtimeAcknowledgementStatus.Error:
|
|
145
|
+
self._cancel_timeout()
|
|
146
|
+
for error_callback in self.error_callbacks:
|
|
147
|
+
error_callback(response)
|
|
148
|
+
elif status == RealtimeAcknowledgementStatus.Timeout:
|
|
149
|
+
for timeout_callback in self.timeout_callbacks:
|
|
150
|
+
timeout_callback()
|
|
151
|
+
else:
|
|
152
|
+
assert_never(status)
|
|
153
|
+
|
|
154
|
+
def destroy(self) -> None:
|
|
155
|
+
self._cancel_timeout()
|
|
156
|
+
|
|
157
|
+
def _cancel_timeout(self) -> None:
|
|
158
|
+
if not self.timeout_task:
|
|
159
|
+
return
|
|
160
|
+
|
|
161
|
+
self.timeout_task.cancel()
|
|
162
|
+
self.timeout_task = None
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import logging
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
|
|
5
|
+
logger = logging.getLogger(__name__)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AsyncTimer:
|
|
9
|
+
def __init__(self, callback: Callable, timer_calc: Callable[[int], float]) -> None:
|
|
10
|
+
self.callback = callback
|
|
11
|
+
self.timer_calc = timer_calc
|
|
12
|
+
self.timer: asyncio.Task | None = None
|
|
13
|
+
self.tries: int = 0
|
|
14
|
+
|
|
15
|
+
def reset(self) -> None:
|
|
16
|
+
self.tries = 0
|
|
17
|
+
if self.timer and not self.timer.done():
|
|
18
|
+
self.timer.cancel()
|
|
19
|
+
self.timer = None
|
|
20
|
+
logger.debug(
|
|
21
|
+
"AsyncTimer has been reset and any scheduler tasks have been cancelled"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def schedule_timeout(self, delay: float | None = None) -> None:
|
|
25
|
+
if self.timer:
|
|
26
|
+
self.timer.cancel()
|
|
27
|
+
|
|
28
|
+
self.tries += 1
|
|
29
|
+
if delay is None:
|
|
30
|
+
delay = self.timer_calc(self.tries)
|
|
31
|
+
logger.debug(f"Scheduling callback to run after {delay} seconds.")
|
|
32
|
+
self.timer = asyncio.create_task(self._run_timer(delay))
|
|
33
|
+
|
|
34
|
+
async def _run_timer(self, delay: float) -> None:
|
|
35
|
+
try:
|
|
36
|
+
await asyncio.sleep(delay)
|
|
37
|
+
await self.callback()
|
|
38
|
+
except asyncio.CancelledError:
|
|
39
|
+
logger.debug("AsyncTimer task was cancelled.")
|
|
40
|
+
except Exception as e:
|
|
41
|
+
logger.exception(f"Error in AsyncTimer callback: {e}")
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from corebase.realtime.types import RealtimeChannelOptions
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from .client import SyncRealtimeClient
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SyncRealtimeChannel:
|
|
12
|
+
"""
|
|
13
|
+
`Channel` is an abstraction for a topic listener for an existing socket connection.
|
|
14
|
+
Each Channel has its own topic and a list of event-callbacks that responds to messages.
|
|
15
|
+
Should only be instantiated through `connection.RealtimeClient().channel(topic)`.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
socket: SyncRealtimeClient,
|
|
21
|
+
topic: str,
|
|
22
|
+
params: RealtimeChannelOptions | None = None,
|
|
23
|
+
) -> None:
|
|
24
|
+
"""
|
|
25
|
+
Initialize the Channel object.
|
|
26
|
+
|
|
27
|
+
:param socket: RealtimeClient object
|
|
28
|
+
:param topic: Topic that it subscribes to on the realtime server
|
|
29
|
+
:param params: Optional parameters for connection.
|
|
30
|
+
"""
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from .channel import RealtimeChannelOptions, SyncRealtimeChannel
|
|
4
|
+
|
|
5
|
+
NOT_IMPLEMENTED_MESSAGE = "This feature isn't available in the sync client. You can use the realtime feature in the async client only."
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SyncRealtimeClient:
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
url: str,
|
|
12
|
+
token: str,
|
|
13
|
+
auto_reconnect: bool = True,
|
|
14
|
+
params: dict[str, Any] | None = None,
|
|
15
|
+
hb_interval: int = 30,
|
|
16
|
+
max_retries: int = 5,
|
|
17
|
+
initial_backoff: float = 1.0,
|
|
18
|
+
) -> None:
|
|
19
|
+
"""
|
|
20
|
+
Initialize a RealtimeClient instance for WebSocket communication.
|
|
21
|
+
|
|
22
|
+
:param url: WebSocket URL of the Realtime server. Starts with `ws://` or `wss://`.
|
|
23
|
+
Also accepts default Supabase URL: `http://` or `https://`.
|
|
24
|
+
:param token: Authentication token for the WebSocket connection.
|
|
25
|
+
:param auto_reconnect: If True, automatically attempt to reconnect on disconnection. Defaults to False.
|
|
26
|
+
:param params: Optional parameters for the connection. Defaults to an empty dictionary.
|
|
27
|
+
:param hb_interval: Interval (in seconds) for sending heartbeat messages to keep the connection alive. Defaults to 30.
|
|
28
|
+
:param max_retries: Maximum number of reconnection attempts. Defaults to 5.
|
|
29
|
+
:param initial_backoff: Initial backoff time (in seconds) for reconnection attempts. Defaults to 1.0.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def channel(
|
|
33
|
+
self, topic: str, params: RealtimeChannelOptions | None = None
|
|
34
|
+
) -> SyncRealtimeChannel:
|
|
35
|
+
"""
|
|
36
|
+
:param topic: Initializes a channel and creates a two-way association with the socket
|
|
37
|
+
:return: Channel
|
|
38
|
+
"""
|
|
39
|
+
raise NotImplementedError(NOT_IMPLEMENTED_MESSAGE)
|
|
40
|
+
|
|
41
|
+
def get_channels(self) -> list[SyncRealtimeChannel]:
|
|
42
|
+
raise NotImplementedError(NOT_IMPLEMENTED_MESSAGE)
|
|
43
|
+
|
|
44
|
+
def remove_channel(self, channel: SyncRealtimeChannel) -> None:
|
|
45
|
+
"""
|
|
46
|
+
Unsubscribes and removes a channel from the socket
|
|
47
|
+
:param channel: Channel to remove
|
|
48
|
+
:return: None
|
|
49
|
+
"""
|
|
50
|
+
raise NotImplementedError(NOT_IMPLEMENTED_MESSAGE)
|
|
51
|
+
|
|
52
|
+
def remove_all_channels(self) -> None:
|
|
53
|
+
"""
|
|
54
|
+
Unsubscribes and removes all channels from the socket
|
|
55
|
+
:return: None
|
|
56
|
+
"""
|
|
57
|
+
raise NotImplementedError(NOT_IMPLEMENTED_MESSAGE)
|
|
58
|
+
|
|
59
|
+
def set_auth(self, token: str | None) -> None:
|
|
60
|
+
"""
|
|
61
|
+
Set the authentication token for the connection and update all joined channels.
|
|
62
|
+
|
|
63
|
+
This method updates the access token for the current connection and sends the new token
|
|
64
|
+
to all joined channels. This is useful for refreshing authentication or changing users.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
token (Optional[str]): The new authentication token. Can be None to remove authentication.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
None
|
|
71
|
+
"""
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class NotConnectedError(Exception):
|
|
2
|
+
"""
|
|
3
|
+
Raised when operations requiring a connection are executed when socket is not connected
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
def __init__(self, func_name: str) -> None:
|
|
7
|
+
self.offending_func_name: str = func_name
|
|
8
|
+
|
|
9
|
+
def __str__(self) -> str:
|
|
10
|
+
return f"A WS connection has not been established. Ensure you call AsyncRealtimeClient.connect() before calling AsyncRealtimeClient.{self.offending_func_name}()"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AuthorizationError(Exception):
|
|
14
|
+
"""
|
|
15
|
+
Raised when there is an authorization failure for private channels
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, message: str | None = None) -> None:
|
|
19
|
+
self.message: str = message or "Authorization failed for private channel"
|
|
20
|
+
|
|
21
|
+
def __str__(self) -> str:
|
|
22
|
+
return self.message
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class RealtimeHTTPError(Exception):
|
|
26
|
+
"""
|
|
27
|
+
Raised when a request to the Realtime REST API fails, e.g. `AsyncRealtimeChannel.http_send`.
|
|
28
|
+
|
|
29
|
+
`status` is the HTTP status code, or None when no response was received (timeout).
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(self, message: str, status: int | None = None) -> None:
|
|
33
|
+
super().__init__(message)
|
|
34
|
+
self.message: str = message
|
|
35
|
+
self.status: int | None = status
|
|
36
|
+
|
|
37
|
+
def __str__(self) -> str:
|
|
38
|
+
return self.message
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
from collections.abc import Mapping
|
|
2
|
+
from typing import Any, Literal, TypeAlias
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field, TypeAdapter
|
|
5
|
+
|
|
6
|
+
from .types import (
|
|
7
|
+
BroadcastPayload,
|
|
8
|
+
ChannelEvents,
|
|
9
|
+
PostgresChangesPayload,
|
|
10
|
+
RawPresenceDiff,
|
|
11
|
+
RawPresenceState,
|
|
12
|
+
RealtimeChannelOptions,
|
|
13
|
+
RealtimePostgresChangesListenEvent,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Message(BaseModel):
|
|
18
|
+
"""
|
|
19
|
+
Dataclass abstraction for message
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
event: str
|
|
23
|
+
payload: Mapping[str, Any]
|
|
24
|
+
topic: str
|
|
25
|
+
ref: str | None = None
|
|
26
|
+
join_ref: str | None = None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class JoinMessage(BaseModel):
|
|
30
|
+
event: Literal[ChannelEvents.join]
|
|
31
|
+
topic: str
|
|
32
|
+
ref: str
|
|
33
|
+
payload: RealtimeChannelOptions
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class PostgresRowChange(BaseModel):
|
|
37
|
+
id: int
|
|
38
|
+
event: RealtimePostgresChangesListenEvent
|
|
39
|
+
table: str | None = None
|
|
40
|
+
schema_: str | None = Field(alias="schema", default=None)
|
|
41
|
+
filter: str | None = None
|
|
42
|
+
select: list[str] | None = None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class ReplyPostgresChanges(BaseModel):
|
|
46
|
+
postgres_changes: list[PostgresRowChange] | None = None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class SuccessReplyMessage(BaseModel):
|
|
50
|
+
status: Literal["ok"]
|
|
51
|
+
response: ReplyPostgresChanges
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class ErrorReplyMessage(BaseModel):
|
|
55
|
+
status: Literal["error"]
|
|
56
|
+
response: dict[str, Any] # TODO: what goes in here?
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class ReplyMessage(BaseModel):
|
|
60
|
+
event: Literal[ChannelEvents.reply]
|
|
61
|
+
topic: str
|
|
62
|
+
payload: SuccessReplyMessage | ErrorReplyMessage
|
|
63
|
+
ref: str | None
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class SuccessSystemPayload(BaseModel):
|
|
67
|
+
channel: str
|
|
68
|
+
extension: str
|
|
69
|
+
message: str
|
|
70
|
+
status: Literal["ok"]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class ErrorSystemPayload(BaseModel):
|
|
74
|
+
channel: str
|
|
75
|
+
extension: str
|
|
76
|
+
message: str
|
|
77
|
+
status: Literal["error"]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class SystemMessage(BaseModel):
|
|
81
|
+
event: Literal[ChannelEvents.system]
|
|
82
|
+
topic: str
|
|
83
|
+
payload: SuccessSystemPayload | ErrorSystemPayload
|
|
84
|
+
ref: Literal[None]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class HeartbeatPayload(BaseModel):
|
|
88
|
+
pass
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class HeartbeatMessage(BaseModel):
|
|
92
|
+
event: Literal[ChannelEvents.heartbeat]
|
|
93
|
+
topic: Literal["phoenix"]
|
|
94
|
+
ref: str
|
|
95
|
+
payload: HeartbeatPayload
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class AccessTokenPayload(BaseModel):
|
|
99
|
+
access_token: str
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class AccessTokenMessage(BaseModel):
|
|
103
|
+
event: Literal[ChannelEvents.access_token]
|
|
104
|
+
topic: str
|
|
105
|
+
payload: AccessTokenPayload
|
|
106
|
+
ref: Literal[None]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class PostgresChangesMessage(BaseModel):
|
|
110
|
+
event: Literal[ChannelEvents.postgres_changes]
|
|
111
|
+
topic: str
|
|
112
|
+
payload: PostgresChangesPayload
|
|
113
|
+
ref: Literal[None]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class BroadcastMessage(BaseModel):
|
|
117
|
+
event: Literal[ChannelEvents.broadcast]
|
|
118
|
+
topic: str
|
|
119
|
+
payload: BroadcastPayload
|
|
120
|
+
ref: Literal[None]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class PresenceMessage(BaseModel):
|
|
124
|
+
event: Literal[ChannelEvents.presence]
|
|
125
|
+
topic: str
|
|
126
|
+
payload: dict[str, Any]
|
|
127
|
+
ref: Literal[None]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class PresenceStateMessage(BaseModel):
|
|
131
|
+
event: Literal[ChannelEvents.presence_state]
|
|
132
|
+
topic: str
|
|
133
|
+
payload: RawPresenceState
|
|
134
|
+
ref: Literal[None]
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class PresenceDiffMessage(BaseModel):
|
|
138
|
+
event: Literal[ChannelEvents.presence_diff]
|
|
139
|
+
topic: str
|
|
140
|
+
payload: RawPresenceDiff
|
|
141
|
+
ref: Literal[None]
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class ChannelErrorMessage(BaseModel):
|
|
145
|
+
event: Literal[ChannelEvents.error]
|
|
146
|
+
topic: str
|
|
147
|
+
payload: dict[str, Any]
|
|
148
|
+
ref: str | None
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class ChannelCloseMessage(BaseModel):
|
|
152
|
+
event: Literal[ChannelEvents.close]
|
|
153
|
+
topic: str
|
|
154
|
+
payload: dict[str, Any]
|
|
155
|
+
ref: str | None
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
ServerMessage: TypeAlias = (
|
|
159
|
+
SystemMessage
|
|
160
|
+
| ReplyMessage
|
|
161
|
+
| HeartbeatMessage
|
|
162
|
+
| BroadcastMessage
|
|
163
|
+
| PresenceStateMessage
|
|
164
|
+
| PresenceDiffMessage
|
|
165
|
+
| PostgresChangesMessage
|
|
166
|
+
| ChannelErrorMessage
|
|
167
|
+
| ChannelCloseMessage
|
|
168
|
+
)
|
|
169
|
+
ServerMessageAdapter: TypeAdapter[ServerMessage] = TypeAdapter(ServerMessage)
|
|
170
|
+
ClientMessage: TypeAlias = (
|
|
171
|
+
JoinMessage
|
|
172
|
+
| HeartbeatMessage
|
|
173
|
+
| BroadcastMessage
|
|
174
|
+
| PresenceMessage
|
|
175
|
+
| AccessTokenMessage
|
|
176
|
+
)
|
|
File without changes
|