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
🌳
- Host: GitHub
- URL: https://github.com/blackglory/json-rpc-types
- Owner: BlackGlory
- License: mit
- Created: 2022-03-05T17:24:20.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-13T02:11:24.000Z (over 1 year ago)
- Last Synced: 2025-07-04T10:05:48.227Z (12 months ago)
- Topics: browser, library, nodejs, npm-package, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/json-rpc-types
- Size: 116 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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>
```