archastro.platform.channels.api_object_channel

  1# Copyright (c) 2026 ArchAstro Inc. Licensed under the MIT License.
  2# This file is auto-generated by @archastro/sdk-generator. Do not edit.
  3# Content hash: 97417bfbd8b3
  4
  5from collections.abc import Callable
  6from typing import TYPE_CHECKING, Any, Required, TypedDict
  7
  8if TYPE_CHECKING:
  9    from archastro.phx_channel.socket import Socket
 10
 11
 12class UpdateFieldsInput(TypedDict, total=False):
 13    fields: Required[dict[str, Any]]
 14    operation_id: str
 15
 16
 17class PresenceUpdateInput(TypedDict):
 18    presence: dict[str, Any]
 19
 20
 21class ObjectUpdatedPayload(TypedDict):
 22    fields: dict[str, Any]
 23    id: str
 24    operation_id: str
 25    partial: bool
 26
 27
 28class ObjectCreatedPayload(TypedDict):
 29    connection_id: str
 30    fields: dict[str, Any]
 31    id: str
 32    presence: list[dict[str, Any]]
 33    readonly: bool
 34
 35
 36class ObjectDeletedPayload(TypedDict):
 37    id: str
 38
 39
 40class PresenceUpdatedPayload(TypedDict):
 41    presence: dict[str, Any]
 42
 43
 44class PresenceLeftPayload(TypedDict):
 45    connection_id: str
 46
 47
 48class AccessRevokedPayload(TypedDict):
 49    reason: str
 50
 51
 52# Channel for real-time custom object collaboration.
 53# Clients join `api:object:{object_id}` to receive the current object state
 54# and subscribe to field-level updates. Mutations are sent as key:value maps.
 55class ApiObjectChannel:
 56    def __init__(self, channel, join_response=None):
 57        self._channel = channel
 58        self.join_response = join_response
 59
 60    @staticmethod
 61    def topic_by_id(object_id: str) -> str:
 62        return f"api:object:{object_id}"
 63
 64    @classmethod
 65    async def join_by_id(
 66        cls,
 67        socket: "Socket",
 68        object_id: str,
 69        *,
 70        connection_id: str | None = None,
 71        partial_updates: bool | None = None,
 72    ) -> "ApiObjectChannel":
 73        topic = cls.topic_by_id(object_id)
 74        channel = socket.channel(topic)
 75        payload: dict[str, object] = {}
 76        if connection_id is not None:
 77            payload["connection_id"] = connection_id
 78        if partial_updates is not None:
 79            payload["partial_updates"] = partial_updates
 80        join_response = await channel.join(payload)
 81        return cls(channel, join_response)
 82
 83    @staticmethod
 84    def topic_by_row_key(schema_type: str, row_key: str) -> str:
 85        return f"api:object:{schema_type}:{row_key}"
 86
 87    @classmethod
 88    async def join_by_row_key(
 89        cls,
 90        socket: "Socket",
 91        schema_type: str,
 92        row_key: str,
 93        *,
 94        connection_id: str | None = None,
 95        partial_updates: bool | None = None,
 96    ) -> "ApiObjectChannel":
 97        topic = cls.topic_by_row_key(schema_type, row_key)
 98        channel = socket.channel(topic)
 99        payload: dict[str, object] = {}
100        if connection_id is not None:
101            payload["connection_id"] = connection_id
102        if partial_updates is not None:
103            payload["partial_updates"] = partial_updates
104        join_response = await channel.join(payload)
105        return cls(channel, join_response)
106
107    # Leave the underlying channel.
108    async def leave(self):
109        await self._channel.leave()
110
111    async def update_fields(self, payload: UpdateFieldsInput) -> dict[str, Any]:
112        return await self._channel.push("update_fields", payload)
113
114    async def save(self, payload: dict) -> dict[str, Any]:
115        return await self._channel.push("save", payload)
116
117    async def presence_update(self, payload: PresenceUpdateInput) -> dict[str, Any]:
118        return await self._channel.push("presence_update", payload)
119
120    def on_object_updated(
121        self, callback: Callable[[ObjectUpdatedPayload], None]
122    ) -> Callable[[], None]:
123        return self._channel.on("object_updated", callback)
124
125    def on_object_created(
126        self, callback: Callable[[ObjectCreatedPayload], None]
127    ) -> Callable[[], None]:
128        return self._channel.on("object_created", callback)
129
130    def on_object_deleted(
131        self, callback: Callable[[ObjectDeletedPayload], None]
132    ) -> Callable[[], None]:
133        return self._channel.on("object_deleted", callback)
134
135    def on_presence_updated(
136        self, callback: Callable[[PresenceUpdatedPayload], None]
137    ) -> Callable[[], None]:
138        return self._channel.on("presence_updated", callback)
139
140    def on_presence_left(
141        self, callback: Callable[[PresenceLeftPayload], None]
142    ) -> Callable[[], None]:
143        return self._channel.on("presence_left", callback)
144
145    def on_access_revoked(
146        self, callback: Callable[[AccessRevokedPayload], None]
147    ) -> Callable[[], None]:
148        return self._channel.on("access_revoked", callback)
class UpdateFieldsInput(typing.TypedDict):
13class UpdateFieldsInput(TypedDict, total=False):
14    fields: Required[dict[str, Any]]
15    operation_id: str
fields: Required[dict[str, Any]]
operation_id: str
class PresenceUpdateInput(typing.TypedDict):
18class PresenceUpdateInput(TypedDict):
19    presence: dict[str, Any]
presence: dict[str, typing.Any]
class ObjectUpdatedPayload(typing.TypedDict):
22class ObjectUpdatedPayload(TypedDict):
23    fields: dict[str, Any]
24    id: str
25    operation_id: str
26    partial: bool
fields: dict[str, typing.Any]
id: str
operation_id: str
partial: bool
class ObjectCreatedPayload(typing.TypedDict):
29class ObjectCreatedPayload(TypedDict):
30    connection_id: str
31    fields: dict[str, Any]
32    id: str
33    presence: list[dict[str, Any]]
34    readonly: bool
connection_id: str
fields: dict[str, typing.Any]
id: str
presence: list[dict[str, typing.Any]]
readonly: bool
class ObjectDeletedPayload(typing.TypedDict):
37class ObjectDeletedPayload(TypedDict):
38    id: str
id: str
class PresenceUpdatedPayload(typing.TypedDict):
41class PresenceUpdatedPayload(TypedDict):
42    presence: dict[str, Any]
presence: dict[str, typing.Any]
class PresenceLeftPayload(typing.TypedDict):
45class PresenceLeftPayload(TypedDict):
46    connection_id: str
connection_id: str
class AccessRevokedPayload(typing.TypedDict):
49class AccessRevokedPayload(TypedDict):
50    reason: str
reason: str
class ApiObjectChannel:
 56class ApiObjectChannel:
 57    def __init__(self, channel, join_response=None):
 58        self._channel = channel
 59        self.join_response = join_response
 60
 61    @staticmethod
 62    def topic_by_id(object_id: str) -> str:
 63        return f"api:object:{object_id}"
 64
 65    @classmethod
 66    async def join_by_id(
 67        cls,
 68        socket: "Socket",
 69        object_id: str,
 70        *,
 71        connection_id: str | None = None,
 72        partial_updates: bool | None = None,
 73    ) -> "ApiObjectChannel":
 74        topic = cls.topic_by_id(object_id)
 75        channel = socket.channel(topic)
 76        payload: dict[str, object] = {}
 77        if connection_id is not None:
 78            payload["connection_id"] = connection_id
 79        if partial_updates is not None:
 80            payload["partial_updates"] = partial_updates
 81        join_response = await channel.join(payload)
 82        return cls(channel, join_response)
 83
 84    @staticmethod
 85    def topic_by_row_key(schema_type: str, row_key: str) -> str:
 86        return f"api:object:{schema_type}:{row_key}"
 87
 88    @classmethod
 89    async def join_by_row_key(
 90        cls,
 91        socket: "Socket",
 92        schema_type: str,
 93        row_key: str,
 94        *,
 95        connection_id: str | None = None,
 96        partial_updates: bool | None = None,
 97    ) -> "ApiObjectChannel":
 98        topic = cls.topic_by_row_key(schema_type, row_key)
 99        channel = socket.channel(topic)
100        payload: dict[str, object] = {}
101        if connection_id is not None:
102            payload["connection_id"] = connection_id
103        if partial_updates is not None:
104            payload["partial_updates"] = partial_updates
105        join_response = await channel.join(payload)
106        return cls(channel, join_response)
107
108    # Leave the underlying channel.
109    async def leave(self):
110        await self._channel.leave()
111
112    async def update_fields(self, payload: UpdateFieldsInput) -> dict[str, Any]:
113        return await self._channel.push("update_fields", payload)
114
115    async def save(self, payload: dict) -> dict[str, Any]:
116        return await self._channel.push("save", payload)
117
118    async def presence_update(self, payload: PresenceUpdateInput) -> dict[str, Any]:
119        return await self._channel.push("presence_update", payload)
120
121    def on_object_updated(
122        self, callback: Callable[[ObjectUpdatedPayload], None]
123    ) -> Callable[[], None]:
124        return self._channel.on("object_updated", callback)
125
126    def on_object_created(
127        self, callback: Callable[[ObjectCreatedPayload], None]
128    ) -> Callable[[], None]:
129        return self._channel.on("object_created", callback)
130
131    def on_object_deleted(
132        self, callback: Callable[[ObjectDeletedPayload], None]
133    ) -> Callable[[], None]:
134        return self._channel.on("object_deleted", callback)
135
136    def on_presence_updated(
137        self, callback: Callable[[PresenceUpdatedPayload], None]
138    ) -> Callable[[], None]:
139        return self._channel.on("presence_updated", callback)
140
141    def on_presence_left(
142        self, callback: Callable[[PresenceLeftPayload], None]
143    ) -> Callable[[], None]:
144        return self._channel.on("presence_left", callback)
145
146    def on_access_revoked(
147        self, callback: Callable[[AccessRevokedPayload], None]
148    ) -> Callable[[], None]:
149        return self._channel.on("access_revoked", callback)
ApiObjectChannel(channel, join_response=None)
57    def __init__(self, channel, join_response=None):
58        self._channel = channel
59        self.join_response = join_response
join_response
@staticmethod
def topic_by_id(object_id: str) -> str:
61    @staticmethod
62    def topic_by_id(object_id: str) -> str:
63        return f"api:object:{object_id}"
@classmethod
async def join_by_id( cls, socket: archastro.phx_channel.Socket, object_id: str, *, connection_id: str | None = None, partial_updates: bool | None = None) -> ApiObjectChannel:
65    @classmethod
66    async def join_by_id(
67        cls,
68        socket: "Socket",
69        object_id: str,
70        *,
71        connection_id: str | None = None,
72        partial_updates: bool | None = None,
73    ) -> "ApiObjectChannel":
74        topic = cls.topic_by_id(object_id)
75        channel = socket.channel(topic)
76        payload: dict[str, object] = {}
77        if connection_id is not None:
78            payload["connection_id"] = connection_id
79        if partial_updates is not None:
80            payload["partial_updates"] = partial_updates
81        join_response = await channel.join(payload)
82        return cls(channel, join_response)
@staticmethod
def topic_by_row_key(schema_type: str, row_key: str) -> str:
84    @staticmethod
85    def topic_by_row_key(schema_type: str, row_key: str) -> str:
86        return f"api:object:{schema_type}:{row_key}"
@classmethod
async def join_by_row_key( cls, socket: archastro.phx_channel.Socket, schema_type: str, row_key: str, *, connection_id: str | None = None, partial_updates: bool | None = None) -> ApiObjectChannel:
 88    @classmethod
 89    async def join_by_row_key(
 90        cls,
 91        socket: "Socket",
 92        schema_type: str,
 93        row_key: str,
 94        *,
 95        connection_id: str | None = None,
 96        partial_updates: bool | None = None,
 97    ) -> "ApiObjectChannel":
 98        topic = cls.topic_by_row_key(schema_type, row_key)
 99        channel = socket.channel(topic)
100        payload: dict[str, object] = {}
101        if connection_id is not None:
102            payload["connection_id"] = connection_id
103        if partial_updates is not None:
104            payload["partial_updates"] = partial_updates
105        join_response = await channel.join(payload)
106        return cls(channel, join_response)
async def leave(self):
109    async def leave(self):
110        await self._channel.leave()
async def update_fields( self, payload: UpdateFieldsInput) -> dict[str, typing.Any]:
112    async def update_fields(self, payload: UpdateFieldsInput) -> dict[str, Any]:
113        return await self._channel.push("update_fields", payload)
async def save(self, payload: dict) -> dict[str, typing.Any]:
115    async def save(self, payload: dict) -> dict[str, Any]:
116        return await self._channel.push("save", payload)
async def presence_update( self, payload: PresenceUpdateInput) -> dict[str, typing.Any]:
118    async def presence_update(self, payload: PresenceUpdateInput) -> dict[str, Any]:
119        return await self._channel.push("presence_update", payload)
def on_object_updated( self, callback: Callable[[ObjectUpdatedPayload], None]) -> Callable[[], None]:
121    def on_object_updated(
122        self, callback: Callable[[ObjectUpdatedPayload], None]
123    ) -> Callable[[], None]:
124        return self._channel.on("object_updated", callback)
def on_object_created( self, callback: Callable[[ObjectCreatedPayload], None]) -> Callable[[], None]:
126    def on_object_created(
127        self, callback: Callable[[ObjectCreatedPayload], None]
128    ) -> Callable[[], None]:
129        return self._channel.on("object_created", callback)
def on_object_deleted( self, callback: Callable[[ObjectDeletedPayload], None]) -> Callable[[], None]:
131    def on_object_deleted(
132        self, callback: Callable[[ObjectDeletedPayload], None]
133    ) -> Callable[[], None]:
134        return self._channel.on("object_deleted", callback)
def on_presence_updated( self, callback: Callable[[PresenceUpdatedPayload], None]) -> Callable[[], None]:
136    def on_presence_updated(
137        self, callback: Callable[[PresenceUpdatedPayload], None]
138    ) -> Callable[[], None]:
139        return self._channel.on("presence_updated", callback)
def on_presence_left( self, callback: Callable[[PresenceLeftPayload], None]) -> Callable[[], None]:
141    def on_presence_left(
142        self, callback: Callable[[PresenceLeftPayload], None]
143    ) -> Callable[[], None]:
144        return self._channel.on("presence_left", callback)
def on_access_revoked( self, callback: Callable[[AccessRevokedPayload], None]) -> Callable[[], None]:
146    def on_access_revoked(
147        self, callback: Callable[[AccessRevokedPayload], None]
148    ) -> Callable[[], None]:
149        return self._channel.on("access_revoked", callback)