Skip to content

Commit efdc8d9

Browse files
ImriKochWixclaude
andcommitted
feat(realtime): export RealtimeHandler type from SDK
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 30b4ed6 commit efdc8d9

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ export type {
110110

111111
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
112112

113+
export { RealtimeHandler, type Conn } from "./realtime-handler.js";
114+
113115
export type {
114116
ConnectorsModule,
115117
UserConnectorsModule,

src/realtime-handler.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Type-only base class for Realtime Handlers.
3+
*
4+
* Import and extend this in your handler files:
5+
* import { RealtimeHandler } from "@base44/sdk";
6+
* export class MyHandler extends RealtimeHandler { ... }
7+
*
8+
* At deploy time the bundler replaces this import with the compiled
9+
* Cloudflare Durable Object implementation — this file provides types only.
10+
*/
11+
12+
export interface Conn {
13+
userId: string;
14+
appId: string;
15+
instanceId: string;
16+
send(data: unknown): void;
17+
reject(code: number, reason: string): void;
18+
}
19+
20+
export abstract class RealtimeHandler<_State = unknown, Message = unknown> {
21+
abstract handleConnect(conn: Conn): void | Promise<void>;
22+
abstract handleMessage(conn: Conn, msg: Message): void | Promise<void>;
23+
abstract handleClose(conn: Conn): void | Promise<void>;
24+
abstract handleTick(): void | Promise<void>;
25+
26+
protected broadcast(_data: unknown): void {
27+
throw new Error("RealtimeHandler.broadcast() is only available inside a deployed handler");
28+
}
29+
30+
protected getConnections(): Conn[] {
31+
throw new Error("RealtimeHandler.getConnections() is only available inside a deployed handler");
32+
}
33+
34+
protected startLoop(_ms: number): Promise<void> {
35+
throw new Error("RealtimeHandler.startLoop() is only available inside a deployed handler");
36+
}
37+
38+
protected stopLoop(): Promise<void> {
39+
throw new Error("RealtimeHandler.stopLoop() is only available inside a deployed handler");
40+
}
41+
}

0 commit comments

Comments
 (0)