@base44-preview/sdk 0.8.35-pr.212.5aafd7f → 0.8.35-pr.212.5b28711
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 +31 -8
- package/dist/realtime-handler.js +15 -0
- package/package.json +1 -1
|
@@ -9,11 +9,19 @@
|
|
|
9
9
|
* Cloudflare Durable Object implementation — this file provides types only.
|
|
10
10
|
*/
|
|
11
11
|
import type { Base44Client } from "./client.types.js";
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* A single client connection. `Send` is the message type this connection accepts
|
|
14
|
+
* via {@link send} — the handler's *outgoing* (server→client) messages.
|
|
15
|
+
*/
|
|
16
|
+
export interface Conn<Send = unknown> {
|
|
17
|
+
/** Unique per-connection id (one per socket/tab), the same value the client
|
|
18
|
+
* receives from `subscribe()`. Use this — not userId — to identify a distinct
|
|
19
|
+
* client, so multiple tabs of the same user are separate connections. */
|
|
20
|
+
id: string;
|
|
13
21
|
userId: string;
|
|
14
22
|
appId: string;
|
|
15
23
|
instanceId: string;
|
|
16
|
-
send(data:
|
|
24
|
+
send(data: Send): void;
|
|
17
25
|
reject(code: number, reason: string): void;
|
|
18
26
|
}
|
|
19
27
|
export interface Storage {
|
|
@@ -21,10 +29,25 @@ export interface Storage {
|
|
|
21
29
|
put(key: string, value: unknown): Promise<void>;
|
|
22
30
|
delete(key: string): Promise<boolean>;
|
|
23
31
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Base class for a Realtime Handler.
|
|
34
|
+
*
|
|
35
|
+
* @typeParam Incoming - messages this handler *receives* from clients
|
|
36
|
+
* (`handleMessage`'s `msg`) — the client's outbound direction.
|
|
37
|
+
* @typeParam Outgoing - messages this handler *sends* to clients
|
|
38
|
+
* (`conn.send`/`broadcast`) — the client's inbound direction.
|
|
39
|
+
*
|
|
40
|
+
* With a generated `schema.jsonc`, wire both from the registry so they can't drift
|
|
41
|
+
* from the client's types:
|
|
42
|
+
* ```ts
|
|
43
|
+
* type Reg = RealtimeHandlerRegistry["MyHandler"];
|
|
44
|
+
* class MyHandler extends RealtimeHandler<Reg["outbound"], Reg["inbound"]> { ... }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare abstract class RealtimeHandler<Incoming = unknown, Outgoing = unknown> {
|
|
48
|
+
abstract handleConnect(conn: Conn<Outgoing>): void | Promise<void>;
|
|
49
|
+
abstract handleMessage(conn: Conn<Outgoing>, msg: Incoming): void | Promise<void>;
|
|
50
|
+
abstract handleClose(conn: Conn<Outgoing>): void | Promise<void>;
|
|
28
51
|
abstract handleTick(): void | Promise<void>;
|
|
29
52
|
onStart(): void | Promise<void>;
|
|
30
53
|
/**
|
|
@@ -39,8 +62,8 @@ export declare abstract class RealtimeHandler<_State = unknown, Message = unknow
|
|
|
39
62
|
*/
|
|
40
63
|
protected tickIntervalMs: number;
|
|
41
64
|
protected shouldTick?(): boolean;
|
|
42
|
-
protected broadcast(_data:
|
|
43
|
-
protected getConnections(): Conn[];
|
|
65
|
+
protected broadcast(_data: Outgoing): void;
|
|
66
|
+
protected getConnections(): Conn<Outgoing>[];
|
|
44
67
|
protected startLoop(_ms: number): Promise<void>;
|
|
45
68
|
protected stopLoop(): Promise<void>;
|
|
46
69
|
protected get instanceId(): string;
|
package/dist/realtime-handler.js
CHANGED
|
@@ -8,6 +8,21 @@
|
|
|
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
|
+
/**
|
|
12
|
+
* Base class for a Realtime Handler.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam Incoming - messages this handler *receives* from clients
|
|
15
|
+
* (`handleMessage`'s `msg`) — the client's outbound direction.
|
|
16
|
+
* @typeParam Outgoing - messages this handler *sends* to clients
|
|
17
|
+
* (`conn.send`/`broadcast`) — the client's inbound direction.
|
|
18
|
+
*
|
|
19
|
+
* With a generated `schema.jsonc`, wire both from the registry so they can't drift
|
|
20
|
+
* from the client's types:
|
|
21
|
+
* ```ts
|
|
22
|
+
* type Reg = RealtimeHandlerRegistry["MyHandler"];
|
|
23
|
+
* class MyHandler extends RealtimeHandler<Reg["outbound"], Reg["inbound"]> { ... }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
11
26
|
export class RealtimeHandler {
|
|
12
27
|
constructor() {
|
|
13
28
|
/**
|