partysync
Version:
Experimental library to synchronize state between a Durable Object and client. See [design discussion](https://github.com/cloudflare/partykit/issues/147).
29 lines (26 loc) • 685 B
TypeScript
import { Server, Connection, WSMessage } from "partyserver";
type ActionType = {
type: string;
payload: unknown;
};
type RecordType = unknown[];
type Channels = {
[Channel: string]: {
record: RecordType;
action: ActionType;
};
};
declare class SyncServer<
Env,
TChannels extends Channels = Channels
> extends Server<Env> {
static options: {
hibernate: boolean;
};
onAction<Channel extends keyof TChannels>(
channel: Channel,
action: TChannels[typeof channel]["action"]
): TChannels[Channel]["record"][] | Promise<TChannels[Channel]["record"][]>;
onMessage(connection: Connection, message: WSMessage): Promise<void>;
}
export { SyncServer };