rwsdk
Version:
Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime
54 lines (53 loc) • 1.22 kB
text/typescript
export type SyncedStateValue = unknown;
export declare const PROTOCOL_VERSION = 1;
export type SyncedStateEnvelope = {
v: typeof PROTOCOL_VERSION;
} & SyncedStateMessage;
export type SyncedStateMessage = ClientMessage | ServerMessage;
export type ClientMessage = {
kind: "getState";
key: string;
id: string;
} | {
kind: "setState";
key: string;
value: SyncedStateValue;
id: string;
} | {
kind: "subscribe";
key: string;
id: string;
} | {
kind: "unsubscribe";
key: string;
id: string;
};
export type ServerMessage = {
kind: "getState";
key: string;
value?: SyncedStateValue | undefined;
id: string;
} | {
kind: "setState";
key: string;
id: string;
} | {
kind: "subscribe";
key: string;
id: string;
} | {
kind: "unsubscribe";
key: string;
id: string;
} | {
kind: "update";
key: string;
value?: SyncedStateValue;
} | {
kind: "error";
message: string;
id?: string;
};
export declare function packMessage(message: SyncedStateMessage): string;
export declare function unpackClientMessage(data: string): ClientMessage;
export declare function unpackServerMessage(data: string): ServerMessage;