An open API service indexing awesome lists of open source software.

https://github.com/blackglory/json-rpc-types

🌳
https://github.com/blackglory/json-rpc-types

browser library nodejs npm-package typescript

Last synced: 5 months ago
JSON representation

🌳

Awesome Lists containing this project

README

          

# json-rpc-types
## Install
```sh
npm install --save json-rpc-types
# or
yarn add json-rpc-types
```

## API
```ts
type JsonRpcId = string | number
type JsonRpcParams = T[] | Record

interface JsonRpcNotification {
jsonrpc: '2.0'
method: string
params?: JsonRpcParams
}

interface JsonRpcRequest {
jsonrpc: '2.0'
id: JsonRpcId
method: string
params?: JsonRpcParams
}

type JsonRpcResponse =
| JsonRpcSuccess
| JsonRpcError

interface JsonRpcSuccess {
jsonrpc: '2.0'
id: JsonRpcId
result: T
}

interface JsonRpcError {
jsonrpc: '2.0'
id: JsonRpcId
error: JsonRpcErrorObject
}

interface JsonRpcErrorObject {
code: number
message: string
data?: T
}

function isJsonRpcNotification(val: unknown): val is JsonRpcNotification
function isntJsonRpcNotification(
val: T
): val is Exclude>

function isJsonRpcRequest(val: unknown): val is JsonRpcRequest
function isntJsonRpcRequest(val: T): val is Exclude>

function isJsonRpcSuccess(val: unknown): val is JsonRpcSuccess
function isntJsonRpcSuccess(val: T): val is Exclude>

function isJsonRpcError(val: unknown): val is JsonRpcError
function isntJsonRpcError(val: T): val is Exclude>
```