@metamask-previews/polling-controller 16.0.0-preview-a4b203f → 16.0.0-preview-102c9cee

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.
@@ -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,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,GAE7C,EAAE,CAAC,kCAAkC,CAA6B,KAAK,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"]}
@@ -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"}
@@ -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;QA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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":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":";;;;;AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAO3D,OAAO,EACL,kCAAkC,EAClC,MAAM,EACP,wCAAoC;AAWrC;;;;;;GAMG;AACH,gFAAgF;AAChF,8EAA8E;AAC9E,kHAAkH;AAClH,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,e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AAc,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,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,GAE/C,EAAE,CAAC,oCAAoC,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;YAE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,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"]}
@@ -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"}
@@ -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;AAG3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,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,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-previews/polling-controller",
3
- "version": "16.0.0-preview-a4b203f",
3
+ "version": "16.0.0-preview-102c9cee",
4
4
  "description": "Polling Controller is the base for controllers that polling by networkClientId",
5
5
  "keywords": [
6
6
  "MetaMask",