Skip to content

Commit

Permalink
fix: allow using integers as id
Browse files Browse the repository at this point in the history
  • Loading branch information
BelfordZ committed Jul 25, 2019
1 parent 097c960 commit 2042f72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/RequestManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ describe("client-js", () => {
const result = JSON.stringify([
{
jsonrpc: "2.0",
id: "0",
id: 0,
result: "foo",
},
{
jsonrpc: "2.0",
id: "1",
id: 1,
result: "bar",
},
]);
Expand Down
5 changes: 3 additions & 2 deletions src/RequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ITransport from "./transports/Transport";

interface IJSONRPCRequest {
jsonrpc: "2.0";
id: string;
id: string | number;
method: string;
params: any[] | object;
}
Expand All @@ -14,7 +14,7 @@ interface IJSONRPCError {

interface IJSONRPCResponse {
jsonrpc: "2.0";
id: string; // can also be null
id: string | number; // can also be null
result?: any;
error?: IJSONRPCError;
}
Expand Down Expand Up @@ -117,6 +117,7 @@ class RequestManager {
const results = parsedData instanceof Array ? parsedData : [parsedData];

results.forEach((response) => {
const id = typeof response.id === "string" ? response.id : response.id.toString();
const promiseForResult = this.requests[response.id];
if (promiseForResult === undefined) {
throw new Error(
Expand Down

0 comments on commit 2042f72

Please sign in to comment.