Sitelet https://github.com/open-rpc/client-js/commit/2042f72
Skip to content

Commit 2042f72

Browse files
committed
fix: allow using integers as id
1 parent 097c960 commit 2042f72

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎src/RequestManager.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ describe("client-js", () => {
9696
const result = JSON.stringify([
9797
{
9898
jsonrpc: "2.0",
99-
id: "0",
99+
id: 0,
100100
result: "foo",
101101
},
102102
{
103103
jsonrpc: "2.0",
104-
id: "1",
104+
id: 1,
105105
result: "bar",
106106
},
107107
]);

‎src/RequestManager.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ITransport from "./transports/Transport";
22

33
interface IJSONRPCRequest {
44
jsonrpc: "2.0";
5-
id: string;
5+
id: string | number;
66
method: string;
77
params: any[] | object;
88
}
@@ -14,7 +14,7 @@ interface IJSONRPCError {
1414

1515
interface IJSONRPCResponse {
1616
jsonrpc: "2.0";
17-
id: string; // can also be null
17+
id: string | number; // can also be null
1818
result?: any;
1919
error?: IJSONRPCError;
2020
}
@@ -117,6 +117,7 @@ class RequestManager {
117117
const results = parsedData instanceof Array ? parsedData : [parsedData];
118118

119119
results.forEach((response) => {
120+
const id = typeof response.id === "string" ? response.id : response.id.toString();
120121
const promiseForResult = this.requests[response.id];
121122
if (promiseForResult === undefined) {
122123
throw new Error(

0 commit comments

Comments
 (0)