UNPKG

rwsdk

Version:

Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime

37 lines (36 loc) 2.3 kB
import type { RpcStub } from "capnweb"; import { DurableObject } from "cloudflare:workers"; import type { RequestInfo } from "../runtime/requestInfo/types"; export type SyncedStateValue = unknown; type OnSetHandler = (key: string, value: SyncedStateValue, stub: DurableObjectStub<SyncedStateServer>) => void; type OnGetHandler = (key: string, value: SyncedStateValue | undefined, stub: DurableObjectStub<SyncedStateServer>) => void; type OnKeyHandler = (key: string, stub: DurableObjectStub<SyncedStateServer>) => Promise<string>; type OnRoomHandler = (roomId: string | undefined, requestInfo: RequestInfo | null) => Promise<string>; type OnSubscribeHandler = (key: string, stub: DurableObjectStub<SyncedStateServer>) => void; type OnUnsubscribeHandler = (key: string, stub: DurableObjectStub<SyncedStateServer>) => void; /** * Durable Object that keeps shared state for multiple clients and notifies subscribers. */ export declare class SyncedStateServer extends DurableObject { #private; static registerKeyHandler(handler: OnKeyHandler | null): void; static getKeyHandler(): OnKeyHandler | null; static registerRoomHandler(handler: OnRoomHandler | null): void; static getRoomHandler(): OnRoomHandler | null; static registerNamespace(namespace: DurableObjectNamespace<SyncedStateServer>, durableObjectName?: string): void; static getNamespace(): DurableObjectNamespace<SyncedStateServer> | null; static getDurableObjectName(): string; setStub(stub: DurableObjectStub<SyncedStateServer>): void; static registerSetStateHandler(handler: OnSetHandler | null): void; static registerGetStateHandler(handler: OnGetHandler | null): void; static registerSubscribeHandler(handler: OnSubscribeHandler | null): void; static registerUnsubscribeHandler(handler: OnUnsubscribeHandler | null): void; static getSubscribeHandler(): OnSubscribeHandler | null; static getUnsubscribeHandler(): OnUnsubscribeHandler | null; getState(key: string): SyncedStateValue; setState(value: SyncedStateValue, key: string): void; subscribe(key: string, client: RpcStub<(value: SyncedStateValue) => void>): void; unsubscribe(key: string, client: RpcStub<(value: SyncedStateValue) => void>): void; fetch(request: Request): Promise<Response>; } export {};