UNPKG

json-rpc-protocol

Version:

JSON-RPC 2 protocol messages parsing and formatting

80 lines (79 loc) 1.84 kB
/** * JSON-RPC 2.0 Specification * http://www.jsonrpc.org/specification */ export declare type JsonRpcId = number | string; export declare type JsonRpcVersion = '1.0' | '2.0'; export interface JsonRpcParamsSchemaByName { [name: string]: any; } export declare type JsonRpcParamsSchemaByPositional = any[]; export declare type JsonRpcParamsSchema = JsonRpcParamsSchemaByName | JsonRpcParamsSchemaByPositional | undefined; export declare type PayloadTypeError = 'error'; export declare type PayloadTypeNotification = 'notification'; export declare type PayloadTypeRequest = 'request'; export declare type PayloadTypeResponse = 'response'; export declare type PayloadType = PayloadTypeError | PayloadTypeNotification | PayloadTypeRequest | PayloadTypeResponse; /** * * Error Schema * * */ export interface JsonRpcErrorSchema { code: number; data?: string; message: string; } /** * * Notification Payload * */ export interface JsonRpcPayloadNotification { jsonrpc: JsonRpcVersion; method: string; params: JsonRpcParamsSchema; type: PayloadTypeNotification; } /** * * Payload Request * */ export interface JsonRpcPayloadRequest { jsonrpc: JsonRpcVersion; id: JsonRpcId; method: string; params: JsonRpcParamsSchema; type: PayloadTypeRequest; } /** * * Response Payload * */ export interface JsonRpcPayloadResponse { id: JsonRpcId; jsonrpc: JsonRpcVersion; result: any; type: PayloadTypeResponse; } /** * * Error Payload * */ export interface JsonRpcPayloadError { id: null | JsonRpcId; jsonrpc: JsonRpcVersion; error: JsonRpcErrorSchema; type: PayloadTypeError; } /** * * * JsonRpc Payload * */ export declare type JsonRpcPayload = JsonRpcPayloadError | JsonRpcPayloadNotification | JsonRpcPayloadRequest | JsonRpcPayloadResponse;