jsonrpc-client-websocket 1.5.1 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +50 -21
  2. package/package.json +17 -16
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Travis build status](https://travis-ci.com/fabriciobastian/jsonrpc-client-websocket.svg?branch=master)](https://travis-ci.com/fabriciobastian/jsonrpc-client-websocket) [![License](https://img.shields.io/github/license/fabriciobastian/jsonrpc-client-websocket)](https://choosealicense.com/licenses/mit/) [![NPM downloads](https://img.shields.io/npm/dt/jsonrpc-client-websocket.svg)](https://www.npmjs.com/package/jsonrpc-client-websocket)
1
+ [![Travis build status](https://travis-ci.com/fabriciobastian/jsonrpc-client-websocket.svg?branch=master)](https://travis-ci.com/fabriciobastian/jsonrpc-client-websocket) [![License](https://img.shields.io/github/license/fabriciobastian/jsonrpc-client-websocket)](https://choosealicense.com/licenses/mit/) [![NPM downloads](https://img.shields.io/npm/dt/jsonrpc-client-websocket.svg)](https://www.npmjs.com/package/jsonrpc-client-websocket)
2
2
 
3
3
  ![jsonrpc-client-websocket](https://github.com/fabriciobastian/jsonrpc-client-websocket/blob/master/assets/jsonrpc-client-websocket-banner-light-small.png?raw=true)
4
4
 
@@ -7,14 +7,14 @@ A simple JSON RPC 2.0 client over websockets
7
7
  ## Open connection
8
8
 
9
9
  ```typescript
10
- const websocketUrl = "ws://mywebsocketurl:port"
10
+ const websocketUrl = 'ws://mywebsocketurl:port';
11
11
  const requestTimeoutMs = 2000;
12
- const websocket = new JsonRpcWebsocket(
13
- websocketUrl,
14
- requestTimeoutMs,
15
- (error: JsonRpcError) => { /* handle error */ });
12
+ const websocket = new JsonRpcWebsocket(websocketUrl, requestTimeoutMs, (error: JsonRpcError) => {
13
+ /* handle error */
14
+ });
16
15
  await websocket.open();
17
16
  ```
17
+
18
18
  Requests that do not receive a response within the specified timeout will fail with a REQUEST_TIMEOUT code.
19
19
  The callback (optional) is used for eventual errors, such as receiving a response that does not match any request id and
20
20
  connection errors. Furthermore, all errors that are sent to an eventual caller are also reported on the callback, e.g.
@@ -33,25 +33,25 @@ Considering that the server has a method `sum(a: int, b: int)`
33
33
  ### with positional parameters
34
34
 
35
35
  ```typescript
36
- websocket.call('sum', [1,2])
37
- .then((response) => {
38
- // handle response
39
- })
40
- .catch((error) => {
41
- // handle error
42
- });
36
+ websocket.call('sum', [1, 2])
37
+ .then((response) => {
38
+ // handle response
39
+ })
40
+ .catch((error) => {
41
+ // handle error
42
+ });
43
43
  ```
44
44
 
45
45
  ### with named parameters
46
46
 
47
47
  ```typescript
48
- websocket.call('sum', {b: 1, a: 2})
49
- .then((response) => {
50
- // handle response
51
- })
52
- .catch((error) => {
53
- // handle error
54
- });
48
+ websocket.call('sum', { b: 1, a: 2 })
49
+ .then((response) => {
50
+ // handle response
51
+ })
52
+ .catch((error) => {
53
+ // handle error
54
+ });
55
55
  ```
56
56
 
57
57
  ## Send notification
@@ -66,12 +66,41 @@ websocket.notify('log', ['a log message']);
66
66
 
67
67
  ```typescript
68
68
  websocket.on('sum', (a: number, b: number) => {
69
- return a + b;
69
+ return a + b;
70
70
  });
71
71
  ```
72
+
72
73
  The defined RPC methods can also be called with both positional and named parameters.
73
74
 
75
+ ### Minification/Obfuscation
76
+
77
+ When using code minification/obfuscation the parameter names may change, which can
78
+ cause calls using named parameters to fail. To mitigate this you can do one or a
79
+ combination of the following:
80
+ - do not minify/obfuscate the code where `on` is used, so the function registration does not get modified
81
+ - use positional parameters
82
+ - register functions as following:
83
+
84
+ ```typescript
85
+ websocket.on('sum', (params: { a: number; b: number }) => {
86
+ return params.a + params.b;
87
+ });
88
+ ```
89
+
90
+ and then call the function using positional parameters using the object:
91
+
92
+ ```typescript
93
+ websocket.call('sum', [{ a: 1, b: 2 }])
94
+ .then((response) => {
95
+ // handle response
96
+ })
97
+ .catch((error) => {
98
+ // handle error
99
+ });
100
+ ```
101
+
74
102
  ## Remove RPC method
103
+
75
104
  ```typescript
76
105
  websocket.off('sum');
77
106
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsonrpc-client-websocket",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "A simple JSON RPC 2.0 websocket client",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "test": "jest",
12
- "coverage": "jest --config jestconfig.json --coverage",
12
+ "coverage": "jest --config jest.config.ts --coverage",
13
13
  "build": "tsc",
14
14
  "format": "prettier --write \"src/**/*.ts\"",
15
15
  "lint": "tsc --noEmit && eslint . --ext .js,.jsx,.ts,.tsx --fix",
@@ -38,20 +38,21 @@
38
38
  "author": "Fabricio Bastian",
39
39
  "license": "MIT",
40
40
  "devDependencies": {
41
- "@types/jest": "^27.0.3",
42
- "@typescript-eslint/eslint-plugin": "^5.4.0",
43
- "@typescript-eslint/parser": "^5.4.0",
44
- "eslint": "^8.3.0",
45
- "eslint-config-prettier": "^8.3.0",
46
- "eslint-plugin-jest": "^25.3.0",
47
- "jest": "^27.3.1",
48
- "jest-websocket-mock": "^2.2.1",
49
- "mock-socket": "^9.0.8",
50
- "npm-check-updates": "^12.0.2",
51
- "prettier": "^2.5.0",
52
- "ts-jest": "^27.0.7",
53
- "ts-node": "^10.4.0",
54
- "typescript": "^4.5.2"
41
+ "@types/jest": "^28.1.6",
42
+ "@typescript-eslint/eslint-plugin": "^5.31.0",
43
+ "@typescript-eslint/parser": "^5.31.0",
44
+ "eslint": "^8.20.0",
45
+ "eslint-config-prettier": "^8.5.0",
46
+ "eslint-plugin-jest": "^26.6.0",
47
+ "jest": "^28.1.3",
48
+ "jest-environment-jsdom": "^28.1.3",
49
+ "jest-websocket-mock": "^2.3.0",
50
+ "mock-socket": "^9.1.5",
51
+ "npm-check-updates": "^16.0.1",
52
+ "prettier": "^2.7.1",
53
+ "ts-jest": "^28.0.7",
54
+ "ts-node": "^10.9.1",
55
+ "typescript": "^4.7.4"
55
56
  },
56
57
  "dependencies": {
57
58
  "get-parameter-names": "^0.3.0"