@base44-preview/sdk 0.8.37-pr.212.00d8065 → 0.8.37-pr.212.f0764ee
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/{realtime-handler.d.ts → actor.d.ts} +11 -11
- package/dist/{realtime-handler.js → actor.js} +18 -18
- package/dist/client.js +6 -6
- package/dist/client.types.d.ts +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/modules/{realtime.d.ts → actors.d.ts} +8 -8
- package/dist/modules/{realtime.js → actors.js} +13 -13
- package/dist/modules/actors.types.d.ts +77 -0
- package/package.json +1 -1
- package/dist/modules/realtime.types.d.ts +0 -77
- /package/dist/modules/{realtime.types.js → actors.types.js} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Type-only base class for
|
|
2
|
+
* Type-only base class for Actors.
|
|
3
3
|
*
|
|
4
|
-
* Import and extend this in your
|
|
5
|
-
* import {
|
|
6
|
-
* export class
|
|
4
|
+
* Import and extend this in your actor files:
|
|
5
|
+
* import { Actor } from "@base44/sdk";
|
|
6
|
+
* export class MyActor extends Actor { ... }
|
|
7
7
|
*
|
|
8
8
|
* At deploy time the bundler replaces this import with the compiled
|
|
9
9
|
* Cloudflare Durable Object implementation — this file provides types only.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import type { Base44Client } from "./client.types.js";
|
|
12
12
|
/**
|
|
13
13
|
* A single client connection. `Send` is the message type this connection accepts
|
|
14
|
-
* via {@link send} — the
|
|
14
|
+
* via {@link send} — the actor's *outgoing* (server→client) messages.
|
|
15
15
|
*/
|
|
16
16
|
export interface Conn<Send = unknown> {
|
|
17
17
|
/** Unique per-connection id (one per socket/tab), the same value the client
|
|
@@ -30,21 +30,21 @@ export interface Storage {
|
|
|
30
30
|
delete(key: string): Promise<boolean>;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* Base class for
|
|
33
|
+
* Base class for an Actor.
|
|
34
34
|
*
|
|
35
|
-
* @typeParam Incoming - messages this
|
|
35
|
+
* @typeParam Incoming - messages this actor *receives* from clients
|
|
36
36
|
* (`handleMessage`'s `msg`) — the schema's `toServer` section.
|
|
37
|
-
* @typeParam Outgoing - messages this
|
|
37
|
+
* @typeParam Outgoing - messages this actor *sends* to clients
|
|
38
38
|
* (`conn.send`/`broadcast`) — the schema's `toClient` section.
|
|
39
39
|
*
|
|
40
40
|
* With a generated `schema.jsonc`, wire both from the registry so they can't drift
|
|
41
41
|
* from the client's types:
|
|
42
42
|
* ```ts
|
|
43
|
-
* type Reg =
|
|
44
|
-
* class
|
|
43
|
+
* type Reg = ActorRegistry["MyActor"];
|
|
44
|
+
* class MyActor extends Actor<Reg["toServer"], Reg["toClient"]> { ... }
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
|
-
export declare abstract class
|
|
47
|
+
export declare abstract class Actor<Incoming = unknown, Outgoing = unknown> {
|
|
48
48
|
abstract handleConnect(conn: Conn<Outgoing>): void | Promise<void>;
|
|
49
49
|
abstract handleMessage(conn: Conn<Outgoing>, msg: Incoming): void | Promise<void>;
|
|
50
50
|
abstract handleClose(conn: Conn<Outgoing>): void | Promise<void>;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Type-only base class for
|
|
2
|
+
* Type-only base class for Actors.
|
|
3
3
|
*
|
|
4
|
-
* Import and extend this in your
|
|
5
|
-
* import {
|
|
6
|
-
* export class
|
|
4
|
+
* Import and extend this in your actor files:
|
|
5
|
+
* import { Actor } from "@base44/sdk";
|
|
6
|
+
* export class MyActor extends Actor { ... }
|
|
7
7
|
*
|
|
8
8
|
* At deploy time the bundler replaces this import with the compiled
|
|
9
9
|
* Cloudflare Durable Object implementation — this file provides types only.
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
12
|
-
* Base class for
|
|
12
|
+
* Base class for an Actor.
|
|
13
13
|
*
|
|
14
|
-
* @typeParam Incoming - messages this
|
|
14
|
+
* @typeParam Incoming - messages this actor *receives* from clients
|
|
15
15
|
* (`handleMessage`'s `msg`) — the schema's `toServer` section.
|
|
16
|
-
* @typeParam Outgoing - messages this
|
|
16
|
+
* @typeParam Outgoing - messages this actor *sends* to clients
|
|
17
17
|
* (`conn.send`/`broadcast`) — the schema's `toClient` section.
|
|
18
18
|
*
|
|
19
19
|
* With a generated `schema.jsonc`, wire both from the registry so they can't drift
|
|
20
20
|
* from the client's types:
|
|
21
21
|
* ```ts
|
|
22
|
-
* type Reg =
|
|
23
|
-
* class
|
|
22
|
+
* type Reg = ActorRegistry["MyActor"];
|
|
23
|
+
* class MyActor extends Actor<Reg["toServer"], Reg["toClient"]> { ... }
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
export class
|
|
26
|
+
export class Actor {
|
|
27
27
|
constructor() {
|
|
28
28
|
/**
|
|
29
29
|
* Managed ticker (opt-in). Override {@link shouldTick} and the platform runs
|
|
@@ -39,22 +39,22 @@ export class RealtimeHandler {
|
|
|
39
39
|
}
|
|
40
40
|
onStart() { }
|
|
41
41
|
broadcast(_data) {
|
|
42
|
-
throw new Error("
|
|
42
|
+
throw new Error("Actor.broadcast() is only available inside a deployed actor");
|
|
43
43
|
}
|
|
44
44
|
getConnections() {
|
|
45
|
-
throw new Error("
|
|
45
|
+
throw new Error("Actor.getConnections() is only available inside a deployed actor");
|
|
46
46
|
}
|
|
47
47
|
startLoop(_ms) {
|
|
48
|
-
throw new Error("
|
|
48
|
+
throw new Error("Actor.startLoop() is only available inside a deployed actor");
|
|
49
49
|
}
|
|
50
50
|
stopLoop() {
|
|
51
|
-
throw new Error("
|
|
51
|
+
throw new Error("Actor.stopLoop() is only available inside a deployed actor");
|
|
52
52
|
}
|
|
53
53
|
get instanceId() {
|
|
54
|
-
throw new Error("
|
|
54
|
+
throw new Error("Actor.instanceId is only available inside a deployed actor");
|
|
55
55
|
}
|
|
56
56
|
get storage() {
|
|
57
|
-
throw new Error("
|
|
57
|
+
throw new Error("Actor.storage is only available inside a deployed actor");
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* SDK client acting **as the connected user** — every entity call respects
|
|
@@ -66,7 +66,7 @@ export class RealtimeHandler {
|
|
|
66
66
|
*/
|
|
67
67
|
createClientFromConnection(conn) {
|
|
68
68
|
void conn;
|
|
69
|
-
throw new Error("
|
|
69
|
+
throw new Error("Actor.createClientFromConnection() is only available inside a deployed actor");
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Service-role SDK client — bypasses RLS. For work with **no user in scope**
|
|
@@ -74,6 +74,6 @@ export class RealtimeHandler {
|
|
|
74
74
|
* `createClientFromConnection(conn)`.
|
|
75
75
|
*/
|
|
76
76
|
createServiceClient() {
|
|
77
|
-
throw new Error("
|
|
77
|
+
throw new Error("Actor.createServiceClient() is only available inside a deployed actor");
|
|
78
78
|
}
|
|
79
79
|
}
|
package/dist/client.js
CHANGED
|
@@ -12,7 +12,7 @@ import { createAppLogsModule } from "./modules/app-logs.js";
|
|
|
12
12
|
import { createUsersModule } from "./modules/users.js";
|
|
13
13
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
14
14
|
import { createAnalyticsModule } from "./modules/analytics.js";
|
|
15
|
-
import {
|
|
15
|
+
import { createActorsModule } from "./modules/actors.js";
|
|
16
16
|
/**
|
|
17
17
|
* Creates a Base44 client.
|
|
18
18
|
*
|
|
@@ -179,17 +179,17 @@ export function createClient(config) {
|
|
|
179
179
|
appId,
|
|
180
180
|
userAuthModule,
|
|
181
181
|
}),
|
|
182
|
-
|
|
182
|
+
actors: createActorsModule({
|
|
183
183
|
appId,
|
|
184
184
|
dispatcherWsUrl: resolvedDispatcherWsUrl,
|
|
185
185
|
webSocketImpl,
|
|
186
|
-
getToken: async (
|
|
186
|
+
getToken: async (actorName, instanceId, connId) => {
|
|
187
187
|
// axiosClient interceptors unwrap response.data, so the result is the body directly.
|
|
188
188
|
// conn_id rides inside the signed token (not a WS query param) so it survives
|
|
189
|
-
// proxies that strip params; the dispatcher forwards it as the
|
|
189
|
+
// proxies that strip params; the dispatcher forwards it as the actor's conn.id.
|
|
190
190
|
// Base44-Functions-Version rides along (like function calls) so live apps get
|
|
191
|
-
// tokens for the *published*
|
|
192
|
-
const data = await axiosClient.post(`/apps/${appId}/
|
|
191
|
+
// tokens for the *published* actor script and previews get the draft.
|
|
192
|
+
const data = await axiosClient.post(`/apps/${appId}/actor-token`, { handler_name: actorName, instance_id: instanceId, conn_id: connId }, functionsVersion
|
|
193
193
|
? { headers: { "Base44-Functions-Version": functionsVersion } }
|
|
194
194
|
: undefined);
|
|
195
195
|
return data.token;
|
package/dist/client.types.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { AgentsModule } from "./modules/agents.types.js";
|
|
|
8
8
|
import type { AiGatewayModule } from "./modules/ai-gateway.types.js";
|
|
9
9
|
import type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
10
10
|
import type { AnalyticsModule } from "./modules/analytics.types.js";
|
|
11
|
-
import type {
|
|
11
|
+
import type { ActorsModule } from "./modules/actors.types.js";
|
|
12
12
|
/**
|
|
13
13
|
* Options for creating a Base44 client.
|
|
14
14
|
*/
|
|
@@ -111,8 +111,8 @@ export interface Base44Client {
|
|
|
111
111
|
analytics: AnalyticsModule;
|
|
112
112
|
/** {@link AppLogsModule | App logs module} for tracking app usage. */
|
|
113
113
|
appLogs: AppLogsModule;
|
|
114
|
-
/** {@link
|
|
115
|
-
|
|
114
|
+
/** {@link ActorsModule | Actors module} for subscribing to and sending messages via Cloudflare Durable Object-backed Actors. */
|
|
115
|
+
actors: ActorsModule;
|
|
116
116
|
/** {@link AuthModule | Auth module} for user authentication and management. */
|
|
117
117
|
auth: AuthModule;
|
|
118
118
|
/** {@link UserConnectorsModule | Connectors module} for app-user OAuth flows. */
|
package/dist/index.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./mod
|
|
|
11
11
|
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
12
|
export type { AiGatewayModule, AiGatewayConnection, } from "./modules/ai-gateway.types.js";
|
|
13
13
|
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
14
|
-
export type {
|
|
14
|
+
export type { ActorsModule, ActorClient, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
|
|
15
15
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
16
|
-
export {
|
|
16
|
+
export { Actor, type Conn } from "./actor.js";
|
|
17
17
|
export type { ConnectorsModule, UserConnectorsModule, } from "./modules/connectors.types.js";
|
|
18
18
|
export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
|
|
19
19
|
export type { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions, GetLoginUrlOptions, } from "./utils/auth-utils.types.js";
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,4 @@ import { Base44Error } from "./utils/axios-client.js";
|
|
|
3
3
|
import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, } from "./utils/auth-utils.js";
|
|
4
4
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
5
|
export * from "./types.js";
|
|
6
|
-
export {
|
|
6
|
+
export { Actor } from "./actor.js";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function createActorsModule(config: {
|
|
2
2
|
appId: string;
|
|
3
|
-
getToken(
|
|
3
|
+
getToken(actorName: string, instanceId: string, connId: string): Promise<string>;
|
|
4
4
|
dispatcherWsUrl: string;
|
|
5
5
|
/** WebSocket implementation for runtimes without a global one (Node < 22). */
|
|
6
6
|
webSocketImpl?: unknown;
|
|
7
|
-
}): Record<string,
|
|
8
|
-
/** Handle for an active
|
|
9
|
-
interface
|
|
10
|
-
/** This connection's id — the same value the
|
|
7
|
+
}): Record<string, ActorClient>;
|
|
8
|
+
/** Handle for an active actor subscription. */
|
|
9
|
+
interface ActorSubscription {
|
|
10
|
+
/** This connection's id — the same value the actor receives as `conn.id`. */
|
|
11
11
|
id: string;
|
|
12
12
|
/** Close the subscription and its underlying socket. */
|
|
13
13
|
unsubscribe(): void;
|
|
14
14
|
}
|
|
15
|
-
interface
|
|
15
|
+
interface ActorClient {
|
|
16
16
|
subscribe(instanceId: string, callback: (data: unknown) => void, options?: {
|
|
17
17
|
id?: string;
|
|
18
|
-
}):
|
|
18
|
+
}): ActorSubscription;
|
|
19
19
|
send(instanceId: string, data: unknown): void;
|
|
20
20
|
}
|
|
21
21
|
export {};
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import PartySocket from "partysocket";
|
|
2
|
-
// Module-level map: "
|
|
2
|
+
// Module-level map: "ActorName:instanceId" → active socket
|
|
3
3
|
const activeSockets = new Map();
|
|
4
|
-
function socketKey(
|
|
5
|
-
return `${
|
|
4
|
+
function socketKey(actorName, instanceId) {
|
|
5
|
+
return `${actorName}:${instanceId}`;
|
|
6
6
|
}
|
|
7
|
-
export function
|
|
7
|
+
export function createActorsModule(config) {
|
|
8
8
|
return new Proxy({}, {
|
|
9
|
-
get(_,
|
|
9
|
+
get(_, actorName) {
|
|
10
10
|
return {
|
|
11
11
|
subscribe(instanceId, callback, options) {
|
|
12
12
|
var _a, _b;
|
|
13
|
-
const key = socketKey(
|
|
13
|
+
const key = socketKey(actorName, instanceId);
|
|
14
14
|
// close existing if any
|
|
15
15
|
(_a = activeSockets.get(key)) === null || _a === void 0 ? void 0 : _a.close();
|
|
16
16
|
// Connection id: caller-supplied (stable — reuse across reconnects/tabs as
|
|
17
17
|
// you see fit) or auto-generated per subscription. It travels INSIDE the
|
|
18
|
-
// signed
|
|
18
|
+
// signed actor token (never as a WS query param, which proxies strip);
|
|
19
19
|
// the dispatcher forwards the verified claim as partyserver's _pk, so the
|
|
20
|
-
//
|
|
20
|
+
// actor sees this exact value as conn.id. Reconnects re-mint the token
|
|
21
21
|
// with the same id, so conn.id is stable across reconnects.
|
|
22
22
|
const connId = (_b = options === null || options === void 0 ? void 0 : options.id) !== null && _b !== void 0 ? _b : crypto.randomUUID();
|
|
23
23
|
// query as async fn: called on every (re)connect, fetches a fresh token each time
|
|
24
24
|
const ws = new PartySocket({
|
|
25
25
|
host: config.dispatcherWsUrl,
|
|
26
|
-
party:
|
|
26
|
+
party: actorName,
|
|
27
27
|
room: instanceId,
|
|
28
28
|
...(config.webSocketImpl ? { WebSocket: config.webSocketImpl } : {}),
|
|
29
|
-
query: () => config.getToken(
|
|
29
|
+
query: () => config.getToken(actorName, instanceId, connId).then((token) => ({ token })),
|
|
30
30
|
});
|
|
31
31
|
activeSockets.set(key, ws);
|
|
32
32
|
// Heartbeat / half-open detection. PartySocket only reconnects on a
|
|
@@ -68,7 +68,7 @@ export function createRealtimeModule(config) {
|
|
|
68
68
|
}
|
|
69
69
|
}, PING_MS);
|
|
70
70
|
return {
|
|
71
|
-
id: connId, // the connection id (same value the
|
|
71
|
+
id: connId, // the connection id (same value the actor sees as conn.id)
|
|
72
72
|
unsubscribe() {
|
|
73
73
|
clearInterval(heartbeat);
|
|
74
74
|
activeSockets.delete(key);
|
|
@@ -77,10 +77,10 @@ export function createRealtimeModule(config) {
|
|
|
77
77
|
};
|
|
78
78
|
},
|
|
79
79
|
send(instanceId, data) {
|
|
80
|
-
const key = socketKey(
|
|
80
|
+
const key = socketKey(actorName, instanceId);
|
|
81
81
|
const ws = activeSockets.get(key);
|
|
82
82
|
if (!ws)
|
|
83
|
-
throw new Error(`No active subscription for ${
|
|
83
|
+
throw new Error(`No active subscription for ${actorName}:${instanceId}`);
|
|
84
84
|
ws.send(JSON.stringify(data));
|
|
85
85
|
},
|
|
86
86
|
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extend this interface to add typed `subscribe` callbacks and `send` payloads
|
|
3
|
+
* for your deployed Actors.
|
|
4
|
+
*
|
|
5
|
+
* This is separate from {@link ActorNameRegistry} (which is auto-generated
|
|
6
|
+
* by `base44 types generate`), so there are no conflicts.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* declare module "@base44/sdk" {
|
|
11
|
+
* interface ActorRegistry {
|
|
12
|
+
* ChatRoom: {
|
|
13
|
+
* toClient: { type: "joined" | "left" | "message"; userId?: string; from?: string; text?: string };
|
|
14
|
+
* toServer: { type: "message"; text: string };
|
|
15
|
+
* };
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export interface ActorRegistry {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
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.
|
|
25
|
+
*/
|
|
26
|
+
export interface ActorNameRegistry {
|
|
27
|
+
}
|
|
28
|
+
type AllActorNames = keyof ActorRegistry | keyof ActorNameRegistry;
|
|
29
|
+
type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
|
|
30
|
+
toClient: infer I;
|
|
31
|
+
} ? I : unknown : unknown;
|
|
32
|
+
type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
|
|
33
|
+
toServer: infer O;
|
|
34
|
+
} ? O : unknown : unknown;
|
|
35
|
+
/**
|
|
36
|
+
* Client for a single named Actor.
|
|
37
|
+
* Typed automatically when the actor is registered in {@link ActorRegistry}.
|
|
38
|
+
*/
|
|
39
|
+
export interface ActorClient<N extends string = string> {
|
|
40
|
+
/**
|
|
41
|
+
* Open a WebSocket subscription. Returns a {@link ActorSubscription} with the
|
|
42
|
+
* connection `id` (same value the actor sees as `conn.id`) and an `unsubscribe()` method.
|
|
43
|
+
*
|
|
44
|
+
* Pass `options.id` to control the connection id (e.g. a stable per-tab id so a
|
|
45
|
+
* reconnect reuses the same server-side connection); omit it for an auto-generated
|
|
46
|
+
* per-connection id.
|
|
47
|
+
*/
|
|
48
|
+
subscribe(instanceId: string, callback: (data: ToClientFor<N>) => void, options?: {
|
|
49
|
+
id?: string;
|
|
50
|
+
}): ActorSubscription;
|
|
51
|
+
/** Send a message over the open socket. Throws if not subscribed. */
|
|
52
|
+
send(instanceId: string, data: ToServerFor<N>): void;
|
|
53
|
+
}
|
|
54
|
+
/** Handle for an active actor subscription. */
|
|
55
|
+
export interface ActorSubscription {
|
|
56
|
+
/** This connection's id — the same value the actor receives as `conn.id`. */
|
|
57
|
+
id: string;
|
|
58
|
+
/** Close the subscription and its underlying socket. */
|
|
59
|
+
unsubscribe(): void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The actors module provides access to Cloudflare Durable Object-backed
|
|
63
|
+
* Actors deployed by the Base44 platform.
|
|
64
|
+
*
|
|
65
|
+
* Actor names are accessed as dynamic properties on this module:
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const sub = await base44.actors.MyActor.subscribe("room-1", (msg) => {
|
|
68
|
+
* console.log(msg); // typed if MyActor is in ActorRegistry
|
|
69
|
+
* });
|
|
70
|
+
* const { id, unsubscribe } = sub;
|
|
71
|
+
* unsubscribe();
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export type ActorsModule = {
|
|
75
|
+
[K in AllActorNames]: K extends keyof ActorRegistry ? ActorClient<string & K> : ActorClient;
|
|
76
|
+
} & Record<string, ActorClient>;
|
|
77
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extend this interface to add typed `subscribe` callbacks and `send` payloads
|
|
3
|
-
* for your deployed RealtimeHandlers.
|
|
4
|
-
*
|
|
5
|
-
* This is separate from {@link RealtimeHandlerNameRegistry} (which is auto-generated
|
|
6
|
-
* by `base44 types generate`), so there are no conflicts.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* declare module "@base44/sdk" {
|
|
11
|
-
* interface RealtimeHandlerRegistry {
|
|
12
|
-
* ChatRoom: {
|
|
13
|
-
* toClient: { type: "joined" | "left" | "message"; userId?: string; from?: string; text?: string };
|
|
14
|
-
* toServer: { type: "message"; text: string };
|
|
15
|
-
* };
|
|
16
|
-
* }
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export interface RealtimeHandlerRegistry {
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Auto-populated by `base44 types generate` with the names of your deployed handlers.
|
|
24
|
-
* Do not edit this interface manually — use {@link RealtimeHandlerRegistry} for message types.
|
|
25
|
-
*/
|
|
26
|
-
export interface RealtimeHandlerNameRegistry {
|
|
27
|
-
}
|
|
28
|
-
type AllHandlerNames = keyof RealtimeHandlerRegistry | keyof RealtimeHandlerNameRegistry;
|
|
29
|
-
type ToClientFor<N extends string> = N extends keyof RealtimeHandlerRegistry ? RealtimeHandlerRegistry[N] extends {
|
|
30
|
-
toClient: infer I;
|
|
31
|
-
} ? I : unknown : unknown;
|
|
32
|
-
type ToServerFor<N extends string> = N extends keyof RealtimeHandlerRegistry ? RealtimeHandlerRegistry[N] extends {
|
|
33
|
-
toServer: infer O;
|
|
34
|
-
} ? O : unknown : unknown;
|
|
35
|
-
/**
|
|
36
|
-
* Client for a single named RealtimeHandler.
|
|
37
|
-
* Typed automatically when the handler is registered in {@link RealtimeHandlerRegistry}.
|
|
38
|
-
*/
|
|
39
|
-
export interface RealtimeHandlerClient<N extends string = string> {
|
|
40
|
-
/**
|
|
41
|
-
* Open a WebSocket subscription. Returns a {@link RealtimeSubscription} with the
|
|
42
|
-
* connection `id` (same value the handler sees as `conn.id`) and an `unsubscribe()` method.
|
|
43
|
-
*
|
|
44
|
-
* Pass `options.id` to control the connection id (e.g. a stable per-tab id so a
|
|
45
|
-
* reconnect reuses the same server-side connection); omit it for an auto-generated
|
|
46
|
-
* per-connection id.
|
|
47
|
-
*/
|
|
48
|
-
subscribe(instanceId: string, callback: (data: ToClientFor<N>) => void, options?: {
|
|
49
|
-
id?: string;
|
|
50
|
-
}): RealtimeSubscription;
|
|
51
|
-
/** Send a message over the open socket. Throws if not subscribed. */
|
|
52
|
-
send(instanceId: string, data: ToServerFor<N>): void;
|
|
53
|
-
}
|
|
54
|
-
/** Handle for an active realtime subscription. */
|
|
55
|
-
export interface RealtimeSubscription {
|
|
56
|
-
/** This connection's id — the same value the handler receives as `conn.id`. */
|
|
57
|
-
id: string;
|
|
58
|
-
/** Close the subscription and its underlying socket. */
|
|
59
|
-
unsubscribe(): void;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* The realtime module provides access to Cloudflare Durable Object-backed
|
|
63
|
-
* RealtimeHandlers deployed by the Base44 platform.
|
|
64
|
-
*
|
|
65
|
-
* Handler names are accessed as dynamic properties on this module:
|
|
66
|
-
* ```typescript
|
|
67
|
-
* const sub = await base44.realtime.MyHandler.subscribe("room-1", (msg) => {
|
|
68
|
-
* console.log(msg); // typed if MyHandler is in RealtimeHandlerRegistry
|
|
69
|
-
* });
|
|
70
|
-
* const { id, unsubscribe } = sub;
|
|
71
|
-
* unsubscribe();
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
export type RealtimeModule = {
|
|
75
|
-
[K in AllHandlerNames]: K extends keyof RealtimeHandlerRegistry ? RealtimeHandlerClient<string & K> : RealtimeHandlerClient;
|
|
76
|
-
} & Record<string, RealtimeHandlerClient>;
|
|
77
|
-
export {};
|
|
File without changes
|