@base44-preview/sdk 0.8.52-pr.307.064de09 → 0.8.53-pr.289.39e1f1f

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
- /** Wipe the room's entire persisted storage (match-end cleanup). Safe: a
29
- * later rejoin re-bootstraps exactly like a brand-new room. */
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,22 @@
1
1
  /**
2
- * Extend this interface to add typed `subscribe` callbacks and `send` payloads
3
- * for your deployed Actors.
2
+ * Maps actor names to their incoming and outgoing message types.
4
3
  *
5
- * This is separate from {@link ActorNameRegistry} (which is auto-generated
6
- * by `base44 types generate`), so there are no conflicts.
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
+ *
9
+ * To generate types from deployed actors instead, use the
10
+ * [`types generate`](/developers/references/cli/commands/types-generate) CLI command.
11
+ * To learn how incoming and outgoing messages work, see
12
+ * [message types](/developers/backend/resources/actors/overview#message-types).
7
13
  *
8
14
  * @example
9
15
  * ```typescript
16
+ * // Type messages for an actor
10
17
  * declare module "@base44/sdk" {
11
18
  * interface ActorRegistry {
12
- * ChatRoom: {
19
+ * chatRoom: {
13
20
  * toClient: { type: "joined" | "left" | "message"; userId?: string; from?: string; text?: string };
14
21
  * toServer: { type: "message"; text: string };
15
22
  * };
@@ -20,8 +27,11 @@
20
27
  export interface ActorRegistry {
21
28
  }
22
29
  /**
23
- * Auto-populated by `base44 types generate` with the names of your deployed actors.
24
- * Do not edit this interface manually — use {@link ActorRegistry} for message types.
30
+ * Lists actor names when your project includes types generated by the CLI
31
+ * with [`types generate`](/developers/references/cli/commands/types-generate).
32
+ *
33
+ * The generated names provide autocomplete for deployed actors. To define
34
+ * incoming and outgoing message types manually, augment [ActorRegistry](#actorregistry).
25
35
  */
26
36
  export interface ActorNameRegistry {
27
37
  }
@@ -32,71 +42,173 @@ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
32
42
  type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
33
43
  toServer: infer O;
34
44
  } ? O : unknown : unknown;
35
- /** Options for {@link ActorRef.connect}. */
45
+ /**
46
+ * Configures the connection that [ActorRef.connect](#connect) opens.
47
+ */
36
48
  export interface ActorConnectOptions {
37
49
  /**
38
- * The connection id — becomes the actor's `conn.id`. Supply a stable value
39
- * (e.g. persisted per tab) so a reconnect reuses the same server-side
40
- * identity; omit for an auto-generated per-connection id.
50
+ * Connection ID that the actor receives as `conn.id`.
51
+ *
52
+ * To let the actor recognize the same client if it reconnects, use a stable
53
+ * value, such as an ID stored per browser tab. If you omit this property, the
54
+ * SDK generates a connection ID.
55
+ *
56
+ * For more about connection IDs, see
57
+ * [connections](/developers/backend/resources/actors/reference#connections).
41
58
  */
42
59
  id?: string;
43
60
  }
44
- /** Handle for one listener registered via {@link Connection.subscribe}. */
61
+ /**
62
+ * Represents a listener for messages from the actor, registered with
63
+ * [Connection.subscribe](#subscribe).
64
+ */
45
65
  export interface ActorSubscription {
46
- /** Remove this listener; other listeners and the socket stay live. */
66
+ /**
67
+ * Removes this listener. Other listeners and the socket stay open.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * // Remove a listener
72
+ * sub.unsubscribe();
73
+ * ```
74
+ */
47
75
  unsubscribe(): void;
48
76
  }
49
77
  /**
50
- * A live connection to an actor instance, returned by {@link ActorRef.connect}.
51
- * `subscribe`/`send` are always valid — you only get a `Connection` once the
52
- * socket has been opened, so there's no pre-connect state to guard against.
78
+ * Represents a client's WebSocket connection to an actor session.
79
+ *
80
+ * [ActorRef.connect](#connect) returns this object. The socket buffers messages
81
+ * you send before it opens.
53
82
  */
54
83
  export interface Connection<N extends string = string> {
55
- /** The connection id (the value the actor sees as `conn.id`). */
84
+ /** Connection ID that the actor receives as `conn.id`. */
56
85
  readonly id: string;
57
- /** Register a message listener. Multiple are allowed; returns a per-listener unsubscribe. */
86
+ /**
87
+ * Registers a listener for messages from the actor.
88
+ *
89
+ * You can register multiple listeners on the same connection.
90
+ *
91
+ * @param callback - Callback that runs for each message the actor sends to this connection.
92
+ * @returns A subscription handle. Call `unsubscribe()` on it to remove this listener without closing the socket.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // Listen for messages from the actor
97
+ * const sub = conn.subscribe((msg) => {
98
+ * console.log(msg);
99
+ * });
100
+ *
101
+ * // Stop listening without closing the socket.
102
+ * sub.unsubscribe();
103
+ * ```
104
+ */
58
105
  subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
59
- /** Send a message. Buffered by the socket until it's open; dropped after
60
- * {@link close}. */
106
+ /**
107
+ * Sends a message to the actor.
108
+ *
109
+ * The socket buffers messages until it opens. After you call [close](#close),
110
+ * the socket drops further sends.
111
+ *
112
+ * @param data - Message to send to the actor. The type comes from [ActorRegistry](#actorregistry) when you register the actor there.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * // Send a message to the actor
117
+ * conn.send({ type: "message", text: "Hello" });
118
+ * ```
119
+ */
61
120
  send(data: ToServerFor<N>): void;
62
121
  /**
63
- * Tear down the socket, heartbeat, and all listeners. Safe to call more
64
- * than once. A connection also closes itself when it fails permanently —
65
- * see {@link ActorRef.connect}.
122
+ * Closes the connection and removes all listeners.
123
+ *
124
+ * You can call this method more than once. A connection also closes itself
125
+ * when it fails permanently. To open a new connection, call
126
+ * [ActorRef.connect](#connect) again.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * // Close the connection
131
+ * conn.close();
132
+ * ```
66
133
  */
67
134
  close(): void;
68
135
  }
69
136
  /**
70
- * A handle to one actor instance — `base44.actors.MyActor(id)`. Call
71
- * {@link connect} to open the socket and get a {@link Connection}.
137
+ * Represents a reference to an actor session, identified by actor name and session ID.
138
+ *
139
+ * Call [connect](#connect) to open the WebSocket and get a [Connection](#connection).
72
140
  */
73
141
  export interface ActorRef<N extends string = string> {
74
142
  /**
75
- * Open the WebSocket and return the {@link Connection}. Idempotent while the
76
- * connection is open.
143
+ * Creates or returns the [Connection](#connection) for this session.
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.
149
+ *
150
+ * For a sample flow, see
151
+ * [connect a client to a session](/developers/backend/resources/actors/sample-flows#connect-a-client-to-a-session).
77
152
  *
78
- * A connection that fails permanently (for example, the actor doesn't exist
79
- * or the caller isn't allowed to connect) closes itself and reports the
80
- * error to the client's `onError` handler. Call `connect()` again after
81
- * fixing the cause to get a fresh {@link Connection}, and re-subscribe.
153
+ * @param options - Optional connection settings, such as a stable connection ID.
154
+ * @returns The [Connection](#connection) for this actor session.
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * // Connect to a session
159
+ * const conn = base44.actors.chatRoom("session-1").connect({ id: "tab-1" });
160
+ * ```
82
161
  */
83
162
  connect(options?: ActorConnectOptions): Connection<N>;
84
163
  }
85
164
  /**
86
- * Client for a single named Actor — call it with an instance id to get an
87
- * {@link ActorRef}. Typed automatically when the actor is registered in
88
- * {@link ActorRegistry}.
165
+ * Selects a session for a named actor.
166
+ *
167
+ * TypeScript infers message types when you register the actor in
168
+ * [ActorRegistry](#actorregistry). [ActorNameRegistry](#actornameregistry)
169
+ * provides autocomplete for actor names only.
89
170
  */
90
171
  export interface ActorClient<N extends string = string> {
172
+ /**
173
+ * Gets a reference to an actor session.
174
+ *
175
+ * Clients that specify the same actor name and session ID join the same session.
176
+ *
177
+ * @param instanceId - Session ID that identifies which session to connect to.
178
+ * @returns A reference to the actor session.
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * // Select a session
183
+ * const session = base44.actors.chatRoom("session-1");
184
+ * ```
185
+ */
91
186
  (instanceId: string): ActorRef<N>;
92
187
  }
93
188
  /**
94
- * The actors module provides access to Cloudflare Durable Object-backed
95
- * Actors deployed by the Base44 platform.
189
+ * Connects your frontend to [actor sessions](/developers/backend/resources/actors/overview),
190
+ * shared live backend processes where clients can exchange messages in realtime.
96
191
  *
192
+ * The following table lists what you can do with the actors module:
193
+ *
194
+ * | Member | Purpose |
195
+ * |---|---|
196
+ * | [`connect()`](#connect) | Opens a connection to a session. Clients that use the same actor name and session ID join the same session. |
197
+ * | [`subscribe()`](#subscribe) | Receives messages from an actor. |
198
+ * | [`send()`](#send) | Sends a message to an actor. |
199
+ * | [`ActorRegistry`](#actorregistry) | Defines message types for autocomplete and compile-time safety. |
200
+ *
201
+ * ## Authentication modes
202
+ *
203
+ * This module is available in anonymous and user authentication modes.
204
+ * Apps that require login can reject anonymous connections in the actor's `handleConnect()` method.
205
+ * To learn more, see [manage client connections](/developers/backend/resources/actors/sample-flows#manage-client-connections).
206
+ *
207
+ * @example
97
208
  * ```typescript
98
- * const conn = base44.actors.MyActor("room-1").connect();
99
- * const sub = conn.subscribe((msg) => console.log(msg)); // typed via ActorRegistry
209
+ * // Connect, subscribe, send, and close
210
+ * const conn = base44.actors.chatRoom("session-1").connect({ id: "tab-1" });
211
+ * const sub = conn.subscribe((msg) => console.log(msg));
100
212
  * conn.send({ type: "message", text: "hi" });
101
213
  * sub.unsubscribe();
102
214
  * conn.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.52-pr.307.064de09",
3
+ "version": "0.8.53-pr.289.39e1f1f",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",