@metamask/polling-controller
Advanced tools
Comparing version 5.0.1 to 6.0.0
@@ -10,2 +10,16 @@ # Changelog | ||
## [6.0.0] | ||
### Added | ||
- **BREAKING**: Add ESM build ([#3998](https://github.com/MetaMask/core/pull/3998)) | ||
- It's no longer possible to import files from `./dist` directly. | ||
### Changed | ||
- **BREAKING:** Bump `@metamask/base-controller` to `^5.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039)) | ||
- This version has a number of breaking changes. See the changelog for more. | ||
- **BREAKING:** Bump dependency and peer dependency on `@metamask/network-controller` to `^18.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039)) | ||
- Bump `@metamask/controller-utils` to `^9.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039)) | ||
## [5.0.1] | ||
@@ -99,3 +113,4 @@ | ||
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@5.0.1...HEAD | ||
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@6.0.0...HEAD | ||
[6.0.0]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@5.0.1...@metamask/polling-controller@6.0.0 | ||
[5.0.1]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@5.0.0...@metamask/polling-controller@5.0.1 | ||
@@ -102,0 +117,0 @@ [5.0.0]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@4.0.0...@metamask/polling-controller@5.0.0 |
@@ -1,87 +0,9 @@ | ||
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AbstractPollingControllerBaseMixin = exports.getKey = void 0; | ||
const fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify")); | ||
const uuid_1 = require("uuid"); | ||
const getKey = (networkClientId, options) => `${networkClientId}:${(0, fast_json_stable_stringify_1.default)(options)}`; | ||
exports.getKey = getKey; | ||
/** | ||
* AbstractPollingControllerBaseMixin | ||
* | ||
* @param Base - The base class to mix onto. | ||
* @returns The composed class. | ||
*/ | ||
function AbstractPollingControllerBaseMixin(Base) { | ||
var _AbstractPollingControllerBase_pollingTokenSets, _AbstractPollingControllerBase_callbacks; | ||
class AbstractPollingControllerBase extends Base { | ||
constructor() { | ||
super(...arguments); | ||
_AbstractPollingControllerBase_pollingTokenSets.set(this, new Map()); | ||
_AbstractPollingControllerBase_callbacks.set(this, new Map()); | ||
} | ||
startPollingByNetworkClientId(networkClientId, options = {}) { | ||
var _a; | ||
const pollToken = (0, uuid_1.v4)(); | ||
const key = (0, exports.getKey)(networkClientId, options); | ||
const pollingTokenSet = (_a = __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").get(key)) !== null && _a !== void 0 ? _a : new Set(); | ||
pollingTokenSet.add(pollToken); | ||
__classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").set(key, pollingTokenSet); | ||
if (pollingTokenSet.size === 1) { | ||
this._startPollingByNetworkClientId(networkClientId, options); | ||
} | ||
return pollToken; | ||
} | ||
stopAllPolling() { | ||
__classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").forEach((tokenSet, _key) => { | ||
tokenSet.forEach((token) => { | ||
this.stopPollingByPollingToken(token); | ||
}); | ||
}); | ||
} | ||
stopPollingByPollingToken(pollingToken) { | ||
if (!pollingToken) { | ||
throw new Error('pollingToken required'); | ||
} | ||
let keyToDelete = null; | ||
for (const [key, tokenSet] of __classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f")) { | ||
if (tokenSet.delete(pollingToken)) { | ||
if (tokenSet.size === 0) { | ||
keyToDelete = key; | ||
} | ||
break; | ||
} | ||
} | ||
if (keyToDelete) { | ||
this._stopPollingByPollingTokenSetId(keyToDelete); | ||
__classPrivateFieldGet(this, _AbstractPollingControllerBase_pollingTokenSets, "f").delete(keyToDelete); | ||
const callbacks = __classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").get(keyToDelete); | ||
if (callbacks) { | ||
for (const callback of callbacks) { | ||
// eslint-disable-next-line n/callback-return | ||
callback(keyToDelete); | ||
} | ||
callbacks.clear(); | ||
} | ||
} | ||
} | ||
onPollingCompleteByNetworkClientId(networkClientId, callback, options = {}) { | ||
var _a; | ||
const key = (0, exports.getKey)(networkClientId, options); | ||
const callbacks = (_a = __classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").get(key)) !== null && _a !== void 0 ? _a : new Set(); | ||
callbacks.add(callback); | ||
__classPrivateFieldGet(this, _AbstractPollingControllerBase_callbacks, "f").set(key, callbacks); | ||
} | ||
} | ||
_AbstractPollingControllerBase_pollingTokenSets = new WeakMap(), _AbstractPollingControllerBase_callbacks = new WeakMap(); | ||
return AbstractPollingControllerBase; | ||
} | ||
exports.AbstractPollingControllerBaseMixin = AbstractPollingControllerBaseMixin; | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunk4HJ6GRV5js = require('./chunk-4HJ6GRV5.js'); | ||
exports.AbstractPollingControllerBaseMixin = _chunk4HJ6GRV5js.AbstractPollingControllerBaseMixin; exports.getKey = _chunk4HJ6GRV5js.getKey; | ||
//# sourceMappingURL=AbstractPollingController.js.map |
@@ -1,60 +0,12 @@ | ||
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BlockTrackerPollingControllerV1 = exports.BlockTrackerPollingController = exports.BlockTrackerPollingControllerOnly = void 0; | ||
const base_controller_1 = require("@metamask/base-controller"); | ||
const AbstractPollingController_1 = require("./AbstractPollingController"); | ||
/** | ||
* BlockTrackerPollingControllerMixin | ||
* A polling controller that polls using a block tracker. | ||
* | ||
* @param Base - The base class to mix onto. | ||
* @returns The composed class. | ||
*/ | ||
function BlockTrackerPollingControllerMixin(Base) { | ||
var _BlockTrackerPollingController_activeListeners; | ||
class BlockTrackerPollingController extends (0, AbstractPollingController_1.AbstractPollingControllerBaseMixin)(Base) { | ||
constructor() { | ||
super(...arguments); | ||
_BlockTrackerPollingController_activeListeners.set(this, {}); | ||
} | ||
_startPollingByNetworkClientId(networkClientId, options) { | ||
const key = (0, AbstractPollingController_1.getKey)(networkClientId, options); | ||
if (__classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key]) { | ||
return; | ||
} | ||
const networkClient = this._getNetworkClientById(networkClientId); | ||
if (networkClient) { | ||
const updateOnNewBlock = this._executePoll.bind(this, networkClientId, options); | ||
networkClient.blockTracker.addListener('latest', updateOnNewBlock); | ||
__classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key] = updateOnNewBlock; | ||
} | ||
else { | ||
throw new Error(`Unable to retrieve blockTracker for networkClientId ${networkClientId}`); | ||
} | ||
} | ||
_stopPollingByPollingTokenSetId(key) { | ||
const [networkClientId] = key.split(':'); | ||
const networkClient = this._getNetworkClientById(networkClientId); | ||
if (networkClient && __classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key]) { | ||
const listener = __classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key]; | ||
if (listener) { | ||
networkClient.blockTracker.removeListener('latest', listener); | ||
delete __classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key]; | ||
} | ||
} | ||
} | ||
} | ||
_BlockTrackerPollingController_activeListeners = new WeakMap(); | ||
return BlockTrackerPollingController; | ||
} | ||
class Empty { | ||
} | ||
exports.BlockTrackerPollingControllerOnly = BlockTrackerPollingControllerMixin(Empty); | ||
exports.BlockTrackerPollingController = BlockTrackerPollingControllerMixin(base_controller_1.BaseController); | ||
exports.BlockTrackerPollingControllerV1 = BlockTrackerPollingControllerMixin(base_controller_1.BaseControllerV1); | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkJEAX4QNHjs = require('./chunk-JEAX4QNH.js'); | ||
require('./chunk-4HJ6GRV5.js'); | ||
exports.BlockTrackerPollingController = _chunkJEAX4QNHjs.BlockTrackerPollingController; exports.BlockTrackerPollingControllerOnly = _chunkJEAX4QNHjs.BlockTrackerPollingControllerOnly; exports.BlockTrackerPollingControllerV1 = _chunkJEAX4QNHjs.BlockTrackerPollingControllerV1; | ||
//# sourceMappingURL=BlockTrackerPollingController.js.map |
@@ -1,12 +0,20 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StaticIntervalPollingControllerV1 = exports.StaticIntervalPollingController = exports.StaticIntervalPollingControllerOnly = exports.BlockTrackerPollingControllerV1 = exports.BlockTrackerPollingController = exports.BlockTrackerPollingControllerOnly = void 0; | ||
var BlockTrackerPollingController_1 = require("./BlockTrackerPollingController"); | ||
Object.defineProperty(exports, "BlockTrackerPollingControllerOnly", { enumerable: true, get: function () { return BlockTrackerPollingController_1.BlockTrackerPollingControllerOnly; } }); | ||
Object.defineProperty(exports, "BlockTrackerPollingController", { enumerable: true, get: function () { return BlockTrackerPollingController_1.BlockTrackerPollingController; } }); | ||
Object.defineProperty(exports, "BlockTrackerPollingControllerV1", { enumerable: true, get: function () { return BlockTrackerPollingController_1.BlockTrackerPollingControllerV1; } }); | ||
var StaticIntervalPollingController_1 = require("./StaticIntervalPollingController"); | ||
Object.defineProperty(exports, "StaticIntervalPollingControllerOnly", { enumerable: true, get: function () { return StaticIntervalPollingController_1.StaticIntervalPollingControllerOnly; } }); | ||
Object.defineProperty(exports, "StaticIntervalPollingController", { enumerable: true, get: function () { return StaticIntervalPollingController_1.StaticIntervalPollingController; } }); | ||
Object.defineProperty(exports, "StaticIntervalPollingControllerV1", { enumerable: true, get: function () { return StaticIntervalPollingController_1.StaticIntervalPollingControllerV1; } }); | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkJEAX4QNHjs = require('./chunk-JEAX4QNH.js'); | ||
var _chunkLNXPCWKHjs = require('./chunk-LNXPCWKH.js'); | ||
require('./chunk-4HJ6GRV5.js'); | ||
exports.BlockTrackerPollingController = _chunkJEAX4QNHjs.BlockTrackerPollingController; exports.BlockTrackerPollingControllerOnly = _chunkJEAX4QNHjs.BlockTrackerPollingControllerOnly; exports.BlockTrackerPollingControllerV1 = _chunkJEAX4QNHjs.BlockTrackerPollingControllerV1; exports.StaticIntervalPollingController = _chunkLNXPCWKHjs.StaticIntervalPollingController; exports.StaticIntervalPollingControllerOnly = _chunkLNXPCWKHjs.StaticIntervalPollingControllerOnly; exports.StaticIntervalPollingControllerV1 = _chunkLNXPCWKHjs.StaticIntervalPollingControllerV1; | ||
//# sourceMappingURL=index.js.map |
@@ -1,80 +0,12 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StaticIntervalPollingControllerV1 = exports.StaticIntervalPollingController = exports.StaticIntervalPollingControllerOnly = void 0; | ||
const base_controller_1 = require("@metamask/base-controller"); | ||
const AbstractPollingController_1 = require("./AbstractPollingController"); | ||
/** | ||
* StaticIntervalPollingControllerMixin | ||
* A polling controller that polls on a static interval. | ||
* | ||
* @param Base - The base class to mix onto. | ||
* @returns The composed class. | ||
*/ | ||
function StaticIntervalPollingControllerMixin(Base) { | ||
var _StaticIntervalPollingController_intervalIds, _StaticIntervalPollingController_intervalLength; | ||
class StaticIntervalPollingController extends (0, AbstractPollingController_1.AbstractPollingControllerBaseMixin)(Base) { | ||
constructor() { | ||
super(...arguments); | ||
_StaticIntervalPollingController_intervalIds.set(this, {}); | ||
_StaticIntervalPollingController_intervalLength.set(this, 1000); | ||
} | ||
setIntervalLength(intervalLength) { | ||
__classPrivateFieldSet(this, _StaticIntervalPollingController_intervalLength, intervalLength, "f"); | ||
} | ||
getIntervalLength() { | ||
return __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f"); | ||
} | ||
_startPollingByNetworkClientId(networkClientId, options) { | ||
if (!__classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f")) { | ||
throw new Error('intervalLength must be defined and greater than 0'); | ||
} | ||
const key = (0, AbstractPollingController_1.getKey)(networkClientId, options); | ||
const existingInterval = __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key]; | ||
this._stopPollingByPollingTokenSetId(key); | ||
__classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key] = setTimeout(() => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield this._executePoll(networkClientId, options); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
} | ||
this._startPollingByNetworkClientId(networkClientId, options); | ||
}), existingInterval ? __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalLength, "f") : 0); | ||
} | ||
_stopPollingByPollingTokenSetId(key) { | ||
const intervalId = __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key]; | ||
if (intervalId) { | ||
clearTimeout(intervalId); | ||
delete __classPrivateFieldGet(this, _StaticIntervalPollingController_intervalIds, "f")[key]; | ||
} | ||
} | ||
} | ||
_StaticIntervalPollingController_intervalIds = new WeakMap(), _StaticIntervalPollingController_intervalLength = new WeakMap(); | ||
return StaticIntervalPollingController; | ||
} | ||
class Empty { | ||
} | ||
exports.StaticIntervalPollingControllerOnly = StaticIntervalPollingControllerMixin(Empty); | ||
exports.StaticIntervalPollingController = StaticIntervalPollingControllerMixin(base_controller_1.BaseController); | ||
exports.StaticIntervalPollingControllerV1 = StaticIntervalPollingControllerMixin(base_controller_1.BaseControllerV1); | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
var _chunkLNXPCWKHjs = require('./chunk-LNXPCWKH.js'); | ||
require('./chunk-4HJ6GRV5.js'); | ||
exports.StaticIntervalPollingController = _chunkLNXPCWKHjs.StaticIntervalPollingController; exports.StaticIntervalPollingControllerOnly = _chunkLNXPCWKHjs.StaticIntervalPollingControllerOnly; exports.StaticIntervalPollingControllerV1 = _chunkLNXPCWKHjs.StaticIntervalPollingControllerV1; | ||
//# sourceMappingURL=StaticIntervalPollingController.js.map |
{ | ||
"name": "@metamask/polling-controller", | ||
"version": "5.0.1", | ||
"version": "6.0.0", | ||
"description": "Polling Controller is the base for controllers that polling by networkClientId", | ||
@@ -18,2 +18,11 @@ "keywords": [ | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js", | ||
"types": "./dist/types/index.d.ts" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "./dist/index.js", | ||
@@ -25,2 +34,3 @@ "types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean", | ||
"build:docs": "typedoc", | ||
@@ -36,5 +46,5 @@ "changelog:update": "../../scripts/update-changelog.sh @metamask/polling-controller", | ||
"dependencies": { | ||
"@metamask/base-controller": "^4.1.1", | ||
"@metamask/controller-utils": "^8.0.4", | ||
"@metamask/network-controller": "^17.2.1", | ||
"@metamask/base-controller": "^5.0.0", | ||
"@metamask/controller-utils": "^9.0.0", | ||
"@metamask/network-controller": "^18.0.0", | ||
"@metamask/utils": "^8.3.0", | ||
@@ -57,3 +67,3 @@ "@types/uuid": "^8.3.0", | ||
"peerDependencies": { | ||
"@metamask/network-controller": "^17.2.0" | ||
"@metamask/network-controller": "^18.0.0" | ||
}, | ||
@@ -60,0 +70,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
123645
41
622
1
+ Added@metamask/base-controller@5.0.2(transitive)
+ Added@metamask/controller-utils@10.0.09.1.0(transitive)
+ Added@metamask/network-controller@18.1.3(transitive)
+ Added@noble/hashes@1.6.1(transitive)
+ Added@spruceid/siwe-parser@2.1.0(transitive)
+ Added@types/bn.js@5.1.6(transitive)
+ Added@types/node@22.10.0(transitive)
+ Addedasync-mutex@0.5.0(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedvalid-url@1.0.9(transitive)
- Removed@metamask/base-controller@4.1.1(transitive)
- Removed@metamask/controller-utils@8.0.4(transitive)
- Removed@metamask/network-controller@17.2.1(transitive)
- Removed@noble/hashes@1.5.0(transitive)
- Removed@spruceid/siwe-parser@1.1.3(transitive)
- Removedasync-mutex@0.2.6(transitive)
- Removedeth-block-tracker@8.1.0(transitive)