Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test using @metamask/utils@8.0.0 #276

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
247 changes: 247 additions & 0 deletions .yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions .yarn/patches/@metamask-utils-npm-7.1.0-4e01225a9e.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
diff --git a/dist/types/json.d.ts b/dist/types/json.d.ts
index cb6272ee23e3a97aeeb52dcbd3ee1e20f3d8005c..1533dcbb925903367f6cf082a4a54d5aa306caf9 100644
--- a/dist/types/json.d.ts
+++ b/dist/types/json.d.ts
@@ -88,18 +88,18 @@ export declare type OptionalField<Type extends Record<string, unknown>, Key exte
* `OptionalField` helper, to explicitly make it optional.
*/
export declare type JsonRpcError = OptionalField<Infer<typeof JsonRpcErrorStruct>, 'data'>;
-export declare const JsonRpcParamsStruct: Struct<Json[] | Record<string, Json> | undefined, null>;
-export declare type JsonRpcParams = Infer<typeof JsonRpcParamsStruct>;
+export declare const JsonRpcParamsStruct: Struct<Json[] | Record<string, Json>, null>;
+export declare type JsonRpcParams = Json[] | Record<string, Json>;
export declare const JsonRpcRequestStruct: Struct<{
id: string | number | null;
method: string;
jsonrpc: "2.0";
- params?: Json[] | Record<string, Json> | undefined;
+ params: Json[] | Record<string, Json>;
}, {
id: Struct<string | number | null, null>;
jsonrpc: Struct<"2.0", "2.0">;
method: Struct<string, null>;
- params: Struct<Json[] | Record<string, Json> | undefined, null>;
+ params: Struct<Json[] | Record<string, Json>, null>;
}>;
export declare type InferWithParams<Type extends Struct<any>, Params extends JsonRpcParams> = Omit<Infer<Type>, 'params'> & (keyof Params extends undefined ? {
params?: Params;
@@ -113,12 +113,12 @@ export declare type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams>
export declare const JsonRpcNotificationStruct: Struct<{
method: string;
jsonrpc: "2.0";
- params?: Json[] | Record<string, Json> | undefined;
+ params: Json[] | Record<string, Json>;
}, Omit<{
id: Struct<string | number | null, null>;
jsonrpc: Struct<"2.0", "2.0">;
method: Struct<string, null>;
- params: Struct<Json[] | Record<string, Json> | undefined, null>;
+ params: Struct<Json[] | Record<string, Json>, null>;
}, "id">>;
/**
* A JSON-RPC notification object.
diff --git a/dist/types/json.d.ts.map b/dist/types/json.d.ts.map
index e4b182c6d30a4cecf94bdc97d2402d7395f21d24..b8af457fd46d71f4687d6164df970f05e392966e 100644
--- a/dist/types/json.d.ts.map
+++ b/dist/types/json.d.ts.map
@@ -1 +1 @@
-{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAuBjD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAG1D;;GAEG;AACH,oBAAY,IAAI,GACZ,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,IAAI,EAAE,GACN;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAa7B;;;;GAIG;AAEH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAUxC,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,UAAU,uBAWrB,CAAC;AAEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAOzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI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AC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAExE;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EAEd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,cAAc,CAOjC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EAEd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,YAAY,CAO/B;AAED,aAAK,uBAAuB,GAAG;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,uBAAuB,QAevC,OAAO,kCAStC"}
\ No newline at end of file
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@
"test": "jest && jest-it-up",
"test:watch": "jest --watch"
},
"resolutions": {
"@metamask/rpc-errors@^5.1.1": "patch:@metamask/rpc-errors@npm:5.1.1#.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch"
},
"dependencies": {
"@metamask/json-rpc-engine": "^7.0.0",
"@metamask/object-multiplex": "^1.1.0",
"@metamask/rpc-errors": "^5.1.1",
"@metamask/safe-event-emitter": "^3.0.0",
"@metamask/utils": "^8.0.0",
"detect-browser": "^5.2.0",
"eth-rpc-errors": "^4.0.2",
"extension-port-stream": "^2.0.1",
"fast-deep-equal": "^3.1.3",
"is-stream": "^2.0.0",
"json-rpc-engine": "^6.1.0",
"json-rpc-middleware-stream": "^4.2.1",
"pump": "^3.0.0",
"webextension-polyfill": "^0.10.0"
Expand Down
39 changes: 17 additions & 22 deletions src/BaseProvider.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { JsonRpcEngine, JsonRpcMiddleware } from '@metamask/json-rpc-engine';
import { rpcErrors, JsonRpcError } from '@metamask/rpc-errors';
import SafeEventEmitter from '@metamask/safe-event-emitter';
import { ethErrors, EthereumRpcError } from 'eth-rpc-errors';
import dequal from 'fast-deep-equal';
import {
JsonRpcEngine,
JsonRpcRequest,
JsonRpcId,
JsonRpcVersion,
JsonRpcVersion2,
JsonRpcSuccess,
JsonRpcMiddleware,
} from 'json-rpc-engine';
JsonRpcParams,
Json,
} from '@metamask/utils';
import dequal from 'fast-deep-equal';

import messages from './messages';
import {
Expand All @@ -20,7 +21,7 @@ import {

export type UnvalidatedJsonRpcRequest = {
id?: JsonRpcId;
jsonrpc?: JsonRpcVersion;
jsonrpc?: JsonRpcVersion2;
method: string;
params?: unknown;
};
Expand All @@ -37,10 +38,10 @@ export type BaseProviderOptions = {
maxEventListeners?: number;

/**
* `json-rpc-engine` middleware. The middleware will be inserted in the given
* `@metamask/json-rpc-engine` middleware. The middleware will be inserted in the given
* order immediately after engine initialization.
*/
rpcMiddleware?: JsonRpcMiddleware<unknown, unknown>[];
rpcMiddleware?: JsonRpcMiddleware<JsonRpcParams, Json>[];
};

export type RequestArguments = {
Expand Down Expand Up @@ -169,7 +170,7 @@ export abstract class BaseProvider extends SafeEventEmitter {
*/
async request<T>(args: RequestArguments): Promise<Maybe<T>> {
if (!args || typeof args !== 'object' || Array.isArray(args)) {
throw ethErrors.rpc.invalidRequest({
throw rpcErrors.invalidRequest({
message: messages.errors.invalidRequestArgs(),
data: args,
});
Expand All @@ -178,7 +179,7 @@ export abstract class BaseProvider extends SafeEventEmitter {
const { method, params } = args;

if (typeof method !== 'string' || method.length === 0) {
throw ethErrors.rpc.invalidRequest({
throw rpcErrors.invalidRequest({
message: messages.errors.invalidRequestMethod(),
data: args,
});
Expand All @@ -189,7 +190,7 @@ export abstract class BaseProvider extends SafeEventEmitter {
!Array.isArray(params) &&
(typeof params !== 'object' || params === null)
) {
throw ethErrors.rpc.invalidRequest({
throw rpcErrors.invalidRequest({
message: messages.errors.invalidRequestParams(),
data: args,
});
Expand Down Expand Up @@ -285,15 +286,9 @@ export abstract class BaseProvider extends SafeEventEmitter {
callback(error, response);
};
}
return this._rpcEngine.handle(
payload as JsonRpcRequest<unknown>,
callbackWrapper,
);
return this._rpcEngine.handle(payload as JsonRpcRequest, callbackWrapper);
}
return this._rpcEngine.handle(
payload as JsonRpcRequest<unknown>[],
callbackWrapper,
);
return this._rpcEngine.handle(payload as JsonRpcRequest[], callbackWrapper);
}

/**
Expand Down Expand Up @@ -331,13 +326,13 @@ export abstract class BaseProvider extends SafeEventEmitter {

let error;
if (isRecoverable) {
error = new EthereumRpcError(
error = new JsonRpcError(
1013, // Try again later
errorMessage ?? messages.errors.disconnected(),
);
this._log.debug(error);
} else {
error = new EthereumRpcError(
error = new JsonRpcError(
1011, // Internal error
errorMessage ?? messages.errors.permanentlyDisconnected(),
);
Expand Down
4 changes: 2 additions & 2 deletions src/MetaMaskInpageProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsonRpcRequest } from 'json-rpc-engine';
import { JsonRpcRequest } from '@metamask/utils';

import messages from './messages';
import {
Expand Down Expand Up @@ -58,7 +58,7 @@ async function getInitializedProvider({
onMethodCalled?: {
substream: string;
method: string;
callback: (data: JsonRpcRequest<unknown>) => void;
callback: (data: JsonRpcRequest) => void;
}[];
} = {}): Promise<InitializedProviderDetails> {
const onWrite = jest.fn();
Expand Down
27 changes: 15 additions & 12 deletions src/MetaMaskInpageProvider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ethErrors } from 'eth-rpc-errors';
import type { JsonRpcRequest, JsonRpcResponse } from 'json-rpc-engine';
import { rpcErrors } from '@metamask/rpc-errors';
import type { Json, JsonRpcRequest, JsonRpcResponse } from '@metamask/utils';
import type { Duplex } from 'stream';

import type { UnvalidatedJsonRpcRequest } from './BaseProvider';
import { UnvalidatedJsonRpcRequest } from './BaseProvider';
import messages from './messages';
import { sendSiteMetadata } from './siteMetadata';
import {
Expand All @@ -22,7 +22,7 @@ export type SendSyncJsonRpcRequest = {
| 'eth_coinbase'
| 'eth_uninstallFilter'
| 'net_version';
} & JsonRpcRequest<unknown>;
} & JsonRpcRequest;

type WarningEventName = keyof SentWarningsState['events'];

Expand Down Expand Up @@ -171,8 +171,8 @@ export class MetaMaskInpageProvider extends AbstractStreamProvider {
* @param callback - The callback function.
*/
sendAsync(
payload: JsonRpcRequest<unknown>,
callback: (error: Error | null, result?: JsonRpcResponse<unknown>) => void,
payload: JsonRpcRequest,
callback: (error: Error | null, result?: JsonRpcResponse<Json>) => void,
): void {
this._rpcRequest(payload, callback);
}
Expand Down Expand Up @@ -283,7 +283,10 @@ export class MetaMaskInpageProvider extends AbstractStreamProvider {
* @returns A Promise that resolves with the JSON-RPC response object for the
* request.
*/
send<T>(method: string, params?: T[]): Promise<JsonRpcResponse<T>>;
send<T extends Json>(
method: string,
params?: T[],
): Promise<JsonRpcResponse<T>>;

/**
* Submits an RPC request per the given JSON-RPC request object.
Expand All @@ -293,8 +296,8 @@ export class MetaMaskInpageProvider extends AbstractStreamProvider {
* @param callback - An error-first callback that will receive the JSON-RPC
* response object.
*/
send<T>(
payload: JsonRpcRequest<unknown>,
send<T extends Json>(
payload: JsonRpcRequest,
callback: (error: Error | null, result?: JsonRpcResponse<T>) => void,
): void;

Expand All @@ -306,7 +309,7 @@ export class MetaMaskInpageProvider extends AbstractStreamProvider {
* @param payload - A JSON-RPC request object.
* @returns A JSON-RPC response object.
*/
send<T>(payload: SendSyncJsonRpcRequest): JsonRpcResponse<T>;
send<T extends Json>(payload: SendSyncJsonRpcRequest): JsonRpcResponse<T>;

// eslint-disable-next-line @typescript-eslint/promise-function-async
send(methodOrPayload: unknown, callbackOrArgs?: unknown): unknown {
Expand Down Expand Up @@ -335,7 +338,7 @@ export class MetaMaskInpageProvider extends AbstractStreamProvider {
typeof callbackOrArgs === 'function'
) {
return this._rpcRequest(
methodOrPayload as JsonRpcRequest<unknown>,
methodOrPayload as JsonRpcRequest,
callbackOrArgs as (...args: unknown[]) => void,
);
}
Expand Down Expand Up @@ -412,7 +415,7 @@ export class MetaMaskInpageProvider extends AbstractStreamProvider {
*/
requestBatch: async (requests: UnvalidatedJsonRpcRequest[]) => {
if (!Array.isArray(requests)) {
throw ethErrors.rpc.invalidRequest({
throw rpcErrors.invalidRequest({
message:
'Batch requests must be made with an array of request objects.',
data: requests,
Expand Down
5 changes: 3 additions & 2 deletions src/StreamProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { JsonRpcMiddleware } from 'json-rpc-engine';
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
import { Json, JsonRpcParams } from '@metamask/utils';

import messages from './messages';
import { StreamProvider } from './StreamProvider';
Expand All @@ -15,7 +16,7 @@ const mockStreamName = 'mock-stream';
* @returns A tuple containing the StreamProvider instance and the mock stream.
*/
function getStreamProvider(
rpcMiddleware: JsonRpcMiddleware<unknown, unknown>[] = [],
rpcMiddleware: JsonRpcMiddleware<JsonRpcParams, Json>[] = [],
) {
const mockStream = new MockConnectionStream();
const streamProvider = new StreamProvider(mockStream, {
Expand Down
Loading