UNPKG

@hazae41/jsonrpc

Version:

Rust-like JSON-RPC for TypeScript

37 lines (35 loc) 1.35 kB
type RpcId = number | string | null; type RpcRequestPreinit<T = unknown> = (undefined extends T ? RpcParamlessRequestPreinit : never) | RpcParamfulRequestPreinit<T>; interface RpcParamfulRequestPreinit<T = unknown> { readonly id?: RpcId; readonly method: string; readonly params: T; } interface RpcParamlessRequestPreinit { readonly id?: RpcId; readonly method: string; readonly params?: undefined; } type RpcRequestInit<T = unknown> = (undefined extends T ? RpcParamlessRequestInit : never) | RpcParamfulRequestInit<T>; interface RpcParamfulRequestInit<T = unknown> { readonly jsonrpc: "2.0"; readonly id: RpcId; readonly method: string; readonly params: T; } interface RpcParamlessRequestInit { readonly jsonrpc: "2.0"; readonly id: RpcId; readonly method: string; readonly params?: undefined; } declare class RpcRequest<T = unknown> { readonly id: RpcId; readonly method: string; readonly params: T; readonly jsonrpc: "2.0"; constructor(id: RpcId, method: string, params: T); static from<T>(init: RpcRequestInit<T>): RpcRequest<T>; toJSON(): RpcRequestInit<T>; } export { type RpcId, type RpcParamfulRequestInit, type RpcParamfulRequestPreinit, type RpcParamlessRequestInit, type RpcParamlessRequestPreinit, RpcRequest, type RpcRequestInit, type RpcRequestPreinit };