New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jsonrpc-ts

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonrpc-ts - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

2

interfaces/rpc-response.interface.d.ts

@@ -7,3 +7,3 @@ import { RpcResponseError } from './rpc-response-error.interface';

*/
export interface RpcResponse<TResult = any, TErrorData = any> {
export interface RpcResponse<TResult, TErrorData = any> {
/**

@@ -10,0 +10,0 @@ * A String specifying the version of the JSON-RPC protocol.

{
"name": "jsonrpc-ts",
"version": "0.1.0",
"version": "0.2.0",
"description": "Strongly Typed Fast and lightweight JSON RPC 2.0 Client for Nodejs",

@@ -24,13 +24,13 @@ "main": "index.js",

"devDependencies": {
"@types/jest": "^23.3.3",
"@types/node": "^10.11.4",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"coveralls": "^3.0.2",
"http-jsonrpc-server": "^1.0.0-beta.4",
"jest": "^23.6.0",
"ts-jest": "^23.10.3"
"jest": "^24.8.0",
"ts-jest": "^24.0.0"
},
"dependencies": {
"axios": "^0.18.0",
"axios": "^0.19.0",
"typescript": "^3.1.1"
}
}
# JSONRPC Typescript
[![Build Status](https://travis-ci.org/shekohex/jsonrpc-ts.svg?branch=master)](https://travis-ci.org/shekohex/jsonrpc-ts) [![Greenkeeper badge](https://badges.greenkeeper.io/shekohex/jsonrpc-ts.svg)](https://greenkeeper.io/)
[![Coverage Status](https://coveralls.io/repos/github/shekohex/jsonrpc-ts/badge.svg?branch=master)](https://coveralls.io/github/shekohex/jsonrpc-ts?branch=master)
[![npm version](https://badge.fury.io/js/jsonrpc-ts.svg)](https://badge.fury.io/js/jsonrpc-ts)

@@ -10,7 +12,11 @@ Strongly 💪 Typed JSON RPC 2.0 Client for Nodejs

## Quick Overview
By Declaring events using a simple interface mapping methods names to their parameters to get Strongly Typed, Fast and Modern Rpc client for your service.
## Install
todo: Add NPM install Here
```
npm i jsonrpc-ts
```
## Usage

@@ -24,6 +30,8 @@

interface MathService {
// a method called sum that accepts 2 args of type number
sum: [number, number];
// methods can have named paramerter too.
sub: { left: number, right: number };
// a method called sum that accepts 2 args of type number
sum: [number, number];
// methods can have named paramerter too.
sub: { left: number; right: number };
// or if you need return type, you can have that too :)
sumWithReturnType: ({ x, y }: { x: number; y: number }) => number;
}

@@ -40,6 +48,18 @@ ```

// try to change [3, 2] to ['3', '2'] and the typescript compiler will catch you !
const response = await rpcClient.makeRequest({ method: 'sum', params: [3, 2], id: 1, jsonrpc: '2.0' });
const response = await rpcClient.makeRequest({
method: 'sum',
params: [3, 2],
id: 1,
jsonrpc: '2.0',
});
// response.data.result === 5
// response2.data.result has type of number :)
const response2 = await rpcClient.makeRequest({
method: 'sumWithReturnType',
params: { x: 3, y: 2 },
id: 2,
jsonrpc: '2.0',
});
// response2.data.result === 5
```
TODO: Add API Docs Here !

@@ -5,2 +5,6 @@ import { AxiosResponse } from 'axios';

declare type RpcBatchResponse<TResponse, TError> = Array<RpcResponse<TResponse, TError>>;
declare type ReturnTypeOfMethod<T> = T extends (...args: Array<any>) => any ? ReturnType<T> : any;
declare type ReturnTypeOfMethodIfExists<T, S> = S extends keyof T ? ReturnTypeOfMethod<T[S]> : any;
declare type MethodParams<T> = T extends (...args: infer P) => any ? P[0] : T;
declare type MethodParamsIfExists<T, S> = S extends keyof T ? MethodParams<T[S]> : S;
export declare class RpcClient<TMethods = any> {

@@ -11,3 +15,3 @@ private readonly options;

/**
* Make JSON RPC Batch Request
* Make JSON RPC Batch Request of the same method
* @throws {AxiosError | RpcError} http/rpc error

@@ -20,4 +24,4 @@ */

*/
makeRequest<K extends keyof TMethods, TResponse = any, TError = any>(request: RpcRequest<K, TMethods[K]>): Promise<AxiosResponse<RpcResponse<TResponse, TError>>>;
makeRequest<K extends keyof TMethods, TError = any>(request: RpcRequest<K, MethodParamsIfExists<TMethods, K>>): Promise<AxiosResponse<RpcResponse<ReturnTypeOfMethodIfExists<TMethods, K>, TError>>>;
}
export {};

@@ -19,3 +19,3 @@ "use strict";

/**
* Make JSON RPC Batch Request
* Make JSON RPC Batch Request of the same method
* @throws {AxiosError | RpcError} http/rpc error

@@ -22,0 +22,0 @@ */

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc