0.10.0 • Published 6 years ago
@erebos/rpc-base v0.10.0
rpc-base
Abstract class to handle JSON-RPC 2.0 calls, used by rpc-request and rpc-stream.
Installation
yarn add @erebos/rpc-baseUsage
import BaseRPC from '@erebos/rpc-base'
class MyRPC extends BaseRPC {
request(...params: any): Promise<any> {
// ...
}
}Types
RPCID
type RPCID = string | number | nullRPCRequest
interface RPCRequest<T = any> {
jsonrpc: '2.0'
method: string
id?: RPCID
params?: T
}RPCError
interface RPCErrorObject<T = any> {
code: number;
message?: ?string;
data?: T;
}RPCResponse
interface RPCResponse<T = any, E = any> {
jsonrpc: '2.0';
id: RPCID;
result?: T;
error?: RPCErrorObject<E>;
}API
new BaseRPC()
Arguments
canSubscribe: boolean = false: whether subscription calls (using a stateful connection) are supported by the implementation or not.
.canSubscribe
Returns boolean
.createId()
Returns string: an unique ID for RPC calls.
.request()
⚠️ This is an abstract method, it must be implemented by extending classes\
Arguments
method: stringparams?: P
Returns Promise<T = any>
License
MIT
0.10.0
6 years ago