jsonrpc-client-websocket 1.5.3 → 1.5.5
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.
- package/README.md +1 -1
- package/lib/jsonrpc-websocket.d.ts +2 -1
- package/lib/jsonrpc-websocket.js +13 -6
- package/package.json +20 -18
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[](https://github.com/fabriciobastian/jsonrpc-client-websocket/actions/workflows/build.yml) [](https://choosealicense.com/licenses/mit/) [](https://www.npmjs.com/package/jsonrpc-client-websocket)
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|
|
|
5
5
|
A simple JSON RPC 2.0 client over websockets
|
|
6
6
|
|
|
@@ -17,7 +17,7 @@ export declare class JsonRpcWebsocket {
|
|
|
17
17
|
private pendingRequests;
|
|
18
18
|
private rpcMethods;
|
|
19
19
|
get state(): WebsocketReadyStates;
|
|
20
|
-
constructor(url: string, requestTimeoutMs: number, onError?: ErrorCallback);
|
|
20
|
+
constructor(url: string, requestTimeoutMs: number, onError?: ErrorCallback | undefined);
|
|
21
21
|
open(): Promise<Event>;
|
|
22
22
|
close(): Promise<CloseEvent>;
|
|
23
23
|
on(methodName: string, callback: (...args: any[]) => any): void;
|
|
@@ -38,4 +38,5 @@ export declare class JsonRpcWebsocket {
|
|
|
38
38
|
private callOnError;
|
|
39
39
|
private getRequestId;
|
|
40
40
|
private hasProperty;
|
|
41
|
+
private getErrorMessage;
|
|
41
42
|
}
|
package/lib/jsonrpc-websocket.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import getParameterNames from 'get-parameter-names';
|
|
2
2
|
import { DeferredPromise } from './deferred-promise';
|
|
3
3
|
import { JsonRpcErrorCodes } from './jsonrpc.model';
|
|
4
4
|
export var WebsocketReadyStates;
|
|
@@ -57,7 +57,10 @@ export class JsonRpcWebsocket {
|
|
|
57
57
|
}
|
|
58
58
|
catch (e) {
|
|
59
59
|
// istanbul ignore next
|
|
60
|
-
return Promise.reject({
|
|
60
|
+
return Promise.reject({
|
|
61
|
+
code: JsonRpcErrorCodes.INTERNAL_ERROR,
|
|
62
|
+
message: `Internal error. ${this.getErrorMessage(e)}`,
|
|
63
|
+
});
|
|
61
64
|
}
|
|
62
65
|
return this.createPendingRequest(request);
|
|
63
66
|
}
|
|
@@ -75,7 +78,7 @@ export class JsonRpcWebsocket {
|
|
|
75
78
|
}
|
|
76
79
|
catch (e) {
|
|
77
80
|
// istanbul ignore next
|
|
78
|
-
throw Error(e);
|
|
81
|
+
throw Error(this.getErrorMessage(e));
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
createWebsocket() {
|
|
@@ -132,7 +135,7 @@ export class JsonRpcWebsocket {
|
|
|
132
135
|
}
|
|
133
136
|
catch (e) {
|
|
134
137
|
// istanbul ignore next
|
|
135
|
-
throw Error(e);
|
|
138
|
+
throw Error(this.getErrorMessage(e));
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
141
|
handleMessage(msg) {
|
|
@@ -172,7 +175,7 @@ export class JsonRpcWebsocket {
|
|
|
172
175
|
requestParams = this.getRequestParams(method, request);
|
|
173
176
|
}
|
|
174
177
|
catch (error) {
|
|
175
|
-
this.handleError(JsonRpcErrorCodes.INVALID_PARAMS, error
|
|
178
|
+
this.handleError(JsonRpcErrorCodes.INVALID_PARAMS, this.getErrorMessage(error), request.id);
|
|
176
179
|
return;
|
|
177
180
|
}
|
|
178
181
|
try {
|
|
@@ -182,7 +185,7 @@ export class JsonRpcWebsocket {
|
|
|
182
185
|
}
|
|
183
186
|
}
|
|
184
187
|
catch (error) {
|
|
185
|
-
this.handleError(JsonRpcErrorCodes.REQUEST_FAILED, `Method '${request.method}' has thrown: '${error
|
|
188
|
+
this.handleError(JsonRpcErrorCodes.REQUEST_FAILED, `Method '${request.method}' has thrown: '${this.getErrorMessage(error)}'`, request.id);
|
|
186
189
|
}
|
|
187
190
|
}
|
|
188
191
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -289,4 +292,8 @@ export class JsonRpcWebsocket {
|
|
|
289
292
|
hasProperty(object, propertyName) {
|
|
290
293
|
return !!Object.prototype.hasOwnProperty.call(object, propertyName);
|
|
291
294
|
}
|
|
295
|
+
getErrorMessage(error) {
|
|
296
|
+
// istanbul ignore next
|
|
297
|
+
return error instanceof Error ? error?.message : JSON.stringify(error);
|
|
298
|
+
}
|
|
292
299
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsonrpc-client-websocket",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"description": "A simple JSON RPC 2.0 websocket client",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
"coverage": "jest --config jest.config.ts --coverage",
|
|
13
13
|
"build": "tsc",
|
|
14
14
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
15
|
-
"lint": "tsc --noEmit && eslint . --
|
|
15
|
+
"lint": "tsc --noEmit && eslint . --fix",
|
|
16
16
|
"prepublishOnly": "npm test && npm run lint",
|
|
17
17
|
"prepare": "npm run build",
|
|
18
18
|
"preversion": "npm run lint",
|
|
19
19
|
"version": "npm run format && git add -A src",
|
|
20
20
|
"postversion": "git push && git push --tags",
|
|
21
|
-
"
|
|
21
|
+
"update-all": "npm-check-updates --upgrade"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
@@ -38,21 +38,23 @@
|
|
|
38
38
|
"author": "Fabricio Bastian",
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"eslint": "^8.
|
|
45
|
-
"eslint
|
|
46
|
-
"eslint
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"jest
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
41
|
+
"@eslint/eslintrc": "^3.1.0",
|
|
42
|
+
"@eslint/js": "^9.9.0",
|
|
43
|
+
"@types/jest": "^29.5.12",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^8.1.0",
|
|
45
|
+
"@typescript-eslint/parser": "^8.1.0",
|
|
46
|
+
"eslint": "^9.9.0",
|
|
47
|
+
"eslint-config-prettier": "^9.1.0",
|
|
48
|
+
"eslint-plugin-jest": "^28.8.0",
|
|
49
|
+
"jest": "^29.7.0",
|
|
50
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
51
|
+
"jest-websocket-mock": "^2.5.0",
|
|
52
|
+
"mock-socket": "^9.3.1",
|
|
53
|
+
"npm-check-updates": "^17.0.6",
|
|
54
|
+
"prettier": "^3.3.3",
|
|
55
|
+
"ts-jest": "^29.2.4",
|
|
56
|
+
"ts-node": "^10.9.2",
|
|
57
|
+
"typescript": "^5.5.4"
|
|
56
58
|
},
|
|
57
59
|
"dependencies": {
|
|
58
60
|
"get-parameter-names": "^0.3.0"
|