Skip to content
This repository was archived by the owner on Nov 9, 2023. It is now read-only.

Commit 12bf9ba

Browse files
committed
JsonRpcParams all the things!1
1 parent e8d9b61 commit 12bf9ba

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/createEngineStream.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Duplex } from 'readable-stream';
22
import { JsonRpcEngine } from '@metamask/json-rpc-engine';
3-
import { JsonRpcRequest } from '@metamask/utils';
3+
import { JsonRpcRequest, JsonRpcParams } from '@metamask/utils';
44

55
interface EngineStreamOptions {
66
engine: JsonRpcEngine;
@@ -36,7 +36,7 @@ export default function createEngineStream(opts: EngineStreamOptions): Duplex {
3636
* @param cb - The stream write callback.
3737
*/
3838
function write(
39-
req: JsonRpcRequest<unknown>,
39+
req: JsonRpcRequest<JsonRpcParams>,
4040
_encoding: unknown,
4141
cb: (error?: Error | null) => void,
4242
) {

src/createStreamMiddleware.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ import { Duplex } from 'readable-stream';
33
import type {
44
JsonRpcEngineNextCallback,
55
JsonRpcEngineEndCallback,
6-
JsonRpcNotification,
76
JsonRpcMiddleware,
7+
} from '@metamask/json-rpc-engine';
8+
9+
import type {
10+
JsonRpcNotification,
11+
JsonRpcParams,
812
JsonRpcRequest,
913
PendingJsonRpcResponse,
10-
} from '@metamask/json-rpc-engine';
14+
} from '@metamask/utils';
1115

1216
interface IdMapValue {
13-
req: JsonRpcRequest<unknown>;
14-
res: PendingJsonRpcResponse<unknown>;
17+
req: JsonRpcRequest<JsonRpcParams>;
18+
res: PendingJsonRpcResponse<JsonRpcParams>;
1519
next: JsonRpcEngineNextCallback;
1620
end: JsonRpcEngineEndCallback;
1721
retryCount?: number;
@@ -44,7 +48,7 @@ export default function createStreamMiddleware(options: Options = {}) {
4448

4549
const events = new SafeEventEmitter();
4650

47-
const middleware: JsonRpcMiddleware<unknown, unknown> = (
51+
const middleware: JsonRpcMiddleware<JsonRpcParams, JsonRpcParams> = (
4852
req,
4953
res,
5054
next,
@@ -63,7 +67,7 @@ export default function createStreamMiddleware(options: Options = {}) {
6367
*
6468
* @param req - The JSON-RPC request object.
6569
*/
66-
function sendToStream(req: JsonRpcRequest<unknown>) {
70+
function sendToStream(req: JsonRpcRequest<JsonRpcParams>) {
6771
// TODO: limiting retries could be implemented here
6872
stream.push(req);
6973
}
@@ -76,15 +80,17 @@ export default function createStreamMiddleware(options: Options = {}) {
7680
* @param cb - The stream write callback.
7781
*/
7882
function processMessage(
79-
res: PendingJsonRpcResponse<unknown>,
83+
res: PendingJsonRpcResponse<JsonRpcParams>,
8084
_encoding: unknown,
8185
cb: (error?: Error | null) => void,
8286
) {
8387
let err: Error | null = null;
8488
try {
8589
const isNotification = !res.id;
8690
if (isNotification) {
87-
processNotification(res as unknown as JsonRpcNotification<unknown>);
91+
processNotification(
92+
res as unknown as JsonRpcNotification<JsonRpcParams>,
93+
);
8894
} else {
8995
processResponse(res);
9096
}
@@ -100,7 +106,7 @@ export default function createStreamMiddleware(options: Options = {}) {
100106
*
101107
* @param res - The response to process.
102108
*/
103-
function processResponse(res: PendingJsonRpcResponse<unknown>) {
109+
function processResponse(res: PendingJsonRpcResponse<JsonRpcParams>) {
104110
const context = idMap[res.id as unknown as string];
105111
if (!context) {
106112
console.warn(`StreamMiddleware - Unknown response id "${res.id}"`);
@@ -120,7 +126,7 @@ export default function createStreamMiddleware(options: Options = {}) {
120126
*
121127
* @param notif - The notification to process.
122128
*/
123-
function processNotification(notif: JsonRpcNotification<unknown>) {
129+
function processNotification(notif: JsonRpcNotification<JsonRpcParams>) {
124130
if (options?.retryOnMessage && notif.method === options.retryOnMessage) {
125131
retryStuckRequests();
126132
}

0 commit comments

Comments
 (0)