UNPKG

rwsdk

Version:

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

51 lines (50 loc) 1.44 kB
import { MESSAGE_TYPE } from "./shared"; export type Message = ActionRequestMessage | ActionStartMessage | ActionChunkMessage | ActionEndMessage | ActionErrorMessage | RscStartMessage | RscChunkMessage | RscEndMessage; export type ActionRequestMessage = { type: typeof MESSAGE_TYPE.ACTION_REQUEST; id: string | null; args: any; requestId: string; clientUrl: string; }; export type ActionStartMessage = { type: typeof MESSAGE_TYPE.ACTION_START; id: string; status: number; }; export type ActionChunkMessage = { type: typeof MESSAGE_TYPE.ACTION_CHUNK; id: string; payload: Uint8Array; }; export type ActionEndMessage = { type: typeof MESSAGE_TYPE.ACTION_END; id: string; }; export type ActionErrorMessage = { type: typeof MESSAGE_TYPE.ACTION_ERROR; id: string; error: string; }; export type RscStartMessage = { type: typeof MESSAGE_TYPE.RSC_START; id: string; status: number; }; export type RscChunkMessage = { type: typeof MESSAGE_TYPE.RSC_CHUNK; id: string; payload: Uint8Array; }; export type RscEndMessage = { type: typeof MESSAGE_TYPE.RSC_END; id: string; }; /** * Packs a message object into a Uint8Array for sending over WebSocket. */ export declare function packMessage(message: Message): Uint8Array; /** * Unpacks a Uint8Array from WebSocket into a message object. */ export declare function unpackMessage(data: Uint8Array): Message;