@mainframe/rpc-base
Base RPC class
Last updated 2 years ago by paul_lecam .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @mainframe/rpc-base 
SYNC missed versions from official npm registry.

rpc-base

Abstract class to handle JSON-RPC 2.0 calls, used by rpc-request and rpc-stream.

Installation

yarn add @mainframe/rpc-base

Usage

import BaseRPC from '@mainframe/rpc-base'

class MyRPC extends BaseRPC {
  request(...params: any): Promise<any> {
    // ...
  }
}

Types

RPCID

type RPCID = string | number | null

RPCRequest

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

  1. 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

  1. method: string
  2. params?: P

Returns Promise<T = any>

License

MIT

Current Tags

  • 0.3.0                                ...           latest (2 years ago)

6 Versions

  • 0.3.0                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 4
Last Day 0
Last Week 1
Last Month 6
Dependencies (3)
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |