@metamask/polling-controller 16.0.0 → 16.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [16.0.2]
11
+
12
+ ### Changed
13
+
14
+ - Bump `@metamask/network-controller` from `^28.0.0` to `^29.0.0` ([#7642](https://github.com/MetaMask/core/pull/7642))
15
+
16
+ ## [16.0.1]
17
+
18
+ ### Changed
19
+
20
+ - Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))
21
+ - Move peer dependencies for controller and service packages to direct dependencies ([#7209](https://github.com/MetaMask/core/pull/7209), [#7258](https://github.com/MetaMask/core/pull/7258), [#7534](https://github.com/MetaMask/core/pull/7534), [#7583](https://github.com/MetaMask/core/pull/7583), [#7604](https://github.com/MetaMask/core/pull/7604))
22
+ - The dependencies moved are:
23
+ - `@metamask/network-controller` (^28.0.0)
24
+ - In clients, it is now possible for multiple versions of these packages to exist in the dependency tree.
25
+ - For example, this scenario would be valid: a client relies on `@metamask/controller-a` 1.0.0 and `@metamask/controller-b` 1.0.0, and `@metamask/controller-b` depends on `@metamask/controller-a` 1.1.0.
26
+ - Note, however, that the versions specified in the client's `package.json` always "win", and you are expected to keep them up to date so as not to break controller and service intercommunication.
27
+ - Bump `@metamask/controller-utils` from `^11.16.0` to `^11.18.0` ([#7534](https://github.com/MetaMask/core/pull/7534), [#7583](https://github.com/MetaMask/core/pull/7583))
28
+
10
29
  ## [16.0.0]
11
30
 
12
31
  ### Changed
@@ -280,7 +299,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
280
299
 
281
300
  - Initial release
282
301
 
283
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@16.0.0...HEAD
302
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@16.0.2...HEAD
303
+ [16.0.2]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@16.0.1...@metamask/polling-controller@16.0.2
304
+ [16.0.1]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@16.0.0...@metamask/polling-controller@16.0.1
284
305
  [16.0.0]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@15.0.0...@metamask/polling-controller@16.0.0
285
306
  [15.0.0]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@14.0.2...@metamask/polling-controller@15.0.0
286
307
  [14.0.2]: https://github.com/MetaMask/core/compare/@metamask/polling-controller@14.0.1...@metamask/polling-controller@14.0.2
@@ -15,6 +15,9 @@ const AbstractPollingController_1 = require("./AbstractPollingController.cjs");
15
15
  * @param Base - The base class to mix onto.
16
16
  * @returns The composed class.
17
17
  */
18
+ // This is a function that's used as class, and the return type is inferred from
19
+ // the class defined inside the function scope, so this can't be easily typed.
20
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention
18
21
  function BlockTrackerPollingControllerMixin(Base) {
19
22
  var _BlockTrackerPollingController_activeListeners;
20
23
  class BlockTrackerPollingController extends (0, AbstractPollingController_1.AbstractPollingControllerBaseMixin)(Base) {
@@ -1 +1 @@
1
- {"version":3,"file":"BlockTrackerPollingController.cjs","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":";;;;;;;;AAAA,+DAA2D;AAO3D,+EAGqC;AAWrC;;;;;;GAMG;AACH,SAAS,kCAAkC,CAGzC,IAAW;;IACX,MAAe,6BAA8B,SAAQ,IAAA,8DAAkC,EAGrF,IAAI,CAAC;QAHP;;YAIE,yDAAqE,EAAE,EAAC;QA2C1E,CAAC;QArCC,aAAa,CAAC,KAAmB;YAC/B,MAAM,GAAG,GAAG,IAAA,kCAAM,EAAC,KAAK,CAAC,CAAC;YAE1B,IAAI,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC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K,CAAC,CAAC;AAFhE,QAAA,iCAAiC,qCAE+B;AAEtE,MAAM,6BAA6B,GAAG,GAEzC,EAAE,CACJ,kCAAkC,CAChC,gCAAc,CACf,CAAC;AALS,QAAA,6BAA6B,iCAKtC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n NetworkClientId,\n NetworkClient,\n} from '@metamask/network-controller';\nimport type { Json } from '@metamask/utils';\n\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController';\nimport type { Constructor, PollingTokenSetId } from './types';\n\n/**\n * The minimum input required to start polling for a {@link BlockTrackerPollingController}.\n * Implementing classes may provide additional properties.\n */\nexport type BlockTrackerPollingInput = {\n networkClientId: NetworkClientId;\n};\n\n/**\n * BlockTrackerPollingControllerMixin\n * A polling controller that polls using a block tracker.\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\nfunction BlockTrackerPollingControllerMixin<\n TBase extends Constructor,\n PollingInput extends BlockTrackerPollingInput,\n>(Base: TBase) {\n abstract class BlockTrackerPollingController extends AbstractPollingControllerBaseMixin<\n TBase,\n PollingInput\n >(Base) {\n #activeListeners: Record<string, (options: Json) => Promise<void>> = {};\n\n abstract _getNetworkClientById(\n networkClientId: NetworkClientId,\n ): NetworkClient | undefined;\n\n _startPolling(input: PollingInput) {\n const key = getKey(input);\n\n if (this.#activeListeners[key]) {\n return;\n }\n\n const networkClient = this._getNetworkClientById(input.networkClientId);\n if (networkClient) {\n const updateOnNewBlock = this._executePoll.bind(this, input);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.addListener('latest', updateOnNewBlock);\n this.#activeListeners[key] = updateOnNewBlock;\n } else {\n throw new Error(\n `Unable to retrieve blockTracker for networkClientId ${input.networkClientId}`,\n );\n }\n }\n\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId) {\n const { networkClientId } = JSON.parse(key);\n const networkClient = this._getNetworkClientById(\n networkClientId as NetworkClientId,\n );\n\n if (networkClient && this.#activeListeners[key]) {\n const listener = this.#activeListeners[key];\n if (listener) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.removeListener('latest', listener);\n delete this.#activeListeners[key];\n }\n }\n }\n }\n\n return BlockTrackerPollingController;\n}\n\nclass Empty {}\n\nexport const BlockTrackerPollingControllerOnly = <\n PollingInput extends BlockTrackerPollingInput,\n>() => BlockTrackerPollingControllerMixin<typeof Empty, PollingInput>(Empty);\n\nexport const BlockTrackerPollingController = <\n PollingInput extends BlockTrackerPollingInput,\n>() =>\n BlockTrackerPollingControllerMixin<typeof BaseController, PollingInput>(\n BaseController,\n );\n"]}
1
+ {"version":3,"file":"BlockTrackerPollingController.cjs","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":";;;;;;;;AAAA,+DAA2D;AAO3D,+EAGqC;AAWrC;;;;;;GAMG;AACH,gFAAgF;AAChF,8EAA8E;AAC9E,kHAAkH;AAClH,SAAS,kCAAkC,CAGzC,IAAW;;IACX,MAAe,6BAA8B,SAAQ,IAAA,8DAAkC,EAGrF,IAAI,CAAC;QAHP;;YAIE,yDAAqE,EAAE,EAAC;QA2C1E,CAAC;QArCC,aAAa,CAAC,KAAmB;YAC/B,MAAM,GAAG,GAAG,IAAA,kCAAM,EAAC,KAAK,CAAC,CAAC;YAE1B,IAAI,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC/B,OAAO;YACT,CAAC;YAED,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACxE,IAAI,aAAa,EAAE,CAAC;gBAClB,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC7D,gFAAgF;gBAChF,kEAAkE;gBAClE,aAAa,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;gBACnE,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC;YAChD,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,uDAAuD,KAAK,CAAC,eAAe,EAAE,CAC/E,CAAC;YACJ,CAAC;QACH,CAAC;QAED,+BAA+B,CAAC,GAAsB;YACpD,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAC9C,eAAkC,CACnC,CAAC;YAEF,IAAI,aAAa,IAAI,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChD,MAAM,QAAQ,GAAG,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,CAAC;gBAC5C,IAAI,QAAQ,EAAE,CAAC;oBACb,gFAAgF;oBAChF,kEAAkE;oBAClE,aAAa,CAAC,YAAY,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;oBAC9D,OAAO,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;KACF;;IAED,OAAO,6BAA6B,CAAC;AACvC,CAAC;AAED,MAAM,KAAK;CAAG;AAEP,MAAM,iCAAiC,GAAG,GAK7C,EAAE,CAAC,kCAAkC,CAA6B,KAAK,CAAC,CAAC;AALhE,QAAA,iCAAiC,qCAK+B;AAEtE,MAAM,6BAA6B,GAAG,GAKzC,EAAE,CACJ,kCAAkC,CAChC,gCAAc,CACf,CAAC;AARS,QAAA,6BAA6B,iCAQtC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n NetworkClientId,\n NetworkClient,\n} from '@metamask/network-controller';\nimport type { Json } from '@metamask/utils';\n\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController';\nimport type { Constructor, PollingTokenSetId } from './types';\n\n/**\n * The minimum input required to start polling for a {@link BlockTrackerPollingController}.\n * Implementing classes may provide additional properties.\n */\nexport type BlockTrackerPollingInput = {\n networkClientId: NetworkClientId;\n};\n\n/**\n * BlockTrackerPollingControllerMixin\n * A polling controller that polls using a block tracker.\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\n// This is a function that's used as class, and the return type is inferred from\n// the class defined inside the function scope, so this can't be easily typed.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention\nfunction BlockTrackerPollingControllerMixin<\n TBase extends Constructor,\n PollingInput extends BlockTrackerPollingInput,\n>(Base: TBase) {\n abstract class BlockTrackerPollingController extends AbstractPollingControllerBaseMixin<\n TBase,\n PollingInput\n >(Base) {\n #activeListeners: Record<string, (options: Json) => Promise<void>> = {};\n\n abstract _getNetworkClientById(\n networkClientId: NetworkClientId,\n ): NetworkClient | undefined;\n\n _startPolling(input: PollingInput): void {\n const key = getKey(input);\n\n if (this.#activeListeners[key]) {\n return;\n }\n\n const networkClient = this._getNetworkClientById(input.networkClientId);\n if (networkClient) {\n const updateOnNewBlock = this._executePoll.bind(this, input);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.addListener('latest', updateOnNewBlock);\n this.#activeListeners[key] = updateOnNewBlock;\n } else {\n throw new Error(\n `Unable to retrieve blockTracker for networkClientId ${input.networkClientId}`,\n );\n }\n }\n\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void {\n const { networkClientId } = JSON.parse(key);\n const networkClient = this._getNetworkClientById(\n networkClientId as NetworkClientId,\n );\n\n if (networkClient && this.#activeListeners[key]) {\n const listener = this.#activeListeners[key];\n if (listener) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.removeListener('latest', listener);\n delete this.#activeListeners[key];\n }\n }\n }\n }\n\n return BlockTrackerPollingController;\n}\n\nclass Empty {}\n\nexport const BlockTrackerPollingControllerOnly = <\n PollingInput extends BlockTrackerPollingInput,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() => BlockTrackerPollingControllerMixin<typeof Empty, PollingInput>(Empty);\n\nexport const BlockTrackerPollingController = <\n PollingInput extends BlockTrackerPollingInput,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() =>\n BlockTrackerPollingControllerMixin<typeof BaseController, PollingInput>(\n BaseController,\n );\n"]}
@@ -12,7 +12,7 @@ export type BlockTrackerPollingInput = {
12
12
  declare class Empty {
13
13
  }
14
14
  export declare const BlockTrackerPollingControllerOnly: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
15
- "__#14@#activeListeners": Record<string, (options: Json) => Promise<void>>;
15
+ "__#13@#activeListeners": Record<string, (options: Json) => Promise<void>>;
16
16
  _getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
17
17
  _startPolling(input: PollingInput): void;
18
18
  _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
@@ -25,7 +25,7 @@ export declare const BlockTrackerPollingControllerOnly: <PollingInput extends Bl
25
25
  onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
26
26
  }) & typeof Empty;
27
27
  export declare const BlockTrackerPollingController: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
28
- "__#14@#activeListeners": Record<string, (options: Json) => Promise<void>>;
28
+ "__#13@#activeListeners": Record<string, (options: Json) => Promise<void>>;
29
29
  _getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
30
30
  _startPolling(input: PollingInput): void;
31
31
  _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
@@ -1 +1 @@
1
- {"version":3,"file":"BlockTrackerPollingController.d.cts","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAAe,iBAAiB,EAAE,oBAAgB;AAE9D;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAiEF,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,iCAAiC;uDAlDC,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;;yCAuBS,iBAAiB;;;;;;;;iBAyBkB,CAAC;AAE7E,eAAO,MAAM,6BAA6B;uDAtDK,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;;yCAuBS,iBAAiB;;;;;;;;0BAgCvD,CAAC"}
1
+ {"version":3,"file":"BlockTrackerPollingController.d.cts","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAAe,iBAAiB,EAAE,oBAAgB;AAE9D;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAoEF,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,iCAAiC;uDAlDC,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;wCAEQ,IAAI;yCAqBH,iBAAiB,GAAG,IAAI;;;;;;;;iBA4BW,CAAC;AAE7E,eAAO,MAAM,6BAA6B;uDAzDK,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;wCAEQ,IAAI;yCAqBH,iBAAiB,GAAG,IAAI;;;;;;;;0BAsC9D,CAAC"}
@@ -12,7 +12,7 @@ export type BlockTrackerPollingInput = {
12
12
  declare class Empty {
13
13
  }
14
14
  export declare const BlockTrackerPollingControllerOnly: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
15
- "__#14@#activeListeners": Record<string, (options: Json) => Promise<void>>;
15
+ "__#13@#activeListeners": Record<string, (options: Json) => Promise<void>>;
16
16
  _getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
17
17
  _startPolling(input: PollingInput): void;
18
18
  _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
@@ -25,7 +25,7 @@ export declare const BlockTrackerPollingControllerOnly: <PollingInput extends Bl
25
25
  onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
26
26
  }) & typeof Empty;
27
27
  export declare const BlockTrackerPollingController: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
28
- "__#14@#activeListeners": Record<string, (options: Json) => Promise<void>>;
28
+ "__#13@#activeListeners": Record<string, (options: Json) => Promise<void>>;
29
29
  _getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
30
30
  _startPolling(input: PollingInput): void;
31
31
  _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
@@ -1 +1 @@
1
- {"version":3,"file":"BlockTrackerPollingController.d.mts","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAAe,iBAAiB,EAAE,oBAAgB;AAE9D;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAiEF,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,iCAAiC;uDAlDC,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;;yCAuBS,iBAAiB;;;;;;;;iBAyBkB,CAAC;AAE7E,eAAO,MAAM,6BAA6B;uDAtDK,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;;yCAuBS,iBAAiB;;;;;;;;0BAgCvD,CAAC"}
1
+ {"version":3,"file":"BlockTrackerPollingController.d.mts","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAAe,iBAAiB,EAAE,oBAAgB;AAE9D;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAoEF,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,iCAAiC;uDAlDC,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;wCAEQ,IAAI;yCAqBH,iBAAiB,GAAG,IAAI;;;;;;;;iBA4BW,CAAC;AAE7E,eAAO,MAAM,6BAA6B;uDAzDK,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;wCAEQ,IAAI;yCAqBH,iBAAiB,GAAG,IAAI;;;;;;;;0BAsC9D,CAAC"}
@@ -12,6 +12,9 @@ import { AbstractPollingControllerBaseMixin, getKey } from "./AbstractPollingCon
12
12
  * @param Base - The base class to mix onto.
13
13
  * @returns The composed class.
14
14
  */
15
+ // This is a function that's used as class, and the return type is inferred from
16
+ // the class defined inside the function scope, so this can't be easily typed.
17
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention
15
18
  function BlockTrackerPollingControllerMixin(Base) {
16
19
  var _BlockTrackerPollingController_activeListeners;
17
20
  class BlockTrackerPollingController extends AbstractPollingControllerBaseMixin(Base) {
@@ -1 +1 @@
1
- {"version":3,"file":"BlockTrackerPollingController.mjs","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":";;;;;AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAO3D,OAAO,EACL,kCAAkC,EAClC,MAAM,EACP,wCAAoC;AAWrC;;;;;;GAMG;AACH,SAAS,kCAAkC,CAGzC,IAAW;;IACX,MAAe,6BAA8B,SAAQ,kCAAkC,CAGrF,IAAI,CAAC;QAHP;;YAIE,yDAAqE,EAAE,EAAC;QA2C1E,CAAC;QArCC,aAAa,CAAC,KAAmB;YAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAE1B,IAAI,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC/B,OAAO;YACT,CAAC;YAED,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACxE,IAAI,aAAa,EAAE,CAAC;gBAClB,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC7D,gFAAgF;gBAChF,kEAAkE;gBAClE,aAAa,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;gBACnE,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC;YAChD,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,uDAAuD,KAAK,CAAC,eAAe,EAAE,CAC/E,CAAC;YACJ,CAAC;QACH,CAAC;QAED,+BAA+B,CAAC,GAAsB;YACpD,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAC9C,eAAkC,CACnC,CAAC;YAEF,IAAI,aAAa,IAAI,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChD,MAAM,QAAQ,GAAG,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,CAAC;gBAC5C,IAAI,QAAQ,EAAE,CAAC;oBACb,gFAAgF;oBAChF,kEAAkE;oBAClE,aAAa,CAAC,YAAY,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;oBAC9D,OAAO,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;KACF;;IAED,OAAO,6BAA6B,CAAC;AACvC,CAAC;AAED,MAAM,KAAK;CAAG;AAEd,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAE7C,EAAE,CAAC,kCAAkC,CAA6B,KAAK,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAEzC,EAAE,CACJ,kCAAkC,CAChC,cAAc,CACf,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n NetworkClientId,\n NetworkClient,\n} from '@metamask/network-controller';\nimport type { Json } from '@metamask/utils';\n\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController';\nimport type { Constructor, PollingTokenSetId } from './types';\n\n/**\n * The minimum input required to start polling for a {@link BlockTrackerPollingController}.\n * Implementing classes may provide additional properties.\n */\nexport type BlockTrackerPollingInput = {\n networkClientId: NetworkClientId;\n};\n\n/**\n * BlockTrackerPollingControllerMixin\n * A polling controller that polls using a block tracker.\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\nfunction BlockTrackerPollingControllerMixin<\n TBase extends Constructor,\n PollingInput extends BlockTrackerPollingInput,\n>(Base: TBase) {\n abstract class BlockTrackerPollingController extends AbstractPollingControllerBaseMixin<\n TBase,\n PollingInput\n >(Base) {\n #activeListeners: Record<string, (options: Json) => Promise<void>> = {};\n\n abstract _getNetworkClientById(\n networkClientId: NetworkClientId,\n ): NetworkClient | undefined;\n\n _startPolling(input: PollingInput) {\n const key = getKey(input);\n\n if (this.#activeListeners[key]) {\n return;\n }\n\n const networkClient = this._getNetworkClientById(input.networkClientId);\n if (networkClient) {\n const updateOnNewBlock = this._executePoll.bind(this, input);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.addListener('latest', updateOnNewBlock);\n this.#activeListeners[key] = updateOnNewBlock;\n } else {\n throw new Error(\n `Unable to retrieve blockTracker for networkClientId ${input.networkClientId}`,\n );\n }\n }\n\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId) {\n const { networkClientId } = JSON.parse(key);\n const networkClient = this._getNetworkClientById(\n networkClientId as NetworkClientId,\n );\n\n if (networkClient && this.#activeListeners[key]) {\n const listener = this.#activeListeners[key];\n if (listener) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.removeListener('latest', listener);\n delete this.#activeListeners[key];\n }\n }\n }\n }\n\n return BlockTrackerPollingController;\n}\n\nclass Empty {}\n\nexport const BlockTrackerPollingControllerOnly = <\n PollingInput extends BlockTrackerPollingInput,\n>() => BlockTrackerPollingControllerMixin<typeof Empty, PollingInput>(Empty);\n\nexport const BlockTrackerPollingController = <\n PollingInput extends BlockTrackerPollingInput,\n>() =>\n BlockTrackerPollingControllerMixin<typeof BaseController, PollingInput>(\n BaseController,\n );\n"]}
1
+ {"version":3,"file":"BlockTrackerPollingController.mjs","sourceRoot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iB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChD,MAAM,QAAQ,GAAG,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,CAAC;gBAC5C,IAAI,QAAQ,EAAE,CAAC;oBACb,gFAAgF;oBAChF,kEAAkE;oBAClE,aAAa,CAAC,YAAY,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;oBAC9D,OAAO,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;KACF;;IAED,OAAO,6BAA6B,CAAC;AACvC,CAAC;AAED,MAAM,KAAK;CAAG;AAEd,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAK7C,EAAE,CAAC,kCAAkC,CAA6B,KAAK,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAKzC,EAAE,CACJ,kCAAkC,CAChC,cAAc,CACf,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n NetworkClientId,\n NetworkClient,\n} from '@metamask/network-controller';\nimport type { Json } from '@metamask/utils';\n\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController';\nimport type { Constructor, PollingTokenSetId } from './types';\n\n/**\n * The minimum input required to start polling for a {@link BlockTrackerPollingController}.\n * Implementing classes may provide additional properties.\n */\nexport type BlockTrackerPollingInput = {\n networkClientId: NetworkClientId;\n};\n\n/**\n * BlockTrackerPollingControllerMixin\n * A polling controller that polls using a block tracker.\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\n// This is a function that's used as class, and the return type is inferred from\n// the class defined inside the function scope, so this can't be easily typed.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention\nfunction BlockTrackerPollingControllerMixin<\n TBase extends Constructor,\n PollingInput extends BlockTrackerPollingInput,\n>(Base: TBase) {\n abstract class BlockTrackerPollingController extends AbstractPollingControllerBaseMixin<\n TBase,\n PollingInput\n >(Base) {\n #activeListeners: Record<string, (options: Json) => Promise<void>> = {};\n\n abstract _getNetworkClientById(\n networkClientId: NetworkClientId,\n ): NetworkClient | undefined;\n\n _startPolling(input: PollingInput): void {\n const key = getKey(input);\n\n if (this.#activeListeners[key]) {\n return;\n }\n\n const networkClient = this._getNetworkClientById(input.networkClientId);\n if (networkClient) {\n const updateOnNewBlock = this._executePoll.bind(this, input);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.addListener('latest', updateOnNewBlock);\n this.#activeListeners[key] = updateOnNewBlock;\n } else {\n throw new Error(\n `Unable to retrieve blockTracker for networkClientId ${input.networkClientId}`,\n );\n }\n }\n\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void {\n const { networkClientId } = JSON.parse(key);\n const networkClient = this._getNetworkClientById(\n networkClientId as NetworkClientId,\n );\n\n if (networkClient && this.#activeListeners[key]) {\n const listener = this.#activeListeners[key];\n if (listener) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.removeListener('latest', listener);\n delete this.#activeListeners[key];\n }\n }\n }\n }\n\n return BlockTrackerPollingController;\n}\n\nclass Empty {}\n\nexport const BlockTrackerPollingControllerOnly = <\n PollingInput extends BlockTrackerPollingInput,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() => BlockTrackerPollingControllerMixin<typeof Empty, PollingInput>(Empty);\n\nexport const BlockTrackerPollingController = <\n PollingInput extends BlockTrackerPollingInput,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() =>\n BlockTrackerPollingControllerMixin<typeof BaseController, PollingInput>(\n BaseController,\n );\n"]}
@@ -21,6 +21,9 @@ const AbstractPollingController_1 = require("./AbstractPollingController.cjs");
21
21
  * @param Base - The base class to mix onto.
22
22
  * @returns The composed class.
23
23
  */
24
+ // This is a function that's used as class, and the return type is inferred from
25
+ // the class defined inside the function scope, so this can't be easily typed.
26
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention
24
27
  function StaticIntervalPollingControllerMixin(Base) {
25
28
  var _StaticIntervalPollingController_intervalIds, _StaticIntervalPollingController_intervalLength;
26
29
  class StaticIntervalPollingController extends (0, AbstractPollingController_1.AbstractPollingControllerBaseMixin)(Base) {
@@ -73,6 +76,9 @@ class Empty {
73
76
  }
74
77
  const StaticIntervalPollingControllerOnly = () => StaticIntervalPollingControllerMixin(Empty);
75
78
  exports.StaticIntervalPollingControllerOnly = StaticIntervalPollingControllerOnly;
79
+ // The return type is inferred from the class defined inside the function
80
+ // scope, so this can't be easily typed.
81
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
76
82
  const StaticIntervalPollingController = () => StaticIntervalPollingControllerMixin(base_controller_1.BaseController);
77
83
  exports.StaticIntervalPollingController = StaticIntervalPollingController;
78
84
  //# sourceMappingURL=StaticIntervalPollingController.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"StaticIntervalPollingController.cjs","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAA2D;AAG3D,+EAGqC;AAOrC;;;;;;GAMG;AACH,SAAS,oCAAoC,CAG3C,IAAW;;IACX,MAAe,+BACb,SAAQ,IAAA,8DAAkC,EAAsB,IAAI,CAAC;QADvE;;YAIW,uDAA0D,EAAE,EAAC;YAEtE,0DAAsC,IAAI,EAAC;QA4C7C,CAAC;QA1CC,iBAAiB,CAAC,cAAsB;YACtC,uBAAA,IAAI,mDAAmB,cAAc,MAAA,CAAC;QACxC,CAAC;QAED,iBAAiB;YACf,OAAO,uBAAA,IAAI,uDAAgB,CAAC;QAC9B,CAAC;QAED,aAAa,CAAC,KAAmB;YAC/B,IAAI,CA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C,CAA6B,KAAK,CAAC,CAAC;AAFlE,QAAA,mCAAmC,uCAE+B;AAExE,MAAM,+BAA+B,GAAG,GAA8B,EAAE,CAC7E,oCAAoC,CAClC,gCAAc,CACf,CAAC;AAHS,QAAA,+BAA+B,mCAGxC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type { Json } from '@metamask/utils';\n\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController';\nimport type {\n Constructor,\n IPollingController,\n PollingTokenSetId,\n} from './types';\n\n/**\n * StaticIntervalPollingControllerMixin\n * A polling controller that polls on a static interval.\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\nfunction StaticIntervalPollingControllerMixin<\n TBase extends Constructor,\n PollingInput extends Json,\n>(Base: TBase) {\n abstract class StaticIntervalPollingController\n extends AbstractPollingControllerBaseMixin<TBase, PollingInput>(Base)\n implements IPollingController<PollingInput>\n {\n readonly #intervalIds: Record<PollingTokenSetId, NodeJS.Timeout> = {};\n\n #intervalLength: number | undefined = 1000;\n\n setIntervalLength(intervalLength: number) {\n this.#intervalLength = intervalLength;\n }\n\n getIntervalLength() {\n return this.#intervalLength;\n }\n\n _startPolling(input: PollingInput) {\n if (!this.#intervalLength) {\n throw new Error('intervalLength must be defined and greater than 0');\n }\n\n const key = getKey(input);\n const existingInterval = this.#intervalIds[key];\n this._stopPollingByPollingTokenSetId(key);\n\n // eslint-disable-next-line no-multi-assign\n const intervalId = (this.#intervalIds[key] = setTimeout(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async () => {\n try {\n await this._executePoll(input);\n } catch (error) {\n console.error(error);\n }\n if (intervalId === this.#intervalIds[key]) {\n this._startPolling(input);\n }\n },\n existingInterval ? this.#intervalLength : 0,\n ));\n }\n\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId) {\n const intervalId = this.#intervalIds[key];\n if (intervalId) {\n clearTimeout(intervalId);\n delete this.#intervalIds[key];\n }\n }\n }\n\n return StaticIntervalPollingController;\n}\n\nclass Empty {}\n\nexport const StaticIntervalPollingControllerOnly = <\n PollingInput extends Json,\n>() => StaticIntervalPollingControllerMixin<typeof Empty, PollingInput>(Empty);\n\nexport const StaticIntervalPollingController = <PollingInput extends Json>() =>\n StaticIntervalPollingControllerMixin<typeof BaseController, PollingInput>(\n BaseController,\n );\n"]}
1
+ {"version":3,"file":"StaticIntervalPollingController.cjs","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAA2D;AAG3D,+EAGqC;AAOrC;;;;;;GAMG;AACH,gFAAgF;AAChF,8EAA8E;AAC9E,kHAAkH;AAClH,SAAS,oCAAoC,CAG3C,IAAW;;IACX,MAAe,+BACb,SAAQ,IAAA,8DAAkC,EAAsB,IAAI,CAAC;QADvE;;YAIW,uDAA0D,EAAE,EAAC;YAEtE,0DAAsC,IAAI,EAAC;QA4C7C,CAAC;QA1CC,iBAAiB,CAAC,cAAsB;YACtC,uBAAA,IAAI,mDAAmB,cAAc,MAAA,CAAC;QACxC,CAAC;QAED,iBAAiB;YACf,OAAO,uBAAA,IAAI,uDAAgB,CAAC;QAC9B,CAAC;QAED,aAAa,CAAC,KAAmB;YAC/B,IAAI,CAAC,uBAAA,IAAI,uDAAgB,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;YACvE,CAAC;YAED,MAAM,GAAG,GAAG,IAAA,kCAAM,EAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,gBAAgB,GAAG,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,CAAC;YAChD,IAAI,CAAC,+BAA+B,CAAC,GAAG,CAAC,CAAC;YAE1C,2CAA2C;YAC3C,MAAM,UAAU,GAAG,CAAC,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,GAAG,UAAU;YACrD,gFAAgF;YAChF,kEAAkE;YAClE,KAAK,IAAI,EAAE;gBACT,IAAI,CAAC;oBACH,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;gBACjC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC;gBACD,IAAI,UAAU,KAAK,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC1C,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC,EACD,gBAAgB,CAAC,CAAC,CAAC,uBAAA,IAAI,uDAAgB,CAAC,CAAC,CAAC,CAAC,CAC5C,CAAC,CAAC;QACL,CAAC;QAED,+BAA+B,CAAC,GAAsB;YACpD,MAAM,UAAU,GAAG,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,CAAC;YAC1C,IAAI,UAAU,EAAE,CAAC;gBACf,YAAY,CAAC,UAAU,CAAC,CAAC;gBACzB,OAAO,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;KACF;;IAED,OAAO,+BAA+B,CAAC;AACzC,CAAC;AAED,MAAM,KAAK;CAAG;AAEP,MAAM,mCAAmC,GAAG,GAK/C,EAAE,CAAC,oCAAoC,CAA6B,KAAK,CAAC,CAAC;AALlE,QAAA,mCAAmC,uCAK+B;AAE/E,yEAAyE;AACzE,wCAAwC;AACxC,4EAA4E;AACrE,MAAM,+BAA+B,GAAG,GAA8B,EAAE,CAC7E,oCAAoC,CAClC,gCAAc,CACf,CAAC;AAHS,QAAA,+BAA+B,mCAGxC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type { Json } from '@metamask/utils';\n\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController';\nimport type {\n Constructor,\n IPollingController,\n PollingTokenSetId,\n} from './types';\n\n/**\n * StaticIntervalPollingControllerMixin\n * A polling controller that polls on a static interval.\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\n// This is a function that's used as class, and the return type is inferred from\n// the class defined inside the function scope, so this can't be easily typed.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention\nfunction StaticIntervalPollingControllerMixin<\n TBase extends Constructor,\n PollingInput extends Json,\n>(Base: TBase) {\n abstract class StaticIntervalPollingController\n extends AbstractPollingControllerBaseMixin<TBase, PollingInput>(Base)\n implements IPollingController<PollingInput>\n {\n readonly #intervalIds: Record<PollingTokenSetId, NodeJS.Timeout> = {};\n\n #intervalLength: number | undefined = 1000;\n\n setIntervalLength(intervalLength: number): void {\n this.#intervalLength = intervalLength;\n }\n\n getIntervalLength(): number | undefined {\n return this.#intervalLength;\n }\n\n _startPolling(input: PollingInput): void {\n if (!this.#intervalLength) {\n throw new Error('intervalLength must be defined and greater than 0');\n }\n\n const key = getKey(input);\n const existingInterval = this.#intervalIds[key];\n this._stopPollingByPollingTokenSetId(key);\n\n // eslint-disable-next-line no-multi-assign\n const intervalId = (this.#intervalIds[key] = setTimeout(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async () => {\n try {\n await this._executePoll(input);\n } catch (error) {\n console.error(error);\n }\n if (intervalId === this.#intervalIds[key]) {\n this._startPolling(input);\n }\n },\n existingInterval ? this.#intervalLength : 0,\n ));\n }\n\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void {\n const intervalId = this.#intervalIds[key];\n if (intervalId) {\n clearTimeout(intervalId);\n delete this.#intervalIds[key];\n }\n }\n }\n\n return StaticIntervalPollingController;\n}\n\nclass Empty {}\n\nexport const StaticIntervalPollingControllerOnly = <\n PollingInput extends Json,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() => StaticIntervalPollingControllerMixin<typeof Empty, PollingInput>(Empty);\n\n// The return type is inferred from the class defined inside the function\n// scope, so this can't be easily typed.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport const StaticIntervalPollingController = <PollingInput extends Json>() =>\n StaticIntervalPollingControllerMixin<typeof BaseController, PollingInput>(\n BaseController,\n );\n"]}
@@ -4,8 +4,8 @@ import type { PollingTokenSetId } from "./types.cjs";
4
4
  declare class Empty {
5
5
  }
6
6
  export declare const StaticIntervalPollingControllerOnly: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
7
- readonly "__#15@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
8
- "__#15@#intervalLength": number | undefined;
7
+ readonly "__#14@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
8
+ "__#14@#intervalLength": number | undefined;
9
9
  setIntervalLength(intervalLength: number): void;
10
10
  getIntervalLength(): number | undefined;
11
11
  _startPolling(input: PollingInput): void;
@@ -19,8 +19,8 @@ export declare const StaticIntervalPollingControllerOnly: <PollingInput extends
19
19
  onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
20
20
  }) & typeof Empty;
21
21
  export declare const StaticIntervalPollingController: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
22
- readonly "__#15@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
23
- "__#15@#intervalLength": number | undefined;
22
+ readonly "__#14@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
23
+ "__#14@#intervalLength": number | undefined;
24
24
  setIntervalLength(intervalLength: number): void;
25
25
  getIntervalLength(): number | undefined;
26
26
  _startPolling(input: PollingInput): void;
@@ -1 +1 @@
1
- {"version":3,"file":"StaticIntervalPollingController.d.cts","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAGV,iBAAiB,EAClB,oBAAgB;AAoEjB,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,mCAAmC;mCArDrB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;6BAE/C,MAAM,GAAG,SAAS;sCAED,MAAM;;;yCAmCH,iBAAiB;;;;;;;;iBAgBoB,CAAC;AAE/E,eAAO,MAAM,+BAA+B;mCAzDjB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;6BAE/C,MAAM,GAAG,SAAS;sCAED,MAAM;;;yCAmCH,iBAAiB;;;;;;;;0BAqBvD,CAAC"}
1
+ {"version":3,"file":"StaticIntervalPollingController.d.cts","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAGV,iBAAiB,EAClB,oBAAgB;AAuEjB,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,mCAAmC;mCArDrB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;6BAE/C,MAAM,GAAG,SAAS;sCAED,MAAM,GAAG,IAAI;yBAI1B,MAAM,GAAG,SAAS;wCAIH,IAAI;yCA2BH,iBAAiB,GAAG,IAAI;;;;;;;;iBAmBa,CAAC;AAK/E,eAAO,MAAM,+BAA+B;mCA/DjB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;6BAE/C,MAAM,GAAG,SAAS;sCAED,MAAM,GAAG,IAAI;yBAI1B,MAAM,GAAG,SAAS;wCAIH,IAAI;yCA2BH,iBAAiB,GAAG,IAAI;;;;;;;;0BA2B9D,CAAC"}
@@ -4,8 +4,8 @@ import type { PollingTokenSetId } from "./types.mjs";
4
4
  declare class Empty {
5
5
  }
6
6
  export declare const StaticIntervalPollingControllerOnly: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
7
- readonly "__#15@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
8
- "__#15@#intervalLength": number | undefined;
7
+ readonly "__#14@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
8
+ "__#14@#intervalLength": number | undefined;
9
9
  setIntervalLength(intervalLength: number): void;
10
10
  getIntervalLength(): number | undefined;
11
11
  _startPolling(input: PollingInput): void;
@@ -19,8 +19,8 @@ export declare const StaticIntervalPollingControllerOnly: <PollingInput extends
19
19
  onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
20
20
  }) & typeof Empty;
21
21
  export declare const StaticIntervalPollingController: <PollingInput extends Json>() => (abstract new (...args: any[]) => {
22
- readonly "__#15@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
23
- "__#15@#intervalLength": number | undefined;
22
+ readonly "__#14@#intervalIds": Record<PollingTokenSetId, NodeJS.Timeout>;
23
+ "__#14@#intervalLength": number | undefined;
24
24
  setIntervalLength(intervalLength: number): void;
25
25
  getIntervalLength(): number | undefined;
26
26
  _startPolling(input: PollingInput): void;
@@ -1 +1 @@
1
- {"version":3,"file":"StaticIntervalPollingController.d.mts","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAGV,iBAAiB,EAClB,oBAAgB;AAoEjB,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,mCAAmC;mCArDrB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;6BAE/C,MAAM,GAAG,SAAS;sCAED,MAAM;;;yCAmCH,iBAAiB;;;;;;;;iBAgBoB,CAAC;AAE/E,eAAO,MAAM,+BAA+B;mCAzDjB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;6BAE/C,MAAM,GAAG,SAAS;sCAED,MAAM;;;yCAmCH,iBAAiB;;;;;;;;0BAqBvD,CAAC"}
1
+ {"version":3,"file":"StaticIntervalPollingController.d.mts","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,KAAK,EAGV,iBAAiB,EAClB,oBAAgB;AAuEjB,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,mCAAmC;mCArDrB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;6BAE/C,MAAM,GAAG,SAAS;sCAED,MAAM,GAAG,IAAI;yBAI1B,MAAM,GAAG,SAAS;wCAIH,IAAI;yCA2BH,iBAAiB,GAAG,IAAI;;;;;;;;iBAmBa,CAAC;AAK/E,eAAO,MAAM,+BAA+B;mCA/DjB,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;6BAE/C,MAAM,GAAG,SAAS;sCAED,MAAM,GAAG,IAAI;yBAI1B,MAAM,GAAG,SAAS;wCAIH,IAAI;yCA2BH,iBAAiB,GAAG,IAAI;;;;;;;;0BA2B9D,CAAC"}
@@ -18,6 +18,9 @@ import { AbstractPollingControllerBaseMixin, getKey } from "./AbstractPollingCon
18
18
  * @param Base - The base class to mix onto.
19
19
  * @returns The composed class.
20
20
  */
21
+ // This is a function that's used as class, and the return type is inferred from
22
+ // the class defined inside the function scope, so this can't be easily typed.
23
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention
21
24
  function StaticIntervalPollingControllerMixin(Base) {
22
25
  var _StaticIntervalPollingController_intervalIds, _StaticIntervalPollingController_intervalLength;
23
26
  class StaticIntervalPollingController extends AbstractPollingControllerBaseMixin(Base) {
@@ -69,5 +72,8 @@ function StaticIntervalPollingControllerMixin(Base) {
69
72
  class Empty {
70
73
  }
71
74
  export const StaticIntervalPollingControllerOnly = () => StaticIntervalPollingControllerMixin(Empty);
75
+ // The return type is inferred from the class defined inside the function
76
+ // scope, so this can't be easily typed.
77
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
72
78
  export const StaticIntervalPollingController = () => StaticIntervalPollingControllerMixin(BaseController);
73
79
  //# sourceMappingURL=StaticIntervalPollingController.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"StaticIntervalPollingController.mjs","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,EACL,kCAAkC,EAClC,MAAM,EACP,wCAAoC;AAOrC;;;;;;GAMG;AACH,SAAS,oCAAoC,CAG3C,IAAW;;IACX,MAAe,+BACb,SAAQ,kCAAkC,CAAsB,IAAI,CAAC;QADvE;;YAIW,uDAA0D,EAAE,EAAC;YAEtE,0DAAsC,IAAI,EAAC;QA4C7C,CAAC;QA1CC,iBAAiB,CAAC,cAAsB;YACtC,uBAAA,IAAI,mDAAmB,cAAc,MAAA,CAAC;QACxC,CAAC;QAED,iBAAiB;YACf,OAAO,uBAAA,IAAI,uDAAgB,CAAC;QAC9B,CAAC;QAED,aAAa,CAAC,KAAmB;YAC/B,IAAI,CAAC,uBAAA,IAAI,uDAAgB,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;YACvE,CAAC;YAED,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1B,MAAM,gBAAgB,GAAG,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,CAAC;YAChD,IAAI,CAAC,+BAA+B,CAAC,GAAG,CAAC,CAAC;YAE1C,2CAA2C;YAC3C,MAAM,UAAU,GAAG,CAAC,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,GAAG,UAAU;YACrD,gFAAgF;YAChF,kEAAkE;YAClE,KAAK,IAAI,EAAE;gBACT,IAAI,CAAC;oBACH,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;gBACjC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC;gBACD,IAAI,UAAU,KAAK,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC1C,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC,EACD,gBAAgB,CAAC,CAAC,CAAC,uBAAA,IAAI,uDAAgB,CAAC,CAAC,CAAC,CAAC,CAC5C,CAAC,CAAC;QACL,CAAC;QAED,+BAA+B,CAAC,GAAsB;YACpD,MAAM,UAAU,GAAG,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,CAAC;YAC1C,IAAI,UAAU,EAAE,CAAC;gBACf,YAAY,CAAC,UAAU,CAAC,CAAC;gBACzB,OAAO,uBAAA,IAAI,oDAAa,CAAC,GAAG,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;KACF;;IAED,OAAO,+BAA+B,CAAC;AACzC,CAAC;AAED,MAAM,KAAK;CAAG;AAEd,MAAM,CAAC,MAAM,mCAAmC,GAAG,GAE/C,EAAE,CAAC,oCAAoC,CAA6B,KAAK,CAAC,CAAC;AAE/E,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAA8B,EAAE,CAC7E,oCAAoC,CAClC,cAAc,CACf,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type { Json } from '@metamask/utils';\n\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController';\nimport type {\n Constructor,\n IPollingController,\n PollingTokenSetId,\n} from './types';\n\n/**\n * StaticIntervalPollingControllerMixin\n * A polling controller that polls on a static interval.\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\nfunction StaticIntervalPollingControllerMixin<\n TBase extends Constructor,\n PollingInput extends Json,\n>(Base: TBase) {\n abstract class StaticIntervalPollingController\n extends AbstractPollingControllerBaseMixin<TBase, PollingInput>(Base)\n implements IPollingController<PollingInput>\n {\n readonly #intervalIds: Record<PollingTokenSetId, NodeJS.Timeout> = {};\n\n #intervalLength: number | undefined = 1000;\n\n setIntervalLength(intervalLength: number) {\n this.#intervalLength = intervalLength;\n }\n\n getIntervalLength() {\n return this.#intervalLength;\n }\n\n _startPolling(input: PollingInput) {\n if (!this.#intervalLength) {\n throw new Error('intervalLength must be defined and greater than 0');\n }\n\n const key = getKey(input);\n const existingInterval = this.#intervalIds[key];\n this._stopPollingByPollingTokenSetId(key);\n\n // eslint-disable-next-line no-multi-assign\n const intervalId = (this.#intervalIds[key] = setTimeout(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async () => {\n try {\n await this._executePoll(input);\n } catch (error) {\n console.error(error);\n }\n if (intervalId === this.#intervalIds[key]) {\n this._startPolling(input);\n }\n },\n existingInterval ? this.#intervalLength : 0,\n ));\n }\n\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId) {\n const intervalId = this.#intervalIds[key];\n if (intervalId) {\n clearTimeout(intervalId);\n delete this.#intervalIds[key];\n }\n }\n }\n\n return StaticIntervalPollingController;\n}\n\nclass Empty {}\n\nexport const StaticIntervalPollingControllerOnly = <\n PollingInput extends Json,\n>() => StaticIntervalPollingControllerMixin<typeof Empty, PollingInput>(Empty);\n\nexport const StaticIntervalPollingController = <PollingInput extends Json>() =>\n StaticIntervalPollingControllerMixin<typeof BaseController, PollingInput>(\n BaseController,\n );\n"]}
1
+ {"version":3,"file":"StaticIntervalPollingController.mjs","sourceRoot":"","sources":["../src/StaticIntervalPollingController.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,EACL,kCAAkC,EAClC,MAAM,EACP,wCAAoC;AAOrC;;;;;;GAMG;AACH,gFAAgF;AAChF,8EAA8E;AAC9E,kHAAkH;AAClH,SAAS,oCAAoC,CAG3C,IAAW;;IACX,MAAe,+BACb,SAAQ,kCAAkC,CAAsB,IAAI,CAAC;QADvE;;YAIW,uDAA0D,EAAE,EAAC;YAEtE,0DAAsC,IAAI,EAAC;QA4C7C,CAAC;QA1CC,iBAAiB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AAa,CAAC,GAAG,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;KACF;;IAED,OAAO,+BAA+B,CAAC;AACzC,CAAC;AAED,MAAM,KAAK;CAAG;AAEd,MAAM,CAAC,MAAM,mCAAmC,GAAG,GAK/C,EAAE,CAAC,oCAAoC,CAA6B,KAAK,CAAC,CAAC;AAE/E,yEAAyE;AACzE,wCAAwC;AACxC,4EAA4E;AAC5E,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAA8B,EAAE,CAC7E,oCAAoC,CAClC,cAAc,CACf,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type { Json } from '@metamask/utils';\n\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n} from './AbstractPollingController';\nimport type {\n Constructor,\n IPollingController,\n PollingTokenSetId,\n} from './types';\n\n/**\n * StaticIntervalPollingControllerMixin\n * A polling controller that polls on a static interval.\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\n// This is a function that's used as class, and the return type is inferred from\n// the class defined inside the function scope, so this can't be easily typed.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention\nfunction StaticIntervalPollingControllerMixin<\n TBase extends Constructor,\n PollingInput extends Json,\n>(Base: TBase) {\n abstract class StaticIntervalPollingController\n extends AbstractPollingControllerBaseMixin<TBase, PollingInput>(Base)\n implements IPollingController<PollingInput>\n {\n readonly #intervalIds: Record<PollingTokenSetId, NodeJS.Timeout> = {};\n\n #intervalLength: number | undefined = 1000;\n\n setIntervalLength(intervalLength: number): void {\n this.#intervalLength = intervalLength;\n }\n\n getIntervalLength(): number | undefined {\n return this.#intervalLength;\n }\n\n _startPolling(input: PollingInput): void {\n if (!this.#intervalLength) {\n throw new Error('intervalLength must be defined and greater than 0');\n }\n\n const key = getKey(input);\n const existingInterval = this.#intervalIds[key];\n this._stopPollingByPollingTokenSetId(key);\n\n // eslint-disable-next-line no-multi-assign\n const intervalId = (this.#intervalIds[key] = setTimeout(\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async () => {\n try {\n await this._executePoll(input);\n } catch (error) {\n console.error(error);\n }\n if (intervalId === this.#intervalIds[key]) {\n this._startPolling(input);\n }\n },\n existingInterval ? this.#intervalLength : 0,\n ));\n }\n\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void {\n const intervalId = this.#intervalIds[key];\n if (intervalId) {\n clearTimeout(intervalId);\n delete this.#intervalIds[key];\n }\n }\n }\n\n return StaticIntervalPollingController;\n}\n\nclass Empty {}\n\nexport const StaticIntervalPollingControllerOnly = <\n PollingInput extends Json,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() => StaticIntervalPollingControllerMixin<typeof Empty, PollingInput>(Empty);\n\n// The return type is inferred from the class defined inside the function\n// scope, so this can't be easily typed.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport const StaticIntervalPollingController = <PollingInput extends Json>() =>\n StaticIntervalPollingControllerMixin<typeof BaseController, PollingInput>(\n BaseController,\n );\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/polling-controller",
3
- "version": "16.0.0",
3
+ "version": "16.0.2",
4
4
  "description": "Polling Controller is the base for controllers that polling by networkClientId",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -49,15 +49,15 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@metamask/base-controller": "^9.0.0",
52
- "@metamask/controller-utils": "^11.16.0",
53
- "@metamask/utils": "^11.8.1",
52
+ "@metamask/controller-utils": "^11.18.0",
53
+ "@metamask/network-controller": "^29.0.0",
54
+ "@metamask/utils": "^11.9.0",
54
55
  "@types/uuid": "^8.3.0",
55
56
  "fast-json-stable-stringify": "^2.1.0",
56
57
  "uuid": "^8.3.2"
57
58
  },
58
59
  "devDependencies": {
59
60
  "@metamask/auto-changelog": "^3.4.4",
60
- "@metamask/network-controller": "^26.0.0",
61
61
  "@ts-bridge/cli": "^0.6.4",
62
62
  "@types/jest": "^27.4.1",
63
63
  "deepmerge": "^4.2.2",
@@ -68,9 +68,6 @@
68
68
  "typedoc-plugin-missing-exports": "^2.0.0",
69
69
  "typescript": "~5.3.3"
70
70
  },
71
- "peerDependencies": {
72
- "@metamask/network-controller": "^26.0.0"
73
- },
74
71
  "engines": {
75
72
  "node": "^18.18 || >=20"
76
73
  },