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

BREAKING: Use @metamask/utils #105

Merged
merged 4 commits into from
May 16, 2022
Merged

BREAKING: Use @metamask/utils #105

merged 4 commits into from
May 16, 2022

Conversation

rekmarks
Copy link
Member

@rekmarks rekmarks commented May 16, 2022

Replace various utility types and functions with implementations copied over to @metamask/utils. Functionality should be practically identical.

The one possible deviation is that two in checks have been replaced with hasProperty, which does not walk the prototype chain. This should not be breaking for our purposes.

@rekmarks rekmarks marked this pull request as ready for review May 16, 2022 22:07
@rekmarks rekmarks requested a review from a team as a code owner May 16, 2022 22:07
@rekmarks rekmarks changed the title Use @metamask/utils BREAKING: Use @metamask/utils May 16, 2022
@@ -487,7 +441,7 @@ export class JsonRpcEngine extends SafeEventEmitter {
res: PendingJsonRpcResponse<unknown>,
isComplete: boolean,
): void {
if (!('result' in res) && !('error' in res)) {
if (!hasProperty(res, 'result') && !hasProperty(res, 'error')) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replaced in checks.

Copy link

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me!

export type JsonRpcMiddleware<T, U> = (
req: JsonRpcRequest<T>,
res: PendingJsonRpcResponse<U>,
export type JsonRpcMiddleware<Params, Result> = (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like these type parameter names a lot better than T and U 👍🏻

result?: T;
error?: Error | JsonRpcError;
}
export type PendingJsonRpcResponse<Result> = Omit<
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not suggesting any changes, but I wonder if this is type is right, considering that it seems that such a response can theoretically have both result and error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is meant to be used inside middleware functions and internally in JsonRpcEngine during request processing. It permits both, either, or neither property being present. Or did you mean something else?

@rekmarks rekmarks merged commit 61e159f into main May 16, 2022
@rekmarks rekmarks deleted the use-@metamask/utils branch May 16, 2022 23:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants