UNPKG

rpc-websocketserver

Version:

Simple rpc websocket server, wrapping the very popular 'ws' library. Register your RPCs with convenient decorators.

25 lines (24 loc) 1.17 kB
import { ErrorObject, ErrorDetails, Id, Request, ResponseObject } from './interfaces'; import { ErrorType } from '../utils'; /** * Builds and returns a JSON RPC 2 conform error object. * * @param code {number} - JSON RPC 2 error code * @param details {ErrorDetails} - optional primitive or structured value with detailed error information */ export declare function buildError(code: number, details?: ErrorDetails): ErrorObject; /** * Builds and returns a JSON RPC 2 conform response object. * * @param error {boolean} - if true -> builds JSON RPC 2 error response, if false -> JSON RPC 2 result response * @param id {Id} - JSON RPC 2 id * @param data {any | ErrorObject} - should be rpc result if error is false, otherwise ErrorObject */ export declare function buildResponse(error: boolean, id: Id, data: any | ErrorObject): ResponseObject; /** * Assertion to ensure value is a JSON RPC 2 conform request * * @param val {*} - value to be asserted on * @param Err {ErrorType} - Error to be thrown if assertion fails */ export declare function assertValidJSONRPC2Request(val: any, Err: ErrorType<Error>): asserts val is Request;