/** The only JSON-RPC version this server speaks. */ export declare const JSON_RPC_VERSION: "2.0"; /** A request/response correlation id. `null` is legal and means "unknown". */ export type JsonRpcId = string | number | null; export interface JsonRpcErrorObject { readonly code: number; readonly message: string; readonly data?: unknown; } export interface JsonRpcRequest { readonly jsonrpc: typeof JSON_RPC_VERSION; readonly id: JsonRpcId; readonly method: string; readonly params?: unknown; } /** A request WITHOUT an id. JSON-RPC forbids replying to one. */ export interface JsonRpcNotification { readonly jsonrpc: typeof JSON_RPC_VERSION; readonly method: string; readonly params?: unknown; } export interface JsonRpcSuccess { readonly jsonrpc: typeof JSON_RPC_VERSION; readonly id: JsonRpcId; readonly result: unknown; } export interface JsonRpcFailure { readonly jsonrpc: typeof JSON_RPC_VERSION; readonly id: JsonRpcId; readonly error: JsonRpcErrorObject; } export type JsonRpcResponse = JsonRpcSuccess | JsonRpcFailure; /** Standard JSON-RPC codes. The server adds no private codes of its own. */ export declare const JSON_RPC_PARSE_ERROR = -32700; export declare const JSON_RPC_INVALID_REQUEST = -32600; export declare const JSON_RPC_METHOD_NOT_FOUND = -32601; export declare const JSON_RPC_INVALID_PARAMS = -32602; export declare const JSON_RPC_INTERNAL_ERROR = -32603; export declare function isPlainObject(value: unknown): value is Record; /** What one decoded line turned out to be. */ export type DecodedMessage = { readonly kind: 'request'; readonly request: JsonRpcRequest; } | { readonly kind: 'notification'; readonly notification: JsonRpcNotification; } | { readonly kind: 'invalid'; readonly id: JsonRpcId; readonly error: JsonRpcErrorObject; }; export declare function makeError(code: number, message: string, data?: unknown): JsonRpcErrorObject; export declare function successResponse(id: JsonRpcId, result: unknown): JsonRpcSuccess; export declare function failureResponse(id: JsonRpcId, error: JsonRpcErrorObject): JsonRpcFailure; /** * Decode one frame. * * `undefined` means "nothing to answer" — an empty line, which is legal padding * and must not be reported as a parse error (an empty line is not a message the * peer sent; it is whitespace between messages). */ export declare function decodeMessage(line: string): DecodedMessage | undefined; /** * Encode one frame for the wire. `JSON.stringify` escapes every newline inside * a string, which is what keeps one message on one line. */ export declare function encodeMessage(message: JsonRpcResponse | JsonRpcNotification): string; /** * The buffer that turns an arbitrary chunking of bytes into whole lines. * * Needed because a pipe delivers no framing of its own: one `data` event may * carry half a message or three of them, and a server that parsed each event as * a message would work on a fast local pipe and fail on a loaded one. */ export declare class LineDecoder { private buffer; /** Feed a chunk; get back the complete lines it completed (no trailing newline). */ push(chunk: string): string[]; /** Whatever is left when the stream ends. A peer that never sent a newline still sent a message. */ flush(): string[]; }