From 0968bf01b4c00b7692509c61700efbdf6e9a6c3d Mon Sep 17 00:00:00 2001 From: legobeat <109787230+legobeat@users.noreply.github.com> Date: Mon, 25 Sep 2023 08:45:03 +0000 Subject: [PATCH] deps: replace deep-cloning implementation `clone` with `klona` (#250) * deps: pify@3.0.0->^5.0.0 * deps: safe-stable-stringify@^2.3.2->^2.4.3 * deps: replace clone with klona --- package.json | 9 ++++---- src/block-ref.ts | 4 ++-- src/inflight-cache.ts | 6 ++--- src/retryOnEmpty.ts | 4 ++-- test/util/helpers.ts | 4 ++-- yarn.lock | 53 ++++++++++++++++--------------------------- 6 files changed, 32 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index b63eb435..6f5cbf49 100644 --- a/package.json +++ b/package.json @@ -33,10 +33,10 @@ "@metamask/json-rpc-engine": "^7.1.1", "@metamask/rpc-errors": "^6.0.0", "@metamask/utils": "^8.1.0", - "clone": "^2.1.1", "eth-block-tracker": "^8.0.0", - "pify": "^3.0.0", - "safe-stable-stringify": "^2.3.2" + "klona": "^2.0.6", + "pify": "^5.0.0", + "safe-stable-stringify": "^2.4.3" }, "devDependencies": { "@jest/globals": "^27.5.1", @@ -47,10 +47,9 @@ "@metamask/eslint-config-nodejs": "^12.1.0", "@metamask/eslint-config-typescript": "^12.1.0", "@types/btoa": "^1.2.3", - "@types/clone": "^2.1.0", "@types/jest": "^27.4.1", "@types/node": "^17.0.23", - "@types/pify": "^3.0.2", + "@types/pify": "^5.0.2", "@typescript-eslint/eslint-plugin": "^5.42.1", "@typescript-eslint/parser": "^5.42.1", "eslint": "^8.44.0", diff --git a/src/block-ref.ts b/src/block-ref.ts index c4627fee..0146ee12 100644 --- a/src/block-ref.ts +++ b/src/block-ref.ts @@ -6,8 +6,8 @@ import type { JsonRpcParams, PendingJsonRpcResponse, } from '@metamask/utils'; -import clone from 'clone'; import type { PollingBlockTracker } from 'eth-block-tracker'; +import { klona } from 'klona/full'; import pify from 'pify'; import { projectLogger, createModuleLogger } from './logging-utils'; @@ -60,7 +60,7 @@ export function createBlockRefMiddleware({ ); // create child request with specific block-ref - const childRequest = clone(req); + const childRequest = klona(req); if (Array.isArray(childRequest.params)) { childRequest.params[blockRefIndex] = latestBlockNumber; diff --git a/src/inflight-cache.ts b/src/inflight-cache.ts index d65fdbe5..a5b94312 100644 --- a/src/inflight-cache.ts +++ b/src/inflight-cache.ts @@ -4,7 +4,7 @@ import type { Json, PendingJsonRpcResponse, } from '@metamask/utils'; -import clone from 'clone'; +import { klona } from 'klona/full'; import { projectLogger, createModuleLogger } from './logging-utils'; import type { JsonRpcRequestToCache, JsonRpcCacheMiddleware } from './types'; @@ -78,8 +78,8 @@ export function createInflightCacheMiddleware(): JsonRpcCacheMiddleware< const { resolve, promise } = deferredPromise(); activeRequestHandlers.push((handledRes: PendingJsonRpcResponse) => { // append a copy of the result and error to the response - res.result = clone(handledRes.result); - res.error = clone(handledRes.error); + res.result = klona(handledRes.result); + res.error = klona(handledRes.error); resolve(); }); return promise; diff --git a/src/retryOnEmpty.ts b/src/retryOnEmpty.ts index 9bb4dfb2..f4e717e4 100644 --- a/src/retryOnEmpty.ts +++ b/src/retryOnEmpty.ts @@ -6,8 +6,8 @@ import type { JsonRpcParams, PendingJsonRpcResponse, } from '@metamask/utils'; -import clone from 'clone'; import type { PollingBlockTracker } from 'eth-block-tracker'; +import { klona } from 'klona/full'; import pify from 'pify'; import { projectLogger, createModuleLogger } from './logging-utils'; @@ -100,7 +100,7 @@ export function createRetryOnEmptyMiddleware({ ); // create child request with specific block-ref - const childRequest = clone(req); + const childRequest = klona(req); // attempt child request until non-empty response is received const childResponse: PendingJsonRpcResponse = await retry( 10, diff --git a/test/util/helpers.ts b/test/util/helpers.ts index 9acca7a3..f6380304 100644 --- a/test/util/helpers.ts +++ b/test/util/helpers.ts @@ -6,7 +6,7 @@ import type { JsonRpcRequest, JsonRpcResponse, } from '@metamask/utils'; -import clone from 'clone'; +import { klona } from 'klona/full'; import { isDeepStrictEqual } from 'util'; /** @@ -212,7 +212,7 @@ export function stubProviderRequests( provider: SafeEventEmitterProvider, stubs: ProviderRequestStub[], ) { - const remainingStubs = clone(stubs); + const remainingStubs = klona(stubs); const callNumbersByRequest = new Map, number>(); return jest.spyOn(provider, 'sendAsync').mockImplementation((request, cb) => { const stubIndex = remainingStubs.findIndex((stub) => diff --git a/yarn.lock b/yarn.lock index 7541f77b..61d47ff0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -987,13 +987,11 @@ __metadata: "@metamask/rpc-errors": ^6.0.0 "@metamask/utils": ^8.1.0 "@types/btoa": ^1.2.3 - "@types/clone": ^2.1.0 "@types/jest": ^27.4.1 "@types/node": ^17.0.23 - "@types/pify": ^3.0.2 + "@types/pify": ^5.0.2 "@typescript-eslint/eslint-plugin": ^5.42.1 "@typescript-eslint/parser": ^5.42.1 - clone: ^2.1.1 eslint: ^8.44.0 eslint-config-prettier: ^8.1.0 eslint-plugin-import: ^2.27.5 @@ -1004,11 +1002,12 @@ __metadata: eslint-plugin-promise: ^6.1.1 eth-block-tracker: ^8.0.0 jest: ^27.5.1 - pify: ^3.0.0 + klona: ^2.0.6 + pify: ^5.0.0 prettier: ^2.2.1 prettier-plugin-packagejson: ^2.2.11 rimraf: ^3.0.2 - safe-stable-stringify: ^2.3.2 + safe-stable-stringify: ^2.4.3 ts-jest: ^27.1.4 ts-node: ^10.7.0 typescript: ~4.8.4 @@ -1336,13 +1335,6 @@ __metadata: languageName: node linkType: hard -"@types/clone@npm:^2.1.0": - version: 2.1.1 - resolution: "@types/clone@npm:2.1.1" - checksum: bda9668b9d6e0875d64bbe00763676f566e8647bc224333a03ac7fd66655dfed56a98a9f8304d0145c4411b964649c84c4d1a03adbdb6547eafb9ab8f303d254 - languageName: node - linkType: hard - "@types/debug@npm:^4.1.7": version: 4.1.7 resolution: "@types/debug@npm:4.1.7" @@ -1448,10 +1440,10 @@ __metadata: languageName: node linkType: hard -"@types/pify@npm:^3.0.2": - version: 3.0.2 - resolution: "@types/pify@npm:3.0.2" - checksum: 965f0fb0d7e414332cf952c8e7e3af002878ebf99811845ab78750d574119abc3ccf7d5e7ad7d71f579b1e43c2c40f9ac9ba89c3d55a5d8e4688f43fb1213044 +"@types/pify@npm:^5.0.2": + version: 5.0.2 + resolution: "@types/pify@npm:5.0.2" + checksum: dcfa7aad04cdab4cf006d7c4af651137080749678ab87abdb768d3f3228872c23fa7516e4a169b20b325ef3fe38668ca28b9a00155c3911eb1c2c1ba1bdc59af languageName: node linkType: hard @@ -2223,13 +2215,6 @@ __metadata: languageName: node linkType: hard -"clone@npm:^2.1.1": - version: 2.1.2 - resolution: "clone@npm:2.1.2" - checksum: aaf106e9bc025b21333e2f4c12da539b568db4925c0501a1bf4070836c9e848c892fa22c35548ce0d1132b08bbbfa17a00144fe58fccdab6fa900fec4250f67d - languageName: node - linkType: hard - "cmd-shim@npm:^6.0.0": version: 6.0.1 resolution: "cmd-shim@npm:6.0.1" @@ -4734,6 +4719,13 @@ __metadata: languageName: node linkType: hard +"klona@npm:^2.0.6": + version: 2.0.6 + resolution: "klona@npm:2.0.6" + checksum: ac9ee3732e42b96feb67faae4d27cf49494e8a3bf3fa7115ce242fe04786788e0aff4741a07a45a2462e2079aa983d73d38519c85d65b70ef11447bbc3c58ce7 + languageName: node + linkType: hard + "leven@npm:^3.1.0": version: 3.1.0 resolution: "leven@npm:3.1.0" @@ -5474,13 +5466,6 @@ __metadata: languageName: node linkType: hard -"pify@npm:^3.0.0": - version: 3.0.0 - resolution: "pify@npm:3.0.0" - checksum: 6cdcbc3567d5c412450c53261a3f10991665d660961e06605decf4544a61a97a54fefe70a68d5c37080ff9d6f4cf51444c90198d1ba9f9309a6c0d6e9f5c4fde - languageName: node - linkType: hard - "pify@npm:^5.0.0": version: 5.0.0 resolution: "pify@npm:5.0.0" @@ -5795,10 +5780,10 @@ __metadata: languageName: node linkType: hard -"safe-stable-stringify@npm:^2.3.2": - version: 2.4.2 - resolution: "safe-stable-stringify@npm:2.4.2" - checksum: 0324ba2e40f78cae63e31a02b1c9bdf1b786621f9e8760845608eb9e81aef401944ac2078e5c9c1533cf516aea34d08fa8052ca853637ced84b791caaf1e394e +"safe-stable-stringify@npm:^2.4.3": + version: 2.4.3 + resolution: "safe-stable-stringify@npm:2.4.3" + checksum: 3aeb64449706ee1f5ad2459fc99648b131d48e7a1fbb608d7c628020177512dc9d94108a5cb61bbc953985d313d0afea6566d243237743e02870490afef04b43 languageName: node linkType: hard