@base44-preview/sdk 0.8.53-pr.289.545edf7 → 0.8.53-pr.289.762dbd5
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.
- package/dist/modules/actors.types.d.ts +36 -32
- package/package.json +1 -1
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Maps actor names to their incoming and outgoing message types.
|
|
3
3
|
*
|
|
4
|
-
* Extend this interface when you want typed actor
|
|
5
|
-
* messages without generating types with the CLI
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Extend this interface through module augmentation when you want typed actor
|
|
5
|
+
* messages without generating types with the CLI. For each actor, `toServer`
|
|
6
|
+
* defines incoming messages that a client sends to the actor. `toClient` defines
|
|
7
|
+
* outgoing messages that the actor sends to connected clients.
|
|
8
8
|
*
|
|
9
|
-
* To generate types from deployed actors, use the
|
|
9
|
+
* To generate types from deployed actors instead, use the
|
|
10
10
|
* [`types generate`](/developers/references/cli/commands/types-generate) CLI command.
|
|
11
|
-
*
|
|
12
11
|
* To learn how incoming and outgoing messages work, see
|
|
13
12
|
* [message types](/developers/backend/resources/actors/overview#message-types).
|
|
14
13
|
*
|
|
@@ -32,7 +31,7 @@ export interface ActorRegistry {
|
|
|
32
31
|
* with [`types generate`](/developers/references/cli/commands/types-generate).
|
|
33
32
|
*
|
|
34
33
|
* The generated names provide autocomplete for deployed actors. To define
|
|
35
|
-
* incoming and outgoing message types manually, augment
|
|
34
|
+
* incoming and outgoing message types manually, augment [ActorRegistry](#actorregistry).
|
|
36
35
|
*/
|
|
37
36
|
export interface ActorNameRegistry {
|
|
38
37
|
}
|
|
@@ -44,21 +43,24 @@ type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
|
|
|
44
43
|
toServer: infer O;
|
|
45
44
|
} ? O : unknown : unknown;
|
|
46
45
|
/**
|
|
47
|
-
* Configures the connection that
|
|
46
|
+
* Configures the connection that [ActorRef.connect](#connect) opens.
|
|
48
47
|
*/
|
|
49
48
|
export interface ActorConnectOptions {
|
|
50
49
|
/**
|
|
51
50
|
* Connection ID that the actor receives as `conn.id`.
|
|
52
51
|
*
|
|
53
|
-
* To let the actor recognize
|
|
52
|
+
* To let the actor recognize the same client if it reconnects, use a stable
|
|
54
53
|
* value, such as an ID stored per browser tab. If you omit this property, the
|
|
55
|
-
* SDK generates a
|
|
54
|
+
* SDK generates a connection ID.
|
|
55
|
+
*
|
|
56
|
+
* For more about connection IDs, see
|
|
57
|
+
* [connections](/developers/backend/resources/actors/reference#connections).
|
|
56
58
|
*/
|
|
57
59
|
id?: string;
|
|
58
60
|
}
|
|
59
61
|
/**
|
|
60
62
|
* Represents a listener for messages from the actor, registered with
|
|
61
|
-
*
|
|
63
|
+
* [Connection.subscribe](#subscribe).
|
|
62
64
|
*/
|
|
63
65
|
export interface ActorSubscription {
|
|
64
66
|
/**
|
|
@@ -73,11 +75,10 @@ export interface ActorSubscription {
|
|
|
73
75
|
unsubscribe(): void;
|
|
74
76
|
}
|
|
75
77
|
/**
|
|
76
|
-
* Represents a client's WebSocket connection to an actor session
|
|
77
|
-
* [`connect()`](#connect). The socket queues messages you send before it opens.
|
|
78
|
+
* Represents a client's WebSocket connection to an actor session.
|
|
78
79
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
80
|
+
* [ActorRef.connect](#connect) returns this object. The socket buffers messages
|
|
81
|
+
* you send before it opens.
|
|
81
82
|
*/
|
|
82
83
|
export interface Connection<N extends string = string> {
|
|
83
84
|
/** Connection ID that the actor receives as `conn.id`. */
|
|
@@ -105,10 +106,10 @@ export interface Connection<N extends string = string> {
|
|
|
105
106
|
/**
|
|
106
107
|
* Sends a message to the actor.
|
|
107
108
|
*
|
|
108
|
-
* The socket
|
|
109
|
-
* the socket drops
|
|
109
|
+
* The socket buffers messages until it opens. After you call [close](#close),
|
|
110
|
+
* the socket drops further sends.
|
|
110
111
|
*
|
|
111
|
-
* @param data - Message to send to the actor. The type comes from
|
|
112
|
+
* @param data - Message to send to the actor. The type comes from [ActorRegistry](#actorregistry) when you register the actor there.
|
|
112
113
|
*
|
|
113
114
|
* @example
|
|
114
115
|
* ```typescript
|
|
@@ -121,7 +122,8 @@ export interface Connection<N extends string = string> {
|
|
|
121
122
|
* Closes the connection and removes all listeners.
|
|
122
123
|
*
|
|
123
124
|
* You can call this method more than once. A connection also closes itself
|
|
124
|
-
* when it fails permanently.
|
|
125
|
+
* when it fails permanently. To open a new connection, call
|
|
126
|
+
* [ActorRef.connect](#connect) again.
|
|
125
127
|
*
|
|
126
128
|
* @example
|
|
127
129
|
* ```typescript
|
|
@@ -134,20 +136,22 @@ export interface Connection<N extends string = string> {
|
|
|
134
136
|
/**
|
|
135
137
|
* Represents a reference to an actor session, identified by actor name and session ID.
|
|
136
138
|
*
|
|
137
|
-
* Call
|
|
139
|
+
* Call [connect](#connect) to open the WebSocket and get a [Connection](#connection).
|
|
138
140
|
*/
|
|
139
141
|
export interface ActorRef<N extends string = string> {
|
|
140
142
|
/**
|
|
141
|
-
* Creates or returns the [Connection](#
|
|
143
|
+
* Creates or returns the [Connection](#connection) for this session.
|
|
142
144
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
+
* Repeated calls return the same connection until it closes. If the connection
|
|
146
|
+
* fails permanently, for example because the actor doesn't exist or the actor
|
|
147
|
+
* denies the connection, fix the cause and call `connect()` again. Then
|
|
148
|
+
* subscribe again on the new connection.
|
|
145
149
|
*
|
|
146
150
|
* For a sample flow, see
|
|
147
151
|
* [connect a client to a session](/developers/backend/resources/actors/sample-flows#connect-a-client-to-a-session).
|
|
148
152
|
*
|
|
149
153
|
* @param options - Optional connection settings, such as a stable connection ID.
|
|
150
|
-
* @returns The [Connection](#
|
|
154
|
+
* @returns The [Connection](#connection) for this actor session.
|
|
151
155
|
*
|
|
152
156
|
* @example
|
|
153
157
|
* ```typescript
|
|
@@ -161,7 +165,7 @@ export interface ActorRef<N extends string = string> {
|
|
|
161
165
|
* Selects a session for a named actor.
|
|
162
166
|
*
|
|
163
167
|
* TypeScript infers message types when you register the actor in
|
|
164
|
-
*
|
|
168
|
+
* [ActorRegistry](#actorregistry). [ActorNameRegistry](#actornameregistry)
|
|
165
169
|
* provides autocomplete for actor names only.
|
|
166
170
|
*/
|
|
167
171
|
export interface ActorClient<N extends string = string> {
|
|
@@ -182,19 +186,19 @@ export interface ActorClient<N extends string = string> {
|
|
|
182
186
|
(instanceId: string): ActorRef<N>;
|
|
183
187
|
}
|
|
184
188
|
/**
|
|
185
|
-
* Actors module for connecting a client to an [actor](/developers/backend/resources/actors/overview)
|
|
189
|
+
* Actors module for connecting a client to an [actor](/developers/backend/resources/actors/overview) session and exchanging messages.
|
|
186
190
|
*
|
|
187
191
|
* An actor is a long-running backend process that multiple clients connect to simultaneously. A session
|
|
188
192
|
* is a running instance of an actor, identified by the actor name and a session ID. Each
|
|
189
193
|
* session manages its own state, storage, and client connections independently.
|
|
190
194
|
*
|
|
191
|
-
* The actors module supports
|
|
195
|
+
* The actors module supports the following functionality:
|
|
192
196
|
*
|
|
193
|
-
* -
|
|
194
|
-
* -
|
|
195
|
-
* -
|
|
196
|
-
* -
|
|
197
|
-
* -
|
|
197
|
+
* - [`connect()`](#connect): Open a WebSocket connection to a session.
|
|
198
|
+
* - [`subscribe()`](#subscribe): Receive messages from the actor.
|
|
199
|
+
* - [`unsubscribe()`](#unsubscribe): Stop receiving messages from the actor without closing the connection.
|
|
200
|
+
* - [`send()`](#send): Send messages to the actor.
|
|
201
|
+
* - [`close()`](#close): Close the WebSocket connection to the actor.
|
|
198
202
|
*
|
|
199
203
|
* For a sample flow, see
|
|
200
204
|
* [connect a client to a session](/developers/backend/resources/actors/sample-flows#connect-a-client-to-a-session).
|