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

Commit be37c73

Browse files
committed
Rename _middleware to _requestMiddleware
1 parent 852e6ee commit be37c73

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/JsonRpcEngine.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ export type JsonRpcNotificationMiddleware<T> = (
9595
* Give it a stack of middleware, pass it requests, and get back responses.
9696
*/
9797
export class JsonRpcEngine extends SafeEventEmitter {
98-
private _middleware: JsonRpcMiddleware<unknown, unknown>[];
98+
private _requestMiddleware: JsonRpcMiddleware<unknown, unknown>[];
9999

100100
private _notificationMiddleware: JsonRpcNotificationMiddleware<unknown>[];
101101

102102
constructor() {
103103
super();
104-
this._middleware = [];
104+
this._requestMiddleware = [];
105105
this._notificationMiddleware = [];
106106
}
107107

@@ -111,7 +111,9 @@ export class JsonRpcEngine extends SafeEventEmitter {
111111
* @param middleware - The middleware function to add.
112112
*/
113113
pushRequestMiddleware<T, U>(middleware: JsonRpcMiddleware<T, U>): void {
114-
this._middleware.push(middleware as JsonRpcMiddleware<unknown, unknown>);
114+
this._requestMiddleware.push(
115+
middleware as JsonRpcMiddleware<unknown, unknown>,
116+
);
115117
}
116118

117119
/**
@@ -133,7 +135,9 @@ export class JsonRpcEngine extends SafeEventEmitter {
133135
pushNotificationMiddleware<T>(
134136
middleware: JsonRpcNotificationMiddleware<T>,
135137
): void {
136-
this._middleware.push(middleware as JsonRpcNotificationMiddleware<unknown>);
138+
this._requestMiddleware.push(
139+
middleware as JsonRpcNotificationMiddleware<unknown>,
140+
);
137141
}
138142

139143
/**
@@ -225,7 +229,11 @@ export class JsonRpcEngine extends SafeEventEmitter {
225229
return async (req, res, next, end) => {
226230
try {
227231
const [middlewareError, isComplete, returnHandlers] =
228-
await JsonRpcEngine._runAllMiddleware(req, res, this._middleware);
232+
await JsonRpcEngine._runAllMiddleware(
233+
req,
234+
res,
235+
this._requestMiddleware,
236+
);
229237

230238
if (isComplete) {
231239
await JsonRpcEngine._runReturnHandlers(returnHandlers);
@@ -379,7 +387,7 @@ export class JsonRpcEngine extends SafeEventEmitter {
379387
};
380388

381389
try {
382-
await JsonRpcEngine._processRequest(req, res, this._middleware);
390+
await JsonRpcEngine._processRequest(req, res, this._requestMiddleware);
383391
} catch (_error) {
384392
// A request handler error, a re-thrown middleware error, or something
385393
// unexpected.
@@ -401,13 +409,13 @@ export class JsonRpcEngine extends SafeEventEmitter {
401409
* Runs all notification middleware on the specified notification.
402410
*
403411
* @param notification - The notification object to process.
404-
* @param middlewareStack - The stack of notification middleware functions.
412+
* @param notificationMiddlewares - The stack of notification middleware functions.
405413
*/
406414
private static async _processNotification(
407415
notification: JsonRpcNotification<unknown>,
408-
middlewareStack: JsonRpcNotificationMiddleware<unknown>[],
416+
notificationMiddlewares: JsonRpcNotificationMiddleware<unknown>[],
409417
): Promise<void> {
410-
for (const middleware of middlewareStack) {
418+
for (const middleware of notificationMiddlewares) {
411419
await middleware(notification);
412420
}
413421
}
@@ -419,15 +427,15 @@ export class JsonRpcEngine extends SafeEventEmitter {
419427
*
420428
* @param req - The request object.
421429
* @param res - The response object.
422-
* @param middlewareStack - The stack of request middleware functions.
430+
* @param requestMiddlewares - The stack of request middleware functions.
423431
*/
424432
private static async _processRequest(
425433
req: JsonRpcRequest<unknown>,
426434
res: PendingJsonRpcResponse<unknown>,
427-
middlewareStack: JsonRpcMiddleware<unknown, unknown>[],
435+
requestMiddlewares: JsonRpcMiddleware<unknown, unknown>[],
428436
): Promise<void> {
429437
const [error, isComplete, returnHandlers] =
430-
await JsonRpcEngine._runAllMiddleware(req, res, middlewareStack);
438+
await JsonRpcEngine._runAllMiddleware(req, res, requestMiddlewares);
431439

432440
// Throw if "end" was not called, or if the response has neither a result
433441
// nor an error.
@@ -449,15 +457,15 @@ export class JsonRpcEngine extends SafeEventEmitter {
449457
*
450458
* @param req - The request object.
451459
* @param res - The response object.
452-
* @param middlewareStack - The stack of middleware functions to execute.
460+
* @param requestMiddlewares - The stack of middleware functions to execute.
453461
* @returns An array of any error encountered during middleware execution,
454462
* a boolean indicating whether the request was completed, and an array of
455463
* middleware-defined return handlers.
456464
*/
457465
private static async _runAllMiddleware(
458466
req: JsonRpcRequest<unknown>,
459467
res: PendingJsonRpcResponse<unknown>,
460-
middlewareStack: JsonRpcMiddleware<unknown, unknown>[],
468+
requestMiddlewares: JsonRpcMiddleware<unknown, unknown>[],
461469
): Promise<
462470
[
463471
unknown, // error
@@ -470,7 +478,7 @@ export class JsonRpcEngine extends SafeEventEmitter {
470478
let isComplete = false;
471479

472480
// Go down stack of middleware, call and collect optional returnHandlers
473-
for (const middleware of middlewareStack) {
481+
for (const middleware of requestMiddlewares) {
474482
[error, isComplete] = await JsonRpcEngine._runMiddleware(
475483
req,
476484
res,

0 commit comments

Comments
 (0)