@base44-preview/sdk 0.8.53-pr.308.2df7905 → 0.8.53-pr.311.53c78b4
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/actor.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ export interface Storage {
|
|
|
25
25
|
get<T>(key: string): Promise<T | undefined>;
|
|
26
26
|
put(key: string, value: unknown): Promise<void>;
|
|
27
27
|
delete(key: string): Promise<boolean>;
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
28
|
+
/** Deletes all persisted storage for the session. A later connection starts
|
|
29
|
+
* with empty storage, the same as a new session. */
|
|
30
30
|
deleteAll(): Promise<void>;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* for your deployed Actors.
|
|
2
|
+
* Maps actor names to their incoming and outgoing message types.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Extend this interface when you want typed actor
|
|
5
|
+
* messages without generating types with the CLI:
|
|
6
|
+
* - `toServer`: Defines incoming messages that a client sends to the actor.
|
|
7
|
+
* - `toClient`: Defines outgoing messages that the actor sends to connected clients.
|
|
8
|
+
*
|
|
9
|
+
* To generate types from deployed actors, use the
|
|
10
|
+
* [`types generate`](/developers/references/cli/commands/types-generate) CLI command.
|
|
11
|
+
*
|
|
12
|
+
* To learn how incoming and outgoing messages work, see
|
|
13
|
+
* [message types](/developers/backend/resources/actors/overview#message-types).
|
|
7
14
|
*
|
|
8
15
|
* @example
|
|
9
16
|
* ```typescript
|
|
17
|
+
* // Type messages for an actor
|
|
10
18
|
* declare module "@base44/sdk" {
|
|
11
19
|
* interface ActorRegistry {
|
|
12
|
-
*
|
|
20
|
+
* chatRoom: {
|
|
13
21
|
* toClient: { type: "joined" | "left" | "message"; userId?: string; from?: string; text?: string };
|
|
14
22
|
* toServer: { type: "message"; text: string };
|
|
15
23
|
* };
|
|
@@ -20,8 +28,11 @@
|
|
|
20
28
|
export interface ActorRegistry {
|
|
21
29
|
}
|
|
22
30
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
31
|
+
* Lists actor names when your project includes types generated by the CLI
|
|
32
|
+
* with [`types generate`](/developers/references/cli/commands/types-generate).
|
|
33
|
+
*
|
|
34
|
+
* The generated names provide autocomplete for deployed actors. To define
|
|
35
|
+
* incoming and outgoing message types manually, augment {@linkcode ActorRegistry}.
|
|
25
36
|
*/
|
|
26
37
|
export interface ActorNameRegistry {
|
|
27
38
|
}
|
|
@@ -32,75 +43,169 @@ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
|
|
|
32
43
|
type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
|
|
33
44
|
toServer: infer O;
|
|
34
45
|
} ? O : unknown : unknown;
|
|
35
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Configures the connection that {@linkcode ActorRef.connect | connect()} opens.
|
|
48
|
+
*/
|
|
36
49
|
export interface ActorConnectOptions {
|
|
37
50
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
51
|
+
* Connection ID that the actor receives as `conn.id`.
|
|
52
|
+
*
|
|
53
|
+
* To let the actor recognize a client when it reconnects, use a stable
|
|
54
|
+
* value, such as an ID stored per browser tab. If you omit this property, the
|
|
55
|
+
* SDK generates a new connection ID.
|
|
41
56
|
*/
|
|
42
57
|
id?: string;
|
|
43
58
|
}
|
|
44
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Represents a listener for messages from the actor, registered with
|
|
61
|
+
* {@linkcode Connection.subscribe | subscribe()}.
|
|
62
|
+
*/
|
|
45
63
|
export interface ActorSubscription {
|
|
46
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Removes this listener. Other listeners and the socket stay open.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* // Remove a listener
|
|
70
|
+
* sub.unsubscribe();
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
47
73
|
unsubscribe(): void;
|
|
48
74
|
}
|
|
49
75
|
/**
|
|
50
|
-
*
|
|
51
|
-
* `
|
|
52
|
-
*
|
|
76
|
+
* Represents a client's [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) connection to an actor session, returned after calling
|
|
77
|
+
* [`connect()`](#connect). The WebSocket queues messages you send before it opens.
|
|
78
|
+
*
|
|
79
|
+
* Learn more about
|
|
80
|
+
* [connections](/developers/backend/resources/actors/reference#connections).
|
|
53
81
|
*/
|
|
54
82
|
export interface Connection<N extends string = string> {
|
|
55
|
-
/**
|
|
83
|
+
/** Connection ID that the actor receives as `conn.id`. */
|
|
56
84
|
readonly id: string;
|
|
57
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Registers a listener for messages from the actor.
|
|
87
|
+
*
|
|
88
|
+
* You can register multiple listeners on the same connection.
|
|
89
|
+
*
|
|
90
|
+
* @param callback - Callback that runs for each message the actor sends to this connection.
|
|
91
|
+
* @returns A subscription handle. Call `unsubscribe()` on it to remove this listener without closing the socket.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // Listen for messages from the actor
|
|
96
|
+
* const sub = conn.subscribe((msg) => {
|
|
97
|
+
* console.log(msg);
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* // Stop listening without closing the socket.
|
|
101
|
+
* sub.unsubscribe();
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
58
104
|
subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
105
|
+
/**
|
|
106
|
+
* Sends a message to the actor.
|
|
107
|
+
*
|
|
108
|
+
* The WebSocket queues messages until it opens. When you call {@linkcode Connection.close | close()},
|
|
109
|
+
* the WebSocket drops any messages you send afterward.
|
|
110
|
+
*
|
|
111
|
+
* @param data - Message to send to the actor. The type comes from {@linkcode ActorRegistry} when you register the actor there.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* // Send a message to the actor
|
|
116
|
+
* conn.send({ type: "message", text: "Hello" });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
61
119
|
send(data: ToServerFor<N>): void;
|
|
62
120
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
121
|
+
* Closes the connection and removes all listeners.
|
|
122
|
+
*
|
|
123
|
+
* You can call this method more than once. A connection also closes itself
|
|
124
|
+
* when it fails permanently.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* // Close the connection
|
|
129
|
+
* conn.close();
|
|
130
|
+
* ```
|
|
66
131
|
*/
|
|
67
132
|
close(): void;
|
|
68
133
|
}
|
|
69
134
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
135
|
+
* Represents a reference to an actor session, identified by actor name and session ID.
|
|
136
|
+
*
|
|
137
|
+
* Call {@linkcode ActorRef.connect | connect()} to open the WebSocket and get a [connection](/developers/backend/resources/actors/overview#connections).
|
|
72
138
|
*/
|
|
73
139
|
export interface ActorRef<N extends string = string> {
|
|
74
140
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
141
|
+
* Creates or returns the connection for this session.
|
|
142
|
+
*
|
|
143
|
+
* Calling `connect()` again on the same session reference returns the same
|
|
144
|
+
* connection until it closes.
|
|
145
|
+
*
|
|
146
|
+
* For a sample flow, see
|
|
147
|
+
* [connect a client to a session](/developers/backend/resources/actors/sample-flows#connect-a-client-to-a-session).
|
|
77
148
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
149
|
+
* @param options - Optional connection settings, such as a stable connection ID.
|
|
150
|
+
* @returns The connection for this actor session.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* // Connect to a session
|
|
155
|
+
* const conn = base44.actors.chatRoom("session-1").connect({ id: "tab-1" });
|
|
156
|
+
* ```
|
|
82
157
|
*/
|
|
83
158
|
connect(options?: ActorConnectOptions): Connection<N>;
|
|
84
159
|
}
|
|
85
160
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
161
|
+
* Selects a session for a named actor.
|
|
162
|
+
*
|
|
163
|
+
* TypeScript infers message types when you register the actor in
|
|
164
|
+
* {@linkcode ActorRegistry}. {@linkcode ActorNameRegistry}
|
|
165
|
+
* provides autocomplete for actor names only.
|
|
89
166
|
*/
|
|
90
167
|
export interface ActorClient<N extends string = string> {
|
|
168
|
+
/**
|
|
169
|
+
* Gets a reference to an actor session.
|
|
170
|
+
*
|
|
171
|
+
* Clients that specify the same actor name and session ID join the same session.
|
|
172
|
+
*
|
|
173
|
+
* @param instanceId - Session ID that identifies which session to connect to.
|
|
174
|
+
* @returns A reference to the actor session.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* // Select a session
|
|
179
|
+
* const session = base44.actors.chatRoom("session-1");
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
91
182
|
(instanceId: string): ActorRef<N>;
|
|
92
183
|
}
|
|
93
184
|
/**
|
|
94
|
-
*
|
|
95
|
-
* Actors deployed by the Base44 platform.
|
|
185
|
+
* Actors module for interacting with [actors](/developers/backend/resources/actors/overview) from your app.
|
|
96
186
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
187
|
+
* An actor is a long-running backend process that multiple clients connect to simultaneously. A session
|
|
188
|
+
* is a running instance of an actor, identified by the actor name and a session ID. Each
|
|
189
|
+
* session manages its own state, storage, and client connections independently.
|
|
190
|
+
*
|
|
191
|
+
* The actors module provides the functionality to:
|
|
192
|
+
*
|
|
193
|
+
* - Manage connections: {@link ActorRef.connect | Open} and {@link Connection.close | close} a WebSocket connection to a session.
|
|
194
|
+
* - Exchange messages: {@link Connection.send | Send} and {@link Connection.subscribe | listen} for messages to and from an actor.
|
|
195
|
+
* - Manage subscriptions: {@link Connection.subscribe | Subscribe} and {@link ActorSubscription.unsubscribe | unsubscribe} from actor messages without closing the connection.
|
|
196
|
+
*
|
|
197
|
+
* For a sample flow, see
|
|
198
|
+
* [connect a client to a session](/developers/backend/resources/actors/sample-flows#connect-a-client-to-a-session).
|
|
199
|
+
*
|
|
200
|
+
* ## Authentication modes
|
|
201
|
+
*
|
|
202
|
+
* This module is available to use with a client in anonymous or user authentication mode. Access it
|
|
203
|
+
* through `base44.actors`. It isn't available in
|
|
204
|
+
* [service role authentication mode](/developers/references/sdk/getting-started/client#service-role).
|
|
205
|
+
*
|
|
206
|
+
* The actor receives each client's [identity](/developers/backend/resources/actors/reference#connections)
|
|
207
|
+
* when the client connects. A client that hasn't logged in connects as anonymous, and a client that
|
|
208
|
+
* has [logged in](/developers/references/sdk/docs/interfaces/auth) connects as authenticated.
|
|
104
209
|
*/
|
|
105
210
|
export type ActorsModule = {
|
|
106
211
|
[K in AllActorNames]: K extends keyof ActorRegistry ? ActorClient<string & K> : ActorClient;
|
|
@@ -470,7 +470,7 @@ export interface UserConnectorsModule {
|
|
|
470
470
|
* authenticate with the external service. The scopes and integration type are
|
|
471
471
|
* derived from the connector configuration in the backend.
|
|
472
472
|
*
|
|
473
|
-
* @param connectorId - The ID of the app user connector configured in your workspace. The AI
|
|
473
|
+
* @param connectorId - The ID of the app user connector configured in your workspace. The AI inserts this ID into generated code when it sets up the connector flow. You can also retrieve it from the workspace connectors API.
|
|
474
474
|
* @returns Promise resolving to the redirect URL string.
|
|
475
475
|
*
|
|
476
476
|
* @example
|
|
@@ -489,7 +489,7 @@ export interface UserConnectorsModule {
|
|
|
489
489
|
* Removes the stored OAuth credentials for the currently authenticated app user's
|
|
490
490
|
* connection to the specified connector.
|
|
491
491
|
*
|
|
492
|
-
* @param connectorId - The ID of the app user connector configured in your workspace. The AI
|
|
492
|
+
* @param connectorId - The ID of the app user connector configured in your workspace. The AI inserts this ID into generated code when it sets up the connector flow. You can also retrieve it from the workspace connectors API.
|
|
493
493
|
* @returns Promise resolving when the connection has been removed.
|
|
494
494
|
*
|
|
495
495
|
* @example
|