partyfn
Version:
RPC on Durable Objects
43 lines (40 loc) • 903 B
TypeScript
import { WebSocket } from "partysocket";
type RpcAction<T> = {
id: string;
channel: string;
rpc: true;
action: T;
};
type RpcResponse<ResponseType> =
| {
id: string;
channel: string;
rpc: true;
type: "success";
result: ResponseType;
}
| {
id: string;
channel: string;
rpc: true;
type: "error";
error: string[];
};
type RpcException = {
rpc: true;
type: "exception";
exception: string[];
};
declare class RPCClient<RequestType, ResponseType> {
private channel;
private socket;
private rpcCache;
private controller;
constructor(channel: string, socket: WebSocket);
private rpc;
call(action: RequestType, timeout?: number): Promise<ResponseType>;
private resolve;
onException(exception: string[]): void;
destroy(): void;
}
export { RPCClient, type RpcAction, type RpcException, type RpcResponse };